Table model example

The following Python example sets up a table model grid with two parameters. The parameters, energies and fluxes are given arbitrary values, in practice these could be read from text files.

test = table()

# set table descriptors and the energy array
test.setModelName("Test")
test.setModelUnits(" ")
test.setisRedshift(True)
test.setisAdditive(True)
test.setisError(False)

# set up the energies. note that the size is one greater
# than that of the array for the model fluxes
test.setEnergies(linspace(0.1,10.0,100))

test.setNumIntParams(2)
test.setNumAddParams(0)

# define first parameter and give it 11 values ranging from
# 0.0 to 2.0 in steps of 0.2.

testpar = tableParameter()
testpar.setName("param1")
testpar.setInterpolationMethod(0)
testpar.setInitialValue(1.0)
testpar.setDelta(0.1)
testpar.setMinimum(0.0)
testpar.setBottom(0.0)
testpar.setTop(2.0)
testpar.setMaximum(2.0)
testpar.setTabulatedValues(linspace(0.0,2.0,11))

# and push it onto the vector of parameters
test.pushParameter(testpar)

# define the second parameter and give it 5 values ranging from
# 4.6 to 5.4 in steps of 0.2. As an example this parameter is set up
# using a create method which allows information to be passed in one call

testpar2 = tableParameter("param2", 0, 5.0, 0.1, 4.6, 4.6, 5.4, 5.4) 
testpar2.setTabulatedValues(linspace(4.6,5.4,5)

# and push it onto the vector of parameters
test.pushParameter(testpar2);

# now set up the spectra. these are arbitrarily calculated, in a real program 
# this step would read a file or call a routine.

for i1 in range(11):
  for i2 in range(5):
    flux = empty((99))
    for j in range(99): flux[j] = 0.2*i1+10*(4.6+0.2*i2)+j*0.1
    testspec = tableSpectrum()
    testspec.setParameterValues(array([0.2*i1,4.6+0.2*i2]))
    testspec.setFlux(flux)
    test.pushSpectrum(testspec)

# now write out the table.
test.write("test.mod");




HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public

Last modified: Wednesday, 23-Mar-2022 21:09:04 EDT