-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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_iris' and 'from_iris' to methods Dataset #2449
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.
My only hesitation here is on the name: is it entirely obvious that Dataset.to_iris()
should produce a CubeList? Maybe Dataset.to_iris_cubelist()
?
I guess Iris doesn't have other high level data structures for multiple cubes, so this is the obvious choice.
def dataset_from_iris(cubelist): | ||
""" Convert an Iris CubeList into a Dataset. | ||
""" | ||
return Dataset({cube.var_name: DataArray.from_iris(cube) for cube in cubelist}) |
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.
Can we use the name
attribute already on DataArray.from_iris(cube)
? We have some special logic already for figuring out names in DataArray.from_iris
.
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.
So cube.name
instead of cube.var_name
?
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 say DataArray.from_iris(cube).name
, but it probably makes sense save it in an intermediate variable to avoid converting the cube twice.
Thanks for the feedback. I think when working in iris that you expect multiple cubes to be returned as a cube list. Also when calling I would propose that |
I'm happy to defer to Iris users (like you) on what they would expect for converting to/from an xarray.Dataset. |
Apologies about adding my thoughts after a bit of a gap on here...
I like the
Does this logic include handling multiple cubes of the same name in a single CubeList? Iris will quite happily handle this, but I guess the name:DataArray mapping in Xarray requires unique names. For example: >>> names = [c.name() for c in cubes]
>>> print(names)
['air_pressure', 'air_pressure', 'air_pressure_at_sea_level', 'air_temperature', 'air_temperature', 'air_temperature', 'air_temperature', 'air_temperature', 'dew_point_temperature', 'geopotential_height', 'relative_humidity', 'relative_humidity', 'specific_humidity', 'surface_air_pressure', 'upward_air_velocity', 'x_wind', 'x_wind', 'x_wind', 'y_wind', 'y_wind', 'y_wind'] The differences between these cubes is one or more of:
If such a case isn't currently handled, it could be handled by using this differing metadata to modify the name used for the key; for example |
@DPeterK / @jacobtomlinson - this has grown quite stale. Any interest in finishing this up or should we close this in favor of a new contribution down the line? |
@pp-mo 👀 |
@jhamman this PR is 5 years old and my need for it has long since gone away. If other folks want to pick this up that would be awesome. |
This PR adds
to_iris
andfrom_iris
methods to DataSet. I've added this because I frequently find myself writing little list and dictionary comprehensions to pack and unpack both DataSets from DataArrays and Iris CubeLists from Cubes.whats-new.rst
for all changes andapi.rst
for new API