Exemplo n.º 1
0
def find_roi(mca, left, right, energy=False):
    """
    This procedure finds the index number of the ROI with a specified
    left and right channel number.

    Parameters:
    -----------
    * mca: mca object
    * left: Left channel number (or energy) of this ROI
    * right: Right channel number (or energy) of this ROI
    * energy: Set this flag to True to indicate that Left and Right are
      in units of energy rather than channel number.

    Output:
    -------
    * Returns the index of the specified ROI,
      -1 if the ROI was not found.

    Example:
    --------
    >>index = find_roi(mca, 100, 200)
    """
    if energy:
        kws   = dict(offset=mca.offset, slope=mca.slope,
                     quad=mca.quad, clip=len(mca.data))
        left  = energy_to_channel(left, **kws)
        right = energy_to_channel(right, **kws)
    index = 0
    for roi in self.rois:
        if left == roi.left and right == roi.right:
            return index
        index = index + 1
    return -1
Exemplo n.º 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])