/
StationsVELO.py
68 lines (58 loc) · 2.48 KB
/
StationsVELO.py
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
#plot starting positions of stations and add velocity vectors
#move plotmap with ASDW-keys, zoom with IO-keys
import geoplotlib as gp
from geoplotlib.colors import colorbrewer
from geoplotlib.utils import epoch_to_str, BoundingBox, read_csv
import glob, os, sys, csv, fnmatch
from graphing import parse_binary_llh
from math import degrees as deg
#path to converted files
path = os.path.dirname(os.path.realpath(__file__))+'/conv'
os.chdir(path)
#get starting location of all stations from files
Earth_radius = float(6378) #[m]
Locations = []
for file in os.listdir():
if fnmatch.fnmatch(file, '*.neu'):
Sname,T,N = file.split('.')
Collection = parse_binary_llh(path+'/'+file)
series = sorted(Collection, key=lambda x: x.time)
#convert list with [phi, lambda, h] to [name, lat, lon]
S_startlat = deg(series[0].pos[0])
S_startlon = deg(series[0].pos[1])
S_Starttime = series[0].time
S_destilat = deg(series[100].pos[0])
S_destilon = deg(series[100].pos[1])
S_destitime = series[100].time
V_destilat = S_startlat + ((S_destilat-S_startlat)*750000)
V_destilon = S_startlon - ((S_destilon-S_startlon)*750000)
Locations.append([Sname,S_startlat,S_startlon,V_destilat,V_destilon])
#path to VLOCs.csv
os.chdir(os.path.dirname(os.path.realpath(__file__)))
#empty VLOCs.csv
f = open("VLOCs.csv", "w+")
f.close()
#write csv to be read by geoplotlib
with open('VLOCs.csv', mode='w', newline='') as VLOCs:
VLOCs = csv.writer(VLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
VLOCs.writerow(['name', 'S_lat', 'S_lon', 'D_lat', 'D_lon'])
for station in Locations:
VLOCs.writerow([station[0], station[1], station[2], station[3], station[4]])
#empty SLOCs.csv
f = open("SLOCs.csv", "w+")
f.close()
#write csv to be read by geoplotlib
with open('SLOCs.csv', mode='w', newline='') as SLOCs:
SLOCs = csv.writer(SLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
SLOCs.writerow(['name', 'lat', 'lon'])
for station in Locations:
SLOCs.writerow([station[0], station[1], station[2]])
#plot stations
Plotdata1 = read_csv('VLOCs.csv')
Plotdata2 = read_csv('SLOCs.csv')
gp.set_bbox(BoundingBox(north=9, west=110, south=1, east=95))
gp.graph(Plotdata1, 'S_lat', 'S_lon', 'D_lat', 'D_lon', linewidth=2, color='Blues')
gp.dot(Plotdata2, color='blue', point_size=3)
gp.labels(Plotdata2, 'name', color='black', font_size=8, anchor_x='center')
gp.tiles_provider('positron')
gp.show()