natcap.invest.scenic_quality package

Submodules

natcap.invest.scenic_quality.grass_examples module

GRASS Python script examples.

class natcap.invest.scenic_quality.grass_examples.grasswrapper(dbBase='', location='', mapset='')
natcap.invest.scenic_quality.grass_examples.random_string(length)

natcap.invest.scenic_quality.los_sextante module

natcap.invest.scenic_quality.los_sextante.main()
natcap.invest.scenic_quality.los_sextante.run_script(iface)

this shall be called from Script Runner

natcap.invest.scenic_quality.scenic_quality module

natcap.invest.scenic_quality.scenic_quality.add_field_feature_set_uri(fs_uri, field_name, field_type)
natcap.invest.scenic_quality.scenic_quality.add_id_feature_set_uri(fs_uri, id_name)
natcap.invest.scenic_quality.scenic_quality.compute_viewshed(input_array, visibility_uri, in_structure_uri, cell_size, rows, cols, nodata, GT, I_uri, J_uri, curvature_correction, refr_coeff, args)

array-based function that computes the viewshed as is defined in ArcGIS

natcap.invest.scenic_quality.scenic_quality.compute_viewshed_uri(in_dem_uri, out_viewshed_uri, in_structure_uri, curvature_correction, refr_coeff, args)

Compute the viewshed as it is defined in ArcGIS where the inputs are:

-in_dem_uri: URI to input surface raster -out_viewshed_uri: URI to the output raster -in_structure_uri: URI to a point shapefile that contains the location of the observers and the viewshed radius in (negative) meters -curvature_correction: flag for the curvature of the earth. Either FLAT_EARTH or CURVED_EARTH. Not used yet. -refraction: refraction index between 0 (max effect) and 1 (no effect). Default is 0.13.

natcap.invest.scenic_quality.scenic_quality.execute(args)

Scenic Quality.

Warning

The Scenic Quality model is under active development and is currently unstable.

Parameters:
  • workspace_dir (string) – The selected folder is used as the workspace where all intermediate and output files will be written. If the selected folder does not exist, it will be created. If datasets already exist in the selected folder, they will be overwritten. (required)
  • aoi_uri (string) – An OGR-supported vector file. This AOI instructs the model where to clip the input data and the extent of analysis. Users will create a polygon feature layer that defines their area of interest. The AOI must intersect the Digital Elevation Model (DEM). (required)
  • cell_size (float) – Length (in meters) of each side of the (square) cell. (optional)
  • structure_uri (string) – An OGR-supported vector file. The user must specify a point feature layer that indicates locations of objects that contribute to negative scenic quality, such as aquaculture netpens or wave energy facilities. In order for the viewshed analysis to run correctly, the projection of this input must be consistent with the project of the DEM input. (required)
  • dem_uri (string) – A GDAL-supported raster file. An elevation raster layer is required to conduct viewshed analysis. Elevation data allows the model to determine areas within the AOI’s land-seascape where point features contributing to negative scenic quality are visible. (required)
  • refraction (float) – The earth curvature correction option corrects for the curvature of the earth and refraction of visible light in air. Changes in air density curve the light downward causing an observer to see further and the earth to appear less curved. While the magnitude of this effect varies with atmospheric conditions, a standard rule of thumb is that refraction of visible light reduces the apparent curvature of the earth by one-seventh. By default, this model corrects for the curvature of the earth and sets the refractivity coefficient to 0.13. (required)
  • pop_uri (string) – A GDAL-supported raster file. A population raster layer is required to determine population within the AOI’s land-seascape where point features contributing to negative scenic quality are visible and not visible. (optional)
  • overlap_uri (string) – An OGR-supported vector file. The user has the option of providing a polygon feature layer where they would like to determine the impact of objects on visual quality. This input must be a polygon and projected in meters. The model will use this layer to determine what percent of the total area of each polygon feature can see at least one of the point features impacting scenic quality.optional
  • valuation_function (string) – Either ‘polynomial’ or ‘logarithmic’. This field indicates the functional form f(x) the model will use to value the visual impact for each viewpoint. For distances less than 1 km (x<1), the model uses a linear form g(x) where the line passes through f(1) (i.e. g(1) == f(1)) and extends to zero with the same slope as f(1) (i.e. g’(x) == f’(1)). (optional)
  • a_coefficient (float) – First coefficient used either by the polynomial or by the logarithmic valuation function. (required)
  • b_coefficient (float) – Second coefficient used either by the polynomial or by the logarithmic valuation function. (required)
  • c_coefficient (float) – Third coefficient for the polynomial’s quadratic term. (required)
  • d_coefficient (float) – Fourth coefficient for the polynomial’s cubic exponent. (required)
  • max_valuation_radius (float) – Radius beyond which the valuation is set to zero. The valuation function ‘f’ cannot be negative at the radius ‘r’ (f(r)>=0). (required)
