Exemplo n.º 1
0
def load_BL7_XAS_files(file_name_filter):
    """helper function to load a bunch of spectra from ALS BL 7.0.1.1 XAS text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for f in files:
        m = re.search('(' + file_name_filter + '.*)\d\.txt$', f)
        if (m):
            filename = f
            print filename
            name = filename
            nametey = name + 'TEY'
            nametfy = name + 'TFY'
            spectra[nametey] = Spectrum()
            spectra[nametey].name = nametey

            spectra[nametfy] = Spectrum()
            spectra[nametfy].name = nametfy

            data = read_bl7011_xas(filename)

            spectra[nametey].EE = data['MonoEnergy']
            spectra[nametey].data = data['Counter1'] / data['Izero']

            spectra[nametfy].EE = data['MonoEnergy']
            spectra[nametfy].data = data['Counter2'] / data['Izero']

    return spectra
Exemplo n.º 2
0
def load_BL7_XAS_files(file_name_filter):
    """helper function to load a bunch of spectra from ALS BL 7.0.1.1 XAS text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for f in files:
        m = re.search('('+file_name_filter+'.*)\d\.txt$',f)
        if (m):
            filename = f
            print filename
            name = filename
            nametey = name+'TEY'
            nametfy = name+'TFY'
            spectra[nametey] = Spectrum()
            spectra[nametey].name = nametey

            spectra[nametfy] = Spectrum()
            spectra[nametfy].name = nametfy

            data = read_bl7011_xas(filename)

            spectra[nametey].EE = data['MonoEnergy']
            spectra[nametey].data = data['Counter1']/data['Izero']

            spectra[nametfy].EE = data['MonoEnergy']
            spectra[nametfy].data = data['Counter2']/data['Izero']

    return spectra
Exemplo n.º 3
0
def load_BL62_text_files(file_name_filter):
    """helper function to load a bunch of spectra from SSRL BL6-2 text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('('+file_name_filter+'.*)\.dat',spec_file)
        if (m):
            name = spec_file
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(name,skip_header=37)
            #print data
            spectra[name].EE = data[:,1]
            spectra[name].data = data[:,1:]

    return spectra
Exemplo n.º 4
0
def load_BL62_text_files(file_name_filter):
    """helper function to load a bunch of spectra from SSRL BL6-2 text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('(' + file_name_filter + '.*)\.dat', spec_file)
        if (m):
            name = spec_file
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(name, skip_header=37)
            #print data
            spectra[name].EE = data[:, 1]
            spectra[name].data = data[:, 1:]

    return spectra
Exemplo n.º 5
0
def load_AugerScan_text_files(file_name_filter):
    """helper function to load a bunch of spectra from AugerScan text files in the current dir"""
    files = os.listdir('.')

    special_chars = r'[ \t\(\"\(\)\*\&\^\%\$\#\@\!\_\+\-\=\[\]\{\}\|\;\'\"\:\/\.\,\<\>\\\?]'

    spectra = {}
    EE = []
    data = []
    i = 0
    for spec_file in files:
        m = re.search('(' + file_name_filter + ')\.txt', spec_file)
        if (m):
            filename = spec_file
            print filename
            f = open(filename, 'r')
            name = m.group(1)
            header = True
            for line in f:
                if (re.search('Element', line)):
                    print '+e'
                    header = False
                    m = re.search(
                        'Element\s(.*);.*;\sDepth Cycle (\d+).*;\sTime Per Step (\d+);\sSweeps (\d+);.*',
                        line)
                    #print m.group(0)
                    label = i  #name+'-'+line
                    i = i + 1
                    #print '+' + label
                    spectrum = Spectrum()
                    spectrum.element = m.group(1)
                    spectrum.depth_cycle = double(m.group(2))
                    spectrum.time_per_step = double(m.group(3))
                    spectrum.sweeps = double(m.group(4))
                    spectrum.name = name
                    spectrum.EE = array([])
                    spectrum.data = array([])
                    spectra[label] = spectrum
                elif header:
                    continue
                elif (re.search('^[\d\.]+\s\d+\s*$', line)):
                    m = re.search('^([\d\.]+)\s(\d+)', line)
                    #print m.group(0)
                    spectra[label].EE = append(spectra[label].EE,
                                               double(m.group(1)))
                    spectra[label].data = append(spectra[label].data,
                                                 double(m.group(2)))

    return spectra
