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 – NEMO

Changeset 13723


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

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

Location:
NEMO/branches/2020/dev_r13648_ASINTER-04_laurent_bulk_ice/tests/STATION_ASF/EXPREF
Files:
2 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            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • NEMO/branches/2020/dev_r13648_ASINTER-04_laurent_bulk_ice/tests/STATION_ASF/EXPREF/plot_station_asf_OCE.py

    r13719 r13723  
    33# 
    44########################################################################################## 
    5 # Post-diagnostic of STATION_ASF for ocean only  (no sea-ice support) 
     5# Post-diagnostic of STATION_ASF for air-sea fluxes (over open ocean) 
    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 = [ 'ANDREAS' , 'COARE3p6' , 'ECMWF'   , 'NCAR' ] 
    3130l_color = [ '0.85'    ,  '#ffed00' , '#008ab8' , '0.4'  ] ; # colors to differentiate algos on the plot 
    3231l_width = [  4        ,     3      ,    2      ,  1     ] ; # line-width to differentiate algos on the plot 
    3332l_style = [ '-'       ,    '-'     ,   '-'     , '--'   ] ; # line-style 
    3433 
    35 nb_algos = len(L_ALGOS) ; print(nb_algos) 
    3634 
    3735# Variables to compare between algorithms 
    3836############################################ 
     37crealm = 'open-ocean' 
    3938L_VNEM = [   'Cd_oce'  ,   'Ce_oce'  ,   'qla_oce' , 'qsb_oce'     ,     'qt_oce' ,   'qlw_oce' ,  'taum'     ,    'dt_skin'         ] 
    4039L_VARO = [     'Cd'    ,     'Ce'    ,   'Qlat'    ,    'Qsen'     ,     'Qnet'   ,   'Qlw'     ,  'Tau'      ,    'dT_skin'         ] ; # name of variable on figure 
    4140L_VARL = [ r'$C_{D}$'  , r'$C_{E}$'  , r'$Q_{lat}$', r'$Q_{sens}$' , r'$Q_{net}$' , r'$Q_{lw}$' , r'$|\tau|$' , r'$\Delta T_{skin}$' ] ; # name of variable in latex mode 
    4241L_VUNT = [     ''      ,     ''      , r'$W/m^2$'  , r'$W/m^2$'    , r'$W/m^2$'   , r'$W/m^2$'  , r'$N/m^2$'  ,      'K'             ] 
    43 L_BASE = [    0.005    ,    0.005    ,      5.     ,      5.       ,       5      ,      5.     ,    0.05      ,       0.05           ] 
     42L_BASE = [    0.0005   ,    0.0005   ,      5.     ,      5.       ,       5      ,      5.     ,    0.05      ,       0.05           ] 
    4443L_PREC = [      3      ,      3      ,      0      ,      0        ,       0      ,      0      ,     2       ,        3             ] 
    4544L_ANOM = [   False     ,   False     ,   True      ,    True       ,    True      ,    True     ,   True      ,      False           ] 
    4645 
     46# About STATION_ASF output files to read: 
     47cpref = 'STATION_ASF-'          ; np = len(cpref) 
     48csuff = '_gridT.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_gridT.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 
     
    146173xxx = nmp.zeros((Nt,ntemp)) 
    147174 
    148 for ja in range(nb_algos): 
     175for ja in range(nb_exp): 
    149176    # 
    150177    # Temperatures... 
     
    170197    ax1.grid(color='k', linestyle='-', linewidth=0.3) 
    171198    plt.legend(loc='best', ncol=1, shadow=True, fancybox=True) 
    172     ax1.annotate('Algo: '+L_ALGOS[ja]+', station: '+cforcing, xy=(0.5, 1.), xycoords='axes fraction', ha='center',  bbox={'facecolor':'w', 'alpha':1., 'pad':10}, zorder=50, **font_inf) 
    173     plt.savefig('01_temperatures_'+L_ALGOS[ja]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
     199    ax1.annotate('Algo: '+list_exp[ja]+', station: '+cforcing, xy=(0.5, 1.), xycoords='axes fraction', ha='center',  bbox={'facecolor':'w', 'alpha':1., 'pad':10}, zorder=50, **font_inf) 
     200    plt.savefig('01_temperatures_'+list_exp[ja]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    174201    plt.close(1) 
    175202 
     
    183210nb_var = len(L_VNEM) 
    184211 
    185 xF  = nmp.zeros((Nt,nb_algos)) 
    186 xFa = nmp.zeros((Nt,nb_algos)) 
     212xF  = nmp.zeros((Nt,nb_exp)) 
     213xFa = nmp.zeros((Nt,nb_exp)) 
    187214 
    188215 
     
    190217    print('\n *** Treating variable: '+L_VARO[jv]+' !') 
    191218 
    192     for ja in range(nb_algos): 
     219    for ja in range(nb_exp): 
    193220        # 
    194221        id_in = Dataset(cf_in[ja]) 
     
    206233    plt.xticks(rotation='60', **font_x) 
    207234 
    208     for ja in range(nb_algos): 
     235    for ja in range(nb_exp): 
    209236        fplot = nmp.ma.masked_where( xF[:,ja]==0., xF[:,ja] ) 
    210237        plt.plot(vtime, fplot, '-', color=l_color[ja], \ 
    211                  linestyle=l_style[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
     238                 linestyle=l_style[ja], linewidth=l_width[ja], label=list_exp[ja], zorder=10+ja) 
    212239 
    213240    fmin, fmax = round_bounds( nmp.min(xF[idx_okay]) , nmp.max(xF[idx_okay]), base=L_BASE[jv], prec=L_PREC[jv]) 
     
    220247                 ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
    221248                 zorder=50, **font_inf) 
    222     plt.savefig(L_VARO[jv]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
     249    plt.savefig(L_VARO[jv]+'_'+cforcing+'_'+crealm+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    223250    plt.close(jv) 
    224251    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    239266    if L_ANOM[jv]: 
    240267 
    241         for ja in range(nb_algos): xFa[:,ja] = xF[:,ja] - nmp.mean(xF,axis=1) 
     268        for ja in range(nb_exp): xFa[:,ja] = xF[:,ja] - nmp.mean(xF,axis=1) 
    242269 
    243270        if nmp.sum(nmp.abs(xFa[:,:])) == 0.0: 
     
    251278            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    252279            fig = plt.figure(num = 10+jv, figsize=size_fig, facecolor='w', edgecolor='k') 
    253             ax1 = plt.axes([0.09, 0.25, 0.9, 0.7]) 
     280            ax1 = plt.axes([0.09, 0.23, 0.9, 0.7]) 
    254281            ax1.set_xticks(vtime[::xticks_d]) 
    255282            ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S')) 
    256283            plt.xticks(rotation='60', **font_x) 
    257284 
    258             for ja in range(nb_algos): 
    259                 plt.plot(vtime, xFa[:,ja], '-', color=l_color[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
     285            for ja in range(nb_exp): 
     286                fplot = nmp.ma.masked_where( xF[:,ja]==0., xF[:,ja] ) 
     287                plt.plot(vtime, fplot, '-', color=l_color[ja], \ 
     288                         linewidth=l_width[ja], label=list_exp[ja], zorder=10+ja) 
    260289 
    261290            ax1.set_ylim(-yrng,yrng) ; ax1.set_xlim(vtime[0],vtime[Nt-1]) 
     
    263292            ax1.grid(color='k', linestyle='-', linewidth=0.3) 
    264293            plt.legend(bbox_to_anchor=(0.45, 0.2), ncol=1, shadow=True, fancybox=True) 
    265             ax1.annotate('Anomaly of '+cvar_lnm, xy=(0.3, 0.97), xycoords='axes fraction',  bbox={'facecolor':'w', 'alpha':1., 'pad':10}, zorder=50, **font_inf) 
    266             plt.savefig(L_VARO[jv]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
     294            ax1.annotate('Anomaly of '+cvar_lnm+', station: '+cforcing, xy=(0.5, 1.04), xycoords='axes fraction', \ 
     295                         ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
     296                         zorder=50, **font_inf) 
     297            plt.savefig(L_VARO[jv]+'_'+cforcing+'_anomaly_'+crealm+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    267298            plt.close(10+jv) 
     299            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Note: See TracChangeset for help on using the changeset viewer.