-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_carbounds.pro
271 lines (209 loc) · 8.96 KB
/
run_carbounds.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
pro run_carbounds,year_tag=year_tag,month_tag=month_tag,run_tag=run_tag
; Total number of towers
n_towers=5
; Total number of groups
n_groups=1
info2={tower_names:strarr(n_towers),lon:fltarr(n_towers),lat:fltarr(n_towers),$
alt:fltarr(n_towers),outdir:' ',indir:' ',year:0l,month:0l,$
max_towers:fltarr(n_groups),lag_towers:0l,lpdm_timestep:0d,dx:0d,$
length:0l,dimx:0d,dimy:0d,dimbx:0d,dimby:0d,dimbz:0d,lag:0d,$
num_days:0l,wrf_file:' ',rel_rate:0d,num_file_per_h:0d,run:' ',$
proj_std_lon:0.,proj_res:30e3,hemisphere:1,true_lats:fltarr(2),proj_proj:1,$
flux_window:0l}
print,tag_names(info2)
restore,"lpd_config.sav",/RELAXED_STRUCTURE_ASSIGNMENT,/VERBOSE,/NO_COMPILE
STRUCT_ASSIGN,/VERBOSE,info,info2
info=info2
print,tag_names(info)
info.run=run_tag
; carsurf input is LPDM output
info.indir=info.outdir
;info.indir='/mc1s2/s3/tul5/OUTPUTS_LPDM_ACT/'
info.outdir='/mc1s2/s4/dfw5129/data/LPDM_2010_fpbounds/'+info.run+'/'
print,info.indir
info.year=year_tag
info.month=month_tag
; Indicate the number of towers in each group
; read in from saved LPDM configuration
;info.max_towers=[1] ;,4,5]
; LPDM output time step (in seconds)
; int(60/info.num_file_per_h)
; Keep in sync with updates to run_lpdm.pro
; TODO: change to read LPD config file
info.lpdm_timestep=60.
; Resolution of the domain
; km?
info.dx=27.
; Number of particles released over an hour
info.rel_rate=35.
; Number of LPDM output files per hour
; copy from LPDM dtoutp
info.num_file_per_h=3.
; WRF file for projection parameters
info.wrf_file='/mc1s2/s4/mpb186/CMS_WRF/Output/2010012312/wrfout_d01_2010-01-24_12:00:00'
; Lag for each period (spin-up time between flux steps and obs time)
; (in day)
;; flux lag in other scripts
info.lag=info.flux_window
; Number of days
day_month=[31,28,31,30,31,30,31,31,30,31,30,31]
test_leap=leap_or_not(info.year)
if test_leap eq 1 then day_month=[31,29,31,30,31,30,31,31,30,31,30,31]
info.num_days=(day_month(info.month-1)+info.lag)
; Flux time steps (in hour)
; number of hours back to include in the footprint files
;; Make sure this corresponds to the lag
;; carsurf_loop divides this by the flux interval to get dimension
;; sizes.
info.length=info.lag * 24
; Names of the sites (now read in from LPDM config savefile)
;; info.site_names=[strtrim(fix(findgen(n_towers))+1,1)]
;; for i=0,n_towers-1 do if ((i+1) lt 10) then info.site_names[i]='0'+info.site_names[i]
; Copy these from LPDM namelist specification in run_lpdm.pro
; Dimensions of the domain
info.dimx=249
info.dimy=184
; for output of carbound
; Dimensions of the boundaries
; Number of walls
info.dimbx=4.
; Number of horiz. pixels on each boundary
info.dimby=29.
; Number of vertical levels
info.dimbz=6.
info.lag_towers=0l
for i=0,n_groups-1 do begin
prep_carbound,i,info,input
create_sub_surf,i,info,input
submit_carsurf,i,info,input
; create_sub_bound,i,info,input
; submit_carbound,i,info,input
info.lag_towers+=info.max_towers(i)
print,input.site_names
end
stop
end
pro submit_carbound,group,info,input
spawn,'qsub -q kjd1 Sub_Carb_'+info.run+'_'+strtrim(info.year,1)+'_M'+input.month+'_G'+strtrim(group+1,1)+'.csh'
end
pro create_sub_bound,group,info,input
month=strtrim( fix( ((findgen(14)+11) mod 12)+1),1)
for i=0,13 do if ((i+11) mod 12)+1 lt 10 then month(i)='0'+month(i)
for j=0,n_elements(info.max_towers)-1 do begin
openw,lun,'Sub_Carb_'+info.run+'_'+strtrim(info.year,1)+'_M'+month(info.month)+'_G'+strtrim(j+1,1)+'.csh',/get_lun
printf,lun,"#!/bin/bash"
printf,lun,"#"
printf,lun,"# Example PBS script to run a job on the cluster."
printf,lun,"# The lines beginning #PBS set various queuing parameters."
printf,lun,"#"
printf,lun,"#PBS -N CARB_"+info.run+"_"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)
printf,lun,"#PBS -e logCarbound"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)+".e"
printf,lun,"#PBS -o logCarbound"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)+".o"
printf,lun,"#PBS -l nodes=1:ppn=8"
printf,lun,"#PBS -m bea"
printf,lun,"#"
printf,lun,"# o Export all my environment variables to the job"
printf,lun,"#PBS -V"
printf,lun,"#"
printf,lun,"# cd ~/LPDM/"
printf,lun,"idl << EOF"
printf,lun,".comp carbounds_loop"
printf,lun,".comp carbounds_loop"
printf,lun,"carbounds_loop, tag='"+info.outdir+"input_"+strtrim(info.year,1)+"_M"+input.month+"_G"+strtrim(group+1,1)+".sav'"
printf,lun,"EOF"
free_lun,lun
end
end
pro submit_carsurf,group,info,input
spawn,'qsub -q kjd1 Sub_Cars_'+info.run+'_'+strtrim(info.year,1)+'_M'+input.month+'_G'+strtrim(group+1,1)+'.csh'
end
pro create_sub_surf,group,info,input
month=strtrim( fix( ((findgen(14)+11) mod 12)+1),1)
for i=0,13 do if ((i+11) mod 12)+1 lt 10 then month(i)='0'+month(i)
for j=0,n_elements(info.max_towers)-1 do begin
openw,lun,'Sub_Cars_'+info.run+'_'+strtrim(info.year,1)+'_M'+month(info.month)+'_G'+strtrim(j+1,1)+'.csh',/get_lun
printf,lun,"#!/bin/bash"
printf,lun,"#"
printf,lun,"# Example PBS script to run a job on the cluster."
printf,lun,"# The lines beginning #PBS set various queuing parameters."
printf,lun,"#"
printf,lun,"#PBS -N CARS_"+info.run+"_"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)
printf,lun,"#PBS -e logCarsurf"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)+".e"
printf,lun,"#PBS -o logCarsurf"+strtrim(info.year,1)+"_M"+month(info.month)+"_G"+strtrim(j+1,1)+".o"
;; Python:
;; 2 week lag with 35 particles/time step, 20s time step, 27 km grid uses about 6GB and 20 hours (probably)
;; no idea how to generalize that.
printf,lun,"#PBS -l nodes=1:ppn=4"
printf,lun,"#PBS -m bae"
printf,lun,"#"
printf,lun,"# o Export all my environment variables to the job"
printf,lun,"#PBS -V"
printf,lun,"#"
printf,lun,"# cd ~/LPDM/"
;; printf,lun,". ~/LPDM.intel"
printf,lun,"source activate lpdm_post"
printf,lun,"export OMP_NUM_THREADS=4"
printf,lun,"python carsurf_loop.py '"+info.outdir+"input_"+strtrim(info.year,1)+"_M"+input.month+"_G"+strtrim(group+1,1)+".sav'"
free_lun,lun
end
end
pro prep_carbound,group,info,input
here_towers = info.max_towers[group]
input={site_names:strarr(here_towers),lpdm_timestep:0d,$
dx:0d,length:0l,dimx:0d,dimy:0d,dimbx:0d,dimby:0d,dimbz:0d,$
lag:0d,num_days:0l,indir:' ',outdir:' ',ini_date:0l,month:' ',$
wrf_file:' ',rel_rate:0d,num_file_per_h:0d,$
lon:fltarr(here_towers),lat:fltarr(here_towers),$
alt:fltarr(here_towers),proj_std_lon:0.,proj_res:30e3,hemisphere:1,$
true_lats:fltarr(2),proj_proj:1,year:' '}
input.site_names[0:info.max_towers[group]-1]=$
info.tower_names[info.lag_towers:info.lag_towers+info.max_towers(group)-1]
input.lpdm_timestep=info.lpdm_timestep
input.dx=info.dx
input.length=info.length
input.dimx=info.dimx
input.dimy=info.dimy
input.num_days=info.num_days
input.dimbx=info.dimbx
input.dimby=info.dimby
input.dimbz=info.dimbz
input.rel_rate=info.rel_rate
input.num_file_per_h=info.num_file_per_h
input.lag=info.lag
; copy info needed for aux coords
input.lon[0:info.max_towers[group]-1]=info.lon[info.lag_towers:info.lag_towers+$
info.max_towers(group)-1]
input.lat[0:info.max_towers[group]-1]=info.lat[info.lag_towers:info.lag_towers+$
info.max_towers(group)-1]
input.alt[0:info.max_towers[group]-1]=info.alt[info.lag_towers:info.lag_towers+$
info.max_towers(group)-1]
input.proj_std_lon=info.proj_std_lon
input.proj_res=info.proj_res
input.hemisphere=info.hemisphere
input.true_lats=info.true_lats
input.proj_proj=info.proj_proj
input.year=info.year
spawn,'mkdir -p '+info.outdir+strtrim(info.year,1)
input.wrf_file=info.outdir+strtrim(info.year,1)+'/'+$
strmid(info.wrf_file,strpos(info.wrf_file,'wrfout_d0'),45)
; I don't need all the file, so I'm dropping everything but XLAT and XLONG
spawn,'ncks -v XLAT,XLONG --dimension time,0 --deflate 6 --netcdf4 '+ $
info.wrf_file + ' --overwrite --output ' + input.wrf_file
month=strtrim( fix( ((findgen(14)+11) mod 12)+1),1)
for i=0,13 do if ((i+11) mod 12)+1 lt 10 then month(i)='0'+month(i)
input.month=month(info.month)
input.ini_date=1l
input.outdir=info.outdir+'/'+strtrim(info.year,1)+'/'+input.month+'/GROUP'+strtrim(group+1,1)+'/'
input.indir=info.indir+'/'+strtrim(info.year,1)+'/'+input.month+'/GROUP'+strtrim(group+1,1)+'/'
spawn,'mkdir -p '+info.outdir+strtrim(info.year,1)+'/'+input.month+'/'
spawn,'mkdir -p '+input.outdir+'/'
save,input,filename=info.outdir+'input_'+strtrim(info.year,1)+'_M'+input.month+'_G'+strtrim(group+1,1)+'.sav'
end
function leap_or_not,year_select_in
; This function tests if the year is a leap year or not
; It should work for any year (not limited to a period)
flag_leap=0l
if (((year_select_in mod 4) eq 0) and ((year_select_in mod 100) ne 0)) or $
((year_select_in mod 400) eq 0) then flag_leap=1
return, flag_leap
end