@@ -3230,9 +3230,22 @@ def push_params(self, cnn, params=None, reset_polynomial=False, reset_periodic=F
3230
3230
('Year' not in params .keys () and 'DOY' in params .keys ()):
3231
3231
raise pyETMException ('Both parameters Year and DOY must be specified if either one is set' )
3232
3232
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
+
3233
3241
elif params ['object' ] == 'periodic' :
3234
3242
reset_periodic = True
3235
3243
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
+
3236
3249
# add the fields for station and network
3237
3250
params ['NetworkCode' ] = self .NetworkCode
3238
3251
params ['StationCode' ] = self .StationCode
@@ -3256,18 +3269,22 @@ def push_params(self, cnn, params=None, reset_polynomial=False, reset_periodic=F
3256
3269
if params :
3257
3270
if params ['object' ] == 'jump' :
3258
3271
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
+
3261
3280
# query params to find the jump
3262
3281
qpar = copy .deepcopy (params )
3263
3282
qpar = {k : v for k , v in qpar .items () if k not in ('action' , 'relaxation' , 'jump_type' )}
3264
3283
3265
3284
# remove existing parameters
3266
3285
cnn .delete ('etm_params' , ** qpar )
3267
3286
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
3271
3288
cnn .insert ('etm_params' , ** params )
3272
3289
3273
3290
0 commit comments