Enhancement: Add a Dimension Validator for 5-D and 3-D Array Structures #763
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Validate the Dimensions of 5-D and 3-D Arrays
This PR adds new validation functionality for arrays that should adhere to dimensions requirements of N wind directions x N wind speeds x N turbines or N wind directions x N wind speeds x N turbines x N grid x N grid. An additional mixin class that wraps
attrs.validate(class_instance)
has been added to easily enable attrs class validators to be run at key points in a simulation.Related issue
At least partially resolves #761 by using the
factory=lambda: np.array([])
paradigm to not build extensive carveouts for data that should only be valid at initialization.Impacted areas of the software
floris.type_dec.py
validate_5DArray_shape
is an attrs validator checking the adherence to the shape being N wind directions x N wind speeds x N turbines x N grid x N grid, with the exception of empty arrays and those that can be broadcast along the grid axes.validate_3DArray_shape
is an attrs validator checking the adherence to the shape being N wind directions x N wind speeds x N turbines, with the exception of empty arrays and those that can be broadcast along the wind speed axis.validate_mixed_dim
runs the 5D, then 3D validation to check for theturbulence_intensity
attributes that start as 5D, then are reduced to 3D.array_3D_field
is a custom field for defining a field with the 3D validator and lambda factory built in to reduce the number of multi-line attribute initializations.array_5D_field
is a custom field for defining a field with the 5D validator and lambda factory built into reduce the number of multi-line attribute initializations.array_mixed_dim_field
is a custom field for defining a field with the 3D/5D validator and lambda factory built into reduce the number of multi-line attribute initializations.ValidateMixin
providesself.validate()
, which is a wrapper forattrs.validate(class_instance)
to easily run all validators in a class.floris/simulation/base.py
BaseClass
: now inheritsValidateMixin
floris/simulation/farm.py
andfloris/simulation/flow_field.py
array_3D_field
,array_5D_field
, andarray_mixed_dim_field
as appropriatefloris/simulation/grid.py
array_3D_field
andarray_5D_field
where appropriatefloris/tests/floris_unit_test.py
floris/tests/type_dec_unit_test.py
ValidateMixin.validate()
and the new dimensions validators.Additional supporting information
This largely stems from a conversation with @rafmudaf about questions of how to check if attributes are staying the same shape throughout a simulation, and adding methods to ensure the correctness of dimension sizes.
Test results, if applicable
Tests are passing with a slight modification to an existing test that was using incorrect dimensions.