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

A hierarchical spatial index for fast culling of points in 2D space.

class natcap.invest.recreation.out_of_core_quadtree.OutOfCoreQuadTree

Bases: object

An out of core quad tree spatial indexing structure.

add_points()

Add a list of points to the current node.

This function will split the current node if the added points exceed the maximum number of points allowed per node and is already not at the maximum level.

Parameters:
  • point_list (numpy.ndarray) – a numpy array of (data, x_coord, y_coord) tuples
  • left_bound (int) – left index inclusive of points to consider under point_list
  • right_bound (int) – right index non-inclusive of points to consider under point_list
Returns:

None

build_node_shapes()

Add features to an ogr.Layer to visualize quadtree segmentation.

Parameters:ogr_polygon_layer (ogr.layer) – an ogr polygon layer with fields ‘n_points’ (int) and ‘bb_box’ (string) defined.
Returns:None
flush()

Flush any cached data to disk.

get_intersecting_points_in_bounding_box()

Get list of data that is contained by bounding_box.

This function takes in a bounding box and returns a list of (data, lat, lng) tuples that are contained in the leaf nodes that intersect that bounding box.

Parameters:bounding_box (list) – of the form [xmin, ymin, xmax, ymax]
Returns:numpy.ndarray array of (data, x_coord, lng) of nodes that intersect the bounding box.
get_intersecting_points_in_polygon()

Return the points contained in shapely_prepared_polygon.

This function is a high performance test routine to return the points contained in the shapely_prepared_polygon that are stored in self‘s representation of a quadtree.

Parameters:shapely_polygon (ogr.DataSource) – a polygon datasource to bound against
Returns:deque of (data, x_coord, y_coord) of nodes that are contained in shapely_prepared_polygon.
n_nodes()

Return the number of nodes in the quadtree

n_points()

Return the number of nodes in the quadtree

next_available_blob_id = 0

natcap.invest.recreation.recmodel_client module

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