Skip to content

Commit

Permalink
Finished passing relative humidity through in bespoke and added icing…
Browse files Browse the repository at this point in the history
…/low temp cutoff test.
  • Loading branch information
WilliamsTravis committed Jun 10, 2024
1 parent f16d961 commit 685c1db
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 7 deletions.
33 changes: 29 additions & 4 deletions reV/bespoke/bespoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self, res_fpath, sc_gid_to_hh, sc_gid_to_res_gid):
self._wind_speeds = None
self._temps = None
self._pressures = None
self._relative_humidities = None
self._time_index = None
self._pre_load_data()

Expand Down Expand Up @@ -117,6 +118,10 @@ def _pre_load_data(self):
hh: res[f"pressure_{hh}m", :, gids]
for hh, gids in self.hh_to_res_gids.items()
}
self._relative_humidities = {
hh: res["relativehumidity_2m", :, gids]
for hh, gids in self.hh_to_res_gids.items()
}
self._time_index = res.time_index

logger.debug(
Expand Down Expand Up @@ -146,6 +151,7 @@ def get_preloaded_data_for_gid(self, sc_gid):
self._wind_speeds[hh][:, data_inds],
self._temps[hh][:, data_inds],
self._pressures[hh][:, data_inds],
self._relative_humidities[hh][:, data_inds],
self._time_index,
)

Expand All @@ -159,7 +165,8 @@ class BespokeSinglePlantData:
"""

def __init__(
self, data_inds, wind_dirs, wind_speeds, temps, pressures, time_index
self, data_inds, wind_dirs, wind_speeds, temps, pressures,
relative_humidities, time_index
):
"""Initialize BespokeSinglePlantData
Expand All @@ -170,9 +177,24 @@ def __init__(
the second dimension of `wind_dirs`, `wind_speeds`, `temps`,
and `pressures`. The GID value of data_inds[0] should
correspond to the `wind_dirs[:, 0]` data, etc.
wind_dirs, wind_speeds, temps, pressures : 2D np.array
Array of wind directions, wind speeds, temperatures, and
pressures, respectively. Dimensions should be correspond to
wind_dirs : 2D np.array
Array of wind directions. Dimensions should be correspond to
[time, location]. See documentation for `data_inds` for
required spatial mapping of GID values.
wind_speeds : 2D np.array
Array of wind speeds. Dimensions should be correspond to
[time, location]. See documentation for `data_inds` for
required spatial mapping of GID values.
temps : 2D np.array
Array oftemperatures. Dimensions should be correspond to
[time, location]. See documentation for `data_inds` for
required spatial mapping of GID values.
pressures : 2D np.array
Array of pressures. Dimensions should be correspond to
[time, location]. See documentation for `data_inds` for
required spatial mapping of GID values.
relative_humidities : 2D np.array
Array of relative humidities. Dimensions should be correspond to
[time, location]. See documentation for `data_inds` for
required spatial mapping of GID values.
time_index : 1D np.array
Expand All @@ -185,6 +207,7 @@ def __init__(
self.wind_speeds = wind_speeds
self.temps = temps
self.pressures = pressures
self.relative_humidities = relative_humidities
self.time_index = time_index

def __getitem__(self, key):
Expand All @@ -198,6 +221,8 @@ def __getitem__(self, key):
return self.temps[t_idx, data_inds]
if "pressure" in dset_name:
return self.pressures[t_idx, data_inds]
if "relativehumidity" in dset_name:
return self.relative_humidities[t_idx, data_inds]
msg = f"Unknown dataset name: {dset_name!r}"
logger.error(msg)
raise ValueError(msg)
Expand Down
78 changes: 75 additions & 3 deletions tests/test_bespoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"padus": {"dset": "ri_padus", "method": "mode", "fpath": EXCL},
}

# note that this differs from the
# Note that this differs from the
EXCL_DICT = {
"ri_srtm_slope": {"inclusion_range": (None, 5), "exclude_nodata": False},
"ri_srtm_slope": {"include_range": (None, 5), "exclude_nodata": False},
"ri_padus": {"exclude_values": [1], "exclude_nodata": False},
"ri_reeds_regions": {
"inclusion_range": (None, 400),
"include_range": (None, 400),
"exclude_nodata": False,
},
}
Expand Down Expand Up @@ -930,6 +930,74 @@ def test_bespoke_wind_plant_with_power_curve_losses():
assert np.isclose(aep_losses / aep, 0.9), err_msg


def test_bespoke_run_with_icing_cutoff():
"""Test bespoke run with icing cutoff enabled."""
output_request = ("system_capacity", "cf_mean", "cf_profile")
with tempfile.TemporaryDirectory() as td:
res_fp = os.path.join(td, "ri_100_wtk_{}.h5")
excl_fp = os.path.join(td, "ri_exclusions.h5")
shutil.copy(EXCL, excl_fp)
shutil.copy(RES.format(2012), res_fp.format(2012))
shutil.copy(RES.format(2013), res_fp.format(2013))
res_fp = res_fp.format("*")

TechMapping.run(excl_fp, RES.format(2012), dset=TM_DSET, max_workers=1)
bsp = BespokeSinglePlant(
33,
excl_fp,
res_fp,
TM_DSET,
SAM_SYS_INPUTS,
OBJECTIVE_FUNCTION,
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
ga_kwargs={"max_time": 5},
excl_dict=EXCL_DICT,
output_request=output_request,
)

out = bsp.run_plant_optimization()
out = bsp.run_wind_plant_ts()
bsp.close()

sam_inputs_ice = copy.deepcopy(SAM_SYS_INPUTS)
sam_inputs_ice["en_icing_cutoff"] = 1
sam_inputs_ice["en_low_temp_cutoff"] = 1
sam_inputs_ice["icing_cutoff_rh"] = 90 # High values to ensure diff
sam_inputs_ice["icing_cutoff_temp"] = 10
sam_inputs_ice["low_temp_cutoff"] = 0
bsp = BespokeSinglePlant(
33,
excl_fp,
res_fp,
TM_DSET,
sam_inputs_ice,
OBJECTIVE_FUNCTION,
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
ga_kwargs={"max_time": 5},
excl_dict=EXCL_DICT,
output_request=output_request,
)

out_ice = bsp.run_plant_optimization()
out_ice = bsp.run_wind_plant_ts()
bsp.close()

ae_dsets = [
"annual_energy-2012",
"annual_energy-2013",
"annual_energy-means",
]
for dset in ae_dsets:
assert not np.isclose(out[dset], out_ice[dset])
assert out[dset] > out_ice[dset]


def test_bespoke_run_with_power_curve_losses():
"""Test bespoke run with power curve losses."""
output_request = ("system_capacity", "cf_mean", "cf_profile")
Expand Down Expand Up @@ -1558,3 +1626,7 @@ def test_bespoke_5min_sample():
assert len(f["time_index-2010"]) == 8760
assert len(f["windspeed-2010"]) == 8760
assert len(f["winddirection-2010"]) == 8760


if __name__ == "__main__":
test_bespoke_run_with_icing_cutoff()

0 comments on commit 685c1db

Please sign in to comment.