-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add xarray support to MathematicalExpression
#621
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report
@@ Coverage Diff @@
## master #621 +/- ##
==========================================
- Coverage 94.62% 94.56% -0.07%
==========================================
Files 93 93
Lines 5936 5958 +22
==========================================
+ Hits 5617 5634 +17
- Misses 319 324 +5
Continue to review full report at Codecov.
|
I updated the schema and did some small refactoring. @CagtayFabry You might want to have a look at the changes. If there are no further concerns, I will merge this PR after lunch. |
anyOf: | ||
- wx_property_tag: "asdf://weldx.bam.de/weldx/tags/core/data_array-0.1.*" | ||
- wx_property_tag: "asdf://weldx.bam.de/weldx/tags/units/quantity-0.1.*" |
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 would prefer if we don't have data_array here as it is very verbose, that should still be possible right? @vhirtham
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.
Well, the solution would be to not use data arrays as parameters if you don't need to. But if I have a multi-dimensional equation that uses data arrays as parameters to make my life easier, I can't store it in asdf unless I sort out the dimensions myself and restore the parameters as quantities.
if we want to allow data_array tags in the schema we should bump the schema version (which I would like to avoid for the 0.5.x releases) |
Since the schema is now less restrictive, no existing file will break. Furthermore, the current userbase is just us. So I think we can get away with not bumping the version. |
true, but I find the xarray schema for simple things like this borderline unreadable in the schema can some parameters be passed as xarray and others as quantities in the current python implementation? |
weldx/core.py
Outdated
@@ -450,7 +467,7 @@ def _interp_time_discrete(self, time: Time) -> xr.DataArray: | |||
"""Interpolate the time series if its data is composed of discrete values.""" | |||
return ut.xr_interp_like( | |||
self._data, | |||
{"time": time.as_timedelta()}, | |||
{"time": time.as_timedelta_index()}, |
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.
we should pass the reference time here as well
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.
well, if you use as_data_array
here, you get the "non-monotonic" error I mentioned above 😉
Why in the schema? Did you mean the written file?
If this is a problem it needs to be addressed in a follow-up issue/PR.
Yes. Every parameter is stored internally (and also written to asdf) as a quantity unless it is a |
In that case I guess the schema wouldn't work for 'mixed' parameters anyway since I'll catch up with you later so we can discuss in detail :) |
All right, I will take care of the tutorials in the meantime. |
Just implemented the matadata approach and tested it. Works like a charm. I will add the tuple construction tomorrow and add a warning if coordinates are dropped. |
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 really clean now 👍
Changes
MathematicalExpression
now uses xarray internally. This can simplify multi-dimensional expressions if one usesDataArray
s with correctly named dimensions. If noDataArray
s are used as parameters and variables, the behavior should remain more or less the same since xarray will automatically add dimension names.In the current version
evaluate
will now return aDataArray
instead of a quantity. This requires some changes to the internals of theTimeSeries
. However, when those changes are fully applied, theTimeSeries
implementation should be much simpler than before.Related Issues
Closes #619
Checks