-
Notifications
You must be signed in to change notification settings - Fork 0
/
grouperPlotM69.py
111 lines (86 loc) · 3.34 KB
/
grouperPlotM69.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import simplekml
# Time zone offset for red grouper file
# if time in UTC, offsetHours = 0
offsetHours = 0
# import files
gpsFile = '/w/loggerhead/glider/M69_Jan2017/M69gps.csv'
dataFile = '/w/loggerhead/glider/M69_Jan2017/M69_RedGrouper.csv'
#dataFile = '/w/loggerhead/glider/M69_Jan2017/M69_RedGrouper_DSG.csv'
tagFile = '/w/loggerhead/glider/M69_Jan2017/M69_VMT.csv'
# output files
mergeFile = '/w/loggerhead/glider/M69_Jan2017/M69_merge.csv'
kmlFile = '/w/loggerhead/glider/M69_Jan2017/M69_RedGrouper.kml'
#mergeFile = '/w/loggerhead/glider/M69_Jan2017/M69_merge_DSG.csv'
#kmlFile = '/w/loggerhead/glider/M69_Jan2017/M69_RedGrouper_DSG.kml'
kmlGlider = '/w/loggerhead/glider/M69_Jan2017/M69gps.kml'
# read in and format GPS csv file
df = pd.read_csv(gpsFile, header=0, sep=',', names=['Date_Time', 'Latitude', 'Longitude'], dtype = {'Date_Time': str, 'Latitude': np.float64, 'Longitude': np.float64})
df = df.dropna()
df.index = pd.to_datetime(df.Date_Time)
# df = df.drop('Date', 1)
# df = df.drop('Time', 1)
df = df.drop('Date_Time', 1)
df = df.dropna()
df = df.sort_index()
# resample location to 1 minute intervals averaging lat and lon values
df = df.resample('1T').mean()
df = df.interpolate()
# read in grouper data
df2 = pd.read_csv(dataFile, sep=',', usecols=[1, 2])
df2.index = pd.to_datetime(df2[df2.columns[0]])
df2.index = df2.index + pd.DateOffset(hours=offsetHours)
df2 = df2.drop(df2.columns[0], axis=1)
df2 = df2.sort_index()
# resample 1 minute bins
df2 = df2.resample('1T').sum()
df2.columns = ['sounds']
# # read in VMT
# df3 = pd.read_csv(tagFile, sep=',')
# df3.index = pd.to_datetime(df3[df3.columns[0]])
# df3 = df3.drop(df3.columns[0], axis=1)
# df3 = df3.sort_index()
# # bin VMT data into pings per minute (not unique)
# df4 = df3.resample('1T').count()
# df4.columns = ['tagCount']
# join dataframes
df_join = df.join(df2, how='outer')
# df_join = df_join.join(df4, how='outer')
# df_join = df_join.dropna()
# Summary stats
print("Sounds: ")
print(df2.sum())
# Glider and sound plot
plt.scatter(df_join.Longitude, df_join.Latitude, c='c')
plt.scatter(df_join.Longitude, df_join.Latitude, c='r', s=df_join['sounds'] * 50)
plt.title(dataFile)
plt.show()
# plot with tag data
# limit time range
# df5 = df_join.loc['2017-05-19 15:53':'2017-06-05 14:36']
# plt.scatter(df5.Longitude, df5.Latitude, c='c')
# plt.scatter(df5.Longitude, df5.Latitude, marker='v', c='b', s=df5['tagCount'] * 20)
# plt.scatter(df5.Longitude, df5.Latitude, c='r', s=df5['sounds'] * 20)
# plt.show()
# export to csv
df_join.to_csv(mergeFile)
# export to kml
kml = simplekml.Kml()
style = simplekml.Style()
style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png'
# i is index ; row.Name row.lat row.lon row.count
for i, row in df_join.iterrows():
pnt = kml.newpoint(name = "", description = "", coords=[(row.Longitude, row.Latitude)])
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png'
pnt.style.iconstyle.scale = str(np.float(row[2])/1.4)
kml.save(kmlFile)
latlon = []
for i,row in df.iterrows():
latlon.append((row.Longitude, row.Latitude, 0.0))
kml = simplekml.Kml()
ls = kml.newlinestring(name = "glider", description = "", coords=latlon)
ls.extrude = 1
ls.altitudemode = simplekml.AltitudeMode.relativetoground
kml.save(kmlGlider)