Skip to content

Commit bc279f2

Browse files
committed
dev
1 parent 354b662 commit bc279f2

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

cf/field.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,55 +2365,41 @@ def _weights_geometry_area(
23652365

23662366
print (111)
23672367

2368-
# if ugrid:
2369-
# # UGRID face cell bounds do not have a "parts"
2370-
# # dimension, so insert a dummy one.
2371-
# x = x.insert_dimension(1).persist()
2372-
# y = y.insert_dimension(1).persist()
2373-
# x = x.concatenate(x, x[:,0:1]], axis=1)
2374-
# y = y.concatenate(y, y[:,0:1]], axis=1)
2368+
if ugrid:
2369+
x = x.array
2370+
col_indices = np.ma.count(x, axis=1)
2371+
empty_column = np.ma.masked_all((x.shape[0], 1), dtype=x.dtype)
2372+
x = np.ma.concatenate((x, empty_column), axis=1)
2373+
x[np.arange(x.shape[0]), col_indices] = x[:, 0]
2374+
# x = np.ma.where(x <0, x + np.pi, x)
2375+
x = self._Data(x, units= _units_radians)
2376+
print (x.shape, x[0].array)
2377+
2378+
y = y.array
2379+
col_indices = np.ma.count(y, axis=1)
2380+
empty_column = np.ma.masked_all((y.shape[0], 1), dtype=y.dtype)
2381+
y = np.ma.concatenate((y, empty_column), axis=1)
2382+
y[np.arange(y.shape[0]), col_indices] = y[:, 0]
2383+
y = self._Data(y, units= _units_radians)
2384+
print(y.shape, y[0].array)
23752385

2376-
2377-
23782386
interior_angle = self._weights_interior_angle(x, y)
2379-
2387+
print (interior_angle.array[0])
23802388

23812389
# Find the number of edges of each polygon (note that
23822390
# this number may be one too few, but we'll adjust for
23832391
# that later).
23842392
# N = interior_angle.sample_size(-1, squeeze=True)
23852393
N = interior_angle.count(-1, keepdims=False)
2394+
print (N.array)
23862395

23872396
all_areas = interior_angle.sum(-1, squeeze=True) - (N - 2) * np.pi
2388-
2389-
if ugrid:
2390-
x = x.persist()
2391-
y = y.persist()
2392-
for i, (nodes_x, nodes_y) in enumerate(zip(x, y)):
2393-
print (axis, i)
2394-
nodes_x = nodes_x.compressed().persist()
2395-
nodes_y = nodes_y.compressed().persist()
2396-
2397-
if (nodes_x.size and nodes_x[0] != nodes_x[-1]) or (
2398-
nodes_y.size and nodes_y[0] != nodes_y[-1]
2399-
):
2400-
# First and last nodes of this polygon
2401-
# part are different => need to account
2402-
# for the "last" edge of the polygon that
2403-
# joins the first and last points.
2404-
interior_angle = self._weights_interior_angle(
2405-
nodes_x[[0, -1]], nodes_y[[0, -1]]
2406-
)
2407-
all_areas[i] += interior_angle + np.pi
2408-
2409-
else:
2397+
print (all_areas.array[0])
2398+
if not ugrid:
24102399
for i, (parts_x, parts_y) in enumerate(zip(x, y)):
2411-
print (ugrid, axis, i, parts_x.shape, parts_y.shape)
24122400
for j, (nodes_x, nodes_y) in enumerate(zip(parts_x, parts_y)):
24132401
nodes_x = nodes_x.compressed()
24142402
nodes_y = nodes_y.compressed()
2415-
print (nodes_x.shape)
2416-
24172403
if (nodes_x.size and nodes_x[0] != nodes_x[-1]) or (
24182404
nodes_y.size and nodes_y[0] != nodes_y[-1]
24192405
):
@@ -2425,7 +2411,7 @@ def _weights_geometry_area(
24252411
nodes_x[[0, -1]], nodes_y[[0, -1]]
24262412
)
24272413

2428-
all_areas[i, j] += interior_angle + np.pi
2414+
all_areas[i, j] += interior_angle + np.pi # -?
24292415

24302416
area_min = all_areas.min()
24312417
if area_min < 0:
@@ -2446,7 +2432,9 @@ def _weights_geometry_area(
24462432
if ugrid:
24472433
areas = all_areas
24482434
else:
2449-
areas = all_areas.sum(-1, squeeze=True)
2435+
# Sum the areas of each geometry polygon part to get the
2436+
# total area of each cell
2437+
areas = all_areas.sum(-1, squeeze=True)
24502438

24512439
if measure and spherical and aux_Z is not None:
24522440
# Multiply by radius squared, accounting for any Z
@@ -2787,7 +2775,7 @@ def _weights_interior_angle(self, data_lambda, data_phi):
27872775
The interior angles in units of radians.
27882776

27892777
"""
2790-
delta_lambda = data_lambda.diff(axis=-1)
2778+
delta_lambda = abs(data_lambda.diff(axis=-1))
27912779

27922780
cos_phi = data_phi.cos()
27932781
sin_phi = data_phi.sin()
@@ -2813,6 +2801,7 @@ def _weights_interior_angle(self, data_lambda, data_phi):
28132801
denominator = (
28142802
sin_phi_1 * sin_phi_2 + cos_phi_1 * cos_phi_2 * cos_delta_lambda
28152803
)
2804+
print ('dem=', denominator[0].array)
28162805

28172806
# TODO RuntimeWarning: overflow encountered in true_divide comes from
28182807
# numerator/denominator with missing values

0 commit comments

Comments
 (0)