@@ -312,20 +312,17 @@ def dac(self, expanded=False, returnres=64, inplace=False):
312
312
313
313
# Do inplace conversion and set relevant variables.
314
314
if inplace :
315
- # No clever memory saving here...
316
315
if expanded :
317
- p_signal = []
318
316
for ch in range (0 , self .nsig ):
319
317
# nan locations for the channel
320
- chnanlocs = self .e_d_signals [ch ] == dnans [ch ]
321
-
322
- p_signal . append ((( self .e_d_signals [ch ] - self .baseline [ch ]) / self .adcgain [ch ]). astype ( floatdtype , copy = False ) )
323
- p_signal [ch ][ chnanlocs ] = np . nan
324
-
325
- self .e_p_signals = p_signal
318
+ ch_nanlocs = self .e_d_signals [ch ] == dnans [ch ]
319
+ self . e_d_signals [ ch ] = self . e_d_signals [ ch ]. astype ( floatdtype , copy = False )
320
+ np . subtract ( self .e_d_signals [ch ], self .baseline [ch ], self .e_d_signals [ch ])
321
+ np . divide ( self . e_d_signals [ch ], self . adcgain [ ch ], self . e_d_signals [ ch ])
322
+ self . e_d_signals [ ch ][ ch_nanlocs ] = np . nan
323
+ self .e_p_signals = self . e_d_signals
326
324
self .e_d_signals = None
327
325
else :
328
- # nan locations
329
326
nanlocs = self .d_signals == dnans
330
327
# Do float conversion immediately to avoid potential under/overflow
331
328
# of efficient int dtype
@@ -342,13 +339,17 @@ def dac(self, expanded=False, returnres=64, inplace=False):
342
339
p_signal = []
343
340
for ch in range (0 , self .nsig ):
344
341
# nan locations for the channel
345
- chnanlocs = self .e_d_signals [ch ] == dnans [ch ]
346
- p_signal .append (((self .e_d_signals [ch ] - self .baseline [ch ])/ self .adcgain [ch ]).astype (floatdtype , copy = False ))
347
- p_signal [ch ][chnanlocs ] = np .nan
342
+ ch_nanlocs = self .e_d_signals [ch ] == dnans [ch ]
343
+ ch_p_signal = self .e_d_signals [ch ].astype (floatdtype , copy = False )
344
+ np .subtract (ch_p_signal , self .baseline [ch ], ch_p_signal )
345
+ np .divide (ch_p_signal , self .adcgain [ch ], ch_p_signal )
346
+ ch_p_signal [ch_nanlocs ] = np .nan
347
+ p_signal .append (ch_p_signal )
348
348
else :
349
- # nan locations
350
349
nanlocs = self .d_signals == dnans
351
- p_signal = ((self .d_signals - self .baseline ) / self .adcgain ).astype (floatdtype , copy = False )
350
+ p_signal = self .d_signal .astype (floatdtype , copy = False )
351
+ np .subtract (p_signal , self .baseline , p_signal )
352
+ np .divide (p_signal , self .adcgain , p_signal )
352
353
p_signal [nanlocs ] = np .nan
353
354
354
355
return p_signal
0 commit comments