Commit c12a5b3b33358030415d77e331e160728054c531

Authored by Dany Dumont
2 parents f6e4d1a4 34a1af0f
Exists in master

mise a jour de tr_sort sur mingan

Showing 3 changed files with 386 additions and 226 deletions   Show diff stats
tr_position.py
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 #! python 2 #! python
3 3
  4 +"""
  5 + SPOT position recovery from internet.
  6 + Positions are also flagged if they are in water/land or onboard
  7 +
  8 +"""
  9 +
4 import sys 10 import sys
5 import xml.dom.minidom as minidom 11 import xml.dom.minidom as minidom
6 import urllib 12 import urllib
7 import math 13 import math
8 import csv 14 import csv
9 import fiona 15 import fiona
  16 +import pandas as pd
10 import shapely.geometry 17 import shapely.geometry
11 from time import localtime, strftime, ctime 18 from time import localtime, strftime, ctime
12 19
13 -# 20 +# debug pour le protocole ssl
  21 +import ssl
  22 +from functools import wraps
  23 +def sslwrap(func):
  24 + @wraps(func)
  25 + def bar(*args, **kw):
  26 + kw['ssl_version'] = ssl.PROTOCOL_TLSv1
  27 + return func(*args, **kw)
  28 + return bar
  29 +
  30 +ssl.wrap_socket = sslwrap(ssl.wrap_socket)
  31 +
  32 +#==================================================
14 #Liste globale contenant tous les objets 33 #Liste globale contenant tous les objets
15 #instancies a partir de la classe Spot 34 #instancies a partir de la classe Spot
16 -# 35 +#==================================================
17 36
18 spots = [] 37 spots = []
19 38
20 class Spot: 39 class Spot:
21 - '''Classe pour les GPS SPOT'''  
22 - spotCount=0  
23 - rayonTerre = 6371.0 # Rayon moyen de la terre  
24 -  
25 - distancePlusPres = 100000000.0 # Init a 1 million de km !  
26 - capPlusPres = 0.0  
27 - identPlusPres = 0  
28 - parentPlusPres = 0  
29 - ecartDistance = 0  
30 -  
31 - spotPlusPres = None  
32 - dejaTraite = False  
33 -  
34 - def __init__(self,esnName):  
35 - self.esnName = esnName  
36 - Spot.spotCount += 1  
37 -  
38 - def setEsn(self,esn):  
39 - self.esn = esn  
40 -  
41 - def setTimestamp(self, timestamp):  
42 - self.timestamp = timestamp  
43 -  
44 - def setTimeGMT(self, timeGMT):  
45 - self.timeGMT = int(timeGMT)  
46 -  
47 - def setTimeStampEST(self, timeGMT):  
48 - self.timeStampEST = ctime(int(timeGMT))  
49 -  
50 - def setLatitude(self,latitude):  
51 - self.latitude = float(latitude)  
52 -  
53 - def setLongitude(self, longitude):  
54 - self.longitude = float(longitude)  
55 -  
56 - def setMessageType(self, messagetype):  
57 - self.messagetype = messagetype  
58 -  
59 - def setFlag(self, flag): 40 + """
  41 + Classe pour les GPS SPOT
  42 + """
  43 + spotCount=0
  44 + rayonTerre = 6371.0 # Rayon moyen de la terre
  45 +
  46 + distancePlusPres = 100000000.0 # Init a 1 million de km !
  47 + capPlusPres = 0.0
  48 + identPlusPres = 0
  49 + parentPlusPres = 0
  50 + ecartDistance = 0
  51 +
  52 + spotPlusPres = None
  53 + dejaTraite = False
  54 +
  55 + def __init__(self,esnName):
  56 + self.esnName = esnName
  57 + Spot.spotCount += 1
  58 +
  59 + def setEsn(self,esn):
  60 + self.esn = esn
  61 +
  62 + def setTimestamp(self, timestamp):
  63 + self.timestamp = timestamp
  64 +
  65 + def setTimeGMT(self, timeGMT):
  66 + self.timeGMT = int(timeGMT)
  67 +
  68 + def setTimeStampEST(self, timeGMT):
  69 + self.timeStampEST = ctime(int(timeGMT))
  70 +
  71 + def setLatitude(self,latitude):
  72 + self.latitude = float(latitude)
  73 +
  74 + def setLongitude(self, longitude):
  75 + self.longitude = float(longitude)
  76 +
  77 + def setMessageType(self, messagetype):
  78 + self.messagetype = messagetype
  79 +
  80 + def setFlag(self, flag):
60 self.flag = flag 81 self.flag = flag
61 -  
62 - 82 +
  83 +
63 84
64 ############################################################# 85 #############################################################
65 # 86 #
66 #Lecture du fichier XML contenant les information des spots et 87 #Lecture du fichier XML contenant les information des spots et
67 #Instanciation de tous les objets Spot a partir de ces info. 88 #Instanciation de tous les objets Spot a partir de ces info.
68 # 89 #
69 -#A la sortie de cette fonction, la liste globale spots[] contient tous 90 +#A la sortie de cette fonction, la liste globale spots[] contient
70 #tous les spots necessaires au traitement 91 #tous les spots necessaires au traitement
71 # 92 #
72 ############################################################# 93 #############################################################
73 94
74 def getTags(url): 95 def getTags(url):
75 - """  
76 - Initialiser tous les spots a partir du fichier XML  
77 - """ 96 + """
  97 + Initialiser tous les spots a partir du fichier XML
  98 + """
