コード例 #1
0
    def __loadxml__(cls, element, *args, **kwargs):
        child = element.find('baseoptions')
        if child is None:
            raise IOError, 'Base options missing'
        baseoptions = XMLIO.from_xml(list(child)[0])

        detector_key = element.get('detector_key')
        detector = baseoptions.detectors[detector_key]

        measurement = cls(baseoptions, detector)

        for child in element.iterfind('kratio'):
            val = float(child.get('val'))
            unc = float(child.get('unc'))

            grandchild = child.find('transition')
            if grandchild is None:
                raise IOError, 'kratio does not have a transition'
            transition = XMLIO.from_xml(list(grandchild)[0])

            grandchild = child.find('standard')
            if grandchild is None:
                raise IOError, 'kratio does not have a standard'
            standard = XMLIO.from_xml(list(grandchild)[0])

            measurement.add_kratio(transition, val, unc, standard)

        return measurement
コード例 #2
0
    def __loadxml__(cls, element, *args, **kwargs):
        child = element.find('baseoptions')
        if child is None:
            raise IOError, 'Base options missing'
        baseoptions = XMLIO.from_xml(list(child)[0])

        detector_key = element.get('detector_key')
        detector = baseoptions.detectors[detector_key]

        measurement = cls(baseoptions, detector)

        for child in element.iterfind('kratio'):
            val = float(child.get('val'))
            unc = float(child.get('unc'))

            grandchild = child.find('transition')
            if grandchild is None:
                raise IOError, 'kratio does not have a transition'
            transition = XMLIO.from_xml(list(grandchild)[0])

            grandchild = child.find('standard')
            if grandchild is None:
                raise IOError, 'kratio does not have a standard'
            standard = XMLIO.from_xml(list(grandchild)[0])

            measurement.add_kratio(transition, val, unc, standard)

        return measurement
コード例 #3
0
    def __loadxml__(cls, element, *args, **kwargs):
        # Options
        parent = element.find('options')
        if parent is None:
            raise IOError, 'No options defined.'
        child = list(parent)[0]
        ops = XMLIO.from_xml(child)

        # Unknown body
        bodies = list(ops.geometry.get_bodies())
        indexes = map(attrgetter('_index'), bodies)
        bodies_lookup = dict(zip(indexes, bodies))

        index = int(element.get('body'))
        unknown_body = bodies_lookup[index]

        # Detector
        parent = element.find('detector')
        if parent is None:
            raise IOError, 'No detector defined.'
        child = list(parent)[0]
        detector = XMLIO.from_xml(child)

        measurement = cls(ops, unknown_body, detector)

        # k-ratios
        parent = element.find('kratios')
        if parent is not None:
            for child in parent:
                val = float(child.get('val'))
                unc = float(child.get('unc', 0.0))

                grandchild = child.find('transition')
                if grandchild is None:
                    raise IOError, 'kratio does not have a transition'
                transition = XMLIO.from_xml(list(grandchild)[0])

                grandchild = child.find('standard')
                if grandchild is None:
                    raise IOError, 'kratio does not have a standard'
                standard = XMLIO.from_xml(list(grandchild)[0])

                measurement.add_kratio(transition, val, unc, standard)

        # Rules
        parent = element.find('rules')
        if parent is not None:
            for child in parent:
                rule = XMLIO.from_xml(child)
                measurement.add_rule(rule)

        return measurement
コード例 #4
0
    def __loadxml__(cls, element, *args, **kwargs):
        # Options
        parent = element.find('options')
        if parent is None:
            raise IOError, 'No options defined.'
        child = list(parent)[0]
        ops = XMLIO.from_xml(child)

        # Unknown body
        bodies = list(ops.geometry.get_bodies())
        indexes = map(attrgetter('_index'), bodies)
        bodies_lookup = dict(zip(indexes, bodies))

        index = int(element.get('body'))
        unknown_body = bodies_lookup[index]

        # Detector
        parent = element.find('detector')
        if parent is None:
            raise IOError, 'No detector defined.'
        child = list(parent)[0]
        detector = XMLIO.from_xml(child)

        measurement = cls(ops, unknown_body, detector)

        # k-ratios
        parent = element.find('kratios')
        if parent is not None:
            for child in parent:
                val = float(child.get('val'))
                unc = float(child.get('unc', 0.0))

                grandchild = child.find('transition')
                if grandchild is None:
                    raise IOError, 'kratio does not have a transition'
                transition = XMLIO.from_xml(list(grandchild)[0])

                grandchild = child.find('standard')
                if grandchild is None:
                    raise IOError, 'kratio does not have a standard'
                standard = XMLIO.from_xml(list(grandchild)[0])

                measurement.add_kratio(transition, val, unc, standard)

        # Rules
        parent = element.find('rules')
        if parent is not None:
            for child in parent:
                rule = XMLIO.from_xml(child)
                measurement.add_rule(rule)

        return measurement
