Skip to content

Commit

Permalink
Merge pull request #95 from IMMM-SFA/dev
Browse files Browse the repository at this point in the history
v2.3 release
  • Loading branch information
crvernon authored Mar 13, 2023
2 parents 547cde5 + d3d1d74 commit 03b80a0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

env:
OS: ${{ matrix.os }}
PYTHON: '3.8'
PYTHON: '3.9'

steps:

Expand All @@ -21,7 +21,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@master
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion cerf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .install_supplement import install_package_data


__version__ = "2.2.1"
__version__ = "2.3"
3 changes: 2 additions & 1 deletion cerf/install_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class InstallSupplement:
'2.1.0': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.1.1': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.2.0': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.2.1': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1'}
'2.2.1': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1'}

def __init__(self, data_dir=None):

Expand Down
4 changes: 3 additions & 1 deletion cerf/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def get_sited_data(self):
logging.info("Initializing previous siting data")
init_arr, init_df = util.ingest_sited_data(run_year=self.settings_dict['run_year'],
x_array=self.xcoords,
siting_data=self.initialize_site_data)
siting_data=self.initialize_site_data,
template_raster_file=self.settings_dict.get('region_raster_file'),
precision=self.settings_dict.get("lookup_coordinate_precision", 1))

return init_arr, init_df

Expand Down
53 changes: 52 additions & 1 deletion cerf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,39 @@ def raster_to_coord_arrays(template_raster):
return x, y


def ingest_sited_data(run_year, x_array, siting_data):
def genrate_grid_coordinate_lookup(template_raster: str,
precision: int = 1) -> pd.DataFrame:
"""Generate a lookup data frame from the input template raster.
:param template_raster: Full path with file name and extension to the input tempate raster file
:type template_raster: str
:param precision: Desired precision of coordinates to round to
:type precision: int
:returns: DataFrame of grid index, xcoords, and ycoords in template raster
:rtype: pd.DataFrame
"""

with rasterio.open(template_raster) as src:
arr = src.read(1)
height, width = arr.shape
cols, rows = np.meshgrid(np.arange(width), np.arange(height))
xs, ys = rasterio.transform.xy(src.transform, rows, cols)

# convert to arrays, flatten to 1D and round to tenth
xcoords = np.array(xs).flatten().round(precision)
ycoords = np.array(ys).flatten().round(precision)

return pd.DataFrame({"grid_index": range(xcoords.shape[0]), "xcoord": xcoords, "ycoord": ycoords})


def ingest_sited_data(run_year,
x_array,
siting_data,
template_raster_file: str,
precision: int = 1):
"""Import sited data containing the locations and additional data to establish an initial suitability condition
representing power plants and their siting buffer.
Expand All @@ -284,6 +316,12 @@ def ingest_sited_data(run_year, x_array, siting_data):
Pandas DataFrame
:type siting_data: str, DataFrame
:param template_raster_file: Full path with file name and extension to the input tempate raster file
:type template_raster_file: str
:param precision: Desired precision of coordinates to round to
:type precision: int
:return: [0] 2D array of 0 (suitable) and 1 (unsuitable) values where 1 are the sites
and their buffers of active power plants
Expand All @@ -307,6 +345,19 @@ def ingest_sited_data(run_year, x_array, siting_data):
# initialize an array to hold the 0, 1 sited and buffer data
sited_arr = np.zeros_like(x_array).flatten()

# convert coordinates from initialization file
lookup_df = genrate_grid_coordinate_lookup(template_raster_file, precision=precision)

# match coordinates in input file to the lookup from the template raster
df_input = df_active[["xcoord", "ycoord"]].copy().round(precision)
df_input = pd.merge(df_input,
lookup_df,
how="left",
on=["xcoord", "ycoord"])

# give the input data frame the new index from the coordinate lookup
df_active["index"] = df_input["grid_index"]

for ix in df_active['index'].tolist():

# get the buffer size for the site
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sphinx_rtd_theme

# import cerf
version = "2.2.1" #str(cerf.__version__)
version = "2.3" #str(cerf.__version__)


sys.path.insert(0, os.path.abspath('../../'))
Expand All @@ -25,7 +25,7 @@
# -- Project information -----------------------------------------------------

project = 'cerf'
copyright = '2021-2022, Battelle Memorial Institute'
copyright = '2021-current, Battelle Memorial Institute'
author = 'Chris R. Vernon'

# The full version, including alpha/beta/rc tags
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_requirements():
description='An open-source geospatial Python package for assessing and analyzing future electricity technology capacity expansion feasibility',
long_description=readme(),
long_description_content_type="text/markdown",
python_requires='>=3.7.*, <4',
python_requires='>=3.9.*, <4',
include_package_data=True,
install_requires=[
'numpy>=1.19.4',
Expand Down

0 comments on commit 03b80a0

Please sign in to comment.