-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Add a Dimension Validator for 5-D and 3-D Array Structures #763
base: develop
Are you sure you want to change the base?
Enhancement: Add a Dimension Validator for 5-D and 3-D Array Structures #763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @RHammond2, I reviewed this code and all looks good to me! I went through the changes and re-ran the tests locally. Do I understand right the plan is to confirm this all works in 5D, then merge into 4D work and update there?
Thanks, @paulf81, and that's the plan for now, or if the 4D work happens first, this branch will get updated prior to merging. The idea was to keep the work separated and avoiding dependent PRs on either end. |
That sounds good! |
@rafmudaf the examples all work on my machine now, so this should be ready for review. |
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.