Skip to content

[Feature request] Specify number of significant digits for lat/lon coordinates? #3321

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

Closed
mariellep opened this issue Sep 19, 2019 · 2 comments

Comments

@mariellep
Copy link

mariellep commented Sep 19, 2019

Problem Description

I'm working with netCDF files that have a spatial resolution of 1.25 degrees. However, on some of these files, the coordinates have a trailing float so that -88.75 becomes -88.750008 etc. When using xr.open_mfdataset, this means that rather than having lat/lon dimensions of (145, 288) like I would see on a single file, I have lat/lon dimensions of (230, 467) and nans interspersed throughout the dataset due to misaligned grids. Therefore, it would be useful to be able to limit the number of trailing digits to 2 or 3 so that I don't run into this issue in the future!

MCVE Code Sample

d_mf=xa.open_mfdataset(flist_rean['JRA'])
v1=d_mf['ua'].isel(time=0,plev=21)
print(v1)
# which returns:
<xarray.DataArray 'ua' (lat: 230, lon: 467)>
dask.array<shape=(230, 467), dtype=float32, chunksize=(230, 467)>
Coordinates:
  * lat      (lat) float64 -90.0 -88.75 -88.75 -87.5 ... 88.75 88.75 90.0 90.0
  * lon      (lon) float64 0.0 1.25 2.5 3.75 3.75 ... 357.5 357.5 358.8 358.8
#... etc. As you can see, there are multiple values for these coordinates!

#if we look at the values:
v1.values
array([[-15.603317  , -15.665817  , -15.728317  , ..., -15.447067  ,
                 nan, -15.540817  ],...#truncated for ease of viewing

Expected Output

#This is opening a single file
x1=xa.open_dataset(flist_rean['JRA'][0]).isel(time=0,plev=21)
print(x1)
<xarray.Dataset>
Dimensions:                (lat: 145, lon: 288)
Coordinates:
  * lat                    (lat) float32 90.00001 88.75001 ... -88.75001 -90.0
  * lon                    (lon) float32 0.0 1.25 2.5 ... 357.50003 358.75003

x1['ua'].values
array([[-15.603317  , -15.665817  , -15.728317  , ..., -15.384567  ,
        -15.447067  , -15.540817  ],...#truncated for ease of viewing

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.12.14-150.27-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.1
xarray: 0.11.3
pandas: 0.24.2
numpy: 1.16.2
scipy: 1.2.1
netCDF4: 1.4.2
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.3.4
PseudonetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
cyordereddict: None
dask: 1.1.5
distributed: None
matplotlib: 3.0.3
cartopy: None
seaborn: 0.9.0
setuptools: 40.8.0
pip: 19.0.3
conda: None
pytest: None
IPython: 7.4.0
sphinx: None

@dcherian
Copy link
Contributor

Thanks for opening this issue. The underlying issue is #2217.

Until that gets solved, you can specify join='override' after updating xarray to 0.13.0. this will skip alignment and should do what you want.

Let us know if that works for you.

@mariellep
Copy link
Author

Hmmm. I added in the join='override' flag as suggested and it still exhibits the same behavior. However, if I do the following:

xtest=xa.open_mfdataset(flist_rean['JRA'],join='override',combine='nested',concat_dim='time')

then it seems to work!

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

No branches or pull requests

2 participants