pcloud package

Subpackages

Submodules

pcloud.mem_to_file_proxy module

class pcloud.mem_to_file_proxy.MemToFileProxy(mem_check_threshold=None)

Bases: object

Author:

Alberto M. Esmoris Pena

Class representing a proxy between point clouds loaded in memory and a binary file in persistent storage representing them. The proxy must support the operation of loading a point cloud from its binary representation, the operation of saving a point cloud from its binary representation, and the logic to check when the data of a given point cloud must be dumped to save memory sources.

Variables:
  • mem_check_threshold (float) – Decimal number inside [0, 1] that determines the cut value (threshold) of occupied memory that is acceptable before dumping the point cloud’s data. More concretely, when the memory required by the point cloud’s data divided by the system’s memory is greater than this threshold, dumping the point cloud data will be recommended.

  • proxy_file (None or file object) – The binary proxy file where the point cloud’s data is stored.

__init__(mem_check_threshold=None)
dump(pcloud)

Dump the given point cloud’s data to the binary proxy file.

Parameters:

pcloud (PointCloud) – The point cloud which data must be dumped.

load(pcloud)

Load the data from the binary proxy file into the given point cloud.

Parameters:

pcloud (PointCloud) – Point cloud for which the data in the proxy file must be loaded.

release()

Discards the proxy file, if any. This means closing the file and removing the reference.

Check whether dumping the given point cloud is recommended (True) or not (False). A point cloud must be dumped when the memory it requires is greater than self.mem_check_threshold considering the system’s memory.

See SysUtils and SysUtils.get_sys_mem().

Parameters:

pcloud (PointCloud) – The point cloud to be checked.

Returns:

True if the given point cloud should be dumped, False otherwise.

Return type:

bool

is_dumped()

Check whether the proxy is representing a dumped point cloud or not.

Returns:

True if the proxy holds a dumped point cloud, false otherwise.

Return type:

bool

pcloud.point_cloud module

exception pcloud.point_cloud.PointCloudException(message)

Bases: VL3DException

Author:

Alberto M. Esmoris Pena

Class for exceptions related to the PointCloud data structure and associated methods.

See VL3DException

__init__(message)
class pcloud.point_cloud.PointCloud(las, mem_check_threshold=None)

Bases: object

Author:

Alberto M. Esmoris Pena

Base class representing the point cloud data structure and

providing basic data handling methods.

Variables:

las (See laspy) – The LASPY data structure representing the point cloud.

__init__(las, mem_check_threshold=None)

Initialize a PointCloud instance. See the PointCloudFactoryFacade for methods to successfully built PointCloud instances, e.g., by reading a LAS file.

Parameters:

las – The LASPY data structure representing the point cloud.

get_num_points()

Obtain the number of points in the point cloud.

Returns:

Number of points in the point cloud.

Return type:

int

get_header()

Obtain the header representing the input point cloud.

Returns:

Header representing the input point cloud.

get_coordinates_matrix()

Obtain the matrix of coordinates representing the point cloud (supported for 3D point clouds only).

Returns:

The matrix of coordinates representing the point cloud.

Return type:

np.ndarray

get_features_matrix(fnames)

Obtain the matrix of features representing the point cloud.

Parameters:

fnames (list) – The name of the point cloud’s attributes corresponding to the features of interest.

Returns:

The matrix of features representing the point cloud.

Return type:

np.ndarray

get_features_names()
Obtain a list of strings representing the name for each feature in

the point cloud.

Returns:

A list with the name for each feature.

Return type:

list

has_given_features(fnames)

Check whether the point cloud contains the features represented by the given feature names.

Parameters:

fnames – The names of the features to be checked.

Returns:

True if all the features specified in fnames are available, False otherwise.

get_classes_vector()

Obtain a vector which components represent the point-wise classes of the point cloud.

Returns:

The vector of classes (\(\pmb{y}\)).

Return type:

np.ndarray

has_classes()

Check whether there are available classes for the point cloud.

Returns:

True if classes are available, false otherwise.

Return type:

bool

get_predictions_vector()

Obtain a vector which components represent the point-wise classes of a classification model computed on the point cloud.

Returns:

The vector of predicted classes (\(\hat{\pmb{y}}\))

Return type:

np.ndarray

has_predictions()

Check whether there are available predictions for the point cloud.

Returns:

True if predictions are available, false otherwise.

Return type:

bool

equals(pcloud, compare_header=True)

Check whether this (self) and given (pcloud) point clouds are equal or not. In this method, equality holds if and only if all the values of one point cloud match those of the other.

Parameters:
  • pcloud (PointCloud) – The point cloud to be compared against.

  • compare_header (bool) – True to consider the LAS header when comparing the point clouds, False otherwise.

Returns:

True if point clouds are equal, False otherwise.

Return type:

bool

add_features(fnames, feats, ftypes='f')

Add new features to the point cloud.

Parameters:
  • fnames – The name of the features in a list or tuple format.

  • feats – The matrix of features such that each column represents a feature and each row a point (as a numpy array). See np.ndarray.

  • ftypes – The list or tuple of types representing the type for each new feature. If it is a single type, then all features are assumed to have the same type.

Returns:

The updated point cloud.

Return type:

PointCloud

set_feature(fname, f)

Update the feature in the point cloud.

Parameters:
  • fname (str) – The name of the feature to be updated (note that it must exist in the point cloud).

  • f – The new point-wise values for the feature.

Returns:

The updated point cloud.

Return type:

PointCloud

remove_features(fnames)

Remove features from the point cloud.

Parameters:

fnames (list or tuple (of str)) – The name of the features to be removed.

Returns:

The updated point cloud.

Return type:

PointCloud

preserve_mask(mask)

Preserve the points whose index in the mask corresponds to True. Otherwise, the point is discarded.

