コード例 #1
0
ファイル: base_fluo_fitter.py プロジェクト: markbasham/Savu
    def setPositions(self, in_meta_data):
        paramdict = XRFDataset().paramdict
        paramdict["FitParams"]["pileup_cutoff_keV"] = \
            self.parameters["pileup_cutoff_keV"]
        paramdict["FitParams"]["include_pileup"] = \
            self.parameters["include_pileup"]
        paramdict["FitParams"]["include_escape"] = \
            self.parameters["include_escape"]
        paramdict["FitParams"]["fitted_energy_range_keV"] = \
            self.parameters["fitted_energy_range_keV"]
        if self.parameters['mono_energy'] is None:
            paramdict["Experiment"]["incident_energy_keV"] = \
                in_meta_data.get_meta_data("mono_energy")
        else:
            paramdict["Experiment"]["incident_energy_keV"] = \
                self.parameters['mono_energy']
        paramdict["Experiment"]["elements"] = \
            self.parameters["elements"]
        engy = self.findLines(paramdict)
        # make it an index since this is what find peak will also give us
        #         print 'basefluo meta is:'+str(in_meta_data.get_dictionary().keys())
        axis = self.axis = in_meta_data.get_meta_data("energy")
        dq = axis[1] - axis[0]
        logging.debug("the peak energies are:" + str(engy))
        logging.debug("the offset is" + str(axis[0]))
        self.idx = np.round((engy - axis[0]) / dq).astype(int)

        return self.idx
コード例 #2
0
ファイル: base_fluo_fitter.py プロジェクト: markbasham/Savu
    def findLines(self, paramdict=XRFDataset().paramdict):
        """
        Calculates the line energies to fit
        """
        # Incident Energy  used in the experiment
        # Energy range to use for fitting
        pileup_cut_off = paramdict["FitParams"]["pileup_cutoff_keV"]
        include_pileup = paramdict["FitParams"]["include_pileup"]
        include_escape = paramdict["FitParams"]["include_escape"]
        fitting_range = paramdict["FitParams"]["fitted_energy_range_keV"]
        #         x = paramdict["FitParams"]["mca_energies_used"]
        energy = paramdict["Experiment"]["incident_energy_keV"]
        detectortype = 'Vortex_SDD_Xspress'
        fitelements = paramdict["Experiment"]["elements"]
        peakpos = []
        escape_peaks = []
        for _j, el in enumerate(fitelements):
            z = xl.SymbolToAtomicNumber(str(el))
            for i, shell in enumerate(shells):
                if (xl.EdgeEnergy(z, shell) < energy - 0.5):
                    linepos = 0.0
                    count = 0.0
                    for line in transitions[i]:
                        en = xl.LineEnergy(z, line)
                        if (en > 0.0):
                            linepos += en
                            count += 1.0
                    if (count == 0.0):
                        break
                    linepos = linepos / count
                    if (linepos > fitting_range[0]
                            and linepos < fitting_range[1]):
                        peakpos.append(linepos)
        peakpos = np.array(peakpos)
        too_low = set(list(peakpos[peakpos > fitting_range[0]]))
        too_high = set(list(peakpos[peakpos < fitting_range[1]]))
        bar = list(too_low and too_high)
        bar = np.unique(bar)
        peakpos = list(bar)
        peaks = []
        peaks.extend(peakpos)
        if (include_escape):
            for i in range(len(peakpos)):
                escape_energy = calc_escape_energy(peakpos[i], detectortype)[0]
                if (escape_energy > fitting_range[0]):
                    if (escape_energy < fitting_range[1]):
                        escape_peaks.extend([escape_energy])

    #         print escape_peaks
            peaks.extend(escape_peaks)

        if (include_pileup):  # applies just to the fluorescence lines
            pileup_peaks = []
            peakpos1 = np.array(peakpos)
            peakpos_high = peakpos1[peakpos1 > pileup_cut_off]
            peakpos_high = list(peakpos_high)
            for i in range(len(peakpos_high)):
                foo = [peakpos_high[i] + x for x in peakpos_high[i:]]
                foo = np.array(foo)
                pileup_peaks.extend(foo)
            pileup_peaks = np.unique(sorted(pileup_peaks))
            peaks.extend(pileup_peaks)
        peakpos = peaks
        peakpos = np.array(peakpos)
        too_low = set(list(peakpos[peakpos > fitting_range[0]]))
        too_high = set(list(peakpos[peakpos < fitting_range[1] - 0.5]))
        bar = list(too_low and too_high)
        bar = np.unique(bar)
        peakpos = list(bar)
        peakpos = np.unique(peakpos)
        #         print peakpos
        return peakpos
