@@ -532,33 +532,22 @@ def adc(self, expanded=False, inplace=False):
532
532
# To do: choose the minimum return res needed
533
533
intdtype = "int64"
534
534
535
- # Convert a single physical channel to digital. Note that the
536
- # input array is modified!
537
- def adc_inplace_1d (ch_p_signal , adc_gain , baseline , d_nan ):
538
- ch_nanlocs = np .isnan (ch_p_signal )
539
- np .multiply (ch_p_signal , adc_gain , ch_p_signal )
540
- np .add (ch_p_signal , baseline , ch_p_signal )
541
- np .round (ch_p_signal , 0 , ch_p_signal )
542
- np .copyto (ch_p_signal , d_nan , where = ch_nanlocs )
543
- ch_d_signal = ch_p_signal .astype (intdtype , copy = False )
544
- return ch_d_signal
545
-
546
- # Convert a 2D physical signal array to digital. Note that the
547
- # input array is modified!
548
- def adc_inplace_2d (p_signal ):
535
+ # Convert a physical (1D or 2D) signal array to digital. Note that
536
+ # the input array is modified!
537
+ def adc_inplace (p_signal , adc_gain , baseline , d_nan ):
549
538
nanlocs = np .isnan (p_signal )
550
- np .multiply (p_signal , self . adc_gain , p_signal )
551
- np .add (p_signal , self . baseline , p_signal )
539
+ np .multiply (p_signal , adc_gain , p_signal )
540
+ np .add (p_signal , baseline , p_signal )
552
541
np .round (p_signal , 0 , p_signal )
553
- np .copyto (p_signal , d_nans , where = nanlocs )
542
+ np .copyto (p_signal , d_nan , where = nanlocs )
554
543
d_signal = p_signal .astype (intdtype , copy = False )
555
544
return d_signal
556
545
557
546
# Do inplace conversion and set relevant variables.
558
547
if inplace :
559
548
if expanded :
560
549
for ch , ch_p_signal in enumerate (self .e_p_signal ):
561
- ch_d_signal = adc_inplace_1d (
550
+ ch_d_signal = adc_inplace (
562
551
ch_p_signal ,
563
552
self .adc_gain [ch ],
564
553
self .baseline [ch ],
@@ -568,15 +557,20 @@ def adc_inplace_2d(p_signal):
568
557
self .e_d_signal = self .e_p_signal
569
558
self .e_p_signal = None
570
559
else :
571
- self .d_signal = adc_inplace_2d (self .p_signal )
560
+ self .d_signal = adc_inplace (
561
+ self .p_signal ,
562
+ self .adc_gain ,
563
+ self .baseline ,
564
+ d_nans ,
565
+ )
572
566
self .p_signal = None
573
567
574
568
# Return the variable
575
569
else :
576
570
if expanded :
577
571
e_d_signal = []
578
572
for ch , ch_p_signal in enumerate (self .e_p_signal ):
579
- ch_d_signal = adc_inplace_1d (
573
+ ch_d_signal = adc_inplace (
580
574
ch_p_signal .copy (),
581
575
self .adc_gain [ch ],
582
576
self .baseline [ch ],
@@ -586,7 +580,12 @@ def adc_inplace_2d(p_signal):
586
580
return e_d_signal
587
581
588
582
else :
589
- return adc_inplace_2d (self .p_signal .copy ())
583
+ return adc_inplace (
584
+ self .p_signal .copy (),
585
+ self .adc_gain ,
586
+ self .baseline ,
587
+ d_nans ,
588
+ )
590
589
591
590
def dac (self , expanded = False , return_res = 64 , inplace = False ):
592
591
"""
0 commit comments