Parameters:

mask – The binary mask to be applied (True means preserve, False means discard).

Returns:

The point cloud after applying the mask.

Return type:

PointCloud

remove_mask(mask)

Discard the points whose index in the mask corresponds to True. Otherwise, the point is preserved.

Parameters:

mask – The binary mask to be applied (True means remove, False means preserve).

Returns:

The point cloud after applying the mask.

Return type:

PointCloud

set_classes_vector(y)

Set the point-wise classes of the point cloud from the given vector of classes.

Parameters:

y (np.ndarray) – The vector of classes (\(\pmb{y}\)).

Returns:

The updated point cloud.

Return type:

PointCloud

clear_data(proxy_release=False)

Remove all the data from the point cloud. Note that this means removing the data from memory. In case the data is stored in a proxy file it can be restored (from file to memory) when needed. To also remove the proxy file, proxy_release=True must be passed explicitly.

set_coordinates(X)

Set the point-wise coordinates of the point cloud from the given structure space matrix X.

Parameters:

X – The structure space matrix, i.e., a matrix where rows are points and columns represent coordinates.

Returns:

The updated point cloud.

Return type:

PointCloud

update_scale(scale, to_nearest_power_of_ten=False)

Update the scale of the LAS data structure (if necessary) so the precision of the given input scale can be represented. Note that if the current scale of the LAS data structure is enough, then it will not be updated. To force a given salce use PointCloud.set_scale() instead.

Parameters:
  • scale (float or list of float) – The scale of the decimal representation such that decimal differences up to the given scale can be represented.

  • to_nearest_power_of_ten (bool) – If True, then the scale will be rounded to the nearest power of ten that is equal to or less than the given scale. If False (default), the scale will be considered exactly as given.

Returns:

The updated point cloud.

Return type:

PointCloud

set_scale(scale, to_nearest_power_of_ten=False)

Set the escale of the LAS data structure to the given one. Note that the scale determines the precision of the decimal representation.

Parameters:
  • scale (float or list of float) – The new scale for the LAS data structure.

  • to_nearest_power_of_ten (bool) – If True, then the scale will be rounded to the nearest power of ten that is equal to or less than the given scale. If False (default), the scale will be considered exactly as given.

Returns:

The updated point cloud.

Return type:

PointCloud

proxy_dump()

Dump the point cloud to a binary proxy file if and only if it is recommended and not already dumped.

See MemToFileProxy, MemToFileProxy.dump(), and MemToFileProxy.is_dump_recommended().

proxy_load()

Load the point cloud from a binary proxy file if necessary. Any method from the PointCloud class that needs to operate with the point cloud’s date should call proxy_load to be sure that the data is available in main memory.

See MemToFileProxy, MemToFileProxy.dump(), and MemToFileProxy.load().

pcloud.point_cloud_factory_facade module

class pcloud.point_cloud_factory_facade.PointCloudFactoryFacade

Bases: object

Author:

Alberto M. Esmoris Pena

Facade-like class offering methods to make point clouds.

static make_from_file(path)

Build a PointCloud from a given file path (either in the local file system or from a URL pointing to a LAS/LAZ file).

Parameters:

path (str) – Path to a file representing a point cloud (must be stored in LAS format). Alternatively, it can be a URL starting with “http://” or “https://”.

Returns:

Built PointCloud

Return type:

PointCloud

static make_from_arrays(X, F, y=None, header=None, fnames=None, scale=None, force_scale=False, logging=True)

Build a PointCloud from given arrays, and (optionally) header.

Parameters:
  • X – The matrix of coordinates.

  • F – The matrix of features.

  • y – The vector of classes.

  • header – The LAS header. If None, default header is used.

  • fnames – The name of each feature. If None, then features will be named f1,…,fn.

  • scale – The scale for the LAS header. It governs the spatial precision of the points. If None (default) it will be automatically determined from the coordinates (X).

  • force_scale (bool) – True to force the given scale even when a header is given, False (default) otherwise.

  • logging – Govern whether the logging system must be used (True`) or not (``False). In general (by default) it will be used. However, certain calls (e.g., multiprocessing calls) might fail when calling the LOGGING system from different processes. In these cases, it is necessary to disable logging.

Returns:

Built PointCloud

Return type:

PointCloud

static make_from_pcloud(pcloud)

Build a PointCloud from another point cloud. Note that the built point cloud is a copy from the given point cloud.

Parameters:

pcloud (PointCloud) – The point cloud to be copied.

Returns:

A copy of the given point cloud.

Return type:

PointCloud

pcloud.point_cloud_filter module

class pcloud.point_cloud_filter.PointCloudFilter(conditions)

Bases: object

Author:

Alberto M. Esmoris Pena

The base PointCloudFilter class represents a set of operations that can be seen as a data filter to be applied on the point cloud. Typically, filters are relationals that decide whether

Variables:

conditions (list of dict) – The conditions to be applied by the filter.

__init__(conditions)

Initialize a PointCloudFilter from a list of conditions.

Parameters:

conditions (dict) – The list of conditions. Each condition must be a dictionary specifying an operation on the point cloud.

filter(pcloud)

Apply the filter to the given point cloud.

Parameters:

pcloud (PointCloud) – The point cloud to be filtered.

Returns:

The filtered point cloud.

Return type:

PointCloud

apply_relational(pcloud, condition, relational)

Apply a relational to filter the point cloud with respect to a given condition.

Parameters:
  • pcloud (PointCloud) – The point cloud to be filtered.

  • condition (dict) – The condition to be applied as part of the filter.

  • relational (function) – The function that evaluates the relational.

Returns:

The filtered point cloud.

Return type:

PointCloud

Module contents

author:

Alberto M. Esmoris Pena

The pcloud package contains the logic to handle point cloud data.