78 99
79 - doc = minidom.parse(urllib.urlopen(url))  
80 - node = doc.documentElement  
81 - messages = doc.getElementsByTagName("message") 100 + doc = minidom.parse(urllib.urlopen(url))
  101 + node = doc.documentElement
  102 + messages = doc.getElementsByTagName("message")
82 103
83 # Initialisation des listes de donnes 104 # Initialisation des listes de donnes
84 105
85 - esns = []  
86 - esnNames = []  
87 - timestamps = []  
88 - timeInGMTSeconds = []  
89 - latitudes = []  
90 - longitudes = []  
91 - messagetype = []  
92 - spottemp = [] 106 + esns = []
  107 + esnNames = []
  108 + timestamps = []
  109 + timeInGMTSeconds = []
  110 + latitudes = []
  111 + longitudes = []
  112 + messagetype = []
  113 + spottemp = []
93 114
94 # On boucle sur tous les tags messages du fichier XML 115 # On boucle sur tous les tags messages du fichier XML
95 # et on extrait les informations 116 # et on extrait les informations
96 117
97 - if len(messages) == 0:  
98 - sys.exit(1)  
99 -  
100 - for message in messages:  
101 - esnObj = message.getElementsByTagName("messengerId")[0]  
102 - esns.append(esnObj)  
103 - esnNameObj = message.getElementsByTagName("messengerName")[0]  
104 - esnNames.append(esnNameObj)  
105 - timestampObj = message.getElementsByTagName("dateTime")[0]  
106 - timestamps.append(timestampObj)  
107 - timeGMTObj = message.getElementsByTagName("unixTime")[0]  
108 - timeInGMTSeconds.append(timeGMTObj)  
109 - latObj = message.getElementsByTagName("latitude")[0]  
110 - latitudes.append(latObj)  
111 - lonObj = message.getElementsByTagName("longitude")[0]  
112 - longitudes.append(lonObj)  
113 - msgtypeObj = message.getElementsByTagName("messageType")[0]  
114 - messagetype.append(msgtypeObj) 118 + if len(messages) == 0:
  119 + sys.exit(1)
  120 +
  121 + for message in messages:
  122 + esnObj = message.getElementsByTagName("messengerId")[0]
  123 + esns.append(esnObj)
  124 + esnNameObj = message.getElementsByTagName("messengerName")[0]
  125 + esnNames.append(esnNameObj)
  126 + timestampObj = message.getElementsByTagName("dateTime")[0]
  127 + timestamps.append(timestampObj)
  128 + timeGMTObj = message.getElementsByTagName("unixTime")[0]
  129 + timeInGMTSeconds.append(timeGMTObj)
  130 + latObj = message.getElementsByTagName("latitude")[0]
  131 + latitudes.append(latObj)
  132 + lonObj = message.getElementsByTagName("longitude")[0]
  133 + longitudes.append(lonObj)
  134 + msgtypeObj = message.getElementsByTagName("messageType")[0]
  135 + messagetype.append(msgtypeObj)
115 136
116 137
117 #On instancie une liste temporaire d'objets de classe Spot 138 #On instancie une liste temporaire d'objets de classe Spot
118 #qui contient l'information de tous les spots 139 #qui contient l'information de tous les spots
119 - for esnName in esnNames:  
120 - nodes = esnName.childNodes  
121 - for node in nodes:  
122 - spottemp.append(Spot(node.data)) 140 + for esnName in esnNames:
  141 + nodes = esnName.childNodes
  142 + for node in nodes:
  143 + spottemp.append(Spot(node.data))
123 144
124 #On conserve l'info dans chaque objet 145 #On conserve l'info dans chaque objet
125 146
126 - for i,s in enumerate(spottemp):  
127 - nodes = esns[i].childNodes  
128 - for node in nodes:  
129 - s.setEsn(node.data)  
130 - nodes = timestamps[i].childNodes  
131 - for node in nodes:  
132 - s.setTimestamp(node.data)  
133 - nodes = timeInGMTSeconds[i].childNodes  
134 - for node in nodes:  
135 - s.setTimeGMT(node.data)  
136 - s.setTimeStampEST(node.data)  
137 - nodes = latitudes[i].childNodes  
138 - for node in nodes:  
139 - s.setLatitude(node.data)  
140 - nodes = longitudes[i].childNodes  
141 - for node in nodes:  
142 - s.setLongitude(node.data)  
143 - nodes = messagetype[i].childNodes  
144 - for node in nodes:  
145 - s.setMessageType(node.data) 147 + for i,s in enumerate(spottemp):
  148 + nodes = esns[i].childNodes
  149 + for node in nodes:
  150 + s.setEsn(node.data)
  151 + nodes = timestamps[i].childNodes
  152 + for node in nodes:
  153 + s.setTimestamp(node.data)
  154 + nodes = timeInGMTSeconds[i].childNodes
  155 + for node in nodes:
  156 + s.setTimeGMT(node.data)
  157 + s.setTimeStampEST(node.data)
  158 + nodes = latitudes[i].childNodes
  159 + for node in nodes:
  160 + s.setLatitude(node.data)
  161 + nodes = longitudes[i].childNodes
  162 + for node in nodes:
  163 + s.setLongitude(node.data)
  164 + nodes = messagetype[i].childNodes
  165 + for node in nodes:
  166 + s.setMessageType(node.data)
