Commit 0a12a48da279c0c7a603595a4acb7df9c6739673

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

production de carte pour les dates anterieurs

m Veuille le message de validation pour vos modifications. Les lignes
Showing 1 changed file with 318 additions and 0 deletions   Show diff stats
tr_snake_old.py 0 → 100755
... ... @@ -0,0 +1,318 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +
  4 +# produit des cartes des trajectoires des spots dans des zones choisies
  5 +# entre 2 dates a intervale de temps reglables.
  6 +
  7 +from mpl_toolkits.basemap import Basemap
  8 +from time import gmtime, strftime
  9 +import matplotlib.pyplot as plt
  10 +import time
  11 +import datetime
  12 +import numpy as np
  13 +import pandas as pd
  14 +from mpl_toolkits.axes_grid1 import make_axes_locatable
  15 +
  16 +# parametres modifiables --------------------------
  17 +region = 'BDC' # region (GSL / OHA / BDC / SLE)
  18 +
  19 +day0 = 20150929 # jour de la premiere carte (fmt = YYYYMMDD)
  20 +h = 2 # intervalle de temps entre les cartes (h)
  21 +day1 = 20151001 # jour de la derniere carte (fmt = YYYYMMDD)
  22 +
  23 +start = 20150611 # date de debut de suivi de la saison
  24 +
  25 +snake = 36 # nombre d'heure de suivi du serpent
  26 +# ================================================
  27 +
  28 +ts = str(day0)
  29 +t0 = int(time.mktime(datetime.datetime.strptime(ts, "%Y%m%d").timetuple()))
  30 +
  31 +tt = str(day1)
  32 +t1 = int(time.mktime(datetime.datetime.strptime(tt, "%Y%m%d").timetuple()))
  33 +
  34 +tst = str(start)
  35 +tS = int(time.mktime(datetime.datetime.strptime(tst, "%Y%m%d").timetuple()))
  36 +
  37 +sday = 84600
  38 +shour = 3600
  39 +tint = shour * h
  40 +
  41 +
  42 +# colormap
  43 +cmap=plt.get_cmap('OrRd')
  44 +lab1 = int(snake)
  45 +lab2 = int(snake*0.75)
  46 +lab3 = int(snake*0.5)
  47 +lab4 = int(snake*0.25)
  48 +lab5 = 0
  49 +
  50 +# Base de donnees ----------------------------
  51 +df = pd.read_csv('/home/nicopa01/data/spot/spots_pos_flag_clean.csv',delimiter=';')
  52 +df = df.drop_duplicates(take_last=True)
  53 +
  54 +
  55 +for x in xrange(t0, t1, tint):
  56 +
  57 + timestamp = x # temps unix
  58 + dt = timestamp - shour * snake # heure de debut de suivi
  59 + diff = timestamp - dt # intervale de suivi
  60 +
  61 + strtime = datetime.datetime.fromtimestamp(int(x)).strftime('%Y-%m-%d %H:%M')
  62 +
  63 + startt = datetime.datetime.fromtimestamp(int(tS)).strftime('%Y-%m-%d %H:%M')
  64 +
  65 + nametime = datetime.datetime.fromtimestamp(int(x)).strftime('%Y%m%d%H%M')
  66 +
  67 + if region == 'SLE':
  68 +
  69 + # Estuaire du Saint-Laurent ---------------------------
  70 + # traces des x derniers jours dans l'estuaire
  71 + SLE = df.loc[(df.FLAG == "OCN")
  72 + & (df.TIME <= x) & (df.TIME > x - shour*snake)]
  73 +
  74 + # trace depuis le debut de l'ete
  75 + SLE_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= x)
  76 + & (df.TIME > tS)]
  77 +
  78 + fig, ax = plt.subplots()
  79 +
  80 + # caracteristiques de la carte
  81 + m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
  82 + llcrnrlat=47.8,urcrnrlat=49.5,\
  83 + llcrnrlon=-70,urcrnrlon=-67,\
  84 + rsphere=6371.2,resolution='h')
  85 +
  86 + m.drawmapboundary(fill_color='lightblue') # fill to edge
  87 + m.drawcountries()
  88 + m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
  89 + m.drawrivers()
  90 + m.drawcoastlines(linewidth=0.8)
  91 + m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
  92 + m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
  93 +
  94 +
  95 + for spot, group in SLE_start.groupby(['SPOT']):
  96 + lat = group.LAT.values
  97 + lon = group.LON.values
  98 + x,y = m(lon, lat)
  99 + cax = plt.plot(x,y,color='0.35',linewidth=0.7)
  100 +
  101 + # trace les chemins de bouees
  102 + for spot, group in SLE.groupby(['SPOT']):
  103 + latitude = group.LAT.values
  104 + longitude = group.LON.values
  105 + t = (group.TIME.values - float(dt)) / diff
  106 + x,y = m(longitude, latitude)
  107 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  108 +
  109 + # colorbar
  110 + cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
  111 + cbar.set_ticks([0,0.25,0.5,0.75,1])
  112 + cbar.update_ticks()
  113 + cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  114 + cbar.set_label('heures', rotation=270,labelpad=15)
  115 +
  116 +
  117 + # legende
  118 + plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
  119 + xytext=(0.9, 0.1), textcoords='axes fraction',
  120 + horizontalalignment='right', verticalalignment='top')
  121 + plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
  122 + #enregistrement
  123 + #plt.savefig('/home/nicopa01/data/spot/suivi/SLE/SLE5_' + nametime + '.png',dpi=300)
  124 + plt.savefig('/home/nicopa01/data/spot/suivi/SLE/SLE_' + nametime + '.jpg',dpi=300)
  125 + plt.close()
  126 +
  127 + if region == 'BDC':
  128 +
  129 + bdc = df.loc[(df.SPOT == 24) | (df.SPOT == 23) | (df.SPOT == 52) |
  130 + (df.SPOT == 53) | (df.SPOT >= 700) & (df.SPOT < 899)]
  131 +
  132 + # Baie des chaleurs ---------------------------
  133 + # traces des x derniers jours dans la baie
  134 + BDC = bdc.loc[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > x - shour*snake)]
  135 +
  136 + # selectionne les positions depuis le debut de l'ete
  137 + BDC_start = bdc.loc[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > tS)]
  138 +
  139 + n = bdc.loc[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > tS)]
  140 + number = str(n.TIME.count())
  141 +
  142 + fig, ax = plt.subplots()
  143 +
  144 + # caracteristiques de la carte
  145 + m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
  146 + llcrnrlat=47.5,urcrnrlat=48.9,\
  147 + llcrnrlon=-66.9,urcrnrlon=-63.8,\
  148 + rsphere=6371.2,resolution='h')
  149 +
  150 + m.drawmapboundary(fill_color='lightblue') # fill to edge
  151 + m.drawcountries()
  152 + m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
  153 + m.drawrivers()
  154 + m.drawcoastlines(linewidth=0.8)
  155 + m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
  156 + m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
  157 +
  158 + # trace depuis le début de l'ete
  159 + for spot, group in BDC_start.groupby(['SPOT']):
  160 + lat = group.LAT.values
  161 + lon = group.LON.values
  162 + x,y = m(lon, lat)
  163 + plt.plot(x,y,color='0.35',linewidth=0.7)
  164 +
  165 + # trace les chemins de bouees
  166 + for spot, group in BDC.groupby(['SPOT']):
  167 + latitude = group.LAT.values
  168 + longitude = group.LON.values
  169 + t = (group.TIME.values - float(dt)) / diff
  170 + x,y = m(longitude, latitude)
  171 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  172 +
  173 + # colorbar
  174 + cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
  175 + cbar.set_ticks([0,0.25,0.5,0.75,1])
  176 + cbar.update_ticks()
  177 + cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  178 + cbar.set_label('heures', rotation=270,labelpad=15)
  179 +
  180 +
  181 + # legende
  182 + plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
  183 + xytext=(0.6, 0.1), textcoords='axes fraction',
  184 + horizontalalignment='right', verticalalignment='top')
  185 +
  186 + plt.annotate(number + ' positions depuis le ' + startt, xy=(1, 1),
  187 + xycoords='data', size=13,
  188 + xytext=(0.68, 0.9), textcoords='axes fraction',
  189 + horizontalalignment='right', verticalalignment='top')
  190 +
  191 + plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
  192 + #enregistrement
  193 + #plt.savefig('/home/nicopa01/data/spot/suivi/BDC/BDC_' + nametime + '.png',dpi=300)
  194 + plt.savefig('/home/nicopa01/data/spot/suivi/BDC/BDC_' + nametime + '.jpg',dpi=300)
  195 + plt.close()
  196 +
  197 + if region == 'GSL':
  198 +
  199 + # Estuaire du Saint-Laurent ---------------------------
  200 + # traces des x derniers jours dans l'estuaire
  201 + GSL = df[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > dt)]
  202 +
  203 + GSL_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > tS)]
  204 +
  205 + n = df.loc[(df.FLAG == "OCN") & (df.TIME <= x) & (df.TIME > tS)]
  206 + number = str(n.TIME.count())
  207 +
  208 + fig, ax = plt.subplots()
  209 +
  210 + # caracteristiques de la carte
  211 +
  212 +
  213 + m = Basemap(projection='stere',lon_0=-64.5,lat_0=48,\
  214 + llcrnrlat=45.2,urcrnrlat=51.6,\
  215 + llcrnrlon=-70,urcrnrlon=-56.5,\
  216 + rsphere=6371.2,resolution='h')
  217 +
  218 + m.drawmapboundary(fill_color='lightblue') # fill to edge
  219 + m.drawcountries()
  220 + m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
  221 + m.drawrivers()
  222 + m.drawcoastlines(linewidth=0.8)
  223 + m.drawparallels(np.arange(40,60,2),labels=[1,0,0,0],linewidth=0.0)
  224 + m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1],linewidth=0.0)
  225 +
  226 + # trace depuis le début de l'ete
  227 + for spot, group in GSL_start.groupby(['SPOT']):
  228 + lat = group.LAT.values
  229 + lon = group.LON.values
  230 + x,y = m(lon, lat)
  231 + plt.plot(x,y,color='0.35',linewidth=0.7)
  232 +
  233 + # trace les chemins de bouees
  234 + for spot, group in GSL.groupby(['SPOT']):
  235 + latitude = group.LAT.values
  236 + longitude = group.LON.values
  237 + t = (group.TIME.values - float(dt)) / diff
  238 + x,y = m(longitude, latitude)
  239 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  240 + plt.plot(x,y,'k-',linewidth=0.5)
  241 +
  242 + # colorbar
  243 + cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
  244 + cbar.set_ticks([0,0.25,0.5,0.75,1])
  245 + cbar.update_ticks()
  246 + cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  247 + cbar.set_label('heures', rotation=270,labelpad=15)
  248 +
  249 + # legende
  250 + plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
  251 + xytext=(0.9, 0.1), textcoords='axes fraction',
  252 + horizontalalignment='right', verticalalignment='top')
  253 +
  254 + plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
  255 + #enregistrement
  256 + #plt.savefig('/home/nicopa01/data/spot/suivi/GSL/GSL_' + nametime + '.png',dpi=300)
  257 + plt.savefig('/home/nicopa01/data/spot/suivi/GSL/GSL_' + nametime + '.jpg',dpi=300)
  258 + plt.close()
  259 +
  260 + if region == 'OHA':
  261 +
  262 + # Estuaire du Saint-Laurent ---------------------------
  263 + # traces des x derniers jours dans l'estuaire
  264 + OHA = df[(df.FLAG == "OCN")
  265 + & (df.TIME <= x) & (df.TIME > x - shour*snake)]
  266 +
  267 + OHA_start = df.loc[(df.FLAG == "OCN")
  268 + & (df.TIME <= x) & (df.TIME > tS)]
  269 +
  270 + fig, ax = plt.subplots()
  271 +
  272 + # caracteristiques de la carte
  273 + m = Basemap(projection='stere',lon_0=-60,lat_0=49,\
  274 + llcrnrlat=47,urcrnrlat=51.5,\
  275 + llcrnrlon=-63.8,urcrnrlon=-56.8,\
  276 + rsphere=6371.2,resolution='h')
  277 +
  278 + m.drawmapboundary(fill_color='lightblue') # fill to edge
  279 + m.drawcountries()
  280 + m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
  281 + m.drawrivers()
  282 + m.drawcoastlines(linewidth=0.8)
  283 + m.drawparallels(np.arange(40,60,2),labels=[1,0,0,0],linewidth=0.0)
  284 + m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1],linewidth=0.0)
  285 +
  286 + # trace depuis le début de l'ete
  287 + for spot, group in OHA_start.groupby(['SPOT']):
  288 + lat = group.LAT.values
  289 + lon = group.LON.values
  290 + x,y = m(lon, lat)
  291 + plt.plot(x,y,color='0.35',linewidth=0.7)
  292 +
  293 + # trace les chemins de bouees
  294 + for spot, group in OHA.groupby(['SPOT']):
  295 + latitude = group.LAT.values
  296 + longitude = group.LON.values
  297 + t = (group.TIME.values - float(dt)) / diff
  298 + x,y = m(longitude, latitude)
  299 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  300 +
  301 + # colorbar
  302 + cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
  303 + cbar.set_ticks([0,0.25,0.5,0.75,1])
  304 + cbar.update_ticks()
  305 + cbar.ax.set_yticklabels([lab1,lab2,lab3,lab4,lab5])
  306 + cbar.set_label('heures', rotation=270,labelpad=15)
  307 +
  308 + # legende
  309 + plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=16,
  310 + xytext=(0.55, 0.9), textcoords='axes fraction',
  311 + horizontalalignment='right', verticalalignment='top')
  312 + plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
  313 + #enregistrement
  314 + #plt.savefig('/home/nicopa01/data/spot/suivi/OHA/OHA_' + nametime + '.png',dpi=300)
  315 + plt.savefig('/home/nicopa01/data/spot/suivi/OHA/OHA_' + nametime + '.jpg',dpi=300)
  316 + plt.close()
  317 +
  318 +
... ...