コード例 #3
0
    def prep_xrfd(self, in_meta_data):
        self.axis = in_meta_data.get_meta_data("energy")
        xrfd = XRFDataset()
        # now to overide the experiment
        xrfd.paramdict["Experiment"] = {}
        xrfd.paramdict["Experiment"]["incident_energy_keV"] = \
            self.parameters["mono_energy"]
        #         print xrfd.paramdict["Experiment"]["incident_energy_keV"]
        xrfd.paramdict["Experiment"]["collection_time"] = 1
        xrfd.paramdict["Experiment"]['Attenuators'] = \
            self.parameters['sample_attenuators']
        xrfd.paramdict["Experiment"]['detector_distance'] = \
            self.parameters['detector_distance']
        xrfd.paramdict["Experiment"]['elements'] = \
            self.parameters['elements']
        xrfd.paramdict["Experiment"]['incident_angle'] = \
            self.parameters['incident_angle']
        xrfd.paramdict["Experiment"]['exit_angle'] = \
            self.parameters['exit_angle']
        xrfd.paramdict["Experiment"]['photon_flux'] = self.parameters['flux']

        # overide the fitting parameters
        xrfd.paramdict["FitParams"]["background"] = 'strip'
        xrfd.paramdict["FitParams"][
            "fitted_energy_range_keV"] = self.parameters[
                "fitted_energy_range_keV"]
        xrfd.paramdict["FitParams"]["include_pileup"] = self.parameters[
            "include_pileup"]
        xrfd.paramdict["FitParams"]["include_escape"] = self.parameters[
            "include_escape"]
        datadict = {}
        datadict["rows"] = self.get_max_frames()
        datadict["cols"] = 1  # we will just treat it as one long row
        datadict["average_spectrum"] = np.zeros_like(self.axis)
        datadict["Detectors"] = {}
        datadict["Detectors"]["type"] = 'Vortex_SDD_Xspress'
        xrfd.xrfdata(datadict)
        xrfd._createSpectraMatrix()
        if xrfd.paramdict['FitParams']['mca_energies_used'] == self.axis:
            pass
        else:
            self.axis = xrfd.paramdict['FitParams']['mca_energies_used']
        return xrfd
コード例 #4
0
ファイル: fastxrf_fitting.py プロジェクト: mjn19172/Savu
    def pre_process(self, exp):
        """
        This method is called after the plugin has been created by the
        pipeline framework as a pre-processing step.
        """
        in_data_list = self.parameters["in_datasets"]
        in_d1 = exp.index["in_data"][in_data_list[0]]
        mData = in_d1.meta_data # the metadata
        # populate the dictionary from the input parameters

        
        xrfd=XRFDataset()
        # now to overide the experiment
        xrfd.paramdict["Experiment"]={}
        xrfd.paramdict["Experiment"]["incident_energy_keV"] = mData.get_meta_data("mono_energy")/1000.
        xrfd.paramdict["Experiment"]["collection_time"] = 1
        xrfd.paramdict["Experiment"]['Attenuators'] = self.parameters['sample_attenuators']
        xrfd.paramdict["Experiment"]['detector_distance'] = self.parameters['detector_distance']
        xrfd.paramdict["Experiment"]['elements'] = self.parameters['fit_elements'].split(',')#['Zn', 'Cu', 'Fe', 'Cr', 'Cl', 'Br', 'Kr']#
        xrfd.paramdict["Experiment"]['incident_angle'] = self.parameters['incident_angle']
        xrfd.paramdict["Experiment"]['exit_angle'] = self.parameters['exit_angle']
        xrfd.paramdict["Experiment"]['photon_flux'] = self.parameters['flux']
        # overide the detector
