Floats instead of integer for lat/lon settings in xarray coarsen function #6266
Unanswered
jwynnsmith
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I personally mostly use cdo, even though it is a bit more clumsy to use, because it supports more grids and regridding schemes, but depending on your use case xESMF might be enough for you. I add an example how to use cdo from python because I find it non-trivial to do (it reads and writes a netCDF file from and to disk): import cdo
CDO = cdo.Cdo()
CDO.remapcon2(
f'{target_grid}.txt', options='-b F64', input=load_filename, output=save_filename
) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I will compare a downscaled (upsampled) goes16 grid to a coarse 1.25 degree lon by 1 degree lat model grid.
To match the precise collocated obs vs model grids I will need to use floats for the lat/lon settings in xarray coarsen. When I do that I get the error below that basically says lon and lat have to be integers. Is there any way to override or ignore this error to get the function coarsen function to calculate with the float datatype? (i.e. try except [did not work for me but maybe I have commands out of order])
Error message here:
glm_downscale = ds.coarsen(lon=41.75, lat=33.42, boundary=‘pad’).mean()
File “/app/spack/v0.15/linux-rhel7-x86_64/gcc-4.8.5/python/3.7.7-d6cyi6ophaei6arnmzya2kn6yumye2yl/lib/python3.7/site-packages/xarray/core/rolling.py”, line 1036, in wrapped_func
**kwargs,
File “/app/spack/v0.15/linux-rhel7-x86_64/gcc-4.8.5/python/3.7.7-d6cyi6ophaei6arnmzya2kn6yumye2yl/lib/python3.7/site-packages/xarray/core/variable.py”, line 2194, in coarsen
reshaped, axes = self.coarsen_reshape(windows, boundary, side)
File “/app/spack/v0.15/linux-rhel7-x86_64/gcc-4.8.5/python/3.7.7-d6cyi6ophaei6arnmzya2kn6yumye2yl/lib/python3.7/site-packages/xarray/core/variable.py”, line 2248, in coarsen_reshape
variable = variable.pad(pad_width, mode=“constant”)
File “/app/spack/v0.15/linux-rhel7-x86_64/gcc-4.8.5/python/3.7.7-d6cyi6ophaei6arnmzya2kn6yumye2yl/lib/python3.7/site-packages/xarray/core/variable.py”, line 1350, in pad
**pad_option_kwargs,
File “/app/spack/v0.15/linux-rhel7-x86_64/gcc-4.8.5/python/3.7.7-d6cyi6ophaei6arnmzya2kn6yumye2yl/lib/python3.7/site-packages/xarray/core/duck_array_ops.py”, line 56, in f
return wrapped(*args, **kwargs)
File “<array_function internals>”, line 6, in pad
File “/home/Jonathan.Smith/.local/lib/python3.7/site-packages/numpy/lib/arraypad.py”, line 740, in pad
raise TypeError(’pad_width must be of integral type.’)
TypeError: pad_width must be of integral type.
Thanks,
Jonathan
Beta Was this translation helpful? Give feedback.
All reactions