146 167
147 # 168 #
148 #On produit une liste unique des identifiants des spots 169 #On produit une liste unique des identifiants des spots
149 # 170 #
150 - spotlist = sorted(set([s.esnName for s in spottemp ])) 171 + spotlist = sorted(set([s.esnName for s in spottemp ]))
151 172
152 # 173 #
153 #On boucle sur la liste des identifiants uniques 174 #On boucle sur la liste des identifiants uniques
154 #et pour chaque spot on conserve la donnee la plus recente 175 #et pour chaque spot on conserve la donnee la plus recente
155 #(max timestamp) 176 #(max timestamp)
156 # 177 #
157 - for i in spotlist :  
158 - spotmax = None  
159 - for s in spottemp :  
160 - if s.esnName == i:  
161 - if spotmax == None:  
162 - spotmax = s  
163 - if int(s.timeGMT) > int(spotmax.timeGMT) :  
164 - spotmax = s 178 + for i in spotlist :
  179 + spotmax = None
  180 + for s in spottemp :
  181 + if s.esnName == i:
  182 + if spotmax == None:
  183 + spotmax = s
  184 + if int(s.timeGMT) > int(spotmax.timeGMT) :
  185 + spotmax = s
165 186
166 - spots.append(spotmax) 187 + spots.append(spotmax)
167 188
168 # 189 #
169 #Rendu ici, la liste spots contient une entree par spot 190 #Rendu ici, la liste spots contient une entree par spot
@@ -173,42 +194,35 @@ def getTags(url): @@ -173,42 +194,35 @@ def getTags(url):
173 194
174 ############################################################ 195 ############################################################
175 # 196 #
176 -# implemente les positions des spots dans le csv 197 +# implemente les positions des spots dans le csv
177 # 198 #
178 ############################################################ 199 ############################################################
179 200
180 def ecrirecsv(fichier) : 201 def ecrirecsv(fichier) :
181 -  
182 - f = open(fichier, "ab") 202 + """
  203 + Creation of a temporary csv file from SPOT class
  204 + """
  205 +
  206 + # cree un fichier temporaire de spots_pos
  207 + f = open(fichier, "w")
183 writer = csv.writer(f,delimiter=';') 208 writer = csv.writer(f,delimiter=';')
  209 + writer.writerow(['SPOT','LAT','LON','TIME','STATUS','FLAG'])
184 210
185 - # charge le shapefile du trait de cote du GSL  
186 - s = fiona.open("/home/nicopa01/data/spot/shp/GSL_GSHHS_f.shp")  
187 - shapefile_record = s.next()  
188 - shape = shapely.geometry.asShape(shapefile_record['geometry'])  
189 - x_min, y_min, x_max, y_max = shape.bounds  
190 -  
191 for k in spots: 211 for k in spots:
192 - point = shapely.geometry.Point(k.longitude,k.latitude)  
193 -  
194 - if shape.contains(point):  
195 - k.flag = "LND"  
196 - else:  
197 - k.flag = "OCN"  
198 -  
199 - if (k.longitude < x_min) or (k.longitude > x_max) \  
200 - or (k.latitude < y_min) or (k.latitude > y_max):  
201 - k.flag = "OUT"  
202 -  
203 - data = [ str(k.esnName), float(k.latitude), float(k.longitude), int(k.timeGMT), str(k.messagetype), str(k.flag)]  
204 -  
205 - writer.writerow(data)  
206 212
  213 + k.flag = "FLG"
  214 + data = [ str(k.esnName), float(k.latitude), float(k.longitude),\
  215 + int(k.timeGMT), str(k.messagetype), str(k.flag)]
  216 + writer.writerow(data)
207 f.close 217 f.close
208 218
209 def cleancsv(fichier_clean) : 219 def cleancsv(fichier_clean) :
  220 + """
  221 + Nettoyage du csv (suppression des doublons)
  222 + """
  223 +