コード例 #5
0
ファイル: rule.py プロジェクト: pymontecarlo/pymontecarlo
        Updates the specified composition for the selected element.
        """
        raise NotImplementedError

class ElementByDifferenceRule(_CompositionRule):

    def update(self, composition):
        if self.z in composition:
            composition.pop(self.z)

        total = min(sum(composition.values()), 1.0)

        if total < 1.0:
            composition[self.z] = 1.0 - total

XMLIO.register('{http://pymontecarlo.sf.net}elementByDifferenceRule', ElementByDifferenceRule)

class FixedElementRule(_CompositionRule):
    """
    Fixed weight fraction for an element.
    """

    def __init__(self, z, wf):
        _CompositionRule.__init__(self, z)

        if wf <= 0.0 or wf > 1.0:
            raise ValueError, 'Weight fraction must be between ]0.0, 1.0]'
        self._wf = wf

    def __repr__(self):
        return '<%s(%i @ %s wt%%)>' % \
コード例 #6
0
    def get_transitions(self):
        """
        Returns a :class:`list` of all transitions where a k-ratio has been
        defined.
        """
        return self._transitions.values()

    def get_kratios(self):
        """
        Returns a :class:`dict` where the keys are atomic numbers and the values 
        are tuples of the k-ratios and their uncertainties.
        """
        return dict(self._kratios)  # copy

    def get_standards(self):
        """
        Returns a :class:`dict` where the keys are atomic numbers and the values
        are the geometry objects of the standards
        """
        return dict(self._standards)  # copy

    def get_rules(self):
        """
        Returns a :class:`list` of all the defined rules.
        """
        return self._rules.values()


XMLIO.register('{http://pymontecarlo.sf.net}measurement', Measurement)
コード例 #7
0
        """
        Creates the required options to simulate this measurement.

        :arg name: name of the options for this measurement
        :arg unkgeometry: geometry for the unknown
        """
        options = copy.deepcopy(self._baseoptions)
        options.name = name
        options.geometry = unkgeometry
        return options

    def extract_unknown_intensities(self, results):
        """
        Extracts the intensities from the simulation of the unknown of this
        measurements.
        Returns an array with the intensities.
        The value ordering and length of the array are equal to the one returned 
        by :attr:`get_kratios`. 

        :arg results: results for this measurement
        """
        intensities = []

        for transition in sorted(self._kratios.iterkeys()):
            val, _unc = results[self._detector_key].intensity(transition)
            intensities.append(val)

        return intensities
    
XMLIO.register('{http://pymontecarlo.sf.net}measurement', Measurement)
コード例 #8
0
ファイル: rule.py プロジェクト: arooney/pymontecarlo
        """
        raise NotImplementedError


class ElementByDifferenceRule(_CompositionRule):
    def update(self, composition):
        if self.z in composition:
            composition.pop(self.z)

        total = min(sum(composition.values()), 1.0)

        if total < 1.0:
            composition[self.z] = 1.0 - total


XMLIO.register('{http://pymontecarlo.sf.net}elementByDifferenceRule',
               ElementByDifferenceRule)


class FixedElementRule(_CompositionRule):
    """
    Fixed weight fraction for an element.
    """
    def __init__(self, z, wf):
        _CompositionRule.__init__(self, z)

        if wf <= 0.0 or wf > 1.0:
            raise ValueError, 'Weight fraction must be between ]0.0, 1.0]'
        self._wf = wf

    def __repr__(self):
        return '<%s(%i @ %s wt%%)>' % \