Commit c0cb8ae6c2e758d876093e7c1855e345d4503959

Authored by Paul Nicot
1 parent 509db604
Exists in master and in 2 other branches mingan, simon

ajout de la carte du golfe + ajustement

Showing 1 changed file with 83 additions and 68 deletions   Show diff stats
tr_snake.py
... ... @@ -5,82 +5,93 @@ from mpl_toolkits.basemap import Basemap
5 5 from time import gmtime, strftime
6 6 import matplotlib.pyplot as plt
7 7 import time
  8 +import datetime
8 9 import numpy as np
9 10 import pandas as pd
10 11 from mpl_toolkits.axes_grid1 import make_axes_locatable
11 12  
12   -strtime = strftime("%Y-%m-%d %H:%M", gmtime())
13   -nametime = strftime("%Y%m%d%H%M", gmtime())
14   -# temps unix
15   -timestamp = int(time.time())
16   -# sec dans une journee
17   -sday = 60 * 60 * 24
18   -# intervalle de temps
19   -dd = 5 # nombre de jours
20   -dt = timestamp - 5*sday # intervalle de temps depuis dd jours
21   -diff = timestamp - dt #
  13 +# parametres modifiables --------------------------
  14 +snake = 24 # nombre d'heure de suivi du serpent
  15 +# ================================================
  16 +
  17 +sday = 84600
  18 +shour = 3600
22 19  
23 20 # colormap
24 21 cmap=plt.get_cmap('OrRd')
25   -
  22 +lab1 = int(snake)
  23 +lab2 = int(snake*0.75)
  24 +lab3 = int(snake*0.5)
  25 +lab4 = int(snake*0.25)
  26 +lab5 = 0
26 27  
27 28 # Base de donnees ----------------------------
28 29 df = pd.read_csv('/home/nicopa01/data/spot/spots_pos.csv',delimiter=';')
29 30 df = df.drop_duplicates(take_last=True)
30 31  
  32 +timestamp = int(time.time())
  33 +dt = timestamp - shour * snake
  34 +diff = timestamp - dt
  35 +
  36 +strtime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M')
  37 +nametime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y%m%d%H%M')
  38 +
  39 +
  40 +# Golfe du Saint-Laurent ---------------------------
  41 +# traces des x derniers jours dans l'estuaire
  42 +GSL = df[(df.FLAG == "OCN")& (df.TIME <= timestamp)
  43 + & (df.TIME > timestamp - shour*snake)]
31 44  
32   -# Baie des Chaleurs ---------------------------
33   -# traces des x derniers jours dans la baie
34   -BDC = df[(df.SPOT > 699) & (df.SPOT < 800) & (df.FLAG == "OCN")
35   - & (df.TIME > dt)]
36   -
37 45 plt.clf()
38 46 fig, ax = plt.subplots()
39 47  
40 48 # caracteristiques de la carte
41   -m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
42   - llcrnrlat=47.5,urcrnrlat=48.7,\
43   - llcrnrlon=-66.9,urcrnrlon=-64.2,\
  49 +m = Basemap(projection='stere',lon_0=-64.5,lat_0=48,\
  50 + llcrnrlat=45.2,urcrnrlat=51.6,\
  51 + llcrnrlon=-70,urcrnrlon=-56.5,\
44 52 rsphere=6371.2,resolution='h')
45 53  
46 54 m.drawmapboundary(fill_color='lightblue') # fill to edge
47 55 m.drawcountries()
48 56 m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
49 57 m.drawrivers()
50   -m.drawcoastlines(linewidth=0.8)
51   -m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0])
52   -m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1])
  58 +m.drawcoastlines(linewidth=0.7)
  59 +m.drawparallels(np.arange(40,60,2),labels=[1,0,0,0],linewidth=0.0)
  60 +m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1],linewidth=0.0)
53 61  
54 62 # trace les chemins de bouees
55   -for spot, group in BDC.groupby(['SPOT']):
  63 +for spot, group in GSL.groupby(['SPOT']):