210 # nettoyage des doublons 224 # nettoyage des doublons
211 - with open('/home/nicopa01/data/spot/spots_pos.csv','r') as in_file,\ 225 + with open('/share/archives/partage_lasso/spot/spots_pos_flag.csv','r') as in_file,\
212 open(fichier_clean,'w') as out_file: 226 open(fichier_clean,'w') as out_file:
213 seen = set() 227 seen = set()
214 for line in in_file: 228 for line in in_file:
@@ -216,22 +230,121 @@ def cleancsv(fichier_clean) : @@ -216,22 +230,121 @@ def cleancsv(fichier_clean) :
216 seen.add(line) 230 seen.add(line)
217 out_file.write(line) 231 out_file.write(line)
218 232
  233 +def flagcsv(fichier_flag) :
  234 + """
  235 + marquage des positions
  236 + """
  237 +
  238 + # lit le fichier des positions flaguees
  239 + df = pd.read_csv(fichier_flag,delimiter=';')
  240 + df = df.drop_duplicates(take_last=True)
  241 +
  242 + # lit le fichier des dernieres positions crees dans 'ecrirecsv'
  243 + tmp = pd.read_csv('/share/archives/partage_lasso/spot/tmp.csv',delimiter=';')
  244 +
  245 + # charge le shapefile du trait de cote du GSL
  246 + s = fiona.open("/share/archives/nicp0003/spot/shp/GSL_GSHHS_f.shp")
  247 + shapefile_record = s.next()
  248 + shape = shapely.geometry.asShape(shapefile_record['geometry'])
  249 + x_min, y_min, x_max, y_max = shape.bounds
  250 + rayonTerre = 6371.0
  251 +
  252 + #
  253 + for index,val in tmp.iterrows():
  254 + LON = val['LON']
  255 + LAT = val['LAT']
  256 + T = val['TIME']
  257 + SPT = val['SPOT']
  258 + STA = val['STATUS']
  259 +
  260 + # avant-dernieres positions des spots
  261 + T1 = df.loc[(df['SPOT'] == SPT)\
  262 + & (df['TIME'] < T), 'TIME'][-1:].values
  263 +
  264 + LAT1 = df.loc[(df['SPOT'] == SPT)\
  265 + & ((df['TIME'] < T)), 'LAT'][-1:].values
  266 +
  267 + LON1 = df.loc[(df['SPOT'] == SPT)\
  268 + & ((df['TIME'] < T)), 'LON'][-1:].values
  269 +
  270 +
  271 + if not LAT1:
  272 + LAT1 = LAT
  273 + if not LON1:
  274 + LON1 = LON
  275 + if not T1:
  276 + T1 = T
  277 +
  278 + lat1 = math.radians(LAT)
  279 + lon1 = math.radians(LON)
  280 + tim1 = T
  281 + lat2 = math.radians(LAT1)
  282 + lon2 = math.radians(LON1)
  283 + tim2 = T1
  284 + dlat = math.radians(LAT1 - LAT)
  285 + dlon = math.fabs(math.radians(LON1 - LON))
  286 +
  287 + dPhi = math.log(math.tan(lat2/2+math.pi/4)/math.tan(lat1/2+math.pi/4))
  288 +
  289 + if dPhi <> 0 :
  290 + q = dlat/dPhi
  291 + else :
  292 + q = math.cos(lat1)
  293 +
  294 + #if dLon > 180 degres take shorter rhumb across anti-meridian:
  295 + if math.fabs(dlon) > math.pi :
  296 + if dlon > 0 :
  297 + dlon= -(2*math.pi - dlon)
  298 + else:
  299 + dlon = (2*math.pi + dlon)
  300 +
  301 + dist = math.sqrt(dlat*dlat + q*q*dlon*dlon) * rayonTerre
  302 +
  303 + # si distance non nulle (s'il y a une position anterieur du spot)
  304 + # calcul de la vitesse par rapport a la derniere position connue
  305 + if not dist == 0:
  306 + vitesse = (dist * 1000) / abs((tim2 - tim1)) # m.s-1
  307 + # si vitesse > 1.1 m.s (sur bateau par exemple)
  308 + if vitesse > 1.1:
  309 + val.FLAG = "SPD"
  310 + else:
  311 + val.FLAG = "OCN"
  312 +
  313 + # si distance nulle = marque "NEW"
  314 + if dist == 0:
  315 + val.FLAG = "NEW"
  316 +
  317 + # si position a l'interieur du trait de cote = marque "LND"
  318 + point = shapely.geometry.Point(LON,LAT)
  319 + if shape.contains(point):
  320 + val.FLAG = "LND"
  321 +
  322 + # si LON / LAT incoherent = marque "OUT"
  323 + if (LON < x_min) or (LON > x_max) \
  324 + or (LAT < y_min) or (LAT > y_max):
  325 + val.FLAG = "OUT"
  326 +
  327 + # rajoute les positions flaguees au fichier final
  328 + f = open(fichier_flag, "ab")
  329 + writer = csv.writer(f,delimiter=';',lineterminator="\n")
  330 + data = [ str(SPT), float(round(LAT,6)), float(round(LON,6)), int(T), str(STA), str(val.FLAG)]
  331 + writer.writerow(data)
  332 + f.close
  333 +
219 334
220 ############################################################# 335 #############################################################
221 # 336 #
222 -# Debut du programme principal 337 +# Debut du programme principal
223 # 338 #
224 ############################################################# 339 #############################################################
225 340
226 if __name__ == "__main__": 341 if __name__ == "__main__":
227 -# url = ' http://share.findmespot.com/messageService/guestlinkservlet?glId=03kp21oFnOj8bRHaPQPPAjf2TuO19VRa3'  
228 - url = ' https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/0zgtS2Yrxgzl8in5LvVoAg0ae76LfQcdO/message.xml'  
229 -# positions = 'positions_mai_2013.xml'  
230 - getTags(url)  
231 -  
232 -ecrirecsv("/home/nicopa01/data/spot/spots_pos.csv")  
233 -cleancsv("/home/nicopa01/data/spot/spots_pos_clean.csv") 342 +# url = ' http://share.findmespot.com/messageService/guestlinkservlet?glId=03kp21oFnOj8bRHaPQPPAjf2TuO19VRa3'
  343 + url = ' https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/0zgtS2Yrxgzl8in5LvVoAg0ae76LfQcdO/message.xml'
  344 + getTags(url)