Returns:

None

natcap.invest.scenic_quality.scenic_quality.get_count_feature_set_uri(fs_uri)
natcap.invest.scenic_quality.scenic_quality.get_data_type_uri(ds_uri)
natcap.invest.scenic_quality.scenic_quality.old_reproject_dataset_uri(original_dataset_uri, *args, **kwargs)
A URI wrapper for reproject dataset that opens the original_dataset_uri
before passing it to reproject_dataset.

original_dataset_uri - a URI to a gdal Dataset on disk

All other arguments to reproject_dataset are passed in.

return - nothing

natcap.invest.scenic_quality.scenic_quality.reclassify_quantile_dataset_uri(dataset_uri, quantile_list, dataset_out_uri, datatype_out, nodata_out)
natcap.invest.scenic_quality.scenic_quality.reproject_dataset_uri(original_dataset_uri, output_wkt, output_uri, output_type=<Mock id='140449716199632'>)
A function to reproject and resample a GDAL dataset given an output pixel size
and output reference and uri.

original_dataset - a gdal Dataset to reproject pixel_spacing - output dataset pixel size in projected linear units (probably meters) output_wkt - output project in Well Known Text (the result of ds.GetProjection()) output_uri - location on disk to dump the reprojected dataset output_type - gdal type of the output

return projected dataset

natcap.invest.scenic_quality.scenic_quality.set_field_by_op_feature_set_uri(fs_uri, value_field_name, op)

natcap.invest.scenic_quality.scenic_quality_core module

natcap.invest.scenic_quality.scenic_quality_core.add_active_pixel(sweep_line, index, distance, visibility)

Add a pixel to the sweep line in O(n) using a linked_list of linked_cells.

natcap.invest.scenic_quality.scenic_quality_core.add_active_pixel_fast(sweep_line, skip_nodes, distance)

Insert an active pixel in the sweep_line and update the skip_nodes.

-sweep_line: a linked list of linked_cell as created by the
linked_cell_factory.
-skip_nodes: an array of linked lists that constitutes the hierarchy
of skip pointers in the skip list. Each cell is defined as ???

-distance: the value to be added to the sweep_line

Return a tuple (sweep_line, skip_nodes) with the updated sweep_line and skip_nodes

natcap.invest.scenic_quality.scenic_quality_core.cell_angles(cell_coords, viewpoint)

Compute angles between cells and viewpoint where 0 angle is right of viewpoint.

Inputs:
-cell_coords: coordinate tuple (rows, cols) as numpy.where() from which to compute the angles -viewpoint: tuple (row, col) indicating the position of the observer. Each of row and col is an integer.

Returns a sorted list of angles

alias of cell_link

natcap.invest.scenic_quality.scenic_quality_core.compute_viewshed(input_array, nodata, coordinates, obs_elev, tgt_elev, max_dist, cell_size, refraction_coeff, alg_version)

Compute the viewshed for a single observer. Inputs:

-input_array: a numpy array of terrain elevations -nodata: input_array’s nodata value -coordinates: tuple (east, north) of coordinates of viewing

position

-obs_elev: observer elevation above the raster map. -tgt_elev: offset for target elevation above the ground. Applied to

