Overlap Analysis Package

Overlap Analysis

Invest overlap analysis filehandler for data passed in through UI

natcap.invest.overlap_analysis.overlap_analysis.create_hubs_raster(hubs_shape_uri, decay, aoi_raster_uri, hubs_out_uri)

This will create a rasterized version of the hubs shapefile where each pixel on the raster will be set accourding to the decay function from the point values themselves. We will rasterize the shapefile so that all land is 0, and nodata is the distance from the closest point.

Input:
hubs_shape_uri - Open point shapefile containing the hub locations
as points.
decay - Double representing the rate at which the hub importance
depreciates relative to the distance from the location.
aoi_raster_uri - The URI to the area interest raster on which we
want to base our new hubs raster.
hubs_out_uri - The URI location at which the new hubs raster should
be placed.
Output:
This creates a raster within hubs_out_uri whose data will be a function of the decay around points provided from hubs shape.

Returns nothing.

natcap.invest.overlap_analysis.overlap_analysis.create_unweighted_raster(output_dir, aoi_raster_uri, raster_files_uri)

This will create the set of unweighted rasters- both the AOI and individual rasterizations of the activity layers. These will all be combined to output a final raster displaying unweighted activity frequency within the area of interest.

Input:
output_dir- This is the directory in which the final frequency raster
will be placed. That file will be named ‘hu_freq.tif’.
aoi_raster_uri- The uri to the rasterized version of the AOI file
passed in with args[‘zone_layer_file’]. We will use this within the combination function to determine where to place nodata values.
raster_files_uri - The uris to the rasterized version of the files
passed in through args[‘over_layer_dict’]. Each raster file shows the presence or absence of the activity that it represents.
Output:
A raster file named [‘workspace_dir’]/output/hu_freq.tif. This depicts the unweighted frequency of activity within a gridded area or management zone.

Returns nothing.

natcap.invest.overlap_analysis.overlap_analysis.create_weighted_raster(out_dir, intermediate_dir, aoi_raster_uri, inter_weights_dict, layers_dict, intra_name, do_inter, do_intra, do_hubs, hubs_raster_uri, raster_uris, raster_names)

This function will create an output raster that takes into account both inter-activity weighting and intra-activity weighting. This will produce a map that looks both at where activities are occurring, and how much people value those activities and areas.

Input:
out_dir- This is the directory into which our completed raster file
should be placed when completed.
intermediate_dir- The directory in which the weighted raster files can
be stored.
inter_weights_dict- The dictionary that holds the mappings from layer
names to the inter-activity weights passed in by CSV. The dictionary key is the string name of each shapefile, minus the .shp extension. This ID maps to a double representing ther inter-activity weight of each activity layer.
layers_dict- This dictionary contains all the activity layers that are
included in the particular model run. This maps the name of the shapefile (excluding the .shp extension) to the open datasource itself.
intra_name- A string which represents the desired field name in our
shapefiles. This field should contain the intra-activity weight for that particular shape.
do_inter- A boolean that indicates whether inter-activity weighting is
desired.
do_intra- A boolean that indicates whether intra-activity weighting is
desired.
aoi_raster_uri - The uri to the dataset for our Area Of Interest.
This will be the base map for all following datasets.
raster_uris - A list of uris to the open unweighted raster files
created by make_indiv_rasters that begins with the AOI raster. This will be used when intra-activity weighting is not desired.
raster_names- A list of file names that goes along with the unweighted
raster files. These strings can be used as keys to the other ID-based dictionaries, and will be in the same order as the ‘raster_files’ list.
Output:
weighted_raster- A raster file output that takes into account both
inter-activity weights and intra-activity weights.

Returns nothing.

natcap.invest.overlap_analysis.overlap_analysis.execute(args)

Overlap Analysis.

This function will take care of preparing files passed into the overlap analysis model. It will handle all files/inputs associated with calculations and manipulations. It may write log, warning, or error messages to stdout.

Parameters:
  • args – A python dictionary created by the UI and passed to this method. It will contain the following data.
  • args['workspace_dir'] (string) – The directory in which to place all resulting files, will come in as a string. (required)
  • args['zone_layer_uri'] (string) – A URI pointing to a shapefile with the analysis zones on it. (required)
  • args['grid_size'] (int) – This is an int specifying how large the gridded squares over the shapefile should be. (required)
  • args['overlap_data_dir_uri'] (string) – URI pointing to a directory where multiple shapefiles are located. Each shapefile represents an activity of interest for the model. (required)
  • args['do-inter'] (bool) – Boolean that indicates whether or not inter-activity weighting is desired. This will decide if the overlap table will be created. (required)
  • args['do_intra'] (bool) – Boolean which indicates whether or not intra-activity weighting is desired. This will will pull attributes from shapefiles passed in in ‘zone_layer_uri’. (required)
  • args['do_hubs'] (bool) – Boolean which indicates if human use hubs are desired. (required)
  • args['overlap_layer_tbl'] (string) – URI to a CSV file that holds relational data and identifier data for all layers being passed in within the overlap analysis directory. (optional)
  • args['intra_name'] (string) – string which corresponds to a field within the layers being passed in within overlap analysis directory. This is the intra-activity importance for each activity. (optional)
  • args['hubs_uri'] (string) – The location of the shapefile containing points for human use hub calculations. (optional)
  • args['decay_amt'] (float) – A double representing the decay rate of value from the human use hubs. (optional)
Returns:

None

natcap.invest.overlap_analysis.overlap_analysis.format_over_table(over_tbl)

This CSV file contains a string which can be used to uniquely identify a .shp file to which the values in that string’s row will correspond. This string, therefore, should be used as the key for the ovlap_analysis dictionary, so that we can get all corresponding values for a shapefile at once by knowing its name.