234 345
  346 +ecrirecsv("/share/archives/partage_lasso/spot/tmp.csv")
  347 +flagcsv("/share/archives/partage_lasso/spot/spots_pos_flag.csv")
  348 +cleancsv("/share/archives/partage_lasso/spot/spots_pos_flag_clean.csv")
235 349
236 sys.exit(0) 350 sys.exit(0)
237 -  
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
  4 +"""
  5 + Plot maps of the spots tracks, over different parts of the Gulf of St Lawrence.
  6 + Spot positions extract by the script tr_position.py.
  7 + -» map of the entire Gulf of St Lawrence
  8 + -» map of the St Lawrence Estuary
  9 + -» map of the Baie des Chaleurs
  10 +
  11 + the track are compiled from the selected date to the present, the last 48h are
  12 + ploted with a colorscale to better visualise the spot motion.
  13 +
  14 + Autor: Paul Nicot - UQAR-ISMER
  15 + Last updade: Dec 2015
  16 +
  17 +"""
  18 +
  19 +import matplotlib
  20 +matplotlib.use('Agg')
  21 +# for running without X server
4 from mpl_toolkits.basemap import Basemap 22 from mpl_toolkits.basemap import Basemap
5 from time import gmtime, strftime 23 from time import gmtime, strftime
6 import matplotlib.pyplot as plt 24 import matplotlib.pyplot as plt
@@ -10,12 +28,18 @@ import numpy as np @@ -10,12 +28,18 @@ import numpy as np
10 import pandas as pd 28 import pandas as pd
11 from mpl_toolkits.axes_grid1 import make_axes_locatable 29 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 30
13 -# parametres modifiables -------------------------- 31 +# Modifiable parameters
  32 +# ================================================
14 snake = 48 # nombre d'heure de suivi du serpent 33 snake = 48 # nombre d'heure de suivi du serpent
  34 +start = 20150609 # date de debut de suivi de la saison
15 35
16 -start = 20150611 # date de debut de suivi de la saison 36 +file_pos = '/share/archives/partage_lasso/spot/spots_pos_flag_clean.csv'
  37 +dir_carte = '/share/archives/partage_lasso/spot/carte'
17 # ================================================ 38 # ================================================
18 39
  40 +
  41 +# fixed parameters
  42 +#-------------------------------------------------
19 sday = 84600 43 sday = 84600
20 shour = 3600 44 shour = 3600
21 45
@@ -27,10 +51,10 @@ lab3 = int(snake*0.5) @@ -27,10 +51,10 @@ lab3 = int(snake*0.5)
27 lab4 = int(snake*0.25) 51 lab4 = int(snake*0.25)
28 lab5 = 0 52 lab5 = 0
29 53
30 -# Base de donnees ----------------------------  
31 -df = pd.read_csv('/home/nicopa01/data/spot/spots_pos_flag_clean.csv',delimiter=';')  
32 -df = df.drop_duplicates(take_last=True) 54 +# database
  55 +df = pd.read_csv(file_pos,delimiter=';')
33 56
  57 +# time paramters
34 timestamp = int(time.time()) 58 timestamp = int(time.time())
35 dt = timestamp - shour * snake 59 dt = timestamp - shour * snake
36 diff = timestamp - dt 60 diff = timestamp - dt
@@ -38,26 +62,30 @@ diff = timestamp - dt @@ -38,26 +62,30 @@ diff = timestamp - dt
38 strtime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M') 62 strtime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M')
39 nametime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y%m%d%H%M') 63 nametime = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y%m%d%H%M')
40 64
41 -# date de début de suivi 65 +# date of tracks's beginning
42 sT = str(start) 66 sT = str(start)
43 starT = int(time.mktime(datetime.datetime.strptime(sT, "%Y%m%d").timetuple())) 67 starT = int(time.mktime(datetime.datetime.strptime(sT, "%Y%m%d").timetuple()))
44 68
45 -# Golfe du Saint-Laurent ---------------------------  
46 -# traces des x derniers jours dans l'estuaire 69 +
  70 +#===================================================
  71 +# Gulf of St Lawrence tracks map
  72 +#===================================================
  73 +
  74 +# selection of the reliable positions