every point on the raster

-max_dist: maximum visibility radius. By default infinity (-1), -cell_size: cell size in meters (integer) -refraction_coeff: refraction coefficient (0.0-1.0), not used yet -alg_version: name of the algorithm to be used. Either ‘cython’ (default) or ‘python’.

Returns the visibility map for the DEM as a numpy array

natcap.invest.scenic_quality.scenic_quality_core.execute(args)

Entry point for scenic quality core computation.

Inputs:

Returns

natcap.invest.scenic_quality.scenic_quality_core.find_active_pixel(sweep_line, distance)

Find an active pixel based on distance. Return None if can’t be found

natcap.invest.scenic_quality.scenic_quality_core.find_active_pixel_fast(sweep_line, skip_nodes, distance)

Find an active pixel based on distance.

Inputs:
-sweep_line: a linked list of linked_cell as created by the
linked_cell_factory.
-skip_list: an array of linked lists that constitutes the hierarchy
of skip pointers in the skip list. Each cell is defined as ???

-distance: the key used to search the sweep_line

Return the linked_cell associated to ‘distance’, or None if such cell doesn’t exist

natcap.invest.scenic_quality.scenic_quality_core.find_pixel_before_fast(sweep_line, skip_nodes, distance)

Find the active pixel before the one with distance.

Inputs:
-sweep_line: a linked list of linked_cell as created by the
linked_cell_factory.
-skip_list: an array of linked lists that constitutes the hierarchy
of skip pointers in the skip list. Each cell is defined as ???

-distance: the key used to search the sweep_line

Return a tuple (pixel, hierarchy) where:
-pixel is the linked_cell right before ‘distance’, or None if it doesn’t exist (either ‘distance’ is the first cell, or the sweep_line is empty). -hierarchy is the list of intermediate skip nodes starting from the bottom node right above the active pixel up to the top node.
natcap.invest.scenic_quality.scenic_quality_core.get_perimeter_cells(array_shape, viewpoint, max_dist=-1)

Compute cells along the perimeter of an array.

Inputs:
-array_shape: tuple (row, col) as ndarray.shape containing the size of the array from which to compute the perimeter -viewpoint: tuple (row, col) indicating the position of the observer -max_dist: maximum distance in pixels from the center of the array. Negative values are ignored (same effect as infinite distance).

Returns a tuple (rows, cols) of the cell rows and columns following the convention of numpy.where() where the first cell is immediately right to the viewpoint, and the others are enumerated clockwise.

natcap.invest.scenic_quality.scenic_quality_core.hierarchy_is_consistent(pixel, hierarchy, skip_nodes)

Makes simple tests to ensure the the hierarchy is consistent

natcap.invest.scenic_quality.scenic_quality_core.linked_cell_factory

alias of linked_cell

natcap.invest.scenic_quality.scenic_quality_core.list_extreme_cell_angles(array_shape, viewpoint_coords, max_dist)

List the minimum and maximum angles spanned by each cell of a rectangular raster if scanned by a sweep line centered on viewpoint_coords.

Inputs:
-array_shape: a shape tuple (rows, cols) as is created from
calling numpy.ndarray.shape()

-viewpoint_coords: a 2-tuple of coordinates similar to array_shape where the sweep line originates -max_dist: maximum viewing distance

returns a tuple (min, center, max, I, J) with min, center and max Nx1 numpy arrays of each raster cell’s minimum, center, and maximum angles and coords as two Nx1 numpy arrays of row and column of the coordinate of each point.

natcap.invest.scenic_quality.scenic_quality_core.print_hierarchy(hierarchy)
natcap.invest.scenic_quality.scenic_quality_core.print_node(node)

Printing a node by displaying its ‘distance’ and ‘next’ fields

natcap.invest.scenic_quality.scenic_quality_core.print_skip_list(sweep_line, skip_nodes)
natcap.invest.scenic_quality.scenic_quality_core.print_sweep_line(sweep_line)
natcap.invest.scenic_quality.scenic_quality_core.remove_active_pixel(sweep_line, distance)

