natcap.invest.habitat_quality package

Submodules

natcap.invest.habitat_quality.habitat_quality module

InVEST Habitat Quality model

natcap.invest.habitat_quality.habitat_quality.check_projections(ds_uri_dict, proj_unit)

Check that a group of gdal datasets are projected and that they are projected in a certain unit.

ds_uri_dict - a dictionary of uris to gdal datasets proj_unit - a float that specifies what units the projection should be

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.check_projections, line 6)

Unexpected indentation.
in. ex: 1.0 is meters.
returns - False if one of the datasets is not projected or not in the
correct projection type, otherwise returns True if datasets are properly projected
natcap.invest.habitat_quality.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.habitat_quality.make_dictionary_from_csv(csv_uri, key_field)

Make a basic dictionary representing a CSV file, where the keys are a unique field from the CSV file and the values are a dictionary representing each row

csv_uri - a string for the path to the csv file key_field - a string representing which field is to be used

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.make_dictionary_from_csv, line 7)

Unexpected indentation.
from the csv file as the key in the dictionary

returns - a python dictionary

natcap.invest.habitat_quality.habitat_quality.make_linear_decay_kernel_uri(max_distance, kernel_uri)
natcap.invest.habitat_quality.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’

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.map_raster_to_dict_values, line 10)

Definition list ends without a blank line; unexpected unindent.

out_uri - a string for the output path of the created raster attr_dict - a dictionary representing a table of values we are interested

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.map_raster_to_dict_values, line 12)

Unexpected indentation.
in making into a raster

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.map_raster_to_dict_values, line 13)

Block quote ends without a blank line; unexpected unindent.
field - a string of which field in the table or key in the dictionary
to use as the new raster pixel values

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.map_raster_to_dict_values, line 15)

Definition list ends without a blank line; unexpected unindent.

out_nodata - a floating point value that is the nodata value. raise_error - a string that decides how to handle the case where the

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.map_raster_to_dict_values, line 17)

Unexpected indentation.
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.habitat_quality.raster_pixel_count(dataset_uri)

Determine how many of each unique pixel lies in the dataset (dataset)

dataset_uri - a GDAL raster dataset

returns - a dictionary whose keys are the unique pixel values and
whose values are the number of occurrences
natcap.invest.habitat_quality.habitat_quality.resolve_ambiguous_raster_path(uri, raise_error=True)

Get the real uri for a raster when we don’t know the extension of how the raster may be represented.

uri - a python string of the file path that includes the name of the
file but not its extension
raise_error - a Boolean that indicates whether the function should
raise an error if a raster file could not be opened.

return - the resolved uri to the rasster

natcap.invest.habitat_quality.habitat_quality.threat_names_match(threat_dict, sens_dict, prefix)

Check that the threat names in the threat table match the columns in the sensitivity table that represent the sensitivity of each threat on a lulc.

threat_dict - a dictionary representing the threat table:
{‘crp’:{‘THREAT’:’crp’,’MAX_DIST’:‘8.0’,’WEIGHT’:‘0.7’},
‘urb’:{‘THREAT’:’urb’,’MAX_DIST’:‘5.0’,’WEIGHT’:‘0.3’}, ... }
sens_dict - a dictionary representing the sensitivity table:
{‘1’:{‘LULC’:‘1’, ‘NAME’:’Residential’, ‘HABITAT’:‘1’,
‘L_crp’:‘0.4’, ‘L_urb’:‘0.45’...},

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.threat_names_match, line 12)

Block quote ends without a blank line; unexpected unindent.
‘11’:{‘LULC’:‘11’, ‘NAME’:’Urban’, ‘HABITAT’:‘1’,
‘L_crp’:‘0.6’, ‘L_urb’:‘0.3’...},

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/invest/envs/3.3.1/local/lib/python2.7/site-packages/natcap/invest/habitat_quality/habitat_quality.py:docstring of natcap.invest.habitat_quality.habitat_quality.threat_names_match, line 14)

Definition list ends without a blank line; unexpected unindent.

...}

prefix - a string that specifies the prefix to the threat names that is
found in the sensitivity table
returns - False if there is a mismatch in threat names or True if
everything passes

Module contents