47 GSL = df[(df.FLAG == "OCN") & (df.TIME <= timestamp) 75 GSL = df[(df.FLAG == "OCN") & (df.TIME <= timestamp)
48 & (df.TIME > timestamp - shour*snake)] 76 & (df.TIME > timestamp - shour*snake)]
49 -  
50 GSL_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp) 77 GSL_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp)
51 & (df.TIME > starT)] 78 & (df.TIME > starT)]
52 79
53 fig, ax = plt.subplots() 80 fig, ax = plt.subplots()
54 81
55 -# caracteristiques de la carte 82 +# map setting
56 m = Basemap(projection='stere',lon_0=-64.5,lat_0=48,\ 83 m = Basemap(projection='stere',lon_0=-64.5,lat_0=48,\
57 - llcrnrlat=45.2,urcrnrlat=51.6,\  
58 - llcrnrlon=-70,urcrnrlon=-56.5,\  
59 - rsphere=6371.2,resolution='h') 84 + llcrnrlat=45.2,urcrnrlat=51.6,\
  85 + llcrnrlon=-70,urcrnrlon=-56.5,\
  86 + rsphere=6371.2,resolution='h')
60 87
  88 +# map background
61 m.drawmapboundary(fill_color='lightblue') # fill to edge 89 m.drawmapboundary(fill_color='lightblue') # fill to edge
62 m.drawcountries() 90 m.drawcountries()
63 m.fillcontinents(color='grey',lake_color='lightblue',zorder=0) 91 m.fillcontinents(color='grey',lake_color='lightblue',zorder=0)
@@ -66,21 +94,25 @@ m.drawcoastlines(linewidth=0.7) @@ -66,21 +94,25 @@ m.drawcoastlines(linewidth=0.7)
66 m.drawparallels(np.arange(40,60,2),labels=[1,0,0,0],linewidth=0.0) 94 m.drawparallels(np.arange(40,60,2),labels=[1,0,0,0],linewidth=0.0)
67 m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1],linewidth=0.0) 95 m.drawmeridians(np.arange(-80,-40,2),labels=[0,0,0,1],linewidth=0.0)
68 96
69 -# trace depuis le début de l'ete 97 +# plot track from the start date
70 for spot, group in GSL_start.groupby(['SPOT']): 98 for spot, group in GSL_start.groupby(['SPOT']):
71 lat = group.LAT.values 99 lat = group.LAT.values
72 lon = group.LON.values 100 lon = group.LON.values
73 x,y = m(lon, lat) 101 x,y = m(lon, lat)
74 - plt.plot(x,y,color='0.35',linewidth=0.7)  
75 -  
76 -# trace les chemins de bouees  
77 -for spot, group in GSL.groupby(['SPOT']):  
78 - latitude = group.LAT.values  
79 - longitude = group.LON.values  
80 - t = (group.TIME.values - float(dt)) / diff  
81 - x,y = m(longitude, latitude)  
82 - cax = plt.scatter(x,y,c=t, s=35, cmap=cmap,linewidth=0,vmin=0, vmax=1)  
83 - 102 + plt.plot(x,y,color='0.35',linewidth=0.7)
  103 +
  104 +# plot colored track of the last positions (snake)
  105 +if not GSL.empty:
  106 + for spot, group in GSL.groupby(['SPOT']):
  107 + latitude = group.LAT.values
  108 + longitude = group.LON.values
  109 + t = (group.TIME.values -float(dt)) / diff
  110 + x,y = m(longitude, latitude)
  111 + cax = plt.scatter(x,y,c=t, s=35, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  112 +
  113 +if GSL.empty:
  114 + cax = plt.scatter(-1,-1,c=1, s=35, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  115 +
84 # colorbar 116 # colorbar
85 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03) 117 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
86 cbar.set_ticks([0,0.25,0.5,0.75,1]) 118 cbar.set_ticks([0,0.25,0.5,0.75,1])
@@ -90,29 +122,30 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15) @@ -90,29 +122,30 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15)
90 122
91 # legende 123 # legende
92 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20, 124 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
93 - xytext=(0.6, 0.87), textcoords='axes fraction',  
94 - horizontalalignment='right', verticalalignment='top') 125 + xytext=(0.7, 0.9), textcoords='axes fraction',
  126 + horizontalalignment='right', verticalalignment='top')
95 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)") 127 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
96 -#enregistrement  
97 -plt.savefig('/home/nicopa01/data/spot/suivi/GSL/GSL_' + nametime + '.jpg',dpi=300) 128 +# recording
  129 +plt.savefig(dir_carte + '/GSL/GSL_' + nametime + '.png',dpi=300)
  130 +# only png can be generate
98 plt.close() 131 plt.close()
99 -  
100 132
101 -# Estuaire du Saint-Laurent ---------------------------  
102 -# traces des x derniers jours dans l'estuaire 133 +#===================================================
  134 +# St Lawrence Estuary
  135 +#===================================================
  136 +# selection of the reliable positions
103 SLE = df[(df.FLAG == "OCN") 137 SLE = df[(df.FLAG == "OCN")
104 - & (df.TIME <= timestamp) & (df.TIME > timestamp - shour*snake)]  
105 - 138 + & (df.TIME <= timestamp) & (df.TIME > timestamp - shour*snake)]
106 SLE_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp) 139 SLE_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp)
107 - & (df.TIME > starT)] 140 + & (df.TIME > starT)]
108 141
109 fig, ax = plt.subplots() 142 fig, ax = plt.subplots()
110 143
111 -# caracteristiques de la carte 144 +# map setting
112 m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\ 145 m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
113 - llcrnrlat=47.8,urcrnrlat=49.5,\  
114 - llcrnrlon=-70,urcrnrlon=-67,\  
115 - rsphere=6371.2,resolution='h') 146 + llcrnrlat=47.8,urcrnrlat=49.5,\
  147 + llcrnrlon=-70,urcrnrlon=-67,\
  148 + rsphere=6371.2,resolution='h')
