示例#1
0
    def __init__(self, name):

        assert is_valid_variable_name(name), "Illegal characters in name %s. You can only use letters and numbers, " \
                                             "and _" % name

        assert name != "name", "You cannot call a node 'name', it is reserved."

        _Node.__init__(self, name)
示例#2
0
    def __init__(self, name):

        self._children = collections.OrderedDict()
        self._parent = None

        assert is_valid_variable_name(name), "Illegal characters in name %s. You can only use letters and numbers, " \
                                             "and _" % name

        self._name = name
示例#3
0
    def __init__(self, name):

        self.__children = collections.OrderedDict()
        self.__parent = None

        assert is_valid_variable_name(name), "Illegal characters in name %s. You can only use letters and numbers, " \
                                             "and _" % name

        self._name = name

        super(Node, self).__init__('node', self.__children)
示例#4
0
    def __init__(self, name, nuisance_parameters):
        assert is_valid_variable_name(name), "The name %s cannot be used as a name. You need to use a valid " \
                                             "python identifier: no spaces, cannot start with numbers, cannot contain " \
                                             "operators symbols such as -, +, *, /" % name

        # Make sure total is not used as a name (need to use it for other things, like the total value of the statistic)
        assert name.lower() != "total", "Sorry, you cannot use 'total' as name for a plugin."

        self._name = name

        # This is just to make sure that the plugin is legal

        assert isinstance(nuisance_parameters, dict)

        self._nuisance_parameters = nuisance_parameters

        # These are the external properties (time, polarization, etc.)
        # self._external_properties = []

        self._tag = None
示例#5
0
    def __init__(self, name, nuisance_parameters):
        assert is_valid_variable_name(name), "The name %s cannot be used as a name. You need to use a valid " \
                                             "python identifier: no spaces, cannot start with numbers, cannot contain " \
                                             "operators symbols such as -, +, *, /" % name

        # Make sure total is not used as a name (need to use it for other things, like the total value of the statistic)
        assert name.lower() != "total", "Sorry, you cannot use 'total' as name for a plugin."

        self._name = name

        # This is just to make sure that the plugin is legal

        assert isinstance(nuisance_parameters, dict)

        self._nuisance_parameters = nuisance_parameters

        # These are the external properties (time, polarization, etc.)
        # self._external_properties = []

        self._tag = None
示例#6
0
    def __init__(
        self,
        name,
        observation,
        background=None,
        response=None,
        arf_file=None,
        spectrum_number=None,
        verbose=True,
    ):

        assert is_valid_variable_name(name), (
            "Name %s is not a valid name for a plugin. You must use a name which is "
            "a valid python identifier: no spaces, no operators (+,-,/,*), "
            "it cannot start with a number, no special characters" % name)

        # Read the pha file (or the PHAContainer instance)

        assert (isinstance(observation, str)
                or isinstance(observation, PHASpectrum)
                or isinstance(observation, PHAII)
                ), "observation must be a FITS file name or PHASpectrum"

        assert (
            isinstance(background, str) or isinstance(background, PHASpectrum)
            or (background is None) or isinstance(background, PHAII)
            or isinstance(background, SpectrumLike)
            or isinstance(background, XYLike)
        ), "background must be a FITS file name, PHASpectrum, a Plugin or None"

        if isinstance(observation, str) or isinstance(observation, PHAII):

            pha = PHASpectrum(
                observation,
                spectrum_number=spectrum_number,
                file_type="observed",
                rsp_file=response,
                arf_file=arf_file,
            )

        else:

            pha = observation

        # Get the required background file, response and (if present) arf_file either from the
        # calling sequence or the file.
        # NOTE: if one of the file is specified in the calling sequence, it will be used whether or not there is an
        # equivalent specification in the header. This allows the user to override the content of the header of the
        # PHA file, if needed

        if background is None:

            background = pha.background_file

            # assert background is not None, "No background file provided, and the PHA file does not specify one."

        # Get a PHA instance with the background, we pass the response to get the energy bounds in the
        # histogram constructor. It is not saved to the background class

        if background is None:

            # in the case there is no background file

            bak = None

        elif isinstance(background, str) or isinstance(observation, PHAII):

            bak = PHASpectrum(
                background,
                spectrum_number=spectrum_number,
                file_type="background",
                rsp_file=pha.response,
            )

        else:

            bak = background

        # we do not need to pass the response as it is contained in the observation (pha) spectrum
        # already.

        super(OGIPLike, self).__init__(name=name,
                                       observation=pha,
                                       background=bak,
                                       verbose=verbose)
示例#7
0
    def _check_name(name):

        if not is_valid_variable_name(name):
            raise NameError(
                "The name '%s' is not valid. Please use a simple name with no spaces nor "
                "special characters." % (name))
示例#8
0
    def _check_name(name):

        if not is_valid_variable_name(name):
            raise NameError("The name '%s' is not valid. Please use a simple name with no spaces nor "
                            "special characters." % (name))
示例#9
0
文件: OGIPLike.py 项目: giacomov/3ML
    def __init__(self, name, observation, background=None, response=None, arf_file=None, spectrum_number=None,
                 verbose=True):

        assert is_valid_variable_name(name), "Name %s is not a valid name for a plugin. You must use a name which is " \
                                             "a valid python identifier: no spaces, no operators (+,-,/,*), " \
                                             "it cannot start with a number, no special characters" % name

        # Read the pha file (or the PHAContainer instance)

        assert isinstance(observation, str) or isinstance(observation,
                                                          PHASpectrum) or isinstance(observation,
                                                                                     PHAII), 'observation must be a FITS file name or PHASpectrum'

        assert isinstance(background, str) or isinstance(background,
                                                         PHASpectrum) or (
                   background is None) or isinstance(background,
                                                     PHAII) or isinstance(background, SpectrumLike) or isinstance(background,XYLike),\
                                                                                                        'background must be a FITS file name, PHASpectrum, a Plugin or None'



        if isinstance(observation, str) or isinstance(observation, PHAII):

            pha = PHASpectrum(observation, spectrum_number=spectrum_number, file_type='observed', rsp_file=response,
                              arf_file=arf_file)

        else:

            pha = observation

        # Get the required background file, response and (if present) arf_file either from the
        # calling sequence or the file.
        # NOTE: if one of the file is specified in the calling sequence, it will be used whether or not there is an
        # equivalent specification in the header. This allows the user to override the content of the header of the
        # PHA file, if needed

        if background is None:

            background = pha.background_file

            # assert background is not None, "No background file provided, and the PHA file does not specify one."


        # Get a PHA instance with the background, we pass the response to get the energy bounds in the
        # histogram constructor. It is not saved to the background class

        if background is None:

            # in the case there is no background file

            bak = None

        elif isinstance(background, str) or isinstance(observation, PHAII):

            bak = PHASpectrum(background, spectrum_number=spectrum_number, file_type='background',
                              rsp_file=pha.response)

        else:

            bak = background

        # we do not need to pass the response as it is contained in the observation (pha) spectrum
        # already.

        super(OGIPLike, self).__init__(name=name,
                                       observation=pha,
                                       background=bak,
                                       verbose=verbose)