@@ -392,21 +392,41 @@ def index_of(self, position, mode=IndexMode.LessOrEqual):
392
392
393
393
raise ValueError ("Unknown IndexMode: {}" .format (mode ))
394
394
395
- def axis (self , count , start = 0 ):
395
+ def axis (self , count , start = None , start_position = None ):
396
396
"""
397
- Get an axis as defined by this sampled dimension.
397
+ Get an axis as defined by this nixio.SampledDimension. It either starts at the offset of the dimension,
398
+ a number of sample points later, or at a given position. The latter must not be less than the offset. If
399
+ start and start_position are given, start takes precedence.
398
400
399
- :param count: A positive integer specifying the length of the axis
400
- (no of samples).
401
+ :param count: A positive integer specifying the length of the axis (no of samples).
402
+ :type count: int
403
+ :param start: positive integer, indicates the starting sample. Defaults to None. Precedes over the start_position.
404
+ :type start: int
405
+ :param start_position: The start position of the axis. Defaults to None.
406
+ :type start_position: double
401
407
402
- :param start: positive integer, indicates the starting sample .
408
+ :raises: ValueError if start is negative or if the start_position is given and is less than offset .
403
409
404
410
:returns: The created axis
405
411
:rtype: tuple
406
412
"""
407
413
offset = self .offset if self .offset else 0.0
408
414
sample = self .sampling_interval
409
- start_val = start * sample + offset
415
+
416
+ if start is not None :
417
+ if start < 0 :
418
+ raise ValueError ("Start index (%i) must not be negative!" % start )
419
+ start_val = start * sample + offset
420
+ else :
421
+ if start_position is not None :
422
+ if start_position < offset :
423
+ raise ValueError ("SampledDimension.axis: Start position (%.f) must not be "
424
+ "less than the offset of the dimension (%.f)!" % (start_position , offset ))
425
+ else :
426
+ start_val = start_position
427
+ else :
428
+ start_val = offset
429
+
410
430
return tuple (np .arange (count ) * sample + start_val )
411
431
412
432
@property
0 commit comments