#         xrfd.paramdict["Detectors"]={}
#         xrfd.paramdict["Detectors"]["type"] = 'Vortex_SDD_Xspress'#str(self.parameters['detector_type'])
        # overide the fitting parameters
        xrfd.paramdict["FitParams"]["background"] = 'strip'#self.parameters['background']
        xrfd.paramdict["FitParams"]["fitted_energy_range_keV"] = [2., 18.]#self.parameters['fit_range']
        xrfd.paramdict["FitParams"]["include_pileup"] = 1#self.parameters['include_pileup']
        xrfd.paramdict["FitParams"]["include_escape"] = 1#self.parameters['include_escape']
        
        datadict = {}
        datadict["rows"] = self.get_max_frames()
        datadict["cols"] = 1
        datadict["average_spectrum"] = mData.get_meta_data("average")#self.parameters['average_spectrum']
        datadict["Detectors"]={}
        datadict["Detectors"]["type"] = 'Vortex_SDD_Xspress'
        xrfd.xrfdata(datadict)
        xrfd._createSpectraMatrix()
        #I only know the output shape here!xrfd.matrixdict['Total_Matrix'].shape
        
        params = [xrfd]
        return params
コード例 #5
0
ファイル: fastxrf_fitting.py プロジェクト: mjn19172/Savu
    def setup(self, experiment):

        chunk_size = self.get_max_frames()

        #-------------------setup input datasets-------------------------

        # get a list of input dataset names required for this plugin
        in_data_list = self.parameters["in_datasets"]
        # get all input dataset objects
        in_d1 = experiment.index["in_data"][in_data_list[0]]
        # set all input data patterns
        in_d1.set_current_pattern_name("SPECTRUM") # we take in a pattern
        # set frame chunk
        in_d1.set_nFrames(chunk_size)
        
        #----------------------------------------------------------------

        #------------------setup output datasets-------------------------

        # get a list of output dataset names created by this plugin        
        '''
        This type of dataset should output a few things I think.
        1/ Concentration/sum map (including the channel name)
        2/ The average fit
        3/ The background/scattering fit
        4/ The chisq
        5/ The residual (another spectrum I guess...)
       
        if I have these:
        for i,j in enumerate(xrfd.matrixdict['Descriptions']):print i,j DICT -descriptions
        xrfd.matrixdict['Total_Matrix'] # CHARACTERISTIC CURVES
        xrfd.fitdict['parameters'] # WEIGHTS
        xrfd.fitdict['chisq'] - NUMBER
        xrfd.fitdict['resid']   SPECTRUM
        - the rest is easy (ish)
        for now, will just hack it slightly...(sorry :-S)
        '''        
        # will force the code to tell me what it will output!DO IT
        mData = in_d1.meta_data
        datadict = {}
        xrfd=XRFDataset()
        # first chuck in the fitting parameters
        xrfd.paramdict["FitParams"]["background"] = self.parameters['background']
        xrfd.paramdict["FitParams"]["fitted_energy_range_keV"] = self.parameters['fit_range']
        xrfd.paramdict["FitParams"]["include_pileup"] = self.parameters['include_pileup']
        xrfd.paramdict["FitParams"]["include_escape"] = self.parameters['include_escape']
        xrfd.paramdict["Experiment"]['elements'] = self.parameters['fit_elements'].split(',')
        print xrfd.paramdict["Experiment"]['elements'],type(xrfd.paramdict["Experiment"]['elements'])
        datadict["cols"] = 1
        datadict["rows"] = 1
        datadict["Experiment"]={}
        datadict["Experiment"]["incident_energy_keV"] = mData.get_meta_data("mono_energy")/1000.
        datadict["Experiment"]["collection_time"] =1. #or indeed anything. This isn't used!
        datadict["Detectors"]={}
        datadict["Detectors"]["type"] = self.parameters['detector_type']
        npts = xrfd.paramdict['Detectors'][datadict["Detectors"]["type"]]['no_of_pixels']
        datadict["average_spectrum"] = np.zeros((npts,))#mData.get_meta_data("average")
        xrfd.xrfdata(datadict)
        #print type(datadict["Experiment"]["incident_energy_keV"])
        xrfd._createSpectraMatrix()
        
        metadata=xrfd.matrixdict['Descriptions']
        num_els = len(xrfd.matrixdict['Descriptions'])
        spectrum_length = len(xrfd.paramdict["FitParams"]["mca_channels_used"][0])
        
        
        out_data_list = self.parameters["out_datasets"]
        out_d1 = experiment.create_data_object("out_data", out_data_list[0])

        out_d1.meta_data.copy_dictionary(in_d1.meta_data.get_dictionary(), rawFlag=True)
        out_d1.meta_data.set_meta_data('Curve_names',metadata)
        characteristic_curves=xrfd.matrixdict["Total_Matrix"]
        out_d1.meta_data.set_meta_data('Characteristic_curves',characteristic_curves)
        # set pattern for this plugin and the shape
        out_d1.set_current_pattern_name("SPECTRUM_STACK")
        inshape = in_d1.get_shape()
        outshape = inshape[:3]+(num_els, spectrum_length)
        out_d1.set_shape(outshape)#
        
        # now to set the output data patterns
        out_d1.add_pattern("SPECTRUM_STACK", core_dir = (-2,-1), slice_dir = range(len(outshape)-2))# for some reason I HAVE to have this.... annoying
        out_d1.add_pattern("SPECTRUM", core_dir = (-1,), slice_dir = range(len(outshape)-1))
        out_d1.add_pattern("CHANNEL", core_dir = (-2,), slice_dir = range(len(outshape)-2).append(-1))
        # we haven't changed the motors yet so...
        motor_type=mData.get_meta_data("motor_type")
        projection = []
        projection_slice = []
        for item,key in enumerate(motor_type):
            if key == 'translation':
                projection.append(item)
            elif key !='translation':
                projection_slice.append(item)
            if key == 'rotation':
                rotation = item # we will assume one rotation for now to save my headache
        projdir = tuple(projection)
        projsli = tuple(projection_slice)


        if mData.get_meta_data("is_map"):
            ndims = range(len(outshape))
            ovs = []
            for i in ndims:
                if i!=projdir[0]:
                    if i!=projdir[1]:
                        ovs.append(i)
            out_d1.add_pattern("PROJECTION", core_dir = projdir, slice_dir = ovs)# two translation axes
            
        if mData.get_meta_data("is_tomo"):
            ndims = range(len(outshape))
            ovs = []
            for i in ndims:
                if i!=rotation:
                    if i!=projdir[1]:
                        ovs.append(i)
            out_d1.add_pattern("SINOGRAM", core_dir = (rotation,projdir[-1]), slice_dir = ovs)#rotation and fast axis
        # set frame chunk
        print outshape
        out_d1.set_nFrames(chunk_size)