Remove a pixel based on distance. Do nothing if can’t be found.

natcap.invest.scenic_quality.scenic_quality_core.skip_list_is_consistent(linked_list, skip_nodes)

Function that checks for skip list inconsistencies.

Inputs:
-sweep_line: the container proper which is a dictionary
implementing a linked list that contains the items ordered in increasing distance
-skip_nodes: python dict that is the hierarchical structure
that sitting on top of the sweep_line to allow O(log n) operations.
Returns a tuple (is_consistent, message) where is_consistent is
True if list is consistent, False otherwise. If is_consistent is False, the string ‘message’ explains the cause
natcap.invest.scenic_quality.scenic_quality_core.sweep_through_angles(angles, add_events, center_events, remove_events, I, J, distances, visibility, visibility_map)

Update the active pixels as the algorithm consumes the sweep angles

natcap.invest.scenic_quality.scenic_quality_core.update_visible_pixels(active_pixels, I, J, visibility_map)

Update the array of visible pixels from the active pixel’s visibility

Inputs:

-active_pixels: a linked list of dictionaries containing the following fields:

-distance: distance between pixel center and viewpoint -visibility: an elevation/distance ratio used by the algorithm to determine what pixels are bostructed -index: pixel index in the event stream, used to find the pixel’s coordinates ‘i’ and ‘j’. -next: points to the next pixel, or is None if at the end

The linked list is implemented with a dictionary where the pixels distance is the key. The closest pixel is also referenced by the key ‘closest’. -I: the array of pixel rows indexable by pixel[‘index’] -J: the array of pixel columns indexable by pixel[‘index’] -visibility_map: a python array the same size as the DEM with 1s for visible pixels and 0s otherwise. Viewpoint is always visible.

Returns nothing

natcap.invest.scenic_quality.scenic_quality_core.viewshed(input_array, cell_size, array_shape, nodata, output_uri, coordinates, obs_elev=1.75, tgt_elev=0.0, max_dist=-1.0, refraction_coeff=None, alg_version='cython')

URI wrapper for the viewshed computation function

Inputs:

-input_array: numpy array of the elevation raster map -cell_size: raster cell size in meters -array_shape: input_array_shape as returned from ndarray.shape() -nodata: input_array’s raster nodata value -output_uri: output raster uri, compatible with input_array’s size -coordinates: tuple (east, north) of coordinates of viewing

position

-obs_elev: observer elevation above the raster map. -tgt_elev: offset for target elevation above the ground. Applied to

every point on the raster

-max_dist: maximum visibility radius. By default infinity (-1), -refraction_coeff: refraction coefficient (0.0-1.0), not used yet -alg_version: name of the algorithm to be used. Either ‘cython’ (default) or ‘python’.

Returns nothing

natcap.invest.scenic_quality.scenic_quality_cython_core module

natcap.invest.scenic_quality.viewshed_grass module

natcap.invest.scenic_quality.viewshed_grass.execute(args)
class natcap.invest.scenic_quality.viewshed_grass.grasswrapper(dbBase='', location='/home/mlacayo/workspace/newLocation', mapset='PERMANENT')
natcap.invest.scenic_quality.viewshed_grass.project_cleanup()
natcap.invest.scenic_quality.viewshed_grass.project_setup(dataset_uri)
natcap.invest.scenic_quality.viewshed_grass.viewshed(dataset_uri, feature_set_uri, dataset_out_uri)

natcap.invest.scenic_quality.viewshed_sextante module

natcap.invest.scenic_quality.viewshed_sextante.viewshed(input_uri, output_uri, coordinates, obs_elev=1.75, tgt_elev=0.0, max_dist=-1, refraction_coeff=0.14286, memory=500, stream_dir=None, consider_curvature=False, consider_refraction=False, boolean_mode=False, elevation_mode=False, verbose=False, quiet=False)

http://grass.osgeo.org/grass70/manuals/r.viewshed.html

Module contents