Keeping unused dimensions when opening a Dataset?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
I am attempting to open a dataset which has unused dimensions. Is it possible for this information to be retained?
import xarray as xr
import netCDF4
import numpy as np
# create dataset with dims x, y and a variable f
f = netCDF4.Dataset("test.nc", "w")
f.createDimension("x", 2)
f.createDimension("y", 3)
f.createVariable("f", np.float32)
print(f)
f.close()
print('\n')
# open dataset with xarray
ds = xr.open_dataset('test.nc')
print(ds)
This prints the following:
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
dimensions(sizes): x(2), y(3)
variables(dimensions): float32 f()
groups:
<xarray.Dataset> Size: 4B
Dimensions: ()
Data variables:
f float32 4B ...
The output of ncdump test.nc is shown here:
netcdf test {
dimensions:
x = 2 ;
y = 3 ;
variables:
float f ;
data:
f = _ ;
}
This appears to be the same issue as was discussed here, but I could not find if the OP ever opened an issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python reproduction with netCDF4 and xarray.open_dataset, then trace how the unused dimensions are represented after opening the file. Done means the opened xarray.Dataset retains dimensions x and y with their sizes, and the behavior is covered by a regression test based on this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100