reVX.offshore.dist_to_ports.DistanceToPorts

class DistanceToPorts(ports, excl_fpath, input_dist_layer='dist_to_coast')[source]

Bases: object

Class to compute the least cost distance from offshore pixels to port locations. The distance to coast exclusion layer will be used to calculate least cost paths around land masses and other such obstructions. Produces the least cost distance from each offshore pixel to the nearest port. If a distance to port layer already exists it can be updated with the least cost distance to new ports.

NOTE: Computing the least cost distance is both memory and computationally intensive! One EAGLE a bigmem node was needed to run in parallel and a medium (178GB) memory node is needed to run in serial.

Parameters:
  • ports (str) – Path to shape, csv, or json file containing ports to compute least cost distance to

  • excl_fpath (str) – Path to exclusions .h5 file with distance to coast layer

  • input_dist_layer (str, optional) – Exclusions layer name with distance to coast, by default ‘dist_to_coast’

Methods

distance_to_ports(out_dir[, max_workers, ...])

Compute the least cost distance from each offshore pixel to the nearest port in km

lc_dist_to_port(cost_arr, port_idx, port_dist)

Compute the least cost dist from the port coordinates to all offshore coordinates in km

run(ports, excl_fpath, out_dir[, ...])

Compute the least cost distance from offshore pixels to port locations in km.

Attributes

cost_arr

Cost array, used to compute least cost distance to ports Offshore pixels have a value of 90 (pixel size), onshore pixels have a value of -1

ports

DataFrame of port locations

property ports

DataFrame of port locations

Returns:

DataFrame

property cost_arr

Cost array, used to compute least cost distance to ports Offshore pixels have a value of 90 (pixel size), onshore pixels have a value of -1

Returns:

ndarray

classmethod lc_dist_to_port(cost_arr, port_idx, port_dist, geotiff=None, profile=None)[source]

Compute the least cost dist from the port coordinates to all offshore coordinates in km

Parameters:
  • cost_arr (ndarray) – Cost array with offshore pixels set to 90 (pixel width) and onshore pixels set to -1.

  • port_idx (list | tuple | ndarray) – Port (row, col) index, used as starting point for least cost distance

  • port_dist (float) – Distance from port to pixel that corresponds to port_idx in meters

  • geotiff (str, optional) – Output geotiff file path to save least cost distance to ports, by default None

  • profile (dict, optional) – Profile (transform, crs, etc.) of cost array raster, needed to write distance to ports array to geotiff, by default None

Returns:

lc_dist (ndarray, optional) – Least cost distance from port to all offshore pixels in km

distance_to_ports(out_dir, max_workers=1, replace=False)[source]

Compute the least cost distance from each offshore pixel to the nearest port in km

Parameters:
  • out_dir (str) – Directory to save distance to port geotiffs too.

  • max_workers (int, optional) – Number of workers to use for setback computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None run in parallel on all available cores, by default 1

  • replace (bool, optional) – Flag to replace existing ports geotiffs, by default False

classmethod run(ports, excl_fpath, out_dir, input_dist_layer='dist_to_coast', max_workers=1, replace=False)[source]

Compute the least cost distance from offshore pixels to port locations in km. The distance to coast exclusion layer will be used to calculate least cost paths around land masses and other such obstructions. Produces the least cost distance from each offshore pixel to the nearest port. If a distance to port layer already exists it can be updated with the least cost distance to new ports.

Parameters:
  • ports (str) – Path to shape, csv, or json file containing ports to compute least cost distance to

  • excl_fpath (str) – Path to exclusions .h5 file with distance to coast layer. Will also be the file into which the least cost distance to port is saved.

  • out_dir (str) – Directory to save distance to port geotiffs too.

  • input_dist_layer (str, optional) – Exclusions layer with distance to coast values, by default ‘dist_to_coast’

  • max_workers (int, optional) – Number of workers to use for setback computation, if 1 run in serial, if > 1 run in parallel with that many workers, if None run in parallel on all available cores, by default 1

  • replace (bool, optional) – Flag to replace existing ports geotiffs, by default False