Skip to content

Commit 514ea2b

Browse files
committed
cycle meteo
1 parent 26a9d4e commit 514ea2b

File tree

2 files changed

+103
-19
lines changed

2 files changed

+103
-19
lines changed

meteo/ECMWF/process_data.py

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@
2828
load_config(config)
2929
from fun_gen import *
3030

31+
# Try to read date as parameters
32+
# ------------------------------
33+
try :
34+
arg_ini = sys.argv[2]
35+
arg_end = sys.argv[3]
36+
37+
# Define parameters
38+
# -----------------
39+
mdini = dt.datetime.strptime(arg_ini,'%Y-%m-%d').toordinal()
40+
mdend = dt.datetime.strptime(arg_end,'%Y-%m-%d').toordinal()
41+
42+
except :
43+
print('No date arguments given')
44+
print('=> Saving all in one file\n')
45+
46+
# Define parameters
47+
# -----------------
48+
mdini = dt.datetime.strptime(meteo_ini,'%Y-%m-%d').toordinal()
49+
mdend = dt.datetime.strptime(meteo_end,'%Y-%m-%d').toordinal()
50+
51+
52+
53+
3154
print('NB /!\: 3-h fields hard coded ...\n')
3255

3356

@@ -52,10 +75,6 @@
5275
LAT,LON = np.meshgrid(lat,lon)
5376

5477

55-
# Define parameters
56-
# -----------------
57-
mdini = dt.datetime.strptime(meteo_ini,'%Y-%m-%d').toordinal()
58-
mdend = dt.datetime.strptime(meteo_end,'%Y-%m-%d').toordinal()
5978
name = 'reanalysis-cerra-single-levels'
6079

6180

@@ -114,10 +133,17 @@
114133

115134
full_data = []
116135

136+
# Tag for file name
137+
tag_ini = dt.datetime.fromordinal(mdini)
138+
tag_ini = tag_ini.strftime('%Y%m%d')
139+
140+
tag_end = dt.datetime.fromordinal(mdend)
141+
tag_end = tag_end.strftime('%Y%m%d')
142+
117143

118144
# Loop on days
119145
# ------------
120-
for jd in range(mdini,mdend+1):
146+
for jd in range(mdini,mdend+2):
121147

122148
date = dt.datetime.fromordinal(jd)
123149
print(date.strftime('%Y-%m-%d'),end='\r')
@@ -194,18 +220,18 @@
194220

195221
# Write variable to NetCDF
196222
# ------------------------
197-
oname = name +'_'+ftag+ '_'+ meteo_ini +'_'\
198-
+ meteo_end +'.nc'
199-
write_nc_meteo(ncdir+'/'+oname,lon,lat,var,full_data,long_name,units)
223+
oname = name +'_'+ftag+ '_'+ tag_ini +'_'\
224+
+ tag_end +'.nc'
225+
write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,var,full_data,long_name,units)
200226

201227
# TEST !!!!!!!
202228
#if ftag == '2m_temperature':
203229
# full_data = full_data[0:2,:,:]
204230

205231
# Write to binary file
206232
# --------------------
207-
full_data.tofile(bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end,format='float32')
208-
print('[FILE SAVED] '+bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end+'\n')
233+
full_data.tofile(bindir+'/BC_'+otag+'_'+tag_ini+'_'+tag_end,format='float32')
234+
print('[FILE SAVED] '+bindir+'/BC_'+otag+'_'+tag_ini+'_'+tag_end+'\n')
209235

210236
'''
211237
data = np.fromfile(bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end,dtype='float32')
@@ -228,7 +254,7 @@
228254

229255
print('Processing wind variables :\n')
230256
print('---------------------------\n')
231-
for jd in range(mdini,mdend+1):
257+
for jd in range(mdini,mdend+2):
232258

233259
date = dt.datetime.fromordinal(jd)
234260
print(date.strftime('%Y-%m-%d'),end='\r')
@@ -278,22 +304,20 @@
278304
oname = name +'_uwind_'+ meteo_ini +'_'\
279305
+ meteo_end +'.nc'
280306

281-
write_nc_meteo(ncdir+'/'+oname,lon,lat,'u10',ufull_data,long_name,units)
307+
write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,'u10',ufull_data,long_name,units)
282308

283309
# V10
284310
long_name = '10 meter V wind component'
285311
oname = name +'_vwind_'+ meteo_ini +'_'\
286312
+ meteo_end +'.nc'
287313

288-
write_nc_meteo(ncdir+'/'+oname,lon,lat,'v10',vfull_data,long_name,units)
314+
write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,'v10',vfull_data,long_name,units)
289315

290316

291317
# Write to binary file
292318
# --------------------
293-
ufull_data.tofile(bindir+'/BC_uwind_'+meteo_ini+'_'+meteo_end,format='float32')
294-
print('[FILE SAVED] '+bindir+'/BC_uwind_'+meteo_ini+'_'+meteo_end)
295-
296-
vfull_data.tofile(bindir+'/BC_vwind_'+meteo_ini+'_'+meteo_end,format='float32')
297-
print('[FILE SAVED] '+bindir+'/BC_vwind_'+meteo_ini+'_'+meteo_end)
298-
319+
ufull_data.tofile(bindir+'/BC_uwind_'+tag_ini+'_'+tag_end,format='float32')
320+
print('[FILE SAVED] '+bindir+'/BC_uwind_'+tag_ini+'_'+tag_end)
299321

322+
vfull_data.tofile(bindir+'/BC_vwind_'+tag_ini+'_'+meteo_end,format='float32')
323+
print('[FILE SAVED] '+bindir+'/BC_vwind_'+tag_ini+'_'+tag_end)

meteo/ECMWF/run_cycles.ksh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/ksh
2+
3+
# ------------------------------ #
4+
# Routine to process meteo data #
5+
# by looping through cycles #
6+
# ------------------------------ #
7+
8+
# Read config as paramater
9+
config=$1
10+
11+
12+
# Load needed parameters
13+
line=`cat ../../config/config_$config.json | grep meteo_ini \
14+
| sed s_'"'__g | sed s/':'/'='/ | sed s/,//`
15+
eval $line
16+
17+
line=`cat ../../config/config_$config.json | grep n_cycle \
18+
| sed s_'"'__g | sed s/':'/'='/ | sed s/,//`
19+
eval $line
20+
21+
22+
line=`cat ../../config/config_$config.json | grep day_cycle \
23+
| sed s_'"'__g | sed s/':'/'='/ | sed s/,//`
24+
eval $line
25+
26+
echo 'Initial date' $meteo_ini
27+
echo 'Number of cycle' $n_cycle
28+
echo 'Number of days per' $day_cycle
29+
echo ''
30+
31+
32+
# Loop on cycles
33+
# --------------
34+
let n_cycle=$n_cycle-1
35+
36+
for cycle in {0..$n_cycle};do
37+
38+
# Define process parameters
39+
# -------------------------
40+
let end=$cycle*$day_cycle
41+
date_start=`date -d "$meteo_ini + $end days" +%Y-%m-%d`
42+
43+
let end=$end+$day_cycle-1
44+
date_end=`date -d "$meteo_ini + $end days" +%Y-%m-%d`
45+
46+
echo ""
47+
echo "###############################################"
48+
echo "# RUNNING CYCLE FROM $date_start to $date_end #"
49+
echo "###############################################"
50+
echo ""
51+
52+
python3 process_data.py $config $date_start $date_end
53+
54+
done
55+
56+
57+
58+
59+
60+

0 commit comments

Comments
 (0)