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

More verbose name for quad_area -> quadrilateral_area + one more test #64

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions regional_mom6/regional_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"motu_requests",
"dz",
"angle_between",
"quad_area",
"quadilateral_area",
"rectangular_hgrid",
"experiment",
"segment",
Expand Down Expand Up @@ -300,7 +300,7 @@ def angle_between(v1, v2, v3):


# Borrowed from grid tools (GFDL)
def quad_area(lat, lon):
def quadilateral_area(lat, lon):
"""Returns area of spherical quadrilaterals (bounded by great arcs)."""

# x, y, z are 3D coordinates on the unit sphere
Expand Down Expand Up @@ -356,7 +356,7 @@ def rectangular_hgrid(λ, φ):

lon, lat = np.meshgrid(λ, φ)

area = quad_area(lat, lon) * R**2
area = quadilateral_area(lat, lon) * R**2

attrs = {
"tile": {
Expand Down
14 changes: 9 additions & 5 deletions tests/test_grid_generation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest
from regional_mom6 import angle_between
from regional_mom6 import quad_area
from regional_mom6 import quadilateral_area
from regional_mom6 import rectangular_hgrid
import xarray as xr

Expand All @@ -18,17 +18,21 @@ def test_angle_between(v1, v2, v3, true_angle):


# create a lat-lon mesh that covers 1/4 of the North Hemisphere
lon, lat = np.meshgrid(np.linspace(0, 90, 5), np.linspace(0, 90, 5))
lon1, lat1 = np.meshgrid(np.linspace(0, 90, 5), np.linspace(0, 90, 5))

# create a lat-lon mesh that covers 1/4 of the whole globe
lon2, lat2 = np.meshgrid(np.linspace(-45, 45, 5), np.linspace(-90, 90, 5))


@pytest.mark.parametrize(
("lat", "lon", "true_area"),
[
(lat, lon, 0.5 * np.pi),
(lat1, lon1, 0.5 * np.pi),
(lat2, lon2, np.pi),
],
)
def test_quad_area(lat, lon, true_area):
assert np.isclose(np.sum(quad_area(lat, lon)), true_area)
def test_quadilateral_area(lat, lon, true_area):
assert np.isclose(np.sum(quadilateral_area(lat, lon)), true_area)


# a simple test that rectangular_hgrid runs without erroring
Expand Down