Habitat Quality Package¶
Model Entry Point¶
Habitat Quality¶
Module contents¶
InVEST Habitat Quality model.
-
natcap.invest.habitat_quality.
execute
(args)¶ Habitat Quality.
Open files necessary for the portion of the habitat_quality model.
Parameters: - workspace_dir (string) – a uri to the directory that will write output and other temporary files during calculation (required)
- landuse_cur_uri (string) – a uri to an input land use/land cover raster (required)
- landuse_fut_uri (string) – a uri to an input land use/land cover raster (optional)
- landuse_bas_uri (string) – a uri to an input land use/land cover raster (optional, but required for rarity calculations)
- threat_folder (string) – a uri to the directory that will contain all threat rasters (required)
- threats_uri (string) – a uri to an input CSV containing data of all the considered threats. Each row is a degradation source and each column a different attribute of the source with the following names: ‘THREAT’,’MAX_DIST’,’WEIGHT’ (required).
- access_uri (string) – a uri to an input polygon shapefile containing data on the relative protection against threats (optional)
- sensitivity_uri (string) – a uri to an input CSV file of LULC types, whether they are considered habitat, and their sensitivity to each threat (required)
- half_saturation_constant (float) – a python float that determines the spread and central tendency of habitat quality scores (required)
- suffix (string) – a python string that will be inserted into all raster uri paths just before the file extension.
Example Args Dictionary:
{ 'workspace_dir': 'path/to/workspace_dir', 'landuse_cur_uri': 'path/to/landuse_cur_raster', 'landuse_fut_uri': 'path/to/landuse_fut_raster', 'landuse_bas_uri': 'path/to/landuse_bas_raster', 'threat_raster_folder': 'path/to/threat_rasters/', 'threats_uri': 'path/to/threats_csv', 'access_uri': 'path/to/access_shapefile', 'sensitivity_uri': 'path/to/sensitivity_csv', 'half_saturation_constant': 0.5, 'suffix': '_results', }
Returns: None
-
natcap.invest.habitat_quality.
make_linear_decay_kernel_uri
(max_distance, kernel_uri)¶ Create a linear decay kernel as a raster.
Pixels in raster are equal to d / max_distance where d is the distance to the center of the raster in number of pixels.
Parameters: - max_distance (int) – number of pixels out until the decay is 0.
- kernel_uri (string) – path to output raster whose values are in (0,1) representing distance to edge. Size is (max_distance * 2 + 1)^2
Returns: None
-
natcap.invest.habitat_quality.
map_raster_to_dict_values
(key_raster_uri, out_uri, attr_dict, field, out_nodata, raise_error)¶ Creates a new raster from ‘key_raster’ where the pixel values from ‘key_raster’ are the keys to a dictionary ‘attr_dict’. The values corresponding to those keys is what is written to the new raster. If a value from ‘key_raster’ does not appear as a key in ‘attr_dict’ then raise an Exception if ‘raise_error’ is True, otherwise return a ‘out_nodata’
- key_raster_uri - a GDAL raster uri dataset whose pixel values relate to
- the keys in ‘attr_dict’
out_uri - a string for the output path of the created raster attr_dict - a dictionary representing a table of values we are interested
in making into a raster- field - a string of which field in the table or key in the dictionary
- to use as the new raster pixel values
out_nodata - a floating point value that is the nodata value. raise_error - a string that decides how to handle the case where the
value from ‘key_raster’ is not found in ‘attr_dict’. If ‘raise_error’ is ‘values_required’, raise Exception, if ‘none’, return ‘out_nodata’- returns - a GDAL raster, or raises an Exception and fail if:
- raise_error is True and
- the value from ‘key_raster’ is not a key in ‘attr_dict’
-
natcap.invest.habitat_quality.
raster_pixel_count
(raster_path)¶ Count unique pixel values in raster.
Parameters: raster_path (string) – path to a raster Returns: dict of pixel values to frequency.
-
natcap.invest.habitat_quality.
resolve_ambiguous_raster_path
(path, raise_error=True)¶ Determine real path when we don’t know true path extension.
Parameters: - path (string) – file path that includes the name of the file but not its extension
- raise_error (boolean) – if True then function will raise an ValueError if a valid raster file could not be found.
Returns: the full path, plus extension, to the valid raster.