Scene generation and projection#
Learning goals#
In this notebook you will learn how to use two new models
load_star_map
to generate a scene
Generates a scene from scopesim Source object loading objects from the GAIA catalog for given coordinates and FOV.
and
simple_aperture
to project this scene onto your detector.
Converts scene to photon with given aperture. First an xarray Dataset will be extracted from the Scene for a selected wavelength band, where the flux of the objects will be integrated along the wavelength band. This integrated flux in photon/(s cm2) is converted to photon/(s pixel). Finally, the objects are projected onto detector, while converting the object coordinates from arcsec to detector coordinates (pixel).
Both models are are implemented in Pyxel since version 1.11.
Keywords#
scene generator, star map, flux conversion
Summary#
We use Pyxel in exposure mode and generate a scene from the Gaia catalog with a virtual telescope pointing towards the Pleiades with a FOV diameter of \(0.5^{\circ}\). We visualise some selected spectra and the scene in arcsec. Then this scene is projected onto the detector using a simple aperture and a PSF model.
Loading packages#
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import pyxel
import xarray as xr
Load configuration file#
cfg = pyxel.load("tutorial-scene.yaml")
detector = cfg.detector
Loading result#
result = pyxel.run_mode(mode=cfg.exposure, detector=detector, pipeline=cfg.pipeline)
result
INFO:astroquery:Query finished.
INFO: Query finished. [astroquery.utils.tap.core]
<xarray.DatasetView> Size: 9MB Dimensions: (y: 500, x: 500, time: 1) Coordinates: * y (y) int64 4kB 0 1 2 3 4 5 6 7 8 ... 492 493 494 495 496 497 498 499 * x (x) int64 4kB 0 1 2 3 4 5 6 7 8 ... 492 493 494 495 496 497 498 499 * time (time) float64 8B 6e+03 Data variables: photon (time, y, x) float64 2MB 406.7 319.5 294.7 ... 1.585e+03 2.439e+03 charge (time, y, x) float64 2MB 367.0 291.0 264.0 ... 1.409e+03 2.166e+03 pixel (time, y, x) float64 2MB 659.7 525.4 473.7 ... 2.544e+03 3.872e+03 signal (time, y, x) float64 2MB 0.002762 0.002309 ... 0.01029 0.01538 image (time, y, x) uint16 500kB 18 15 12 11 11 13 ... 62 63 72 70 67 100 Attributes: pyxel version: 2.9 running mode: Exposure
Get Scene from DataTree#
Info: Detector object contains only last exposure (time)
data_tree = detector.scene.data
data_tree["/list/0"]
<xarray.DatasetView> Size: 960kB Dimensions: (ref: 345, wavelength: 343) Coordinates: * ref (ref) int64 3kB 0 1 2 3 4 5 6 7 ... 338 339 340 341 342 343 344 * wavelength (wavelength) float64 3kB 336.0 338.0 ... 1.018e+03 1.02e+03 Data variables: x (ref) float64 3kB 2.053e+05 2.055e+05 ... 2.039e+05 2.03e+05 y (ref) float64 3kB 8.528e+04 8.54e+04 ... 8.852e+04 8.82e+04 weight (ref) float64 3kB 15.21 13.22 13.23 12.42 ... 13.69 13.86 12.19 flux (ref, wavelength) float64 947kB 0.003126 0.003373 ... 0.1005 Attributes: right_ascension: 56.75 deg declination: 24.1167 deg fov_radius: 0.5 deg
result.scene
result["scene/list/0"]
<xarray.DatasetView> Size: 963kB Dimensions: (y: 500, x: 500, time: 1, ref: 345, wavelength: 343) Coordinates: * x (x) int64 4kB 0 1 2 3 4 5 6 7 ... 493 494 495 496 497 498 499 * y (y) int64 4kB 0 1 2 3 4 5 6 7 ... 493 494 495 496 497 498 499 * time (time) float64 8B 6e+03 * ref (ref) int64 3kB 0 1 2 3 4 5 6 7 ... 338 339 340 341 342 343 344 * wavelength (wavelength) float64 3kB 336.0 338.0 ... 1.018e+03 1.02e+03 Data variables: weight (ref) float64 3kB 15.21 13.22 13.23 12.42 ... 13.69 13.86 12.19 flux (ref, wavelength) float64 947kB 0.003126 0.003373 ... 0.1005 Attributes: right_ascension: 56.75 deg declination: 24.1167 deg fov_radius: 0.5 deg
Turn DataTree to Dataset#
For now needed, because plotting not available in DataTree yet.
ds = data_tree["/list/0"].to_dataset()
ds
<xarray.Dataset> Size: 960kB Dimensions: (ref: 345, wavelength: 343) Coordinates: * ref (ref) int64 3kB 0 1 2 3 4 5 6 7 ... 338 339 340 341 342 343 344 * wavelength (wavelength) float64 3kB 336.0 338.0 ... 1.018e+03 1.02e+03 Data variables: x (ref) float64 3kB 2.053e+05 2.055e+05 ... 2.039e+05 2.03e+05 y (ref) float64 3kB 8.528e+04 8.54e+04 ... 8.852e+04 8.82e+04 weight (ref) float64 3kB 15.21 13.22 13.23 12.42 ... 13.69 13.86 12.19 flux (ref, wavelength) float64 947kB 0.003126 0.003373 ... 0.1005 Attributes: right_ascension: 56.75 deg declination: 24.1167 deg fov_radius: 0.5 deg
Visualize spectra of selected stars#
ds["flux"].isel(ref=slice(None, 9)).plot.line(col="ref", sharey=False, col_wrap=3)
<xarray.plot.facetgrid.FacetGrid at 0x7b2b0f4d2cf0>

ds["flux"].isel(ref=100).plot.line()
[<matplotlib.lines.Line2D at 0x7b2affdb1bd0>]

Visualize scene with magnitude as intensity scale#
ds.plot.scatter(x="x", y="y", hue="weight", marker="o", size=8)
<matplotlib.collections.PathCollection at 0x7b2b00db27b0>

Display detector#
The new features in the function display_detector
will be part of the next release 1.12 (coming soon).
pyxel.display_detector(detector)
Alternative to display_detector to visualize photon and image array in logarithmic scale
xr.DataArray(result.photon).plot(
norm=colors.LogNorm(
vmin=0.1, # 1
vmax=result.photon.max(),
)
)
<matplotlib.collections.QuadMesh at 0x7b2af214dd10>

xr.DataArray(result.image).plot(
norm=colors.LogNorm(
vmin=1, # 0.1
vmax=result.image.max(),
)
)
<matplotlib.collections.QuadMesh at 0x7b2af251e5d0>

TO DOs:#
We have a first nice working version, but still want to improve the models. See https://gitlab.com/esa/pyxel/-/issues/668.