Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging version 2.4.0 #108

Merged
merged 23 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python setup.py install
python -m pip install .
python -c 'import cerf; cerf.install_package_data()'

- name: Test and generate coverage report on Linux
Expand All @@ -35,8 +35,3 @@ jobs:
pip install pytest-cov
pytest --cov=./ --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
fail_ci_if_error: true
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![build](https://github.com/IMMM-SFA/cerf/actions/workflows/build.yml/badge.svg)](https://github.com/IMMM-SFA/cerf/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/IMMM-SFA/cerf/branch/main/graph/badge.svg?token=9jbGJv8XCJ)](https://codecov.io/gh/IMMM-SFA/cerf)
[![DOI](https://zenodo.org/badge/115649750.svg)](https://zenodo.org/badge/latestdoi/115649750)
[![status](https://joss.theoj.org/papers/28fee3407bbbef020fb4bb19bd451407/status.svg)](https://joss.theoj.org/papers/28fee3407bbbef020fb4bb19bd451407)

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.3.2"
__version__ = "2.4.0"
38 changes: 21 additions & 17 deletions cerf/install_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ class InstallSupplement:
"""

# URL for DOI minted example data hosted on Zenodo
DATA_VERSION_URLS = {'2.0.0': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.1': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.2': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.3': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.4': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.5': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.6': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.7': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.0.8': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.0.9': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'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.3': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3.1': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3.2': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1'}
DATA_VERSION_URLS = {
'2.0.0': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.1': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.2': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.3': 'https://zenodo.org/record/5218436/files/cerf_package_data.zip?download=1',
'2.0.4': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.5': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.6': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1',
'2.0.7': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.0.8': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'2.0.9': 'https://zenodo.org/record/5514010/files/cerf_package_data.zip?download=1',
'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.3': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3.1': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3.2': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.3.3': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
'2.4.0': 'https://zenodo.org/record/6998151/files/cerf_package_data.zip?download=1',
}

def __init__(self, data_dir=None):

Expand Down
47 changes: 24 additions & 23 deletions cerf/interconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@
import logging
import tempfile

import geopandas as gpd
import numpy as np
import rasterio
import whitebox
from rasterio import features
from scipy.ndimage import distance_transform_edt
import yaml

import numpy as np
import geopandas as gpd

import cerf.package_data as pkg

from rasterio import features

from cerf.utils import suppress_callback

# instantiate whitebox toolset
wbt = whitebox.WhiteboxTools()


class Interconnection:
"""Calculate interconnection costs per grid cell in $ / yr using:
Expand Down Expand Up @@ -263,19 +257,17 @@ def process_pipelines(self):

return gdf


def transmission_to_cost_raster(self, setting):
"""Create a cost per grid cell in $/km from the input GeoDataFrame of transmission infrastructure having a cost
designation field as '_rval_'
designation field as '_rval_'.

:param setting: Either 'substations' or 'pipelines'
:type setting: str

:return: Array of transmission interconnection cost per grid cell

"""
# conversion factor for meters to km
m_to_km_factor = 0.001

if setting == 'substations':
infrastructure_gdf = self.process_substations()

Expand Down Expand Up @@ -335,27 +327,36 @@ def transmission_to_cost_raster(self, setting):
# write the outputs to file
dataset.write_band(1, burned)

# calculate Euclidean distance and write raster; result just stores the return value 0
dist_result = wbt.euclidean_distance(out_rast, out_dist, callback=suppress_callback)
# create a mask of target (non-zero) cells
target_cells = burned != 0

# calculate the Euclidean distance and the indices of the nearest target cell
distance_array, nearest_indices = distance_transform_edt(
~target_cells,
return_distances=True,
return_indices=True
)

# calculate Euclidean allocation and write raster
alloc_result = wbt.euclidean_allocation(out_rast, out_alloc, callback=suppress_callback)
# use the nearest indices to map the value of the nearest target to each cell (allocation map)
nearest_row_indices, nearest_col_indices = nearest_indices
allocation_array = burned[nearest_row_indices, nearest_col_indices]

with rasterio.open(out_dist) as dist:
dist_arr = dist.read(1)
with rasterio.open(out_dist, 'w', **metadata) as dist_ds:
dist_ds.write(distance_array.astype(rasterio.float64), 1)

with rasterio.open(out_alloc) as alloc:
alloc_arr = alloc.read(1)
with rasterio.open(out_alloc, 'w', **metadata) as alloc_ds:
alloc_ds.write(allocation_array.astype(rasterio.float64), 1)

with rasterio.open(out_costs, 'w', **metadata) as out:

# distance in km * the cost of the nearest substation; outputs thous$/km
cost_arr = (dist_arr * m_to_km_factor) * alloc_arr
cost_arr = distance_array * allocation_array

out.write(cost_arr, 1)

return cost_arr


def generate_interconnection_costs_array(self):
"""Calculate the costs of interconnection for each technology."""

Expand Down
4 changes: 2 additions & 2 deletions cerf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pandas as pd
import rasterio
import xarray as xr
import rioxarray
import geopandas as gpd
from shapely.geometry import Point

Expand Down Expand Up @@ -253,7 +253,7 @@ def raster_to_coord_arrays(template_raster):
"""

# Read the data
da = xr.open_rasterio(template_raster)
da = rioxarray.open_rasterio(template_raster)

# Compute the lon/lat coordinates with rasterio.warp.transform
x, y = np.meshgrid(da['x'], da['y'])
Expand Down
2 changes: 1 addition & 1 deletion 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.3.2" #str(cerf.__version__)
version = "2.4.0" #str(cerf.__version__)


sys.path.insert(0, os.path.abspath('../../'))
Expand Down
8 changes: 8 additions & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Release notes
This is the list of changes to **cerf** between each release. For full details,
see the `commit logs <https://github.com/IMMM-SFA/cerf/commits>`_.

Version 2.4.0
_____________

- Replaced whitebox dependency used in Euclidean distance calculations with SciPy https://github.com/IMMM-SFA/cerf/pull/107
- Limited NumPy version to less than 2 due Fiona dependency https://github.com/IMMM-SFA/cerf/pull/105
- Updated depreciated calls to xarray https://github.com/IMMM-SFA/cerf/pull/105


Version 2.2.1
_____________

Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ dependencies:
- pip
- pip:
- cerf
- numpy>=1.19.4
- numpy>=1.19.4,<2
- scipy>=1.12
- pandas>=1.1.4
- rasterio>=1.2.3
- xarray>=0.16.1
Expand All @@ -15,7 +16,6 @@ dependencies:
- joblib>=1.0.1
- matplotlib>=3.3.3
- seaborn>=0.11.1
- whitebox>=1.5.1
- fiona>=1.8.19
- pyproj>=3.0.1
- rtree>=0.9.7
Expand Down
Loading