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

Simplify quadilateral_area + better doc #66

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions regional_mom6/regional_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,25 @@ def angle_between(v1, v2, v3):

# Borrowed from grid tools (GFDL)
def quadilateral_area(lat, lon):
"""Returns area of spherical quadrilaterals (bounded by great arcs)."""
"""Returns area of spherical quadrilaterals on the unit sphere that are formed
by constant latitude and longitude lines on the `lat`-`lon` grid provided."""

# x, y, z are 3D coordinates on the unit sphere
x = np.cos(np.deg2rad(lat)) * np.cos(np.deg2rad(lon))
y = np.cos(np.deg2rad(lat)) * np.sin(np.deg2rad(lon))
z = np.sin(np.deg2rad(lat))

c0 = (x[:-1, :-1], y[:-1, :-1], z[:-1, :-1])
c1 = (x[:-1, 1:], y[:-1, 1:], z[:-1, 1:])
c2 = (x[1:, 1:], y[1:, 1:], z[1:, 1:])
c3 = (x[1:, :-1], y[1:, :-1], z[1:, :-1])
c1 = (x[:-1, :-1], y[:-1, :-1], z[:-1, :-1])
c2 = (x[:-1, 1:], y[:-1, 1:], z[:-1, 1:])
c3 = (x[1:, 1:], y[1:, 1:], z[1:, 1:])
c4 = (x[1:, :-1], y[1:, :-1], z[1:, :-1])

a0 = angle_between(c1, c0, c2)
a1 = angle_between(c2, c1, c3)
a2 = angle_between(c3, c2, c0)
a3 = angle_between(c0, c3, c1)
a2 = angle_between(c3, c2, c4)
a3 = angle_between(c4, c3, c1)
a4 = angle_between(c1, c4, c2)

return a0 + a1 + a2 + a3 - 2.0 * np.pi
return a1 + a2 + a3 + a4 - 2.0 * np.pi


def rectangular_hgrid(λ, φ):
Expand Down