Skip to content

Commit a4f9718

Browse files
Merge pull request #346 from ARamsay17/dev
Small PR
2 parents 0d28591 + 0088a68 commit a4f9718

File tree

3 files changed

+70
-21
lines changed

3 files changed

+70
-21
lines changed

Source/ProcessInstrumentUncertainties.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,10 @@ def ClassBased(self, node: HDFRoot, uncGrp: HDFGroup, stats: dict[str, np.array]
336336
with warnings.catch_warnings():
337337
warnings.filterwarnings("ignore", message="invalid value encountered in divide")
338338
# convert to relative in order to avoid a complex unit conversion process in ProcessL2.
339-
ES_unc = es_unc / es
340-
LI_unc = li_unc / li
341-
LT_unc = lt_unc / lt
342-
if any(ES_unc < 0) or any(LI_unc < 0) or any(LT_unc < 0):
343-
print('############ WARNING ###########')
344-
msg = 'Negatives encountered in uncertainties likely deriving from (ir)radiance normalization and bad QC.'
345-
print(msg)
346-
Utilities.writeLogFile(msg)
339+
340+
ES_unc = es_unc / np.abs(es)
341+
LI_unc = li_unc / np.abs(li)
342+
LT_unc = lt_unc / np.abs(lt)
347343

348344

349345
# interpolation step - bringing uncertainties to common wavebands from radiometric calibration wavebands.

Source/ProcessL1aTriOS.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,49 @@ def processL1a(fp, outFilePath):
4646

4747

4848
## Test filename for station/cast
49-
match1 = re.search(r'\d{8}_\d{6}', file.split('/')[-1])
50-
match2 = re.search(r'\d{4}S', file.split('/')[-1])
51-
match3 = re.search(r'\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}', file.split('/')[-1])
52-
if match1 is not None:
53-
a_name = match1.group()
54-
elif match2 is not None:
55-
a_name = match2.group()
56-
elif match3 is not None:
57-
a_name = match3.group()
58-
else:
49+
50+
def parse_filename(data):
51+
dates = []
52+
for pattern in [
53+
r'\d{8}.\d{6}',
54+
r'\d{4}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}',
55+
r'\d{8}.\d{2}.\d{2}.\d{2}',
56+
r'\d{4}.\d{2}.\d{2}.\d{6}',
57+
r'\d{4}S',
58+
]:
59+
match = re.search(pattern, data)
60+
if match is not None:
61+
dates.append(match.group(0))
62+
63+
if len(dates) == 0:
64+
raise IndexError
65+
66+
return dates[0]
67+
68+
try:
69+
a_name = parse_filename(file.split('/')[-1])
70+
except IndexError:
5971
print(" ERROR: no identifier recognized in TRIOS L0 file name" )
6072
print(" L0 filename should have a cast to identify triplet instrument")
6173
print(" ending in 4 digits before S.mlb ")
6274
return None,None
6375

76+
# match1 = re.search(r'\d{8}_\d{6}', file.split('/')[-1])
77+
# match2 = re.search(r'\d{4}S', file.split('/')[-1])
78+
# match3 = re.search(r'\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}', file.split('/')[-1])
79+
# # string except for serial number will be the same for a triplet
80+
# if match1 is not None:
81+
# a_name = match1.group()
82+
# elif match2 is not None:
83+
# a_name = match2.group()
84+
# elif match3 is not None:
85+
# a_name = match3.group()
86+
# else:
87+
# print(" ERROR: no identifier recognized in TRIOS L0 file name" )
88+
# print(" L0 filename should have a cast to identify triplet instrument")
89+
# print(" ending in 4 digits before S.mlb ")
90+
# return None,None
91+
6492
# acq_time.append(a_cast)
6593
acq_name.append(a_name)
6694

@@ -114,8 +142,8 @@ def processL1a(fp, outFilePath):
114142

115143
try:
116144
new_name = file.split('/')[-1].split('.mlb')[0].split(f'SAM_{name}_RAW_SPECTRUM_')[1]
117-
if match2 is not None:
118-
new_name = new_name+'_'+str(start)
145+
if re.search(r'\d{4}S', file.split('/')[-1]) is not None:
146+
new_name = new_name+'_'+str(start) # I'm not sure what match2 was supposed to find in ACRI's code - AR
119147
except IndexError as err:
120148
print(err)
121149
msg = "possibly an error in naming of Raw files"

Source/ProcessL1b.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,33 @@ def read_unc_coefficient_class(root, inpath, radcal_dir):
113113

114114

115115
# Read sensor-specific radiometric calibration
116+
import re
117+
118+
cal_dates = []
119+
for s in ['ES', 'LI', 'LT']:
120+
save_delta = None
121+
if ConfigFile.settings["SensorType"].lower() == "trios":
122+
s_tag = root.getGroup(f"{s}").attributes['IDDevice'][-4:]
123+
else:
124+
s_tag = root.getGroup(f"{s}_LIGHT").attributes['FrameTag'][-4:]
125+
126+
for f in glob.glob(os.path.join(radcal_dir, f'*{s_tag}_RADCAL*')):
127+
cal_date = datetime.strptime(re.search(r'\d{14}', f.split('/')[-1]).group(), "%Y%m%d%H%M%S")
128+
meas_date = root.getGroup("ANCILLARY_METADATA").getDataset("DATETIME").data[0]
129+
t_delta = cal_date - meas_date.replace(tzinfo=None)
130+
131+
if save_delta is None and t_delta.total_seconds() < 0:
132+
save_delta = abs(t_delta.total_seconds())
133+
134+
if t_delta.total_seconds() < 0 and abs(t_delta.total_seconds()) <= save_delta:
135+
save_cal_date = cal_date
136+
save_delta = abs(t_delta.total_seconds())
137+
138+
cal_dates.append(save_cal_date)
139+
116140
for f in glob.glob(os.path.join(radcal_dir, r'*RADCAL*')):
117-
Utilities.read_char(f, gp)
141+
if datetime.strptime(re.search(r'\d{14}', f.split('/')[-1]).group(), "%Y%m%d%H%M%S") in cal_dates:
142+
Utilities.read_char(f, gp)
118143

119144
# Unc dataset renaming
120145
Utilities.RenameUncertainties_Class(root)

0 commit comments

Comments
 (0)