2
2
import multiprocessing
3
3
import posixpath
4
4
import re
5
- import warnings
6
5
7
6
import numpy as np
8
7
import os
@@ -662,15 +661,11 @@ def _arrange_fields(self, seg_numbers, seg_ranges, channels,
662
661
# Update the layout specification segment. At this point it
663
662
# should match the full original header
664
663
665
- # Forcing the signal specifications to match the input
666
- # `channels` variable.
667
- if force_channels :
668
-
669
664
# Have to inspect existing channels of segments; requested
670
665
# input channels will not be enough on its own because not
671
666
# all signals may be present, depending on which section of
672
667
# the signal was read.
673
- else :
668
+ if not force_channels :
674
669
# The desired signal names.
675
670
desired_sig_names = [self .segments [0 ].sig_name [ch ] for ch in channels ]
676
671
# Actual contained signal names of individual segments
@@ -686,15 +681,15 @@ def _arrange_fields(self, seg_numbers, seg_ranges, channels,
686
681
item = getattr (self .segments [0 ], field )
687
682
setattr (self .segments [0 ], field , [item [c ] for c in channels ])
688
683
689
- self .segments [0 ].n_sig = self .n_sig = len (sig_name )
684
+ self .segments [0 ].n_sig = self .n_sig = len (channels )
685
+ if self .n_sig == 0 :
686
+ print ('No signals of the desired channels are contained in the specified sample range.' )
690
687
691
688
# Update record specification parameters
692
689
self .sig_len = sum ([sr [1 ]- sr [0 ] for sr in seg_ranges ])
693
690
self .n_seg = len (self .segments )
694
691
self ._adjust_datetime (sampfrom = sampfrom )
695
692
696
- if self .n_sig == 0 :
697
- warnings .warn ('No signals of the desired channels are contained in the specified sample range.' )
698
693
699
694
def multi_to_single (self , physical , return_res = 64 ):
700
695
"""
@@ -708,8 +703,8 @@ def multi_to_single(self, physical, return_res=64):
708
703
physical : bool
709
704
Whether to convert the physical or digital signal.
710
705
return_res : int, optional
711
- The return resolution of the `p_signal` field. Options are 64, 32,
712
- and 16.
706
+ The return resolution of the `p_signal` field. Options are:
707
+ 64, 32, and 16.
713
708
714
709
Returns
715
710
-------
@@ -750,7 +745,7 @@ def multi_to_single(self, physical, return_res=64):
750
745
# This will be the field dictionary to copy over.
751
746
reference_fields = {'fmt' :n_sig * [None ], 'adc_gain' :n_sig * [None ],
752
747
'baseline' :n_sig * [None ],
753
- 'units' :n_sig * [None ], }
748
+ 'units' :n_sig * [None ]}
754
749
755
750
# For physical signals, mismatched fields will not be copied
756
751
# over. For digital, mismatches will cause an exception.
@@ -786,20 +781,16 @@ def multi_to_single(self, physical, return_res=64):
786
781
if physical :
787
782
sig_attr = 'p_signal'
788
783
# Figure out the largest required dtype
789
- dtype = _signal .np_dtype (_signal .fmt_res (fields ['fmt' ],
790
- maxres = True ),
791
- discrete = False )
792
- nan_vals = self .n_sig * [np .nan ]
784
+ dtype = _signal .np_dtype (return_res , discrete = False )
785
+ nan_vals = np .array ([self .n_sig * [np .nan ]], dtype = dtype )
793
786
else :
794
787
sig_attr = 'd_signal'
795
788
# Figure out the largest required dtype
796
- dtype = _signal .np_dtype (_signal .fmt_res (fields ['fmt' ],
797
- maxres = True ),
798
- discrete = True )
799
- nan_vals = _signal .digi_nan (fields ['fmt' ])
789
+ dtype = _signal .np_dtype (return_res , discrete = True )
790
+ nan_vals = np .array ([_signal .digi_nan (fields ['fmt' ])], dtype = dtype )
800
791
801
- # Create and set the full signal array
802
- combined_signal = np .zeros ([ self . sig_len , self .n_sig ], dtype = dtype )
792
+ # Initialize the full signal array
793
+ combined_signal = np .repeat ( nan_vals , self .sig_len , axis = 0 )
803
794
804
795
# Start and end samples in the overall array to place the
805
796
# segment samples into
@@ -815,24 +806,15 @@ def multi_to_single(self, physical, return_res=64):
815
806
# Copy over the signals into the matching channels
816
807
for i in range (1 , self .n_seg ):
817
808
seg = self .segments [i ]
818
-
819
- # Empty segment
820
- if seg is None :
821
- combined_signal [start_samps [i ]:end_samps [i ], :] = nan_vals
822
- # Non-empty segment
823
- else :
809
+ if seg is not None :
824
810
# Get the segment channels to copy over for each
825
811
# overall channel
826
812
segment_channels = get_wanted_channels (fields ['sig_name' ],
827
813
seg .sig_name ,
828
814
pad = True )
829
815
for ch in range (self .n_sig ):
830
- # Fill with invalids if segment does not contain
831
- # signal
832
- if segment_channels [ch ] is None :
833
- combined_signal [start_samps [i ]:end_samps [i ], ch ] = nan_vals [ch ]
834
816
# Copy over relevant signal
835
- else :
817
+ if segment_channels [ ch ] is not None :
836
818
combined_signal [start_samps [i ]:end_samps [i ], ch ] = getattr (seg , sig_attr )[:, segment_channels [ch ]]
837
819
838
820
# Create the single segment Record object and set attributes
@@ -841,10 +823,6 @@ def multi_to_single(self, physical, return_res=64):
841
823
setattr (record , field , fields [field ])
842
824
setattr (record , sig_attr , combined_signal )
843
825
844
- # Consider the case where no signals are present. ie. only empty.
845
- # pdb.set_trace()
846
- # print(sig_attr)
847
- # print(getattr(record, sig_attr).dtype)
848
826
# Use the signal to set record features
849
827
if physical :
850
828
record .set_p_features ()
0 commit comments