56 64 latitude = group.LAT.values
57 65 longitude = group.LON.values
58 66 t = (group.TIME.values - dt) / diff
59   - x,y = m(longitude, latitude)
60   - cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  67 + x,y = m(longitude, latitude)
  68 + cax = plt.scatter(x,y,c=t, s=
  69 + 35, cmap=cmap,linewidth=0,vmin=0, vmax=1)
61 70 plt.plot(x,y,'k-',linewidth=0.5)
62   -
  71 +
63 72 # colorbar
64 73 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
65   -cbar.set_ticks([0,0.2,0.4,0.6,0.8,1])
  74 +cbar.set_ticks([0,0.25,0.5,0.75,1])
66 75 cbar.update_ticks()
67   -cbar.ax.set_yticklabels(['5','4','3','2','1','0'])
68   -cbar.set_label('jours', rotation=270)
  76 +cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  77 +cbar.set_label('heures', rotation=270,labelpad=15)
69 78  
70 79 # legende
71   -plt.annotate(strtime + ' UTC', xy=(1, 1), xycoords='data', size=20,
72   - xytext=(0.55, 0.1), textcoords='axes fraction',
  80 +plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
  81 + xytext=(0.6, 0.87), textcoords='axes fraction',
73 82 horizontalalignment='right', verticalalignment='top')
74   -plt.title(str(dd) + " derniers jours de derive de surface (BDC)")
75   -# enregistrement
76   -plt.savefig('/home/nicopa01/data/spot/suivi/BDC/BDC' + str(dd) + '_' + nametime + '.png',dpi=300)
  83 +plt.title("Derive de surface (" + str(snake) + " dernieres heures)")
  84 +#enregistrement
  85 +plt.savefig('/home/nicopa01/data/spot/suivi/GSL/GSL_' + nametime + '.png',dpi=300)
  86 +plt.close()
  87 +
  88 +
77 89  
78 90  
79 91 # Estuaire du Saint-Laurent ---------------------------
80 92 # traces des x derniers jours dans l'estuaire
81 93 SLE = df[(df.SPOT > 1) & (df.SPOT < 300) & (df.FLAG == "OCN")
82   - & (df.TIME > dt) | (df.SPOT > 899) & (df.FLAG == "OCN")
83   - & (df.TIME > dt)]
  94 + & (df.TIME <= timestamp) & (df.TIME > timestamp - shour*snake)]
84 95  
85 96 plt.clf()
86 97 fig, ax = plt.subplots()
... ... @@ -95,9 +106,9 @@ m.drawmapboundary(fill_color=&#39;lightblue&#39;) # fill to edge
95 106 m.drawcountries()
96 107 m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
97 108 m.drawrivers()
98   -m.drawcoastlines(linewidth=0.8)
99   -m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0])
100   -m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1])
  109 +m.drawcoastlines(linewidth=0.7)
  110 +m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
  111 +m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
