-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
dataset writeRelating to writing datasetsRelating to writing datasetsenhancementNew feature or requestNew feature or requestxarrayRelated to xarray datasetsRelated to xarray datasets
Milestone
Description
It would be nice to be able to convert cf.Field, cf.Domain, cf.FieldList, cf.DomainList constructs to xarray datasets in memory.
E.g.
>>> import cf
>>> f = cf.example_field(0)
>>> ds = f.to_xarray()
>>> ds
<xarray.Dataset> Size: 640B
Dimensions: (lat: 5, lon: 8, bounds2: 2)
Coordinates:
* lat (lat) float64 40B -75.0 -45.0 0.0 45.0 75.0
* lon (lon) float64 64B 22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5
time float64 8B dask.array<chunksize=(), meta=np.ndarray>
Dimensions without coordinates: bounds2
Data variables:
lat_bnds (lat, bounds2) float64 80B dask.array<chunksize=(5, 2), meta=np.ndarray>
lon_bnds (lon, bounds2) float64 128B dask.array<chunksize=(8, 2), meta=np.ndarray>
q (lat, lon) float64 320B dask.array<chunksize=(5, 8), meta=np.ndarray>
Attributes:
Conventions: CF-1.13
>>>>>> f.nc_set_variable('/forecast/model/q')
>>> ds = f.to_xarray()
>>> ds
<xarray.DataTree>
Group: /
│ Dimensions: (lat: 5, lon: 8, bounds2: 2)
│ Coordinates:
│ * lat (lat) float64 40B -75.0 -45.0 0.0 45.0 75.0
│ * lon (lon) float64 64B 22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5
│ time float64 8B dask.array<chunksize=(), meta=np.ndarray>
│ Dimensions without coordinates: bounds2
│ Data variables:
│ lat_bnds (lat, bounds2) float64 80B dask.array<chunksize=(5, 2), meta=np.ndarray>
│ lon_bnds (lon, bounds2) float64 128B dask.array<chunksize=(8, 2), meta=np.ndarray>
│ Attributes:
│ Conventions: CF-1.13
└── Group: /forecast
└── Group: /forecast/model
Dimensions: (lat: 5, lon: 8)
Data variables:
q (lat, lon) float64 320B dask.array<chunksize=(5, 8), meta=np.ndarray>
>>>>>> ds = cf.write(f, fmt='XARRAY')
>>> ds
<xarray.DataTree>
Group: /
│ Dimensions: (lat: 5, lon: 8, bounds2: 2)
│ Coordinates:
│ * lat (lat) float64 40B -75.0 -45.0 0.0 45.0 75.0
│ * lon (lon) float64 64B 22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5
│ time float64 8B dask.array<chunksize=(), meta=np.ndarray>
│ Dimensions without coordinates: bounds2
│ Data variables:
│ lat_bnds (lat, bounds2) float64 80B dask.array<chunksize=(5, 2), meta=np.ndarray>
│ lon_bnds (lon, bounds2) float64 128B dask.array<chunksize=(8, 2), meta=np.ndarray>
│ Attributes:
│ Conventions: CF-1.13
└── Group: /forecast
└── Group: /forecast/model
Dimensions: (lat: 5, lon: 8)
Data variables:
q (lat, lon) float64 320B dask.array<chunksize=(5, 8), meta=np.ndarray>
>>>See also NCAS-CMS/cfdm#394
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dataset writeRelating to writing datasetsRelating to writing datasetsenhancementNew feature or requestNew feature or requestxarrayRelated to xarray datasetsRelated to xarray datasets