Skip to content

Commit a2815c5

Browse files
committed
add datarmor example
1 parent b02273c commit a2815c5

File tree

2 files changed

+120
-24
lines changed

2 files changed

+120
-24
lines changed
Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# for plotting
88
from matplotlib import pyplot as plt
99

10+
import sys,os,shutil
11+
12+
1013
class 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

5865
if __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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
#PBS -q omp
3+
#PBS -l ncpus=2
4+
#PBS -l mem=65g
5+
#PBS -l walltime=24:00:00
6+
# COMMENT
7+
# Tina ODAKA 06.03.2017
8+
# example for using datarmor with 'queue omp' in a personalised way
9+
# By default, if you use 'omp' it use 1 node with 2 openmp threads
10+
# here we show you example of it using 10 openmp threads (specify ncpus=10)
11+
# and it use 10g of memory in this example (specifly mem=10g)
12+
# and you can run max for 30 minutes with walltime setting
13+
# To optimised multi thread, you need to place a command 'omplace' before your 'exe'
14+
# Here, in this example, we suppose that your code 'exe' is compiled with
15+
# intel compiler.
16+
# for the users who use gnu compiler, plz use omp.10g.gnu.pbs
17+
#
18+
# cd to the directory you submitted your job
19+
20+
cd $PBS_O_WORKDIR
21+
qstat -f $PBS_JOBID
22+
23+
#####################
24+
25+
26+
27+
source /usr/share/Modules/3.2.10/init/bash
28+
module load anaconda-py3.6/4.7.12
29+
30+
#####################
31+
32+
#export PYTHONPATH=$HOME/Python_Modules_p3
33+
#setenv PYTHONPATH $HOME/Python_Modules_p3
34+
source activate eddy-track
35+
36+
37+
38+
#####################
39+
run='run00'
40+
variable='ow'
41+
42+
mkdir $variable/$run
43+
44+
python detection_gigatl6.py $variable $run >& $variable/$run/output_detection_$run
45+
46+
47+

0 commit comments

Comments
 (0)