Skip to content

Commit

Permalink
adding test case for writing techmap dset to h5
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgleason committed Jan 22, 2025
1 parent 381a7b9 commit 79e2bbb
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/test_supply_curve_tech_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@author: gbuster
"""
import os
import shutil

import h5py
import numpy as np
Expand All @@ -23,9 +24,17 @@
TM_DSET = 'techmap_nsrdb_ri_truth'


def test_resource_tech_mapping():
@pytest.mark.parametrize("dset", [None, "tm"])
def test_resource_tech_mapping(tmp_path, dset):
"""Run the supply curve technology mapping and compare to baseline file"""
ind = TechMapping.run(EXCL, RES, dset=None, max_workers=2)

if dset is None:
excl_fpath = EXCL
else:
excl_fpath = tmp_path.joinpath("excl.h5").as_posix()
shutil.copy(EXCL, excl_fpath)

ind = TechMapping.run(excl_fpath, RES, dset=dset, max_workers=2)

with ExclusionLayers(EXCL) as ex:
ind_truth = ex[TM_DSET]
Expand All @@ -36,6 +45,14 @@ def test_resource_tech_mapping():
msg = 'Tech mapping didnt find all 100 generation points!'
assert len(set(ind.flatten())) == 101, msg

if dset is not None:
with h5py.File(excl_fpath, 'r') as f:
assert dset in f, "Techmap dataset was not written to H5"
ind_h5 = np.array(f[dset])
assert np.allclose(ind_h5, ind_truth), (
"H5 tech map dataset does not match baseline results."
)


# pylint: disable=no-member
def plot_tech_mapping(dist_margin=1.05):
Expand Down Expand Up @@ -111,8 +128,8 @@ def execute_pytest(capture='all', flags='-rapP'):
Which tests to show logs and results for.
"""

fname = os.path.basename(__file__)
pytest.main(['-q', '--show-capture={}'.format(capture), fname, flags])
fname = __file__
pytest.main(["-q", "--show-capture={}".format(capture), fname, flags])


if __name__ == '__main__':
Expand Down

0 comments on commit 79e2bbb

Please sign in to comment.