-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_UAV.py
157 lines (96 loc) · 5.46 KB
/
process_UAV.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 1 14:51:43 2021
@author: x51b783
"""
import pandas as pd
import pytz
import process_util
import numpy as np
class UAV_Albedo:
DJI_log = ''
Meteon_log = ''
merged_log = ''
TZ = 'UTC'
MDT = 'US/Mountain'
source_epsg = 'EPSG:4326'
dest_epsg = ''
spectral_bandwidth = ''
def __init__(self, path_to_dji_log, path_to_meteon_log, local_utm_epsg, spectral_bandwidth):
self.dest_epsg = local_utm_epsg
self.spectral_bandwidth = spectral_bandwidth
self.DJI_log = self.prep_DJI_log(path_to_dji_log)
self.Meteon_log = self.clean_Meteon_log(path_to_meteon_log)
self.merged_log = self.merge_logs()
self.merged_log = self.add_radiative_transfer_fields(self.merged_log)
def read_DJI_csv(self, path_to_dji_log):
return pd.read_csv(path_to_dji_log, usecols=['GPS:dateTimeStamp',
'IMU_ATTI(0):roll:C',
'IMU_ATTI(0):pitch:C',
'IMU_ATTI(0):yaw:C',
'IMU_ATTI(0):velComposite:C',
'IMU_ATTI(0):tiltInclination:C',
'IMU_ATTI(0):tiltDirectionEarthFrame:C',
'IMU_ATTI(0):tiltDirectionBodyFrame:C',
'GPS:Long',
'GPS:Lat',
'GPS:heightMSL',
'GPS:dateTimeStamp'], header=0)
def read_Meteon_csv(self, path_to_meteon_log):
return pd.read_csv(path_to_meteon_log, usecols=[0,2,5], skiprows=9, names = ["Time", "incoming (W/m^2)", "reflected (W/m^2)"])
def add_UTM_coordinates(self, df):
projected_lon, projected_lat = process_util.convert_coordinates(self.source_epsg, self.dest_epsg, df['lon'], df['lat'])
df['lon_utm'] = projected_lon
df['lat_utm'] = projected_lat
return df
def prep_DJI_log(self, path_to_dji_log):
df = self.read_DJI_csv(path_to_dji_log)
df = df.rename(columns={'GPS:dateTimeStamp': 'datetime',
'IMU_ATTI(0):roll:C': 'roll',
'IMU_ATTI(0):pitch:C': 'pitch',
'IMU_ATTI(0):yaw:C': 'yaw',
'IMU_ATTI(0):velComposite:C': 'velocity',
'IMU_ATTI(0):tiltInclination:C': 'tilt',
'IMU_ATTI(0):tiltDirectionEarthFrame:C': 'tilt_dir',
'IMU_ATTI(0):tiltDirectionBodyFrame:C': 'tilt_dir_body_frame',
'GPS:Long': 'lon',
'GPS:Lat': 'lat',
'GPS:heightMSL': 'alt_msl'})
#convert to mountain time
df['datetime'] = pd.DatetimeIndex(df['datetime']).tz_convert(pytz.timezone(self.TZ))
#flight logs collect on milliseconds, so we must average values over each second
df = df.groupby(df['datetime']).mean()
df = self.add_UTM_coordinates(df)
return df
def add_radiative_transfer_fields(self, df):
df['6s_Direct_Irradiance_Proportion'] = np.zeros(df.shape[0])
df['6s_Diffuse_Irradiance_Proportion'] = np.zeros(df.shape[0])
df['6s_Solar_Zenith_Angle'] = np.zeros(df.shape[0])
df['6s_Solar_Azimuth_Angle'] = np.zeros(df.shape[0])
for index, row in df.iterrows():
lat = row['lat']
lon = row['lon']
alt_m = row['alt_msl']
dt = index
p_dir, p_diff, solar_zenith, solar_azimuth = process_util.run_radiative_transfer(self.spectral_bandwidth, lat, lon, alt_m, dt)
df.loc[index, '6s_Direct_Irradiance_Proportion'] = p_dir
df.loc[index, '6s_Diffuse_Irradiance_Proportion'] = p_diff
df.loc[index, '6s_Solar_Zenith_Angle'] = solar_zenith
df.loc[index, '6s_Solar_Azimuth_Angle'] = solar_azimuth
return df
def clean_Meteon_log(self, path_to_meteon_log):
df = self.read_Meteon_csv(path_to_meteon_log)
#correct downward faceing sensor for leg interference
reflected_corr = df['reflected (W/m^2)'].multiply(1.0197)
df.insert(3,'albedo', reflected_corr.div(df['incoming (W/m^2)'])) #calculate albedo
df['Time'] = pd.DatetimeIndex(df['Time']).tz_localize(None)
df['Time'] = pd.DatetimeIndex(df['Time']).tz_localize(pytz.timezone(self.MDT))
df['Time'] = pd.DatetimeIndex(df['Time']).tz_convert(pytz.timezone(self.TZ))
df.set_index('Time', inplace=True)
return df
def merge_logs(self):
return pd.concat([self.DJI_log, self.Meteon_log], axis=1, join='inner')
def get_DJI_log(self):
return self.DJI_log
def log_to_csv(self, path_to_output_csv):
self.merged_log.to_csv(path_to_output_csv)