natcap.invest.coastal_vulnerability package¶
Submodules¶
natcap.invest.coastal_vulnerability.coastal_vulnerability module¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability.
execute
(args)¶ Coastal Vulnerability.
Parameters: - workspace_dir (string) – The path to the workspace directory on disk (required)
- aoi_uri (string) – Path to an OGR vector on disk representing the area of interest. (required)
- landmass_uri (string) – Path to an OGR vector on disk representing the global landmass. (required)
- bathymetry_uri (string) – Path to a GDAL raster on disk representing the bathymetry. Must overlap with the Area of Interest if if provided. (optional)
- bathymetry_constant (int) – An int between 1 and 5 (inclusive). (optional)
- relief_uri (string) – Path to a GDAL raster on disk representing the elevation within the land polygon provided. (optional)
- relief_constant (int) – An int between 1 and 5 (inclusive). (optional)
- elevation_averaging_radius (int) – a positive int. The radius around which to compute the average elevation for relief. Must be in meters. (required)
- mean_sea_level_datum (int) – a positive int. This input is the elevation of Mean Sea Level (MSL) datum relative to the datum of the bathymetry layer that they provide. The model transforms all depths to MSL datum by subtracting the value provided by the user to the bathymetry. This input can be used to run the model for a future sea-level rise scenario. Must be in meters. (required)
- cell_size (int) – Cell size in meters. The higher the value, the faster the computation, but the coarser the output rasters produced by the model. (required)
- depth_threshold (int) – Depth in meters (integer) cutoff to determine if fetch rays project over deep areas. (optional)
- exposure_proportion (float) – Minimum proportion of rays that project over exposed and/or deep areas need to classify a shore segment as exposed. (required)
- geomorphology_uri (string) – A OGR-supported polygon vector file that has a field called “RANK” with values between 1 and 5 in the attribute table. (optional)
- geomorphology_constant (int) – Integer value between 1 and 5. If layer associated to this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether.
- habitats_directory_uri (string) – Directory containing OGR-supported polygon vectors associated with natural habitats. The name of these shapefiles should be suffixed with the ID that is specified in the natural habitats CSV file provided along with the habitats (optional)
- habitats_csv_uri (string) – A CSV file listing the attributes for each
habitat. For more information, see ‘Habitat Data Layer’ section in
the model’s documentation. (required if
args['habitat_directory_uri']
is provided) - habitat_constant (int) – Integer value between 1 and 5. If layer associated to this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether. (optional)
- area_computed (string) – Determine if the output data is about all the
coast about sheltered segments only. Either
'sheltered'
or'both'
(required) - suffix (string) – A string that will be added to the end of the output file. (optional)
- climatic_forcing_uri (string) – An OGR-supported vector containing both wind wave information across the region of interest. (optional)
- climatic_forcing_constant (int) – Integer value between 1 and 5. If layer to this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether. (optional)
- continental_shelf_uri (string) – An OGR-supported polygon vector delineating edges of the continental shelf. Default is global continental shelf shapefile. If omitted, the user can specify depth contour. See entry below. (optional)
- depth_contour (int) – Used to delineate shallow and deep areas. Continental limit is at about 150 meters. (optional)
- sea_level_rise_uri (string) – An OGR-supported point or polygon vector file features with “Trend” fields in the attributes table. (optional)
- sea_level_rise_constant (int) – Integer value between 1 and 5. If layer to this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether. (optional)
- structures_uri (string) – An OGR-supported vector file containing rigid structures to identify the portions of the coast that is armored. (optional)
- structures_constant (int) – Integer value between 1 and 5. If layer associated this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether. (optional)
- population_uri (string) – A GDAL-supported raster file representing the population. (required)
- urban_center_threshold (int) – Minimum population required to consider shore segment a population center. (required)
- additional_layer_uri (string) – An OGR-supported vector file representing level rise, and will be used in the computation of coastal vulnerability and coastal vulnerability without habitat. (optional)
- additional_layer_constant (int) – Integer value between 1 and 5. If layer to this field is omitted, replace all shore points for this layer with a constant rank value in the computation of the coastal vulnerability index. If both the file and value for the layer are omitted, the layer is skipped altogether. (optional)
- rays_per_sector (int) – Number of rays used to subsample the fetch distance each of the 16 sectors. (required)
- max_fetch (int) – Maximum fetch distance computed by the model (>=60,000m). (optional)
- spread_radius (int) – Integer multiple of ‘cell size’. The coast from geomorphology layer could be of a better resolution than the global landmass, so the shores do not necessarily overlap. To make them coincide, the shore from the geomorphology layer is widened by 1 or more pixels. The value should be a multiple of ‘cell size’ that indicates how many pixels the coast from the geomorphology layer is widened. The widening happens on each side of the coast (n pixels landward, and n pixels seaward). (required)
- population_radius (int) – Radius length in meters used to count the number people leaving close to the coast. (optional)
Note
If neither
args['bathymetry_uri']
norargs['bathymetry_constant']
is provided, bathymetry is ignored altogether.If neither
args['relief_uri']
norargs['relief_constant']
is provided, relief is ignored altogether.If neither
args['geomorphology_uri']
norargs['geomorphology_constant']
is provided, geomorphology is ignored altogether.If neither
args['climatic_forcing_uri']
norargs['climatic_forcing_constant']
is provided, climatic_forcing is ignored altogether.If neither
args['sea_level_rise_uri']
norargs['sea_level_rise_constant']
is provided, sea level rise is ignored altogether.If neither
args['structures_uri']
norargs['structures_constant']
is provided, structures is ignored altogether.If neither
args['additional_layer_uri']
norargs['additional_layer_constant']
is provided, the additional layer option is ignored altogether.Example args:
args = { u'additional_layer_uri': u'CoastalProtection/Input/SeaLevRise_WCVI.shp', u'aoi_uri': u'CoastalProtection/Input/AOI_BarkClay.shp', u'area_computed': u'both', u'bathymetry_uri': u'Base_Data/Marine/DEMs/claybark_dem/hdr.adf', u'cell_size': 1000, u'climatic_forcing_uri': u'CoastalProtection/Input/WaveWatchIII.shp', u'continental_shelf_uri': u'CoastalProtection/Input/continentalShelf.shp', u'depth_contour': 150, u'depth_threshold': 0, u'elevation_averaging_radius': 5000, u'exposure_proportion': 0.8, u'geomorphology_uri': u'CoastalProtection/Input/Geomorphology_BarkClay.shp', u'habitats_csv_uri': u'CoastalProtection/Input/NaturalHabitat_WCVI.csv', u'habitats_directory_uri': u'CoastalProtection/Input/NaturalHabitat', u'landmass_uri': u'Base_Data/Marine/Land/global_polygon.shp', u'max_fetch': 12000, u'mean_sea_level_datum': 0, u'population_radius': 1000, u'population_uri': u'Base_Data/Marine/Population/global_pop/w001001.adf', u'rays_per_sector': 1, u'relief_uri': u'Base_Data/Marine/DEMs/claybark_dem/hdr.adf', u'sea_level_rise_uri': u'CoastalProtection/Input/SeaLevRise_WCVI.shp', u'spread_radius': 250, u'structures_uri': u'CoastalProtection/Input/Structures_BarkClay.shp', u'urban_center_threshold': 5000, u'workspace_dir': u'coastal_vulnerability_workspace' }
Returns: None
natcap.invest.coastal_vulnerability.coastal_vulnerability_core module¶
Coastal vulnerability model core functions
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
adjust_dataset_ranks
(input_uri, output_uri)¶ Adjust the rank of a dataset’s first band using ‘adjust_layer_ranks’.
- Inputs:
- input_uri: dataset uri where values are 1, 2, 3, 4, or 5
- output_uri: new dataset with values adjusted by ‘adjust_layer_ranks’.
Returns output_uri.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
adjust_layer_ranks
(layer)¶ Adjust the rank of a layer in case there are less than 5 values.
- Inputs:
- layer: a float or int numpy array as extracted by ReadAsArray
- that encodes the layer ranks (valued 1, 2, 3, 4, or 5).
- Output:
adjusted_layer: a numpy array of same dimensions as the input array with rank values reassigned follows:
-non-shore segments have a (no-data) value of zero (0) -all segments have the same value: all are set to a rank of 3 -2 different values: lower values are set to 3, 4 for the rest -3 values: 2, 3, and 4 by ascending level of vulnerability -4 values: 2, 3, 4, and 5 by ascending level of vulnerability
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
adjust_raster_to_aoi
(in_dataset_uri, aoi_datasource_uri, cell_size, out_dataset_uri)¶ Adjust in_dataset_uri to match aoi_dataset_uri’s extents, cell size and projection.
- Inputs:
- in_dataset_uri: the uri of the dataset to adjust
- aoi_dataset_uri: uri to the aoi we want to use to adjust
- in_dataset_uri
- out_dataset_uri: uri to the adjusted dataset
- Returns:
- out_dataset_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
adjust_shapefile_to_aoi
(data_uri, aoi_uri, output_uri, empty_raster_allowed=False)¶ Adjust the shapefile’s data to the aoi, i.e.reproject & clip data points.
- Inputs:
- data_uri: uri to the shapefile to adjust
- aoi_uri: uir to a single polygon shapefile
- base_path: directory where the intermediate files will be saved
- output_uri: dataset that is clipped and/or reprojected to the
aoi if necessary. - empty_raster_allowed: boolean flag that, if False (default),
causes the function to break if output_uri is empty, or return an empty raster otherwise.
Returns: output_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
aggregate_csvs
(csv_list, out_uri)¶ Concatenate 3-row csv files created with tif2csv
- Inputs:
- csv_list: list of csv_uri strings
- Outputs:
- uri_output: the output uri of the concatenated csv
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
aggregate_tifs_from_directory
(path='.', mask=None)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
aggregate_tifs_from_list
(uri_list, path, mask=None)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
assign_sheltered_segments
(exposure_raster_uri, raster_uri, output_raster_uri)¶ Propagate values from ‘sources’ across a surface defined by ‘mask’ in a breadth-first-search manner.
- Inputs:
-exposure_raster_uri: URI to the GDAL dataset that we want to process -mask: a numpy array where 1s define the area across which we want
to propagate the values defined in ‘sources’.- -sources: a tuple as is returned by numpy.where(…) of coordinates
- of where to pick values in ‘raster_uri’ (a source). They are the values we want to propagate across the area defined by ‘mask’.
-output_raster_uri: URI to the GDAL dataset where we want to save the array once the values from source are propagated.
Returns: nothing.
The algorithm tries to spread the values pointed by ‘sources’ to every of the 8 immediately adjascent pixels where mask==1. Each source point is processed in sequence to ensure that values are propagated from the closest source point. If a connected component of 1s in ‘mask’ does not contain any source, its value remains unchanged in the output raster.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
cast_ray_fast
(direction, d_max)¶ March from the origin towards a direction until either land or a maximum distance is met.
Inputs: - origin: algorithm’s starting point – has to be on sea - direction: marching direction - d_max: maximum distance to traverse - raster: land mass raster
Returns the distance to the origin.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
clip_datasource
(aoi_ds, orig_ds, output_uri)¶ Clip an OGR Datasource of geometry type polygon by another OGR Datasource geometry type polygon. The aoi_ds should be a shapefile with a layer that has only one polygon feature
aoi_ds - an OGR Datasource that is the clipping bounding box orig_ds - an OGR Datasource to clip out_uri - output uri path for the clipped datasource
returns - a clipped OGR Datasource
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
combined_rank
(R_k)¶ Compute the combined habitats ranks as described in equation (3)
- Inputs:
- R_k: the list of ranks
- Output:
- R_hab as decribed in the user guide’s equation 3.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_additional_layer
(args)¶ Compute the additional layer the sea level rise index.
- Inputs:
-args[‘additional_layer_uri’]: uri to the additional layer data. -args[‘aoi_uri’]: uri to datasource of the area of interest -args[‘shore_raster_uri’]: uri to the shoreline dataset (land =1, sea =0) -args[‘cell_size’]: integer of the cell size in meters -args[‘intermediate_directory’]: uri to the intermediate file
directory- Output:
- Return a dictionary of all the intermediate file URIs.
- Intermediate outputs:
- rasterized_sea_level_rise.tif:rasterized version of the shapefile
- shore_FIELD_NAME.tif: raw value along the shore.
- FIELD_NAME.tif: index along the shore. If all
- the shore has the same value, assign the moderate index value 3.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_coastal_exposure
(args)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_coastal_exposure_no_habitats
(args)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_coastal_population
(args)¶ Compute population living along the shore within a given radius.
- Inputs:
- args[‘intermediate_directory’]: uri to a directory where intermediate files are stored
- args[‘subdirectory’]: string URI of an existing subdirectory
- args[‘prefix’]: string prefix appended to every file generated
- args[‘population_uri’]: uri to the population density dataset.
- args[‘population_radius’]: used to compute the population density.
- args[‘aoi_uri’]: uri to a polygon shapefile
- args[‘cell_size’]: size of a pixel in meters
- Outputs:
- Return a uri dictionary of all the files created to generate the population density along the coastline.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_continental_shelf_distance
(args)¶ Copy the continental shelf distance data to the outputs/ directory.
- Inputs:
- args[‘shore_shelf_distance’]: uri to the continental shelf distance args[‘prefix’]:
- Outputs:
- data_uri: a dictionary containing the uri where the data is saved.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_erodible_shoreline
(args)¶ Compute the erodible shoreline as described in Greg’s notes. The erodible shoreline is the shoreline segments of rank 5.
- Inputs:
- args[geomorphology]: the geomorphology data. args[‘prefix’]: prefix to be added to the new filename. args[‘aoi_uri’]: URI to the area of interest shapefile args[‘cell_size’]: size of a cell on the raster
- Outputs:
- data_uri: a dictionary containing the uri where the data is saved.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_erosion_exposure
(args)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_fetch
(land_array, rays_per_sector, d_max, cell_size, shore_points, bathymetry, bathymetry_nodata, GT, shore_raster)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_fetch_uri
(landmass_raster_uri, rays_per_sector, d_max, cell_size, shore_uri, bathymetry_uri)¶ Given a land raster, return the fetch distance from a point in given directions
- land_raster: raster where land is encoded as 1s, sea as 0s,
- and cells outside the area of interest as anything different from 0s or 1s.
- directions: tuple of angles (in radians) from which the fetch
- will be computed for each pixel.
- d_max: maximum distance in meters over which to compute the fetch
- cell_size: size of a cell in meters
- shore_uri: URI to the raster where the shoreline is encoded as 1s,
- the rest as 0s.
- returns: a tuple (distances, depths) where:
- distances is a dictionary of fetch data where the key is a shore point (tuple of integer coordinates), and the value is a 1*sectors numpy array containing fetch distances (float) from that point for each sector. The first sector (0) points eastward.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_geomorphology
(args)¶ Translate geomorphology RANKS to shore pixels.
Create a raster identical to the shore pixel raster that has geomorphology RANK values. The values are gathered by finding the closest geomorphology feature to the center of the pixel cell.
Parameters: - args['geomorphology_uri'] (string) – a path on disk to a shapefile of the gemorphology ranking along the coastline.
- args['shore_raster_uri'] (string) – a path on disk to a the shoreline dataset (land = 1, sea = 0).
- args['intermediate_directory'] (string) – a path to the directory where intermediate files are stored.
- args['subdirectory'] (string) – a path for a directory to store the specific geomorphology intermediate steps.
Returns: - a dictionary of with the path for the geomorphology
raster.
Return type: data_uri (dict)
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_habitat_role
(args)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_natural_habitats_vulnerability
(args)¶ Compute the natural habitat rank as described in the user manual.
- Inputs:
- -args[‘habitats_csv_uri’]: uri to a comma-separated text file
- containing the list of habitats.
- -args[‘habitats_directory_uri’]: uri to the directory where to find
- the habitat shapefiles.
-args[‘aoi_uri’]: uri to the datasource of the area of interest -args[‘shore_raster_uri’]: uri to the shoreline dataset
(land =1, sea =0)-args[‘cell_size’]: integer cell size in meters -args[‘intermediate_directory’]: uri to the directory where
intermediate files are stored- Output:
- -data_uri: a dictionary of all the intermediate file URIs.
- Intermediate outputs:
- For each habitat (habitat name ‘ABCD’, with id ‘X’) shapefile:
ABCD_X_raster.tif: rasterized shapefile data.
ABCD_influence.tif: habitat area of influence. Convolution between the rasterized shape data and a circular kernel which
radius is the habitat’s area of influence, TRUNCATED TO CELL_SIZE!!!
ABCD_influence_on_shore.tif: habitat influence along the shore
- habitats_available_data.tif: combined habitat rank along the
shore using equation 4.4 in the user guide.
habitats_missing_data.tif: shore section without habitat data.
habitats.tif: shore ranking using habitat and default ranks.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_relief_rank
(args)¶ Compute the relief index as is described in InVEST’s user guide.
- Inputs:
- args[‘relief_uri’]: uri to an elevation dataset.
- args[‘aoi_uri’]: uri to the datasource of the region of interest.
- args[‘landmass_uri’]: uri to the landmass datasource where land is 1 and sea is 0.
- args[‘spread_radius’]: if the coastline from the geomorphology i
- doesn’t match the land polygon’s shoreline, we can increase the overlap by ‘spreading’ the data from the geomorphology over a wider area. The wider the spread, the more ranking data overlaps with the coast. The spread is a convolution between the geomorphology ranking data and a 2D gaussian kernel of area (2*spread_radius+1)^2. A radius of zero reduces the kernel to the scalar 1, which means no spread at all.
- args[‘spread_radius’]: how much the shore coast is spread to match
- the relief’s coast.
- args[‘shore_raster_uri’]: URI to the shore tiff dataset.
- args[‘cell_size’]: granularity of the rasterization.
- args[‘intermediate_directory’]: where intermediate files are
- stored
- Output:
- Return R_relief as described in the user manual.
- A rastrer file called relief.tif
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_sea_level_rise
(args)¶ Compute the sea level rise index as described in the user manual.
- Inputs:
-args[‘sea_level_rise’]: shapefile with the sea level rise data. -args[‘aoi_uri’]: uri to datasource of the area of interest -args[‘shore_raster_uri’]: uri to the shoreline dataset (land =1, sea =0) -args[‘cell_size’]: integer of the cell size in meters -args[‘intermediate_directory’]: uri to the intermediate file
directory- Output:
- Return a dictionary of all the intermediate file URIs.
- Intermediate outputs:
- rasterized_sea_level_rise.tif:rasterized version of the shapefile
- shore_level_rise.tif: sea level rise along the shore.
- sea_level_rise.tif: sea level rise index along the shore. If all
- the shore has the same value, assign the moderate index value 3.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_segment_exposure
(args)¶ Compute exposed and sheltered shoreline segment map.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_structure_protection
(args)¶ Compute the structure influence on the shore to later include it in the computation of the layers final rankings, as is specified in Gregg’s the additional notes (decrement ranks around structure edges).
- Inputs:
- args[‘aoi_uri’]: string uri to the datasource of the area of
- interest
- args[‘shore_raster_uri’]: dataset uri of the coastline within the AOI
- args[‘structures_uri’]: string of the structure datasource uri
- args[‘cell_size’]: integer of the size of a pixel in meters
- args[‘intermediate_directory’]: string of the uri where
- intermediate files are stored
- args[‘prefix’]: string prefix appended to every intermediate file
- Outputs:
- data_uri: a dictionary of the file uris generated in the intermediate directory.
- data_uri[‘adjusted_structures’]: string of the dataset uri obtained from reprojecting args[‘structures_uri’] and burining it onto the aoi. Contains the structure information across the whole aoi.
- data_uri[‘shore_structures’]: string uri pointing to the structure information along the coast only.
- data_uri[‘structure_influence’]: string uri pointing to a datasource of the spatial influence of the structures.
- data_uri[‘structure_edge’]: string uri pointing to the datasource of the edges of the structures.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_surge_potential
(args)¶ Compute surge potential index as described in the user manual.
- Inputs:
- args[‘bathymetry’]: bathymetry DEM file.
- args[‘landmass’]: shapefile containing land coverage data (land = 1, sea = 0)
- args[‘aoi_uri’]: uri to the datasource of the area of interest
- args[‘shore_raster_uri’]: uri to a shore raster where the shoreline is 1, and everything else is 0.
- args[‘cell_size’]: integer number for the cell size in meters
- args[‘intermediate_directory’]: uri to the directory where intermediate files are stored
- Output:
- Return R_surge as described in the user guide.
- Intermediate outputs:
- rasterized_sea_level_rise.tif:rasterized version of the shapefile
- shore_level_rise.tif: sea level rise along the shore.
- sea_level_rise.tif: sea level rise index along the shore.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_wave_exposure
(args)¶ Compute the wind exposure for every shore segment
- Inputs:
- args[‘climatic_forcing_uri’]: uri to wave datasource
- args[‘aoi_uri’]: uri to area of interest datasource
- args[‘fetch_distances’]: a dictionary of (point, list) pairs where point is a tuple of integer (row, col) coordinates and list is a maximal fetch distance in meters for each fetch sector.
- args[‘fetch_depths’]: same dictionary as fetch_distances, but list is a maximal fetch depth in meters for each fetch sector.
- args[‘cell_size’]: cell size in meters (integer)
- args[‘H_threshold’]: threshold (double) for the H function (eq. 7)
- args[‘intermediate_directory’]: uri to the directory that contains the intermediate files
- Outputs:
- data_uri: dictionary of the uri of all the files created in the function execution
- Detail of files:
- A file called wave.tif that contains the wind exposure index along the shore.
- For each equiangular fetch sector k:
- F_k.tif: per-sector fetch value (see eq. 6).
- H_k.tif: per-sector H value (see eq. 7)
- E_o_k.tif: per-sector average oceanic wave power (eq. 6)
- E_l_k.tif: per-sector average wind-generated wave power (eq.9)
- E_w_k.tif: per-sector wave power (eq.5)
- E_w.tif: combined wave power.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
compute_wind_exposure
(args)¶ Compute the wind exposure for every shore segment as in equation 4.5
- Inputs:
- args[‘climatic_forcing_uri’]: uri to the wind information datasource
- args[‘aoi_uri’]: uri to the area of interest datasource
- args[‘fetch_distances’]: a dictionary of (point, list) pairs where point is a tuple of integer (row, col) coordinates and list is a maximal fetch distance in meters for each fetch sector.
- args[‘fetch_depths’]: same dictionary as fetch_distances, but list is a maximal fetch depth in meters for each fetch sector.
- args[‘cell_size’]: granularity of the rasterization.
- args[‘intermediate_directory’]:where intermediate files are stored
- args[‘prefix’]: string
- Outputs:
- data_uri: dictionary of the uri of all the files created in the function execution
- File description:
- REI.tif: combined REI value of the wind exposure index for all sectors along the shore.
- For each equiangular fetch sector n:
- REI_n.tif: per-sector REI value (U_n * P_n * F_n).
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
convert_tif_to_csv
(tif_uri, csv_uri=None, mask=None)¶ Converts a single band geo-tiff file to a csv text file
- Inputs:
- -tif_uri: the uri to the file to be converted -csv_uri: uri to the output file. The file should not exist.
- Outputs:
- -returns the ouput file uri
returns nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
convert_tifs_to_csv
(tif_list, mask=None)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
detect_shore
(land_sea_array, aoi_array, aoi_nodata)¶ Extract the boundary between land and sea from a raster.
- raster: numpy array with sea, land and nodata values.
returns a numpy array the same size as the input raster with the shore encoded as ones, and zeros everywhere else.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
detect_shore_uri
(landmass_raster_uri, aoi_raster_uri, output_uri)¶ Extract the boundary between land and sea from a raster.
- raster: numpy array with sea, land and nodata values.
returns a numpy array the same size as the input raster with the shore encoded as ones, and zeros everywhere else.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
dict_to_point_shapefile
(dict_data, out_path, spat_ref, columns, row_order)¶ Create a point shapefile from a dictionary.
Parameters: - dict_data (dict) – a dictionary where keys point to a sub dictionary that has at least keys ‘x’, ‘y’. Each sub dictionary will be added as a point feature using ‘x’, ‘y’ as the geometry for the point. All other key, value pairs in the sub dictionary will be added as fields and values to the point feature.
- out_path (string) – a path on disk for the point shapefile.
- spat_ref (osr spatial reference) – an osr spatial reference to use when creating the layer.
- columns (list) – a list of strings representing the order the field names should be written. Attempting the attribute table reflects this order.
- row_order (list) – a list of tuples that match the keys of ‘dict_data’. This is so we can add the points in a specific order and hopefully populate the attribute table in that order.
Returns: Nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
disc_kernel
(r)¶ Create a (r+1)^2 disc-shaped array filled with 1s where d(i-r,j-r) <= r
Input: r, the kernel radius. r=0 is a single scalar of value 1.
- Output: a (r+1)x(r+1) array with:
- 1 if cell is closer than r units to the kernel center (r,r),
- 0 otherwise.
Distances are Euclidean.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
enumerate_shapefile_fields
(shapefile_uri)¶ Enumerate all the fielfd in a shapefile.
- Inputs:
- -shapefile_uri: uri to the shapefile which fields have to be enumerated
Returns a nested list of the field names in the order they are stored in the layer, and groupped per layer in the order the layers appear.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
execute
(args)¶ Entry point for coastal vulnerability core
args[‘’] - actual data structure the way I want them look like :RICH:DESCRIBE ALL THE ARGUMENTS IN ARGS
returns nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
fetch_vectors
(angles)¶ convert the angles passed as arguments to raster vector directions.
- Input:
- -angles: list of angles in radians
- Outputs:
- -directions: vector directions numpy array of size (len(angles), 2)
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
find_attribute_field
(field_name, shapefile_uri)¶ Look for a field name in the shapefile attribute table. Search is case insensitive.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
get_field
(field_name, shapefile, case_sensitive=True)¶ Return the field in shapefile that corresponds to field_name, None otherwise.
- Inputs:
- field_name: string to look for.
- shapefile: where to look for the field.
- case_sensitive: indicates whether the case is relevant when
comparing field names
- Output:
- the field name in the shapefile that corresponds to field_name,
None otherwise.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
get_layer_and_index_from_field_name
(field_name, shapefile)¶ Given a field name, return its layer and field index. Inputs:
- field_name: string to look for.
- shapefile: where to look for the field.
- Output:
- A tuple (layer, field_index) if the field exist in ‘shapefile’.
- (None, None) otherwise.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
has_field
(field_name, shapefile, case_sensitive=True)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
is_point_datasource
(uri)¶ Returns True if the datasource is a point shapefile
- Inputs:
- -uri: uri to a datasource
- Outputs:
- -True if uri points to a point datasource, False otherwise
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
is_polygon_datasource
(uri)¶ Returns True if the datasource is a polygon shapefile
- Inputs:
- -uri: uri to a datasource
- Outputs:
- -True if uri points to a polygon datasource, False otherwise
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
nearest_vector_neighbor
(neighbors_path, point_path, inherit_field)¶ Inherit a field value from the closest shapefile feature.
Each point in ‘point_path’ will inherit field ‘inherit_field’ from the closest feature in ‘neighbors_path’. Uses an rtree to build up a spatial index of ‘neighbor_path’ bounding boxes to find nearest points.
Parameters: - neighbors_path (string) – a filepath on disk to a shapefile that has at least one field called ‘inherit_field’
- point_path (string) – a filepath on disk to a shapefile. A field ‘inherit_field’ will be added to the point features. The value of that field will come from the closest feature’s field in ‘neighbors_path’
- inherit_field (string) – the name of the field in ‘neighbors_path’ to pass along to ‘point_path’.
Returns: Nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
preprocess_dataset
(dataset_uri, aoi_uri, cell_size, output_uri)¶ Funstion that preprocesses an input dataset (clip, reproject, resample) so that it is ready to be used in the model
- Inputs:
-dataset_uri: uri to the input dataset to be pre-processed -aoi_uri: uri to an aoi polygon datasource that is used for
clipping and reprojection.-cell_size: output dataset cell size in meters (integer) -output_uri: uri to the pre-processed output dataset.
Returns output_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
preprocess_inputs
(args)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
preprocess_point_datasource
(datasource_uri, aoi_uri, cell_size, output_uri, field_list, nodata=0.0)¶ Function that converts a point shapefile to a dataset by clipping, reprojecting, resampling, burning, and extrapolating burnt values.
- Inputs:
-datasource_uri: uri to the datasource to be pre-processed -aoi_uri: uri to an aoi polygon datasource that is used for
clipping and reprojection.-cell_size: output dataset cell size in meters (integer) -output_uri: uri to the pre-processed output dataset. -field_name: name of the field in the attribute table to get the values from. If a number, use it as a constant. If Null, use 1.
Returns output_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
preprocess_polygon_datasource
(datasource_uri, aoi_uri, cell_size, output_uri, field_name=None, all_touched=False, nodata=0.0, empty_raster_allowed=False)¶ Function that converts a polygon shapefile to a dataset by clipping, reprojecting, resampling, burning, and extrapolating burnt values.
- Inputs:
-datasource_uri: uri to the datasource to be pre-processed -aoi_uri: uri to an aoi polygon datasource that is used for
clipping and reprojection.-cell_size: output dataset cell size in meters (integer) -output_uri: uri to the pre-processed output dataset. -field_name: name of the field in the attribute table to get the values from. If a number, use it as a constant. If Null, use 1. -all_touched: boolean flag used in gdal’s vectorize_rasters options flag -nodata: float used as nodata in the output raster -empty_raster_allowed: flag that allows the function to return an empty raster if set to True, or break if set to False. False is the default.
Returns output_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
projections_match
(projection_list, silent_mode=True)¶ Check that two gdal datasets are projected identically. Functionality adapted from Doug’s biodiversity_biophysical.check_projections
- Inputs:
- projection_list: list of wkt projections to compare
- silent_mode: id True (default), don’t output anything, otherwise output if and why some projections are not the same.
- Output:
- False the datasets are not projected identically.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
rank_by_quantiles
(X, bin_count)¶ Tries to evenly distribute elements in X among ‘bin_count’ bins. If the boundary of a bin falls within a group of elements with the same value, all these elements will be included in that bin. Inputs:
-X: a 1D numpy array of the elements to bin -bin_count: the number of binsReturns the bin boundaries ready to be used by numpy.digitize
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
rank_shore
(X, bin_count)¶ Assign a rank based on natural breaks (Jenks natural breaks for now).
- Inputs:
- X: a numpy array with the lements to be ranked
- bins: the number of ranks (integer)
- Outputs:
- output: a numpy array with rankings in the interval
- [0, bin_count-1] that correspond to the elements of X (rank of X[i] == outputs[i]).
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
raster_from_shapefile_uri
(shapefile_uri, aoi_uri, cell_size, output_uri, field=None, all_touched=False, nodata=0.0, datatype=<Mock id='140270534831824'>)¶ Burn default or user-defined data from a shapefile on a raster.
- Inputs:
- shapefile: the dataset to be discretized
- aoi_uri: URI to an AOI shapefile
- cell_size: coarseness of the discretization (in meters)
- output_uri: uri where the raster will be saved
- field: optional field name (string) where to extract the data
- from.
- all_touched: optional boolean that indicates if we use GDAL’s ALL_TOUCHED parameter when rasterizing.
- Output: A shapefile where:
If field is specified, the field data is used as burn value. If field is not specified, then:
- shapes on the first layer are encoded as 1s
- the rest is encoded as 0
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
raster_to_point_vector
(raster_path, point_vector_path)¶ Create a point shapefile from raster pixels.
Creates a point feature from each non nodata raster pixel, where the geometry for the point is the center of the pixel. A field ‘Value’ is added to each point feature with the value from the pixel. The created point shapefile will use a spatial reference taking from the rasters projection.
Parameters: - raster_path (string) – a filepath on disk of the raster to convert into a point shapefile.
- point_vector_path (string) – a filepath on disk for where to save the shapefile. Must have a ‘.shp’ extension.
Returns: Nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
raster_wkt
(raster)¶ Return the projection of a raster in the OpenGIS WKT format.
- Input:
- raster: raster file
- Output:
- a projection encoded as a WKT-compliant string.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
read_habitat_info
(habitats_csv_uri, habitats_directory_uri)¶ Extract the habitats information from the csv file and directory.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
rowcol_to_xy
(rows, cols, raster)¶ non-uri version of rowcol_to_xy_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
rowcol_to_xy_uri
(rows, cols, raster_uri)¶ converts row/col coordinates into x/y coordinates using raster_uri’s geotransform
- Inputs:
- -rows: integer scalar or numpy array of row coordinates -cols: integer scalar or numpy array of column coordinates -raster_uri: uri from where the geotransform is going to be extracted
Returns a tuple (X, Y) of scalars or numpy arrays of the projected coordinates
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_array_to_raster
(array, out_uri, base_uri, cell_size, no_data=None, default_nodata=0.0, gdal_type=<Mock id='140270534831696'>)¶ Save an array to a raster constructed from an AOI.
- Inputs:
- array: numpy array to be saved
- out_uri: output raster file URI.
- base_uri: URI to the AOI from which to construct the template raster
- cell_size: granularity of the rasterization in meters
- recompute_nodata: if True, recompute nodata to avoid interferece with existing raster data
- no_data: value of nodata used in the function. If None, revert to default_nodata.
- default_nodata: nodata used if no_data is set to none.
- Output:
- save the array in a raster file constructed from the AOI of granularity specified by cell_size
- Return the array uri.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_fetch_depths
(fetch, aoi_uri, cell_size, base_path, prefix)¶ Create dictionary of raster filenames of fetch F(n) for each sector n.
- Inputs:
- wind_data: wind data points adjusted to the aoi
- aoi: used to create the rasters for each sector
- cell_size: raster granularity in meters
- base_path: base path where the generated raster will be saved
- Output:
- A dictionary where keys are sector angles in degrees and values are raster filenames where F(n) is defined on each cell
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_fetch_distances
(fetch, aoi_uri, cell_size, base_path, prefix='')¶ Create dictionary of raster filenames of fetch F(n) for each sector n.
- Inputs:
- wind_data: wind data points adjusted to the aoi
- aoi: used to create the rasters for each sector
- cell_size: raster granularity in meters
- base_path: base path where the generated raster will be saved
Output: A list of raster URIs corresponding to sectors of increasing angles where data points encode the sector’s fetch distance for that point
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_fetch_to_outputs
(args)¶ Function that copies the fetch information (depth and distances) in the outputs directory.
- Inputs:
- args[‘fetch_distance_uris’]: A dictionary of (‘string’:string)
- entries where the first string is the sector in degrees, and the second string is a uri pointing to the file that contains the fetch distances for this sector.
- args[‘fetch_depths_uris’]: A dictionary similar to the depth one,
- but the second string is pointing to the file that contains fetch depths, not distances.
- args[‘prefix’]: String appended before the filenames. Currently
- used to follow Greg’s output labelling scheme.
- Outputs:
- data_uri that contains the uri of the new files in the outputs
- directory, one for fetch distance and one for fetch depths for each fetch direction ‘n’, for a total of 2n.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_local_wave_exposure_to_subdirectory
(args)¶ Copy local wave exposure to the outputs/ directory.
- Inputs:
- args[‘E_l’]: uri to the local wave exposure data args[‘prefix’]: prefix to be appended to the new filename
- Outputs:
- data_uri: dictionary containing the uri where the data is saved
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_oceanic_wave_exposure_to_subdirectory
(args)¶ Copy oceanic wave exposure to the outputs/ directory.
- Inputs:
- args[‘E_o’]: uri to the oceanic wave exposure data args[‘prefix’]: prefix to be appended to the new filename
- Outputs:
- data_uri: dictionary containing the uri where the data is saved
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_structure_to_subdirectory
(args)¶ Save structure data to its intermediate subdirectory, under a custom prefix.
- Inputs:
args[‘structure_edges’]: the data’s uri to save to /outputs args[‘prefix’]: prefix to add to the new filename. Currently used to
mirror the labeling of outputs in Greg’s notes.- Outputs:
- data_uri: a dictionary of the uri where the data has been saved.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
save_wind_generated_waves_to_subdirectory
(args)¶ Copy the wave height and wave period to the outputs/ directory.
- Inputs:
- args[‘wave_height’][sector]: uri to “sector“‘s wave height data args[‘wave_period’][sector]: uri to “sector“‘s wave period data args[‘prefix’]: prefix to be appended to the new filename
- Outputs:
- data_uri: dictionary containing the uri where the data is saved
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
set_H_threshold
(threshold)¶ Return 0 if fetch is strictly below a threshold in km, 1 otherwise.
- Inputs:
- fetch: fetch distance in meters.
Returns: 1 if fetch >= threshold (in km) 0 if fetch < threshold Note: conforms to equation 4.8 in the invest documentation.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
shapefile_wkt
(shapefile)¶ Return the projection of a shapefile in the OpenGIS WKT format.
- Input:
- raster: raster file
- Output:
- a projection encoded as a WKT-compliant string.
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
xy_to_rowcol
(x, y, raster)¶ non-uri version of xy_to_rowcol_uri
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_core.
xy_to_rowcol_uri
(x, y, raster_uri)¶ Does the opposite of rowcol_to_xy_uri
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing module¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing.
aggregate_csvs
(csv_list, out_uri)¶ Concatenate 3-row csv files created with tif2csv
- Inputs:
- csv_list: list of csv_uri strings
- Outputs:
- uri_output: the output uri of the concatenated csv
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing.
aggregate_tifs_from_directory
(path='.', mask=None)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing.
convert_tif_to_csv
(tif_uri, csv_uri=None, mask=None)¶ Converts a single band geo-tiff file to a csv text file
- Inputs:
- -tif_uri: the uri to the file to be converted -csv_uri: uri to the output file. The file should not exist.
- Outputs:
- -returns the ouput file uri
returns nothing
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing.
convert_tifs_to_csv
(tif_list, mask=None)¶
-
natcap.invest.coastal_vulnerability.coastal_vulnerability_post_processing.
execute
(args)¶