Exemplo n.º 6
0
def load_BL7_XES_files(file_name_filter):
    """helper function to load a bunch of spectra from ALS BL 7.0.1.1 XES text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('('+file_name_filter+'.*)\_spec.txt',spec_file)
        if (m):
            filename = spec_file
            name = filename
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(filename,skip_header=0)
            #print data
            spectra[name].EE = data[:-1,0]
            spectra[name].data = data[:-1,1]

    return spectra
Exemplo n.º 7
0
def load_SUPER_text_files(file_name_filter):
    """helper function to load a bunch of spectra from AugerScan text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('('+file_name_filter+'.*)\.\d\d\d',spec_file)
        if (m):
            filename = spec_file
            name = filename
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(filename,skip_header=12)
            #print data
            spectra[name].EE = data[:,0]
            spectra[name].data = data[:,1:]

    return spectra
Exemplo n.º 8
0
def load_BL7_XES_files(file_name_filter):
    """helper function to load a bunch of spectra from ALS BL 7.0.1.1 XES text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('(' + file_name_filter + '.*)\_spec.txt', spec_file)
        if (m):
            filename = spec_file
            name = filename
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(filename, skip_header=0)
            #print data
            spectra[name].EE = data[:-1, 0]
            spectra[name].data = data[:-1, 1]

    return spectra
Exemplo n.º 9
0
def load_SUPER_text_files(file_name_filter):
    """helper function to load a bunch of spectra from AugerScan text files in the current dir"""
    files = os.listdir('.')

    spectra = {}

    for spec_file in files:
        m = re.search('(' + file_name_filter + '.*)\.\d\d\d', spec_file)
        if (m):
            filename = spec_file
            name = filename
            spectra[name] = Spectrum()
            spectra[name].name = name
            data = np.genfromtxt(filename, skip_header=12)
            #print data
            spectra[name].EE = data[:, 0]
            spectra[name].data = data[:, 1:]

    return spectra
Exemplo n.º 10
0
def load_AugerScan_text_files(file_name_filter):
    """helper function to load a bunch of spectra from AugerScan text files in the current dir"""
    files = os.listdir('.')

    special_chars = r'[ \t\(\"\(\)\*\&\^\%\$\#\@\!\_\+\-\=\[\]\{\}\|\;\'\"\:\/\.\,\<\>\\\?]'

    spectra = {}
    EE=[]
    data=[]
    i = 0;
    for spec_file in files:
        m = re.search('('+file_name_filter+')\.txt',spec_file)
        if (m):
            filename = spec_file
            print filename
            f = open(filename, 'r')
            name = m.group(1)
            header = True
            for line in f:
                if (re.search('Element',line)):
                    print '+e'
                    header = False
                    m = re.search('Element\s(.*);.*;\sDepth Cycle (\d+).*;\sTime Per Step (\d+);\sSweeps (\d+);.*',line)
                    #print m.group(0)
                    label = i#name+'-'+line
                    i = i+1
                    #print '+' + label
                    spectrum = Spectrum()
                    spectrum.element = m.group(1)
                    spectrum.depth_cycle = double(m.group(2))
                    spectrum.time_per_step = double(m.group(3))
                    spectrum.sweeps = double(m.group(4))
                    spectrum.name = name
                    spectrum.EE=array([])
                    spectrum.data=array([])
                    spectra[label] = spectrum
                elif header:
                    continue
                elif (re.search('^[\d\.]+\s\d+\s*$',line)):
                    m = re.search('^([\d\.]+)\s(\d+)',line)
                    #print m.group(0)
                    spectra[label].EE = append(spectra[label].EE, double(m.group(1)))
                    spectra[label].data = append(spectra[label].data, double(m.group(2)))

    return spectra
Exemplo n.º 11
0
    def load_from_file(self, filename=None, filefilter=None):
        ## fix reload behavoir to maintain existing Spectrum objects
        self.spectra = []
        self.names = []

        if filename:
            if filefilter == 'VAMAS (*.vms)':
                experiment = VAMASExperiment(filename)
                i = 1
                for block in experiment.blocks:  #VAMAS file may contain multiple spectra
                    treename = 'B-' + str(i) + '-' + block.comment
                    treename = treename.replace('Not Specified', '')  #DFO
                    treename = treename.strip()
                    spectrum = Spectrum()
                    spectrum.EE = block.abscissa()
                    spectrum.name = os.path.basename(filename) + '-' + treename
                    spectrum.data = block.ordinate(0) / (
                        block.number_of_scans_to_compile_this_block *
                        block.signal_collection_time)
                    spectrum.raw_data = spectrum.data.copy()  #keep a copy
                    if block.analyser_mode in ('FAT', 'FRR'):
                        spectrum.spec_mode = block.analyser_mode
                    spectrum.pass_energy_ratio = block.analyser_pass_energy_of_retard_ratio_or_mass_resolution

                    self.spectra.append(spectrum)
                    self.names.append(treename)
                    i += 1
            elif filefilter == 'SSRL (*.dat)':
                experiment = np.genfromtxt(filename, skip_header=37)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 2]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 3]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 2] / experiment[:, 1]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I1/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 6]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'ICR'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 7]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'FF1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:, 1]
                spectrum.data = experiment[:, 6] / experiment[:, 1]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'ICR/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)
            elif filefilter == 'BL7.0.1.1 XAS (*.txt)':
                experiment = read_bl7011_xas(filename)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter1']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TEY'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter2']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TFY'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter1'] / experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TEY/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter2'] / experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TFY/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

            elif filefilter == 'AugerScan (*.txt)':
                experiment = read_augerscan(filename)
                spectrum = Spectrum()
                spectrum.EE = -experiment['Energy']
                #print spectrum.EE
                spectrum.data = experiment['Counts']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                #print spectrum.data
                spectrum.name = 'Region 1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

            elif filefilter == 'SUPER (*)':
                pass
Exemplo n.º 12
0
    def load_from_file(self, filename=None, filefilter=None):
        ## fix reload behavoir to maintain existing Spectrum objects
        self.spectra = []
        self.names = []

        if filename:
            if filefilter == 'VAMAS (*.vms)':
                experiment = VAMASExperiment(filename)
                i=1
                for block in experiment.blocks:    #VAMAS file may contain multiple spectra
                    treename = 'B-' + str(i) + '-' + block.comment
                    treename = treename.replace('Not Specified','')    #DFO
                    treename = treename.strip()
                    spectrum = Spectrum()
                    spectrum.EE = block.abscissa()
                    spectrum.name = os.path.basename(filename) + '-' + treename
                    spectrum.data = block.ordinate(0)/(block.number_of_scans_to_compile_this_block * block.signal_collection_time)
                    spectrum.raw_data = spectrum.data.copy()  #keep a copy
                    if block.analyser_mode in ('FAT','FRR') :
                        spectrum.spec_mode = block.analyser_mode
                    spectrum.pass_energy_ratio = block.analyser_pass_energy_of_retard_ratio_or_mass_resolution

                    self.spectra.append(spectrum)
                    self.names.append(treename)
                    i += 1
            elif filefilter == 'SSRL (*.dat)':
                experiment = np.genfromtxt(filename,skip_header=37)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,2]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,3]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,2]/experiment[:,1]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I1/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,6]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'ICR'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,7]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'FF1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment[:,1]
                spectrum.data = experiment[:,6]/experiment[:,1]
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'ICR/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)
            elif filefilter == 'BL7.0.1.1 XAS (*.txt)':
                experiment = read_bl7011_xas(filename)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter1']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TEY'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter2']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TFY'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter1']/experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TEY/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

                spectrum = Spectrum()
                spectrum.EE = experiment['MonoEnergy']
                spectrum.data = experiment['Counter2']/experiment['Izero']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                spectrum.name = 'TFY/I0'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

            elif filefilter == 'AugerScan (*.txt)':
                experiment = read_augerscan(filename)
                spectrum = Spectrum()
                spectrum.EE = -experiment['Energy']
                #print spectrum.EE
                spectrum.data = experiment['Counts']
                spectrum.raw_data = spectrum.data.copy()  #keep a copy
                #print spectrum.data
                spectrum.name = 'Region 1'
                self.spectra.append(spectrum)
                self.names.append(spectrum.name)

            elif filefilter == 'SUPER (*)':
                pass