Skip to content

Commit b392046

Browse files
Finish all necessary changes
1 parent f994a84 commit b392046

6 files changed

Lines changed: 130 additions & 104 deletions

File tree

test/test_integrate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_get_faces_constLat_intersection_info_one_intersection():
6767
latitude_cart = -0.8660254037844386
6868
is_latlonface = False
6969
is_GCA_list = None
70-
unique_intersections, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
70+
unique_intersections,unique_intersections_lonlat, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
7171
is_GCA_list, is_latlonface)
7272
assert len(unique_intersections) == 1
7373

@@ -97,7 +97,7 @@ def test_get_faces_constLat_intersection_info_encompass_pole():
9797

9898
is_latlonface = False
9999
is_GCA_list = None
100-
unique_intersections, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
100+
unique_intersections,unique_intersections_lonlat, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
101101
is_GCA_list, is_latlonface)
102102
assert len(unique_intersections) <= 2 * len(face_edges_cart)
103103

@@ -119,7 +119,7 @@ def test_get_faces_constLat_intersection_info_on_pole():
119119
latitude_cart = -0.9998476951563913
120120
is_latlonface = False
121121
is_GCA_list = None
122-
unique_intersections, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
122+
unique_intersections,unique_intersections_lonlat, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
123123
is_GCA_list, is_latlonface)
124124
assert len(unique_intersections) == 2
125125

@@ -141,7 +141,7 @@ def test_get_faces_constLat_intersection_info_near_pole():
141141
latitude_deg = np.rad2deg(latitude_rad)
142142
is_latlonface = False
143143
is_GCA_list = None
144-
unique_intersections, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
144+
unique_intersections,unique_intersections_lonlat, pt_lon_min, pt_lon_max = _get_faces_constLat_intersection_info(face_edges_cart, latitude_cart,
145145
is_GCA_list, is_latlonface)
146146
assert len(unique_intersections) == 1
147147

uxarray/core/zonal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from uxarray.grid.integrate import _zonal_face_weights, _zonal_face_weights_robust
66

77

8-
98
def _compute_non_conservative_zonal_mean(uxda, latitudes, use_robust_weights=False):
109
"""Computes the non-conservative zonal mean across one or more latitudes."""
1110
uxgrid = uxda.uxgrid
@@ -50,4 +49,3 @@ def _compute_non_conservative_zonal_mean(uxda, latitudes, use_robust_weights=Fal
5049
)
5150

5251
return result
53-

uxarray/grid/geometry.py

Lines changed: 75 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _unique_points(points, tolerance=ERROR_TOLERANCE):
103103

