-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDAS_FCNS_Module.py
More file actions
210 lines (169 loc) · 5.67 KB
/
UDAS_FCNS_Module.py
File metadata and controls
210 lines (169 loc) · 5.67 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
##UDAS Functions File_MS202_Spring_2022
#Contains functions to run the various sensors configured to the UDAS system
import numpy as np
import serial
from datetime import datetime
import time
import csv
import board
import busio
import adafruit_gps
import io
import pynmea2
# Fucnction to retrieve the TSG sensor Data
# TSG sensor provides data for Temperature (C), conductivity, and salinity (PSU)
def getTSG(TSG_sensor):
'''Obtain temperature, conducivity, and practical salinity measurments from TSG sensor.
INPUTS:
TSG_sensor - a serial object
RETURNS:
temperature (Celsius)
conductivity
salinity
'''
try:
data = TSG_sensor.readline().decode()
split = data.split(',')
data_T = float(split[0])
data_C = float(split[1])
data_S = float(split[2])
return(data_T,data_C,data_S)
except:
print('No data collected')
data_T = 'nan'
data_C = 'nan'
data_S = 'nan'
return (data_T, data_C, data_S)
#=========================================================
# Function to Retrive SUNA sensor data
# SUNA sensor provides nitrate data (NO3)
def getSUNA(suna,nsample):
'''
Obtain nitrate measurement from SUNA sensor operating in polled mode.
This version has been tested on Python 3 only.
INPUTS:
suna - a Serial object
nsample - number of light samples to average
RETURNS
nitrate_uM (umol/L)
nitrogen (mg/L)
'''
try:
print('Connected to SUNA'+'\n')
suna.write(b'Waking up SUNA\n')
wake1 = suna.readline().decode()
#print('wake1: ' + wake1+'\n')
wake2 = suna.readline().decode()
#print('wake2: ' + wake2+'\n')
#print('Woken up SUNA, exit from command line'+'\n')
suna.write(b'exit\n')
#wait a few secs
time.sleep(10)
#SATSDF: SUNA Dark Full: blank dark reading
#SATSLF: this has the data in it. Check SUNA hardware manual pg 58 for column headers
#... full ascii column
#Request data, take samples and average them together
sample_command = 'measure '+str(nsample)+'\n'
try:
suna.write(sample_command)
except:
suna.write(str.encode(sample_command))
nitrate_list=[]
nitrogen_list = []
count = 1
# Loop through until done, limit to nsample*10 to avoid infinite loop
for i in range(nsample*2):
try:
line=suna.readline().decode()
except:
line=suna.readline()
#print('Line: '+line+'\n')
if 'SATSL' in line:
#Only average the light counts
data = line.split(',')
nitrate_list.append(float(data[3]))
nitrogen_list.append(float(data[4]))
count = count+1
if count > nsample:
break
suna.close()
data = line.split(',')
nitrate_uM = np.mean(nitrate_list)
nitrogen = np.mean(nitrogen_list)
print ('*****************************************\n')
print ('Nitrate (uM): '+str(nitrate_uM)+'\n')
print ('Nitrogen (mg/L): '+str(nitrogen)+'\n')
print ('*****************************************\n')
return (nitrate_uM, nitrogen)
except:
print ('No data received from SUNA.'+'\n')
return ('NA','NA')
#==================================================================================
# Function to retrieve data from the transmissometer sensor
# Transmissometer sensor provides data for beam attenuation
def get_Transmissometer(TM_Sensor):
'''Obtain transmisometer data from transmissometer sensor.
Inputs:
TMSensor - a serial object
Outputs:
Beam_Attenuation
'''
try:
data = TM_Sensor.readline().decode()
index = data.split()
Beam_Attenuation = float(index[4])
return Beam_Attenuation
except:
print('No data collected')
Beam_Attenuation = 'nan'
return Beam_Attenuation
#===============================================================
#Chlorophyll
def get_chla(chla_sensor):
''' Obtain Chlorophyl a and turbidity measurments.
INPUTS:
chla_sensor - a serial object
RETURNS:
Chl_a (chlorophyll a)
turb (Turbidity)
'''
try:
data = chla_sensor.readline().decode()
split = data.split()
chl_a = float(split[3])
turb = float(split[4])
return chl_a,turb
except:
print('No data collected')
chl_a = 'nan'
turb = 'nan'
return chl_a,turb
#=================================================================
# GPS
def get_gps(sio):
timestamp = time.monotonic()
try:
line = sio.readline()
msg= pynmea2.parse(line)
lat = msg.lat
lon = msg.lon
return repr(msg.lat), repr(msg.lon)
except serial.SerialException as e:
lat = 'nan'
lon = 'nan'
#error = str('Device error: {}'.format(e))
return lat,lon
except pynmea2.ParseError as e:
lat = 'nan'
lon = 'nan'
#rror = str('Parse error: {}'.format(e))
return lat,lon
except AttributeError as e:
lat = 'nan'
lon = 'nan'
#error = str('Attribute error: {}'.format(e))
return lat,lon
except:
lat = 'nan'
lon = 'nan'
return lat,lon