natcap.invest.recreation package

Submodules

natcap.invest.recreation.buffered_numpy_disk_map module

Buffered file manager module.

class natcap.invest.recreation.buffered_numpy_disk_map.BufferedNumpyDiskMap(manager_filename, max_bytes_to_buffer)

Bases: object

Persistent object to append and read numpy arrays to unique keys.

This object is abstractly a key/value pair map where the operations are to append, read, and delete numpy arrays associated with those keys. The object attempts to keep data in RAM as much as possible and saves data to files on disk to manage memory and persist between instantiations.

append(array_id, array_data)

Append data to the file.

Parameters:
  • array_id (int) – unique key to identify the array node
  • array_data (numpy.ndarray) – data to append to node.
Returns:

None

delete(array_id)

Delete node array_id from disk and cache.

flush()

Method to flush data in memory to disk.

read(array_id)

Read the entirety of the file.

Internally this might mean that part of the file is read from disk and the end from the buffer or any combination of those.

Parameters:array_id (string) – unique node id to read
Returns:contents of node as a numpy.ndarray.

natcap.invest.recreation.out_of_core_quadtree module

natcap.invest.recreation.recmodel_client module

InVEST Recreation Client.

natcap.invest.recreation.recmodel_client.delay_op(last_time, time_delay, func)

Execute func if last_time + time_delay >= current time.

Parameters:
  • last_time (float) – last time in seconds that func was triggered
  • time_delay (float) – time to wait in seconds since last_time before triggering func
  • func (function) – parameterless function to invoke if current_time >= last_time + time_delay
Returns:

If func was triggered, return the time which it was triggered in seconds, otherwise return last_time.

natcap.invest.recreation.recmodel_client.execute(args)

Recreation.

Execute recreation client model on remote server.

Parameters:
  • args['workspace_dir'] (string) – path to workspace directory
  • args['aoi_path'] (string) – path to AOI vector
  • args['hostname'] (string) – FQDN to recreation server
  • args['port'] (string or int) – port on hostname for recreation server
  • args['start_year'] (string) – start year in form YYYY. This year is the inclusive lower bound to consider points in the PUD and regression.
  • args['end_year'] (string) – end year in form YYYY. This year is the inclusive upper bound to consider points in the PUD and regression.
  • args['grid_aoi'] (boolean) – if true the polygon vector in args[‘aoi_path’] should be gridded into a new vector and the recreation model should be executed on that
  • args['grid_type'] (string) – optional, but must exist if args[‘grid_aoi’] is True. Is one of ‘hexagon’ or ‘square’ and indicates the style of gridding.
  • args['cell_size'] (string/float) – optional, but must exist if args[‘grid_aoi’] is True. Indicates the cell size of square pixels and the width of the horizontal axis for the hexagonal cells.
  • args['compute_regression'] (boolean) – if True, then process the predictor table and scenario table (if present).
  • args['predictor_table_path'] (string) –

    required if args[‘compute_regression’] is True. Path to a table that describes the regression predictors, their IDs and types. Must contain the fields ‘id’, ‘path’, and ‘type’ where:

    • ‘id’: is a <=10 character length ID that is used to uniquely describe the predictor. It will be added to the output result shapefile attribute table which is an ESRI Shapefile, thus limited to 10 characters.
    • ‘path’: an absolute or relative (to this table) path to the predictor dataset, either a vector or raster type.
    • ‘type’: one of the following,
      • ‘raster_mean’: mean of values in the raster under the response polygon
      • ‘raster_sum’: sum of values in the raster under the response polygon
      • ‘point_count’: count of the points contained in the response polygon
      • ‘point_nearest_distance’: distance to the nearest point from the response polygon
      • ‘line_intersect_length’: length of lines that intersect with the response polygon in projected units of AOI
      • ‘polygon_area’: area of the polygon contained within response polygon in projected units of AOI
  • args['scenario_predictor_table_path'] (string) – (optional) if present runs the scenario mode of the recreation model with the datasets described in the table on this path. Field headers are identical to args[‘predictor_table_path’] and ids in the table are required to be identical to the predictor list.
  • args['results_suffix'] (string) – optional, if exists is appended to any output file paths.
Returns:

None

natcap.invest.recreation.recmodel_server module

natcap.invest.recreation.recmodel_workspace_fetcher module

InVEST recreation workspace fetcher.

natcap.invest.recreation.recmodel_workspace_fetcher.execute(args)

Fetch workspace from remote server.

After the call a .zip file exists at args[‘workspace_dir’] named args[‘workspace_id’] + ‘.zip’ and contains the zipped workspace of that model run.

Parameters:
  • args['workspace_dir'] (string) – path to workspace directory
  • args['hostname'] (string) – FQDN to recreation server
  • args['port'] (string or int) – port on hostname for recreation server
  • args['workspace_id'] (string) – workspace identifier
Returns:

None

Module contents