Skip to content

Commit

Permalink
Merge pull request #63 from IMMM-SFA/ic-check
Browse files Browse the repository at this point in the history
JOSS Review:  Ubuntu 18 Limitation
  • Loading branch information
crvernon authored Aug 25, 2021
2 parents 3bd8242 + 91ed395 commit d4616cd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cerf/data/*.xml
cerf/data/*.sdat
cerf/data/*.sgrd
cerf/data/*.img
cerf/data/*.npy

# ignore docs build
docs/build/
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

### Install `cerf`

**NOTE**: `cerf` is not officially supported for Ubuntu 18 users due to a system dependency (`GLIBC_2.29`) required by the `whitebox` package which `cerf` uses to conduct spatial analysis. Ubuntu 18 natively includes `GLIBC_2.27`. It may be possible for Ubuntu 18 users to upgrade to `GLIBC_2.29` but this should be done with careful consideration. Instead, we officially support `cerf` use for Ubuntu users for versions 20.04.2 LTS and greater.

```bash
pip install cerf
```
Expand Down
2 changes: 1 addition & 1 deletion cerf/install_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class InstallSupplement:
'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/5246071/files/cerf_package_data.zip?download=1'}
'2.0.4': 'https://zenodo.org/record/5247690/files/cerf_package_data.zip?download=1'}

def fetch_zenodo(self):
"""Download and unpack the Zenodo example data supplement for the
Expand Down
16 changes: 8 additions & 8 deletions cerf/interconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ class Interconnection:
:param output_cost_file: Write cost file; if True, set 'output_dir' value
:type output_cost_file: bool
:param interconnection_cost_file: Full path with file name and extension to a preprocessed interconnection
cost NPY file that has been previously written. If None, IC will be
cost NPY file that has been previously written. If None, IC will be
calculated.
:type interconnection_cost_file: str
:type interconnection_cost_file: str
:param output_dir: Full path to a directory to write outputs to if desired
:type output_dir: str
Expand All @@ -110,8 +110,8 @@ class Interconnection:

def __init__(self, template_array, technology_dict, technology_order, region_raster_file,
region_abbrev_to_name_file, region_name_to_id_file, substation_file=None,
transmission_costs_dict=None, transmission_costs_file=None, pipeline_costs_dict=None,
pipeline_costs_file=None,pipeline_file=None, output_rasterized_file=False, output_dist_file=False,
transmission_costs_dict=None, transmission_costs_file=None, pipeline_costs_dict=None,
pipeline_costs_file=None, pipeline_file=None, output_rasterized_file=False, output_dist_file=False,
output_alloc_file=False, output_cost_file=False, interconnection_cost_file=None, output_dir=None):

self.template_array = template_array
Expand Down Expand Up @@ -270,7 +270,8 @@ def transmission_to_cost_raster(self, setting):
infrastructure_gdf = self.process_pipelines()

else:
raise ValueError(f"Incorrect setting '{setting}' for transmission data. Must be 'substations' or 'pipelines'")
raise ValueError(
f"Incorrect setting '{setting}' for transmission data. Must be 'substations' or 'pipelines'")

with rasterio.open(self.region_raster_file) as src:

Expand Down Expand Up @@ -340,10 +341,9 @@ def transmission_to_cost_raster(self, setting):

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

# if a preprocessed file has been provided, load and return it
if self.interconnection_cost_file is not None:

logging.info(f"Using prebuilt interconnection costs file: {self.interconnection_cost_file}")
return np.load(self.interconnection_cost_file)

Expand Down
4 changes: 4 additions & 0 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Officially Python 3.7, 3.8, and 3.9
Installation
------------

.. note::

**cerf** is not officially supported for Ubuntu 18 users due to a system dependency (``GLIBC_2.29``) required by the ``whitebox`` package which **cerf** uses to conduct spatial analysis. Ubuntu 18 natively includes ``GLIBC_2.27``. It may be possible for Ubuntu 18 users to upgrade to ``GLIBC_2.29`` but this should be done with careful consideration. Instead, we officially support **cerf** use for Ubuntu users for versions 20.04.2 LTS and greater.

**cerf** can be installed via pip by running the following from a terminal window::

pip install cerf
Expand Down
70 changes: 70 additions & 0 deletions tests/test_interconnect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import unittest

import numpy as np
import pkg_resources

from cerf.read_config import ReadConfig
from cerf.interconnect import Interconnection


class TestInterconnection(unittest.TestCase):

# supporting data
TEST_CONFIG = pkg_resources.resource_filename('cerf', 'data/test_config_2010.yml')
EXPECTED_SUBSET = np.load(pkg_resources.resource_filename('cerf', 'data/test_ic_arr.npy'))

@staticmethod
def get_sample(arr):
"""Get a sample to reduce comparison size. Sample space covers the Southeast U.S."""

return arr[:, 1500:2000, 3000:4000].copy()

def test_interconnection_run(self):
"""Test to make sure interconnection outputs run."""

# read in configuration file
cfg = ReadConfig(self.TEST_CONFIG)

# unpack configuration and assign defaults
substation_file = cfg.infrastructure_dict.get('substation_file', None)
transmission_costs_file = cfg.infrastructure_dict.get('transmission_costs_file', None)
pipeline_costs_file = cfg.infrastructure_dict.get('pipeline_costs_file', None)
pipeline_file = cfg.infrastructure_dict.get('pipeline_file', None)
output_rasterized_file = cfg.infrastructure_dict.get('output_rasterized_file', False)
output_alloc_file = cfg.infrastructure_dict.get('output_alloc_file', False)
output_cost_file = cfg.infrastructure_dict.get('output_cost_file', False)
output_dist_file = cfg.infrastructure_dict.get('output_dist_file', False)
interconnection_cost_file = cfg.infrastructure_dict.get('interconnection_cost_file', None)

template_array = np.zeros(shape=(1, 2999, 4693))

technology_dict_subset = {9: cfg.technology_dict[9]}
technology_order_subset = [cfg.technology_order[0]]

# instantiate class
ic = Interconnection(template_array=template_array,
technology_dict=technology_dict_subset,
technology_order=technology_order_subset,
region_raster_file=cfg.settings_dict.get('region_raster_file'),
region_abbrev_to_name_file=cfg.settings_dict.get('region_abbrev_to_name_file'),
region_name_to_id_file=cfg.settings_dict.get('region_name_to_id_file'),
substation_file=substation_file,
transmission_costs_file=transmission_costs_file,
pipeline_costs_file=pipeline_costs_file,
pipeline_file=pipeline_file,
output_rasterized_file=output_rasterized_file,
output_dist_file=output_dist_file,
output_alloc_file=output_alloc_file,
output_cost_file=output_cost_file,
interconnection_cost_file=interconnection_cost_file,
output_dir=cfg.settings_dict.get('output_directory', None))

ic_arr = ic.generate_interconnection_costs_array()

ic_arr_subset = self.get_sample(ic_arr)

np.testing.assert_array_equal(TestInterconnection.EXPECTED_SUBSET, ic_arr_subset)


if __name__ == '__main__':
unittest.main()

0 comments on commit d4616cd

Please sign in to comment.