Skip to content

Commit bac8b87

Browse files
author
adelepoulle
committed
Remove direct import from numpy
1 parent 303f10c commit bac8b87

File tree

3 files changed

+85
-87
lines changed

3 files changed

+85
-87
lines changed

src/py_eddy_tracker/property_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def uniform_resample(x_val, y_val, method='interp1d', extrapolate=None,
5454
extrapolate : IS NOT RELIABLE (sometimes nans occur)
5555
"""
5656
# Get distances
57-
dist = np.empty_like(x_val)
57+
dist = np.empty(x_val.shape)
5858
dist[0] = 0
5959
distance_vector(
6060
x_val[:-1], y_val[:-1], x_val[1:], y_val[1:], dist[1:])

src/py_eddy_tracker/property_objects.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# from scipy.ndimage import generate_binary_structure, binary_erosion
3333
from scipy.ndimage import binary_erosion
3434
from scipy.ndimage import minimum_filter
35-
import numpy as np
35+
from numpy import array, isfinite, ma, where, ones
3636
from .tools import index_from_nearest_path, distance_matrix
3737
import logging
3838

@@ -69,19 +69,19 @@ def __init__(self, contlon, contlat, eddy, grd):
6969
h_0 = grd.sla_coeffs.ev(self.contlat[1:], self.contlon[1:])
7070

7171
elif 'griddata' in eddy.interp_method:
72-
points = np.array([grd.lon()[self.jslice, self.islice].ravel(),
72+
points = array([grd.lon()[self.jslice, self.islice].ravel(),
7373
grd.lat()[self.jslice, self.islice].ravel()]).T
7474
h_0 = griddata(points, self.sla.ravel(),
7575
(self.contlon[1:], self.contlat[1:]),
7676
'linear')
7777
else:
7878
raise Exception('Unknown method : %s' % eddy.interp_method)
7979

80-
self.h_0 = h_0[np.isfinite(h_0)].mean()
81-
self.amplitude = 0 # np.atleast_1d(0.)
82-
self.local_extrema = None # np.int(0)
80+
self.h_0 = h_0[isfinite(h_0)].mean()
81+
self.amplitude = 0 # atleast_1d(0.)
82+
self.local_extrema = None # int(0)
8383
self.local_extrema_inds = None
84-
self.sla = np.ma.masked_where(-self.mask, self.sla)
84+
self.sla = ma.masked_where(-self.mask, self.sla)
8585

8686
@property
8787
def islice(self):
@@ -122,15 +122,15 @@ def all_pixels_below_h0(self, level):
122122
Check CSS11 criterion 1: The SSH values of all of the pixels
123123
are below a given SSH threshold for cyclonic eddies.
124124
"""
125-
if np.any(self.sla > self.h_0):
125+
if (self.sla > self.h_0).any():
126126
return False # i.e., with self.amplitude == 0
127127
else:
128128
self._set_local_extrema(1)
129129
if (self.local_extrema > 0 and
130130
self.local_extrema <= self.mle):
131131
self._set_cyc_amplitude()
132132
elif self.local_extrema > self.mle:
133-
lmi_j, lmi_i = np.where(self.local_extrema_inds)
133+
lmi_j, lmi_i = where(self.local_extrema_inds)
134134
levnm2 = level - (2 * self.eddy.interval)
135135
slamin = 1e5
136136
for j, i in zip(lmi_j, lmi_i):
@@ -151,7 +151,7 @@ def all_pixels_above_h0(self, level):
151151
Check CSS11 criterion 1: The SSH values of all of the pixels
152152
are above a given SSH threshold for anticyclonic eddies.
153153
"""
154-
if np.any(self.sla < self.h_0):
154+
if (self.sla < self.h_0).any():
155155
# i.e.,with self.amplitude == 0
156156
return False
157157
else:
@@ -161,7 +161,7 @@ def all_pixels_above_h0(self, level):
161161
self._set_acyc_amplitude()
162162

163163
elif self.local_extrema > self.mle:
164-
lmi_j, lmi_i = np.where(self.local_extrema_inds)
164+
lmi_j, lmi_i = where(self.local_extrema_inds)
165165
levnp2 = level + (2 * self.eddy.interval)
166166
slamax = -1e5
167167
for j, i in zip(lmi_j, lmi_i):
@@ -191,7 +191,7 @@ def _detect_local_minima(self, arr):
191191
http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array/3689710#3689710
192192
"""
193193
# Equivalent
194-
neighborhood = np.ones((3, 3), dtype='bool')
194+
neighborhood = ones((3, 3), dtype='bool')
195195
#~ neighborhood = generate_binary_structure(arr.ndim, 2)
196196

197197
# Get local mimima
@@ -238,14 +238,14 @@ def __init__(self, contour):
238238
ci_list.append(len(coll.vertices[:, 0]))
239239
li_list.append(len(cont.get_paths()))
240240

241-
self.x_value = np.array([val for sublist in x_list for val in sublist])
242-
self.y_value = np.array([val for sublist in y_list for val in sublist])
243-
self.nb_pt_per_c = np.array(ci_list, dtype='u4')
244-
self.c_i = np.array(self.nb_pt_per_c.cumsum() - self.nb_pt_per_c,
245-
dtype='u4')
246-
self.nb_c_per_l = np.array(li_list, dtype='u4')
247-
self.l_i = np.array(self.nb_c_per_l.cumsum() - self.nb_c_per_l,
248-
dtype='u4')
241+
self.x_value = array([val for sublist in x_list for val in sublist])
242+
self.y_value = array([val for sublist in y_list for val in sublist])
243+
self.nb_pt_per_c = array(ci_list, dtype='u4')
244+
self.c_i = array(self.nb_pt_per_c.cumsum() - self.nb_pt_per_c,
245+
dtype='u4')
246+
self.nb_c_per_l = array(li_list, dtype='u4')
247+
self.l_i = array(self.nb_c_per_l.cumsum() - self.nb_c_per_l,
248+
dtype='u4')
249249

250250
def get_index_nearest_path(self, level, xpt, ypt):
251251
"""

0 commit comments

Comments
 (0)