Skip to content

Using 2D latitude and longitude as dims in power spectrum #198

Open
@vic1309

Description

@vic1309

Hello all

First of all, congratulations for the nice package.

I have a set of gridded variables. Latitude and longitude have NxN dimensions. A snippet is provided below:

# Define shape of the area
dx = 2.5
dy = dx

Nx = np.shape(eke[:,:])[1] # N of points in x 
Ny = np.shape(eke[:,:])[0] # N of points in y

Lx = Nx*dx
Ly = Ny*dy

x = np.arange(0, Lx, dx)
y = np.arange(0, Ly, dy)

# Build Array
LAT = df.lat.values[p0-pr:p0+pr, p1-pr:p1+pr]
LON = df.lon.values[p0-pr:p0+pr, p1-pr:p1+pr]

uo = xr.DataArray(eke, coords={'x':x, 'y':y, 'lat':(['x','y'], LAT), 'lon': (['x','y'], LON)}, dims=('x', 'y'))

where EKE is my 2D field.

When I run:

iso = xrft.isotropic_power_spectrum(uo, dim=['x','y'], detrend='linear', window=True)

I get the following error:

ValueError: The input array contains coordinate variable(s) (['lat', 'lon']) whose dims include the transform dimension(s) `x`. Please drop these coordinates (`.drop(['lat', 'lon']`) before invoking xrft.

Any ideas on how to solve it? I can provided the eke file if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions