Coastal Protection Package

Coastal Vulnerability

invest_natcap.coastal_vulnerability.coastal_vulnerability.execute(args)

Entry point for coastal vulnerability

#:RICH: describe what args should be

args[‘foo’] - description of what this key is

returns nothing

Coastal Vulnerability Core

Coastal vulnerability model core functions

invest_natcap.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.

invest_natcap.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

invest_natcap.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
invest_natcap.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

invest_natcap.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
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.aggregate_tifs_from_directory(path='.', mask=None)
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.aggregate_tifs_from_list(uri_list, path, mask=None)
invest_natcap.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.

invest_natcap.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.

invest_natcap.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

invest_natcap.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.
invest_natcap.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.

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_coastal_exposure(args)
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_coastal_exposure_no_habitats(args)
invest_natcap.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.
invest_natcap.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.
invest_natcap.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.
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_erosion_exposure(args)
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_fetch(land_array, rays_per_sector, d_max, cell_size, shore_points, bathymetry, bathymetry_nodata, GT, shore_raster)
invest_natcap.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.
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_geomorphology(args)

Compute the geomorphology index as is described in InVEST’s user guide.

Inputs:
-args[‘geomorphology’]: shapefile of the gemorphology ranking
along the coastline.

-args[‘aoi_uri’]: uri to the region of interest (shapefile). -args[‘shore_raster_uri’]: uri to a the shoreline dataset

(land = 1, sea = 0).

-args[‘cell_size’]: integer cell size of in meters. -args[‘spread_radius’]: integer value of the area over which to

spread (smear) the coastline. If the coastline from the geomorphology 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[‘intermediate_directory’]: uri to the directory where intermediate files are stored
Output:
  • data_uri: a dictionary of all the intermediate file URIs.
Detailed output:
  • aoi_reprojected_morphology.shp: the original geomorphology data

    reprojected to the AOI’s projection.

  • geomorphology_rank.tif: the shore ranking as stored in the

    shapefile, rasterized within the aoi using cell_size.

  • spread_rank.tif: shore ranking smoothen by convolution of

    geomorphology_rank.

  • geomorphology_coast.tif: rasterized coast (encoded as 1s)

    extracted from geomorphology data.

  • spread_coast.tif: smoothed shore obtained by convolution of

    geomorphology_coast. Can’t be used as is as a quotient in a division (see normalized_spread_rank), because of 0 values.

  • adjusted_spread_coast.tif: same as spread_coast.tif, where areas

    with zeros set to one to avoid division-by-zero as a quotient.

  • available_coastal_data.tif: coastal information that is available

    given the data.

  • missing_coastal_data.tif: portions of the shore for which rank

    information isn’t available from the data.

  • normalized_spread_rank.tif: raster file of

    spread_rank / spread_coast. The result is floating point values between 1 to 5. To be integer, they need to be approximated.

  • approximated_spread_rank.tif: approximation of normalized_spread_rank to be integers between 1 and 5.

  • geomorphology.tif: combination of rank information from normalized_spread_rank, completed with missing coastal information (from missing_coastal data) set to a moderate level of 3.

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_habitat_role(args)
invest_natcap.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.

invest_natcap.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
invest_natcap.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.

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.compute_segment_exposure(args)

Compute exposed and sheltered shoreline segment map.

invest_natcap.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.
invest_natcap.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.
invest_natcap.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.
invest_natcap.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).
invest_natcap.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

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.convert_tifs_to_csv(tif_list, mask=None)
invest_natcap.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.

invest_natcap.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.

invest_natcap.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.

invest_natcap.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.

invest_natcap.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

invest_natcap.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)
invest_natcap.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.

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.generate_HTML_page(args)

Copy local wave exposure to the outputs/ directory.

Inputs:
args[‘coastal_exposure’]: uri to the coastal exposure data args[‘coastal_population’]: uri to the coastal population data args[‘pop_density’]: uri to the population density data args[‘prefix’]: prefix to be appended to the new filename args[‘intermediate_directory’]: directory where to save the data args[‘outputs_directory’]: directory where to save the data
Outputs:
data_uri: dictionary containing the uri where the data is savedi, which includes the three histograms and the HTML file itself.
invest_natcap.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.

invest_natcap.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.
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.has_field(field_name, shapefile, case_sensitive=True)
invest_natcap.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
invest_natcap.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
invest_natcap.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

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.preprocess_inputs(args)
invest_natcap.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

invest_natcap.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

invest_natcap.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.
invest_natcap.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 bins

Returns the bin boundaries ready to be used by numpy.digitize

invest_natcap.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]).

invest_natcap.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=6)

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
invest_natcap.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.
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.read_habitat_info(habitats_csv_uri, habitats_directory_uri)

Extract the habitats information from the csv file and directory.

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.rowcol_to_xy(rows, cols, raster)

non-uri version of rowcol_to_xy_uri

invest_natcap.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

invest_natcap.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=6)

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.
invest_natcap.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
invest_natcap.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

invest_natcap.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.

invest_natcap.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
invest_natcap.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
invest_natcap.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.
invest_natcap.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
invest_natcap.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.

invest_natcap.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.
invest_natcap.coastal_vulnerability.coastal_vulnerability_core.xy_to_rowcol(x, y, raster)

non-uri version of xy_to_rowcol_uri

invest_natcap.coastal_vulnerability.coastal_vulnerability_core.xy_to_rowcol_uri(x, y, raster_uri)

Does the opposite of rowcol_to_xy_uri

Coastal Vulnerability Cython Core

Coastal Vulnerability Post Processing

invest_natcap.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
invest_natcap.coastal_vulnerability.coastal_vulnerability_post_processing.aggregate_tifs_from_directory(path='.', mask=None)
invest_natcap.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

invest_natcap.coastal_vulnerability.coastal_vulnerability_post_processing.convert_tifs_to_csv(tif_list, mask=None)
invest_natcap.coastal_vulnerability.coastal_vulnerability_post_processing.execute(args)

Module contents