#NEWLINE# @ ValidateLarchPlugin #NEWLINE# def read_gsexdi( fname , _larch = None , nmca = 4 , bad = None , **kws ) : #NEWLINE# #INDENT# 'Read GSE XDI Scan Data to larch group,\n    summing ROI data for MCAs and apply deadtime corrections\n    ' #NEWLINE# group = _larch . symtable . create_group ( ) #NEWLINE# group . __name__ = ( 'GSE XDI Data file %s' % fname ) #NEWLINE# xdi = XDIFile ( str ( fname ) ) #NEWLINE# group . _xdi = xdi #NEWLINE# group . filename = fname #NEWLINE# group . npts = xdi . npts #NEWLINE# group . bad_channels = bad #NEWLINE# group . dtc_taus = XSPRESS3_TAUS #NEWLINE# if _larch . symtable . has_symbol ( '_sys.gsecars.xspress3_taus' ) : #NEWLINE# #INDENT# group . dtc_taus = _larch . symtable . _sys . gsecars . xspress3_taus #NEWLINE# #UNINDENT# for family in ( 'scan' , 'mono' , 'facility' ) : #NEWLINE# #INDENT# for ( key , val ) in xdi . attrs . get ( family , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . items ( ) : #NEWLINE# #INDENT# if ( '||' in val ) : #NEWLINE# #INDENT# ( val , addr ) = val . split ( '||' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# val = float ( val ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# setattr ( group , ( '%s_%s' % ( family , key ) ) , val ) #NEWLINE# #UNINDENT# #UNINDENT# ( ocrs , icrs ) = ( [ ] , [ ] ) #NEWLINE# try : #NEWLINE# #INDENT# ctime = xdi . CountTime #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# ctime = ( xdi . TSCALER / 50000000.0 ) #NEWLINE# #UNINDENT# is_xspress3 = any ( [ ( '13QX4' in a [ 1 ] ) for a in xdi . attrs [ 'column' ] . items ( ) ] ) #NEWLINE# group . with_xspress3 = is_xspress3 #NEWLINE# for i in range ( nmca ) : #NEWLINE# #INDENT# ocr = getattr ( xdi , ( 'OutputCounts_mca%i' % ( i + 1 ) ) , None ) #NEWLINE# if ( ocr is None ) : #NEWLINE# #INDENT# ocr = ctime #NEWLINE# #UNINDENT# ocr = ( ocr / ctime ) #NEWLINE# icr = getattr ( xdi , ( 'InputCounts_mca%i' % ( i + 1 ) ) , None ) #NEWLINE# if ( icr is not None ) : #NEWLINE# #INDENT# icr = ( icr / ctime ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# icr = ( 1.0 * ocr ) #NEWLINE# if is_xspress3 : #NEWLINE# #INDENT# tau = group . dtc_taus [ i ] #NEWLINE# icr = estimate_icr ( ( ocr * 1.0 ) , tau , niter = 7 ) #NEWLINE# #UNINDENT# #UNINDENT# ocrs . append ( ocr ) #NEWLINE# icrs . append ( icr ) #NEWLINE# #UNINDENT# labels = [ ] #NEWLINE# sums = OrderedDict ( ) #NEWLINE# for ( i , arrname ) in enumerate ( xdi . array_labels ) : #NEWLINE# #INDENT# dat = getattr ( xdi , arrname ) #NEWLINE# aname = sumname = rawname = arrname . lower ( ) #NEWLINE# if ( ( '_mca' in aname ) and ( 'outputcounts' not in aname ) and ( 'clock' not in aname ) ) : #NEWLINE# #INDENT# ( sumname , imca ) = sumname . split ( '_mca' ) #NEWLINE# imca = ( int ( imca ) - 1 ) #NEWLINE# datraw = ( dat * 1.0 ) #NEWLINE# rawname = ( sumname + '_nodtc' ) #NEWLINE# dat = ( ( dat * icrs [ imca ] ) / ocrs [ imca ] ) #NEWLINE# if any ( np . isnan ( dat ) ) : #NEWLINE# #INDENT# nan_pts = np . where ( np . isnan ( dat ) ) [ 0 ] #NEWLINE# dat [ nan_pts ] = datraw [ nan_pts ] #NEWLINE# #UNINDENT# #UNINDENT# setattr ( group , aname , dat ) #NEWLINE# if ( sumname not in labels ) : #NEWLINE# #INDENT# labels . append ( sumname ) #NEWLINE# sums [ sumname ] = dat #NEWLINE# if ( rawname != sumname ) : #NEWLINE# #INDENT# sums [ rawname ] = datraw #NEWLINE# if ( rawname not in labels ) : #NEWLINE# #INDENT# labels . append ( rawname ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# sums [ sumname ] = ( sums [ sumname ] + dat ) #NEWLINE# if ( rawname != sumname ) : #NEWLINE# #INDENT# sums [ rawname ] = ( sums [ rawname ] + datraw ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for ( name , dat ) in sums . items ( ) : #NEWLINE# #INDENT# if ( not hasattr ( group , name ) ) : #NEWLINE# #INDENT# setattr ( group , name , dat ) #NEWLINE# #UNINDENT# #UNINDENT# for arrname in xdi . array_labels : #NEWLINE# #INDENT# sname = arrname . lower ( ) #NEWLINE# if ( sname not in labels ) : #NEWLINE# #INDENT# labels . append ( sname ) #NEWLINE# #UNINDENT# #UNINDENT# for imca in range ( nmca ) : #NEWLINE# #INDENT# setattr ( group , ( 'ocr_mca%i' % ( imca + 1 ) ) , ocrs [ imca ] ) #NEWLINE# setattr ( group , ( 'icr_mca%i' % ( imca + 1 ) ) , icrs [ imca ] ) #NEWLINE# #UNINDENT# group . array_labels = labels #NEWLINE# return group