Skip to content

Commit

Permalink
For TriOS - factory, avoid error when SeaBASS writer does not find th…
Browse files Browse the repository at this point in the history
…e uncertainties.
  • Loading branch information
JuanIgnacio.Gossn authored and JuanIgnacio.Gossn committed Oct 30, 2023
1 parent 0deb406 commit 44a12af
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions Source/SeaBASSWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ def formatData2(dataset,dsDelta,dtype, units):
newData = dsCopy
dateDay = dsCopy['Datetag'].tolist()
newData = SeaBASSWriter.removeColumns(newData,'Datetag')
del dsDelta.columns['Datetag']
if dsDelta is not None:
del dsDelta.columns['Datetag']
dateDT = [Utilities.dateTagToDateTime(x) for x in dateDay]
timeTag2 = dsCopy['Timetag2'].tolist()
newData = SeaBASSWriter.removeColumns(newData,'Timetag2')
del dsDelta.columns['Timetag2']
if dsDelta is not None:
del dsDelta.columns['Timetag2']

dsDelta.columnsToDataset()
if dsDelta is not None:
dsDelta.columnsToDataset()

timeDT = []
for i in range(len(dateDT)):
Expand Down Expand Up @@ -151,17 +154,16 @@ def formatData2(dataset,dsDelta,dtype, units):
bands = list(dsCopy.dtype.names)
ls = ['date','time','lat','lon','RelAz','SZA','AOT','cloud','wind']

if dtype == 'rrs':
fieldName = 'Rrs'
elif dtype == 'es':
fieldName = 'Es'
fieldSpecs = {}
fieldSpecs['rrs'] = {'fieldName': 'Rrs', 'unc_or_sd':'unc'}
fieldSpecs['es'] = {'fieldName': 'Es' , 'unc_or_sd':'sd'}

if dtype=='rrs':
fieldsLineStr = ','.join(ls + [f'{fieldName}{band}' for band in bands] \
+ [f'{fieldName}{band}_unc' for band in bands])
else:
fieldsLineStr = ','.join(ls + [f'{fieldName}{band}' for band in bands] \
+ [f'{fieldName}{band}_sd' for band in bands])
fieldsLine = ls + [f'{fieldSpecs[dtype]["fieldName"]}{band}' for band in bands]

if dsDelta is not None:
fieldsLine = fieldsLine + [f'{fieldSpecs[dtype]["fieldName"]}{band}_{fieldSpecs[dtype]["unc_or_sd"]}' for band in bands]

fieldsLineStr = ','.join(fieldsLine)

lenRad = (len(dsCopy.dtype.names))
unitsLine = ['yyyymmdd']
Expand All @@ -171,18 +173,23 @@ def formatData2(dataset,dsDelta,dtype, units):
unitsLine.append('%') # cloud
unitsLine.append('m/s') # wind
unitsLine.extend([units]*lenRad) # data
unitsLine.extend([units]*lenRad) # data uncertainty
if dsDelta is not None:
unitsLine.extend([units]*lenRad) # data uncertainty
unitsLineStr = ','.join(unitsLine)

# Add data for each row
dataOut = []
formatStr = str('{:04d}{:02d}{:02d},{:02d}:{:02d}:{:02d},{:.4f},{:.4f},{:.1f},{:.1f}'\
+ ',{:.4f},{:.0f},{:.1f}'\
+ ',{:.6f}'*lenRad + ',{:.6f}'*lenRad)
+ ',{:.4f},{:.0f},{:.1f}' + ',{:.6f}'*lenRad)
if dsDelta is not None:
formatStr = formatStr + ',{:.6f}' * lenRad
for i in range(dsCopy.shape[0]):
subList = [lat[i],lon[i],relAz[i],sza[i],aod[i],cloud[i],wind[i]]
lineList = [timeDT[i].year,timeDT[i].month,timeDT[i].day,timeDT[i].hour,timeDT[i].minute,timeDT[i].second] +\
subList + list(dsCopy[i].tolist()) + list(dsDelta.data[i].tolist())
subList + list(dsCopy[i].tolist())

if dsDelta is not None:
lineList = lineList + list(dsDelta.data[i].tolist())

# Replace NaNs with -9999.0
lineList = [-9999.0 if np.isnan(element) else element for element in lineList]
Expand Down Expand Up @@ -290,7 +297,11 @@ def outputTXT_Type2(fp):
lonpos = lonposData.columns["LONGITUDE"]

rrsData.datasetToColumns()
rrsDataDelta.datasetToColumns()

# In the case of TriOS factory, rrsDataDelta is None so datasetToColumns() is not applicable
if rrsDataDelta is not None:
rrsDataDelta.datasetToColumns()

esData.datasetToColumns()
esDataDelta.datasetToColumns()
liData.datasetToColumns()
Expand All @@ -300,7 +311,11 @@ def outputTXT_Type2(fp):
esCols = esData.columns
esColsD = esDataDelta.columns
rrsCols = rrsData.columns
rrsColsD = rrsDataDelta.columns

# In the case of TriOS factory, rrsDataDelta is None
if rrsDataDelta is not None:
rrsColsD = rrsDataDelta.columns

for k in list(esCols.keys()):
if (k != 'Datetag') and (k != 'Timetag2'):
if float(k) < minWave or float(k) > maxWave:
Expand All @@ -310,11 +325,14 @@ def outputTXT_Type2(fp):
if (k != 'Datetag') and (k != 'Timetag2'):
if float(k) < minWave or float(k) > maxWave:
del rrsCols[k]
del rrsColsD[k]
if rrsDataDelta is not None:
del rrsColsD[k]
esData.columns = esCols
esDataDelta.columns = esColsD
rrsData.columns = rrsCols
rrsDataDelta.columns = rrsColsD

if rrsDataDelta is not None:
rrsDataDelta.columns = rrsColsD

esData.columns["LATITUDE"] = latpos
rrsData.columns["LATITUDE"] = latpos
Expand All @@ -326,7 +344,10 @@ def outputTXT_Type2(fp):
ltData.columns["LONGITUDE"] = lonpos

rrsData.columnsToDataset()
rrsDataDelta.columnsToDataset()

if rrsDataDelta is not None:
rrsDataDelta.columnsToDataset()

esData.columnsToDataset()
esDataDelta.columnsToDataset()
liData.columnsToDataset()
Expand Down

0 comments on commit 44a12af

Please sign in to comment.