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 to_xarray as field method #123
Conversation
to_xarray returns field values as xarray.DataArray
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. I left a few minor comments.
Please do ignore the failing |
Codecov Report
@@ Coverage Diff @@
## master #123 +/- ##
==========================================
+ Coverage 95.46% 95.58% +0.11%
==========================================
Files 20 20
Lines 1986 2038 +52
==========================================
+ Hits 1896 1948 +52
Misses 90 90
Continue to review full report at Codecov.
|
Check `field.components` is not `None` before assigning it as `comp` co-ordinate values. Assigning `None` as a dimention co-ordinate throws an error.
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.
Great code @swapneelap. I added a few very minor comments.
This looks good. Do we have tests for this method yet? If not, we need one. Martin or I can help to suggest some. |
No, I have not added the tests yet. Yes, it's a good idea to discuss them! |
It is possible to create mesh where attributes donot have `unit` key which ultimately breaks to_xarray function
for more information, see https://pre-commit.ci
… into field-to-xarray
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.
This looks good to me - great work! We can further simplify this code when @lang-m finishes implementing midpoints and vertices :)
- Remove cells showing raised exceptions from `to_xarray` and `from_xarray` for better readability. - Add `print()` to display `xarray.DataArray` as the html representation gives `pytest` errors with nbval.
To avoid problems with nbval all cells that contain xarray html output are tagged with nbval-ignore-output. That way we do not compare the actual html representation (which we don't need to) but we would still notice when the cell execution fails.
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.
The documentation looks good to me, it is very readable. I've removed the print
for the xarray DataArrays to get the nicer-looking html representation and tagged the relevant cells to avoid failures of nbval.
I would suggest to keep this PR open until we can use the new mesh.midpoints
.
Thank you, that sounds good. I will update the methods when you merge the changes. |
Very nice @swapneelap! |
An important improvement - thank you! |
Thank you all for your reviews and comments! It helped in making the methods concise, readable, and efficient. :) |
Adding
to_xarray
method forField
object which returns field value as anxarray.DataArray
.x
,y
,z
, andcomp
. The first three corresponds to geometry while the fourth dimension corresponds to the components of field.comp
dimension hasfield.components
as co-ordinates.Field
object is a scalar field, thecomp
dimension is 'squeezed' and the DataArray has only three dimensions corresponding to the geometry.comp
) the name of the field, the name is assigned to the DataArray itself. The default name is'field'
, but it can be changed withname
parameter.units
parameter. Units of geometry dimensions are set tomesh.attributes['unit']
if the attribute exists, otherwise set to'm'
(meter).