Handle multiplication of `ForEachObject` container by numpy array
I think I found a bug in instrument.py
. The following code fails to run:
i = lisainstrument.Instrument()
i.simulate()
and gives the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-82c47fde1b6d> in <module>
1 i = lisainstrument.Instrument()
----> 2 i.simulate()
~/.local/lib/python3.9/site-packages/lisainstrument/instrument.py in simulate(self, keep_all)
430 self.keep_all = keep_all
431 self.simulated = True
--> 432 self.simulate_noises()
433
434 ## Local beams
~/.local/lib/python3.9/site-packages/lisainstrument/instrument.py in simulate_noises(self)
908 self.clock_noise_offsets = \
909 self.clock_freqoffsets \
--> 910 + self.clock_freqlindrifts * t \
911 + self.clock_freqquaddrifts * t**2
912
~/.local/lib/python3.9/site-packages/lisainstrument/containers.py in __mul__(self, other)
256 if isinstance(other, ForEachMOSA):
257 return self.for_each_mosa() * other
--> 258 return super().__mul__(other)
259
260 def __floordiv__(self, other):
~/.local/lib/python3.9/site-packages/lisainstrument/containers.py in __mul__(self, other)
171 if isinstance(other, type(self)):
172 return self.transformed(lambda index, value: value * other[index])
--> 173 raise TypeError(f"unsupported operand type for *: '{type(self)}' and '{type(other)}'")
174
175 def __rmul__(self, other):
TypeError: unsupported operand type for *: '<class 'lisainstrument.containers.ForEachSC'>' and '<class 'numpy.ndarray'>'
I think the issue is that the for ForEachObject
container does not handle multiplication by a numpy array but only by a scalar. This should be a quick fix...
Edited by Martin Staab