-
-
Notifications
You must be signed in to change notification settings - Fork 6
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.
Looks good! Just a few comments on maybe simplifying some of the asserts, but thanks for adding all the validation!
@@ -24,5 +24,5 @@ class NWP(DataSourceOutput): | |||
@classmethod | |||
def model_validation(cls, v): | |||
""" Check that all values are not NaNs """ | |||
assert (v.data != np.nan).all(), "Some nwp data values are NaNs" | |||
assert (~np.isnan(v.data)).all(), "Some nwp data values are NaNs" |
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.
What about checking for positive and negative infinity? with
assert (~np.isnan(v.data)).all(), "Some nwp data values are NaNs" | |
assert (~np.isfinite(v.data)).all(), "Some nwp data values are NaNs or infinite" |
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.
Yeah, I agree about using np.isfinite
to test for NaNs, +inf and -inf. But, if we use np.isfinite
, then we'll also need to remove the ~
and tweak the string 🙂
assert (~np.isnan(v.data)).all(), "Some nwp data values are NaNs" | |
assert (np.isfinite(v.data)).all(), "Some nwp data values are NaNs or infinities" |
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.
I'm gona go with both isnan and isinf. I this leads to slightly more verbose error messages
For example
assert (~isnan(v.data)).all(), f"Some pv data values are NaNs"
assert (~isinf(v.data)).all(), f"Some pv data values are Infinite"
@@ -27,5 +27,6 @@ class Satellite(DataSourceOutput): | |||
@classmethod | |||
def model_validation(cls, v): | |||
""" Check that all values are non negative """ | |||
assert (v.data != np.NaN).all(), f"Some satellite data values are NaNs" | |||
assert (~np.isnan(v.data)).all(), f"Some satellite data values are NaNs" |
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.
Same as for NWP
assert (~np.isnan(v.data)).all(), f"Some satellite data values are NaNs" | |
assert (~np.isfinite(v.data)).all(), f"Some satellite data values are NaNs or infinite" |
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.
Same as above 🙂
assert (~np.isnan(v.data)).all(), f"Some satellite data values are NaNs" | |
assert (np.isfinite(v.data)).all(), "Some nwp data values are NaNs" |
@@ -21,5 +21,6 @@ class Topographic(DataSourceOutput): | |||
@classmethod | |||
def model_validation(cls, v): | |||
""" Check that all values are non NaNs """ | |||
assert (v.data != np.NaN).all(), f"Some topological data values are NaNs" | |||
assert (~np.isnan(v.data)).all(), f"Some topological data values are NaNs" | |||
assert (v.data != np.Inf).all(), f"Some topological data values are Infinite" |
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.
Possibly just combining the two asserts might be a bit simpler?
assert (v.data != np.Inf).all(), f"Some topological data values are Infinite" | |
assert (np.isfinite(v.data)).all(), f"Some topological data values are Infinite or NaNs" |
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.
See comment above, think I will keep them separate
assert (~np.isnan(v.data)).all(), f"Some gsp data values are NaNs" | ||
assert (v.data != np.Inf).all(), f"Some gsp data values are Infinite" |
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.
Possibly combine the two asserts with
assert (~np.isnan(v.data)).all(), f"Some gsp data values are NaNs" | |
assert (v.data != np.Inf).all(), f"Some gsp data values are Infinite" | |
assert (np.isfinite(v.data)).all(), f"Some gsp data values are NaNs or infinite" |
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.
See comment above, think I will keep them separate
assert (~np.isnan(v.data)).all(), f"Some pv data values are NaNs" | ||
assert (v.data != np.Inf).all(), f"Some pv data values are Infinite" |
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.
Again, possibly combining the two might be a bit cleaner
assert (~np.isnan(v.data)).all(), f"Some pv data values are NaNs" | |
assert (v.data != np.Inf).all(), f"Some pv data values are Infinite" | |
assert (np.isfinite(v.data)).all(), f"Some pv data values are NaNs or infinite" |
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.
See comment above, think I will keep them separate
assert (~np.isnan(v.elevation)).all(), f"Some elevation data values are NaNs" | ||
assert (v.elevation != np.Inf).all(), f"Some elevation data values are Infinite" | ||
|
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.
Possibly combine these two, or if we do want to keep them separate, changing it to
assert (~np.isnan(v.elevation)).all(), f"Some elevation data values are NaNs" | |
assert (v.elevation != np.Inf).all(), f"Some elevation data values are Infinite" | |
assert (~np.isnan(v.elevation)).all(), f"Some elevation data values are NaNs" | |
assert (~np.isinf(v.elevation)).all(), f"Some elevation data values are Infinite" | |
as I believe np.Inf only counts as positive infinity, and wouldn't check for negative infinity
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.
See comment above, think I will keep them separate
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.
Cool, good idea!
assert (~np.isnan(v.azimuth)).all(), f"Some azimuth data values are NaNs" | ||
assert (v.azimuth != np.Inf).all(), f"Some azimuth data values are Infinite" |
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.
Same as above
Ill put np.isfinite Yea good suggestions, I wanted to put but nan check and infinite check with a different error message, so it's easier to debug. I know that its twice as much work, but its seems like it might be worth it |
Okay, yeah, makes sense! I would then suggest using |
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.
LGTM! Thanks!
Pull Request
Description
Add validation for
Fixes #233
#29
How Has This Been Tested?
Add some unittests to check the errors
Checklist: