# Scenic Quality Package¶

## Model Entry Point¶

invest_natcap.scenic_quality.scenic_quality.execute(args)

DOCSTRING

## Scenic Quality¶

invest_natcap.scenic_quality.scenic_quality.add_field_feature_set_uri(fs_uri, field_name, field_type)
invest_natcap.scenic_quality.scenic_quality.add_id_feature_set_uri(fs_uri, id_name)
invest_natcap.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

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

invest_natcap.scenic_quality.scenic_quality.execute(args)

DOCSTRING

invest_natcap.scenic_quality.scenic_quality.get_count_feature_set_uri(fs_uri)
invest_natcap.scenic_quality.scenic_quality.get_data_type_uri(ds_uri)
invest_natcap.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

invest_natcap.scenic_quality.scenic_quality.reclassify_quantile_dataset_uri(dataset_uri, quantile_list, dataset_out_uri, datatype_out, nodata_out)
invest_natcap.scenic_quality.scenic_quality.reproject_dataset_uri(original_dataset_uri, output_wkt, output_uri, output_type=6)
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

invest_natcap.scenic_quality.scenic_quality.set_field_by_op_feature_set_uri(fs_uri, value_field_name, op)

## Scenic Quality Core¶

invest_natcap.scenic_quality.scenic_quality_core.add_active_pixel(sweep_line, index, distance, visibility)

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

-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

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

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

invest_natcap.scenic_quality.scenic_quality_core.execute(args)

Entry point for scenic quality core computation.

Inputs:

Returns

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

invest_natcap.scenic_quality.scenic_quality_core.find_active_pixel_fast(sweep_line, skip_nodes, distance)

Find an active pixel based on distance.

Inputs:
-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

invest_natcap.scenic_quality.scenic_quality_core.find_pixel_before_fast(sweep_line, skip_nodes, distance)

Find the active pixel before the one with distance.

Inputs:
-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.
invest_natcap.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.

invest_natcap.scenic_quality.scenic_quality_core.hierarchy_is_consistent(pixel, hierarchy, skip_nodes)

Makes simple tests to ensure the the hierarchy is consistent

invest_natcap.scenic_quality.scenic_quality_core.linked_cell_factory

alias of linked_cell

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

invest_natcap.scenic_quality.scenic_quality_core.print_hierarchy(hierarchy)
invest_natcap.scenic_quality.scenic_quality_core.print_node(node)

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

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

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

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

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

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

## Viewshed Sextante¶

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