reVX.utilities.exclusions.AbstractBaseExclusionsMerger
- class AbstractBaseExclusionsMerger(excl_fpath, regulations, features, hsds=False)[source]
Bases:
AbstractExclusionCalculatorInterface
Create exclusions layers for exclusions
- Parameters:
excl_fpath (str) – Path to .h5 file containing exclusion layers, will also be the location of any new exclusion layers
regulations (~reVX.utilities.AbstractBaseRegulations subclass) – A regulations object used to extract exclusion regulation values.
features (str) – Path to file containing features to compute exclusions from.
hsds (bool, optional) – Boolean flag to use h5pyd to handle .h5 ‘files’ hosted on AWS behind HSDS. By default False.
Methods
compute_all_local_exclusions
([max_workers])Compute local exclusions for all counties either.
compute_exclusions
([out_layer, out_tiff, ...])Compute exclusions for all states either in serial or parallel.
compute_generic_exclusions
([max_workers])Compute generic exclusions.
compute_local_exclusions
(regulation_value, ...)Compute local feature exclusions.
Reduce regulations to correct state and features.
run
(excl_fpath, features_path, out_fn, ...)Compute exclusions and write them to a geotiff.
Attributes
Function to merge overlapping exclusion layers.
Array representing no exclusions.
Geotiff profile.
Regulations table.
- property regulations_table
Regulations table.
- Returns:
geopandas.GeoDataFrame | None
- compute_all_local_exclusions(max_workers=None)[source]
Compute local exclusions for all counties either.
- Parameters:
max_workers (int, optional) – Number of workers to use for exclusions computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None run in parallel on all available cores. By default None.
- Returns:
exclusions (ndarray) – Raster array of exclusions.
- compute_exclusions(out_layer=None, out_tiff=None, replace=False, max_workers=None)[source]
Compute exclusions for all states either in serial or parallel. Existing exclusions are computed if a regulations file was supplied during class initialization, otherwise generic exclusions are computed.
- Parameters:
out_layer (str, optional) – Name to save rasterized exclusions under in .h5 file. If None, exclusions will not be written to the .h5 file. By default None.
out_tiff (str, optional) – Path to save geotiff containing rasterized exclusions. If None, exclusions will not be written to a geotiff file. By default None.
replace (bool, optional) – Flag to replace geotiff if it already exists. By default False.
max_workers (int, optional) – Number of workers to use for exclusion computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None, run in parallel on all available cores. By default None.
- Returns:
exclusions (ndarray) – Raster array of exclusions
- classmethod run(excl_fpath, features_path, out_fn, regulations, max_workers=None, replace=False, out_layers=None, hsds=False, **kwargs)[source]
Compute exclusions and write them to a geotiff. If a regulations file is given, compute local exclusions, otherwise compute generic exclusions. If both are provided, generic and local exclusions are merged such that the local exclusions override the generic ones.
- Parameters:
excl_fpath (str) – Path to .h5 file containing exclusion layers, will also be the location of any new exclusion layers.
features_path (str) – Path to file or directory feature shape files. This path can contain any pattern that can be used in the glob function. For example, /path/to/features/[A]* would match with all the features in the directory /path/to/features/ that start with “A”. This input can also be a directory, but that directory must ONLY contain feature files. If your feature files are mixed with other files or directories, use something like /path/to/features/*.geojson.
out_fn (str) – Path to output geotiff where exclusion data should be stored.
regulations (~reVX.utilities.AbstractBaseRegulations subclass) – A regulations object used to extract exclusion regulation distances.
max_workers (int, optional) – Number of workers to use for exclusion computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None, run in parallel on all available cores. By default None.
replace (bool, optional) – Flag to replace geotiff if it already exists. By default False.
out_layers (dict, optional) – Dictionary mapping feature file names (with extension) to names of layers under which exclusions should be saved in the excl_fpath .h5 file. If None or empty dictionary, no layers are saved to the h5 file. By default None.
hsds (bool, optional) – Boolean flag to use h5pyd to handle .h5 ‘files’ hosted on AWS behind HSDS. By default False.
**kwargs – Keyword args to exclusions calculator class.
- abstract compute_generic_exclusions(max_workers=None)
Compute generic exclusions.
This method should compute the exclusions using a generic regulation value (self._regulations.generic).
- Parameters:
max_workers (int, optional) – Number of workers to use for exclusions computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None run in parallel on all available cores. By default None.
- Returns:
exclusions (ndarray) – Raster array of exclusions
- abstract static compute_local_exclusions(regulation_value, county, *args)
Compute local feature exclusions.
This method should compute the exclusions using the information about the input county.
- Parameters:
regulation_value (float | int) – Regulation value for county.
county (geopandas.GeoDataFrame) – Regulations for a single county.
*args – Other arguments required for local exclusion calculation.
- Returns:
exclusions (np.ndarray) – Array of exclusions.
slices (2-tuple of slice) – X and Y slice objects defining where in the original array the exclusion data should go.
- abstract property exclusion_merge_func
Function to merge overlapping exclusion layers.
- Type:
callable
- abstract property no_exclusions_array
Array representing no exclusions.
- Type:
np.array
- abstract pre_process_regulations()
Reduce regulations to correct state and features.
When implementing this method, make sure to update self._regulations.df.