Recreation Package¶

Model Entry Point¶

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

Recreation Server¶

InVEST Recreation Server.

class natcap.invest.recreation.recmodel_server.RecModel(*args, **kwargs)

Bases: object

Class that manages RPCs for calculating photo user days.

calc_photo_user_days_in_aoi(*args, **kwargs)

General purpose try/except wrapper.

fetch_workspace_aoi(*args, **kwargs)

General purpose try/except wrapper.

get_valid_year_range()

Return the min and max year queriable.

Returns: (min_year, max_year)
get_version()

Return the rec model server version.

This string can be used to uniquely identify the PUD database and algorithm for publication in terms of reproducibility.

natcap.invest.recreation.recmodel_server.build_quadtree_shape(quad_tree_shapefile_path, quadtree, spatial_reference)

Generate a vector of the quadtree geometry.

natcap.invest.recreation.recmodel_server.construct_userday_quadtree(initial_bounding_box, raw_photo_csv_table, cache_dir, max_points_per_node)

Construct a spatial quadtree for fast querying of userday points.

Parameters: initial_bounding_box (list of int) – () (raw_photo_csv_table) – cache_dir (string) – path to a directory that can be used to cache the quadtree files on disk max_points_per_node (int) – maximum number of points to allow per node of the quadree. A larger amount will cause the quadtree to subdivide. None
natcap.invest.recreation.recmodel_server.execute(args)

Launch recreation server and parse/generate quadtree if necessary.

A call to this function registers a Pyro RPC RecModel entry point given the configuration input parameters described below.

There are many methods to launch a server, including at a Linux command line as shown:

nohup python -u -c “import natcap.invest.recreation.recmodel_server;
args={‘hostname’:’$LOCALIP’, ‘port’:$REC_SERVER_PORT, ‘raw_csv_point_data_path’: $POINT_DATA_PATH, ‘max_year’:$MAX_YEAR, ‘min_year’: $MIN_YEAR, ‘cache_workspace’:$CACHE_WORKSPACE_PATH’};

natcap.invest.recreation.recmodel_server.execute(args)”

Parameters: args['raw_csv_point_data_path'] (string) – path to a csv file of the format args['hostname'] (string) – hostname to host Pyro server. args['port'] (int/or string representation of int) – port number to host Pyro entry point. args['max_year'] (int) – maximum year allowed to be queries by user args['min_year'] (int) – minimum valid year allowed to be queried by user Never returns

Recreation Client¶

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

Recreation Workspace Fetcher¶

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 None