Module Expr Str Import alias identifier ImportFrom alias alias ImportFrom alias alias ImportFrom alias FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad NameLoad Str Str Str decorator_list ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str Str Str body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr If BoolOpAnd Call AttributeLoad AttributeLoad NameLoad attr attr Str Call AttributeLoad AttributeLoad NameLoad attr attr Str body Assign AttributeStore NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Slice Num Num decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad Num Str Num Num Num Str Num Num Num Num Num kwarg body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr ListLoad Assign AttributeStore NameLoad attr ListLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad If CompareIsNot NameLoad NameLoad body Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore Str Return BinOpMod NameLoad TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Str Num Num Num NameLoad NameLoad body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign NameStore ListComp Call AttributeLoad AttributeLoad NameLoad attr attr comprehension NameStore AttributeLoad NameLoad attr If CompareIn Call AttributeLoad NameLoad attr NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore NameLoad If Call NameLoad NameLoad NameLoad body Assign NameStore NameLoad orelse If BoolOpAnd Call NameLoad NameLoad NameLoad CompareLt NameLoad Call NameLoad AttributeLoad NameLoad attr body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad orelse If Call NameLoad NameLoad TupleLoad NameLoad NameLoad body Assign NameStore ListComp Call AttributeLoad AttributeLoad NameLoad attr attr comprehension NameStore AttributeLoad NameLoad attr For TupleStore NameStore NameStore Call NameLoad NameLoad body If Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Break If CompareIs NameLoad NameLoad body Return NameLoad Return Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str Str Str body Expr Str If BoolOpAnd CompareGt Call NameLoad NameLoad Num CompareGt Call NameLoad NameLoad Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If CompareIsNot NameLoad NameLoad body Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str If BoolOpOr CompareLtE AttributeLoad NameLoad attr Num CompareLtE AttributeLoad NameLoad attr Num body Assign AttributeStore NameLoad attr Num Return If CompareGt AttributeLoad NameLoad attr Num body Assign NameStore BinOpDiv AttributeLoad NameLoad attr AttributeLoad NameLoad attr orelse Assign NameStore NameLoad If CompareGtE AttributeLoad NameLoad attr Num body Assign NameStore Call NameLoad NameLoad AttributeLoad NameLoad attr If CompareIs NameLoad NameLoad body Assign NameStore Num Assign AttributeStore NameLoad attr NameLoad orelse If CompareGt AttributeLoad NameLoad attr Num body Assign NameStore BinOpDiv AttributeLoad NameLoad attr AttributeLoad NameLoad attr orelse Assign NameStore NameStore NameLoad Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword NameLoad keyword NameLoad If CompareLtE AttributeLoad NameLoad attr Num body Print Str Assign AttributeStore NameLoad attr Num decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If NameLoad body Return Call AttributeLoad BinOpMult AttributeLoad NameLoad attr AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr orelse Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr BinOpAdd AttributeLoad NameLoad attr BinOpMult NameLoad BinOpAdd AttributeLoad NameLoad attr BinOpMult NameLoad AttributeLoad NameLoad attr Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore Call NameLoad NameLoad Str Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr If CompareIsNot NameLoad NameLoad body For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Assign NameStore Str For TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpMod NameLoad TupleLoad BinOpAdd NameLoad Num AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str For TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign NameStore Num If CompareGt NameLoad Num body Assign NameStore Call AttributeLoad NameLoad attr Call NameLoad NameLoad Num Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str Call NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str Call NameLoad AttributeLoad NameLoad attr For TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad AttributeLoad NameLoad attr For NameStore AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str For NameStore AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Expr Call AttributeLoad NameLoad attr decorator_list decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad Num Num Num Num Str Str Num Num Num Num Num NameLoad kwarg body Expr Str Return Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad NameLoad decorator_list FunctionDef arguments args defaults body Return TupleLoad Str Dict Str NameLoad decorator_list
N/A N/A 
This module defines a device-independent MultiChannel Analyzer (MCA) class.

