Skip to content

Commit b02273c

Browse files
committed
update code
1 parent f0833e0 commit b02273c

File tree

2 files changed

+77
-34
lines changed

2 files changed

+77
-34
lines changed

examples/detection_gigatl6.py

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class RomsDataset(UnRegularGridDataset):
1313

1414
def init_speed_coef(self, uname, vname):
1515
# xi_u and eta_v must be specified because this dimension are not use in lon/lat
16+
print(self.indexs)
1617
u = self.grid(uname, indexs=self.indexs)
1718
v = self.grid(vname, indexs=self.indexs)
19+
print('u.shape',u.shape)
20+
1821
u = self.rho_2d(u.T).T
1922
v = self.rho_2d(v)
2023
self._speed_norm = (v ** 2 + u ** 2) ** .5
@@ -46,59 +49,94 @@ def psi2rho(var_psi):
4649
var_rho[:,Lp-1]=var_rho[:,L-1]
4750
return var_rho
4851

52+
##########################
4953

54+
varname = 'zeta'
5055

56+
##########################
5157

5258
if __name__ == '__main__':
5359
start_logger().setLevel('DEBUG')
5460

5561
# Pick a depth
56-
s_rho = 5 # 1000 m
57-
depths = arange(-3500, 0, 500) # Make sure it is the same than used to generate the 'horizontal_section' files.
58-
59-
depth = depths[s_rho]
62+
63+
if varname == 'zeta':
64+
s_rho = -1
65+
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]
6070

6171
# Time loop
62-
for time in range(7000, 7020):
72+
for time in range(34800, 34801):
6373

64-
65-
infiletime = time%10
66-
filetime = time - time%10
74+
dtfile = 120
75+
infiletime = time%dtfile
76+
filetime = time - time%dtfile
6777

6878
# Using times:
69-
grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}'.format(filetime) + '.nc'
79+
#grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}'.format(filetime) + '.nc'
7080

71-
# or using dates
72-
realyear_origin = datetime(2004,1,15)
73-
date1 = realyear_origin + timedelta(days=float(time)/2.)
74-
date2 = date1 + timedelta(days=float(4.5))
75-
76-
filedate = '{0:04}'.format(date1.year)+'-'+\
77-
'{0:02}'.format(date1.month) + '-'+\
78-
'{0:02}'.format(date1.day)+ '-'+\
79-
'{0:04}'.format(date2.year)+'-'+\
80-
'{0:02}'.format(date2.month) + '-' +\
81-
'{0:02}'.format(date2.day)
81+
if varname =='ow':
82+
grid_name = './GIGATL6/gigatl6_1h_horizontal_section.' + '{0:05}'.format(filetime) + '.nc'
83+
84+
85+
elif varname == 'zeta':
86+
87+
# or using dates
88+
realyear_origin = datetime(2004,1,15)
89+
date1 = realyear_origin + timedelta(days=float(filetime)/24.)
90+
date2 = date1 + timedelta(days=float(4.5))
91+
92+
filedate = '{0:04}'.format(date1.year)+'-'+\
93+
'{0:02}'.format(date1.month) + '-'+\
94+
'{0:02}'.format(date1.day)+ '-'+\
95+
'{0:04}'.format(date2.year)+'-'+\
96+
'{0:02}'.format(date2.month) + '-' +\
97+
'{0:02}'.format(date2.day)
8298

83-
print(filedate)
84-
85-
lon_name, lat_name = 'lon', 'lat'
86-
99+
print(filedate)
87100

101+
grid_name = './GIGATL6/GIGATL6_1h_inst_surf_' + filedate + '.nc'
102+
103+
104+
# Identification
105+
if varname=='zeta':
106+
lon_name, lat_name = 'nav_lon_rho', 'nav_lat_rho'
107+
elif varname=='ow':
108+
lon_name, lat_name = 'lon', 'lat'
109+
110+
# domain grid points: x1, x2, y1, y2
111+
x1, x2 = 0, 1500
112+
y1, y2 = 0, 2000
113+
88114
h = RomsDataset(grid_name, lon_name, lat_name,
89115
indexs=dict(time=infiletime,
90-
eta_rho=slice(500, 800),
91-
xi_rho=slice(500, 800),
92-
eta_v=slice(500, 800-1),
93-
xi_u=slice(500, 800-1),
116+
eta_rho=slice(y1, y2),
117+
xi_rho=slice(x1, x2),
118+
eta_v=slice(y1, y2-1),
119+
xi_u=slice(x1, x2-1),
120+
y_rho=slice(y1, y2),
121+
x_rho=slice(x1, x2),
122+
y_v=slice(y1, y2-1),
123+
y_u=slice(y1, y2),
124+
x_u=slice(x1, x2-1),
125+
x_v=slice(x1, x2),
94126
s_rho=s_rho)
95127
)
96128

97129
# Must be set with time of grid
98130
date = date1
99131

100-
# Identification every 2 mm
101-
a, c = h.eddy_identification('ow', 'u', 'v', date, z_min = -10, z_max = -0.1, step = 0.05, pixel_limit=(10, 2000), shape_error=40, force_height_unit='m',force_speed_unit='m/s',vorticity_name='vrt')
132+
# Identification
133+
if varname=='zeta':
134+
z_min = -2 ; z_max = 1; step = 0.02
135+
elif varname=='ow':
136+
z_min = -10; z_max = -0.1; step = 0.05
137+
138+
139+
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')
102140

103141
filename = 'gigatl6_1h_horizontal_section_' + '{0:04}'.format(-depth) + '_'
104142

src/py_eddy_tracker/dataset/grid.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,11 @@ def eddy_identification(
665665
if precision is not None:
666666
precision /= factor
667667

668-
# Get ssh grid
669-
data = 1e10*self.grid(grid_height).astype("f8")
668+
# Get ssh or ow
669+
if grid_height in ['ow']:
670+
data = 1e10 * self.grid(grid_height).astype("f8")
671+
else:
672+
data = self.grid(grid_height).astype("f8")
670673

671674
if grid_height in ['ow']:
672675
# Get vorticity as an aditional field (to identify cyc/acyc)
@@ -706,9 +709,10 @@ def eddy_identification(
706709
)
707710
z_min, z_max = z_min_p, z_max_p
708711

709-
print('step1 z_min, z_max, step',z_min, z_max, step) #debug
712+
logger.warning('z_min, z_max, step are: %f, %f, %f.',z_min, z_max, step) #debug
710713
levels = arange(z_min - z_min % step, z_max - z_max % step + step, step)
711-
714+
print('levels used are:',levels)
715+
712716
# Get x and y values
713717
x, y = self.x_c, self.y_c
714718

@@ -740,6 +744,7 @@ def eddy_identification(
740744
else:
741745
iterator = 1 if anticyclonic_search else -1
742746

747+
743748
# Loop over each collection
744749
for coll_ind, coll in enumerate(self.contours.iter(step=iterator)):
745750
corrected_coll_index = coll_ind

0 commit comments

Comments
 (0)