101 112  
102 113 # trace les chemins de bouees
103 114 for spot, group in SLE.groupby(['SPOT']):
... ... @@ -107,64 +118,68 @@ for spot, group in SLE.groupby([&#39;SPOT&#39;]):
107 118 x,y = m(longitude, latitude)
108 119 cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
109 120 plt.plot(x,y,'k-',linewidth=0.5)
110   -
  121 +
111 122 # colorbar
112 123 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
113   -cbar.set_ticks([0,0.2,0.4,0.6,0.8,1])
  124 +cbar.set_ticks([0,0.25,0.5,0.75,1])
114 125 cbar.update_ticks()
115   -cbar.ax.set_yticklabels(['5','4','3','2','1','0'])
116   -cbar.set_label('jours', rotation=270)
  126 +cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  127 +cbar.set_label('heures', rotation=270,labelpad=15)
117 128  
118 129 # legende
119   -plt.annotate(strtime + ' UTC', xy=(1, 1), xycoords='data', size=20,
  130 +plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
120 131 xytext=(0.9, 0.1), textcoords='axes fraction',
121 132 horizontalalignment='right', verticalalignment='top')
122   -plt.title(str(dd) + " derniers jours de derive de surface (SLE)")
  133 +plt.title("Derive de surface (" + str(snake) + " dernieres heures)")
123 134 #enregistrement
124   -plt.savefig('/home/nicopa01/data/spot/suivi/SLE/SLE' + str(dd) + '_' + nametime + '.png',dpi=300)
125   -
126   -
127   -# Old Harry ---------------------------
128   -# traces des x derniers jours autour de Old Harry
129   -OHA = df[(df.FLAG == "OCN") & (df.TIME > dt)]
  135 +plt.savefig('/home/nicopa01/data/spot/suivi/SLE/SLE_' + nametime + '.png',dpi=300)
  136 +plt.close()
  137 +
  138 +
  139 +# Baie des chaleurs ---------------------------
  140 +# traces des x derniers jours dans la baie
  141 +BDC = df[(df.SPOT > 699) & (df.FLAG == "OCN")
  142 + & (df.TIME <= timestamp) & (df.TIME > timestamp - shour*snake)]
130 143  
131 144 plt.clf()
132 145 fig, ax = plt.subplots()
133 146  
134 147 # caracteristiques de la carte
135   -m = Basemap(projection='stere',lon_0=-60.5,lat_0=49,\
136   - llcrnrlat=47.1,urcrnrlat=51.2,\
137   - llcrnrlon=-62.9,urcrnrlon=-56.2,\
  148 +m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
  149 + llcrnrlat=47.5,urcrnrlat=48.7,\
  150 + llcrnrlon=-66.9,urcrnrlon=-64.2,\
138 151 rsphere=6371.2,resolution='h')
139 152  
140 153 m.drawmapboundary(fill_color='lightblue') # fill to edge
141 154 m.drawcountries()
142 155 m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
143 156 m.drawrivers()
144   -m.drawcoastlines(linewidth=0.8)
145   -m.drawparallels(np.arange(40,60,1),labels=[1,0,0,0])
146   -m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1])
  157 +m.drawcoastlines(linewidth=0.7)
  158 +m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
  159 +m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
147 160  
148 161 # trace les chemins de bouees
149 162 for spot, group in BDC.groupby(['SPOT']):
150 163 latitude = group.LAT.values
151 164 longitude = group.LON.values
152 165 t = (group.TIME.values - dt) / diff
153   - x,y = m(longitude, latitude)
  166 + x,y = m(longitude, latitude)
154 167 cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
155 168 plt.plot(x,y,'k-',linewidth=0.5)
156   -
  169 +
157 170 # colorbar
158 171 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
159   -cbar.set_ticks([0,0.2,0.4,0.6,0.8,1])
  172 +cbar.set_ticks([0,0.25,0.5,0.75,1])
160 173 cbar.update_ticks()
161   -cbar.ax.set_yticklabels(['5','4','3','2','1','0'])
162   -cbar.set_label('jours', rotation=270)
  174 +cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  175 +cbar.set_label('heures', rotation=270,labelpad=15)
163 176  
164 177 # legende
165   -plt.annotate(strtime + ' UTC', xy=(1, 1), xycoords='data', size=20,
166   - xytext=(0.92, 0.1), textcoords='axes fraction',
167   - horizontalalignment='right', verticalalignment='top')
168   -plt.title(str(dd) + " derniers jours de derive de surface (BDC)")
169   -# enregistrement
170   -plt.savefig('/home/nicopa01/data/spot/suivi/OHA/OHA' + str(dd) + '_' + nametime + '.png',dpi=300)
  178 +plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
  179 + xytext=(0.6, 0.1), textcoords='axes fraction',
  180 + horizontalalignment='right', verticalalignment='top')
  181 +
  182 +plt.title("Derive de surface (" + str(snake) + " dernieres heures)")
  183 +#enregistrement
  184 +plt.savefig('/home/nicopa01/data/spot/suivi/BDC/BDC_' + nametime + '.png',dpi=300)
  185 +plt.close()
... ...