Exemple #1
0
 def get_energy(self):
     """
     Returns array of energy for each channel in the MCA spectra.
     """
     energy = channel_to_energy(self.channels, offset=self.offset,
                                slope=self.slope, quad=self.quad)
     return energy
Exemple #2
0
def med_copy_rois(med, source_mca=0):
    """
    This procedure copies the ROIs defined for one Mca in the Med to all of
    the other Mcas.

    Parameters:
    -----------
    * source_mca: The index number of the Mca from which the ROIs are to
      be copied.  This number ranges from 0 to self.n_detectors-1.
      The default is the first Mca (index=0).

    Notes:
    ------
    The ROIs are copied by their position
    in energy rather than in channels. This is very useful when
    copying ROIs when the calibration parameters for each Mca in
    the Med are not identical.
    """
    units = "channel"
    if energy:
        units = "keV"

    kws = dict(offset = med.mca[source_mca].offset,
               slope =  med.mca[source_mca].slope,
               quad = med.mca[source_mca].quad,
               clip = med.mca[source_mca].clip)

    left, right, label, bgr_width  = [], [], [], []

    for roi in med.mca[source_mca].rois:
        left.append(channel_to_energy(roi.left,   **kws))
        right.append(channel_to_energy(roi.right, **kws))
        label.append(roi.label)
        bgr_width.append(roi.bgr)

    for j in range(med.n_detectors):
        off   = med.mca[j].offset
        slope = med.mca[j].slope
        quad  = med.mca[j].quad
        clip  = len(med.mca[j].data)
        med.mca[j].rois = []
        for k in range(len(left)):
            l = energy_to_channel(left[k],offset=off,slope=slope,quad=quad,clip=clip)
            r = energy_to_channel(right[k],offset=off,slope=slope,quad=quad,clip=clip)
            roi = ROI(left=int(l),right=int(r), label=label[k], bgr_width=bgr_width[k])
Exemple #3
0
def fit_gaussian():
	for dataset in datasets:
		guess_channel = int(dataset.center)
		guess = (guess_channel, dataset.count_diff[guess_channel], fitradius)

		fitrange = slice(guess_channel - fitradius,
	                  guess_channel + fitradius)

		dataset.channel_fit = channel[fitrange]
		dataset.count_fit = dataset.count_diff[fitrange]

		data = scipy.odr.RealData(
			dataset.channel_fit, dataset.count_fit, sy=np.sqrt(dataset.count_fit))

		odr = scipy.odr.ODR(data, scipy.odr.Model(
			lambda p, x: gaussian(x, *p)), beta0=guess)

		result = odr.run()

		dataset.popt = result.beta
		dataset.center = result.beta[0]
		dataset.center_error = result.sd_beta[0]
		dataset.center_energy, dataset.center_energy_error = channel_to_energy(
			dataset.center, dataset.center_error)
Exemple #4
0
import constants
from calibration import channel, channel_to_energy
from datasets import datasets
from detector import detector_inv_efficiency

bb_angles, bb_diff_cross = np.loadtxt(
	'src/bb-diff-cross.dat', usecols=[0, 2], unpack=True)

angles = []
counts = []

for dataset in datasets:
	angles.append(dataset.angle)
	channel = np.argmax(dataset.count_diff)
	energy, _ = channel_to_energy(channel)
	count = np.sum(dataset.count_diff) * detector_inv_efficiency(energy)
	counts.append(count)

angles = np.array(angles)
counts = np.array(counts)
counts_err = np.sqrt(counts)
time = 300  # s
rate = counts / time
rate_err = rate / counts * counts_err

# day not given, assume middle of july
date_inital = datetime.date(1971, 7, 15)
date_experiment = datetime.date(2018, 12, 17)
ratio_remaining = np.power(
	0.5, (date_experiment - date_inital).days / (30.17 * 365.25))