Skip to content
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
4 changes: 3 additions & 1 deletion rex/resource_extraction/resource_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,10 @@ def get_SAM_gid(self, gid, out_path=None, write_time=True,
If multiple lat, lon pairs are given a list of DatFrames is
returned
"""
needs_gid_suffix = True
if isinstance(gid, (int, np.integer)):
gid = [gid]
needs_gid_suffix = False

SAM_df = []
for res_id in gid:
Expand All @@ -933,7 +935,7 @@ def get_SAM_gid(self, gid, out_path=None, write_time=True,
if out_path is not None:
assert out_path.endswith('.csv'), 'out_path must be .csv!'
i_out_path = out_path
if len(gid) > 1:
if needs_gid_suffix:
tag = '_{}.csv'.format(res_id)
i_out_path = i_out_path.replace('.csv', tag)

Expand Down
2 changes: 1 addition & 1 deletion rex/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""rex Version number"""

__version__ = "0.4.1"
__version__ = "0.4.2"
33 changes: 22 additions & 11 deletions tests/test_resource_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ def test_sam_csv_with_extra_commas(NSRDBX_cls):

with tempfile.TemporaryDirectory() as td:
out_path = os.path.join(td, 'test.csv')
assert not os.path.exists(out_path)

NSRDBX_cls.get_SAM_gid(0, out_path=out_path,
extra_meta_data={"urban": "Washington, D.C."})
assert os.path.exists(out_path)
assert not os.path.exists(os.path.join(td, 'test_0.csv'))

with open(out_path) as fh:
col_names = fh.readline()
values = fh.readline()
Expand Down Expand Up @@ -852,7 +857,12 @@ def test_cli_SAM(runner, WindX_cls):
path = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012.h5')
with tempfile.TemporaryDirectory() as td:
truth_path = os.path.join(td, 'truth.csv')
assert not os.path.exists(truth_path)

WindX_cls.get_SAM_gid(gid, 100, out_path=truth_path)
assert os.path.exists(truth_path)
assert not os.path.exists(os.path.join(td, f'test_{gid}.csv'))

truth = pd.read_csv(truth_path, skiprows=1)

result = runner.invoke(main, ['-h5', path,
Expand All @@ -872,7 +882,8 @@ def test_cli_SAM(runner, WindX_cls):
LOGGERS.clear()


def test_windx_make_SAM_files(WindX_cls):
@pytest.mark.parametrize('max_workers', [1, 2])
def test_windx_make_SAM_files(WindX_cls, max_workers):
"""
Test WindX make_SAM_files method
"""
Expand All @@ -881,12 +892,12 @@ def test_windx_make_SAM_files(WindX_cls):

path = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012.h5')
with tempfile.TemporaryDirectory() as td:
for gid in gids:
truth_path = os.path.join(td, f'truth_{gid}.csv')
WindX_cls.get_SAM_gid(gid, 100, out_path=truth_path)
truth_path = os.path.join(td, 'truth.csv')
WindX_cls.get_SAM_gid(gids, 100, out_path=truth_path)

test_path = os.path.join(td, 'test.csv')
WindX.make_SAM_files(path, gids, hub_height=100, out_path=test_path)
WindX.make_SAM_files(path, gids, hub_height=100, out_path=test_path,
max_workers=max_workers)
for gid in gids:
test_path = os.path.join(td, f'test_{gid}.csv')
truth_path = os.path.join(td, f'truth_{gid}.csv')
Expand Down Expand Up @@ -921,11 +932,11 @@ def test_windx_run_SAM_files():
obj.execute()
assert obj.Outputs.annual_energy < energy_no_icing


LOGGERS.clear()


def test_nsrdbx_make_SAM_files(NSRDBX_cls):
@pytest.mark.parametrize('max_workers', [1, 2])
def test_nsrdbx_make_SAM_files(NSRDBX_cls, max_workers):
"""
Test nsrdbx make_SAM_files method
"""
Expand All @@ -934,12 +945,12 @@ def test_nsrdbx_make_SAM_files(NSRDBX_cls):

path = os.path.join(TESTDATADIR, 'nsrdb/ri_100_nsrdb_2012.h5')
with tempfile.TemporaryDirectory() as td:
for gid in gids:
truth_path = os.path.join(td, f'truth_{gid}.csv')
NSRDBX_cls.get_SAM_gid(gid, out_path=truth_path)
truth_path = os.path.join(td, 'truth.csv')
NSRDBX_cls.get_SAM_gid(gids, out_path=truth_path)

test_path = os.path.join(td, 'test.csv')
NSRDBX.make_SAM_files(path, gids, out_path=test_path)
NSRDBX.make_SAM_files(path, gids, out_path=test_path,
max_workers=max_workers)
for gid in gids:
test_path = os.path.join(td, f'test_{gid}.csv')
truth_path = os.path.join(td, f'truth_{gid}.csv')
Expand Down
Loading