Esempio n. 1
0
def get_counts(specEl):
    """Retrieve counts as a numpy ndarray from the first ChannelData element in the given Spectrum element
    Calls Uncompress method if the ChannelData element has an attribute containing
    "compression" equal to "CountedZeroes".
    """
    chandataEl = Rf.requiredElement('ChannelData', specEl)
    # print(etree.tostring(chandataEl, encoding='unicode', method='xml'))

    try:
        dataEl = Rf.requiredElement('Data', chandataEl)
    except Rf.BaseSpectraFormatException:
        dataEl = chandataEl

    counts = numpy.fromstring(dataEl.text, float, sep=' ')
    for attribute, value in dataEl.attrib.items():
        if 'COMPRESSION' in attribute.upper() and value == 'CountedZeroes':
            return uncompressCountedZeroes(counts)
    else:
        return counts
Esempio n. 2
0
def get_counts(specEl):
    """Retrieve counts as a numpy ndarray from the first ChannelData element in the given Spectrum element
    Calls Uncompress method if the ChannelData element has an attribute containing
    "compression" equal to "CountedZeroes".
    """
    chandataEl = Rf.requiredElement('ChannelData', specEl)
    counts = numpy.fromstring(chandataEl.text, float, sep=' ')
    for attribute, value in chandataEl.attrib.items():
        if 'COMPRESSION' in attribute.upper() and value == 'CountedZeroes':
            return uncompressCountedZeroes(counts)
    else:
        return counts
Esempio n. 3
0
def get_container(ET, id=None, containername='RadMeasurement'):
    """
    Retrieves a RadMeasurement object from the ElementTree (or ET root) by id. id can be an int, picking that index
    from the list of RadMeasurements, or a string to compare to the "id" attribute of the RadMeasurement element.
    :param ET:
    :param id:
    :return:
    """
    if id is None: id = 1
    Rf.requiredElement(containername, ET)  #require that RadMeasurement exists
    rads = ET.findall(containername)
    return_rads = []
    for rad in rads:
        if isinstance(id, str) and id in rad.get('id', []):
            return_rads.append(rad)
    if not return_rads:
        try:
            return rads[id - 1]
        except TypeError:  #id is probably a string
            raise Rf.BaseSpectraFormatException(
                f'Cannot find {containername} with id/index {id}')
    assert len(return_rads) == 1
    return return_rads[0]
Esempio n. 4
0
def get_livetime(specEl):
    """Retrieves Livetime as a float from the Spectrum element
    """
    timetext = Rf.requiredElement(('LiveTimeDuration', 'LiveTime'),
                                  specEl).text
    return Rf.ConvertDurationToSeconds(timetext)