# Habitat Quality Package¶

## 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 path to the directory that will write output and other temporary files (required) lulc_cur_path (string) – a path to an input land use/land cover raster (required) lulc_fut_path (string) – a path to an input land use/land cover raster (optional) lulc_bas_path (string) – a path to an input land use/land cover raster (optional, but required for rarity calculations) threat_folder (string) – a path to the directory that will contain all threat rasters (required) threats_table_path (string) – a path 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_vector_path (string) – a path to an input polygon shapefile containing data on the relative protection against threats (optional) sensitivity_table_path (string) – a path 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 path paths just before the file extension.

Example Args Dictionary:

{
'workspace_dir': 'path/to/workspace_dir',
'lulc_cur_path': 'path/to/lulc_cur_raster',
'lulc_fut_path': 'path/to/lulc_fut_raster',
'lulc_bas_path': 'path/to/lulc_bas_raster',
'threat_raster_folder': 'path/to/threat_rasters/',
'threats_table_path': 'path/to/threats_csv',
'access_vector_path': 'path/to/access_shapefile',
'sensitivity_table_path': 'path/to/sensitivity_csv',
'half_saturation_constant': 0.5,
'suffix': '_results',
}

Returns: None
natcap.invest.habitat_quality.make_linear_decay_kernel_path(max_distance, kernel_path)

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_path (string) – path to output raster whose values are in (0,1) representing distance to edge. Size is (max_distance * 2 + 1)^2 None
natcap.invest.habitat_quality.map_raster_to_dict_values(key_raster_path, out_path, attr_dict, field, out_nodata, values_required)

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_path - a GDAL raster path dataset whose pixel values relate to
the keys in ‘attr_dict’

out_path - 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:
1. raise_error is True and
2. 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 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. the full path, plus extension, to the valid raster.