32
32
# from scipy.ndimage import generate_binary_structure, binary_erosion
33
33
from scipy .ndimage import binary_erosion
34
34
from scipy .ndimage import minimum_filter
35
- import numpy as np
35
+ from numpy import array , isfinite , ma , where , ones
36
36
from .tools import index_from_nearest_path , distance_matrix
37
37
import logging
38
38
@@ -69,19 +69,19 @@ def __init__(self, contlon, contlat, eddy, grd):
69
69
h_0 = grd .sla_coeffs .ev (self .contlat [1 :], self .contlon [1 :])
70
70
71
71
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 (),
73
73
grd .lat ()[self .jslice , self .islice ].ravel ()]).T
74
74
h_0 = griddata (points , self .sla .ravel (),
75
75
(self .contlon [1 :], self .contlat [1 :]),
76
76
'linear' )
77
77
else :
78
78
raise Exception ('Unknown method : %s' % eddy .interp_method )
79
79
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)
83
83
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 )
85
85
86
86
@property
87
87
def islice (self ):
@@ -122,15 +122,15 @@ def all_pixels_below_h0(self, level):
122
122
Check CSS11 criterion 1: The SSH values of all of the pixels
123
123
are below a given SSH threshold for cyclonic eddies.
124
124
"""
125
- if np . any (self .sla > self .h_0 ):
125
+ if (self .sla > self .h_0 ). any ( ):
126
126
return False # i.e., with self.amplitude == 0
127
127
else :
128
128
self ._set_local_extrema (1 )
129
129
if (self .local_extrema > 0 and
130
130
self .local_extrema <= self .mle ):
131
131
self ._set_cyc_amplitude ()
132
132
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 )
134
134
levnm2 = level - (2 * self .eddy .interval )
135
135
slamin = 1e5
136
136
for j , i in zip (lmi_j , lmi_i ):
@@ -151,7 +151,7 @@ def all_pixels_above_h0(self, level):
151
151
Check CSS11 criterion 1: The SSH values of all of the pixels
152
152
are above a given SSH threshold for anticyclonic eddies.
153
153
"""
154
- if np . any (self .sla < self .h_0 ):
154
+ if (self .sla < self .h_0 ). any ( ):
155
155
# i.e.,with self.amplitude == 0
156
156
return False
157
157
else :
@@ -161,7 +161,7 @@ def all_pixels_above_h0(self, level):
161
161
self ._set_acyc_amplitude ()
162
162
163
163
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 )
165
165
levnp2 = level + (2 * self .eddy .interval )
166
166
slamax = - 1e5
167
167
for j , i in zip (lmi_j , lmi_i ):
@@ -191,7 +191,7 @@ def _detect_local_minima(self, arr):
191
191
http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array/3689710#3689710
192
192
"""
193
193
# Equivalent
194
- neighborhood = np . ones ((3 , 3 ), dtype = 'bool' )
194
+ neighborhood = ones ((3 , 3 ), dtype = 'bool' )
195
195
#~ neighborhood = generate_binary_structure(arr.ndim, 2)
196
196
197
197
# Get local mimima
@@ -238,14 +238,14 @@ def __init__(self, contour):
238
238
ci_list .append (len (coll .vertices [:, 0 ]))
239
239
li_list .append (len (cont .get_paths ()))
240
240
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' )
249
249
250
250
def get_index_nearest_path (self , level , xpt , ypt ):
251
251
"""
0 commit comments