Skip to content
Snippets Groups Projects
Select Git revision
  • de843e5d31299d2fa8628fc1235f9eb6a2359c75
  • main default protected
2 results

plot_profile_xbt.py

Blame
  • plot_profile_xbt.py 1.18 KiB
    from netCDF4 import Dataset
    import numpy as np
    import matplotlib
    import numpy as np
    import matplotlib.pyplot as plt
    import os
    
    # in batch mode, without display
    #matplotlib.use('Agg')  
    
    file = 'OS_PIRATA-FR29_XBT.nc'
    #ncpath = 'netcdf'
    #path = 'plots'
    ncpath = '.'
    path = 'png'
    
    ncfile = os.path.join(ncpath, file)
    nc = Dataset(ncfile, mode='r')
    
    TEMP = nc.variables['TEMP']
    DEPTH = nc.variables['DEPTH']
    PROFILE = nc.variables['PROFILE']
    STATION = PROFILE.shape[0]
    CM = nc.cycle_mesure
    
    # move subplot outside loop prevent: RuntimeWarning: More than 20 figures have been opened.
    fig, ax = plt.subplots()
    
    for x in range(0,STATION):
        temp = TEMP[x,:]
        depth = DEPTH[x,:]
    
        ax.plot(temp, depth)
        ax.invert_yaxis()
        ax.set(xlabel='{} ({})'.format(TEMP.long_name, TEMP.units), ylabel='{} ({})'.format(DEPTH.long_name,DEPTH.units),
               title='{} - XBT Sippican profile n° {}'.format(CM, x+1))
        ax.axis('auto')
        ax.set_ylim(top=0)
        ax.set_xlim(left=0, right=32)
        ax.grid()
    
        figname = '{}-{:03d}_XBT.png'.format(CM, x+1)
        dest = os.path.join(path, figname)
        fig.savefig(dest)
        print('Printing: ', dest)
        plt.show()
        plt.cla()
    #plt.close(fig)
    print('Done.')