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

multi dimensional coordinates #44

Open
markcollier opened this issue May 21, 2021 · 1 comment
Open

multi dimensional coordinates #44

markcollier opened this issue May 21, 2021 · 1 comment

Comments

@markcollier
Copy link

Hi, is it possible to generate derivatives of multi dimensional coordinates, for example curvilinear (2d) latitude longitude grids? I have tried the following example which does not work:

lat = np.array(( ((50,60), (55,65), (60,70)) ),dtype=float)
lon = np.array(( ((0,180), (0,180), (0,180)) ),dtype=float)

print('lat.shape=',lat.shape)
print('lon.shape=',lon.shape)

d_dlon = FinDiff(1, lon, acc=2)

print(d_dlon)

time = np.array((1,3,5,7), dtype=float)

data = np.array(( (((3,5), (6,2), (4,3)), ((3,5), (6,2), (4,3)), ((3,5), (6,2), (4,3)), ((3,5), (6,2), (4,3))) ),dtype=float)

print('data.shape=',data.shape)

ddata_dlon = d_dlon(data)

print('ddata_dlon=',ddata_dlon)

@maroba
Copy link
Owner

maroba commented May 11, 2022

Do you mean something like the following?

import numpy as np

# latitude coordinates:
thetas = np.linspace(-np.pi/2, np.pi/2, 101) 

# longitude coordinates:
phis = np.linspace(0, 2*np.pi, 101) 

# set up 2D latitude/longitude grid:
Thetas, Phis = np.meshgrid(thetas, phis, indexing='ij')

# then define some 2D array:
f = np.sin(Phis)**2 * np.sin(Thetas)**2

print(
 "theta = %f, phi = %f, f(theta, phi) = %f" % (thetas[17], phis[21], f[17, 21])
)


# partial derivative with respect to Theta:
delta_theta = thetas[1] - thetas[0]
d_dtheta = FinDiff(0, delta_theta, 1)

# apply it:
f_theta = d_dtheta(f)

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

No branches or pull requests

2 participants