|
5 | 5 | # The check_field_cohesion() function will be called in wrheader which checks all the header fields.
|
6 | 6 | # The check_sig_cohesion() function will be called in wrsamp in wrdat to check the d_signal against the header fields.
|
7 | 7 |
|
8 |
| -from calendar import monthrange |
| 8 | + |
9 | 9 | from collections import OrderedDict
|
| 10 | +import datetime |
10 | 11 | import multiprocessing
|
11 | 12 | import numpy as np
|
12 | 13 | import os
|
@@ -105,9 +106,12 @@ def check_field(self, field, channels=None):
|
105 | 106 | if self.sig_len <0:
|
106 | 107 | raise ValueError('sig_len must be a non-negative integer')
|
107 | 108 | elif field == 'base_time':
|
108 |
| - _ = parse_timestring(self.base_time) |
| 109 | + try: |
| 110 | + _ = datetime.datetime.strptime(self.base_time, '%H:%M/%S.%f') |
| 111 | + except ValueError: |
| 112 | + _ = datetime.datetime.strptime(self.base_time, '%H:%M/%S') |
109 | 113 | elif field == 'base_date':
|
110 |
| - _ = parse_datestring(self.base_date) |
| 114 | + _ = datetime.datetime.strptime(self.base_date, '%d/%m/%Y') |
111 | 115 |
|
112 | 116 | # Signal specification fields. Lists of elements to check.
|
113 | 117 | elif field in _header.sig_field_specs:
|
@@ -422,8 +426,10 @@ def wrsamp(self, expanded=False, write_dir=''):
|
422 | 426 |
|
423 | 427 |
|
424 | 428 | def arrange_fields(self, channels, expanded=False):
|
425 |
| - # Arrange/edit object fields to reflect user channel and/or signal range input |
426 |
| - # Account for case when signals are expanded |
| 429 | + """ |
| 430 | + Arrange/edit object fields to reflect user channel and/or signal range input |
| 431 | + Account for case when signals are expanded |
| 432 | + """ |
427 | 433 |
|
428 | 434 | # Rearrange signal specification fields
|
429 | 435 | for field in _header.sig_field_specs:
|
@@ -1295,59 +1301,6 @@ def wrsamp(record_name, fs, units, sig_name, p_signal=None, d_signal=None,
|
1295 | 1301 | record.wrsamp(write_dir=write_dir)
|
1296 | 1302 |
|
1297 | 1303 |
|
1298 |
| -# Time string parser for WFDB header - H(H):M(M):S(S(.sss)) format. |
1299 |
| -def parse_timestring(timestring): |
1300 |
| - times = re.findall("(?P<hours>\d{1,2}):(?P<minutes>\d{1,2}):(?P<seconds>\d{1,2}[.\d+]*)", timestring) |
1301 |
| - |
1302 |
| - if not times: |
1303 |
| - raise ValueError("Invalid time string: "+timestring+". Acceptable format is: 'Hours:Minutes:Seconds'") |
1304 |
| - else: |
1305 |
| - hours, minutes, seconds = times[0] |
1306 |
| - |
1307 |
| - if not hours or not minutes or not seconds: |
1308 |
| - raise ValueError("Invalid time string: "+timestring+". Acceptable format is: 'Hours:Minutes:Seconds'") |
1309 |
| - |
1310 |
| - hours = int(hours) |
1311 |
| - minutes = int(minutes) |
1312 |
| - seconds = float(seconds) |
1313 |
| - |
1314 |
| - if int(hours) >23: |
1315 |
| - raise ValueError('hours must be < 24') |
1316 |
| - elif hours<0: |
1317 |
| - raise ValueError('hours must be positive') |
1318 |
| - if minutes>59: |
1319 |
| - raise ValueError('minutes must be < 60') |
1320 |
| - elif minutes<0: |
1321 |
| - raise ValueError('minutes must be positive') |
1322 |
| - if seconds>59: |
1323 |
| - raise ValueError('seconds must be < 60') |
1324 |
| - elif seconds<0: |
1325 |
| - raise ValueError('seconds must be positive') |
1326 |
| - |
1327 |
| - return (hours, minutes, seconds) |
1328 |
| - |
1329 |
| -# Date string parser for WFDB header - DD/MM/YYYY |
1330 |
| -def parse_datestring(datestring): |
1331 |
| - dates = re.findall(r"(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})", datestring) |
1332 |
| - |
1333 |
| - if not dates: |
1334 |
| - raise ValueError("Invalid date string. Acceptable format is: 'DD/MM/YYYY'") |
1335 |
| - else: |
1336 |
| - day, month, year = dates[0] |
1337 |
| - |
1338 |
| - day = int(day) |
1339 |
| - month = int(month) |
1340 |
| - year = int(year) |
1341 |
| - |
1342 |
| - if year<1: |
1343 |
| - raise ValueError('year must be positive') |
1344 |
| - if month<1 or month>12: |
1345 |
| - raise ValueError('month must be between 1 and 12') |
1346 |
| - if day not in range(1, monthrange(year, month)[1]+1): |
1347 |
| - raise ValueError('day does not exist for specified year and month') |
1348 |
| - |
1349 |
| - return (day, month, year) |
1350 |
| - |
1351 | 1304 | # Returns the unique elements in a list in the order that they appear.
|
1352 | 1305 | # Also returns the indices of the original list that correspond to each output element.
|
1353 | 1306 | def orderedsetlist(fulllist):
|
|
0 commit comments