116 149
117 m.drawmapboundary(fill_color='lightblue') # fill to edge 150 m.drawmapboundary(fill_color='lightblue') # fill to edge
118 m.drawcountries() 151 m.drawcountries()
@@ -122,21 +155,25 @@ m.drawcoastlines(linewidth=0.7) @@ -122,21 +155,25 @@ m.drawcoastlines(linewidth=0.7)
122 m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0) 155 m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
123 m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0) 156 m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
124 157
125 -# trace depuis le début de l'ete 158 +# plot track from the start date
126 for spot, group in SLE_start.groupby(['SPOT']): 159 for spot, group in SLE_start.groupby(['SPOT']):
127 lat = group.LAT.values 160 lat = group.LAT.values
128 lon = group.LON.values 161 lon = group.LON.values
129 x,y = m(lon, lat) 162 x,y = m(lon, lat)
130 plt.plot(x,y,color='0.35',linewidth=0.7) 163 plt.plot(x,y,color='0.35',linewidth=0.7)
131 164
132 -# trace les chemins de bouees  
133 -for spot, group in SLE.groupby(['SPOT']):  
134 - latitude = group.LAT.values  
135 - longitude = group.LON.values  
136 - t = (group.TIME.values - float(dt)) / diff  
137 - x,y = m(longitude, latitude)  
138 - cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)  
139 - 165 +# plot track of the last positions (snake)
  166 +if not SLE.empty:
  167 + for spot, group in SLE.groupby(['SPOT']):
  168 + latitude = group.LAT.values
  169 + longitude = group.LON.values
  170 + t = (group.TIME.values - float(dt)) / diff
  171 + x,y = m(longitude, latitude)
  172 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  173 +
  174 +if SLE.empty:
  175 + cax = plt.scatter(-1,-1,c=1, s=35, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  176 +
140 # colorbar 177 # colorbar
141 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03) 178 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
142 cbar.set_ticks([0,0.25,0.5,0.75,1]) 179 cbar.set_ticks([0,0.25,0.5,0.75,1])
@@ -146,34 +183,29 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15) @@ -146,34 +183,29 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15)
146 183
147 # legende 184 # legende
148 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20, 185 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
149 - xytext=(0.9, 0.1), textcoords='axes fraction',  
150 - horizontalalignment='right', verticalalignment='top') 186 + xytext=(0.9, 0.1), textcoords='axes fraction',
  187 + horizontalalignment='right', verticalalignment='top')
151 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)") 188 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
152 -#enregistrement  
153 -plt.savefig('/home/nicopa01/data/spot/suivi/SLE/SLE_' + nametime + '.jpg',dpi=300)  
154 -plt.close()  
155 -  
156 -  
157 -# Baie des chaleurs ---------------------------  
158 -# traces des x derniers jours dans la baie 189 +# recording
  190 +plt.savefig(dir_carte + '/SLE/SLE_' + nametime + '.png',dpi=300)
159 191
160 -bdc = df.loc[(df.SPOT == 24) | (df.SPOT == 23) | (df.SPOT == 52) |  
161 - (df.SPOT == 53) | (df.SPOT >= 700) & (df.SPOT < 899)]  
162 -  
163 -# Baie des chaleurs ---------------------------  
164 -# traces des x derniers jours dans la baie  
165 -BDC = bdc.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp)  
166 - & (df.TIME > timestamp - shour*snake)]  
167 -  
168 -BDC_start = bdc.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp) & (df.TIME > starT)] 192 +plt.close()
169 193
  194 +#===================================================
  195 +# Baie des chaleurs
  196 +#===================================================
  197 +# selection of the reliable positions
  198 +BDC = df[(df.FLAG == "OCN")
  199 + & (df.TIME <= timestamp) & (df.TIME > timestamp - shour*snake)]
  200 +BDC_start = df.loc[(df.FLAG == "OCN") & (df.TIME <= timestamp)
  201 + & (df.TIME > starT)]
170 fig, ax = plt.subplots() 202 fig, ax = plt.subplots()
171 203
172 -# caracteristiques de la carte 204 +# map setting
173 m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\ 205 m = Basemap(projection='stere',lon_0=-68.5,lat_0=48,\
174 - llcrnrlat=47.5,urcrnrlat=48.7,\  
175 - llcrnrlon=-66.9,urcrnrlon=-64.2,\  
176 - rsphere=6371.2,resolution='h') 206 + llcrnrlat=47.5,urcrnrlat=48.9,\
  207 + llcrnrlon=-66.9,urcrnrlon=-63.8,\
  208 + rsphere=6371.2,resolution='h')
