Friday, May 21, 2010

Fake data FAST!

Sometimes, users just what to simulate a simple model and plot. This can be done quickly with five easy steps. Define the grid, the model, the initial model parameter values, add noise, and plot.

Example:

#!/usr/bin/env python
from
sherpa.astro.ui import *

# create simple grid [0.1, 10] with a
# bin size of 0.01

dataspace1d(0.1,10,0.01, dstype=Data1D)


# define a gaussian model plus a constant

set_model(gauss1d.g1+const1d.c1)


# initialize parameter values

g1.pos = 5

g1.fwhm = 2.5

g1.ampl = 75

c1.c0 = 0.1


# evaluate the model, add poisson noise,
# and populate the dataspace

fake()

# plot faked data

plot_data()

2 comments:

  1. Can you take the same 5 steps to simulate 2D data?
    Of course I would be using corresponding 2d functions:

    dataspace2d()
    ....

    ReplyDelete
  2. Yes, same number of steps, but slightly different to simulate 2D data.

    #!/usr/bin/env python
    from sherpa.astro.ui import *
    dataspace2d([256,256])
    set_model(gauss2d.g1+const2d.c1)
    g1.fwhm = 128
    g1.xpos = 128
    g1.ypos = 128
    g1.ampl = 75
    c1.c0 = 0.1
    fake()
    image_data()

    ReplyDelete