Changeset 2024 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Aug 3, 2018, 10:51:34 PM (7 years ago)
Author:
lfita
Message:

Adding multi_WindRose and fixing some issues

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2015 r2024  
    99549954        close: whether figure should be closed or not
    99559955    """
    9956     fname = 'draw_WindRose'
     9956    fname = 'draw_multiWindRose'
    99579957
    99589958    if values == 'h':
  • trunk/tools/obs-sim_Comparison.bash

    r2020 r2024  
    1 #!/bin/bash -x
     1#!/bin/bash
    22# Shell script to compare observations with simulations using PyNCplot
    33#
     
    720720}
    721721
    722 function Homoeller_SkewT_map_plot() {
     722function Hovmoeller_SkewT_map_plot() {
    723723# Function to plot a Hovmoeller SkewT_map
    724724#   sndstid: id of the sounding station
     
    889889}
    890890
     891function multi_WindRose_plot(){
     892# Function to plot a WindRose with data from multiple soundings
     893#   sti: id of the sounding station
     894#   stn: name of the sounding station to appear in plot ('!' for spaces)
     895#   ofigdir: folder for the output of the figure
     896#   files: files to use
     897#   labs: labels of the legend
     898#   lmark: marker of lines to use
     899#   timeS: time of the plot as it should appear in the figure ('!' for spaces)
     900#   timefS: time of the plot as it should appear in the figure's file
     901#   figheader: header of the figure's file name
     902
     903    valuesfig=$1
     904
     905    stid=`echo ${valuesfig} | tr '%' ' ' | awk '{print $1}'`
     906    stn=`echo ${valuesfig} | tr '%' ' ' | awk '{print $2}'`
     907    ofigdir=`echo ${valuesfig} | tr '%' ' ' | awk '{print $3}'`
     908    files=`echo ${valuesfig} | tr '%' ' ' | awk '{print $4}'`
     909    labs=`echo ${valuesfig} | tr '%' ' ' | awk '{print $5}'`
     910    lmark=`echo ${valuesfig} | tr '%' ' ' | awk '{print $6}'`
     911    timeS=`echo ${valuesfig} | tr '%' ' ' | awk '{print $7}'`
     912    timefS=`echo ${valuesfig} | tr '%' ' ' | awk '{print $8}'`
     913    figheader=`echo ${valuesfig} | tr '%' ' ' | awk '{print $9}'`
     914
     915    values='linepoint;multicol;pres;-;'${lmark}';spectral;auto:'${labs}':'
     916    values=${values}'WindRose!obs!,!sim!comparison!at!'${stid}'!on!'${timeS}'!UTC:'
     917    values=${values}${kfig}':auto:''True'
     918
     919    ofign=${ofigdir}'/'${figheader}'_'${stid}'_'${timefS}'.'${kfig}
     920    if ${gscratch}; then rm ${ofign} >& /dev/null; fi
     921    if test ! -f ${ofign}; then
     922      echo "    WindRose comparison at: "${stid}" on "$(echo ${timeS} | tr '!' ' ')
     923      python ${pyHOME}/drawing.py -o draw_multiWindRose -f ${files} -S ${values}
     924      if test $? -ne 0; then
     925        echo ${errmsg}
     926        echo "  python failed!!"
     927        echo python ${pyHOME}/drawing.py -o draw_multiWindRose -f "'"${files}"'"     \
     928         -S "'"${values}"'"
     929        exit
     930      fi
     931      convert -trim multi_WindRose.${kfig} ${ofign}
     932      echo "* "${ofign} >> ${ofilefigs}
     933      echo python ${pyHOME}/drawing.py -o draw_multiWindRose -f "'"${files}"'"       \
     934        -S "'"${values}"'" -v ${sfcv} >> ${ofilefigs}
     935      echo " "${ofign} >> ${ofilefigs}
     936    fi
     937}
     938
    891939#######    #######
    892940## MAIN
     
    938986obstype='sounding'
    939987prn='snd'
    940 listfiles=${sndfiles}
     988if test ! ${sndHf} = 'None'; then
     989  listfiles=${sndfiles}
     990else
     991  listfiles=' '
     992fi
    941993wrfdiags=${wrfsnddiags}
    942994simdiagd=${simsnddiagd}
     
    9611013    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    9621014    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1015    expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
     1016
     1017    simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
     1018
     1019    ofile=${odir}/simout_${prn}vars_${stid}_${expl}.nc
     1020    if ${fscratch}; then rm ${ofile} >& /dev/null; fi
     1021    if test ! -f ${ofile}; then
     1022      for simf in ${simfiles}; do
     1023        simfn=`basename ${simf}`
     1024        fdate=`echo ${simfn} | tr '.' ' ' | awk '{print $1}' | tr '_' ' ' |          \
     1025          awk '{print $3"_"$4}'`
     1026
     1027        simsndptf=${odir}'/simout_vars_'${prn}'pt_'${stid}'_'${expl}'_'${fdate}'.nc'
     1028        simsnddiagsf=${odir}'/simout_'${prn}'diags_'${stid}'_'${expl}'_'${fdate}'.nc'
     1029
     1030        fvals=${ostlon}'#'${ostlat}'#'${simf}'#XLONG#XLAT#'${wrfdiags}'#'
     1031        fvals=${fvals}${simdiagd}
     1032        get_WRFsounding_data ${fvals}
     1033
     1034      # end of files
     1035      done
     1036
     1037      # Concatenating files
     1038      Nconfc=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc | wc -l |        \
     1039        awk '{print $1}'`
     1040      if test ${Nconfc} -gt 1; then
     1041        values=${odir}',Time,time'
     1042        HMT='simout_'${prn}'diags_,'${stid}'_'${expn},'nc'
     1043        python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}      \
     1044         -f ${HMT} -v all
     1045        if test $? -ne 0; then
     1046          echo ${errmsg}
     1047          echo "  python failed!!"
     1048          echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}\
     1049          -f ${HMT} -v all
     1050          exit
     1051        fi
     1052        echo " * Concatenating "${obstype}" data at point: "${ostlon}", "${ostlat} >> ${ofileins}
     1053        echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S \
     1054          "'"${values}"'" -f ${HMT} -v all >> ${ofileins}
     1055        echo " " >> ${ofileins}
     1056        mv netcdf_fold_concatenated_HMT.nc ${ofile}
     1057      else
     1058        ffilen=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc`
     1059        cp ${ffilen} ${ofile}
     1060      fi
     1061    fi
     1062    iexp=`expr ${iexp} + 1`
     1063  # end of experiments
     1064  done
     1065
     1066  iost=`expr ${iost} + 1`
     1067done
     1068if test ! ${sndHf} = 'None'; then sndstids=${oststids}; fi
     1069
     1070# surface data at station
     1071iost=1
     1072obstype='surface'
     1073prn='sfc'
     1074if test ! ${sfcHf} = 'None'; then
     1075  listfiles=${sndfiles}
     1076else
     1077  listfiles=' '
     1078fi
     1079wrfdiags=${wrfsfcdiags}
     1080simdiagd=${simsfcdiagd}
     1081for ostf in ${listfiles}; do
     1082  stid=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v id | grep NC \
     1083    | awk '{printf("%d",$2)}'`
     1084  ostlon=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lon | grep NC \
     1085    | awk '{print $2}'`
     1086  ostlat=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lat | grep NC \
     1087    | awk '{print $2}'`
     1088  ostheight=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v height |   \
     1089    grep NC | awk '{print $2}'`
     1090
     1091  if test ! ${wdir}/stations.inf; then
     1092    oststids=${stid}'@'${ostf}
     1093    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} > ${wdir}/stations.inf
     1094  else
     1095    oststids=${oststids}':'${stid}'@'${ostf}
     1096    echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} >> ${wdir}/stations.inf
     1097  fi
     1098
     1099  iexp=1
     1100  for exp in ${exps}; do
     1101    expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
     1102    expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
     1103    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
     1104    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1105    expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
    9631106
    9641107    simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
     
    9691112        awk '{print $3"_"$4}'`
    9701113
    971       simsndptf=${odir}'/simout_vars_'${prn}'pt_'${stid}'_'${expl}'_'${fdate}'.nc'
    972       simsnddiagsf=${odir}'/simout_'${prn}'diags_'${stid}'_'${expl}'_'${fdate}'.nc'
     1114      simsfcptf=${odir}'/simout_vars_'${prn}'pt_'${stid}'_'${expl}'_'${fdate}'.nc'
     1115      simsfcdiagsf=${odir}'/simout_'${prn}'diags_'${stid}'_'${expl}'_'${fdate}'.nc'
    9731116
    9741117      fvals=${ostlon}'#'${ostlat}'#'${simf}'#XLONG#XLAT#'${wrfdiags}'#'
    975       fvals=${fvals}${simdiagd}
    976       get_WRFsounding_data ${fvals}
     1118      fvals=${fvals}${wrfsfcnondiags}'#'${simdiagd}
     1119      get_WRFsurface_data ${fvals}
    9771120
    9781121    # end of files
     
    10121155  iost=`expr ${iost} + 1`
    10131156done
    1014 sndstids=${oststids}
    1015 
    1016 # surface data at station
    1017 iost=1
    1018 obstype='surface'
    1019 prn='sfc'
    1020 listfiles=${sfcfiles}
    1021 wrfdiags=${wrfsfcdiags}
    1022 simdiagd=${simsfcdiagd}
    1023 for ostf in ${listfiles}; do
    1024 
    1025   stid=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v id | grep NC \
    1026     | awk '{printf("%d",$2)}'`
    1027   ostlon=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lon | grep NC \
    1028     | awk '{print $2}'`
    1029   ostlat=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v lat | grep NC \
    1030     | awk '{print $2}'`
    1031   ostheight=`python $pyHOME/nc_var.py -o varout -f ${ostf} -S 'time:0' -v height |   \
    1032     grep NC | awk '{print $2}'`
    1033 
    1034   if test ! ${wdir}/stations.inf; then
    1035     oststids=${stid}'@'${ostf}
    1036     echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} > ${wdir}/stations.inf
    1037   else
    1038     oststids=${oststids}':'${stid}'@'${ostf}
    1039     echo ${prn}","${stid}","${ostlon}","${ostlat}","${ostheight} >> ${wdir}/stations.inf
    1040   fi
    1041 
    1042   iexp=1
    1043   for exp in ${exps}; do
    1044     expf=`echo ${exp} | tr ',' ' ' | awk '{print $1}'`
    1045     expl=`echo ${exp} | tr ',' ' ' | awk '{print $2}'`
    1046     expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    1047     expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
    1048 
    1049     simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
    1050 
    1051     for simf in ${simfiles}; do
    1052       simfn=`basename ${simf}`
    1053       fdate=`echo ${simfn} | tr '.' ' ' | awk '{print $1}' | tr '_' ' ' |            \
    1054         awk '{print $3"_"$4}'`
    1055 
    1056       simsfcptf=${odir}'/simout_vars_'${prn}'pt_'${stid}'_'${expl}'_'${fdate}'.nc'
    1057       simsfcdiagsf=${odir}'/simout_'${prn}'diags_'${stid}'_'${expl}'_'${fdate}'.nc'
    1058 
    1059       fvals=${ostlon}'#'${ostlat}'#'${simf}'#XLONG#XLAT#'${wrfdiags}'#'
    1060       fvals=${fvals}${wrfsfcnondiags}'#'${simdiagd}
    1061       get_WRFsurface_data ${fvals}
    1062 
    1063     # end of files
    1064     done
    1065 
    1066     # Concatenating files
    1067     ofile=${odir}/simout_${prn}vars_${stid}_${expl}.nc
    1068     if ${fscratch}; then rm ${ofile} >& /dev/null; fi
    1069     if test ! -f ${ofile}; then
    1070       Nconfc=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc | wc -l | awk '{print $1}'`
    1071       if test ${Nconfc} -gt 1; then
    1072         values=${odir}',Time,time'
    1073         HMT='simout_'${prn}'diags_,'${stid}'_'${expn},'nc'
    1074         python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}      \
    1075          -f ${HMT} -v all
    1076         if test $? -ne 0; then
    1077           echo ${errmsg}
    1078           echo "  python failed!!"
    1079           echo python ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S ${values}\
    1080           -f ${HMT} -v all
    1081           exit
    1082         fi
    1083         echo " * Concatenating "${obstype}" data at point: "${ostlon}", "${ostlat} >> ${ofileins}
    1084         echo python  ${pyHOME}/nc_var.py -o netcdf_fold_concatenation_HMT -S \
    1085           "'"${values}"'" -f ${HMT} -v all >> ${ofileins}
    1086         echo " " >> ${ofileins}
    1087         mv netcdf_fold_concatenated_HMT.nc ${ofile}
    1088       else
    1089         ffilen=`ls -1 ${odir}/simout_${prn}diags_*${stid}*${expl}*.nc`
    1090         cp ${ffilen} ${ofile}
    1091       fi
    1092     fi
    1093     iexp=`expr ${iexp} + 1`
    1094   # end of experiments
    1095   done
    1096 
    1097   iost=`expr ${iost} + 1`
    1098 done
    1099 sfcstids=${oststids}
     1157if test ! ${sfcHf} = 'None'; then sfcstids=${oststids}; fi
    11001158
    11011159# surface data for maps
     
    11121170  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    11131171  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1172  expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
    11141173
    11151174  simfiles=`ls -1 ${simdir}/${expf}/${simH}*${simM}*${simT}`
     
    13431402      expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    13441403      expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1404      expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
    13451405
    13461406      #simjoinselvars=${odir}'/simout_vars_'${expl}'.nc'
     
    13941454        tdacompltyp='-,-.'
    13951455        tacompfiles=${sndorigfn}':pres|-1,time|'${it}':ta,pres;'
    1396         tacompfiles=${tacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
     1456        tacompfiles=${tacompfiles}${simsndptf}':bottom_top|-1,Time|'${timestep}':'
    13971457        tacompfiles=${tacompfiles}'ta,pres'
    13981458        tdacompfiles=${sndorigfn}':pres|-1,time|'${it}':tda,pres;'
    1399         tdacompfiles=${tdacompfiles}${simsndptf}':bottom_top|-1,time|'${timestep}':'
     1459        tdacompfiles=${tdacompfiles}${simsndptf}':bottom_top|-1,Time|'${timestep}':'
    14001460        tdacompfiles=${tdacompfiles}'tda,pres'
     1461
     1462        # multi Wind-Rose
     1463        # Getting pressure level from observations to plot
     1464        if test ${it} -eq 0; then
     1465          fstats=`python $pyHOME/nc_var.py -o field_stats -S full,1.e+20,None        \
     1466            -f ${simsndptf} -v pres | grep MAT | grep pres`
     1467          nsimpres=`echo ${fstats} | awk '{printf ("%d",$3*1000)}'`
     1468        fi
     1469
     1470        obsuavaf=${odir}/sounding_uava_${stid}.nc
     1471        obspres=`python $pyHOME/nc_var.py -o varout -f ${obsuavaf} -S time:${it}     \
     1472          -v pres | awk '{print $2}' | tr '\n' ' '`
     1473        kobs=0
     1474        for obsp0 in ${obspres}; do
     1475          obsp=`echo ${obsp0} | awk '{printf ("%d",$1*1000)}'`
     1476          if test ${obsp} -gt ${nsimpres}; then kobs=`expr ${kobs} + 1`
     1477          else kobs=`expr ${kobs} + 1`; break; fi
     1478        done
     1479
     1480        mWRcomplabs='obs,'${expn}
     1481        mWRcompfiles=${odir}'/sounding_uava_'${stid}'.nc@pres|1,'${kobs}',1;time|'
     1482        mWRcompfiles=${mWRcompfiles}${it}'@ua,va#'${simsndptf}'@bottom_top|-1;Time|'
     1483        mWRcompfiles=${mWRcompfiles}${timestep}'@ua,va'
     1484        mWRmarks='.@'${expm}
    14011485      else
    14021486        tacomplabs=${tacomplabs}',$ta^{'${expn}'}$'
     
    14061490        tacompltyp=${tacompltyp}',-'
    14071491        tdacompltyp=${tdacompltyp}',-.'
    1408         tacompfiles=${tacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}':'
     1492        tacompfiles=${tacompfiles}';'${simsndptf}':bottom_top|-1,Time|'${timestep}':'
    14091493        tacompfiles=${tacompfiles}'ta,pres'
    1410         tdacompfiles=${tdacompfiles}';'${simsndptf}':bottom_top|-1,time|'${timestep}
     1494        tdacompfiles=${tdacompfiles}';'${simsndptf}':bottom_top|-1,Time|'${timestep}
    14111495        tdacompfiles=${tdacompfiles}':tda,pres'
     1496        # multi Wind-Rose
     1497        mWRcomplabs=${mWRcomplabs}','${expn}
     1498        mWRcompfiles=${mWRcompfiles}'#'${simsndptf}'@bottom_top|-1;Time|'${timestep}
     1499        mWRcompfiles=${mWRcompfiles}'@ua,va'
     1500        mWRmarks=${mWRmarks}'@'${expm}
    14121501      fi
    14131502
    1414       # Hovmoeller maps
    1415       sndvs=`echo ${sndvars} | tr ':' ' '`
    1416       for sndv in ${sndvs}; do
    1417 
    1418         CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sndv}`
    1419         cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
    1420 
    1421         fivals=${stid}'#'${sndstn}'#'${sndv}'#'${ofigdir}'#'${datefS}'#'${fmtTts}
    1422         fivals=${fivals}'#'${simsndptf}'#'${sndorigfn}'#'${expl}'#'${expn}'#'${cbar}
    1423         fivals=${fivals}'#SkewT-logP_obs-sim_evol'
    1424 
    1425         Homoeller_SkewT_map_plot ${fivals}
    1426 
    1427       # end sounding vars
    1428       done
     1503      if test ${it} -eq 0; then
     1504        # Hovmoeller maps
     1505        sndvs=`echo ${sndvars} | tr ':' ' '`
     1506        for sndv in ${sndvs}; do
     1507 
     1508          CFvarvals=`python $pyHOME/generic.py -o variables_values -S ${sndv}`
     1509          cbar=`echo ${CFvarvals} | tr ':' ' ' | awk '{print $7}'`
     1510
     1511          fivals=${stid}'#'${sndstn}'#'${sndv}'#'${ofigdir}'#'${datefS}'#'${fmtTts}
     1512          fivals=${fivals}'#'${simsndptf}'#'${sndorigfn}'#'${expl}'#'${expn}'#'${cbar}
     1513          fivals=${fivals}'#SkewT-logP_obs-sim_evol'
     1514
     1515          Hovmoeller_SkewT_map_plot ${fivals}
     1516
     1517        # end sounding vars
     1518        done
     1519      fi
    14291520
    14301521      iexp=`expr ${iexp} + 1`
     
    14381529
    14391530    fivals=${stid}'@'${sndstn}'@'${complabs}'@'${compcols}'@'${compltyp}'@'
    1440     fivals=${fivals}${compfiles}'@'${dateS}'@'${ofigdir}'@'${datefS}'@'${ofigdir}'@'
     1531    fivals=${fivals}${compfiles}'@'${dateS}'@'${ofigdir}'@'${datefS}'@'
    14411532    fivals=${fivals}'SkewT-logP_obs-sim_step'
    14421533    multi_SkewT_logP_plot ${fivals}
    14431534
    14441535    # Wind Rose comparison
    1445     fivals=${it}'#'${stid}'#'${sndstn}'#'${timeS}'#'${ofigdir}'#'${timefS}'#'
    1446     fivals=${fivals}${ouavasndf}'#WindRose_obs-sim_'
     1536    fivals=${stid}'%'${sndstn}'%'${ofigdir}'%'${mWRcompfiles}'%'${mWRcomplabs}'%'
     1537    fivals=${fivals}${mWRmarks}'%'${dateS}'%'${datefS}'%WindRose_obs-sim_step'
     1538
    14471539    multi_WindRose_plot ${fivals}
    14481540
     
    14531545# End of soundings stations
    14541546done
     1547exit
    14551548
    14561549###
     
    16061699    expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    16071700    expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1701    expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
    16081702
    16091703    simsfcdiagf=${odir}'/simout_sfcvars_'${stdi}'_'${expl}'.nc'
     
    16421736  expn=`echo ${exp} | tr ',' ' ' | awk '{print $3}'`
    16431737  expc=`echo ${exp} | tr ',' ' ' | awk '{print $4}'`
     1738  expm=`echo ${exp} | tr ',' ' ' | awk '{print $5}'`
    16441739
    16451740  simsfcdiagf=${odir}'/simout_sfcmapdiags_'${expl}'.nc'
Note: See TracChangeset for help on using the changeset viewer.