Skip to content
Snippets Groups Projects
Commit 852e2050 authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

add plot

parent c6779297
No related branches found
No related tags found
No related merge requests found
from netCDF4 import Dataset
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import os
from datetime import date
import datetime
from PyAstronomy import pyasl
from scipy.interpolate import griddata
#change the year for the plot
annee = 2019
# in batch mode, without display
#matplotlib.use('Agg')
file = 'OS_PIRATA-FR29_TSG.nc'
<<<<<<< HEAD
=======
path_clim = '../climato/'
clim = 'isas13_monthly_surf.nc'
>>>>>>> 0fc9903c756f8ee2046db03512c9fda828b01a9a
ncpath = '.'
path = 'png'
ncfile = os.path.join(ncpath, file)
nc = Dataset(ncfile, mode='r')
SSPS = nc.variables['SSPS']
SSTP = nc.variables['SSTP']
TIME = nc.variables['TIME']
CM = nc.cycle_mesure
LON = nc.variables['LONGITUDE']
LAT = nc.variables['LATITUDE']
#definition of the day for the current year and the start year of netcdf
df = datetime.datetime(annee, 1, 1, 0)
dd = datetime.datetime(1950, 1, 1, 0)
#convert day to julian day real
jul = pyasl.jdcnv(df)
jul2 = pyasl.jdcnv(dd)
#calculation of the current year julian day since the beginig of julian day
DIFF = jul - jul2
#test
#from datetime import datetime
#units=nc.variables['TIME'].units
#buf=nc.variables['TIME']
#TIME=list()
#TIME.extend(buf.tolist())
#dates=nc.num2date(TIME,units,'julian').tolist()
#import julian
#import datetime
#TIME = julian.from_jd(TIME, fmt='mjd')
#end test
#setting of the curent julian day
time = TIME[:] - DIFF
# move subplot outside loop prevent: RuntimeWarning: More than 20 figures have been opened.
fig, ax = plt.subplots(2,1)
fig.set_size_inches(10.5, 8.5, forward=True)
fig.suptitle(CM, fontsize=14, fontweight='bold')
ax[0].plot(time, SSPS, 'r')
ax[0].set_xlabel('Jours Julien')
ax[0].set_ylabel(SSPS.long_name)
ax[0].spines['left'].set_color('red')
ax[0].spines['right'].set_color('red')
ax[0].yaxis.label.set_color('red')
ax[0].tick_params(axis='y', colors='red')
ax[1].plot(time, SSTP, 'g')
ax[1].set_xlabel('Jours Julien')
ax[1].set_ylabel(SSTP.long_name)
ax[1].spines['left'].set_color('green')
ax[1].spines['right'].set_color('green')
ax[1].yaxis.label.set_color('green')
ax[1].tick_params(axis='y', colors='green')
figname = '{}_TSG_COLCOR_SST-SSPS.png'.format(CM)
dest = os.path.join(path, figname)
fig.savefig(dest)
print('Printing: ', dest)
plt.show()
plt.cla()
from netCDF4 import Dataset
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import os
from datetime import date
import datetime
from PyAstronomy import pyasl
from scipy.interpolate import griddata
#change the year for the plot
annee = 2019
# in batch mode, without display
#matplotlib.use('Agg')
file = 'OS_PIRATA-FR29_TSG.nc'
path_clim = '../climato/'
clim = 'isas13_monthly_surf.nc'
ncpath = '.'
path = 'png'
ncfile = os.path.join(ncpath, file)
nc = Dataset(ncfile, mode='r')
climfile = os.path.join(path_clim, clim)
cl = Dataset(climfile, mode='r')
SSPS = nc.variables['SSPS']
SSTP = nc.variables['SSTP']
TIME = nc.variables['TIME']
CM = nc.cycle_mesure
LON = nc.variables['LONGITUDE']
LAT = nc.variables['LATITUDE']
LONC = cl.variables['WOA_LONX']
LATC = cl.variables['WOA_LATX']
grid = griddata(LONC, LATC, (LON, LAT), method='nearest')
print (grid)
#definition of the julian day for the current year
df = datetime.datetime(annee, 1, 1, 0)
dd = datetime.datetime(1950, 1, 1, 0)
jul = pyasl.jdcnv(df)
jul2 = pyasl.jdcnv(dd)
#calculation of the current year julian day since the beginig of julian day
DIFF = jul - jul2
#test
#from datetime import datetime
#units=nc.variables['TIME'].units
#buf=nc.variables['TIME']
#TIME=list()
#TIME.extend(buf.tolist())
#dates=nc.num2date(TIME,units,'julian').tolist()
#import julian
#import datetime
#TIME = julian.from_jd(TIME, fmt='mjd')
#end test
#setting of the curent julian day
time = TIME[:] - DIFF
# move subplot outside loop prevent: RuntimeWarning: More than 20 figures have been opened.
fig, ax = plt.subplots(2,1)
fig.set_size_inches(10.5, 8.5, forward=True)
fig.suptitle(CM, fontsize=14, fontweight='bold')
#ax[0].set_title(CM)
ax[0].plot(time, SSPS, 'r')
ax[0].set_xlabel('Jours Julien')
ax[0].set_ylabel(SSPS.long_name)
ax[0].spines['left'].set_color('red')
ax[0].spines['right'].set_color('red')
ax[0].yaxis.label.set_color('red')
ax[0].tick_params(axis='y', colors='red')
ax[1].plot(time, SSTP, 'g')
ax[1].set_xlabel('Jours Julien')
ax[1].set_ylabel(SSTP.long_name)
ax[1].spines['left'].set_color('green')
ax[1].spines['right'].set_color('green')
ax[1].yaxis.label.set_color('green')
ax[1].tick_params(axis='y', colors='green')
figname = '{}_TSG_COLCOR_SST-SSPS.png'.format(CM)
dest = os.path.join(path, figname)
fig.savefig(dest)
print('Printing: ', dest)
plt.show()
plt.cla()
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.')
\ No newline at end of file
from netCDF4 import Dataset
import numpy as np
#import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import os
# in batch mode, without display
#matplotlib.use('Agg')
file = 'OS_PIRATA-FR29_TSG.nc'
ncpath = '.'
path = 'png'
ncfile = os.path.join(ncpath, file)
nc = Dataset(ncfile, mode='r')
SSPS = nc.variables['SSPS']
SSTP = nc.variables['SSTP']
TIME = nc.variables['TIME']
LATITUDE = nc.variables['LATITUDE']
LONGITUDE = nc.variables['LONGITUDE']
CM = nc.cycle_mesure
# move subplot outside loop prevent: RuntimeWarning: More than 20 figures have been opened.
fig, ax = plt.subplots(2, 1, figsize=(6, 12))
fig.subplots_adjust(left=0.125, bottom=0.1, right=0.9, top=0.9, wspace=0.3, hspace=0.3)
im1 = ax[0].scatter(LONGITUDE[:], LATITUDE[:], c=SSPS[:], s=30, cmap='jet', vmin=32, vmax=37)
fig.colorbar(im1, ax=ax[0], orientation='vertical')
ax[0].set(xlabel='{} '.format(LONGITUDE.standard_name), ylabel='{} '.format(LATITUDE.standard_name),
title='{} - {}'.format(CM, SSPS.long_name))
ax[0].grid()
im2 = ax[1].scatter(LONGITUDE[:], LATITUDE[:], c=SSTP[:], s=30, cmap='jet', vmin=21, vmax=32)
fig.colorbar(im2, ax=ax[1], orientation='vertical')
ax[1].set(xlabel='{} '.format(LONGITUDE.standard_name), ylabel='{} '.format(LATITUDE.standard_name),
title='{} - {}'.format(CM, SSPS.long_name))
ax[1].grid()
figname = '{}_TSG_COLCOR_SCATTER.png'.format(CM)
dest = os.path.join(path, figname)
fig.savefig(dest)
print('Printing: ', dest)
plt.show()
plt.cla()
#im1 = cs[0, 0].contourf(lon,lat,result1, np.linspace(20,30,21), extend='both', cmap=cm.jet)
#cs[0, 0].set_title('VOTEMPER OBS Saison ' + list1[x],fontsize=10)
#fig.colorbar(im1, ax=cs[0, 0], orientation='horizontal')
######################################df = pd.DataFrame(np.transpose([LONGITUDE[:], LATITUDE[:], SSPS[:]]), columns=['LONGITUDE', 'LATITUDE', 'SSPS']) #, columns=['Longitudes','Latitudes']
######################################ax = df.plot.scatter(x='LONGITUDE', y='LATITUDE', c='SSPS', colormap='viridis')
######################################ax.set_ylim(bottom=-12,top=19)
######################################ax.set_xlim(left=-30, right=15)
######################################print(df)
#A = np.array((LONGITUDE, LATITUDE, SSTP), dtype=float)
#print(SSPS[36])
#print(A)
#plt.plot(LATITUDE,LONGITUDE,A)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment