-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Bug]: spatial average error following temporal resample #583
Comments
Thanks for reporting this. In trying to see if something obvious was wrong, I ended up having a similar (but different) issue. # grab a random file
wget http://esgf-data.ucar.edu/thredds/fileServer/esg_dataroot/CMIP6/CMIP/NCAR/CESM2-FV2/historical/r1i1p1f1/Amon/pr/gn/v20191120/pr_Amon_CESM2-FV2_historical_r1i1p1f1_gn_185001-189912.nc I get an issue with the resample command
but the following resample string works (and results in a different error message)
|
@arfriedman Can you provide us with a public link to the dataset so we can take a look at it? It looks like the
@pochedls I tried your code but it didn't work for me. The code below works for resampling, but I also get the import xcdat as xc
fn = "/p/css03/esgf_publish/CMIP6/CMIP/NCAR/CESM2-FV2/historical/r1i1p1f1/Amon/pr/gn/v20191120/pr_Amon_CESM2-FV2_historical_r1i1p1f1_gn_185001-189912.nc"
# Resampling works
ds = xc.open_dataset(fn)
ds = ds.resample(time="3M").sum()
# ValueError: More than one grid cell spans prime meridian.
ds_3m_avg = ds.spatial.average("pr") |
Thanks @tomvothecoder – I pasted in the wrong code excerpt (I also used In looking at this again, I think the longitude bounds get messed up after @arfriedman – Do your bounds also change? Is there a way to use resample while retaining the lon_bnds shape? A potential workaround in this case is to copy the original bounds to the dataset after re-sample. ds_resampled['lon_bnds'] = ds_original.lon_bnds
ds_resampled['lat_bnds'] = ds_original.lat_bnds @tomvothecoder / @arfriedman – do you think this is an xarray issue / question? original boundsds = xc.open_dataset(fn)
print(ds.lon)
print(ds.lon_bnds.values)
print(ds.lon_bnds.shape)
Bounds after re-sample
print(ds2.lon_bnds.values)
print(ds2.lon_bnds.shape)
|
Thanks @tomvothecoder and @pochedls. @tomvothecoder here's a link to the model output -- apologies for the large file size: @pochedls I confirm that spatial averaging works after applying your work-around of copying the original dataset lat and lon bounds. To me this does suggest that the issue is from xarray. |
If anybody is interested, reviving the thread sounds like a good idea since the last comment was from early 2022. ExampleBefore resampling -- no time dimension on "lat_bnds" and "lon_bnds" ds = xc.open_dataset(fn)
print(ds.data_vars)
"""
Data variables:
pr (time, lat, lon) float32 ...
time_bnds (time, nbnd) object ...
lat_bnds (lat, nbnd) float64 ...
lon_bnds (lon, nbnd) float64 ...
""" After resampling -- time dimension added to "lat_bnds" and "lon_bnds" -> breaks spatial averaging ds_3m = ds.resample(time="3M").sum()
"""
Data variables:
pr (time, lat, lon) float32 2.919e-06 2.918e-06 ... 4.918e-06
lat_bnds (time, lat, nbnd) float64 -90.95 -89.05 -89.05 ... 89.05 90.95
lon_bnds (time, lon, nbnd) float64 -1.25 1.25 1.25 ... 356.2 356.2 358.8
""" WorkaroundUse bounds from the original dataset ds_3m["lat_bnds"] = ds.lat_bnds.copy()
ds_3m["lon_bnds"] = ds.lon_bnds.copy()
ds_3m_avg = ds_3m.spatial.average("pr") |
Closing this issue since it is rooted in Xarray |
What happened?
I am encountering an error when taking an xcdat spatial average following xarray temporal resampling.
I am working with monthly model precipitation output named pr_mon:
Taking a spatial average of this monthly variable works fine:
In [8]: pr_mon_avg = pr_mon.spatial.average("precip")
However, after I temporally resample the data using xarray, xcdat spatial averaging returns an error. Here is an example for a three-month temporal sum:
Do you know what might account for this error?
What did you expect to happen? Are there are possible answers you came across?
No response
Minimal Complete Verifiable Example (MVCE)
No response
Relevant log output
No response
Anything else we need to know?
No response
Environment
xCDAT version 0.6.1
In [13]: xr.show_versions()
/home/andrew/miniconda3/envs/Nile-Laki/lib/python3.11/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
INSTALLED VERSIONS
commit: None
python: 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0]
python-bits: 64
OS: Linux
OS-release: 5.15.0-86-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.3
libnetcdf: 4.9.2
xarray: 2023.12.0
pandas: 2.1.4
numpy: 1.26.2
scipy: 1.11.4
netCDF4: 1.6.5
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.3
nc_time_axis: None
iris: None
bottleneck: None
dask: 2023.12.1
distributed: 2023.12.1
matplotlib: 3.8.2
cartopy: 0.22.0
seaborn: None
numbagg: None
fsspec: 2023.12.2
The text was updated successfully, but these errors were encountered: