diff --git a/ard/__init__.py b/ard/__init__.py index c2cc6a17..3491c9df 100644 --- a/ard/__init__.py +++ b/ard/__init__.py @@ -1,13 +1,4 @@ from pathlib import Path -from . import collection -from . import layout -from . import offshore -from . import wind_query -from . import utils -from . import viz - -from .viz import house_style - BASE_DIR = Path(__file__).parent.absolute() ASSET_DIR = BASE_DIR / "api" / "default_systems" diff --git a/ard/api/interface.py b/ard/api/interface.py index 73ec9032..837d35bc 100644 --- a/ard/api/interface.py +++ b/ard/api/interface.py @@ -5,11 +5,6 @@ from openmdao.utils.file_utils import clean_outputs from ard.utils.io import load_yaml, replace_key_value from ard.utils.logging import prepend_tabs_to_stdio -from ard.cost.wisdem_wrap import ( - LandBOSSE_setup_latents, - ORBIT_setup_latents, - FinanceSE_setup_latents, -) import windIO from ard import ASSET_DIR from typing import Union @@ -163,12 +158,11 @@ def set_up_system_recursive( prob = None # Add subsystems directly from the input dictionary + indent = "\t" * _depth if hasattr(parent_group, "name") and (parent_group.name != ""): - print( - f"{''.join(['\t' for _ in range(_depth)])}Adding {system_name} to {parent_group.name}." - ) + print(f"{indent}Adding {system_name} to {parent_group.name}.") else: - print(f"{''.join(['\t' for _ in range(_depth)])}Adding {system_name}.") + print(f"{indent}Adding {system_name}.") if "systems" in input_dict: # Recursively add nested subsystems] if _depth > 0: group = parent_group.add_subsystem( diff --git a/ard/farm_aero/floris.py b/ard/farm_aero/floris.py index 0e436a1e..8a75379e 100644 --- a/ard/farm_aero/floris.py +++ b/ard/farm_aero/floris.py @@ -197,14 +197,16 @@ def setup(self): # set up FLORIS self.fmodel = floris.FlorisModel("defaults") - data_path = self.options["data_path"] self.fmodel.set( turbine_type=[ create_FLORIS_turbine_from_windIO(self.windIO, self.modeling_options), ], - wind_shear=self.windIO["site"]["energy_resource"]["wind_resource"].get( - "shear" - ), + wind_shear=self.windIO["site"]["energy_resource"]["wind_resource"] + .get( + "shear", + {}, + ) + .get("alpha"), reference_wind_height=getattr( self.wind_query, "reference_height", diff --git a/ard/farm_aero/templates.py b/ard/farm_aero/templates.py index 6f4da7b0..db4735ee 100644 --- a/ard/farm_aero/templates.py +++ b/ard/farm_aero/templates.py @@ -51,6 +51,21 @@ def create_windresource_from_windIO( # get the wind resource specification out of the dictionary wind_resource = windIOdict["site"]["energy_resource"]["wind_resource"] + reference_height = wind_resource.get("reference_height") + h_ref = wind_resource.get("shear", {}).get("h_ref") + if ( + reference_height is not None + and h_ref is not None + and not np.isclose(reference_height, h_ref) + ): + raise ValueError( + "Both 'reference_height' and 'h_ref' were provided in wind_resource " + f"with different values ({reference_height} vs {h_ref})." + ) + wind_resource_reference_height = ( + reference_height if reference_height is not None else h_ref + ) + # figure out the case in play fields_wind_resource = wind_resource.keys() case_probability_based = all( @@ -122,11 +137,7 @@ def create_windresource_from_windIO( ti_table=turbulence_intensities, ) # stash some metadata for the wind resource - wind_resource_representation.reference_height = ( - wind_resource["reference_height"] - if "reference_height" in wind_resource - else None - ) + wind_resource_representation.reference_height = wind_resource_reference_height return wind_resource_representation @@ -165,11 +176,7 @@ def create_windresource_from_windIO( turbulence_intensities=turbulence_intensities, ) # stash some metadata for the wind resource - wind_resource_representation.reference_height = ( - wind_resource["reference_height"] - if "reference_height" in wind_resource - else None - ) + wind_resource_representation.reference_height = wind_resource_reference_height wind_resource_representation.time = ( wind_resource["time"] if "time" in wind_resource else None ) diff --git a/ard/utils/__init__.py b/ard/utils/__init__.py index cdb78752..e69de29b 100644 --- a/ard/utils/__init__.py +++ b/ard/utils/__init__.py @@ -1 +0,0 @@ -from . import test_utils diff --git a/test/ard/unit/cost/test_orbit_wrap.py b/test/ard/unit/cost/test_orbit_wrap.py index 2e6e8766..4c13993b 100644 --- a/test/ard/unit/cost/test_orbit_wrap.py +++ b/test/ard/unit/cost/test_orbit_wrap.py @@ -29,7 +29,9 @@ def test_raise_error(self): "site": { "energy_resource": { "wind_resource": { - "shear": 0.2, + "shear": { + "alpha": 0.2, + }, }, }, }, @@ -211,7 +213,9 @@ def test_baseline_farm(self, subtests): "site": { "energy_resource": { "wind_resource": { - "shear": 0.2, + "shear": { + "alpha": 0.2, + }, }, }, }, @@ -408,7 +412,9 @@ def setup_method(self): "site": { "energy_resource": { "wind_resource": { - "shear": 0.2, + "shear": { + "alpha": 0.2, + }, }, }, }, diff --git a/test/ard/unit/cost/test_wisdem_wrap.py b/test/ard/unit/cost/test_wisdem_wrap.py index 8d4ae901..265b9173 100644 --- a/test/ard/unit/cost/test_wisdem_wrap.py +++ b/test/ard/unit/cost/test_wisdem_wrap.py @@ -26,7 +26,9 @@ def setup_method(self): "site": { "energy_resource": { "wind_resource": { - "shear": 0.2, + "shear": { + "alpha": 0.2, + }, }, }, }, diff --git a/test/ard/unit/farm_aero/test_floris.py b/test/ard/unit/farm_aero/test_floris.py index 387a7113..0a592ddc 100644 --- a/test/ard/unit/farm_aero/test_floris.py +++ b/test/ard/unit/farm_aero/test_floris.py @@ -59,7 +59,9 @@ def setup_method(self): "wind_speed": wind_query.get_speeds().tolist(), "turbulence_intensity": wind_query.get_TIs().tolist(), "time": np.zeros_like(wind_query.get_speeds().tolist()), - "shear": 0.585, + "shear": { + "alpha": 0.585, + }, }, "reference_height": 90.0, }, @@ -204,7 +206,9 @@ def setup_method(self): "wind_speed", ], }, - "shear": 0.585, + "shear": { + "alpha": 0.585, + }, "reference_height": 110.0, }, }, diff --git a/test/ard/unit/farm_aero/test_templates.py b/test/ard/unit/farm_aero/test_templates.py index 0e4529cd..0d148e57 100644 --- a/test/ard/unit/farm_aero/test_templates.py +++ b/test/ard/unit/farm_aero/test_templates.py @@ -7,6 +7,56 @@ import ard.wind_query as wq import ard.farm_aero.templates as templates +import ard.farm_aero.templates as farmaero_templates + + +def _build_timeseries_windio(reference_height=None, h_ref=None): + wind_resource = { + "wind_direction": [270.0, 280.0], + "wind_speed": [8.0, 9.0], + "turbulence_intensity": [0.06, 0.06], + "time": [0, 1], + } + if reference_height is not None: + wind_resource["reference_height"] = reference_height + if h_ref is not None: + wind_resource["shear"] = {"h_ref": h_ref} + + return { + "site": { + "energy_resource": { + "wind_resource": wind_resource, + }, + }, + } + + +class TestWindResourceReferenceHeightAliases: + + def test_reference_height_or_h_ref_single_key(self): + windio_ref = _build_timeseries_windio(reference_height=110.0) + resource_ref = farmaero_templates.create_windresource_from_windIO( + windio_ref, "timeseries" + ) + assert resource_ref.reference_height == 110.0 + + windio_href = _build_timeseries_windio(h_ref=95.0) + resource_href = farmaero_templates.create_windresource_from_windIO( + windio_href, "timeseries" + ) + assert resource_href.reference_height == 95.0 + + def test_reference_height_and_h_ref_same_value(self): + windio = _build_timeseries_windio(reference_height=100.0, h_ref=100.0) + resource = farmaero_templates.create_windresource_from_windIO( + windio, "timeseries" + ) + assert resource.reference_height == 100.0 + + def test_reference_height_and_h_ref_different_values_raise(self): + windio = _build_timeseries_windio(reference_height=100.0, h_ref=101.0) + with pytest.raises(ValueError, match="reference_height.*h_ref"): + farmaero_templates.create_windresource_from_windIO(windio, "timeseries") class TestFarmAeroTemplate: diff --git a/test/conftest.py b/test/conftest.py index 9114d9a2..1d93fba8 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,3 +1,4 @@ +import os from pathlib import Path @@ -6,11 +7,11 @@ def pytest_sessionfinish(session, exitstatus): # for each tempdir for pytest_out_dir in Path().glob("pytest*_out"): - for root, dirs, files in pytest_out_dir.walk( - top_down=False + for root, dirs, files in os.walk( + str(pytest_out_dir), topdown=False ): # walk the directory for name in files: - (root / name).unlink() # remove subdirectory files, and + Path(root, name).unlink() # remove subdirectory files, and for name in dirs: - (root / name).rmdir() # remove subdirectories + Path(root, name).rmdir() # remove subdirectories pytest_out_dir.rmdir() # then remove that tempdir