Sequence

class marxs.simulator.Sequence(**kwargs)[source] [edit on github]

Bases: BaseContainer

A Sequence is a container that summarizes several optical elements.

Parameters:
elementslist

The elements of this list are all optical elements that process photons.

preprocess_stepslist

The elements of this list are functions or callable objects that accept a photon list as input and return no output (but changing the photon list in place, e.g. adding meta-data is allowed) (default: []). All preprocess_steps are run before every optical element in the sequence. An example would be a function that writes the photon list to disk as a backup before every optical element or prints some informational message. If your function returns a modified photon list, treat it as an optical element and place it in sequence.

postprocess_stepslist
See preprocess_steps except that the steps are run after each sequence element

(default: []).

Examples

The following example shows a complete marxs simulation. First, we import the required modules:

>>> from astropy.coordinates import SkyCoord
>>> import astropy.units as u
>>> from marxs import source, optics
>>> from marxs.simulator import Sequence

Then, we build up the parts of the simulation, source, pointing model and hardware of our instrument:

>>> mysource = source.PointSource(coords=SkyCoord(30., 30., unit="deg"), flux=1e-3 / u.s / u.cm**2, energy=2. * u.keV)
>>> sky2mission = source.FixedPointing(coords=SkyCoord(30., 30., unit='deg'))
>>> aper = optics.RectangleAperture(position=[50., 0., 0.])
>>> mirr = optics.ThinLens(focallength=10, position=[10., 0., 0.])
>>> ccd = optics.FlatDetector(pixsize=0.05)
>>> sequence = [sky2mission, aper, mirr, ccd]
>>> my_instrument = Sequence(elements=sequence)

Finally, we run one set of photons through the instrument:

>>> photons_in = mysource.generate_photons(1e5 * u.s)
>>> photons_out = my_instrument(photons_in)

Now, let us check where the photons fall on the detector:

>>> set(photons_out['detpix_x'].round())
{19.0, 20.0}

As expected, they fall right around the center of the detector (row 19 and 20 of a 40 * 40 pixel detector).

Define a new MARXS element.