How to use the astromodels.PointSource function in astromodels

To help you get started, we’ve selected a few astromodels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github threeML / threeML / threeML / plugins / XYLike.py View on Github external
def fit(self, function, minimizer="minuit", verbose=False):
        """
        Fit the data with the provided function (an astromodels function)

        :param function: astromodels function
        :param minimizer: the minimizer to use
        :param verbose: print every step of the fit procedure
        :return: best fit results
        """

        # This is a wrapper to give an easier way to fit simple data without having to go through the definition
        # of sources
        pts = PointSource("source", 0.0, 0.0, function)

        model = Model(pts)

        self.set_model(model)

        self._joint_like_obj = JointLikelihood(model, DataList(self), verbose=verbose)

        self._joint_like_obj.set_minimizer(minimizer)

        return self._joint_like_obj.fit()
github threeML / threeML / threeML / bayesian / tutorial_material.py View on Github external
def get_bayesian_analysis_object_simple_likelihood():
    minus_log_L = Simple()

    minus_log_L.mu.set_uninformative_prior(Log_uniform_prior)

    # Instance a plugin (in this case a special one for illustrative purposes)
    plugin = CustomLikelihoodLike("custom")
    # Set the log likelihood function explicitly. This is not needed for any other
    # plugin
    plugin.set_minus_log_likelihood(minus_log_L)

    # Make the data list (in this case just one dataset)
    data = DataList(plugin)

    src = PointSource("test", ra=0.0, dec=0.0, spectral_shape=minus_log_L)
    model = Model(src)

    bayes = BayesianAnalysisWrap(model, data, verbose=False)

    return bayes, model
github threeML / threeML / threeML / plugins / XYLike.py View on Github external
"""
        Generate an XYLike plugin from an astromodels function instance
        
        :param name: name of plugin
        :param function: astromodels function instance
        :param x: where to simulate
        :param yerr: y errors or None for Poisson data
        :param kwargs: kwargs from xylike constructor
        :return: XYLike plugin
        """

        y = function(x)

        xyl_gen = XYLike("generator", x, y, yerr, **kwargs)

        pts = PointSource("fake", 0.0, 0.0, function)

        model = Model(pts)

        xyl_gen.set_model(model)

        return xyl_gen.get_simulated_dataset(name)
github threeML / threeML / threeML / minimizer / tutorial_material.py View on Github external
def get_joint_likelihood_object_complex_likelihood():

    minus_log_L = Complex()

    # Instance a plugin (in this case a special one for illustrative purposes)
    plugin = CustomLikelihoodLike("custom")
    # Set the log likelihood function explicitly. This is not needed for any other
    # plugin
    plugin.set_minus_log_likelihood(minus_log_L)

    # Make the data list (in this case just one dataset)
    data = DataList(plugin)

    src = PointSource("test", ra=0.0, dec=0.0, spectral_shape=minus_log_L)
    model = Model(src)

    jl = JointLikelihoodWrap(model, data, verbose=False)

    return jl, model
github threeML / threeML / threeML / minimizer / tutorial_material.py View on Github external
def get_joint_likelihood_object_simple_likelihood():

    minus_log_L = Simple()

    # Instance a plugin (in this case a special one for illustrative purposes)
    plugin = CustomLikelihoodLike("custom")
    # Set the log likelihood function explicitly. This is not needed for any other
    # plugin
    plugin.set_minus_log_likelihood(minus_log_L)

    # Make the data list (in this case just one dataset)
    data = DataList(plugin)

    src = PointSource("test", ra=0.0, dec=0.0, spectral_shape=minus_log_L)
    model = Model(src)

    jl = JointLikelihoodWrap(model, data, verbose=False)

    return jl, model
github threeML / threeML / threeML / plugins / SpectrumLike.py View on Github external
is_poisson=is_poisson,
                mission="fake_mission",
                instrument="fake_instrument",
                tstart=0.0,
                tstop=1.0,
            )

            # now we have to generate the background counts
            # we treat the background as a simple observation with no
            # other background

            background_gen = SpectrumLike(
                "generator", tmp_background, None, verbose=False
            )

            pts_background = PointSource(
                "fake_background", 0.0, 0.0, background_function
            )

            background_model = Model(pts_background)

            background_gen.set_model(background_model)

            sim_background = background_gen.get_simulated_dataset("fake")

            background = sim_background._observed_spectrum

        else:

            background = None

        generator = cls._get_synthetic_plugin(
github threeML / threeML / threeML / plugins / SpectrumLike.py View on Github external
def _get_synthetic_plugin(cls, observation, background, source_function):

        speclike_gen = cls("generator", observation, background, verbose=False)

        pts = PointSource("fake", 0.0, 0.0, source_function)

        model = Model(pts)

        speclike_gen.set_model(model)

        return speclike_gen
github threeML / threeML / threeML / bayesian / tutorial_material.py View on Github external
def get_bayesian_analysis_object_complex_likelihood():
    minus_log_L = Complex()

    minus_log_L.mu.set_uninformative_prior(Log_uniform_prior)

    # Instance a plugin (in this case a special one for illustrative purposes)
    plugin = CustomLikelihoodLike("custom")
    # Set the log likelihood function explicitly. This is not needed for any other
    # plugin
    plugin.set_minus_log_likelihood(minus_log_L)

    # Make the data list (in this case just one dataset)
    data = DataList(plugin)

    src = PointSource("test", ra=0.0, dec=0.0, spectral_shape=minus_log_L)
    model = Model(src)

    bayes = BayesianAnalysisWrap(model, data, verbose=False)

    return bayes, model