Skip to content

Commit

Permalink
Remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebannis committed Jan 23, 2024
1 parent a10c8bc commit 72b1af4
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 2,484 deletions.
253 changes: 1 addition & 252 deletions reVX/config/least_cost_xmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,264 +4,13 @@
"""
import os
import logging
from typing import Tuple, Union, List, Dict

import pandas as pd

from reV.supply_curve.extent import SupplyCurveExtent
from reV.config.base_analysis_config import AnalysisConfig, BaseConfig
from reV.config.base_analysis_config import AnalysisConfig

logger = logging.getLogger(__name__)

# Transmission barriers format. Also used for forced inclusion. Example:
# barrier_files = [
# (1, 'artificial_reefs.tif'),
# ([1,2,3,4], 'ocean_disposal_sites.tif'),
# ]
_BarrierFile = Tuple[Union[int, List[int]], str]
BarrierFiles = List[_BarrierFile]

# Transmission friction format, example:
# friction_files = [
# # ({'cell value in tiff': 'corresponding friction', ...}, 'filename.tif')
# ({1: 1, 2: 10, 3:5}, 'adjusted_shipping_lanes.tif'),
# ({1: 10}, 'federal_channels.tif'),
# ]
_FrictionFile = Tuple[Dict[int, int], str]
FrictionFiles = List[_FrictionFile]

# JSON requires dict keys to be str. Also allow values to be str.
_JsonFrictionFile = Tuple[Dict[str, Union[int, str]], str]
JsonFrictionFiles = List[_JsonFrictionFile]


class OLD_LayerCreatorConfig(BaseConfig):
"""
Config framework for creating cost, friction, and barrier layers.
"""

NAME = 'LayerCreatorConfig'
REQUIREMENTS = (
'template_raster_fpath', 'h5_fpath',
)

# pylint: disable=useless-parent-delegation
def __init__(self, config: Union[str, dict]):
"""
Parameters
----------
config
Path to config .json or pre-extracted config input dictionary.
"""
super().__init__(config)

@property
def template_raster_fpath(self) -> str:
"""
Path and file name of template raster. (required)
"""
return self['template_raster_fpath']

@property
def h5_fpath(self) -> str:
"""
H5 file for all layers. Will be created if it doesn't exist (required)
"""
return self['h5_fpath']

@property
def land_h5_fpath(self) -> str:
"""
H5 file with land costs and barriers. This has typically been a smaller
raster in both real-world extent and pixels than the offshore raster.
(required)
"""
return self['land_h5_fpath']

@property
def friction_files(self) -> FrictionFiles:
"""
List of friction files with desired frictions. (required)
"""
return self._friction_keys_to_int(self['friction_files'])

@property
def barrier_files(self) -> BarrierFiles:
"""
List of barrier files with values to used as barriers. (required)
"""
return self['barrier_files']


@property
def land_mask_fpath(self) -> str:
"""
Path and file name of land mask raster. Values of 1 represent land,
all other values are assumed to represent water. (required)
"""
return self['land_mask_fpath']

@property
def land_barrier_layer(self) -> str:
"""
Name of land barrier layer in land_h5_fpath. (required)
"""
return self['land_barrier_layer']

@property
def land_costs_layer(self) -> str:
"""
Name of land costs layer in land_h5_fpath. (required)
"""
return self['land_costs_layer']

@property
def layer_dir(self) -> str:
"""
Optional path for search for friction and barrier TIFFs in. It is
allowed to use a mix of full paths with just file names that will need
to be prepended with the layer_dir.
"""
return self.get('layer_dir', '')

@property
def ex_offshore_h5_fpath(self) -> Union[str, None]:
"""
Path and file name of existing offshore h5 file to pull profile and
lat/lng from for creating a new offshore h5 file.
"""
return self.get('ex_offshore_h5_fpath', None)

@property
def forced_inclusion_files(self) -> BarrierFiles:
"""
Path and file name of bathymetry raster.
"""
return self.get('forced_inclusion_files', [])

@property
def save_tiff(self) -> bool:
"""
Save intermediary layers as TIFFs if True
"""
return self.get('save_tiff', True)

@property
def slope_fpath(self) -> Union[str, None]:
"""
Path and filename of slope raster.
"""
return self.get('slope_fpath', None)

@property
def bathy_fpath(self) -> Union[str, None]:
"""
Path and file name of bathymetry raster.
"""
return self.get('bathy_fpath', None)

@property
def bathy_depth_cutoff(self) -> Union[float, None]:
"""
Bathymetric depth below which a friction is applied. Depending on the
bathymetric depth layer, this value may need to be negative.
"""
return self.get('bathy_depth_cutoff', None)

@property
def bathy_friction(self) -> Union[int, None]:
"""
Friction applied to cells with a bathymetric depth greater than the
bathy_depth_cutoff.
"""
return self.get('bathy_friction', None)

@property
def minimum_friction_files(self) -> Union[FrictionFiles, None]:
"""
Layers used to assign minimum friction. Minimum friction is applied
after all other frictions have been combined.
"""
mff = self.get('minimum_friction_files', None)
if mff is None:
return mff
return self._friction_keys_to_int(mff)

@property
def land_cost_mult(self) -> Union[float, None]:
"""
Land cost multiplier for scaling land costs.
"""
return self.get('land_cost_mult', None)

# Optional slope values. Any values specified override the defaults in
# CombineRasters.
@property
def slope_barrier_cutoff(self) -> Union[float, None]:
"""
Cells with slopes greater than this will be set as barriers.
"""
return self.get('slope_barrier_cutoff', None)

@property
def low_slope_cutoff(self) -> Union[float, None]:
"""
Cells with slopes less than this will be given the low_slope_friction.
"""
return self.get('low_slope_cutoff', None)

@property
def high_slope_friction(self) -> Union[float, None]:
"""
Frictions for slopes greater than slope_barrier_cutoff. This is
somewhat redundant as the same cells are also assigned as barriers.
"""
return self.get('high_slope_friction', None)

@property
def medium_slope_friction(self) -> Union[float, None]:
"""
Frictions for slopes less than slope_barrier_cutoff and greater than
low_slope_cutoff.
"""
return self.get('medium_slope_friction', None)

@property
def low_slope_friction(self) -> Union[float, None]:
"""
Frictions for slopes less than low_slope_cutoff.
"""
return self.get('low_slope_friction', None)

@staticmethod
def _friction_keys_to_int(files: JsonFrictionFiles) -> FrictionFiles:
"""
Convert keys in friction dict to ints. JSON requires keys to be
strings, but we want ints. Also check values just in case.
"""
ff: FrictionFiles = []
for friction_map, file in files:
clean_map: Dict[int, int] = {}
for raw_key, raw_val in friction_map.items():
try:
key = int(raw_key)
except ValueError as exc:
msg = f'Unable to convert friction key {raw_key} to int.'
logger.exception(msg)
raise ValueError(msg) from exc

try:
val = int(raw_val)
except ValueError as exc:
msg = f'Unable to convert friction value {raw_val} to int.'
logger.exception(msg)
raise ValueError(msg) from exc

clean_map[key] = val

ff.append((clean_map, file))
return ff


class DryCostCreatorConfig(AnalysisConfig):
"""Config framework for creating dry cost layers"""
Expand Down
Loading

0 comments on commit 72b1af4

Please sign in to comment.