コード例 #6
0
ファイル: fastxrf_fitting.py プロジェクト: FedeMPouzols/Savu
    def prep_xrfd(self, in_meta_data):
        self.axis = in_meta_data.get_meta_data("energy")
        xrfd = XRFDataset()
        # now to overide the experiment
        xrfd.paramdict["Experiment"] = {}
        xrfd.paramdict["Experiment"]["incident_energy_keV"] = self.parameters["mono_energy"]
        #         print xrfd.paramdict["Experiment"]["incident_energy_keV"]
        xrfd.paramdict["Experiment"]["collection_time"] = 1
        xrfd.paramdict["Experiment"]["Attenuators"] = self.parameters["sample_attenuators"]
        xrfd.paramdict["Experiment"]["detector_distance"] = self.parameters["detector_distance"]
        xrfd.paramdict["Experiment"]["elements"] = self.parameters["elements"]
        xrfd.paramdict["Experiment"]["incident_angle"] = self.parameters["incident_angle"]
        xrfd.paramdict["Experiment"]["exit_angle"] = self.parameters["exit_angle"]
        xrfd.paramdict["Experiment"]["photon_flux"] = self.parameters["flux"]

        # overide the fitting parameters
        xrfd.paramdict["FitParams"]["background"] = "strip"
        xrfd.paramdict["FitParams"]["fitted_energy_range_keV"] = self.parameters["fitted_energy_range_keV"]
        xrfd.paramdict["FitParams"]["include_pileup"] = self.parameters["include_pileup"]
        xrfd.paramdict["FitParams"]["include_escape"] = self.parameters["include_escape"]
        datadict = {}
        datadict["rows"] = self.get_max_frames()
        datadict["cols"] = 1  # we will just treat it as one long row
        datadict["average_spectrum"] = np.zeros_like(self.axis)
        datadict["Detectors"] = {}
        datadict["Detectors"]["type"] = "Vortex_SDD_Xspress"
        xrfd.xrfdata(datadict)
        xrfd._createSpectraMatrix()
        if xrfd.paramdict["FitParams"]["mca_energies_used"] == self.axis:
            pass
        else:
            self.axis = xrfd.paramdict["FitParams"]["mca_energies_used"]
        return xrfd