Authors/Modifications:
----------------------
* Mark Rivers, GSECARS
* Modified for Tdl, tpt
* modified and simplified for Larch, M Newville
 N/A numpy np larch Group isgroup larch_plugins.xrf.deadtime calc_icr correction_factor larch_plugins.xrf.roi ROI isLarchMCAGroup N/A N/A grp N/A N/A N/A tests whether variable holds a valid Larch MCAGroup N/A N/A isgroup grp energy counts rois N/A Environment N/A N/A N/A 
    The "environment" or related parameters for a detector.  These might include
    things like motor positions, temperature, anything that describes the
    experiment.

    Attributes:
    -----------
    * name         # A string name of this parameter, e.g. "13IDD:m1"
    * description  # A string description of this parameter, e.g. "X stage"
    * value        # A string value of this parameter,  e.g. "14.223"
     __init__ N/A N/A self desc addr val N/A N/A N/A N/A self addr N/A N/A addr strip N/A N/A self val N/A N/A val strip N/A N/A self desc N/A N/A desc strip N/A N/A N/A N/A N/A self desc startswith ( N/A N/A N/A self desc endswith ) N/A N/A N/A self desc N/A N/A self desc N/A 1 -1 N/A __repr__ N/A N/A self N/A N/A N/A N/A Environment(desc='%s', val='%s', addr='%s') N/A N/A self desc N/A self val N/A self addr N/A N/A MCA N/A Group N/A N/A 
    MultiChannel Analyzer (MCA) class

    Attributes:
    -----------
    * self.name        = 'mca'  # Name of the mca object
    * self.nchans      = 2048   # number of mca channels
    * self.counts      = None   # MCA data

    # Counting parameters
    * self.start_time   = ''    # Start time and date, a string
    * self.live_time    = 0.    # Elapsed live time in seconds
    * self.real_time    = 0.    # Elapsed real time in seconds
    * self.read_time    = 0.    # Time that the MCA was last read in seconds
    * self.total_counts = 0.    # Total counts between the preset start and stop channels
    * self.input_counts = 0.    # Actual total input counts (eg given by detector software)
                                # Note total_counts and input counts ARE NOT time normalized
                                #
    * self.tau          = -1.0  # Factor for deadtime/detector saturation calculations, ie
                                #     ocr = icr * exp(-icr*tau)
    * self.icr_calc     = -1.0  # Calculated input count rate from above expression
    * self.dt_factor   = 1.0    # deadtime correction factor based on icr,ocr,lt,rt
                                # data_corrected = data * dt_factor
                                #
    # Calibration parameters
    * self.offset       = 0.    # Offset
    * self.slope        = 1.0   # Slope
    * self.quad         = 0.    # Quadratic

    Notes:
    ------
    If input_counts are read from the data file then there is no need for tau
    values (and hence icr_calc is not used) - ie we assume the detector
    provides the icr value.

    The application of corrections uses the following logic:
       if tau > 0 this will be used in the correction factor calculation
       if tau = 0 then we assume ocr = icr in the correction factor calculation
       if tau < 0 (or None):
       if input_counts > 0 this will be used for icr in the factor calculation
          if input_counts <= 0 we assume ocr = icr in the correction factor calculation

    Energy calibration is based on the following:
        energy = offset + slope*channel + quad*channel**2

     __init__ N/A N/A self counts nchans start_time offset slope quad name dt_factor real_time live_time input_counts tau N/A None 2048 0 0 0 mca 1 0 0 0 0 kws N/A N/A N/A self name name N/A N/A self nchans nchans N/A N/A self environ N/A N/A N/A self rois N/A N/A N/A self counts counts N/A N/A self offset offset N/A N/A self slope slope N/A N/A self quad quad N/A N/A self start_time start_time N/A N/A self real_time real_time N/A N/A self live_time live_time N/A N/A self input_counts input_counts N/A N/A self total_counts 0.0 N/A N/A self tau tau N/A N/A self icr_calc -1.0 N/A N/A self bgr None N/A N/A self dt_factor N/A float dt_factor N/A N/A counts None N/A N/A N/A self nchans N/A len counts N/A N/A self total_counts N/A N/A counts sum N/A N/A N/A self get_energy N/A N/A N/A self _calc_correction N/A N/A N/A Group __init__ self N/A __repr__ N/A N/A self N/A N/A N/A form <MCA %s, nchans=%d, counts=%d, realtime=%.1f> N/A N/A form N/A N/A self name N/A self nchans N/A self total_counts N/A self real_time N/A add_roi N/A N/A self name left right bgr_width counts sort N/A 0 0 3 None True N/A N/A add an ROI N/A name N/A N/A name strip N/A roi N/A ROI name name left left right right bgr_width bgr_width counts counts N/A rnames N/A N/A N/A N/A r name lower N/A r N/A self rois N/A N/A N/A N/A name lower rnames N/A N/A iroi N/A N/A rnames index N/A N/A name lower N/A N/A N/A self rois N/A iroi roi N/A N/A N/A N/A N/A self rois append roi N/A sort N/A N/A N/A N/A N/A self rois sort N/A get_roi_counts N/A N/A self roi net N/A False N/A N/A get counts for an roi N/A thisroi None N/A N/A isinstance roi ROI N/A N/A thisroi roi N/A N/A N/A N/A isinstance roi int N/A roi N/A len N/A self rois N/A N/A thisroi N/A N/A self rois N/A roi N/A N/A N/A isinstance roi N/A str unicode N/A N/A rnames N/A N/A N/A N/A r name lower N/A r N/A self rois N/A N/A iroi nam N/A enumerate rnames N/A N/A N/A N/A nam startswith N/A N/A roi lower N/A N/A thisroi N/A N/A self rois N/A iroi N/A N/A N/A thisroi None N/A N/A None N/A N/A N/A thisroi get_counts N/A self counts net net N/A add_environ N/A N/A self desc val addr N/A N/A N/A add an Environment setting N/A N/A N/A N/A len desc 0 N/A N/A len val 0 N/A N/A N/A N/A N/A self environ append N/A Environment desc desc val val addr addr N/A update_correction N/A N/A self tau N/A None N/A N/A 
        Update the deadtime correction

        if tau == None just recompute,
        otherwise assign a new tau and recompute
         N/A N/A tau None N/A N/A N/A self tau tau N/A N/A N/A self _calc_correction N/A _calc_correction N/A N/A self N/A N/A N/A 
        if self.tau > 0 this will be used in the correction factor calculation
        if self.tau = 0 then we assume ocr = icr in the correction factor calculation,
                      ie only lt correction
                     (note deadtime.calc_icr handles above two conditions)
        if self.tau < 0 (or None):
           if input_counts > 0  this will be used for icr in the factor calculation
           if input_counts <= 0 we assume ocr = icr in the correction factor calculation,
                                ie only lt correction
         N/A N/A N/A N/A self live_time 0 N/A N/A self real_time 0 N/A N/A N/A self dt_factor 1.0 N/A N/A N/A N/A self total_counts 0 N/A N/A ocr N/A N/A self total_counts N/A self live_time N/A N/A ocr None N/A N/A N/A self tau 0 N/A N/A icr N/A calc_icr ocr N/A self tau N/A N/A icr None N/A N/A icr 0 N/A N/A self icr_calc icr N/A N/A N/A N/A self input_counts 0 N/A N/A icr N/A N/A self input_counts N/A self live_time N/A N/A icr ocr None N/A N/A self dt_factor N/A correction_factor N/A self real_time N/A self live_time icr icr ocr ocr N/A N/A N/A self dt_factor 0 N/A N/A Error computing counts correction factor --> setting to 1 N/A N/A self dt_factor 1.0 N/A get_counts N/A N/A self correct N/A True N/A N/A 
        Returns the counts array from the MCA

        Note if correct == True the corrected counts is returned. However,
        this does not (re)compute the correction factor, therefore, make
        sure the correction factor is up to date before requesting
        corrected counts...
         N/A correct N/A N/A N/A N/A N/A N/A self dt_factor N/A self counts astype N/A np int N/A N/A N/A self counts N/A get_energy N/A N/A self N/A N/A N/A 
        Returns array of energy for each channel in the MCA spectra.
         N/A chans N/A N/A np arange N/A self nchans dtype N/A np float N/A N/A self energy N/A N/A self offset N/A chans N/A N/A self slope N/A chans N/A self quad N/A N/A self energy N/A save_columnfile N/A N/A self filename headerlines N/A None N/A N/A write summed counts to simple ASCII column file for mca counts N/A f N/A open filename w+ N/A N/A N/A f write N/A #XRF counts for %s
 N/A self name N/A N/A headerlines None N/A N/A i headerlines N/A N/A N/A N/A f write N/A #%s
 i N/A N/A N/A f write #
 N/A N/A N/A f write N/A #EnergyCalib.offset = %.9g 
 N/A self offset N/A N/A N/A f write N/A #EnergyCalib.slope = %.9g 
 N/A self slope N/A N/A N/A f write N/A #EnergyCalib.quad  = %.9g 
 N/A self quad N/A N/A N/A f write N/A #Acquire.RealTime  = %.9g 
 N/A self real_time N/A N/A N/A f write N/A #Acquire.LiveTime  = %.9g 
 N/A self live_time N/A roiform #ROI_%i '%s': [%i, %i]
 N/A N/A i r N/A enumerate N/A self rois N/A N/A N/A N/A f write N/A roiform N/A N/A i 1 N/A r name N/A r left N/A r right N/A N/A N/A f write #-----------------------------------------
 N/A N/A N/A f write #    energy       counts     log_counts
 N/A N/A e d N/A zip N/A self energy N/A self counts N/A N/A dlog 0.0 N/A N/A d 0 N/A N/A dlog N/A N/A np log10 N/A max d 1 N/A N/A N/A f write N/A  %10.4f  %12i  %12.6g
 N/A e d dlog N/A N/A N/A f write N/A N/A N/A f close N/A save_mcafile N/A N/A self filename N/A N/A N/A write MCA file

        Parameters:
        -----------
        * filename: output file name
         N/A fp N/A open filename w N/A N/A N/A fp write VERSION:    3.1
 N/A N/A N/A fp write ELEMENTS:   1
 N/A N/A N/A fp write N/A DATE:       %s
 N/A self start_time N/A N/A N/A fp write N/A CHANNELS:   %i
 N/A len N/A self counts N/A N/A N/A fp write N/A REAL_TIME:  %f
 N/A self real_time N/A N/A N/A fp write N/A LIVE_TIME:  %f
 N/A self live_time N/A N/A N/A fp write N/A CAL_OFFSET: %e
 N/A self offset N/A N/A N/A fp write N/A CAL_SLOPE:  %e
 N/A self slope N/A N/A N/A fp write N/A CAL_QUAD:   %e
 N/A self quad N/A N/A N/A fp write N/A ROIS:      %i
 N/A len N/A self rois N/A N/A i roi N/A enumerate N/A self rois N/A N/A N/A N/A fp write N/A ROI_%i_LEFT:  %i
 N/A i N/A roi left N/A N/A N/A fp write N/A ROI_%i_RIGHT:  %i
 N/A i N/A roi right N/A N/A N/A fp write N/A ROI_%i_LABEL: %s &
 N/A i N/A roi name N/A e N/A self environ N/A N/A N/A N/A fp write N/A ENVIRONMENT: %s="%s" (%s)
 N/A N/A e addr N/A e val N/A e desc N/A N/A N/A fp write DATA: 
 N/A d N/A self counts N/A N/A N/A N/A fp write N/A  %s
 d N/A N/A N/A fp close N/A N/A create_mca N/A N/A counts nchans offset slope quad name start_time real_time live_time dt_factor input_counts tau _larch N/A None 2048 0 0 0 mca 0 0 1 0 0 None kws N/A N/A create an MCA object, containing an XRF (or similar) spectrum

     Parameters:
     ------------
      counts:   counts array
      nchans:   # channels

     Returns:
     ----------
      an MCA object

     N/A N/A MCA counts counts nchans nchans name name start_time start_time offset offset slope slope quad quad dt_factor dt_factor real_time real_time live_time live_time input_counts input_counts tau tau kws N/A registerLarchPlugin N/A N/A N/A N/A N/A N/A _xrf N/A create_mca create_mca N/A