Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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()