Input:
over_tbl- A CSV that contains a list of each interest shapefile,
and the inter activity weights corresponding to those layers.
Returns:
over_dict- The analysis layer dictionary that maps the unique name
of each layer to the optional parameter of inter-activity weight. For each entry, the key will be the string name of the layer that it represents, and the value will be the inter-activity weight for that layer.
natcap.invest.overlap_analysis.overlap_analysis.make_indiv_rasters(out_dir, overlap_shape_uris, aoi_raster_uri)

This will pluck each of the files out of the dictionary and create a new raster file out of them. The new file will be named the same as the original shapefile, but with a .tif extension, and will be placed in the intermediate directory that is being passed in as a parameter.

Input:
out_dir- This is the directory into which our completed raster files
should be placed when completed.
overlap_shape_uris- This is a dictionary containing all of the open
shapefiles which need to be rasterized. The key for this dictionary is the name of the file itself, minus the .shp extension. This key maps to the open shapefile of that name.
aoi_raster_uri- The dataset for our AOI. This will be the base map for
all following datasets.
Returns:
raster_files- This is a list of the datasets that we want to sum. The
first will ALWAYS be the AOI dataset, and the rest will be the variable number of other datasets that we want to sum.
raster_names- This is a list of layer names that corresponds to the
files in ‘raster_files’. The first layer is guaranteed to be the AOI, but all names after that will be in the same order as the files so that it can be used for indexing later.
natcap.invest.overlap_analysis.overlap_analysis.make_indiv_weight_rasters(input_dir, aoi_raster_uri, layers_dict, intra_name)

This is a helper function for create_weighted_raster, which abstracts some of the work for getting the intra-activity weights per pixel to a separate function. This function will take in a list of the activities layers, and using the aoi_raster as a base for the tranformation, will rasterize the shapefile layers into rasters where the burn value is based on a per-pixel intra-activity weight (specified in each polygon on the layer). This function will return a tuple of two lists- the first is a list of the rasterized shapefiles, starting with the aoi. The second is a list of the shapefile names (minus the extension) in the same order as they were added to the first list. This will be used to reference the dictionaries containing the rest of the weighting information for the final weighted raster calculation.

Input:
input_dir: The directory into which the weighted rasters should be
placed.
aoi_raster_uri: The uri to the rasterized version of the area of
interest. This will be used as a basis for all following rasterizations.
layers_dict: A dictionary of all shapefiles to be rasterized. The key
is the name of the original file, minus the file extension. The value is an open shapefile datasource.
intra_name: The string corresponding to the value we wish to pull out
of the shapefile layer. This is an attribute of all polygons corresponding to the intra-activity weight of a given shape.
Returns:
A list of raster versions of the original
activity shapefiles. The first file will ALWAYS be the AOI, followed by the rasterized layers.
weighted_names: A list of the filenames minus extensions, of the
rasterized files in weighted_raster_files. These can be used to reference properties of the raster files that are located in other dictionaries.
Return type:weighted_raster_files

Overlap Analysis Core

Core module for both overlap analysis and management zones. This function can be used by either of the secondary modules within the OA model.

natcap.invest.overlap_analysis.overlap_core.get_files_dict(folder)

Returns a dictionary of all .shp files in the folder.

Input:
folder- The location of all layer files. Among these, there should
be files with the extension .shp. These will be used for all activity calculations.
Returns:
file_dict- A dictionary which maps the name (minus file extension)
of a shapefile to the open datasource itself. The key in this dictionary is the name of the file (not including file path or extension), and the value is the open shapefile.
natcap.invest.overlap_analysis.overlap_core.listdir(path)

A replacement for the standar os.listdir which, instead of returning only the filename, will include the entire path. This will use os as a base, then just lambda transform the whole list.

Input:
path- The location container from which we want to gather all files.
Returns:A list of full URIs contained within ‘path’.

Overlap Analysis Management Zone

This is the preperatory class for the management zone portion of overlap analysis.

natcap.invest.overlap_analysis.overlap_analysis_mz.execute(args)

Overlap Analysis: Management Zones.

Parameters:
  • args – A python dictionary created by the UI and passed to this method. It will contain the following data.
  • args['workspace_dir'] (string) – The directory in which to place all resulting files, will come in as a string. (required)
  • args['zone_layer_loc'] (string) – A URI pointing to a shapefile with the analysis zones on it. (required)
  • args['overlap_data_dir_loc'] (string) – URI pointing to a directory where multiple shapefiles are located. Each shapefile represents an activity of interest for the model. (required)
Returns:

None

Overlap Analysis Management Zone Core

This is the core module for the management zone analysis portion of the Overlap Analysis model.

natcap.invest.overlap_analysis.overlap_analysis_mz_core.execute(args)

This is the core module for the management zone model, which was extracted from the overlap analysis model. This particular one will take in a shapefile conatining a series of AOI’s, and a folder containing activity layers, and will return a modified shapefile of AOI’s, each of which will have an attribute stating how many activities take place within that polygon.

Input:
args[‘workspace_dir’]- The folder location into which we can write an
Output or Intermediate folder as necessary, and where the final shapefile will be placed.
args[‘zone_layer_file’]- An open shapefile which contains our
management zone polygons. It should be noted that this should not be edited directly but instead, should have a copy made in order to add the attribute field.
args[‘over_layer_dict’] - A dictionary which maps the name of the
shapefile (excluding the .shp extension) to the open datasource itself. These files are each an activity layer that will be counted within the totals per management zone.
Output:
A file named [workspace_dir]/Ouput/mz_frequency.shp which is a copy of args[‘zone_layer_file’] with the added attribute “ACTIV_CNT” that will total the number of activities taking place in each polygon.

Returns nothing.

Module contents