77# for plotting
88from matplotlib import pyplot as plt
99
10+ import sys ,os ,shutil
11+
12+
1013class RomsDataset (UnRegularGridDataset ):
1114
1215 __slots__ = list ()
@@ -51,42 +54,82 @@ def psi2rho(var_psi):
5154
5255##########################
5356
54- varname = 'zeta'
57+ varname = sys .argv [1 ]
58+
59+ print ("varname id %s" , varname )
60+
61+ #varname = 'zeta'
5562
5663##########################
5764
5865if __name__ == '__main__' :
5966 start_logger ().setLevel ('DEBUG' )
67+
68+
69+
70+ ####
71+ # create case-specific folder
72+ folder = varname + '/' + sys .argv [2 ] + '/'
73+
74+ try :
75+ os .mkdir (folder )
76+ except OSError :
77+ print ("Directory %s already exists" % folder )
78+
79+
80+ # copy script in folder
81+ shutil .copy ('detection_gigatl6.py' ,folder )
82+
6083
61- # Pick a depth
84+ # Pick a depth/isopycnal
6285
6386 if varname == 'zeta' :
6487 s_rho = - 1
6588 depth = 0
66- else :
67- s_rho = 5 # 1000 m
68- depths = arange (- 3500 , 0 , 500 ) # Make sure it is the same than used to generate the 'horizontal_section' files.
69- depth = depths [s_rho ]
89+ elif varname == 'ow' :
90+ #isopycnal
91+ grid_name = './iso/gigatl6_1h_isopycnal_section.01440.nc'
92+ nc = Dataset (grid_name ,'r' )
93+ isopycnals = nc .variables ['isopycnal' ][:]
94+ nc .close ()
95+
96+ s_rho = 1 #
97+ depth = isopycnals [s_rho ]
98+
99+
70100
71101 # Time loop
72- for time in range (34800 , 34801 ):
102+ #for time in range(34800, 34801):
103+ for time in range (1440 , 6000 ):
104+
105+
106+ # hourly data
107+ #dtfile = 1
108+ # 12-hourly
109+ dtfile = 12
110+
111+ tfile = 5 * 24 // dtfile
112+
113+ ###########
114+ realyear_origin = datetime (2004 ,1 ,15 )
115+ date = realyear_origin + timedelta (days = float (time )* dtfile / 24. )
116+
117+ infiletime = time % tfile
118+ filetime = time - time % tfile
73119
74- dtfile = 120
75- infiletime = time % dtfile
76- filetime = time - time % dtfile
77120
78121 # Using times:
79122 #grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}'.format(filetime) + '.nc'
80123
81124 if varname == 'ow' :
82- grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}' .format (filetime ) + '.nc'
125+ #grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}'.format(filetime) + '.nc'
126+ grid_name = './iso/gigatl6_1h_isopycnal_section.' + '{0:05}' .format (filetime ) + '.nc'
83127
84128
85129 elif varname == 'zeta' :
86130
87131 # or using dates
88- realyear_origin = datetime (2004 ,1 ,15 )
89- date1 = realyear_origin + timedelta (days = float (filetime )/ 24. )
132+ date1 = realyear_origin + timedelta (days = float (filetime )* dtfile / 24. )
90133 date2 = date1 + timedelta (days = float (4.5 ))
91134
92135 filedate = '{0:04}' .format (date1 .year )+ '-' + \
@@ -98,7 +141,7 @@ def psi2rho(var_psi):
98141
99142 print (filedate )
100143
101- grid_name = './GIGATL6 /GIGATL6_1h_inst_surf_' + filedate + '.nc'
144+ grid_name = './HIS /GIGATL6_1h_inst_surf_' + filedate + '.nc'
102145
103146
104147 # Identification
@@ -108,11 +151,14 @@ def psi2rho(var_psi):
108151 lon_name , lat_name = 'lon' , 'lat'
109152
110153 # domain grid points: x1, x2, y1, y2
111- x1 , x2 = 0 , 1500
154+ x1 , x2 = 400 , 1200
155+ y1 , y2 = 400 , 1200
156+
157+ x1 , x2 = 0 , 1600
112158 y1 , y2 = 0 , 2000
113159
114160 h = RomsDataset (grid_name , lon_name , lat_name ,
115- indexs = dict (time = infiletime ,
161+ indexs = dict (time = infiletime ,time_counter = infiletime ,
116162 eta_rho = slice (y1 , y2 ),
117163 xi_rho = slice (x1 , x2 ),
118164 eta_v = slice (y1 , y2 - 1 ),
@@ -126,23 +172,26 @@ def psi2rho(var_psi):
126172 s_rho = s_rho )
127173 )
128174
129- # Must be set with time of grid
130- date = date1
175+
131176
132177 # Identification
133178 if varname == 'zeta' :
134- z_min = - 2 ; z_max = 1 ; step = 0.02
179+ z_min = - 2 ; z_max = 1.5 ; step = 0.02
135180 elif varname == 'ow' :
136- z_min = - 10 ; z_max = - 0.1 ; step = 0.05
181+ # ow is multiplied by 1e10
182+ z_min = - 1 ; z_max = - 0.01 ; step = 0.01
137183
138184
139185 a , c = h .eddy_identification (varname , 'u' , 'v' , date , z_min = z_min , z_max = z_max , step = step , pixel_limit = (10 , 2000 ), shape_error = 40 , force_height_unit = 'm' ,force_speed_unit = 'm/s' ,vorticity_name = 'vrt' )
140186
141- filename = 'gigatl6_1h_horizontal_section_' + '{0:04}' .format (- depth ) + '_'
187+
188+ ####
189+
190+ filename = 'gigatl6_1h_' + varname + '_' + '{0:04}' .format (depth ) + '_'
142191
143- with Dataset (date .strftime ('Anticyclonic_' + filename + '%Y%m%d%H.nc' ), 'w' ) as h :
192+ with Dataset (date .strftime (folder + 'Anticyclonic_' + filename + '%Y%m%d%H.nc' ), 'w' ) as h :
144193 a .to_netcdf (h )
145- with Dataset (date .strftime ('Cyclonic_' + filename + '%Y%m%d%H.nc' ), 'w' ) as h :
194+ with Dataset (date .strftime (folder + 'Cyclonic_' + filename + '%Y%m%d%H.nc' ), 'w' ) as h :
146195 c .to_netcdf (h )
147196
148197 # PLOT
@@ -157,6 +206,6 @@ def psi2rho(var_psi):
157206 a .display (ax , color = 'b' , linewidth = .5 )
158207 c .display (ax , color = 'r' , linewidth = .5 )
159208 ax .grid ()
160- fig .savefig ('eddies_' + date .strftime ( filename + '%Y%m%d%H' ) + '.png' )
209+ fig .savefig (folder + 'eddies_' + date .strftime ( filename + '%Y%m%d%H' ) + '.png' )
161210
162211
0 commit comments