Changeset 3300 for trunk


Ignore:
Timestamp:
Apr 15, 2024, 9:42:47 AM (7 months ago)
Author:
jbclement
Message:

PEM:
Update of "output_layering.py" in the deftank.
JBC

Location:
trunk/LMDZ.COMMON/libf/evolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/changelog.txt

    r3298 r3300  
    274274== 10/04/2024 == JBC
    275275Addition of a Python script "output_layering.py" in the deftank which allows to output layering data nicely from the "startpem.nc" files.
     276
     277== 15/04/2024 == JBC
     278Update of "output_layering.py" in the deftank.
  • trunk/LMDZ.COMMON/libf/evolution/deftank/output_layering.py

    r3298 r3300  
    77import matplotlib.pyplot as plt
    88import sys
     9import os.path
    910
    1011##############################
    1112### Parameters to fill in
    12 filename = 'startpem3.nc' # File name
     13filename = 'startpem9.nc' # File name
    1314igrid = 1  # Grid point
    1415islope = 1 # Slope number
     
    1718
    1819### Open the NetCDF file
    19 nc_file = nc.Dataset(filename,'r')
     20if os.path.isfile(filename):
     21    nc_file = nc.Dataset(filename,'r')
     22else:
     23    sys.exit('The file \"' + filename + '\" does not exist!')
    2024
    2125### Get the dimensions
     
    2529nb_str_max = len(nc_file.dimensions['nb_str_max'])
    2630if igrid > ngrid or igrid < 1:
    27     sys.exit("Asked grid point is not possible!.")
     31    sys.exit('Asked grid point is not possible!')
    2832if islope > nslope or islope < 1:
    29     sys.exit("Asked slope number is not possible!")
     33    sys.exit('Asked slope number is not possible!')
    3034if istr > nb_str_max or istr < 1:
    31    sys.exit("Asked stratum number is not possible!")
     35    sys.exit('Asked stratum number is not possible!')
    3236
    3337### Get the stratification properties
     
    4953igrid = igrid - 1
    5054islope = islope - 1
    51 istr = istr - 1
    5255labels = 'CO2 ice', 'H2O ice', 'Dust', 'Air'
    53 contents = stratif_co2ice_volfrac[islope][0,:,igrid], stratif_h2oice_volfrac[islope][0,:,igrid], stratif_dust_volfrac[islope][0,:,igrid], stratif_air_volfrac[islope][0,:,igrid]
    54 x = np.zeros([4,len(stratif_top_elevation[islope][0,:,igrid]) + 1])
    55 y = np.zeros(len(stratif_top_elevation[islope][0,:,igrid]) + 1)
    56 y[0] = stratif_top_elevation[islope][0,0,:] - stratif_thickness[islope][0,0,:]
    57 y[1:] = stratif_top_elevation[islope][0,:,igrid]
     56contents = np.zeros([4,len(stratif_top_elevation[islope][0,:,igrid]) + 1])
     57height = np.zeros(len(stratif_top_elevation[islope][0,:,igrid]) + 1)
     58height[0] = stratif_top_elevation[islope][0,0,:] - stratif_thickness[islope][0,0,:]
     59height[1:] = stratif_top_elevation[islope][0,:,igrid]
    5860for i in range(len(stratif_top_elevation[islope][0,:,igrid])):
    59     x[0,1 + i] = stratif_co2ice_volfrac[islope][0,i,igrid]
    60     x[1,1 + i] = stratif_h2oice_volfrac[islope][0,i,igrid]
    61     x[2,1 + i] = stratif_dust_volfrac[islope][0,i,igrid]
    62     x[3,1 + i] = stratif_air_volfrac[islope][0,i,igrid]
    63 x[:,0] = x[:,1]
     61    contents[0,1 + i] = stratif_co2ice_volfrac[islope][0,i,igrid]
     62    contents[1,1 + i] = stratif_h2oice_volfrac[islope][0,i,igrid]
     63    contents[2,1 + i] = stratif_dust_volfrac[islope][0,i,igrid]
     64    contents[3,1 + i] = stratif_air_volfrac[islope][0,i,igrid]
     65contents[:,0] = contents[:,1]
    6466
    65 # Simple multiple subplots for a layering
    66 fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4)
    67 fig.suptitle('Volume fractions [m3/m3] in the layering')
    68 ax1.plot(contents[0],stratif_top_elevation[islope][0,:,igrid])
    69 ax2.plot(contents[1],stratif_top_elevation[islope][0,:,igrid])
    70 ax3.plot(contents[2],stratif_top_elevation[islope][0,:,igrid])
    71 ax4.plot(contents[3],stratif_top_elevation[islope][0,:,igrid])
     67# Simple subplots for a layering
     68fig, (ax1, ax2, ax3, ax4) = plt.subplots(1,4,layout = 'constrained',sharey = True)
     69fig.suptitle('Simple content profiles for the layering')
     70ax1.step(contents[0,:],height,where = 'post')
     71ax2.step(contents[1,:],height,where = 'post')
     72ax3.step(contents[2,:],height,where = 'post')
     73ax4.step(contents[3,:],height,where = 'post')
     74ax1.set_ylabel('Elevation [m]')
     75ax1.set_xlabel('Volume fraction [m3/m3]')
     76ax2.set_xlabel('Volume fraction [m3/m3]')
     77ax3.set_xlabel('Volume fraction [m3/m3]')
     78ax4.set_xlabel('Volume fraction [m3/m3]')
    7279ax1.set_title(labels[0])
    7380ax2.set_title(labels[1])
    7481ax3.set_title(labels[2])
    7582ax4.set_title(labels[3])
    76 
    77 # Pie chart for a stratum
    78 fig, ax = plt.subplots(figsize = (6, 3),subplot_kw = dict(aspect = "equal"))
    79 def func(pct,allvals):
    80     absolute = int(np.round(pct/100.*np.sum(allvals)))
    81     return f"{pct:.1f}%\n({absolute:d} m3/m3)"
    82 wedges, texts, autotexts = ax.pie(x[:,istr + 1],autopct = lambda pct: func(pct,x[:,istr + 1]),textprops = dict(color = "w"))
    83 ax.legend(wedges,labels,title = "Content",loc = "center left",bbox_to_anchor = (1, 0, 0.5, 1))
    84 plt.setp(autotexts,size = 8,weight = "bold")
    85 ax.set_title("Content of the stratum " + str(istr + 1))
     83plt.savefig('layering_simpleprofiles.png')
    8684
    8785# Stackplot for a layering
    8886fig, ax = plt.subplots()
    89 ax.fill_betweenx(y,0,x[0,:],label = labels[0],step = 'pre')
    90 ax.fill_betweenx(y,x[0,:],sum(x[0:2,:]),label = labels[1],step = 'pre')
    91 ax.fill_betweenx(y,sum(x[0:2,:]),sum(x[0:3,:]),label = labels[2],step = 'pre')
    92 ax.fill_betweenx(y,sum(x[0:3,:]),sum(x),label = labels[3],step = 'pre')
    93 plt.vlines(x = 0.,ymin = y[0],ymax = y[len(y) - 1],color = 'k',linestyle = '-')
    94 plt.vlines(x = 1.,ymin = y[0],ymax = y[len(y) - 1],color = 'k',linestyle = '-')
    95 for i in range(len(y)):
    96     plt.hlines(y = y[i],xmin = 0.0,xmax = 1.0,color = 'k',linestyle = '--')
    97 ax.set_title("Layering")
    98 plt.xlabel("Volume fraction [m3/m3]")
    99 plt.ylabel("Elevation [m]")
     87ax.fill_betweenx(height,0,contents[0,:],label = labels[0],color = 'r',step = 'pre')
     88ax.fill_betweenx(height,contents[0,:],sum(contents[0:2,:]),label = labels[1],color = 'b',step = 'pre')
     89ax.fill_betweenx(height,sum(contents[0:2,:]),sum(contents[0:3,:]),label = labels[2],color = 'y',step = 'pre')
     90ax.fill_betweenx(height,sum(contents[0:3,:]),sum(contents),label = labels[3],color = 'g',step = 'pre')
     91plt.vlines(x = 0.,ymin = height[0],ymax = height[len(height) - 1],color = 'k',linestyle = '-')
     92plt.vlines(x = 1.,ymin = height[0],ymax = height[len(height) - 1],color = 'k',linestyle = '-')
     93for i in range(len(height)):
     94    plt.hlines(y = height[i],xmin = 0.0,xmax = 1.0,color = 'k',linestyle = '--')
     95ax.set_title('Stack content profiles for the layering')
     96plt.xlabel('Volume fraction [m3/m3]')
     97plt.ylabel('Elevation [m]')
    10098ax.legend(loc = 'center left',bbox_to_anchor = (1,0.5))
     99plt.savefig('layering_stackprofiles.png')
    101100
    102101plt.show()
Note: See TracChangeset for help on using the changeset viewer.