@@ -1092,5 +1092,94 @@ def parse_logfiles(files):
1092
1092
return out
1093
1093
1094
1094
1095
+ def parse_logfiles_maybe (files ):
1096
+ """
1097
+ Parse time, lat, lon, and amph_total from glider logfiles.
1098
+
1099
+ Parameters
1100
+ ----------
1101
+ files : list of strings or Paths
1102
+ List of logfiles to parse. Should be sorted.
1103
+
1104
+ Returns
1105
+ -------
1106
+ out : xarray
1107
+ xarray data set with fields time, lon, lat, ampH indexed by surfacing.
1108
+ More could be added.
1109
+ """
1110
+
1111
+ times = ['' ] * 10000
1112
+ gps = ['' ] * 10000
1113
+ amph = ['' ] * 10000
1114
+ surfacereason = ''
1115
+ missionnum = ['' ] * 10000
1116
+ abortsegment = 0
1117
+ abortcause = 0
1118
+
1119
+ ntimes = 0
1120
+ for fn in files :
1121
+ found_time = False
1122
+
1123
+ with open (fn , 'r' ) as fin :
1124
+ for l in fin :
1125
+ if 'Curr Time:' in l :
1126
+ times [ntimes ] = l
1127
+ ntimes += 1
1128
+ found_time = True
1129
+ elif found_time and 'GPS Location' in l :
1130
+ gps [ntimes - 1 ] = l
1131
+ elif found_time and "sensor:m_coulomb_amphr_total" in l :
1132
+ amph [ntimes - 1 ] = l
1133
+ elif found_time and "Because:" in l :
1134
+ surfacereason = l
1135
+ elif found_time and "MissionNum" in l :
1136
+ missionnum [ntimes - 1 ] = l
1137
+ elif found_time and "abort segment:" in l :
1138
+ abortsegment = l
1139
+ elif found_time and "abort cause:" in l :
1140
+ abortcause = l
1141
+
1142
+ amph = amph [:ntimes ]
1143
+ gps = gps [:ntimes ]
1144
+ times = times [:ntimes ]
1145
+ missionnum = missionnum [:ntimes ]
1146
+
1147
+ # now parse them
1148
+ out = xr .Dataset (coords = {'time' : ('surfacing' , np .zeros (ntimes , dtype = 'datetime64[ns]' ))})
1149
+ out ['ampH' ] = ('surfacing' , np .zeros (ntimes ) * np .NaN )
1150
+ out ['lon' ] = ('surfacing' , np .zeros (ntimes ) * np .NaN )
1151
+ out ['lat' ] = ('surfacing' , np .zeros (ntimes ) * np .NaN )
1152
+ out ['missionnum' ] = ('surfacing' , np .zeros (ntimes ) * np .NaN )
1153
+ out .attrs ['surfacereason' ] = surfacereason
1154
+ # ABORT HISTORY: last abort segment: hal_1002-2024-183-0-0 (0171.0000)
1155
+ out .attrs ['abortsegment' ] = float (abortsegment [- 11 :- 2 ])
1156
+ out .attrs ['abortcause' ] = abortcause
1157
+
1158
+ for i in range (ntimes ):
1159
+ timestring = times [i ][11 :- 13 ]
1160
+ out ['time' ][i ] = np .datetime64 (datetime .strptime (timestring , '%a %b %d %H:%M:%S %Y' ), 'ns' )
1161
+ try :
1162
+ if '=' in amph [i ]:
1163
+ st = amph [i ].index ('=' )
1164
+ en = amph [i ][st :].index (' ' ) + st
1165
+ out ['ampH' ][i ] = float (amph [i ][(st + 1 ):en ])
1166
+
1167
+ # GPS Location: 4912.737 N -12357.253 E measured 110.757 secs ago
1168
+ sp = gps [i ].split ()
1169
+ out ['lat' ][i ] = utils .nmea2deg (float (sp [2 ]))
1170
+ out ['lon' ][i ] = utils .nmea2deg (float (sp [4 ]))
1171
+
1172
+ # MissionName:calvert.mi MissionNum:hal_1002-2024-183-4-41 (0175.0041)
1173
+ if len (missionnum [i ]) > 12 :
1174
+ out ['missionnum' ][i ] = float (missionnum [i ][- 11 :- 2 ])
1175
+ except :
1176
+ pass
1177
+
1178
+ return out
1179
+
1180
+
1181
+
1182
+
1183
+
1095
1184
__all__ = ['binary_to_rawnc' , 'merge_rawnc' , 'raw_to_timeseries' ,
1096
1185
'parse_gliderState' , 'parse_logfiles' ]
0 commit comments