Esempio n. 1
0
    def process_binned(self, E1, E2, Estep, killzone_mask=None):
        """
    Process spectrum binning

    Parameters:
      E1 - low edge of lowest bin
      E2 - high edge of highest bin
      Estep = bin width
      killzone_mask - optional mask of regions to ignore entirely

    See Calibration.process for prerequisites and results
    """
        calib = calibrate.load(self.calibration_file)

        # zero out killzones of calibration matrix
        # (this causes those pixels to be ignored)
        if killzone_mask is not None:
            calib.calibration_matrix[killzone_mask] = 0

        exposure = Exposure()
        exposure.load_multi(self.exposure_files)
        exposure.apply_filters(self.incident_energy, self.filters)
        spectrum = binned_emission_spectrum(calib.calibration_matrix, exposure,
                                            E1, E2, Estep, self.I0)
        self._set_spectrum(spectrum)
Esempio n. 2
0
  def process_binned(self, E1, E2, Estep, killzone_mask=None):
    """
    Process spectrum binning

    Parameters:
      E1 - low edge of lowest bin
      E2 - high edge of highest bin
      Estep = bin width
      killzone_mask - optional mask of regions to ignore entirely

    See Calibration.process for prerequisites and results
    """
    calib = calibrate.load(self.calibration_file)

    # zero out killzones of calibration matrix
    # (this causes those pixels to be ignored)
    if killzone_mask is not None:
      calib.calibration_matrix[killzone_mask] = 0

    exposure = Exposure()
    exposure.load_multi(self.exposure_files)
    exposure.apply_filters(self.incident_energy, self.filters)
    spectrum = binned_emission_spectrum(calib.calibration_matrix,
                                        exposure,
                                        E1,
                                        E2,
                                        Estep,
                                        self.I0)
    self._set_spectrum(spectrum)
Esempio n. 3
0
  def diagnose(self, return_spectra=False, filters=None, progress=None):
    """
    Process all calibration exposures and fit to gaussians, returning parameters of fit

    Example:
      >>> import minixs as mx
      >>> from matplotlib import pyplot as pt
      >>> c = mx.calibrate.Calibration('example.calib')
      >>> d, spectra = c.diagnose(return_spectra = True, filters=[mx.filter.HighFilter(1000)])
      >>> d[:,3] # sigma for gaussian fits
      array([ 0.4258905 ,  0.54773887,  0.58000567,  0.57056559,  0.56539868,
        0.58693027,  0.60704443,  0.61898894,  0.62726828,  0.63519546,
        0.65309853,  0.66317984,  0.67826396,  0.69466781,  0.75039033,
        0.78887514,  0.84248593,  0.8974527 ])
      >>> s = spectra[5]
      >>> pt.plot(s.emission, s.intensity, 'o')
      >>> pt.plot(s.emission, mx.gauss.gauss_model(d[5,1:], s.emission))
      >>> pt.show()

    Parameters
    ----------
    return_spectra: whether to return processed calibration spectra

    Returns
    -------
    (diagnostics, [processed_spectra])

    diagnostics: an array with one row for each calibration exposure
                 the columns are:
                   incident beam energy
                   amplitude
                   E0
                   sigma

                 the best Gaussian fit to the data is given by:
                   exp(-(E-E0)**2/(2*sigma**2))

    if `return_spectra` is True, then a list of XES spectra will be returned (one for each calibration exposure)
    """

    emin, emax = self.energy_range()
    emission_energies = np.arange(emin, emax, .2)

    diagnostics = np.zeros((len(self.energies), 4))

    if return_spectra:
      spectra = []

    for i in range(len(self.energies)):
      if progress:
        msg = "Processing calibration exposure %d / %d" % (i, len(self.energies))
        prog = i / float(len(self.energies))
        progress.update(msg, prog)

      energy = self.energies[i]
      exposure = Exposure(self.exposure_files[i])
      if filters is not None:
        exposure.apply_filters(energy, filters)

      s = process_spectrum(self.calibration_matrix, exposure, emission_energies, 1, self.dispersive_direction, self.xtals)
      x = s[:,0]
      y = s[:,1]

      fit, ier = gauss_leastsq((x,y), (y.max(), energy, 1.0))

      if not (0 < ier < 5):
        continue

      diagnostics[i,0] = energy
      diagnostics[i,1:] = fit

      if return_spectra:
        xes = EmissionSpectrum()
        xes.incident_energy = energy
        xes.exposure_files = [exposure.filename]
        xes._set_spectrum(s)
        spectra.append(xes)

    diagnostics = diagnostics[np.where(diagnostics[:,0] != 0)]

    if return_spectra:
      return (diagnostics, spectra)
    else:
      return diagnostics