round_to_raster

round_to_raster#

pypulseqpp.round_to_raster()[source]#

Round seconds to the nearest multiple of raster_s, with ties to even.

raster_s is a raster period in seconds, such as pypulseqpp.Opts.grad_raster_time or pypulseqpp.Opts.block_duration_raster.

Parameters:
  • value_s (float) – The time to round (s).

  • raster_s (float) – The raster period to round it onto (s).

Returns:

The nearest multiple of raster_s.

Return type:

float

Examples

>>> import pypulseqpp as pp
>>> pp.round_to_raster(23e-6, 10e-6)
2e-05

A value halfway between two multiples rounds to the even one, so 1.5 and 2.5 raster periods both round to 2:

>>> pp.round_to_raster(15e-6, 10e-6), pp.round_to_raster(25e-6, 10e-6)
(2e-05, 2e-05)