New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 13723 for NEMO/branches/2020/dev_r13648_ASINTER-04_laurent_bulk_ice/tests/STATION_ASF/EXPREF/plot_station_asf_ICE.py – NEMO

Ignore:
Timestamp:
2020-11-03T17:17:45+01:00 (4 years ago)
Author:
laurent
Message:

Keep up with trunk r13718 + figure generation for STATION_ASF (ocean & ice).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2020/dev_r13648_ASINTER-04_laurent_bulk_ice/tests/STATION_ASF/EXPREF/plot_station_asf_ICE.py

    r13719 r13723  
    33# 
    44########################################################################################## 
    5 # Post-diagnostic of STATION_ASF with sea-ice support (ex: run with forcing "ERA5_arctic") 
     5# Post-diagnostic of STATION_ASF for air-ice fluxes (over sea-ice) 
    66# 
    77#  L. Brodeau, 2020 
     
    99 
    1010import sys 
    11 from os import path as path 
     11from os import path, listdir 
    1212import argparse as ap 
    1313from math import floor, ceil, copysign, log 
     
    2828rDPI=100. 
    2929 
    30 L_ALGOS = [ 'ECMWF-CSTC', 'ECMWF-LG15', 'ECMWF-LU12' ] 
    31 l_color = [     '0.4'   ,  '#ffed00'  , '#008ab8'    ] ; # colors to differentiate algos on the plot 
    32 l_width = [       3     ,     3       ,      2       ] ; # line-width to differentiate algos on the plot 
    33 l_style = [      '--'   ,    '-'      ,     '-'      ] ; # line-style 
    34  
    35 nb_algos = len(L_ALGOS) ; print(nb_algos) 
     30l_color = [ '0.85'    ,  '#ffed00' , '#008ab8' , '0.4'  ] ; # colors to differentiate algos on the plot 
     31l_width = [  4        ,     3      ,    2      ,  1     ] ; # line-width to differentiate algos on the plot 
     32l_style = [ '-'       ,    '-'     ,   '-'     , '--'   ] ; # line-style 
     33 
    3634 
    3735# Variables to compare between algorithms 
    3836############################################ 
     37crealm = 'sea-ice' 
    3938L_VNEM = [   'Cd_ice',   'Ce_ice',   'qla_ice' ,   'qsb_ice'   ,  'qt_ice'    ,  'qlw_ice'  ,  'qsr_ice'  , 'taum_ai'   ] 
    4039L_VARO = [     'Cd'  ,     'Ce'  ,   'Qlat'    ,    'Qsen'     ,   'Qnet'     ,   'Qlw'     ,    'Qsw'    ,  'Tau'      ] 
     
    4544L_ANOM = [   False   ,   False   ,   True      ,    True       ,    True      ,    True     ,    True     ,   True      ] 
    4645 
     46# About STATION_ASF output files to read: 
     47cpref = 'STATION_ASF-'          ; np = len(cpref) 
     48csuff = '_icemod.nc'            ; ns = len(csuff) 
     49cclnd = '_1h_YYYY0101_YYYY1231' ; nc = len(cclnd) 
    4750 
    4851 
     
    8487# Populating and checking existence of files to be read 
    8588# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
    86 def chck4f(cf): 
    87     cmesg = 'ERROR: File '+cf+' does not exist !!!' 
    88     if not path.exists(cf): print(cmesg) ; sys.exit(0) 
    89  
    90 cf_in = [] 
    91 for ja in range(nb_algos): 
    92     cfi = cdir_data+'/output/'+CONF+'-'+L_ALGOS[ja]+'_'+cforcing+'_1h_'+cy1+'0101_'+cy2+'1231_icemod.nc' 
    93     chck4f(cfi) 
    94     cf_in.append(cfi) 
    95 print('Files we are goin to use:') 
    96 for ja in range(nb_algos): print(cf_in[ja]) 
     89 
     90dir_out = cdir_data+'/output' 
     91ldir = listdir(dir_out) 
     92 
     93cf_in    = [] 
     94list_exp = [] 
     95list_frc = [] 
     96for fn in ldir: 
     97    fpn = dir_out+'/'+fn 
     98    if path.isfile(dir_out+'/'+fn): 
     99        if fn[:np]==cpref and fn[-ns:]==csuff and cforcing in fn: 
     100            print('\n file: '+fn) 
     101            clab = fn[np:-nc-ns] 
     102            [ cexp, cfrc ] = str.split(clab, '_', 1) 
     103            print('  ===> Experiment = '+cexp+', Forcing = '+cfrc) 
     104            list_exp.append(cexp) 
     105            list_frc.append(cfrc) 
     106            cf_in.append(fpn) 
     107nbf = len( set(list_frc) ) 
     108if not nbf == 1: 
     109    print('PROBLEM: we found files for more that one forcing: ', set(list_frc)) 
     110    sys.exit(0) 
     111 
     112nb_exp = len(list_exp) 
     113 
     114 
     115print('\n\nThere are '+str(nb_exp)+' experiments to compare:') 
     116for ja in range(nb_exp): print('  * '+list_exp[ja]+'\n'+'     ==> '+cf_in[ja]+'\n') 
     117 
     118if nb_exp > len(l_color): 
     119    print('PROBLEM: the max number of experiments for comparison is '+str(len(l_color))+' for now...') 
     120    sys.exit(0) 
     121 
     122 
     123 
    97124#----------------------------------------------------------------- 
    98125 
     
    135162nb_var = len(L_VNEM) 
    136163 
    137 xF  = nmp.zeros((Nt,nb_algos)) 
    138 xFa = nmp.zeros((Nt,nb_algos)) 
     164xF  = nmp.zeros((Nt,nb_exp)) 
     165xFa = nmp.zeros((Nt,nb_exp)) 
    139166 
    140167 
     
    142169    print('\n *** Treating variable: '+L_VARO[jv]+' !') 
    143170 
    144     for ja in range(nb_algos): 
     171    for ja in range(nb_exp): 
    145172        # 
    146173        id_in = Dataset(cf_in[ja]) 
     
    158185    plt.xticks(rotation='60', **font_x) 
    159186 
    160     for ja in range(nb_algos): 
     187    for ja in range(nb_exp): 
    161188        fplot = nmp.ma.masked_where( xF[:,ja]==0., xF[:,ja] ) 
    162189        plt.plot(vtime, fplot, '-', color=l_color[ja], \ 
    163                  linestyle=l_style[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
     190                 linestyle=l_style[ja], linewidth=l_width[ja], label=list_exp[ja], zorder=10+ja) 
    164191 
    165192    fmin, fmax = round_bounds( nmp.min(xF[idx_okay]) , nmp.max(xF[idx_okay]), base=L_BASE[jv], prec=L_PREC[jv]) 
     
    172199                 ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
    173200                 zorder=50, **font_inf) 
    174     plt.savefig(L_VARO[jv]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
     201    plt.savefig(L_VARO[jv]+'_'+cforcing+'_'+crealm+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    175202    plt.close(jv) 
    176203    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    191218    if L_ANOM[jv]: 
    192219 
    193         for ja in range(nb_algos): xFa[:,ja] = xF[:,ja] - nmp.mean(xF,axis=1) 
     220        for ja in range(nb_exp): xFa[:,ja] = xF[:,ja] - nmp.mean(xF,axis=1) 
    194221 
    195222        if nmp.sum(nmp.abs(xFa[:,:])) == 0.0: 
     
    208235            plt.xticks(rotation='60', **font_x) 
    209236 
    210             for ja in range(nb_algos): 
     237            for ja in range(nb_exp): 
    211238                fplot = nmp.ma.masked_where( xF[:,ja]==0., xF[:,ja] ) 
    212                 plt.plot(vtime, fplot, '-', color=l_color[ja], linewidth=l_width[ja], \ 
    213                          label=L_ALGOS[ja], zorder=10+ja) 
     239                plt.plot(vtime, fplot, '-', color=l_color[ja], \ 
     240                         linewidth=l_width[ja], label=list_exp[ja], zorder=10+ja) 
    214241 
    215242            ax1.set_ylim(-yrng,yrng) ; ax1.set_xlim(vtime[0],vtime[Nt-1]) 
     
    220247                         ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
    221248                         zorder=50, **font_inf) 
    222             plt.savefig(L_VARO[jv]+'_anomaly.'+fig_ext, dpi=int(rDPI), transparent=False) 
     249            plt.savefig(L_VARO[jv]+'_'+cforcing+'_anomaly_'+crealm+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    223250            plt.close(10+jv) 
    224251            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Note: See TracChangeset for help on using the changeset viewer.