Ejemplo n.º 1
0
from matplotlib import pyplot as plt
import numpy as np

from sherpa import models, instrument
from sherpa.data import Data1D

# Copy all the objects just to make sure
g1 = models.Gauss1D('g1')
g1.fwhm = 3.0

g2 = models.Gauss1D('g2')
g2.fwhm = 3.0

psf1 = instrument.PSFModel('psf1', g1)
psf2 = instrument.PSFModel('psf2', g2)

mdl_orig = models.Box1D('box')
mdl_orig.xlow = 10.0
mdl_orig.xhi = 20.0

mdl_conv1 = psf1(mdl_orig)
mdl_conv2 = psf2(mdl_orig)

x1 = np.arange(-5.0, 30, 0.5)
d1 = Data1D('grid1', x1, x1 * 0)

x2 = np.arange(1.0, 29.0, 0.2)
d2 = Data1D('grid2', x2, x2 * 0)

y_orig = mdl_orig(x1)
Ejemplo n.º 2
0
import numpy as np
import matplotlib.pyplot as plt
from sherpa import data, models, stats, optmethods, fit, plot

np.random.seed(42)

s1 = models.Gauss1D('sim1')
s2 = models.Gauss1D('sim2')

print(s1)
print([p.name for p in s1.pars])

sim_model = s1 + s2

print(sim_model)
print([p.fullname for p in sim_model.pars])

s1.ampl = 1.0
s1.pos = 0.0
s1.fwhm = 0.5
s2.ampl = 2.5
s2.pos = 0.5
s2.fwhm = 0.25

x = np.linspace(-1, 1, 200)
y = sim_model(x) + np.random.normal(0., 0.2, x.shape)

d = data.Data1D('simulated', x, y)
dplot = plot.DataPlot()
dplot.prepare(d)
print(">>> dplot.plot()")
Ejemplo n.º 3
0
# This isn't currently used

from matplotlib import pyplot as plt
import numpy as np

from sherpa import models, instrument
from sherpa.data import Data1D
from sherpa.utils.err import PSFErr

# For now make sure the convolved models are 0 at both edges of the
# grid, to avoid having to explain the current behavior, which I
# don't understand.
#
g3 = models.Gauss1D('g3')
g3.fwhm = 3.0

# g6 = models.Gauss1D('g6')
# g6.fwhm = 6.0

psf3 = instrument.PSFModel('psf3', g3)
# psf6 = instrument.PSFModel('psf6', g6)

mdl_orig = models.Box1D('box')
mdl_orig.xlow = 10.0
mdl_orig.xhi = 20.0

mdl_conv3 = psf3(mdl_orig)
# mdl_conv6 = psf6(mdl_orig)

print("# Model: PSF=3")
print(mdl_conv3)
Ejemplo n.º 4
0
x_small = np.linspace(-4, 3, 50)
x_large = np.linspace(-4, 300, 5000000)
twod_small = Data2D('data', x_small, x_small, x_small)
twod_large = Data2D('data', x_large, x_large, x_large)

twod_small.ignore(x0low=-3, x0hi=-2, x1lo=-3, x1hi=-2)

# Gauss is a common model, so we pick that as an example here.
# We could do the same benchmarks for all models in Sherpa
# but that might be more than we want ot look at.
# Much of the models shera a common machinary (i.e. they derive
# from the same base class), so a test for a few representative
# models here might be enough as a start.

gauss1d = models.Gauss1D("name")
gauss2d = models.Gauss2D("name")


def time_gauss1d_init():
    g = models.Gauss1d('name')

    
def time_direct_gauss1d_small():
    y = gauss1d(x_small)

    
def time_direct_gauss1d_large():
    y = gauss1d(x_large)