Skip to content

Commit aff89e4

Browse files
committed
Merge create_vertice and custom_concat function
1 parent 68badf5 commit aff89e4

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

examples/06_grid_manipulation/pet_hide_pixel_out_eddies.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from matplotlib import pyplot as plt
88
from matplotlib.path import Path
99
from numpy import ones
10-
from py_eddy_tracker.observations.observation import EddiesObservations, custom_concat
10+
from py_eddy_tracker.observations.observation import EddiesObservations
1111
from py_eddy_tracker.dataset.grid import RegularGridDataset
12+
from py_eddy_tracker.poly import create_vertice
1213
from py_eddy_tracker import data
1314

1415
# %%
@@ -35,7 +36,7 @@
3536
adt = g.grid("adt")
3637
mask = ones(adt.shape, dtype='bool')
3738
for eddy in a:
38-
i, j = Path(custom_concat(eddy[x_name], eddy[y_name])).pixels_in(g)
39+
i, j = Path(create_vertice(eddy[x_name], eddy[y_name])).pixels_in(g)
3940
mask[i, j] = False
4041
adt.mask[:] += ~mask
4142
g.display(ax, "adt")

src/py_eddy_tracker/observations/observation.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from matplotlib.path import Path as BasePath
6060
from .. import VAR_DESCR, VAR_DESCR_inv
6161
from ..generic import distance_grid, distance, flatten_line_matrix, wrap_longitude
62-
from ..poly import bbox_intersection, common_area
62+
from ..poly import bbox_intersection, common_area, create_vertice
6363

6464
logger = logging.getLogger("pet")
6565

@@ -123,16 +123,6 @@ def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5
123123
return m
124124

125125

126-
@njit(cache=True, fastmath=True)
127-
def custom_concat(x, y):
128-
nb = x.shape[0]
129-
a = empty((nb, 2))
130-
for i in range(nb):
131-
a[i, 0] = x[i]
132-
a[i, 1] = y[i]
133-
return a
134-
135-
136126
class EddiesObservations(object):
137127
"""
138128
Class to hold eddy properties *amplitude* and counts of
@@ -761,10 +751,10 @@ def cost_function_common_area(cls, xy_in, xy_out, distance, intern=False):
761751
continue
762752

763753
x_in_, x_out_ = x_in[i], x_out[i]
764-
p_in = Polygon(custom_concat(x_in_, y_in[i]))
754+
p_in = Polygon(create_vertice(x_in_, y_in[i]))
765755
if abs(x_in_[0] - x_out_[0]) > 180:
766756
x_out_ = (x_out[i] - (x_in_[0] - 180)) % 360 + x_in_[0] - 180
767-
p_out = Polygon(custom_concat(x_out_, y_out[i]))
757+
p_out = Polygon(create_vertice(x_out_, y_out[i]))
768758
costs[i] = 1 - (p_in & p_out).area() / min(p_in.area(), p_out.area())
769759
costs.mask = costs == 1
770760
return costs
@@ -1288,7 +1278,7 @@ def grid_count(self, bins, intern=False, center=False):
12881278
else:
12891279
x, y = (self[x_name] - x0) % 360 + x0, self[y_name]
12901280
for x_, y_ in zip(x, y):
1291-
i, j = BasePath(custom_concat(x_, y_)).pixels_in(regular_grid)
1281+
i, j = BasePath(create_vertice(x_, y_)).pixels_in(regular_grid)
12921282
grid_count_(grid, i, j)
12931283
grid.mask = grid == 0
12941284
return regular_grid

src/py_eddy_tracker/poly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def bbox_intersection(x0, y0, x1, y1):
121121
return array(i), array(j)
122122

123123

124-
@njit(cache=True, fastmath=True)
124+
@njit(cache=True)
125125
def create_vertice(x, y):
126126
nb = x.shape[0]
127127
v = empty((nb, 2))

0 commit comments

Comments
 (0)