romainbrette / clampy

4 stars 0 forks source link

Signals of different sizes #29

Closed romainbrette closed 3 years ago

romainbrette commented 4 years ago

It can happen that output signals have different sizes. This can occur typically because of rounding errors (int(x/dt)), when one signal is made of a sequence of steps and the other is not. Apparently the NI card doesn't complain about that. But when saving to .txt.gz, signals are turned to a matrix and an error occurs.

In fact in board.acquire(), consistency of output signal sizes is checked. But this applies to the analog outputs, not the digital outputs (which is not very consistent). I can see two ways of dealing with this:

  1. board.acquire() checks whether all signals have the same size. If they don't, it fills in with zeros so that they all have the same size, and maybe issues a warning. This doesn't solve the (small) misalignment problem, however.

  2. Signals made with constant() etc have a float duration attribute, so that Sequence() concatenates by rounding not durations but end points. This might require a test of approximate equality (as in Brian?). In addition, board.acquire() checks whether all signals have the same size but raises an error if it is not the case.

romainbrette commented 4 years ago

(2) is not possible because constant just returns an array. We would have to make something quite complicated (class inherited from array, dealing with units etc).

Instead I suggest the following: signal functions (constant) use t_start/t_end or (t1, t2) to specify endpoints, instead of duration, and the length will then be int(t2/dt)-int(t1/dt) rather than int((t2-t1)/dt).

romainbrette commented 4 years ago

I've done that, with t1 and t2. It can still be used with duration (not sure it should be forbidden).