onstove.DataProcessor#
- class onstove.DataProcessor(project_crs: pyproj.CRS | int | None = None, cell_size: tuple[float] = None, output_directory: str = 'output')#
Class containing the methods to process the GIS datasets required for the
MCAand theOnStovemodels.- Parameters:
- project_crs: pyproj.CRS or int, optional
The coordinate system of the project. The value can be anything accepted by geopandas.GeoDataFrame.to_crs, such as an authority string (eg “EPSG:4326”), a WKT string or an EPSG int. If defined all datasets added to the
DataProcessorwill be reprojected to this crs when calling thereproject_layers()method. If not defined then thecrsof thebase_layerwill be used.- cell_size: tuple of float (width, height), optional
The desired cell size of the raster layers. It should be defined in the units of the used
crs. If defined, it will be used to rescale all datasets when calling thealign()method. If not defined, thecell_sizeof thebase_layerwill be used.- output_directory: str, default ‘output’
A folder path where to save the output datasets.
- Attributes:
- layers: dict[str, dict[str, ‘RasterLayer’]]
All layers added to the
DataProcessorusing theadd_layer()method.- mask_layer: VectorLayer
Layer used to mask all datasets when calling the
mask_layers()method. It is set with theadd_mask_layer()method.- conn: psycopg2.connect
Connection to a PostgreSQL database, set with the
set_postgres()method.- base_layer:
RasterLayer to use as template for all raster based data processes. For example, the
align_layers()uses the grid cell of this raster to align all other rasters.
Methods
add_layer(category, name, path, layer_type)Adds a new layer (type VectorLayer or RasterLayer) to the MCA class
add_mask_layer(category, name, path[, ...])Adds a vector layer to self.mask_layer, which will be used to mask all other layers into is boundaries
align_layers([datasets])Ensures that the coordinate system and resolution of the raster is the same as the base layer
get_distance_rasters([datasets])Goes through all layer and call their .distance_raster method
mask_layers([datasets])Uses the a mask layer in
self.mask_layerto mask all other layers to its boundaries.normalize_rasters([datasets, buffer])Goes through all layer and call their .normalize method
read_model(path)Reads a model from a pickle
reproject_layers([datasets])Reprojects the layers specified by the user.
save_datasets([datasets])Saves all layers that have not been previously saved
set_postgres(dbname, user, password)Wrapper function to set a connection to a PostgreSQL database using the psycopg2.connect class.
to_pickle(name)Saves the model as a pickle.