Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into move-data-schema-t…
Browse files Browse the repository at this point in the history
…o-common
  • Loading branch information
bayc committed Aug 28, 2024
2 parents 4ed8dd5 + 47058b7 commit 43e7c8c
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 8 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies:
- numpy
- pyyaml
- pytest
- pytest-subtests
- xarray
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EXTRAS = {
"test": {
'pytest',
'pytest-subtests',
'py_wake',
'topfarm',
},
Expand Down
587 changes: 587 additions & 0 deletions test/plant/conftest.py

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions test/plant/wind_farm_schema_unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import numpy as np
import numpy.testing as npt
import pytest
from windIO.utils.yml_utils import load_yaml, validate_yaml
from windIO.utils import plant_examples_data_path, plant_schemas_path
from test.plant.conftest import SampleInputs
from jsonschema.exceptions import ValidationError


def test_wind_farm_input(subtests):
"""
Test a complete wind_farm set of inputs, and ensure that
optional properties can be excluded.
"""
with subtests.test("with valid config"):
config = SampleInputs().wind_farm
assert validate_yaml(config, plant_schemas_path + "wind_farm.yaml") is None

with subtests.test("remove optional electrical_substations"):
config = SampleInputs().wind_farm
del config["electrical_substations"]
assert validate_yaml(config, plant_schemas_path + "wind_farm.yaml") is None

with subtests.test("remove optional electrical_collection_array"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]
assert validate_yaml(config, plant_schemas_path + "wind_farm.yaml") is None


def test_wind_farm_invalid_inputs_layouts(subtests):
"""
Test missing inputs for the wind_farm layouts property.
"""
with subtests.test("missing layouts"):
config = SampleInputs().wind_farm
del config["layouts"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing layouts initial_layout"):
config = SampleInputs().wind_farm
del config["layouts"]["initial_layout"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing layouts initial_layout coordinates"):
config = SampleInputs().wind_farm
del config["layouts"]["initial_layout"]["coordinates"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")


def test_wind_farm_invalid_inputs_turbines(subtests):
"""
Test missing inputs for the wind_farm turbines property.
"""
with subtests.test("missing turbines"):
config = SampleInputs().wind_farm
del config["turbines"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")


def test_wind_farm_invalid_inputs_electrical_substations(subtests):
"""
Test missing inputs for the wind_farm electrical_substation property.
"""
with subtests.test("missing electrical_substation"):
config = SampleInputs().wind_farm
del config["electrical_substations"][0]["electrical_substation"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_substation coordinates"):
config = SampleInputs().wind_farm
del config["electrical_substations"][0]["electrical_substation"]["coordinates"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("remove optional electrical_substation capacity"):
config = SampleInputs().wind_farm
del config["electrical_substations"][0]["electrical_substation"]["capacity"]
assert validate_yaml(config, plant_schemas_path + "wind_farm.yaml") is None

def test_wind_farm_invalid_inputs_electrical_collection_array(subtests):
"""
Test missing inputs for the wind_farm electrical_collection_array property.
"""
with subtests.test("missing electrical_collection_array edges"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["edges"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_collection_array cables"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["cables"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_collection_array cables cable_type"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["cables"]["cable_type"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_collection_array cables cross_section"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["cables"]["cross_section"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_collection_array cables capacity"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["cables"]["capacity"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")

with subtests.test("missing electrical_collection_array cables cost"):
config = SampleInputs().wind_farm
del config["electrical_collection_array"]["cables"]["cost"]
with pytest.raises(ValidationError):
validate_yaml(config, plant_schemas_path + "wind_farm.yaml")
11 changes: 11 additions & 0 deletions windIO/plant/energy_resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ properties:
friction_velocity:
title: Friction velocity (m/s)
$ref: "common.yaml#/definitions/multi_dimensional_data"
ground_temperature:
title: Ground Temperature (K)
description: Temperature of the ground in Kelvin
$ref: "common.yaml#/definitions/multi_dimensional_data"
stability:
title: Stability of the atmosphere
description: Roughness length in meters
$ref: "common.yaml#/definitions/multi_dimensional_data"
capping_inversion:
title: Capping Inversion
type: boolean


# DEFINITIONS
Expand Down
96 changes: 88 additions & 8 deletions windIO/plant/wind_farm.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,119 @@
input_format_version: 0
title: definition of the wind energy conversion system
title: Definition of the wind energy conversion system
description: A file used to define the built environment (and other non-tangible components like O&M)
required:
- name
- layouts
- turbines
optional:
- electrical_substations
- electrical_collection_array
- foundations
- O_&_M
additionalProperties: false

# PROPERTIES
properties:
#~
name:
description: Name of the wind farm
type: string
layouts:
description: Position of wind turbines
type: object
required:
- initial_layout
additionalProperties: false
properties:
inital_layout:
$ref: "#/definitions/layout"
initial_layout:
$ref: "#/definitions/initial_layout"

turbines:
description: Turbine models installed in the WES.
description: Turbine models installed in the WES
type: object
$ref: "turbine.yaml#"
#~
electrical_substations:
description: Information about electrical substations
type: array
items:
type: object
required:
- electrical_substation
additionalProperties: false
properties:
electrical_substation:
$ref: "#/definitions/electrical_substation"

electrical_collection_array:
title: Electrical collection array
description: Definition of electrical collection array (cable layout) for wind farm.
type: object
required:
- edges
- cables
additionalProperties: false
properties:
edges:
title: Edges of cable layout
description: List of edges (branches) in the cable layout [[from_node, to_node, cable_type], ...].
type: array
cables:
title: Cables
description: List of the cables
type: object
required:
- cable_type
- cross_section
- capacity
- cost
additionalProperties: false
properties:
cable_type:
title: Cable type
description: List of aviable cable types
type: array
units: mm2
cross_section:
title: Cross section
description: List of cables cross section
type: array
units: mm2
capacity:
title: Cable capacity
description: List of cable capacity
type: array
units: WindTurbine / Cable
cost:
title: Cable cost
description: List of cables cost
type: array
units: euro/meter

definitions:
inital_layout:
initial_layout:
title: Wind turbine layout
type: object
required:
- coordinates
additionalProperties: false
properties:
coordinates:
title: Wind turbine coordinate
$ref: "common.yaml#/definitions/coordinates"


electrical_substation:
title: Electrical substation
type: object
required:
- coordinates
optional:
- capacity
additionalProperties: false
properties:
coordinates:
title: Substation coordinates
$ref: "common.yaml#/definitions/coordinates"
capacity:
title: Substation capacity
description: Capacity of the electrical substation in megawatts
type: number
units: MW

0 comments on commit 43e7c8c

Please sign in to comment.