Skip to content

Commit 6b864fb

Browse files
EliEli
authored andcommitted
Fixed an issue where identification of DMS data was brittle because of extra spaces.
1 parent 48c3ed8 commit 6b864fb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

dms_datastore/read_multi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def ts_multifile(
283283
else:
284284
if force_regular:
285285
tss = [x.asfreq(commonfreq) for x in tss]
286+
286287
patfull = ts_merge(tss)
287288
total_series = total_series + len(tss)
288289
if commonfreq is not None:

dms_datastore/read_ts.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,22 @@ def read_yaml_header(fpath):
168168
def is_dms1_screen(fname):
169169
if not fname.endswith(".csv"):
170170
return False
171-
pattern = re.compile(r"#\s?format\s?:\s?dwr-dms-1.0")
171+
pattern = re.compile(r"format\s?:\s?dwr-dms-1.0")
172+
MAX_SCAN_LINE = 150
172173
with open(fname, "r") as f:
173-
line = f.readline()
174-
if pattern.match(line) is None:
174+
line = f.readline().strip()
175+
if pattern.search(line) is None:
175176
return False
176-
for i in range(150):
177+
for i in range(MAX_SCAN_LINE):
177178
otherline = f.readline()
178-
179-
if "screen:" in otherline:
179+
if "user_flag" in otherline:
180180
return True
181181
return False
182182

183183

184184
def read_dms1_screen(
185185
fpath_pattern, start=None, end=None, selector=None, force_regular=True, nrows=None, freq=None, **kwargs
186-
):
186+
):
187187
if selector is None:
188188
selector = "value"
189189
ts = csv_retrieve_ts(
@@ -1140,9 +1140,11 @@ def read_usgs_csv1(
11401140

11411141

11421142
def is_noaa_file(fname):
1143-
MAX_SCAN_LINE = 14
1143+
MAX_SCAN_LINE = 120
11441144
with open(fname, "r") as f:
11451145
for i, line in enumerate(f):
1146+
if "format: dwr" in line.lower():
1147+
return False
11461148
if i > MAX_SCAN_LINE:
11471149
return False
11481150
linelower = line.lower()
@@ -1154,13 +1156,13 @@ def is_noaa_file(fname):
11541156

11551157

11561158
def noaa_data_column(fname):
1157-
MAX_SCAN_LINE = 60
1159+
MAX_SCAN_LINE = 120
11581160
with open(fname, "r") as f:
11591161
reading_cols = False
11601162
for i, line in enumerate(f):
11611163
if i > MAX_SCAN_LINE:
11621164
raise ValueError(
1163-
"Could not determine data columns within MAX_SCAN lines"
1165+
"Could not determine data columns within MAX_SCAN lines in file: {}".format(fname)
11641166
)
11651167
if not line.startswith("#"):
11661168
parts = [p.strip() for p in line.split(",")]

0 commit comments

Comments
 (0)