177 209
178 m.drawmapboundary(fill_color='lightblue') # fill to edge 210 m.drawmapboundary(fill_color='lightblue') # fill to edge
179 m.drawcountries() 211 m.drawcountries()
@@ -183,21 +215,25 @@ m.drawcoastlines(linewidth=0.7) @@ -183,21 +215,25 @@ m.drawcoastlines(linewidth=0.7)
183 m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0) 215 m.drawparallels(np.arange(40,60,0.5),labels=[1,0,0,0],linewidth=0.0)
184 m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0) 216 m.drawmeridians(np.arange(-80,-40,1),labels=[0,0,0,1],linewidth=0.0)
185 217
186 -# trace depuis le début de l'ete 218 +# plot track from the start date
187 for spot, group in BDC_start.groupby(['SPOT']): 219 for spot, group in BDC_start.groupby(['SPOT']):
188 lat = group.LAT.values 220 lat = group.LAT.values
189 lon = group.LON.values 221 lon = group.LON.values
190 x,y = m(lon, lat) 222 x,y = m(lon, lat)
191 plt.plot(x,y,color='0.35',linewidth=0.7) 223 plt.plot(x,y,color='0.35',linewidth=0.7)
192 224
193 -# trace les chemins de bouees  
194 -for spot, group in BDC.groupby(['SPOT']):  
195 - latitude = group.LAT.values  
196 - longitude = group.LON.values  
197 - t = (group.TIME.values - float(dt)) / diff  
198 - x,y = m(longitude, latitude)  
199 - cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)  
200 - 225 +# plot track of the last positions (snake)
  226 +if not BDC.empty:
  227 + for spot, group in BDC.groupby(['SPOT']):
  228 + latitude = group.LAT.values
  229 + longitude = group.LON.values
  230 + t = (group.TIME.values - float(dt)) / diff
  231 + x,y = m(longitude, latitude)
  232 + cax = plt.scatter(x,y,c=t, s=45, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  233 +
  234 +if BDC.empty:
  235 + cax = plt.scatter(-1,-1,c=1, s=35, cmap=cmap,linewidth=0,vmin=0, vmax=1)
  236 +
201 # colorbar 237 # colorbar
202 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03) 238 cbar = fig.colorbar(cax,fraction=0.03, pad=0.03)
203 cbar.set_ticks([0,0.25,0.5,0.75,1]) 239 cbar.set_ticks([0,0.25,0.5,0.75,1])
@@ -207,10 +243,11 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15) @@ -207,10 +243,11 @@ cbar.set_label(&#39;heures&#39;, rotation=270,labelpad=15)
207 243
208 # legende 244 # legende
209 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20, 245 plt.annotate(strtime + ' HAE', xy=(1, 1), xycoords='data', size=20,
210 - xytext=(0.6, 0.1), textcoords='axes fraction',  
211 - horizontalalignment='right', verticalalignment='top')  
212 - 246 + xytext=(0.6, 0.1), textcoords='axes fraction',
  247 + horizontalalignment='right', verticalalignment='top')
  248 +
213 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)") 249 plt.title(u"Dérive de surface (" + str(snake) + u" dernières heures)")
214 -#enregistrement  
215 -plt.savefig('/home/nicopa01/data/spot/suivi/BDC/BDC_' + nametime + '.jpg',dpi=300) 250 +# recording
  251 +plt.savefig(dir_carte + '/BDC/BDC_' + nametime + '.png',dpi=300)
216 plt.close() 252 plt.close()
  253 +
@@ -21,12 +21,22 @@ function tr_sort(num_spot,mission,debut,h1,fin,h2) @@ -21,12 +21,22 @@ function tr_sort(num_spot,mission,debut,h1,fin,h2)
21 % Enregistrements sous forme de structure sur Brandypot: 21 % Enregistrements sous forme de structure sur Brandypot:
22 % sas/usagers/share_lasso/data/MEOPAR/drifter 22 % sas/usagers/share_lasso/data/MEOPAR/drifter
23 23
  24 +<<<<<<< HEAD
24 %rootdir = '/sas/usagers/share_lasso/data/MEOPAR'; 25 %rootdir = '/sas/usagers/share_lasso/data/MEOPAR';
25 rootdir = '/share/archives/partage_lasso/spot'; 26 rootdir = '/share/archives/partage_lasso/spot';
26 27
27 fid1 = fopen([ rootdir '/spots_pos_flag_clean.csv']); 28 fid1 = fopen([ rootdir '/spots_pos_flag_clean.csv']);
28 header = textscan(fid1,'%s;%s;%s;%s;%s;%s',1); 29 header = textscan(fid1,'%s;%s;%s;%s;%s;%s',1);
29 spot_clean = textscan(fid1,'%f %f %f %f %s %s','Delimiter',';'); 30 spot_clean = textscan(fid1,'%f %f %f %f %s %s','Delimiter',';');
  31 +=======
  32 +rootdir = '/sas/usagers/share_lasso/data/MEOPAR';
  33 +rootdir = '/share/archives/partage_lasso/spot';
  34 +
  35 +datafile = 'spots_pos_flag_clean.csv';
  36 +
  37 +fid1 = fopen([rootdir,'/',datafile]);
  38 +spot_clean = textscan(fid1,'%f %f %f %f %s', 'delimiter',';');
  39 +>>>>>>> 34a1af0f18cd70ac52566c710fb2c8abde1cb78e
30 fclose(fid1); 40 fclose(fid1);
31 41
32 spot = spot_clean{1,1}; 42 spot = spot_clean{1,1};