reVX.least_cost_xmission.trans_cap_costs.TieLineCosts
- class TieLineCosts(cost_fpath, start_indices, cost_layers, row_slice, col_slice, xmission_config=None, tb_layer_name='transmission_barrier', barrier_mult=100, length_invariant_cost_layers=None, tracked_layers=None, cell_size=90)[source]
Bases:
object
Compute Least Cost Tie-line cost from start location to desired end locations
- Parameters:
cost_fpath (str) – Full path to HDF5 file containing cost arrays. The cost data layers should be named
"tie_line_costs_{capacity}MW"
, wherecapacity
is an integer value representing the capacity of the line (the integer values must matches at least one of the integer capacity values represented by the keys in thepower_classes
portion of the transmission config).start_indices (tuple) – Tuple of (row_idx, col_idx) in the clipped cost array (see row_slice and col_slice definitions below) indicating the start position of all paths to compute (typically, this is the centroid of the supply curve cell). Paths will be computed from this start location to each of the
end_indices
, which are also locations in the cost array (typically transmission feature locations).cost_layers (List[str]) – List of layers in H5 that are summed to determine total costs raster used for routing. Costs and distances for each individual layer are also reported (e.g. wet and dry costs). deteremining path using main cost layer.
row_slice, col_slice (slice) – Slices into the cost raster array used to clip the area that should be considered when computing a least cost path. This can be used to limit the consideration space and speed up computation. Note that the start and end indices must be given w.r.t. the cost raster that is “clipped” using these slices.
xmission_config (str | dict | XmissionConfig, optional) – Path to transmission config JSON files, dictionary of transmission config JSONs, or preloaded XmissionConfig objects. If
None
, the default config is used. By default,None
.tb_layer_name (str, default=:obj:BARRIER_H5_LAYER_NAME) – Name of transmission barrier layer in cost_fpath file. This layer defines the multipliers applied to the cost layer to determine LCP routing (but does not actually affect output costs). By default,
BARRIER_H5_LAYER_NAME
.barrier_mult (int, optional) – Multiplier applied to the cost data to create transmission barrier costs. By default,
100
.length_invariant_cost_layers (List[str] | None, optional) – List of layers in H5 to be added to the cost raster. The costs specified by these layers are not scaled with distance traversed across the cell (i.e. fixed one-time costs for crossing these cells).
tracked_layers (dict, optional) – Dictionary mapping layer names to strings, where the strings are numpy methods that should be applied to the layer along the LCP. For example,
tracked_layers={'layer_1': 'mean', 'layer_2': 'max}
would report the average oflayer_1
values along the least cost path and the max oflayer_2
values along the least cost path. Examples of numpy methods (non-exhaustive):mean
max
min
mode
median
std
By default,
None
, which does not track any extra layers.cell_size (int, optional) – Side length of each cell, in meters. Cells are assumed to be square. By default,
CELL_SIZE
.
Methods
compute
(end_indices[, save_paths])Compute least cost paths to given end indices
least_cost_path
(end_idx[, save_path])Find least cost path, its length, and its total (un-barriered) cost.
run
(cost_fpath, start_indices, end_indices, ...)Compute least cost tie-line path to all features to be connected a single supply curve point.
Attributes
Shaped of clipped cost raster
Column index inside clipped array
Offset to apply to column indices to move into clipped array
Tie line costs array
MCP_Geometric instance initialized on mcp_cost array with starting point at sc_point
Tie line costs array with barrier costs applied for MCP analysis
Row index inside clipped array
Offset to apply to row indices to move into clipped array
- property row_offset
Offset to apply to row indices to move into clipped array
- Returns:
int
- property col_offset
Offset to apply to column indices to move into clipped array
- Returns:
int
- property row
Row index inside clipped array
- Returns:
int
- property col
Column index inside clipped array
- Returns:
int
- property cost
Tie line costs array
- Returns:
ndarray
- property mcp_cost
Tie line costs array with barrier costs applied for MCP analysis
- Returns:
ndarray
- property mcp
MCP_Geometric instance initialized on mcp_cost array with starting point at sc_point
- Returns:
MCP_Geometric
- property clip_shape
Shaped of clipped cost raster
- Returns:
tuple
- least_cost_path(end_idx: Tuple[int, int], save_path=False) Tuple[float, float, float, float, Point | LineString | None, Dict[str, float]] [source]
Find least cost path, its length, and its total (un-barriered) cost. Optionally, calculate separate costs for sub-layers, and geometry of path.
- Parameters:
end_idx (Tuple[int, int]) – (row, col) index of end point to connect and compute least cost path to.
save_path (bool) – Flag to save least cost path as a multi-line geometry. By default,
False
.
- Returns:
length (float) – Length of path (km).
cost (float) – Cost of path including terrain and land use multipliers, but not barrier costs.
poi_lat, poi_lon (numpy.float64) – Latitude and longitude of the end_idx of the least cost path (i.e. the POI/transmission feature that was connected to).
path (shapely.geometry.linestring | None, optional) – Path as a LineString, if save_path was set to
True
.cl_results (Dict[str, float]) – Costs and lengths for individual sub-layers.
- compute(end_indices, save_paths=False)[source]
Compute least cost paths to given end indices
- Parameters:
end_indices (tuple | list) – Tuple (row, col) index or list of (row, col) indices in the clipped cost array indicating the end location(s) to compute least cost path paths to. Paths are computed from the start_indices that this class was initialized with to each of the individual pairs of end_indices.
save_paths (bool, optional) – Flag to save least cost path as a multi-line geometry, by default False
- Returns:
tie_lines (pandas.DataFrame | gpd.GeoDataFrame) – DataFrame of lengths and costs for each path or GeoDataFrame of length, cost, and geometry for each path
- classmethod run(cost_fpath, start_indices, end_indices, cost_layers, row_slice, col_slice, xmission_config=None, tb_layer_name='transmission_barrier', barrier_mult=100, save_paths=False, length_invariant_cost_layers=None, tracked_layers=None, cell_size=90)[source]
Compute least cost tie-line path to all features to be connected a single supply curve point.
- Parameters:
cost_fpath (str) – Full path to HDF5 file containing cost arrays. The cost data layers should be named
"tie_line_costs_{capacity}MW"
, wherecapacity
is an integer value representing the capacity of the line (the integer values must matches at least one of the integer capacity values represented by the keys in thepower_classes
portion of the transmission config).start_indices (tuple) – Tuple of (row_idx, col_idx) in the clipped cost array (see row_slice and col_slice definitions below) indicating the start position of all paths to compute (typically, this is the centroid of the supply curve cell). Paths will be computed from this start location to each of the
end_indices
, which are also locations in the cost array (typically transmission feature locations).cost_layers (List[str]) – List of layers in H5 that are summed to determine total costs raster used for routing. Costs and distances for each individual layer are also reported (e.g. wet and dry costs). deteremining path using main cost layer.
row_slice, col_slice (slice) – Slices into the cost raster array used to clip the area that should be considered when computing a least cost path. This can be used to limit the consideration space and speed up computation. Note that the start and end indices must be given w.r.t. the cost raster that is “clipped” using these slices.
xmission_config (str | dict | XmissionConfig, optional) – Path to transmission config JSON files, dictionary of transmission config JSONs, or preloaded XmissionConfig objects. If
None
, the default config is used. By default,None
.tb_layer_name (str, default=:obj:BARRIER_H5_LAYER_NAME) – Name of transmission barrier layer in cost_fpath file. This layer defines the multipliers applied to the cost layer to determine LCP routing (but does not actually affect output costs). By default,
BARRIER_H5_LAYER_NAME
.barrier_mult (int, optional) – Multiplier applied to the cost data to create transmission barrier costs. By default,
100
.save_paths (bool, optional) – Flag to save least cost path as a multi-line geometry. By default,
False
.length_invariant_cost_layers (List[str] | None, optional) – List of layers in H5 to be added to the cost raster. The costs specified by these layers are not scaled with distance traversed across the cell (i.e. fixed one-time costs for crossing these cells).
tracked_layers (dict, optional) – Dictionary mapping layer names to strings, where the strings are numpy methods that should be applied to the layer along the LCP. For example,
tracked_layers={'layer_1': 'mean', 'layer_2': 'max}
would report the average oflayer_1
values along the least cost path and the max oflayer_2
values along the least cost path. Examples of numpy methods (non-exhaustive):mean
max
min
mode
median
std
By default,
None
, which does not track any extra layers.cell_size (int, optional) – Side length of each cell, in meters. Cells are assumed to be square. By default,
CELL_SIZE
.
- Returns:
tie_lines (pandas.DataFrame | gpd.GeoDataFrame) – DataFrame of lengths and costs for each path or GeoDataFrame of length, cost, and geometry for each path