Changeset 923 in lmdz_wrf


Ignore:
Timestamp:
Jun 21, 2016, 5:44:59 PM (9 years ago)
Author:
lfita
Message:

Working version with combos!

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.bash

    r920 r923  
    7979    exit
    8080  fi
     81}
     82
     83function variable_compute(){
     84# Function to retrieve the computation way of a given variable using a series of
     85#   test files
     86#   iwdir= directory with the test files
     87#   var= name of the variable to test
     88#   filtests= '@' separated list of '[head]|[file] test files
     89  fname='variable_compute'
     90
     91  iwdir=$1
     92  var=$2
     93  filtests=$3
     94
     95  ftsts=`echo ${filtests} |tr '@' ' '`
     96  cancompute=true
     97
     98  for ftest in ${ftsts}; do
     99    headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'`
     100    filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'`
     101    compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen} -S ${var}`
     102    ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} |       \
     103      tr ' ' '!')
     104    varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |           \
     105      tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'`
     106    vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |          \
     107      tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'`
     108    echo "  "${var}" mod:"${varmod}" diag: "${vardiag}
     109    if test ${varmod} = 'None' && test ${vardiag} = 'None'; then
     110      cancompute=false
     111    else
     112      cancompute=true
     113    # Should be considered that variable can also be computed by both ways?
     114      break
     115    fi
     116  done
     117  if ! ${cancompute}; then
     118    msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod}
     119# Too extrict!
     120#    ferrmsg 1 ${main} ${msg}
     121    echo ${warnmsg}
     122    echo $(echo $msg | tr '!' ' ')
     123  fi
     124
     125  # a ';' list 'varcompute' it is created for each variable giving:
     126  #   [var]|[vark]|[headerf][varmod]|[vardiag]
     127  # This list will be used to compute a new file for each variable
     128  varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag}
     129
     130  echo "varcomp= "${varcomp}
    81131}
    82132
     
    182232#        diff: differences between models
    183233#        direct: no statistics
     234#        last: last temporal value
     235#        Lmean: latitudinal mean values
    184236#        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
    185237#        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
     
    187239#        pinterp: pressure interpolation (to the given $plevels)
    188240#        tmean: temporal mean values
     241#        tmean: temporal mean values
     242#        xmean: x-axis mean values
     243#        ymean: y-axis mean values
    189244#        zsum: vertical aggregated values
    190245#     [headerf]: header of the files to use
     
    335390#        diff: differences between models
    336391#        direct: no statistics
     392#        last: last temporal value
    337393#        Lmean: latitudinal mean values
    338394#        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
     
    360416  scratch=$7
    361417
     418  # Getting a previous file name to continue with(for combinations)
     419  if test $# -eq 8; then
     420    echo ${warnmsg}
     421    echo "  "${fname}": using a previous file '"$8"' to continue with!!"
     422    prevfile=$8
     423    usefiles=$8
     424  fi
     425
    362426  CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
    363427  vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
     
    377441  cd ${odir}
    378442
    379   if test ${vark} == 'pinterp'; then
    380     fhead=${headerf}p
     443  if test $# -ne 8; then
     444    if test ${vark} == 'pinterp'; then
     445      fhead=${headerf}p
     446    else
     447      fhead=${headerf}
     448    fi
     449    filen=${CFvarn}_${fhead}_${vark}.nc
    381450  else
    382     fhead=${headerf}
     451    Lprevfile=`expr length ${prevfile}`
     452    Lprevfile3=`expr ${Lprevfile} - 3`
     453    filen=${prevfile:0:$Lprevfile3}_${vark}.nc
    383454  fi
    384   filen=${CFvarn}_${fhead}_${vark}.nc
    385455  if ${scratch}; then rm ${filen} >& /dev/null; fi
    386456
     
    401471      'direct')
    402472        cp ${cfiles} ${filen}
     473      ;;
     474      # last temporal value
     475      'last')
     476        Lcfiles=`expr length ${cfiles}`
     477        Lcfiles3=`expr ${Lcfiles} - 3`
     478        vals='time,-9,0,0'
     479        pyout=`python ${pyHOME}/nc_var.py -o DataSetSection -S ${vals} -f ${cfiles}  \
     480          -v ${CFvarn}`
     481        pyn=$?
     482        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     483        ferrmsg ${pyn} ${fname} "python!'DataSetSection'!'last'!failed#"${Spyout}
     484        mv ${cfiles:0:${Lcfiles3}}_time_B-9-E0-I0.nc ${filen}
    403485      ;;
    404486      # latitudinal mean values
     
    490572
    491573  cleaning_varsfile ${filen} ${CFvarn}':lon:lat:pres:time'${varkeep}
    492 #  exit
    493 # LLUIS
    494574}
    495575
     
    624704# Kind variables loop
    625705##
     706      combo=false
    626707      ik=1
    627708      itotv=1
     
    632713            varvks=${varacc}
    633714          ;;
     715          'combo')
     716            combo=true
     717            varvcombo=${varcombo}
     718            varcos=`echo ${varvcombo} | tr ':' ' '`
     719            varvks=''
     720            ivco=1
     721            for vco in ${varcos}; do
     722              vn=`echo ${vco} | tr '@' ' ' | awk '{print $1}'`
     723              if test ${ivco} -eq 1; then
     724                varvks=${vco}
     725              else
     726                varvks=${varvks}':'${vco}
     727              fi
     728              ivco=`expr ${ivco} + 1`
     729            done
     730          ;;
    634731          'diff')
    635732            varvks=${vardiff}
     
    637734          'direct')
    638735            varvks=${vardirect}
     736          ;;
     737          'last')
     738            varvks=${varlast}
    639739          ;;
    640740          'Lmean')
     
    690790        for var in ${vars}; do
    691791          echo "      "${var}
    692           # How to copmute it?
    693           cancompute=true
    694           for ftest in ${testfs}; do
    695             headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'`
    696             filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'`
    697             compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen}      \
    698               -S ${var}`
    699             ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} | \
    700                tr ' ' '!')
    701             varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |   \
    702                tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'`
    703             vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |  \
    704                tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'`
    705             echo "  "${var}" mod:"${varmod}" diag: "${vardiag}
    706             if test ${varmod} = 'None' && test ${vardiag} = 'None'; then
    707               cancompute=false
    708             else
    709               cancompute=true
    710               # Should be considered that variable can also be computed by both ways?
    711               break
    712             fi
    713           done
    714           if ! ${cancompute}; then
    715             msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod}
    716 # Too extrict!
    717 #            ferrmsg 1 ${main} ${msg}
    718             echo ${warnmsg}
    719             echo $(echo $msg | tr '!' ' ')
    720           fi
    721 
    722           # A ';' list 'varcompute' it is created for each variable giving:
    723           #   [var]|[vark]|[headerf][varmod]|[vardiag]
    724           # This list will be used to compute a new file for each variable
    725           varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag}
     792          # How to compute it?
     793          varcomp=`variable_compute ${iwdir} ${var} ${testfiles} | grep varcomp |    \
     794            awk '{print $2}'`
     795
    726796          if test ${itotv} -eq 1; then
    727797            varcompute=${varcomp}
     
    743813varcompute: ${varcompute}
    744814itotv: ${itotv}
     815testfs: ${testfiles}
    745816EOF
    746817    else
     
    750821      varcompute=`cat ${owdir}/varcompute.inf | grep varcompute | awk '{print $2}'`
    751822      itotv=`cat ${owdir}/varcompute.inf | grep itotv | awk '{print $2}'`
     823      testfiles=`cat ${owdir}/varcompute.inf | grep testfs | awk '{print $2}'`
    752824# End of avoiding to repeat all the experiment search
    753825    fi
     
    774846        ic=`expr ${ic} + 1`
    775847
    776         if test ! ${vark} = 'diff'; then
     848        if test ! ${vark} = 'diff' && test ! ${vark} = 'combo'; then
    777849          if test ${vark} = 'pinterp'; then
    778850            fhead=${fileh}'p'
     
    784856          isc=`expr ${isc} + 1`
    785857        else
    786           echo "  "${main}": differences will be calculated when all the " \
    787             "model/experiments will be done !"
     858          if test ${vark} = 'diff'; then
     859            echo "  "${main}": differences will be calculated when all the "         \
     860              "model/experiments will be done !"
     861          elif test ${vark} = 'diff'; then
     862            echo "  "${main}": combos will be calculated later when all the "        \
     863              "variables will be done !"
     864          fi
    788865        fi
    789866      else
     
    794871# end of computing vars
    795872    done
     873
     874    # Computing combos
     875    if ${combo}; then
     876      echo "      Computing combos: "${varcombo}
     877      varcos=`echo ${varcombo} | tr ':' ' '`
     878      for vco in ${varcos}; do
     879        echo "        "${vco}
     880        CFvarn=`echo ${vco} | tr ';' ' ' | awk '{print $1}'`
     881        cvar=`variable_compute ${iwdir} ${CFvarn} ${testfiles} | grep varcomp |      \
     882          awk '{print $2}'`
     883        CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
     884        vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
     885        fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
     886        modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
     887        diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
     888
     889        combs=`echo ${vco} | tr ';' ' ' | awk '{print $2}' | tr '@' ' '`
     890        ifile=${CFv}_${fhead}
     891        for comb in ${combs}; do
     892          combcvar=${CFv}'|'${comb}'|'${fileh}'|'${modv}'|'${diagv}
     893          compute_statistics ${iwdir} ${ifile}.nc ${owdir} ${combcvar} ${moddims}    \
     894            ${modvdims} ${scratch} ${ifile}.nc
     895          ifile=${ifile}_${comb}
     896          isc=`expr ${isc} + 1`
     897        # End of combo
     898        done
     899      # End of combo variables
     900      done
     901    fi
     902# LLUIS
     903
    796904    echo "  "${main}": "${ic}" variables has been computed"
    797905    echo "  "${main}": "${isc}" statistics has been computed"
     
    10191127          fi
    10201128        fi
    1021         echo "HereLluis"${var}
     1129
    10221130# Time means
    10231131        if $(isin_list ${var2Dtmeans} ${var}); then
  • trunk/tools/model_graphics_template.dat

    r908 r923  
    4949LMDZheaders = histins
    5050
    51 # Kind of calculations (adding the euiqvalent `surname' to each variable)
     51# Kind of calculations (adding the equivalent `surname' to each variable)
    5252#   acc: temporal accumulated values
    5353#   diff: differences between models
    5454#   direct: no statistics
     55#   last: last temporal value
    5556#   Lmean: latitudinal mean values
    5657#   Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
     
    6263#   ymean: y-axis mean values
    6364#   zsum: vertical aggregated values
    64 varkinds = direct:tmean:xmean:diff:pinterp
     65varkinds = direct:tmean:xmean:diff:pinterp:combo
    6566
    6667# variables (providing CF-name, script must provide equivalent variable for each model)
    6768#   in foudre values from: ${HOME}/UNSW-CCRC-WRF/tools/postprocess/GMS-UC/WRF4G/util/postprocess/wrfncxnj/wrfncxnj.table
    6869#   must exist on the table $pyHOME/variables_values.dat
     70#   varcombo = [varn];[vark1]@...@[varkN]: variable as consecutive kinds of operation
    6971vardirect = tas:uas:vas:ps:pr:pracc:rsds:prw:evspsbl:hfss:hfls:hurs:huss:zmla:hufs:wakes:lwakeh:stherm:zmaxth:clt:cll:clm:clh:prc:prls:bils
    7072vartmean = prc:prls:zmla:hfss:hfls:evspsbl:bils:uas:vas:tas:ps:clt:cll:clm:clh:prw:huss:pr:wakes:wakeh:stherm:zmaxth
     
    7274vardiff = ualmean:valmean:talmean:huslmean:uas:vas:ps:pr
    7375varpinterp = ta:ua:va:hur
     76varcombo = ta;pinterp@last@xmean:ua;pinterp@last@xmean:va;pinterp@last@xmean:hur;pinterp@last@xmean
    7477
    7578# Pressure levels
     
    8386#   map3D: 2D map of 3D values of 1 variable
    8487#   shadcount2D: 2D map of shadow (1st variable) and countour (2nd variable) [var1]@[var2] (no `surname' = 'direct')
    85 shadcount2D = huslmean@talmean:valmean@ualmean:tas@ps:uas@vas:pr@rsds:prw@huss:prls@prc:hfls@hfss:evspsbl@bils:zmaxth@stherm:wakeh@wakes:zmaxth@stherm:prls@prc:clt@cll:clh@clm
     88shadcount2D = husxmean@taxmean:vaxmean@uaxmean:tas@ps:uas@vas:pr@rsds:prw@huss:prls@prc:hfls@hfss:evspsbl@bils:zmaxth@stherm:wakeh@wakes:zmaxth@stherm:prls@prc:clt@cll:clh@clm
    8689diffmap2Dsfc = uas:vas:ps:pr
    87 diffmap2Dz = ualmean:valmean:talmean:huslmean
     90diffmap2Dz = uapxmean:vapxmean:tapxmean:huspxmean
    8891
    8992# Figures output
Note: See TracChangeset for help on using the changeset viewer.