Skip to content
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]: grid.transform has unnecessary checks for non-periodic dims #606

Open
dhruvbalwada opened this issue May 3, 2023 · 1 comment
Open
Labels

Comments

@dhruvbalwada
Copy link
Contributor

Issue: grid. transform is checking for that even dimensions not being transformed along are not periodic. Peridocity should only checked in the direction that is being transformed (e.g why would a transformation to density grid from depth care if my longitude is periodic).

import xarray as xr 
import xgcm
import numpy as np
import matplotlib.pyplot as plt

# Make the coords
dx = 0.5
L = 20
x_left = np.arange(0,L-dx, dx)
x = np.arange(dx, L, dx)

dz = 10
L = 2000
z_left = np.arange(0,L-dz, dz)
z = np.arange(dz, L, dz)

da_z = xr.DataArray(z, dims=['z'])
da_x = xr.DataArray(x, dims=['x'])

# Make a fake density like profile
da_ones = xr.DataArray(np.ones( (len(x), len(z)) ), dims=['x','z'])
da_rho = da_ones*np.exp(da_z/-1000)

ds = xr.Dataset(coords={'x':da_x, 'xg':x_left, 
                          'z':da_z, 'zg':z_left})
ds['rho'] = da_rho

# Define grid
grid = xgcm.Grid(ds, 
                 coords={"X": {"center": "x", "left": "xg"},
                         "Z": {"center": "z", "left": "zg"}},
                periodic='X')
#                 periodic=False) To make it work

# Rho axis to be used for transformation
rho_ax = np.linspace(0,1, 50)

# do the transform
Z_transformed = grid.transform(ds.z.broadcast_like(ds.rho), 'Z', rho_ax, 
                               target_data=ds.rho)

The above code fails if we say that 'X' is periodic, even though we are transforming along 'Z'.

xgcm.__version__ = '0.8.1'

@hdrake
Copy link

hdrake commented Sep 1, 2023

The periodic argument seems to not longer be working properly, now that it is in process of being deprecated in favor of boundary (and I think eventually both in favor of padding?). I had the same issue as you and the following fixed it for me:

grid = xgcm.Grid(ds, coords=coords, boundary={'X':'periodic', 'Y':'periodic', 'Z':'extend'})

Also fixes #604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants