@@ -59,13 +59,18 @@ def __init__(self, contour, contour_height, data, interval):
5959 self .contour = contour
6060 # Link on original grid (local view) or copy if it's on bound
6161 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 :
6364 self .grid_extract = ma .concatenate ((data [slice_x .start :, slice_y ], data [:slice_x .stop , slice_y ]))
6465 else :
6566 self .grid_extract = data [slice_x , slice_y ]
6667 # => maybe replace pixel out of contour by nan?
6768 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
6974
7075 # Only pixel in contour
7176 self .sla = data [contour .pixels_index ]
@@ -77,19 +82,9 @@ def __init__(self, contour, contour_height, data, interval):
7782 def within_amplitude_limits (self ):
7883 """Need update
7984 """
80- return True
85+ return ( self . interval * 2 ) <= self . amplitude
8186 return self .eddy .ampmin <= self .amplitude <= self .eddy .ampmax
8287
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-
9388 def all_pixels_below_h0 (self , level ):
9489 """
9590 Check CSS11 criterion 1: The SSH values of all of the pixels
@@ -101,17 +96,23 @@ def all_pixels_below_h0(self, level):
10196 else :
10297 # All local extrema index on th box
10398 lmi_i , lmi_j = self ._set_local_extrema (1 )
99+ nb = len (lmi_i )
104100 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 ]
107106 else :
108107 # Verify if several extrema are seriously below contour
109108 nb_real_extrema = ((level - self .grid_extract [lmi_i , lmi_j ]) >= 2 * self .interval ).sum ()
110109 if nb_real_extrema > self .mle :
111110 return False
112111 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
115116 return i , j
116117
117118 def all_pixels_above_h0 (self , level ):
@@ -121,23 +122,27 @@ def all_pixels_above_h0(self, level):
121122 """
122123 # In some case pixel value must be very near of contour bounds
123124 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
125125 return False
126126 else :
127-
128127 # All local extrema index on th box
129128 lmi_i , lmi_j = self ._set_local_extrema (- 1 )
129+ nb = len (lmi_i )
130130 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 ]
133136 else :
134137 # Verify if several extrema are seriously above contour
135138 nb_real_extrema = ((self .grid_extract [lmi_i , lmi_j ] - level ) >= 2 * self .interval ).sum ()
136139 if nb_real_extrema > self .mle :
137140 return False
138141 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
141146 return i , j
142147
143148 def _set_local_extrema (self , sign ):
@@ -149,7 +154,7 @@ def _set_local_extrema(self, sign):
149154 # Only index in contour
150155 m = self .mask [i_x , i_y ]
151156 i_x , i_y = i_x [m ], i_y [m ]
152- # Verify if some extramum is contigus
157+ # Verify if some extremum is contigus
153158 nb_extrema = len (i_x )
154159 if nb_extrema > 1 :
155160 # Group
@@ -316,7 +321,7 @@ def __init__(self, x, y, z, levels, bbox_surface_min_degree, wrap_x=False, keep_
316321 logging .debug ('Y shape : %s' , y .shape )
317322 logging .debug ('Z shape : %s' , z .shape )
318323 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 ' )
320325 if wrap_x :
321326 self .find_wrapcut_path_and_join (x [0 ], x [- 1 ])
322327 logging .info ('Finish computing iso lines' )
0 commit comments