Getting Started#

scopesim.source.Source objects are composed of a spatial description and a spectral one. Spatial description can be astropy.table.Table objects for point sources or an astropy.fits.ImageHDU for extended sources. Spectral description is provided as synphot.SourceSpectrum or compatible objects. Spectral datacubes can also be accepted

Creation of a Source#

The creation of scopesim.source.Source objects might require quite a bit of interaction from the user. For example

import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
import synphot
from scopesim import Source

# creation of a image with a central source defined by a 2D gaussian
x, y = np.meshgrid(np.arange(100), np.arange(100))
img = np.exp(-1 * ( ( (x - 50) / 5)**2 + ( (y - 50) / 5)**2 ) )

# Fits headers of the image. Yes it needs a WCS
hdr = fits.Header(dict(NAXIS=2,
                       NAXIS1=img.shape[0]+1,
                       NAXIS2=img.shape[1]+1,
                       CRPIX1=img.shape[0] / 2,
                       CRPIX2=img.shape[1] / 2,
                       CRVAL1=0,
                       CRVAL2=0,
                       CDELT1=0.2/3600,
                       CDELT2=0.2/3600,
                       CUNIT1="DEG",
                       CUNIT2="DEG",
                       CTYPE1='RA---TAN',
                       CTYPE2='DEC--TAN'))

# Creating an ImageHDU object
hdu = fits.ImageHDU(data=img, header=hdr)

# Creating of a black body spectrum
wave = np.arange(1000, 35000, 10 )
bb = synphot.models.BlackBody1D(temperature=5000)
sp = synphot.SourceSpectrum(synphot.Empirical1D, points=wave, lookup_table=bb(wave))

# Source creation
src1 = Source(image_hdu=hdu, spectra=sp)

plt.imshow(src1.fields[0].data)
src1.spectra[0].plot()
py.warnings - WARNING: /home/docs/checkouts/readthedocs.org/user_builds/scopesim-templates/envs/latest/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

../_images/6cc876727558b65c39d84353facacb37b86d9f303cccafccb266b31cde8018d3.png ../_images/02b3d609efa02571cd517b258004ba14ad1bb14ec124f08a7e935339ac988c29.png

The attributes .fields and .spectra contain the spatial and spectral description of the sources respectively. Datacubes are stored in the cube attribute

These attributes are actually lists of objects which allow to store several sources to be used in one simulation.

Combining sources#

For example, let’s create now a simple point source and combine it with the previous one

lam = np.arange(1000, 10000, 1)
flux = np.ones(lam.shape)

src2 = Source(x=[0], y=[0], lam=lam, spectra=flux, weight=[1], ref=[0])

src = src1 + src2

# printing information about the combined source
print(src)
[0]: ImageHDU with size (100, 100), referencing spectrum 0
[1]: Table with 1 rows, referencing spectra {1}

More details can be found in the respective fields

print(src.spectra)

print(src.fields)
{0: <synphot.spectrum.SourceSpectrum object at 0x7b2165d0f950>, 1: <synphot.spectrum.SourceSpectrum object at 0x7b2165d17b50>}
[ImageSourceField(field=<astropy.io.fits.hdu.image.ImageHDU object at 0x7b2165d20dd0>, wcs=WCS Keywords

Number of WCS axes: 2
CTYPE : 'RA---TAN' 'DEC--TAN'
CUNIT : 'deg' 'deg'
CRVAL : 0.0 0.0
CRPIX : 50.0 50.0
PC1_1 PC1_2  : 1.0 0.0
PC2_1 PC2_2  : 0.0 1.0
CDELT : 5.55555555555555e-05 5.55555555555555e-05
NAXIS : 100  100, spectra={0: <synphot.spectrum.SourceSpectrum object at 0x7b2165d0f950>}), TableSourceField(field=<Table length=1>
   x       y     ref  weight
 arcsec  arcsec             
float64 float64 int64 int64 
------- ------- ----- ------
    0.0     0.0     1      1, spectra={1: <synphot.spectrum.SourceSpectrum object at 0x7b2165d17b50>})]

ScopeSim_Templates#

The idea of ScopeSim_Templates is exactly to aid the creation of standard sources to used in the simulator ScopeSim.

Currently the package contain sources to work with stellar and extragalactic objects, as well as general function for other purposes.

The following example combines galaxy and a central source simulating an AGN

from scopesim_templates.extragalactic import galaxy
from scopesim_templates.misc import point_source

gal = galaxy(sed="kc96/s0", amplitude=15, filter_curve="g")  # This will create a galaxy with an S0 SED from the Kinney-Calzetti library (see speXtra)
agn = point_source(sed="agn/qso", amplitude=13, filter_curve="g") # and this an AGN

source = gal + agn

print(repr(source))
Downloading file 'libraries/agn/index.yml' from 'https://scopesim.univie.ac.at/spextra/database/libraries/agn/index.yml' to '/home/docs/.spextra_cache'.
  0%|                                              | 0.00/2.09k [00:00<?, ?B/s]
  0%|                                              | 0.00/2.09k [00:00<?, ?B/s]
100%|█████████████████████████████████████| 2.09k/2.09k [00:00<00:00, 1.47MB/s]
Downloading file 'libraries/agn/qso.fits' from 'https://scopesim.univie.ac.at/spextra/database/libraries/agn/qso.fits' to '/home/docs/.spextra_cache'.
  0%|                                              | 0.00/23.0k [00:00<?, ?B/s]
 31%|███████████▌                         | 7.17k/23.0k [00:00<00:00, 60.2kB/s]
 62%|███████████████████████              | 14.3k/23.0k [00:00<00:00, 59.6kB/s]
  0%|                                              | 0.00/23.0k [00:00<?, ?B/s]
100%|█████████████████████████████████████| 23.0k/23.0k [00:00<00:00, 23.5MB/s]
[0]: ImageHDU with size (150, 150), referencing spectrum 0
[1]: Table with 1 rows, referencing spectra {1}