Changeset 886 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jun 18, 2016, 8:06:09 PM (8 years ago)
Author:
lfita
Message:

Getting there! Altready on the statistics

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.bash

    r868 r886  
    3232}
    3333
    34 function isin_list() {
     34function isInlist() {
    3535# Function to check whether a value is in a list
    3636  list=$1
     
    6060    exit
    6161  fi
     62}
     63
     64function ferrmsgF() {
     65# Function to exit and write an error message and remove a file
     66#  comdexit: code number exit from the last execution
     67#  ref: script/reference from which error occurs
     68#  msg: message to write ('!' for spaces, '#' for end of line)
     69#  FileName: name of the file to remove in case of error
     70  comdexit=$1
     71  ref=$2
     72  msg=$3
     73  FileName=$4
     74
     75  if test ${comdexit} -ne 0; then
     76    echo "ERROR -- error -- ERROR -- error"
     77    echo "  "${ref}": "$(echo ${msg} | tr '!' ' ' | tr '#' '\n')" !!"
     78    rm ${FileName} >& /dev/null
     79    exit
     80  fi
     81}
     82
     83function WRF_toCF() {
     84# Function to pass a WRF original file to CF-conventions
     85#   wrff= WRF file
     86#   wrfvl= WRF longitude var name (it might come from WPS!)
     87#   wrfvL= WRF latitude var name (it might come from WPS!)
     88
     89  wrff=$1
     90  wrfvl=$2
     91  wrfvL=$3
     92
     93  fdims=`${pyHOME}/nc_var.py -o idims -f ${wrff} | grep alldims | tr '=' ' ' |       \
     94    awk '{print $3}'`
     95
     96  CFdims='west_east@lon:south_north@lat:Time@time'
     97  CFds=`echo ${CFdims} | tr ':' ' '`
     98 
     99  pyout=`${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes        \
     100    -f ${wrff} -v time`
     101  pyn=$?
     102  Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     103  ferrmsgF ${pyn} ${fname} "python!'WRF_CFtime_creation'!failed"${Spyout} ${wrff}
     104 
     105  pyout=`${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${wrfvl},${wrfvL}           \
     106    -f ${wrff} -S lon,lat`
     107  pyn=$?
     108  Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     109  ferrmsgF ${pyn} ${fname} "python!'WRF_CFlonlat_creation'!failed"${Spyout} ${wrff}
     110
     111  for CFd in ${CFds}; do
     112    cd=`echo ${CFd} | tr '@' ' ' | awk '{print $2}'`
     113    wd=`echo ${CFd} | tr '@' ' ' | awk '{print $1}'`
     114    if $(isInlist ${fdims} ${wd}); then
     115      pyout=`${pyHOME}/nc_var.py -o chdimname -f ${wrff} -S ${wd}':'${cd}`
     116      pyn=$?
     117      Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     118      ferrmsgF ${pyn} ${fname} "python!'chdimname'!'"${wd}"'!failed#"${Spyout} ${wrff}
     119    fi
     120  done
     121
    62122}
    63123
     
    81141#     [modvar]: variable to use from the file
    82142#     [diagvar]: variable computed from the diagnostics (diagnostic.py)
     143#   mdim: name of the dimensions in the model
     144#   mvdim: name of the vaariable-dimensions in the model
    83145#   scratch: whether is has to be done from the scratch or not
    84146  fname='compute_variable'
     
    87149  odir=$3
    88150  cvar=$4
    89   scratch=$5
     151  mdim=$5
     152  mvdim=$6
     153  scratch=$7
    90154
    91155  CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
     
    98162    awk '{print $2}' | tr '@' ' '`
    99163
     164# dimensions
     165  dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'`
     166  dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'`
     167# var-dimensions
     168  vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'`
     169  vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'`
     170
    100171  cd ${odir}
    101172
     
    103174  Ntotfiles=`echo ${cfiles} | wc -w | awk '{print $1}'`
    104175  ifile=1
     176
    105177  for cf in ${cfiles}; do
    106178    ifS=`printf "%0${Ntotfiles}d" ${ifile}`
     179
    107180    # Computing variable
    108181    filen=${odir}/${CFvarn}_${headerf}_${ifile}-${Ntotfiles}.nc
    109     if ${scratch}; then rm ${filen}; fi
    110 
    111     if test ! -f ${filen}; then
     182    if ${scratch}; then
     183      rm ${filen}
     184      rm ${odir}/${CFvarn}_${headerf}.nc
     185    fi
     186
     187    if test ! -f ${filen} && test ! -f ${odir}/${CFvarn}_${headerf}.nc; then
    112188      if test ! ${modvar} = 'None'; then
    113189        # model variable
     
    116192        pyout=`${pyHOME}/nc_var.py -f ${cf} -o DataSetSection_multivars -v ${vs}     \
    117193          -S ${values} | grep succesfull | awk '{print $6}' | tr '"' ' '`
    118         ferrmsg $? ${fname} "python!'DataSetSection_multivars'!failed"
     194        pyn=$?
     195        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     196        ferrmsg ${pyn} ${fname} "python!'DataSetSection_multivars'!failed"${Spyout}
    119197        mv ${pyout} ${filen}
    120         pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${vs} -S ${CFvarn}`
    121         ferrmsg $? ${fname} "python!'chvarname'!failed"       
    122 
    123         # adding CF lon,lat,time in WRF files
    124         if test ${headerf:0:3} = 'wrf'; then
    125           ${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes       \
    126             -f ${filen} -v time
    127           ${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${vdnx},${vdny}            \
    128             -f ${filen} -S lon,lat
    129         fi
     198
     199        pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${modvar} -S ${CFvarn}`
     200        pyn=$?
     201        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     202        ferrmsgF ${pyn} ${fname} "python!'chvarname'!failed"${Spyout} ${filen}
    130203      else
    131204        # diagnostic variable
     
    145218        done
    146219
    147         echo "python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}"
    148220        pyout=`python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}`
    149         ferrmsg $? ${fname} "python!'diagnostics'!failed"
     221        pyn=$?
     222        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     223        ferrmsg ${pyn} ${fname} "python!'diagnostics'!failed#"${Spyout}
    150224        mv diagnostics.nc ${filen}
    151 
    152         # adding CF lon,lat,time in WRF files
    153         if test ${headerf:0:3} = 'wrf'; then
    154           ${pyHOME}/nc_var.py -o WRF_CFtime_creation -S 19491201000000,minutes       \
    155             -f ${filen} -v time
    156           ${pyHOME}/nc_var.py -o WRF_CFlonlat_creation -v ${vdnx},${vdny}            \
    157             -f ${filen} -S lon,lat
    158         fi
    159       fi
     225      fi
     226
     227      # adding CF lon,lat,time in WRF files
     228      if test ${headerf:0:3} = 'wrf'; then
     229        WRF_toCF ${filen} ${vdnx} ${vdny}
     230      fi
     231
     232LLUIS TO ADD ALL CF attributes!!!!!!!
     233
    160234    fi
    161235
    162236    ifile=`expr ${ifile} + 1`
     237# End of files
    163238  done
    164239
     240  # Joining variable files
     241  filen=${odir}/${CFvarn}_${headerf}.nc
     242  if ${scratch}; then rm ${filen}; fi
     243
     244  if test ! -f ${filen}; then
     245    pyout=`python ${pyHOME}/nc_var.py -f ${CFvarn}_${headerf}_                       \
     246      -o netcdf_fold_concatenation -S ./,time -v all`
     247    pyn=$?
     248    Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     249    ferrmsg ${pyn} ${fname} "python!'netcdf_fold_concatenation'!failed#"${Spyout}
     250
     251    mv netcdf_fold_concatenated.nc ${filen}
     252    if test -f ${filen}; then
     253      rm ${CFvarn}_${headerf}_*
     254    fi
     255  fi
     256}
     257
     258function compute_statistics(){
     259# Function to compute different statistics
     260#   idir: directory with the input files
     261#   usefiles: ',' list of files to use [file1],...,[fileN]
     262#   odir: directory to write the output files
     263#   cvar: [CFvarn]|[varkind]|[headerf]|[varmod]|[vardiag]
     264#     [CFvarn]: CF name of the variable
     265#     [vark]: kind of variable:
     266#        acc: temporal accumulated values
     267#        diff: differences between models
     268#        direct: no statistics
     269#        Lmean: latitudinal mean values
     270#        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
     271#        lmean: longitudinal mean values
     272#        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
     273#        tmean: temporal mean values
     274#        xmean: x-axis mean values
     275#        ymean: y-axis mean values
     276#        zsum: vertical aggregated values
     277#     [headerf]: header of the files to use
     278#     [modvar]: variable to use from the file
     279#     [diagvar]: variable computed from the diagnostics (diagnostic.py)
     280#   mdim: name of the dimensions in the model
     281#   mvdim: name of the vaariable-dimensions in the model
     282#   scratch: whether is has to be done from the scratch or not
     283  fname='compute_statistics'
     284
     285  idir=$1
     286  usefiles=$2
     287  odir=$3
     288  cvar=$4
     289  mdim=$5
     290  mvdim=$6
     291  scratch=$7
     292
     293  CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
     294  vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
     295  headerf=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
     296  modvar=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
     297  diagvar=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
     298
     299  cfiles=`echo ${usefiles} | tr ',' ' '`
     300
     301# dimensions
     302  dnx=`echo ${mdim} | tr ',' ' ' | awk '{print $1}'`
     303  dny=`echo ${mdim} | tr ',' ' ' | awk '{print $2}'`
     304# var-dimensions
     305  vdnx=`echo ${mvdim} | tr ',' ' ' | awk '{print $1}'`
     306  vdny=`echo ${mvdim} | tr ',' ' ' | awk '{print $2}'`
     307
     308  cd ${odir}
     309
     310  filen=${CFvarn}_${headerf}_${vark}.nc
     311  if ${scratch}; then rm ${filen} >& /dev/null; fi
     312
     313  if test ! -f ${filen}; then
     314    # Computing stats
     315    case ${vark} in
     316       # temporal accumulated values
     317      'acc')
     318        echo "  "${fname}": kind '"${vark}"' not ready !!"
     319        exit
     320      ;;
     321      # differences between models
     322      'diff')
     323        echo "  "${fname}": kind '"${vark}"' not ready !!"
     324        exit
     325      ;;
     326      # no statistics
     327      'direct')
     328        cp ${cfiles} ${filen}
     329      ;;
     330      # latitudinal mean values
     331      'Lmean')
     332        echo "  "${fname}": kind '"${vark}"' not ready !!"
     333        exit
     334      ;;
     335      # latitudinal section (latitudinal value must be given, [var]@[lat])
     336      'Lsec')
     337        echo "  "${fname}": kind '"${vark}"' not ready !!"
     338        exit
     339      ;;
     340      # longitudinal section (longitudinal value must be given, [var]@[lat])
     341      'lsec')
     342        echo "  "${fname}": kind '"${vark}"' not ready !!"
     343        exit
     344      ;;
     345      # longitudinal mean values
     346      'lmean')
     347        echo "  "${fname}": kind '"${vark}"' not ready !!"
     348        exit
     349      ;;
     350      # temporal mean values
     351      'tmean')
     352        vals='time:-1,time,mean,lon:lat:'${vdnz}':time'
     353        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
     354
     355        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}          \
     356          -f ${cfiles} -v ${CFvarn}`
     357        pyn=$?
     358        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     359        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
     360        mv file_oper_alongdims_mean.nc ${filen}
     361      ;;
     362      # x-axis mean values
     363      'xmean')
     364        vals='lon:-1,lon,mean,lon:lat:'${vdnz}':time'
     365        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
     366        echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}"
     367
     368        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}         \
     369          -f ${cfiles} -v ${CFvarn}`
     370        pyn=$?
     371        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     372        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
     373        mv file_oper_alongdims_mean.nc ${filen}
     374      ;;
     375      # y-axis mean values
     376      'ymean')
     377        vals='lat:-1,lat,mean,lon:lat:'${vdnz}':time'
     378        dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon'
     379        echo "python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals} -f ${cfiles} -v ${CFvarn}"
     380
     381        pyout=`python ${pyHOME}/nc_var.py -o file_oper_alongdims -S ${vals}         \
     382          -f ${cfiles} -v ${CFvarn}`
     383        pyn=$?
     384        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
     385        ferrmsg ${pyn} ${fname} "python!'file_oper_alongdims'!'tmean'!failed#"${Spyout}
     386        mv file_oper_alongdims_mean.nc ${filen}
     387      ;;
     388      # vertical aggregated values
     389      'zsum')
     390        echo "  "${fname}": kind '"${vark}"' not ready !!"
     391        exit
     392      ;;
     393      *)
     394        echo ${errmsg}
     395        echo "  "${fname}": kind '"${vark}"' not ready !!"
     396        exit
     397      ;;
     398    esac
     399  fi
     400#  exit
    165401# LLUIS
    166 #  exit
    167402}
    168403
     
    238473  echo "  dims: "${dnx}", "${dny}", "${dnz}", "${dnt}
    239474  echo "  var dims: "${vdnx}", "${vdny}", "${vdnz}", "${vdnt}
     475  moddims=${dnx}','${dny}','${dnz}','${dnt}
     476  modvdims=${vdnx}','${vdny}','${vdnz}','${vdnt}
    240477
    241478# Experiments loop
     
    290527        echo "    "${vark}" ..."
    291528        case ${vark} in
    292           'varacc')
     529          'acc')
    293530            varvks=${varacc}
    294531          ;;
    295           'vardiff')
     532          'diff')
    296533            varvks=${vardiff}
    297534          ;;
     
    299536            varvks=${vardirect}
    300537          ;;
    301           'varLsec')
     538          'Lmean')
     539            varvks=${varLmean}
     540          ;;
     541          'Lsec')
    302542            varvks=${varLsec}
    303543          ;;
    304           'varlsec')
     544          'lmean')
     545            varvks=${varlmean}
     546          ;;
     547          'lsec')
    305548            varvks=${varlsec}
    306549          ;;
    307           'varlmean')
    308             varvks=${varlmean}
    309           ;;
    310           'vartmean')
     550          'tmean')
    311551            varvks=${vartmean}
    312552          ;;
    313           'varzsum')
     553          'xmean')
     554            varvks=${varxmean}
     555          ;;
     556          'ymean')
     557            varvks=${varymean}
     558          ;;
     559          'zsum')
    314560            varvks=${varzsum}
    315561          ;;
     
    408654    cd $owdir
    409655    ic=1
     656    isc=1
    410657    cvars=`echo ${varcompute} | tr ';' ' '`
    411658    for cvar in ${cvars}; do
    412659      CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
     660      vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
     661      fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
    413662      modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
    414663      diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
     
    416665
    417666      if test ! ${modv} = 'None' || test ! ${diagv} = 'None'; then
    418         compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${scratch}
     667        compute_variable ${iwdir} ${files} ${owdir} ${cvar} ${moddims} ${modvdims}   \
     668          ${scratch}
    419669        ic=`expr ${ic} + 1`
     670
     671        if test ! ${vark} = 'diff'; then
     672          compute_statistics ${iwdir} ${CFv}_${fileh}.nc ${owdir} ${cvar}            \
     673            ${moddims} ${modvdims} ${scratch}
     674          isc=`expr ${isc} + 1`
     675        else
     676          echo "  "${main}": differences will be calculated when all the " \
     677            "model/experiments will be done !"
     678        fi
    420679      else
    421680        echo "        not computing '"${CFv}"' for model '"${mod}"' !!"
     
    425684# end of computing vars
    426685    done
    427     echo "  "${main}": has been "${ic}" variables computed"
     686    echo "  "${main}": "${ic}" variables has been computed"
     687    echo "  "${main}": "${isc}" statistics has been computed"
     688
    428689    cd ${rootsh}
    429690    exit
  • trunk/tools/model_graphics_template.dat

    r868 r886  
    1313#  - WRF outputs will have added 'WRFtime' variable
    1414#
    15 # NOTE: in this file all the values without '
     15# NOTE: in this file all the values are ':' separated lists without '
    1616
    1717# python HOME
     
    5050#   diff: differences between models
    5151#   direct: no statistics
     52#   Lmean: latitudinal mean values
    5253#   Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
     54#   lmean: longitudinal mean values
    5355#   lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
    54 #   lmean: longitudinal mean values
    5556#   tmean: temporal mean values
     57#   xmean: x-axis mean values
     58#   ymean: y-axis mean values
    5659#   zsum: vertical aggregated values
    57 varkinds = direct:tmean:lmean:diff
     60varkinds = direct:tmean:xmean:diff
    5861
    5962# variables (providing CF-name, script must provide equivalent variable for each model)
     
    6265vardirect = 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
    6366vartmean = prc:prls:zmla:hfss:hfls:evspsbl:bils:uas:vas:tas:ps:clt:cll:clm:clh:prw:huss:pr:wakes:wakeh:stherm:zmaxth
    64 varlmean = ta:ua:va:hur
     67varxmean = ta:ua:va:hur
    6568vardiff = ualmean:valmean:talmean:huslmean:uas:vas:ps:pr
    6669
Note: See TracChangeset for help on using the changeset viewer.