Skip to content
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

Initial xarray support #35

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

magnusuMET
Copy link
Contributor

It is fairly easy to implement support for using xarray with fimex as a reader. I am opening this PR in the hope this will be useful for others who use xarray

There is still a lot to do to support more features of xarray, but this should cover the basic API

data = self.fh.getDataSliceSB(vname, slicebuilder)
datav = data.values()
data_shaped = np.reshape(datav, dimsizes)
if self.scale_offset:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using getScaledDataSliceSB and let fimex do the scale/offset handling

@alexander-buerger-met-no
Copy link
Member

Thanks. I think that the scale and offset handling should be replaced with getScaledDataSlice or so, or at least that the code from lines 50-60 and 160-170 should be moved into a function.

I wonder why you commented out the pyfimex0 dependency in pyproject.toml.

Did you try putting this into modules/python?

var = np.array([np.datetime64(int(v), "s") for v in var])

coords["time"] = var

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what this should do in xarray, but the time-variable in netcdf is every variable with a time unit, i.e. 'days since 2005-09-03 +15:00'. One cannot rely on the dimension-name, and that there is only one "time"-axis per file.
Fimex supports conversion of the time-units, i.e. by getScaledDataSizeInUnit(...) so you can get a unified handling (needs doubles or quads, I would say). Not really sure what you do her (expect time to be epoch-seconds?).

add_offset = cdm.getAttribute(cname, "add_offset").getData().values()
except RuntimeError:
add_offset = 0
values = values*scale_factor + add_offset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use getScaledData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants