Skip to content

Commit 723dc33

Browse files
committed
Added sanity checks to push_params in pyETM
Check for bad parameters during push parameters. Minor fix to igslog.py
1 parent 41cbc7b commit 723dc33

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

pgamit/igslog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
to: ((?:Nine\sCharacter\sID)|(?:Four\sCharacter\sID)|(?:Site\sID))
1616
(ps. probably same issue in the regex for igs format v2)
1717
It also needs to allow 'Nine Character ID' in v1
18+
DDG: no, changed back to (?:Nine\sCharacter\sID|Four\sCharacter\sID|Site\sID)\s+\:\s*(\w{4}).*\W+
1819
1920
extract_id_block() inside:
2021
id_block = [id_block[1].decode().upper(), id_block[2].decode().upper()] =
@@ -66,7 +67,7 @@
6667

6768
_REGEX_ID_V1 = _re.compile(
6869
rb"""
69-
((?:Nine\sCharacter\sID)|(?:Four\sCharacter\sID)|(?:Site\sID))\s+\:\s*(\w{4}).*\W+
70+
(?:Nine\sCharacter\sID|Four\sCharacter\sID|Site\sID)\s+\:\s*(\w{4}).*\W+
7071
.*\W+
7172
(?:\s{25}.+\W+|)
7273
IERS.+\:\s*(\w{9}|)

pgamit/pyETM.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,9 +3230,22 @@ def push_params(self, cnn, params=None, reset_polynomial=False, reset_periodic=F
32303230
('Year' not in params.keys() and 'DOY' in params.keys()):
32313231
raise pyETMException('Both parameters Year and DOY must be specified if either one is set')
32323232

3233+
# check that terms is an integer > 0
3234+
if type(params['terms']) is not int or params['terms'] <= 0:
3235+
raise pyETMException('Parameter terms must be of type int > 0')
3236+
3237+
# check that the date is valid
3238+
if 'Year' in params.keys() and 'DOY' in params.keys():
3239+
_ = pyDate.Date(year=params['Year'], doy=params['DOY'])
3240+
32333241
elif params['object'] == 'periodic':
32343242
reset_periodic = True
32353243

3244+
# check that frequencies are not negative
3245+
for f in params['frequencies']:
3246+
if f <= 0:
3247+
raise pyETMException('Cannot insert negative frequencies for periodic components')
3248+
32363249
# add the fields for station and network
32373250
params['NetworkCode'] = self.NetworkCode
32383251
params['StationCode'] = self.StationCode
@@ -3256,18 +3269,22 @@ def push_params(self, cnn, params=None, reset_polynomial=False, reset_periodic=F
32563269
if params:
32573270
if params['object'] == 'jump':
32583271

3259-
if params['jump_type'] > 0 and params['action'] == '+' and 'relaxation' not in params.keys():
3260-
raise pyETMException('Relaxation parameter needed when jump_type>0 and action=+')
3272+
if params['action'] == '+' and params['jump_type'] > 0 and 'relaxation' not in params.keys():
3273+
raise pyETMException('Relaxation parameters needed when jump_type > 0 and action = +')
3274+
3275+
if 'relaxation' in params.keys():
3276+
for r in params['relaxation']:
3277+
if r <= 0:
3278+
raise pyETMException('Relaxation parameters must be > 0')
3279+
32613280
# query params to find the jump
32623281
qpar = copy.deepcopy(params)
32633282
qpar = {k: v for k, v in qpar.items() if k not in ('action', 'relaxation', 'jump_type')}
32643283

32653284
# remove existing parameters
32663285
cnn.delete('etm_params', **qpar)
32673286

3268-
if type(params['terms']) is not int:
3269-
raise pyETMException('Parameter terms must be of type int')
3270-
3287+
# insert the parameters passed to the database
32713288
cnn.insert('etm_params', **params)
32723289

32733290

0 commit comments

Comments
 (0)