I ran into this issue during e3sm_diags development while testing a function to reconstruct pressure levels.
I passed a single pressure level (e.g., plevs=[800]) to create_axis("lev", plevs, generate_bounds=True) and it threw an error about generating bounds requiring > 1 data points.
To workaround this, I tried setting generate_bounds=False. However, I ran into the issue of create_grid breaking because of a bug in the conditional for copying bounds as described below.
Steps to reproduce (refer to MVCE):
Use z_axis = xc.create_axis(...generate_bounds=False), which will return a tuple consisting of (xr.DataArray, None).
Pass this tuple as an argument to xc.create_grid(z=z_axis)
xc.create_grid breaks on line 544 -- AttributeError: 'NoneType' object has no attribute 'copy'
This line attempts to deep copy bounds (the second element of the tuple), which breaks since it is None.
import xcdat as xc
plevs = [800, 200]
# Create the output pressure grid to regrid to using the `plevs` array.
z_axis = xc.create_axis("lev", plevs, generate_bounds=False)
pressure_grid = xc.create_grid(z=z_axis)
Relevant log output
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/global/homes/v/vo13/mambaforge/envs/e3sm_diags_dev_658/lib/python3.10/site-packages/xcdat/regridder/grid.py", line 544, in create_grid
axis, bnds = item[0].copy(deep=True), item[1].copy(deep=True) # type: ignore[union-attr]
AttributeError: 'NoneType' object has no attribute 'copy'
What happened?
I ran into this issue during e3sm_diags development while testing a function to reconstruct pressure levels. I passed a single pressure level (e.g.,
plevs=[800]
) tocreate_axis("lev", plevs, generate_bounds=True)
and it threw an error about generating bounds requiring > 1 data points.To workaround this, I tried setting
generate_bounds=False
. However, I ran into the issue ofcreate_grid
breaking because of a bug in the conditional for copying bounds as described below.Steps to reproduce (refer to MVCE):
z_axis = xc.create_axis(...generate_bounds=False)
, which will return a tuple consisting of(xr.DataArray, None)
.xc.create_grid(z=z_axis)
xc.create_grid
breaks on line 544 --AttributeError: 'NoneType' object has no attribute 'copy'
None
.What did you expect to happen? Are there are possible answers you came across?
The conditional to check the argument type for
create_grid
should also check if the second element isNone
and execute the appropriate logichttps://github.com/xCDAT/xcdat/blob/08cfea37cf47454abea83de66cf7677ab157708b/xcdat/regridder/grid.py#L532-L553
Minimal Complete Verifiable Example (MVCE)
Relevant log output
Anything else we need to know?
No response
Environment
xcdat=0.6.0rc1 and main branch