104104
@njit(cache=True)
105105
def _pad_closed_face_nodes(
106-
face_node_connectivity, n_face, n_max_face_nodes, n_nodes_per_face
106+
face_node_connectivity, n_face, n_max_face_nodes, n_nodes_per_face
107107
):
108108
"""Pads a closed array of face nodes by inserting the first element at any
109109
point a fill value is encountered.
@@ -123,14 +123,14 @@ def _pad_closed_face_nodes(
123123

124124

125125
def _build_polygon_shells(
126-
node_lon,
127-
node_lat,
128-
face_node_connectivity,
129-
n_face,
130-
n_max_face_nodes,
131-
n_nodes_per_face,
132-
projection=None,
133-
central_longitude=0.0,
126+
node_lon,
127+
node_lat,
128+
face_node_connectivity,
129+
n_face,
130+
n_max_face_nodes,
131+
n_nodes_per_face,
132+
projection=None,
133+
central_longitude=0.0,
134134
):
135135
"""Builds an array of polygon shells, which can be used with Shapely to
136136
construct polygons."""
@@ -266,7 +266,7 @@ def _grid_to_polygon_geodataframe(grid, periodic_elements, projection, project,
266266

267267

268268
def _build_geodataframe_without_antimeridian(
269-
polygon_shells, projected_polygon_shells, antimeridian_face_indices, engine
269+
polygon_shells, projected_polygon_shells, antimeridian_face_indices, engine
270270
):
271271
"""Builds a ``spatialpandas.GeoDataFrame`` or
272272
``geopandas.GeoDataFrame``excluding any faces that cross the
@@ -295,10 +295,10 @@ def _build_geodataframe_without_antimeridian(
295295

296296

297297
def _build_geodataframe_with_antimeridian(
298-
polygon_shells,
299-
projected_polygon_shells,
300-
antimeridian_face_indices,
301-
engine,
298+
polygon_shells,
299+
projected_polygon_shells,
300+
antimeridian_face_indices,
301+
engine,
302302
):
303303
"""Builds a ``spatialpandas.GeoDataFrame`` or ``geopandas.GeoDataFrame``
304304
including any faces that cross the antimeridian."""
@@ -317,9 +317,9 @@ def _build_geodataframe_with_antimeridian(
317317

318318

319319
def _build_corrected_shapely_polygons(
320-
polygon_shells,
321-
projected_polygon_shells,
322-
antimeridian_face_indices,
320+
polygon_shells,
321+
projected_polygon_shells,
322+
antimeridian_face_indices,
323323
):
324324
if projected_polygon_shells is not None:
325325
# use projected shells if a projection is applied
@@ -438,7 +438,7 @@ def _build_corrected_polygon_shells(polygon_shells):
438438

439439

440440
def _grid_to_matplotlib_polycollection(
441-
grid, periodic_elements, projection=None, **kwargs
441+
grid, periodic_elements, projection=None, **kwargs
442442
):
443443
"""Constructs and returns a ``matplotlib.collections.PolyCollection``"""
444444

@@ -642,7 +642,7 @@ def _get_polygons(grid, periodic_elements, projection=None, apply_projection=Tru
642642

643643

644644
def _grid_to_matplotlib_linecollection(
645-
grid, periodic_elements, projection=None, **kwargs
645+
grid, periodic_elements, projection=None, **kwargs
646646
):
647647
"""Constructs and returns a ``matplotlib.collections.LineCollection``"""
648648

@@ -688,6 +688,7 @@ def _convert_shells_to_polygons(shells):
688688
return polygons
689689

690690

691+
# TODO: If we don't actually use this one, remove it
691692
def _pole_point_inside_polygon_cartesian(pole, face_edges_xyz):
692693
if isinstance(pole, str):
693694
pole = POLE_NAME_TO_INT[pole]
@@ -913,7 +914,7 @@ def _check_intersection(ref_edge_xyz, edges_xyz):
913914
for i in range(n_edges):
914915
edge_xyz = edges_xyz[i]
915916
if allclose(
916-
intersection_point, edge_xyz[0], atol=ERROR_TOLERANCE
917+
intersection_point, edge_xyz[0], atol=ERROR_TOLERANCE
917918
) or allclose(intersection_point, edge_xyz[1], atol=ERROR_TOLERANCE):
918919
return 0
919920

@@ -1140,10 +1141,10 @@ def insert_pt_in_latlonbox(old_box, new_pt, is_lon_periodic=True):
11401141

11411142
@njit(cache=True)
11421143
def _populate_face_latlon_bound(
1143-
face_edges_xyz,
1144-
face_edges_lonlat,
1145-
is_latlonface=False,
1146-
is_GCA_list=None,
1144+
face_edges_xyz,
1145+
face_edges_lonlat,
1146+
is_latlonface=False,
1147+
is_GCA_list=None,
11471148
):
11481149
# Check if face_edges contains pole points
11491150
has_north_pole = pole_point_inside_polygon(1, face_edges_xyz, face_edges_lonlat)
@@ -1198,9 +1199,9 @@ def _populate_face_latlon_bound(
11981199
# Check if the node matches the pole point or if the pole point is within the edge
11991200
max_abs_diff = np.max(np.abs(n1_cart - pole_point_xyz))
12001201
if max_abs_diff <= ERROR_TOLERANCE or point_within_gca(
1201-
pole_point_xyz,
1202-
n1_cart,
1203-
n2_cart,
1202+
pole_point_xyz,
1203+
n1_cart,
1204+
n2_cart,
12041205
):
12051206
is_center_pole = False
12061207
face_latlon_array = insert_pt_in_latlonbox(
@@ -1292,15 +1293,15 @@ def _populate_face_latlon_bound(
12921293

12931294
# Insert extreme latitude points into the latlonbox
12941295
if (
1295-
abs(node1_lat_rad - lat_max) > ERROR_TOLERANCE
1296-
and abs(node2_lat_rad - lat_max) > ERROR_TOLERANCE
1296+
abs(node1_lat_rad - lat_max) > ERROR_TOLERANCE
1297+
and abs(node2_lat_rad - lat_max) > ERROR_TOLERANCE
12971298
):
12981299
face_latlon_array = insert_pt_in_latlonbox(
12991300
face_latlon_array, np.array([lat_max, node1_lon_rad])
13001301
)
13011302
elif (
1302-
abs(node1_lat_rad - lat_min) > ERROR_TOLERANCE
1303-
and abs(node2_lat_rad - lat_min) > ERROR_TOLERANCE
1303+
abs(node1_lat_rad - lat_min) > ERROR_TOLERANCE
1304+
and abs(node2_lat_rad - lat_min) > ERROR_TOLERANCE
13041305
):
13051306
face_latlon_array = insert_pt_in_latlonbox(
13061307
face_latlon_array, np.array([lat_min, node1_lon_rad])
@@ -1315,23 +1316,23 @@ def _populate_face_latlon_bound(
13151316

13161317
@njit(cache=True, parallel=True)
13171318
def compute_temp_latlon_array(
1318-
face_node_connectivity,
1319-
faces_edges_cartesian,
1320-
faces_edges_lonlat_rad,
1321-
n_nodes_per_face,
1322-
is_latlonface,
1323-
is_face_GCA_list,
1324-
INT_FILL_VALUE,
1319+
face_node_connectivity,
1320+
faces_edges_cartesian,
1321+
faces_edges_lonlat_rad,
1322+
n_nodes_per_face,
1323+
is_latlonface,
1324+
is_face_GCA_list,
1325+
INT_FILL_VALUE,
13251326
):
13261327
n_face = face_node_connectivity.shape[0]
13271328
temp_latlon_array = np.full((n_face, 2, 2), INT_FILL_VALUE, dtype=np.float64)
13281329
for face_idx in prange(n_face):
13291330
cur_face_edges_cartesian = faces_edges_cartesian[
1330-
face_idx, 0: n_nodes_per_face[face_idx]
1331-
]
1331+
face_idx, 0 : n_nodes_per_face[face_idx]
1332+
]
13321333
cur_faces_edges_lonlat_rad = faces_edges_lonlat_rad[
1333-
face_idx, 0: n_nodes_per_face[face_idx]
1334-
]
1334+
face_idx, 0 : n_nodes_per_face[face_idx]
1335+
]
13351336
if is_face_GCA_list is not None:
13361337
is_GCA_list = is_face_GCA_list[face_idx]
13371338
else:
@@ -1347,9 +1348,14 @@ def compute_temp_latlon_array(
13471348

13481349

13491350
def _populate_faces_edges_cartesian(grid, return_array=False):
1350-
faces_edges_cartesian = _get_cartesian_faces_edge_nodes(grid.face_node_connectivity.values, grid.n_face,
1351-
grid.n_max_face_edges, grid.node_x.values,
1352-
grid.node_y.values, grid.node_z.values)
1351+
faces_edges_cartesian = _get_cartesian_faces_edge_nodes(
1352+
grid.face_node_connectivity.values,
1353+
grid.n_face,
1354+
grid.n_max_face_edges,
1355+
grid.node_x.values,
1356+
grid.node_y.values,
1357+
grid.node_z.values,
1358+
)
13531359

13541360
faces_edges_cartesian_xarray = xr.DataArray(
13551361
faces_edges_cartesian,
@@ -1358,7 +1364,7 @@ def _populate_faces_edges_cartesian(grid, return_array=False):
13581364
"cf_role": "faces_edges_cartesian",
13591365
"_FillValue": INT_FILL_VALUE,
13601366
"long_name": "Provide the Cartesian coordinates of the edge for each face",
1361-
"start_index": INT_DTYPE(0)
1367+
"start_index": INT_DTYPE(0),
13621368
},
13631369
)
13641370

@@ -1369,9 +1375,13 @@ def _populate_faces_edges_cartesian(grid, return_array=False):
13691375

13701376

13711377
def _populate_faces_edges_spherical(grid, return_array=False):
1372-
faces_edges_lonlat_rad = _get_lonlat_rad_faces_edge_nodes(grid.face_node_connectivity.values, grid.n_face,
1373-
grid.n_max_face_edges, grid.node_lon.values,
1374-
grid.node_lat.values)
1378+
faces_edges_lonlat_rad = _get_lonlat_rad_faces_edge_nodes(
1379+
grid.face_node_connectivity.values,
1380+
grid.n_face,
1381+
grid.n_max_face_edges,
1382+
grid.node_lon.values,
1383+
grid.node_lat.values,
1384+
)
13751385

13761386
faces_edges_lonlat_rad_xarray = xr.DataArray(
13771387
faces_edges_lonlat_rad,
@@ -1380,7 +1390,7 @@ def _populate_faces_edges_spherical(grid, return_array=False):
13801390
"cf_role": "faces_edges_spherical",
13811391
"_FillValue": INT_FILL_VALUE,
13821392
"long_name": "Provide the Spherical coordinates (lon lat) in radians of the edge for each face",
1383-
"start_index": INT_DTYPE(0)
1393+
"start_index": INT_DTYPE(0),
13841394
},
13851395
)
13861396

@@ -1391,10 +1401,7 @@ def _populate_faces_edges_spherical(grid, return_array=False):
13911401

13921402

13931403
def _populate_bounds(
1394-
grid,
1395-
is_latlonface: bool = False,
1396-
is_face_GCA_list=None,
1397-
return_array=False
1404+
grid, is_latlonface: bool = False, is_face_GCA_list=None, return_array=False
13981405
):
13991406
"""Populates the bounds of the grid based on the geometry of its faces,
14001407
taking into account special conditions such as faces crossing the
@@ -1408,17 +1415,6 @@ def _populate_bounds(
14081415
The grid object whose internal representation will be updated with the computed
14091416
face bounds.
14101417
1411-
faces_edges_cartesian : np.ndarray, optional
1412-
An array of shape (n_face, n_max_face_edges, 2, 3) containing the Cartesian coordinates
1413-
of each face's edges. This array may include dummy values for grids with holes.
1414-
Default is None.
1415-
1416-
faces_edges_lonlat_rad : np.ndarray, optional
1417-
An array of shape (n_face, n_max_face_edges, 2, 2) containing the longitude and latitude
1418-
(in radians) coordinates of each face's edges. This array may include dummy values for
1419-
grids with holes.
1420-
Default is None.
1421-
14221418
is_latlonface : bool, optional
14231419
A global flag that indicates if faces are latlon faces. If True, all faces
14241420
are treated as latlon faces, meaning that all edges are either longitude or
@@ -1563,16 +1559,16 @@ def stereographic_projection(lon, lat, central_lon, central_lat):
15631559

15641560
# Calculate constant used for calculation
15651561
k = 2.0 / (
1566-
1.0
1567-
+ np.sin(central_lat) * np.sin(lat)
1568-
+ np.cos(central_lat) * np.cos(lat) * np.cos(lon - central_lon)
1562+
1.0
1563+
+ np.sin(central_lat) * np.sin(lat)
1564+
+ np.cos(central_lat) * np.cos(lat) * np.cos(lon - central_lon)
15691565
)
15701566

15711567
# Calculate the x and y coordinates
15721568
x = k * np.cos(lat) * np.sin(lon - central_lon)
15731569
y = k * (
1574-
np.cos(central_lat) * np.sin(lat)
1575-
- np.sin(central_lat) * np.cos(lat) * np.cos(lon - central_lon)
1570+
np.cos(central_lat) * np.sin(lat)
1571+
- np.sin(central_lat) * np.cos(lat) * np.cos(lon - central_lon)
15761572
)
15771573

15781574
return x, y
@@ -1608,7 +1604,7 @@ def inverse_stereographic_projection(x, y, central_lon, central_lat):
16081604
central_lat = np.deg2rad(central_lat)
16091605

16101606
# Calculate constants used for calculation
1611-
p = np.sqrt(x ** 2 + y ** 2)
1607+
p = np.sqrt(x**2 + y**2)
16121608

16131609
c = 2 * np.arctan(p / 2)
16141610

@@ -1627,9 +1623,9 @@ def inverse_stereographic_projection(x, y, central_lon, central_lat):
16271623

16281624
@njit(cache=True)
16291625
def point_in_face(
1630-
edges_xyz,
1631-
point_xyz,
1632-
inclusive=True,
1626+
edges_xyz,
1627+
point_xyz,
1628+
inclusive=True,
16331629
):
16341630
"""Determines if a point lies inside a face.
16351631
@@ -1679,9 +1675,9 @@ def point_in_face(
16791675
for ind in range(len(edges_xyz)):
16801676
# If the point lies on an edge, return True if inclusive
16811677
if point_within_gca(
1682-
point_xyz,
1683-
edges_xyz[ind][0],
1684-
edges_xyz[ind][1],
1678+
point_xyz,
1679+
edges_xyz[ind][0],
1680+
edges_xyz[ind][1],
16851681
):
16861682
if inclusive:
16871683
return True
@@ -1774,7 +1770,7 @@ def _populate_max_face_radius(self):
17741770

17751771
@njit(cache=True)
17761772
def calculate_max_face_radius(
1777-
face_node_connectivity, node_lats_rad, node_lons_rad, face_lats_rad, face_lons_rad
1773+
face_node_connectivity, node_lats_rad, node_lons_rad, face_lats_rad, face_lons_rad
17781774
):
17791775
"""Finds the max face radius in the mesh.
17801776
Parameters
@@ -1848,7 +1844,7 @@ def haversine_distance(lon_a, lat_a, lon_b, lat_b):
18481844

18491845
# Haversine formula
18501846
equation_in_sqrt = (np.sin(dlat / 2) ** 2) + np.cos(lat_a) * np.cos(lat_b) * (
1851-
np.sin(dlon / 2) ** 2
1847+
np.sin(dlon / 2) ** 2
18521848
)
18531849
distance = 2 * np.arcsin(np.sqrt(equation_in_sqrt))
18541850

0 commit comments

Comments
 (0)