source: lmdz_wrf/trunk/tools/getting_fields-trajectories.bash @ 1906

Last change on this file since 1906 was 661, checked in by lfita, 9 years ago

Adding las improvements in the script

  • Property svn:executable set to *
File size: 14.2 KB
Line 
1#!/bin/bash -x
2# Script to analyse results from model outputs following trajectories
3# L. Fita, LMD May 2015
4
5# isim: folder with the model outputs
6# osim: folder for the outputs of the analysis
7
8# A file called 'trajectory.dat' is mandatory to proceed
9# Concatenated file `netcdf_fold_concatenated.nc' is used to retrieve the trajectory
10# Output
11##
12# netcdf_fold_concatenated.nc: File with only `P' to retrieve the trajectory
13# full_concatenated.nc: File with a given set of variables concatenated
14# diagnostics.nc: file with the computed diagnostics
15# fullout.nc: merge of `full_concatenated.nc' and `diagnostics.nc'
16# tevol_boxtraj.nc: file with the values following the trajectory
17
18models='wrf:lwrf'
19
20ifold=/media/ExtDiskD/bkup/ciclad/etudes/WL_HyMeX/superstorm
21ofold=/home/lluis/etudes/WL_HyMeX/superstorm
22
23#WRFexps='control:mp1:pbl1:pbl2:rad1'
24WRFexps='control:cu1:pblsfc1:rad1:shallow'
25LMDZexps='lmdza:lmdzb'
26LWRFexps='lmdza:lmdzb'
27
28# Domain to analyse
29dom='1'
30
31#ofold=/homedata/lfita/etudes/WRFdynamicoSENS
32#HOMEpy=/home/lfita/etudes/WRF_LMDZ/svn/LMDZ_WRF/tools
33HOMEpy=/home/lluis/etudes/WRF_LMDZ/svn/LMDZ_WRF/tools
34
35use_concatenated=true
36
37####### ###### ##### #### ### ## #
38errormsg='ERROR -- error -- ERROR -- error'
39main='getting_fields-trajectories.bash'
40
41#WRFvars='all'
42WRFvars='Times,XLONG,XLAT,T2,U10,V10,P,PB,PSFC,HGT,T,QVAPOR,RAINC,RAINNC'
43
44#LMDZvars='all'
45LMDZars='Time_counter,longitude,latitude,u10m,v10m,t2m,wind10m,slp,precip'
46
47LWRFvars='Times,XLONG,XLAT,T2,U10,V10,P,PB,PSFC,HGT,T,QVAPOR,RAINC,RAINNC'
48#LWRFvars='LU_INDEX,ZNU,ZNW,ZS,DZS,U,RU_TEND,V,RV_TEND,W,PH,PHB,T,HFX_FORCE,LH_FORCE,'
49#LWRFvars=${LWRFvars}'TSK_FORCE,HFX_FORCE_TEND,LH_FORCE_TEND,TSK_FORCE_TEND,MU,MUB,'
50#LWRFvars=${LWRFvars}'NEST_POS,P,PB,FNM,FNP,RDNW,RDN,DNW,DN,CFN,CFN1,P_HYD,Q2,T2,TH2,'
51#LWRFvars=${LWRFvars}'PSFC,U10,V10,RDX,RDY,RESM,ZETATOP,CF1,CF2,CF3,XTIME,QVAPOR,'
52#LWRFvars=${LWRFvars}'LANDMASK,TOPOSTDV,TSLB,SMOIS,SH2O,SMCREL,SEAICE,XICEM,SFROFF,'
53#LWRFvars=${LWRFvars}'UDROFF,VEGFRA,GRDFLX,ACGRDFLX,SNOW,SNOWH,CANWAT,SST,SSTSK,LAI,'
54#LWRFvars=${LWRFvars}'H_DIABATIC,MAPFAC_M,MAPFAC_U,MAPFAC_V,MAPFAC_MX,MAPFAC_MY,'
55#LWRFvars=${LWRFvars}'MAPFAC_UX,MAPFAC_UY,MAPFAC_VX,MF_VX_INV,MAPFAC_VY,F,E,SINALPHA,'
56#LWRFvars=${LWRFvars}'COSALPHA,HGT,TSK,P_TOP,T00,P00,TLP,TISO,MAX_MSTFX,MAX_MSTFY,'
57#LWRFvars=${LWRFvars}'RAINC,RAINSH,RAINNC,SNOWNC,GRAUPELNC,HAILNC,CLDFRA,SWDOWN,GLW,'
58#LWRFvars=${LWRFvars}'SWNORM,OLR,XLAT,XLONG,XLAT_U,XLONG_U,XLAT_V,XLONG_V,ALBEDO,'
59#LWRFvars=${LWRFvars}'ALBBCK,EMISS,NOAHRES,TMN,XLAND,ZNT,UST,PBLH,HFX,QFX,LH,ACHFX,'
60#LWRFvars=${LWRFvars}'ACLHF,SNOWC,SR,POTEVP,SNOPCX,SOILTB,LAGES_LIC,LAGES_OCE,'
61#LWRFvars=${LWRFvars}'LAGES_SIC,LAGES_TER,LAIRE,LAIRETER,LALB1,LALB2,LALBE_LIC,'
62#LWRFvars=${LWRFvars}'LALBE_OCE,LALBE_SIC,LALBE_TER,LALE,LALE_BL,LALE_WK,LALP,LALP_BL,'
63#LWRFvars=${LWRFvars}'LALP_WK,LA_TH,LBETA_PREC,LBILS,LBILS_DISS,LBILS_EC,'
64#LWRFvars=${LWRFvars}'LBILS_ENTHALP,LBILS_KINETIC,LBILS_LATENT,LBILS_TKE,LCAPE,'
65#LWRFvars=${LWRFvars}'LCAPE_MAX,LCDRH,LCDRM,LCLDEMI,LCLDH,LCLDL,LCLDM,LCLDQ,LCLDT,'
66#LWRFvars=${LWRFvars}'LCLDTAU,LCLWCON,LCONTFRACATM,LCONTFRACOR,LCUMPB,LCUMRN,LDMC,'
67#LWRFvars=${LWRFvars}'LDNWD,LDNWD0,LDQAJS,LDQCON,LDQDYN,LDQEVA,LDQLSC,LDQLSCST,'
68#LWRFvars=${LWRFvars}'LDQLSCTH,LDQPHY,LDQTHE,LDQVDF,LDQWAK,LDTAJS,LDTCON,LDTDIS,'
69#LWRFvars=${LWRFvars}'LDTDYN,LDTEC,LDTEVA,LD_TH,LDTHMIN,LDTLIF,LDTLSC,LDTLSCHR,'
70#LWRFvars=${LWRFvars}'LDTLSCST,LDTLSCTH,LDTLW0,LDTLWR,LDTORO,LDTPHY,LDTSVDFG,LDTSVDFI,'
71#LWRFvars=${LWRFvars}'LDTSVDFO,LDTSVDFT,LDTSW0,LDTSWR,LDTTHE,LDTVDF,LDTWAK,LDUCON,'
72#LWRFvars=${LWRFvars}'LDUDYN,LDULIF,LDUORO,LDUVDF,LDVCON,LDVDYN,LDVLIF,LDVORO,LDVVDF,'
73#LWRFvars=${LWRFvars}'LEC550AER,LE_TH,LEVAP,LEVAP_LIC,LEVAP_OCE,LEVAPPOT_LIC,'
74#LWRFvars=${LWRFvars}'LEVAPPOT_OCE,LEVAPPOT_SIC,LEVAPPOT_TER,LEVAP_SIC,LEVAP_TER,LEVU,'
75#LWRFvars=${LWRFvars}'LFBASE,LFDER,LFFONTE,LFL,LFLAT,LFLW_LIC,LFLW_OCE,LFLW_SIC,'
76#LWRFvars=${LWRFvars}'LFLW_TER,LFQCALVING,LFQFONTE,LFRACT_LIC,LFRACT_OCE,LFRACT_SIC,'
77#LWRFvars=${LWRFvars}'LFRACT_TER,LFSNOW,LFSW_LIC,LFSW_OCE,LFSW_SIC,LFSW_TER,'
78#LWRFvars=${LWRFvars}'LFTIME_CON,LFTIME_TH,LGEOP,LH2O,LIWCON,LIWP,LKZ,LKZ_MAX,'
79#LWRFvars=${LWRFvars}'LLAMBDA_TH,LLAT_LIC,LLAT_OCE,LLAT_SIC,LLAT_TER,LLMAXTH,LLWCON,'
80#LWRFvars=${LWRFvars}'LLWDN200,LLWDN200CLR,LLWDNSFC,LLWDNSFCCLR,LLWDOWNOR,LLWP,'
81#LWRFvars=${LWRFvars}'LLWUP200,LLWUP200CLR,LLWUPSFC,LLWUPSFCCLR,LMA,LMASS,LMC,LMCD,'
82#LWRFvars=${LWRFvars}'LMSNOW,LNDAYRAIN,LNETTOP,LOLIQ,LOVAP,LOVAPINIT,LOZONE,LPAPRS,'
83#LWRFvars=${LWRFvars}'LPB,LPBASE,LPHIS,LPLCL,LPLFC,LPLUC,LPLUL,LPLULST,LPLULTH,'
84#LWRFvars=${LWRFvars}'LPOURC_LIC,LPOURC_OCE,LPOURC_SIC,LPOURC_TER,LPR_CON_I,LPR_CON_L,'
85#LWRFvars=${LWRFvars}'LPRECIP,LPRES,LPRESNIVS,LPR_LSC_I,LPR_LSC_L,LPRW,LPSOL,LPTCONV,'
86#LWRFvars=${LWRFvars}'LPTOP,LQ10,LQ100,LQ200,LQ2M,LQ50,LQ500,LQ700,LQ850,LQSAT2M,'
87#LWRFvars=${LWRFvars}'LQSOL,LQSURF,LQ_TH,LRADSOL,LRATQS,LRE,LREF_ICE,LREF_LIQ,LRH2M,'
88#LWRFvars=${LWRFvars}'LRH2M_MAX,LRH2M_MIN,LRHUM,LRLD,LRLDCS,LRLU,LRLUCS,LRN,LRNEB,'
89#LWRFvars=${LWRFvars}'LRNEBCON,LRNEBLS,LRSD,LRSDCS,LRSU,LRSUCS,LRUGS,LRUGS_LIC,'
90#LWRFvars=${LWRFvars}'LRUGS_OCE,LRUGS_SIC,LRUGS_TER,LSENS,LSENS_LIC,LSENS_OCE,'
91#LWRFvars=${LWRFvars}'LSENS_SIC,LSENS_TER,LSICF,LS_LCL,LSLP,LSNOW,LSNOWL,LSOLL,LSOLL0,'
92#LWRFvars=${LWRFvars}'LSOLLWDOWN,LSOLS,LSOLS0,LS_PBLH,LS_PBLT,LS_THERM,LSWDN200,'
93#LWRFvars=${LWRFvars}'LSWDN200CLR,LSWDNSFC,LSWDNSFCCLR,LSWDNTOA,LSWDNTOACLR,LSWDOWNOR,'
94#LWRFvars=${LWRFvars}'LSWNETOR,LSWUP200,LSWUP200CLR,LSWUPSFC,LSWUPSFCCLR,LSWUPTOA,'
95#LWRFvars=${LWRFvars}'LSWUPTOACLR,LT10,LT100,LT200,LT2M,LT2M_LIC,LT2M_MAX,LT2M_MIN,'
96#LWRFvars=${LWRFvars}'LT2M_OCE,LT2M_SIC,LT2M_TER,LT50,LT500,LT700,LT850,LTAUX,'
97#LWRFvars=${LWRFvars}'LTAUX_LIC,LTAUX_OCE,LTAUX_SIC,LTAUX_TER,LTAUY,LTAUY_LIC,'
98#LWRFvars=${LWRFvars}'LTAUY_OCE,LTAUY_SIC,LTAUY_TER,LTEMP,LTHETA,LTKE,LTKE_LIC,'
99#LWRFvars=${LWRFvars}'LTKE_MAX,LTKE_MAX_LIC,LTKE_MAX_OCE,LTKE_MAX_SIC,LTKE_MAX_TER,'
100#LWRFvars=${LWRFvars}'LTKE_OCE,LTKE_SIC,LTKE_TER,LTNHUS,LTNHUSC,LTNHUSSCPBL,LTNT,'
101#LWRFvars=${LWRFvars}'LTNTC,LTNTR,LTNTSCPBL,LT_OCE_SIC,LTOPL,LTOPL0,LTOPS,LTOPS0,'
102#LWRFvars=${LWRFvars}'LTPOT,LTPOTE,LTSOL,LTSOL_LIC,LTSOL_OCE,LTSOL_SIC,LTSOL_TER,LU10,'
103#LWRFvars=${LWRFvars}'LU100,LU10M,LU10M_LIC,LU10M_OCE,LU10M_SIC,LU10M_TER,LU200,LU50,'
104#LWRFvars=${LWRFvars}'LU500,LU700,LU850,LUE,LUPWD,LUQ,LUSTAR,LUSTAR_LIC,LUSTAR_OCE,'
105#LWRFvars=${LWRFvars}'LUSTAR_SIC,LUSTAR_TER,LV10,LV100,LV10M,LV10M_LIC,LV10M_OCE,'
106#LWRFvars=${LWRFvars}'LV10M_SIC,LV10M_TER,LV200,LV50,LV500,LV700,LV850,LVE,LVITU,'
107#LWRFvars=${LWRFvars}'LVITV,LVITW,LVPRECIP,LVQ,LW10,LW100,LW200,LW50,LW500,LW700,'
108#LWRFvars=${LWRFvars}'LW850,LWAKE_DELTAQ,LWAKE_DELTAT,LWAKE_H,LWAKE_OMG,LWAKE_S,LWAPE,'
109#LWRFvars=${LWRFvars}'LWBEFF,LWBILO_LIC,LWBILO_OCE,LWBILO_SIC,LWBILO_TER,LWBILS_LIC,'
110#LWRFvars=${LWRFvars}'LWBILS_OCE,LWBILS_SIC,LWBILS_TER,LWDTRAINA,LWDTRAINM,LWEAKINV,'
111#LWRFvars=${LWRFvars}'LWIND10M,LWIND10MAX,LZ10,LZ100,LZ200,LZ50,LZ500,LZ700,LZ850,'
112#LWRFvars=${LWRFvars}'LZFULL,LZHALF,LZMAX_TH,LCONTROL,LMSK,LTER,LLIC,LOCE,LSIC,'
113#LWRFvars=${LWRFvars}'LTKSOIL,LOTTER,LOTLIC,LOTOCE,LOTSIC,LQKSOIL,LWSOL,LALBKSOIL,'
114#LWRFvars=${LWRFvars}'LLWALBKSOIL,LEVAPKSOIL,LSNOWKSOIL,LRADS,LSOLSW,LSOLLW,LRAIN,'
115#LWRFvars=${LWRFvars}'LRUGKSOIL,LAGESNOKSOIL,LZMEA,LZSTD,LZSIG,LZGAM,LZTHE,LZPIC,'
116#LWRFvars=${LWRFvars}'LZVAL,LZRUGSREL,LRUGSEA,LRUNOFFLIC,LZMAX0,LF0,LEMA_WORK1,'
117#LWRFvars=${LWRFvars}'LEMA_WORK2,LWAKE_CSTAR,LWAKE_PE,LWAKE_FIP,Times,'
118#LWRFvars=${LWRFvars}'ITIMESTEP,IVGTYP,ISLTYP,STEPAVE_COUNT,SAVE_TOPO_FROM_REAL'
119
120LMDZtrjvars='time_counter,u10m,v10m,precip,slp,psol'
121#LMDZ lon/lat file
122#if test ! -f lmdz_lonlat.nc; then
123#  python ${HOMEpy}/nc_var.py -o selvar -v t2m -f \
124#    ${ifold}/lmdz/run/lmdza/lmdzout/histins.nc -S 'lon@lon,lat@lat'
125#  mv selvar_new.nc lmdz_lonlat.nc
126#fi
127
128WRFvdims='XLONG,XLAT,ZNU,time'
129LMDZvdims='lon,lat,presnivs,time_counter'
130LWRFvdims='XLONG,XLAT,ZNU,time'
131
132WRFtrajvars='T2,wss,psl,pr'
133LMDZtrajvars='t2m,wind10m,slp,precip'
134LWRFtrajvars='T2,wss,psl,pr'
135
136#######    #######
137## MAIN
138    #######
139
140mods=`expr ${models} | tr ':' ' '`
141
142
143for mod in ${mods}; do
144  echo ${mod}"..."
145  if test ${mod} = 'wrf'; then 
146    experiments=${WRFexps}
147    allvars=${WRFvars}
148    dimvars=${WRFvdims}
149    trjvars=${WRFtrajvars}
150  fi
151  if test ${mod} = 'lmdz'; then 
152    experiments=${LMDZexps}
153    allvars=${LMDZvars}
154    dimvars=${LMDZvdims}
155    trjvars=${LMDZtrajvars}
156  fi
157  if test ${mod} = 'lwrf'; then 
158    experiments=${LWRFexps}
159    allvars=${LWRFvars}
160    dimvars=${LWRFvdims}
161    trjvars=${LWRFtrajvars}
162  fi
163
164  exps=`expr ${experiments} | tr ':' ' '`
165
166  for exp in ${exps}; do
167    echo "  "${exp}"..."
168# Destination folder with the outputs of the analysis
169#    osim=${ofold}/${mod}/run/${exp}
170    osim=${ofold}/${exp}
171    if test ${mod} = 'wrf' || test ${mod} = 'lwrf'; then
172      isim=${ifold}/${mod}/run/${exp}/wrfout
173# Trajectory file
174##
175      if test ! -f ${osim}/P_lev1_values.nc; then
176        python ${HOMEpy}/nc_var.py -o netcdf_fold_concatenation -f wrfout_d0${dom}   \
177          -S ${isim},Time -v P
178        if test $? -ne 0; then
179          echo ${errormsg}
180          echo "  "${main}": python does not work !!"
181          echo "  "${HOMEpy}"/nc_var.py -o netcdf_fold_concatenation -f wrfout_d0"${dom}\
182            " -S "${isim}",Time -v P"
183          exit
184        else
185          python ${HOMEpy}/nc_var.py -o DataSetSection_multidims                     \
186            -f netcdf_fold_concatenated.nc -S bottom_top,0,0,1
187          if test $? -ne 0; then
188            echo ${errormsg}
189            echo "  "${main}": python does not work !!"
190            echo "  "${HOMEpy}"/nc_var.py -o DataSetSection_multidims -f "\
191              "netcdf_fold_concatenated.nc -S bottom_top,0,0,1"
192            exit
193          fi
194          mv netcdf_fold_concatenated_bottom_top_B0-E0-I1.nc ${osim}/P_lev1_values.nc
195          rm netcdf_fold_concatenated.nc
196        fi
197      fi
198
199# concatenating all file
200##
201      if test ! -f ${osim}/full_concatenated.nc; then
202        python ${HOMEpy}/nc_var.py -o netcdf_fold_concatenation -f wrfout_d0${dom}   \
203          -S ${isim},Time -v ${allvars}
204        if test $? -ne 0; then
205          echo ${errormsg}
206          echo "  "${main}": python does not work !!"
207          echo "  "${HOMEpy}"/nc_var.py -o netcdf_fold_concatenation -f wrfout_d0"${dom}\
208            " -S "${isim}",Time -v "${allvars}
209          exit
210        else
211          mv netcdf_fold_concatenated.nc ${osim}/full_concatenated.nc
212        fi
213        python ${HOMEpy}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,hours    \
214          -f ${osim}/full_concatenated.nc -v time
215      fi
216
217# diagnostics
218##
219      if test ! -f ${osim}/diagnostics.nc; then
220        if ${use_concatenated}; then
221          diags='RAINTOT|RAINC@RAINNC@time,WRFmslp|WRFp@PSFC@HGT@WRFt@QVAPOR,wss|U10@V10'
222          python ${HOMEpy}/diagnostics.py -f ${osim}/full_concatenated.nc              \
223            -d 'Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -v ${diags} \
224            -f ${osim}/full_concatenated.nc
225          if test $? -ne 0; then
226            echo ${errormsg}
227            echo "  "${main}": python does not work !!"
228            echo "  python "${HOMEpy}"/diagnostics.py -f "${osim}"/full_concatenated.nc \
229              -d 'Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -v "${diags} \
230              "-f ${osim}/full_concatenated.nc"
231            exit
232          else
233            mv diagnostics.nc ${osim}/diagnostics.nc
234          fi
235        else
236          echo "Computing diagnostics file by file..."
237          diags='RAINTOT|RAINC@RAINNC@WRFtime,WRFmslp|WRFp@PSFC@HGT@WRFt@QVAPOR,wss|U10@V10'
238          for file in ${isim}/wrfout_d0${dom}*; do
239            fdate=`echo ${file} | tr '_' ' ' | awk '{print $3"_"$4}'`
240            if test ! ${osim}/diagnostics_${fdate}.nc; then
241              echo "  "${file}
242              python ${HOMEpy}/diagnostics.py -f ${osim}/full_concatenated.nc              \
243                -d 'Time@Times,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -v ${diags}\
244                -f ${file}
245              #exit
246              if test $? -ne 0; then
247                echo ${errormsg}
248                echo "  "${main}": python does not work !!"
249                echo "  python "${HOMEpy}"/diagnostics.py -f "${osim}"/full_concatenated.nc \
250                  -d 'Time@Times,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -v "${diags} \
251                  "-f "${file}
252                exit
253              else
254                mv diagnostics.nc ${osim}/diagnostics_${fdate}.nc
255              fi
256            fi
257          done
258          python ${HOMEpy}/nc_var.py -o netcdf_fold_concatenation -f diagnostics_    \
259            -S ${isim},Time -v ${allvars}
260          if test $? -ne 0; then
261            echo ${errormsg}
262            echo "  "${main}": python does not work !!"
263            echo "  "${HOMEpy}"/nc_var.py -o netcdf_fold_concatenation -f diagnostics_"\
264              " -S "${isim}",Time -v all"
265            exit
266          else
267            mv netcdf_fold_concatenated.nc ${osim}/full_concatenated.nc
268          fi
269          python ${HOMEpy}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,hours    \
270            -f ${osim}/full_concatenated.nc -v time
271        fi
272      fi
273# full file
274##
275      if test ! -f ${osim}/fullout.nc; then
276        cdo merge ${osim}/full_concatenated.nc ${osim}/diagnostics.nc                \
277          ${osim}/fullout.nc
278      fi
279
280# End of if 'wrf', 'lwrf'
281    else
282      osim=${ofold}/${mod}/run/erai/${exp}
283      isim=${osim}/lmdzout
284# Trajectory file
285##
286      if test ! -f ${osim}/trajectory.nc; then
287        cdo selvar,${LMDZtrjvars} ${isim}/histins.nc ${osim}/trajectory.nc
288      fi
289
290    fi
291    if test ${mod} = 'lmdz'; then
292      trjfile=${osim}/lmdzout/histins.nc
293    else
294      trjfile=${osim}/fullout.nc
295    fi
296
297# Following trajectory values
298##
299    if test ! -f ${osim}/tevol_boxtraj.nc && test -f ${osim}/trajectory.dat; then
300      tfirst=`cat ${osim}/trajectory.dat | grep -v '#' | head -n 1 | awk '{print $1-1}'`
301      echo "tfirst: "${tfirst}
302      trajvalues=${osim}'/trajectory.dat@'${tfirst}','${dimvars}',cf,5,5'
303      python ${HOMEpy}/nc_var.py -f ${trjfile} -o compute_tevolboxtraj               \
304        -S ${trajvalues} -v ${trjvars}
305      if test $? -ne 0; then
306        echo ${errormsg}
307        echo "  "${main}": python does not work !!"
308        echo "  python "${HOMEpy}"nc_var.py -f ${trjfile} -o compute_tevolboxtraj -S \
309          ${trajvalues}  -v ${trjvars}"
310        exit
311      else
312        mv tevolboxtraj_multi-var.nc ${osim}/tevol_boxtraj.nc
313      fi
314    fi
315#    exit
316# end experiments
317  done
318#  exit
319# end models
320done
Note: See TracBrowser for help on using the repository browser.