@@ -59,13 +59,18 @@ def __init__(self, contour, contour_height, data, interval):
59
59
self .contour = contour
60
60
# Link on original grid (local view) or copy if it's on bound
61
61
slice_x , slice_y = contour .bbox_slice
62
- if slice_x .start > slice_x .stop :
62
+ on_bounds = slice_x .start > slice_x .stop
63
+ if on_bounds :
63
64
self .grid_extract = ma .concatenate ((data [slice_x .start :, slice_y ], data [:slice_x .stop , slice_y ]))
64
65
else :
65
66
self .grid_extract = data [slice_x , slice_y ]
66
67
# => maybe replace pixel out of contour by nan?
67
68
self .mask = zeros (self .grid_extract .shape , dtype = 'bool' )
68
- self .mask [contour .pixels_index [0 ] - slice_x .start , contour .pixels_index [1 ] - slice_y .start ] = True
69
+ if on_bounds :
70
+ i_x = (contour .pixels_index [0 ] - slice_x .start ) % data .shape [0 ]
71
+ else :
72
+ i_x = contour .pixels_index [0 ] - slice_x .start
73
+ self .mask [i_x , contour .pixels_index [1 ] - slice_y .start ] = True
69
74
70
75
# Only pixel in contour
71
76
self .sla = data [contour .pixels_index ]
@@ -77,19 +82,9 @@ def __init__(self, contour, contour_height, data, interval):
77
82
def within_amplitude_limits (self ):
78
83
"""Need update
79
84
"""
80
- return True
85
+ return ( self . interval * 2 ) <= self . amplitude
81
86
return self .eddy .ampmin <= self .amplitude <= self .eddy .ampmax
82
87
83
- def _set_cyc_amplitude (self ):
84
- """Get amplitude for cyclone
85
- """
86
- self .amplitude = self .h_0 - self .sla .min ()
87
-
88
- def _set_acyc_amplitude (self ):
89
- """Get amplitude for anticyclone
90
- """
91
- self .amplitude = self .sla .max () - self .h_0
92
-
93
88
def all_pixels_below_h0 (self , level ):
94
89
"""
95
90
Check CSS11 criterion 1: The SSH values of all of the pixels
@@ -101,17 +96,23 @@ def all_pixels_below_h0(self, level):
101
96
else :
102
97
# All local extrema index on th box
103
98
lmi_i , lmi_j = self ._set_local_extrema (1 )
99
+ nb = len (lmi_i )
104
100
slice_x , slice_y = self .contour .bbox_slice
105
- if len (lmi_i ) == 1 :
106
- i , j = lmi_i [0 ] + slice_x .start , lmi_j [0 ] + slice_y .start
101
+ if nb == 0 :
102
+ logging .warning ('No extrema found in contour in level %f' , level )
103
+ return False
104
+ elif nb == 1 :
105
+ i , j = lmi_i [0 ], lmi_j [0 ]
107
106
else :
108
107
# Verify if several extrema are seriously below contour
109
108
nb_real_extrema = ((level - self .grid_extract [lmi_i , lmi_j ]) >= 2 * self .interval ).sum ()
110
109
if nb_real_extrema > self .mle :
111
110
return False
112
111
index = self .grid_extract [lmi_i , lmi_j ].argmin ()
113
- i , j = lmi_i [index ] + slice_x .start , lmi_j [index ] + slice_y .start
114
- self ._set_cyc_amplitude ()
112
+ i , j = lmi_i [index ], lmi_j [index ]
113
+ self .amplitude = abs (self .grid_extract [i , j ] - self .h_0 )
114
+ i += slice_x .start
115
+ j += slice_y .start
115
116
return i , j
116
117
117
118
def all_pixels_above_h0 (self , level ):
@@ -121,23 +122,27 @@ def all_pixels_above_h0(self, level):
121
122
"""
122
123
# In some case pixel value must be very near of contour bounds
123
124
if ((self .sla - self .h_0 ) < - self .EPSILON ).any () or (hasattr (self .sla , 'mask' ) and self .sla .mask .any ()):
124
- # i.e.,with self.amplitude == 0
125
125
return False
126
126
else :
127
-
128
127
# All local extrema index on th box
129
128
lmi_i , lmi_j = self ._set_local_extrema (- 1 )
129
+ nb = len (lmi_i )
130
130
slice_x , slice_y = self .contour .bbox_slice
131
- if len (lmi_i ) == 1 :
132
- i , j = lmi_i [0 ] + slice_x .start , lmi_j [0 ] + slice_y .start
131
+ if nb == 0 :
132
+ logging .warning ('No extrema found in contour in level %f' , level )
133
+ return False
134
+ elif nb == 1 :
135
+ i , j = lmi_i [0 ], lmi_j [0 ]
133
136
else :
134
137
# Verify if several extrema are seriously above contour
135
138
nb_real_extrema = ((self .grid_extract [lmi_i , lmi_j ] - level ) >= 2 * self .interval ).sum ()
136
139
if nb_real_extrema > self .mle :
137
140
return False
138
141
index = self .grid_extract [lmi_i , lmi_j ].argmax ()
139
- i , j = lmi_i [index ] + slice_x .start , lmi_j [index ] + slice_y .start
140
- self ._set_cyc_amplitude ()
142
+ i , j = lmi_i [index ], lmi_j [index ]
143
+ self .amplitude = abs (self .grid_extract [i , j ] - self .h_0 )
144
+ i += slice_x .start
145
+ j += slice_y .start
141
146
return i , j
142
147
143
148
def _set_local_extrema (self , sign ):
@@ -149,7 +154,7 @@ def _set_local_extrema(self, sign):
149
154
# Only index in contour
150
155
m = self .mask [i_x , i_y ]
151
156
i_x , i_y = i_x [m ], i_y [m ]
152
- # Verify if some extramum is contigus
157
+ # Verify if some extremum is contigus
153
158
nb_extrema = len (i_x )
154
159
if nb_extrema > 1 :
155
160
# Group
@@ -316,7 +321,7 @@ def __init__(self, x, y, z, levels, bbox_surface_min_degree, wrap_x=False, keep_
316
321
logging .debug ('Y shape : %s' , y .shape )
317
322
logging .debug ('Z shape : %s' , z .shape )
318
323
logging .info ('Start computing iso lines with %d levels from %f to %f ...' , len (levels ), levels [0 ], levels [- 1 ])
319
- self .contours = ax .contour (x , y , z .T , levels , cmap = 'Spectral_r ' )
324
+ self .contours = ax .contour (x , y , z .T , levels , cmap = 'rainbow ' )
320
325
if wrap_x :
321
326
self .find_wrapcut_path_and_join (x [0 ], x [- 1 ])
322
327
logging .info ('Finish computing iso lines' )
0 commit comments