Skip to content
Open
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
9 changes: 0 additions & 9 deletions ard/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 3 additions & 9 deletions ard/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions ard/farm_aero/floris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 17 additions & 10 deletions ard/farm_aero/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand Down
1 change: 0 additions & 1 deletion ard/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import test_utils
12 changes: 9 additions & 3 deletions test/ard/unit/cost/test_orbit_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_raise_error(self):
"site": {
"energy_resource": {
"wind_resource": {
"shear": 0.2,
"shear": {
"alpha": 0.2,
},
},
},
},
Expand Down Expand Up @@ -211,7 +213,9 @@ def test_baseline_farm(self, subtests):
"site": {
"energy_resource": {
"wind_resource": {
"shear": 0.2,
"shear": {
"alpha": 0.2,
},
},
},
},
Expand Down Expand Up @@ -408,7 +412,9 @@ def setup_method(self):
"site": {
"energy_resource": {
"wind_resource": {
"shear": 0.2,
"shear": {
"alpha": 0.2,
},
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion test/ard/unit/cost/test_wisdem_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def setup_method(self):
"site": {
"energy_resource": {
"wind_resource": {
"shear": 0.2,
"shear": {
"alpha": 0.2,
},
},
},
},
Expand Down
8 changes: 6 additions & 2 deletions test/ard/unit/farm_aero/test_floris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -204,7 +206,9 @@ def setup_method(self):
"wind_speed",
],
},
"shear": 0.585,
"shear": {
"alpha": 0.585,
},
"reference_height": 110.0,
},
},
Expand Down
50 changes: 50 additions & 0 deletions test/ard/unit/farm_aero/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path


Expand All @@ -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
Loading