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 13719 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-03T12:02:23+01:00 (4 years ago)
Author:
laurent
Message:

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

File:
1 moved

Legend:

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

    r13718 r13719  
    1010import sys 
    1111from os import path as path 
    12 import math 
     12import argparse as ap 
     13from math import floor, ceil, copysign, log 
    1314import numpy as nmp 
    1415from netCDF4 import Dataset,num2date 
     
    1819import matplotlib.dates as mdates 
    1920 
    20 CONFIG='STATION_ASF' 
    21  
    22 cforcing = 'PAPA' ; # name of forcing ('PAPA', 'ERA5_arctic', etc...) 
    23  
    24 # (files are: output/3x3/'+CONFIG+'-'+algo+'_1h_'+year+'0101_'+year+'1231_gridT_'+cforcing+'.nc' ) 
    25 cstation = 'ERA5 81N, 36.75E' 
    26  
    27 cy1     = '2018' ; # First year 
    28 cy2     = '2018' ; # Last year 
    29  
    30 jt0 = 0 
    31  
    3221dir_figs='.' 
    33 size_fig=(13,8) 
     22size_fig=(13,8.5) 
    3423size_fig0=(12,10) 
    35 fig_ext='png' 
    3624 
    3725clr_red = '#AD0000' 
    38 clr_sat = '#ffed00' 
    3926clr_mod = '#008ab8' 
    4027 
    4128rDPI=100. 
    4229 
    43 L_ALGOS = [ 'ECMWF-LG15', 'ECMWF-LU12', 'ECMWF-CSTC' ] 
    44 l_color = [  '#ffed00'  , '#008ab8'   ,     '0.4'    ] ; # colors to differentiate algos on the plot 
    45 l_width = [     3       ,      2      ,       1      ] ; # line-width to differentiate algos on the plot 
    46 l_style = [    '-'      ,     '-'     ,      '--'    ] ; # line-style 
    47  
    48  
    49 # Variables to compare for A GIVEN algorithm 
    50 ############################################### 
    51 #L_VNEM0 = [  
    52  
    53  
     30L_ALGOS = [ 'ECMWF-CSTC', 'ECMWF-LG15', 'ECMWF-LU12' ] 
     31l_color = [     '0.4'   ,  '#ffed00'  , '#008ab8'    ] ; # colors to differentiate algos on the plot 
     32l_width = [       3     ,     3       ,      2       ] ; # line-width to differentiate algos on the plot 
     33l_style = [      '--'   ,    '-'      ,     '-'      ] ; # line-style 
     34 
     35nb_algos = len(L_ALGOS) ; print(nb_algos) 
    5436 
    5537# Variables to compare between algorithms 
     
    5941L_VARL = [ r'$C_{D}$', r'$C_{E}$', r'$Q_{lat}$', r'$Q_{sens}$' , r'$Q_{net}$' , r'$Q_{lw}$' , r'$Q_{sw}$' , r'$|\tau|$' ] 
    6042L_VUNT = [     ''    ,     ''    , r'$W/m^2$'  , r'$W/m^2$'    , r'$W/m^2$'   , r'$W/m^2$'  , r'$W/m^2$'  , r'$N/m^2$'  ] 
    61 L_VMAX = [    0.003  ,    0.003  ,     75.     ,     75.       ,    800.      ,    200.     ,    200.     ,    1.2      ] 
    62 L_VMIN = [    0.     ,    0.     ,   -250.     ,   -125.       ,   -400.      ,   -200.     ,      0.     ,    0.       ] 
     43L_BASE = [    0.0005 ,    0.0005 ,      5.     ,     5.        ,     5.       ,    5.       ,     5.      ,    0.05     ] 
     44L_PREC = [     3     ,     3     ,      0     ,      0        ,      0      ,      0        ,     0       ,     2       ] 
    6345L_ANOM = [   False   ,   False   ,   True      ,    True       ,    True      ,    True     ,    True     ,   True      ] 
    6446 
    6547 
    66 nb_algos = len(L_ALGOS) 
    67  
    68 # Getting arguments: 
    69 narg = len(sys.argv) 
    70 if narg != 2: 
    71     print('Usage: '+sys.argv[0]+' <DIR_OUT_SASF>'); sys.exit(0) 
    72 cdir_data = sys.argv[1] 
     48 
     49################## ARGUMENT PARSING / USAGE ################################################################################################ 
     50parser = ap.ArgumentParser(description='Generate pixel maps of a given scalar.') 
     51# 
     52requiredNamed = parser.add_argument_group('required arguments') 
     53requiredNamed.add_argument('-d', '--dirout' , required=True,                 help='Path to (production) directory where STATION_ASF was run') 
     54requiredNamed.add_argument('-f', '--forcing', required=True, default="PAPA", help='Name of forcing (ex: PAPA, ERA5_arctic') 
     55# 
     56parser.add_argument('-C', '--conf',   default="STATION_ASF",  help='specify NEMO config (ex: STATION_ASF)') 
     57parser.add_argument('-s', '--ystart', default="2018",         help='specify first year of experiment (ex: 2018)') 
     58parser.add_argument('-e', '--yend',   default="2018",         help='specify last  year of experiment (ex: 2018)') 
     59# 
     60parser.add_argument('-t', '--itype',   default="png",         help='specify the type of image you want to create (ex: png, svg, etc.)') 
     61#parser.add_argument('-l', '--lev' , type=int, default=0,    help='specify the level to use if 3D field (default: 0 => 2D)') 
     62#parser.add_argument('-I', '--ice' , action='store_true',    help='draw sea-ice concentration layer onto the field') 
     63# 
     64args = parser.parse_args() 
     65# 
     66cdir_data = args.dirout 
     67cforcing  = args.forcing 
     68# 
     69CONF      = args.conf 
     70cy1       = args.ystart 
     71cy2       = args.yend 
     72# 
     73fig_ext   = args.itype 
     74#jk    = args.lev 
     75#lshow_ice = args.ice 
     76# 
     77#print(''); print(' *** cdir_data = ', cdir_data); print(' *** cforcing  = ', cforcing) 
     78#print(' *** CONF = ', CONF); print(' *** cy1 = ', cy1); print(' *** cy2 = ', cy2) 
     79############################################################################################################################################### 
    7380 
    7481 
     
    8390cf_in = [] 
    8491for ja in range(nb_algos): 
    85     cfi = cdir_data+'/output/3x3/'+CONFIG+'-'+L_ALGOS[ja]+'_1h_'+cy1+'0101_'+cy2+'1231_icemod_'+cforcing+'.nc' 
     92    cfi = cdir_data+'/output/'+CONF+'-'+L_ALGOS[ja]+'_'+cforcing+'_1h_'+cy1+'0101_'+cy2+'1231_icemod.nc' 
    8693    chck4f(cfi) 
    8794    cf_in.append(cfi) 
     
    9097#----------------------------------------------------------------- 
    9198 
     99 
     100def round_bounds( x1, x2,  base=5, prec=3 ): 
     101    rmin =  base * round( floor(float(x1)/base), prec ) 
     102    rmax =  base * round(  ceil(float(x2)/base), prec ) 
     103    return rmin, rmax 
     104 
     105 
    92106# Getting time array from the first file: 
    93107id_in = Dataset(cf_in[0]) 
    94 vt = id_in.variables['time_counter'][jt0:] 
     108vt = id_in.variables['time_counter'][:] 
    95109cunit_t = id_in.variables['time_counter'].units ; print(' "time_counter" is in "'+cunit_t+'"') 
    96110id_in.close() 
    97111Nt = len(vt) 
    98112 
    99 vtime = num2date(vt, units=cunit_t) ; # something understandable! 
     113vtime = num2date(vt, units=cunit_t) ; # something human! 
    100114vtime = vtime.astype(dtype='datetime64[D]') 
    101115 
     
    131145        # 
    132146        id_in = Dataset(cf_in[ja]) 
    133         xF[:,ja] = id_in.variables[L_VNEM[jv]][jt0:,1,1] # only the center point of the 3x3 spatial domain! 
     147        xF[:,ja] = id_in.variables[L_VNEM[jv]][:,1,1] # only the center point of the 3x3 spatial domain! 
    134148        if ja == 0: cvar_lnm = id_in.variables[L_VNEM[jv]].long_name 
    135149        id_in.close() 
    136150 
     151    idx_okay = nmp.where( nmp.abs(xF) < 1.e+10 ) 
     152 
    137153    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    138154    fig = plt.figure(num = jv, figsize=size_fig, facecolor='w', edgecolor='k') 
    139     ax1 = plt.axes([0.08, 0.25, 0.9, 0.7]) 
     155    ax1 = plt.axes([0.083, 0.23, 0.9, 0.7]) 
    140156    ax1.set_xticks(vtime[::xticks_d]) 
    141157    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S')) 
     
    143159 
    144160    for ja in range(nb_algos): 
    145         plt.plot(vtime, xF[:,ja], '-', color=l_color[ja], linestyle=l_style[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
    146  
    147     ax1.set_ylim(L_VMIN[jv], L_VMAX[jv]) ; ax1.set_xlim(vtime[0],vtime[Nt-1]) 
     161        fplot = nmp.ma.masked_where( xF[:,ja]==0., xF[:,ja] ) 
     162        plt.plot(vtime, fplot, '-', color=l_color[ja], \ 
     163                 linestyle=l_style[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
     164 
     165    fmin, fmax = round_bounds( nmp.min(xF[idx_okay]) , nmp.max(xF[idx_okay]), base=L_BASE[jv], prec=L_PREC[jv]) 
     166    ax1.set_ylim(fmin, fmax) ; ax1.set_xlim(vtime[0],vtime[Nt-1]) 
    148167    plt.ylabel(L_VARL[jv]+' ['+L_VUNT[jv]+']') 
    149168 
    150169    ax1.grid(color='k', linestyle='-', linewidth=0.3) 
    151170    plt.legend(loc='best', ncol=1, shadow=True, fancybox=True) 
    152     ax1.annotate(cvar_lnm+', station: '+cstation, xy=(0.3, 1.), xycoords='axes fraction',  bbox={'facecolor':'w', 'alpha':1., 'pad':10}, zorder=50, **font_inf) 
    153     plt.savefig(L_VARO[jv]+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
     171    ax1.annotate(cvar_lnm+', station: '+cforcing, xy=(0.5, 1.04), xycoords='axes fraction', \ 
     172                 ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
     173                 zorder=50, **font_inf) 
     174    plt.savefig(L_VARO[jv]+'_'+cforcing+'.'+fig_ext, dpi=int(rDPI), transparent=False) 
    154175    plt.close(jv) 
    155176    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     177 
     178 
     179 
    156180 
    157181    def symetric_range( pmin, pmax ): 
     
    164188        return frng 
    165189 
    166      
    167190 
    168191    if L_ANOM[jv]: 
     
    180203            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    181204            fig = plt.figure(num = 10+jv, figsize=size_fig, facecolor='w', edgecolor='k') 
    182             ax1 = plt.axes([0.08, 0.25, 0.9, 0.7]) 
     205            ax1 = plt.axes([0.083, 0.23, 0.9, 0.7]) 
    183206            ax1.set_xticks(vtime[::xticks_d]) 
    184207            ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S')) 
     
    186209 
    187210            for ja in range(nb_algos): 
    188                 plt.plot(vtime, xFa[:,ja], '-', color=l_color[ja], linewidth=l_width[ja], label=L_ALGOS[ja], zorder=10+ja) 
     211                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) 
    189214 
    190215            ax1.set_ylim(-yrng,yrng) ; ax1.set_xlim(vtime[0],vtime[Nt-1]) 
     
    192217            ax1.grid(color='k', linestyle='-', linewidth=0.3) 
    193218            plt.legend(bbox_to_anchor=(0.45, 0.2), ncol=1, shadow=True, fancybox=True) 
    194             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) 
     219            ax1.annotate('Anomaly of '+cvar_lnm+', station: '+cforcing, xy=(0.5, 1.04), xycoords='axes fraction', \ 
     220                         ha='center', bbox={'facecolor':'w', 'alpha':1., 'pad':10}, \ 
     221                         zorder=50, **font_inf) 
    195222            plt.savefig(L_VARO[jv]+'_anomaly.'+fig_ext, dpi=int(rDPI), transparent=False) 
    196223            plt.close(10+jv) 
    197224            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    198  
    199  
    200  
    201  
Note: See TracChangeset for help on using the changeset viewer.