Skip to content

Commit a95265f

Browse files
committed
Small fixes of meta_attr issues.
Added raw strings for meta_attr regex. Fixed some issues with read_in functions not having correct meta_attr settings.
1 parent b967aa5 commit a95265f

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

ims/gcims.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def read_zip(cls, path):
171171
name = os.path.split(path)[1]
172172
time = datetime.strptime(meta_attr["Timestamp"], "%Y-%m-%dT%H:%M:%S")
173173

174-
return cls(name, values, ret_time, drift_time, time)
174+
return cls(name, values, ret_time, drift_time, time, meta_attr)
175175

176176
@classmethod
177177
def read_mea(cls, path):
@@ -210,9 +210,9 @@ def read_mea(cls, path):
210210

211211
meta_attr = meta_attr.split("\n")
212212

213-
key_re = re.compile("^.*?(?==)")
214-
value_re = re.compile("(?<==)(.*?)(?=\[|$)")
215-
# unit_re = re.compile("\[(.*?)\]")
213+
key_re = re.compile(r"^.*?(?==)")
214+
value_re = re.compile(r"(?<==)(.*?)(?=\[|$)")
215+
# unit_re = re.compile(r"\[(.*?)\]")
216216

217217
for i in meta_attr:
218218
key = key_re.search(i).group(0).strip()
@@ -312,8 +312,12 @@ def read_hdf5(cls, path):
312312
name = str(f.attrs["name"])
313313
time = datetime.strptime(f.attrs["time"], "%Y-%m-%dT%H:%M:%S")
314314
drift_time_label = str(f.attrs["drift_time_label"])
315+
if "meta_attr" in f.attrs:
316+
meta_attr = json.loads(f.attrs["meta_attr"])
317+
else:
318+
meta_attr = {}
315319

316-
spectrum = cls(name, values, ret_time, drift_time, time)
320+
spectrum = cls(name, values, ret_time, drift_time, time, meta_attr)
317321
spectrum._drift_time_label = drift_time_label
318322
return spectrum
319323

@@ -346,6 +350,7 @@ def to_hdf5(self, path=None):
346350
f.attrs["name"] = self.name
347351
f.attrs["time"] = datetime.strftime(self.time, "%Y-%m-%dT%H:%M:%S")
348352
f.attrs["drift_time_label"] = self._drift_time_label
353+
f.attrs["meta_attr"] = json.dumps(self.meta_attr)
349354

350355
def normalization(self):
351356
"""

0 commit comments

Comments
 (0)