Exemple #1
0
def _read_spectra(fname,**kw):
    """
    read spectra files and return a list of med or xrf objects
    """
    start   = kw.get('start',-1)
    end     = kw.get('end',-1)
    nfmt    = kw.get('nfmt',3)
    fmt     = kw.get('fmt','CARS')
    #
    bad     = kw.get('bad_mca_idx',[])
    total   = kw.get('total',True)
    align   = kw.get('align',True)
    correct = kw.get('correct',True)
    tau     = kw.get('tau',None)
    #
    xrf     = kw.get('xrf',False)
    det_idx = kw.get('det_idx',0)
    emin    = kw.get('emin',-1.)
    emax    = kw.get('emax',-1.)
    xrf_params = kw.get('xrf_params',{})
    lines      = kw.get('lines',None)
        
    if start > -1:
        if end == -1:
            ret = self._spectra_range(fname)  
            if ret:
                (start,end) = ret
            else:
                print "No files found"
                return None
        if xrf:
            spectra = xrf_data.read_files(fname,start=start,end=end,nfmt=nfmt,
                                          bad_mca_idx=bad,total=total,align=align,
                                          correct=correct,tau=tau,det_idx=det_idx,
                                          emin=emin,emax=emax,xrf_params=xrf_params,
                                          lines=lines,fmt=fmt)
        else:
            spectra = med_data.read_files(fname,start=start,end=end,nfmt=nfmt,
                                          bad_mca_idx=bad,total=total,align=align,
                                          correct=correct,tau=tau,fmt=fmt)
    else:
        if xrf:
            spectra = xrf_data.read_file(fname,bad_mca_idx=bad,total=total,align=align,
                                         correct=correct,tau=tau,det_idx=det_idx,
                                         emin=emin,emax=emax,xrf_params=xrf_params,
                                         lines=lines,fmt=fmt)
        else:
            spectra = med_data.read_file(fname,bad_mca_idx=bad,total=total,align=align,
                                         correct=correct,tau=tau,fmt=fmt)
    if spectra == None: return None
    if type(spectra) != types.ListType:
        spectra = [spectra]
    return spectra
Exemple #2
0
def read_files(prefix,
               start=0,
               end=100,
               nfmt=3,
               bad_mca_idx=[],
               total=True,
               align=True,
               correct=True,
               tau=None,
               det_idx=0,
               emin=-1.0,
               emax=-1.0,
               xrf_params={},
               lines=None,
               fmt='CARS'):
    """
    Read multiple detector files

    Notes:
    ------
    * xrf_params should have the same format as returned
      by Xrf.get_params
    
    * if xrf_params == None: returns a list of med objects
      otherwise: returns a list of xrf objects (default)
    """
    med = read_files(prefix,
                     start=start,
                     end=end,
                     nfmt=nfmt,
                     bad_mca_idx=bad_mca_idx,
                     total=total,
                     align=align,
                     correct=correct,
                     tau=tau,
                     fmt=fmt)
    if med == None: return None

    xrf = med2xrf(med,
                  xrf_params=xrf_params,
                  lines=lines,
                  det_idx=det_idx,
                  emin=emin,
                  emax=emax)
    return xrf
Exemple #3
0
def read_files(
    prefix,
    start=0,
    end=100,
    nfmt=3,
    bad_mca_idx=[],
    total=True,
    align=True,
    correct=True,
    tau=None,
    det_idx=0,
    emin=-1.0,
    emax=-1.0,
    xrf_params={},
    lines=None,
    fmt="CARS",
):
    """
    Read multiple detector files

    Notes:
    ------
    * xrf_params should have the same format as returned
      by Xrf.get_params
    
    * if xrf_params == None: returns a list of med objects
      otherwise: returns a list of xrf objects (default)
    """
    med = read_files(
        prefix,
        start=start,
        end=end,
        nfmt=nfmt,
        bad_mca_idx=bad_mca_idx,
        total=total,
        align=align,
        correct=correct,
        tau=tau,
        fmt=fmt,
    )
    if med == None:
        return None

    xrf = med2xrf(med, xrf_params=xrf_params, lines=lines, det_idx=det_idx, emin=emin, emax=emax)
    return xrf
Exemple #4
0
def _read_spectra(fname, **kw):
    """
    read spectra files and return a list of med or xrf objects
    """
    start = kw.get('start', -1)
    end = kw.get('end', -1)
    nfmt = kw.get('nfmt', 3)
    fmt = kw.get('fmt', 'CARS')
    #
    bad = kw.get('bad_mca_idx', [])
    total = kw.get('total', True)
    align = kw.get('align', True)
    correct = kw.get('correct', True)
    tau = kw.get('tau', None)
    #
    xrf = kw.get('xrf', False)
    det_idx = kw.get('det_idx', 0)
    emin = kw.get('emin', -1.)
    emax = kw.get('emax', -1.)
    xrf_params = kw.get('xrf_params', {})
    lines = kw.get('lines', None)

    if start > -1:
        if end == -1:
            ret = self._spectra_range(fname)
            if ret:
                (start, end) = ret
            else:
                print "No files found"
                return None
        if xrf:
            spectra = xrf_data.read_files(fname,
                                          start=start,
                                          end=end,
                                          nfmt=nfmt,
                                          bad_mca_idx=bad,
                                          total=total,
                                          align=align,
                                          correct=correct,
                                          tau=tau,
                                          det_idx=det_idx,
                                          emin=emin,
                                          emax=emax,
                                          xrf_params=xrf_params,
                                          lines=lines,
                                          fmt=fmt)
        else:
            spectra = med_data.read_files(fname,
                                          start=start,
                                          end=end,
                                          nfmt=nfmt,
                                          bad_mca_idx=bad,
                                          total=total,
                                          align=align,
                                          correct=correct,
                                          tau=tau,
                                          fmt=fmt)
    else:
        if xrf:
            spectra = xrf_data.read_file(fname,
                                         bad_mca_idx=bad,
                                         total=total,
                                         align=align,
                                         correct=correct,
                                         tau=tau,
                                         det_idx=det_idx,
                                         emin=emin,
                                         emax=emax,
                                         xrf_params=xrf_params,
                                         lines=lines,
                                         fmt=fmt)
        else:
            spectra = med_data.read_file(fname,
                                         bad_mca_idx=bad,
                                         total=total,
                                         align=align,
                                         correct=correct,
                                         tau=tau,
                                         fmt=fmt)
    if spectra == None: return None
    if type(spectra) != types.ListType:
        spectra = [spectra]
    return spectra