simcado.source module

The module that contains the functionality to create Source objects

Module Summary

The Source is essentially a list of spectra and a list of positions. The list of positions contains a reference to the relevant spectra. The advantage here is that if there are repeated spectra in a data cube, we can reduce the amount of calculations needed. Furthermore, if the input is originally a list of stars, etc., where the position of a star is not always an integer multiple of the plate scale, we can keep the information until the PSFs are needed.

Classes

Source

Functions

Functions to create Source objects

empty_sky()
star(mag, filter_name="Ks", spec_type="A0V", x=0, y=0)
stars(mags, filter_name="Ks", spec_types=["A0V"], x=[0], y=[0])
star_grid(n, mag_min, mag_max, filter_name="Ks", separation=1, area=1,
          spec_type="A0V")
source_from_image(images, lam, spectra, pix_res, oversample=1,
                  units="ph/s/m2", flux_threshold=0,
                  center_pixel_offset=(0, 0))
source_1E4_Msun_cluster(distance=50000, half_light_radius=1)

Functions for manipulating spectra for a Source object

scale_spectrum(lam, spec, mag, filter_name="Ks", return_ec=False)
scale_spectrum_sb(lam, spec, mag_per_arcsec, pix_res=0.004,
                  filter_name="Ks", return_ec=False)
flat_spectrum(mag, filter_name="Ks", return_ec=False)
flat_spectrum_sb(mag_per_arcsec, filter_name="Ks", pix_res=0.004,
                 return_ec=False)

Functions regarding photon flux and magnitudes

zero_magnitude_photon_flux(filter_name)
_get_stellar_properties(spec_type, cat=None, verbose=False)
_get_stellar_mass(spec_type)
_get_stellar_Mv(spec_type)
_get_pickles_curve(spec_type, cat=None, verbose=False)

Helper functions

value_at_lambda(lam_i, lam, val, return_index=False)
SED(spec_type, filter_name="V", magnitude=0.)
class simcado.source.Source(filename=None, lam=None, spectra=None, x=None, y=None, ref=None, weight=None, **kwargs)[source]

Bases: object

Create a source object from a file or from arrays

Source class generates the arrays needed for source. It takes various inputs and converts them to an array of positions and references to spectra. It also converts spectra to photons/s/voxel. The default units for input data is ph/s/m2/bin.

The internal variables are related like so:

f(x[i], y[i]) = spectra[ref[i]] * weight[i]
Parameters
filenamestr

FITS file that contains either a previously saved Source object or a data cube with dimensions x, y, lambda. A Source object is identified by the header keyword SIMCADO with value SOURCE.

or
lamnp.array

[um] Wavelength bins of length (m)

spectranp.array

[ph/s/m2/bin] A (n, m) array with n spectra, each with m spectral bins

x, ynp.array

[arcsec] coordinates of where the emitting sources are relative to the centre of the field of view

refnp.array

the index for .spectra which connects a position (x, y) to a spectrum f(x[i], y[i]) = spectra[ref[i]] * weight[i]

weightnp.array

A weighting to scale the relevant spectrum for each position

add_background_surface_brightness(self)[source]

Add an EmissionCurve for the background surface brightness of the object

apply_optical_train(self, opt_train, detector, chips='all', sub_pixel=False, **kwargs)[source]

Apply all effects along the optical path to the source photons

Parameters
opt_trainsimcado.OpticalTrain

the object containing all information on what is to happen to the photons as they travel from the source to the detector

detectorsimcado.Detector

the object representing the detector

chipsint, str, list, optional

The IDs of the chips to be readout. “all” is also acceptable

sub_pixelbool, optional

if sub-pixel accuracy is needed, each source is shifted individually. Default is False

Other Parameters
INST_DEROT_PERFORMANCEfloat

[0 .. 100] Percentage of the sky rotation that the derotator removes

SCOPE_JITTER_FWHMfloat

[arcsec] The FWMH of the gaussian blur caused by jitter

SCOPE_DRIFT_DISTANCEfloat

[arcsec] How far from the centre of the field of view has the telescope drifted during a DIT

Notes

Output array is in units of [ph/s/pixel] where the pixel is internal oversampled pixels - not the pixel size of the detector chips

dump(self, filename)[source]

Save to filename as a pickle

image_in_range(self, psf, lam_min, lam_max, chip, **kwargs)[source]

Find the sources that fall in the chip area and generate an image for the wavelength range [lam_min, lam_max)

Output is in [ph/s/pixel]

Parameters
psfpsf.PSF object

The PSF that the sources will be convolved with

lam_min, lam_maxfloat

[um] the wavelength range relevant for the psf

chipstr, detector.Chip
  • detector.Chip : the chip that will be seeing this image.

  • str : [“tiny”, “small”, “center”] -> [128, 1024, 4096] pixel chips

Returns
slice_arraynp.ndarray

the image of the source convolved with the PSF for the given range

property info_keys

Return keys of the info dict

classmethod load(filename)[source]

Load :class:’.Source’ object from filename

on_grid(self, pix_res=0.004)[source]

Return an image with the positions of all sources.

The pixel values correspond to the number of emitting objects in that pixel

Parameters
pix_resfloat

[arcsec] The grid spacing

Returns
im2D array

A numpy array containing an image of where the sources are

photons_in_range(self, lam_min=None, lam_max=None)[source]

Number of photons between lam_min and lam_max in units of [ph/s/m2]

Calculate how many photons for each source exist in the wavelength range defined by lam_min and lam_max.

Parameters
lam_min, lam_maxfloat, optional

[um] integrate photons between these two limits. If both are None, limits are set at lam[0], lam[-1] for the source’s wavelength range

Returns
slice_photonsfloat

[ph/s/m2] The number of photons in the wavelength range

project_onto_chip(self, image, chip)[source]

Re-project the photons onto the same grid as the detectors use

Parameters
imagenp.ndarray

the image to be re-projected

chipdetector.Chip

the chip object where the image will land

read(self, filename)[source]

Read in a previously saved Source FITS file

Parameters
filenamestr

Path to the file

rotate(self, angle, unit='degree', use_orig_xy=False)[source]

Rotates the x and y coordinates by angle [degrees]

Parameters
anglefloat

Default is in degrees, this can set with unit

unitstr, astropy.Unit

Either a string with the unit name, or an astropy.unit.Unit object

use_orig_xybool

If the rotation should be based on the original coordinates or the current coordinates (e.g. if rotation has already been applied)

scale_spectrum(self, idx=0, mag=20, filter_name='Ks')[source]

Scale a certain spectrum to a certain magnitude

See simcado.source.scale_spectrum() for examples

Parameters
idxint

The index of the spectrum to be scaled: <Source>.spectra[idx] Default is <Source>.spectra[0]

magfloat

[mag] new magnitude of spectrum

filter_namestr, TransmissionCurve

Any filter name from SimCADO or a TransmissionCurve object (see get_filter_set())

scale_with_distance(self, distance_factor)[source]

Scale the source for a new distance

Scales the positions and brightnesses of the Source object according to the ratio of the new and old distances

i.e. distance_factor = new_distance / current_distance

Warning

This does not yet take into account redshift

Todo

Implement redshift

Parameters
distance_factorfloat

The ratio of the new distance to the current distance i.e. distance_factor = new_distance / current_distance

Examples

 >>> from simcado.source import cluster
 >>>
 >>> curr_dist = 50000  # pc, i.e. LMC
 >>> new_dist = 770000  # pc, i.e. M31
>>> src = cluster(distance=curr_dist)
 >>> src.scale_with_distance( new_dist/curr_dist )
shift(self, dx=0, dy=0, use_orig_xy=False)[source]

Shifts the coordinates of the source by (dx, dy) in [arcsec]

Parameters
dx, dyfloat, array

[arcsec] The offsets for each coordinate in the arrays x, y. - If dx, dy are floats, the same offset is applied to all coordinates - If dx, dy are arrays, they must be the same length as x, y

use_orig_xybool

If the shift should be based on the original coordinates or the current coordinates (e.g. if shift has already been applied)

write(self, filename)[source]

Write the current Source object out to a FITS file

Parameters
filenamestr

where to save the FITS file

Notes

Just a place holder so that I know what’s going on with the input table * The first extension [0] contains an “image” of size 4 x N where N is the number of sources. The 4 columns are x, y, ref, weight. * The second extension [1] contains an “image” with the spectra of all sources. The image is M x len(spectrum), where M is the number of unique spectra in the source list. M = max(ref) - 1

simcado.source.star(spec_type='A0V', mag=0, filter_name='Ks', x=0, y=0, **kwargs)[source]

Creates a simcado.Source object for a star with a given magnitude

This is just the single star variant for simcado.source.stars()

Parameters
spec_typestr

the spectral type of the star, e.g. “A0V”, “G5III”

magfloat

magnitude of star

filter_namestr

Filter in which the magnitude is given. Can be the name of any filter curve file in the simcado/data folder, or a path to a custom ASCII file

x, yfloat, int, optional

[arcsec] the x,y position of the star on the focal plane

Returns
sourcesimcado.Source

See also

stars
simcado.source.stars(spec_types='A0V', mags=0, filter_name='Ks', x=None, y=None, **kwargs)[source]

Creates a simcado.Source object for a bunch of stars.

Parameters
spec_typesstr, list of strings

the spectral type(s) of the stars, e.g. “A0V”, “G5III” Default is “A0V”

magsfloat, array

[mag] magnitudes of the stars.

filter_namestr,

Filter in which the magnitude is given. Can be the name of any filter curve file in the simcado/data folder, or a path to a custom ASCII file

x, yarrays

[arcsec] x and y coordinates of the stars on the focal plane

Returns
sourcesimcado.Source

Examples

Create a Source object for a random group of stars

>>> import numpy as np
>>> from simcado.source import stars
>>>
>>> spec_types = ["A0V", "G2V", "K0III", "M5III", "O8I"]
>>> ids = np.random.randint(0,5, size=100)
>>> star_list = [spec_types[i] for i in ids]
>>> mags = np.random.normal(20, 3, size=100)
>>>
>>> src = stars(spec_types, mags, filter_name="Ks")

If we don’t specify any coordinates all stars have the position (0, 0). All positions are in arcsec. There are two possible ways to add positions. If we know them to begin with we can add them when generating the source full of stars

>>> x, y = np.random.random(-20, 20, size=(100,2)).tolist()
>>> src = stars(star_list, mags, filter_name="Ks", x=x, y=y)

Or we can add them to the Source object directly (although, there are less checks to make sure the dimensions match here):

>>> src.x, src.y = x, y
simcado.source.cluster(mass=1000.0, distance=50000, half_light_radius=1)[source]

Generate a source object for a cluster

The cluster distribution follows a gaussian profile with the half_light_radius corresponding to the HWHM of the distribution. The choice of stars follows a Kroupa IMF, with no evolved stars in the mix. Ergo this is more suitable for a young cluster than an evolved custer

Parameters
massfloat

[Msun] Mass of the cluster (not number of stars). Max = 1E5 Msun

distancefloat

[pc] distance to the cluster

half_light_radiusfloat

[pc] half light radius of the cluster

Returns
srcsimcado.Source

Examples

Create a Source object for a young open cluster with half light radius of around 0.2 pc at the galactic centre and 100 solar masses worth of stars:

>>> from simcado.source import cluster
>>> src = cluster(mass=100, distance=8500, half_light_radius=0.2)
simcado.source.point_source(spectrum='AOV', mag=0, filter_name='TC_filter_Ks.dat', x=0, y=0, **kwargs)[source]

Creates a simcado.Source object for a point source with a given magnitude

This is a variant for simcado.source.star() but can accept any SED as well as an user provided EmissionCurve object

Parameters
spectrumstr, EmissionCurve, optional

The spectrum to be associated with the point source. Values can either be: - the name of a SimCADO SED spectrum : see get_SED_names() - an EmissionCurve with a user defined spectrum

magfloat

magnitude of object

filter_namefilter_name

Default is “Ks”. Values can be either: - the name of a SimCADO filter : see optics.get_filter_set() - or a TransmissionCurve containing a user-defined filter

x, yfloat, int, optional

[arcsec] the x,y position of the point source on the focal plane

Returns
sourcesimcado.Source

See also

star
simcado.source.spiral(half_light_radius, plate_scale, magnitude=10, filter_name='Ks', normalization='total', spectrum='spiral', **kwargs)[source]

Create a extended Source object for a “Galaxy”

Parameters
half_light_radiusfloat

[arcsec]

plate_scalefloat

[arcsec]

magnitudefloat

[mag, mag/arcsec2]

filter_namestr, TransmissionCurve, optional. Default is “Ks”. Values can be either:
  • the name of a SimCADO filter : see optics.get_filter_set()

  • or a TransmissionCurve containing a user-defined filter

normalizationstr, optional

[“half-light”, “centre”, “total”] Where in the profile equals unityy If normalization equals:

  • “half-light” : the pixels at the half-light radius have a surface brightness of magnitude [mag/arcsec2]

  • “centre” : the maximum pixels have a surface brightness of magnitude [mag/arcsec2]

  • “total” : the whole image has a brightness of magnitude [mag]

spectrumstr, EmissionCurve, optional

The spectrum to be associated with the galaxy. Values can either be: - the name of a SimCADO SED spectrum : see get_SED_names() - an EmissionCurve with a user defined spectrum

Returns
galaxy_srcsimcado.Source

See also

sersic_profile
spiral_profile
optics.get_filter_set
source.get_SED_names
spectral.TransmissionCurve
spectral.EmissionCurve
simcado.source.spiral_profile(r_eff, ellipticity=0.5, angle=45, n_arms=2, tightness=4.0, arms_width=0.1, central_brightness=10, normalization='total', width=1024, height=1024, oversample=1, **kwargs)[source]

Creates a spiral profile with arbitary parameters

Parameters
r_efffloat

[pixel] Effective (half-light) radius

ellipticityfloat

Ellipticity is defined as (a - b)/a. Default = 0.5

anglefloat

[deg] Default = 45. Rotation anti-clockwise from the x-axis

n_armsint

Number of spiral arms

tightnessfloat

How many times an arm crosses the major axis. Default = 4.

arms_widthfloat

An arbitary scaling factor for how think the arms should be. Seems to scale with central_brightness. Default = 0.1

central_brightnessfloat

An arbitary scaling factor for the strength of the central region. Has some connection to ars_width. Default = 10

normalizationstr, optional

[“half-light”, “centre”, “total”] Where the profile equals unity If normalization equals: - “centre” : the maximum values are set to 1 - “total” : the image sums to 1

width, heightint, int

[pixel] Dimensions of the image

x_offset, y_offsetfloat

[pixel] The distance between the centre of the profile and the centre of the image

oversampleint

Factor of oversampling, default factor = 1. If > 1, the model is discretized by taking the average of an oversampled grid.

Returns
imgnp.ndarray

A 2D image of a spiral disk

See also

sersic_profile

Notes

The intensity drop-off is dictated by a sersic profile of with indes n=1, i.e. an exponential drop-off. This can be altered by passing the keyword “n=” as an optional parameter.

Spiral structure taken from here: https://stackoverflow.com/questions/36095775/creating-a-spiral-structure-in-python-using-hyperbolic-tangent

simcado.source.elliptical(half_light_radius, plate_scale, magnitude=10, n=4, filter_name='Ks', normalization='total', spectrum='elliptical', **kwargs)[source]

Create a extended Source object for a “Galaxy”

Parameters
half_light_radiusfloat

[arcsec]

plate_scalefloat

[arcsec]

magnitudefloat

[mag, mag/arcsec2]

nfloat, optional

Power law index. Default = 4 - n=1 for exponential (spiral), - n=4 for de Vaucouleurs (elliptical)

filter_namestr, TransmissionCurve, optional

Default is “Ks”. Values can be either: - the name of a SimCADO filter : see optics.get_filter_set() - or a TransmissionCurve containing a user-defined filter

normalizationstr, optional

[“half-light”, “centre”, “total”] Where the profile equals unity If normalization equals:

  • “half-light” : the pixels at the half-light radius have a surface brightness of magnitude [mag/arcsec2]

  • “centre” : the maximum pixels have a surface brightness of magnitude [mag/arcsec2]

  • “total” : the whole image has a brightness of magnitude [mag]

spectrumstr, EmissionCurve, optional

The spectrum to be associated with the galaxy. Values can either be: - the name of a SimCADO SED spectrum : see get_SED_names() - an EmissionCurve with a user defined spectrum

Returns
galaxy_srcSource
simcado.source.sersic_profile(r_eff=100, n=4, ellipticity=0.5, angle=30, normalization='total', width=1024, height=1024, x_offset=0, y_offset=0, oversample=1)[source]

Returns a 2D array with a normalised Sersic profile

Parameters
r_efffloat

[pixel] Effective (half-light) radius

nfloat

Power law index. - n=1 for exponential (spiral), - n=4 for de Vaucouleurs (elliptical)

ellipticityfloat

Ellipticity is defined as (a - b)/a. Default = 0.5

anglefloat

[deg] Default = 30. Rotation anti-clockwise from the x-axis

normalizationstr, optional

[“half-light”, “centre”, “total”] Where the profile equals unity If normalization equals: - “half-light” : the pixels at the half-light radius are set to 1 - “centre” : the maximum values are set to 1 - “total” : the image sums to 1

width, heightint

[pixel] Dimensions of the image

x_offset, y_offsetfloat

[pixel] The distance between the centre of the profile and the centre of the image

oversampleint

Factor of oversampling, default factor = 1. If > 1, the model is discretized by taking the average of an oversampled grid.

Returns
img2D array

Notes

Most units are in [pixel] in this function. This differs from galaxy() where parameter units are in [arcsec] or [pc]

simcado.source.source_from_image(images, lam, spectra, plate_scale, oversample=1, units='ph/s/m2', flux_threshold=0, center_offset=(0, 0), conserve_flux=True, **kwargs)[source]

Create a Source object from an image or a list of images.

Note

plate_scale is the original plate scale of the images. If this is not the same as the plate scale of the Detector then you will need to specify oversample to interpolate between the two scales. I.e. oversample = Image plate scale / Detector plate scale

Parameters
imagesnp.ndarray, list

A single or list of np.ndarrays describing where the flux is coming from The spectrum for each pixel in the image is weighted by the pixel value.

lamnp.ndarray

An array contains the centres of the wavelength bins for the spectra

spectranp.ndarray

A (n,m) array with n spectra, each with m bins

plate_scalefloat

[arcsec] The plate scale of the images in arcseconds (e.g. 0.004”/pixel)

oversampleint

The factor with which to oversample the image. Each image pixel is split into (oversample)^2 individual point sources.

unitsstr, optional

The energy units of the spectra. Default is [ph/s/m2]

flux_thresholdfloat, optional

If there is noise in the image, set threshold to the noise limit so that only real photon sources are extracted. Default is 0.

center_offset(float, float)

[arcsec] If the centre of the image is offset, add this offset to (x,y) coordinates.

conserve_fluxbool, optional

If True, when the image is rescaled, flux is conserved i.e. np.sum(image) remains constant If False, the maximum value of the image stays constant after rescaling i.e. np.max(image) remains constant

Returns
srcSource object

Notes

Currently only one object per image is supported.

Examples

To create a Source object we need an image that describes the spatial distribution of the object of interest and spectrum. For the sake of ease we will assign a generic elliptical galaxy spectrum to the image.:

>>> from astropy.io import fits
>>> from simcado.source import SED, source_from_image
>>>
>>> im = fits.getdata("galaxy.fits")
>>> lam, spec = SED("elliptical")
>>> src = source_from_image(im, lam, spec,
                            plate_scale=0.004)

Note Here we have assumed that the plate scale of the image is the same as the MICADO wide-field mode, i.e. 0.004 arcseconds. If the image is from a real observation, or it was generated with a different pixel scale, we will need to tell SimCADO about this:

>>> src = source_from_image(im, lam, spec,
                            plate_scale=0.01,
                            oversample=2.5)

If the image is from real observations, chances are good that the background flux is higher than zero. We can set a threshold in order to tell SimCADO to ignore all pixel with values below the background level:

>>> src = source_from_image(im, lam, spec,
                            plate_scale=0.01,
                            oversample=2.5,
                            flux_threshold=0.2)

Finally, if the image centre is not the centre of the observation, we can shift the image relative to the MICADO field of view. The units for the offset are [arcsec]:

>>> src = source_from_image(im, lam, spec,
                            plate_scale=0.01,
                            oversample=2.5,
                            flux_threshold=0.2,
                            center_offset=(10,-15))
simcado.source.star_grid(n, mag_min, mag_max, filter_name='Ks', separation=1, spec_type='A0V')[source]

Creates a square grid of A0V stars at equal magnitude intervals

Parameters
nfloat

the number of stars in the grid

mag_min, mag_maxfloat

[vega mag] the minimum (brightest) and maximum (faintest) magnitudes for stars in the grid

filter_namestr

any filter that is in the SimCADO package directory. See simcado.optics.get_filter_set()

separationfloat, optional

[arcsec] an average speration between the stars in the grid can be specified. Default is 1 arcsec

spec_typestr, optional

the spectral type of the star, e.g. “A0V”, “G5III”

Returns
sourcesimcado.Source

Notes

The units of the A0V spectrum in source are [ph/s/m2/bin]. The weight values are the scaling factors to bring a V=0 A0V spectrum down to the required magnitude for each star.

simcado.source.empty_sky()[source]

Returns an empty source so that instrumental fluxes can be simulated

Returns
skySource
simcado.source.SED(spec_type, filter_name='V', magnitude=0.0)[source]

Return a scaled SED for a star or type of galaxy

The SED can be for stellar spectra of galacty spectra. It is best not to mix the two types when calling SED(). Either provide a list of stellar types, e.g. [“G2V”, “A0V”], of a list of galaxy types, e.g. [“elliptical”, “starburst”]

To get the list of galaxy types that are installed, call get_SED_names(). All stellar types from the Pickles (1998) catalogue are available.

Parameters
spec_typestr, list

The spectral type of the star(s) - from the Pickles 1998 catalogue The names of a galaxy spectrum - see get_SED_names()

filter_namestr, optional

Default is “V”. Any filter in the simcado/data directory can be used, or the user can specify a file path to an ASCII file for the filter

magnitudefloat, list, optional

Apparent magnitude of the star. Default is 0.

Returns
lamnp.ndarray

[um] The centre of each 5 Ang bin along the spectral axis

valnp.ndarray

[ph/s/m2/bin] The photon flux of the star in each bin

Notes

Original flux units for the stellar spectra are in [ph/s/m2/AA], so we multiply the flux by 5 to get [ph/s/m2/bin]. Therefore divide by 5*1E4 if you need the flux in [ph/s/cm2/Angstrom]

Examples

Get the SED and the wavelength bins for a J=0 A0V star

>>> from simcado.source import SED
>>> lam, spec = SED("A0V", "J", 0)

Get the SED for a generic starburst galaxy

>>> lam, spec = SED("starburst")

Get the SEDs for several spectral types with different magnitudes

import matplotlib.pyplot as plt
from simcado.source import SED

lam, spec = SED(spec_type=["A0V", "G2V"],
                    filter_name="Pa-beta",
                    magnitude=[15, 20])

plt.plot(lam, spec[0], "blue", label="Vega")
plt.plot(lam, spec[1], "orange", label="G2V")
plt.semilogy(); plt.legend(); plt.show()

(Source code, png, hires.png, pdf)

../_images/simcado-source-1.png
simcado.source.redshift_SED(z, spectrum, mag, filter_name='TC_filter_Ks.dat')[source]

Redshift a SimCADO SED and scale it to a magnitude in a user specified filter

Parameters
z: redshift of the source
spectrum: str, EmissionCurve, optional

The spectrum to be associated with the source. Values can either be: - the name of a SimCADO SED spectrum : see get_SED_names() - an EmissionCurve with a user defined spectrum

mag: magnitude to scale the the SED after redshifting the spectrum
filter_name: filter in which the magnitude is given
Returns
ec: EmissionCurve object

Notes

wavelength and flux of the redshifted spectrum can be accessed with ec.lam and ec.val

the returned object can directly be used in any source function that accepts an EmissionCurve object (source.elliptical, source.spiral, source.point_source)

simcado.source.sie_grad(x, y, par)[source]

Compute the deflection of an SIE (singular isothermal ellipsoid) potential

Parameters
x, ymeshgrid arrays

vectors or images of coordinates; should be matching numpy ndarrays

parlist

vector of parameters with 1 to 5 elements, defined as follows: par[0]: lens strength, or ‘Einstein radius’ par[1]: (optional) x-center (default = 0.0) par[2]: (optional) y-center (default = 0.0) par[3]: (optional) axis ratio (default=1.0) par[4]: (optional) major axis Position Angle

in degrees c.c.w. of x axis. (default = 0.0)

Returns
xg, yggradients at the positions (x, y)

Notes

This routine implements an ‘intermediate-axis’ convention.
Analytic forms for the SIE potential can be found in:

Kassiola & Kovner 1993, ApJ, 417, 450 Kormann et al. 1994, A&A, 284, 285 Keeton & Kochanek 1998, ApJ, 495, 157

The parameter-order convention in this routine differs from that of a previous IDL routine of the same name by ASB.

simcado.source.apply_grav_lens(image, x_cen=0, y_cen=0, r_einstein=None, eccentricity=1, rotation=0)[source]

Apply a singular isothermal ellipsoid (SIE) gravitational lens to an image

Parameters
imagenp.ndarray
x_cen, y_cenfloat

[pixel] centre of the background image relative to the centre of the field of view

r_einsteinfloat

[pixel] Einstein radius of lens. If None, r_einstein = image.shape[0] // 4

eccentricityfloat

[1..0] The ratio of semi-minor to semi-major axis for the lens

rotationfloat

[degrees] Rotation of lens ccw from the x axis

Returns
lensed_imagenp.ndarray
simcado.source.get_SED_names(path=None)[source]

Return a list of the SEDs installed in the package directory

Looks for files that follow the naming convention SED_<name>.dat. For example, SimCADO contains an SED for an elliptical galaxy named SED_elliptical.dat

Parameters
pathstr, optional

Directory to look in for filters

Returns
sed_nameslist

A list of names for the SED files available

See also

SED()

Examples

Names returned here can be used with the function SED() to call up

>>> from simcado.source import SED, get_SED_names
>>> print(get_SED_names())
['elliptical', 'interacting', 'spiral', 'starburst', 'ulirg']
>>> SED("spiral")
(array([ 0.3  ,  0.301,  0.302, ...,  2.997,  2.998,  2.999]),
 array([        0.        ,         0.        ,  26055075.98709349, ...,
          5007498.76444208,   5000699.21993188,   4993899.67542169]))
simcado.source.scale_spectrum(lam, spec, mag, filter_name='Ks', return_ec=False)[source]

Scale a spectrum to be a certain magnitude

Parameters
lamnp.ndarray

[um] The wavelength bins for spectrum

specnp.ndarray

The spectrum to be scaled into [ph/s/m2] for the given broadband filter

magfloat

magnitude of the source

filter_namestr, TransmissionCurve, optional

Any filter name from SimCADO or a TransmissionCurve object (see get_filter_set())

return_ecbool, optional

If True, a simcado.spectral.EmissionCurve object is returned. Default is False

Returns
lamnp.ndarray

[um] The centres of the wavelength bins for the new spectrum

specnp.ndarray

[ph/s/m2] The spectrum scaled to the specified magnitude

If return_ec == True, a simcado.spectral.EmissionCurve is returned

Examples

Scale the spectrum of a G2V star to J=25:

>>> lam, spec = simcado.source.SED("G2V")
>>> lam, spec = simcado.source.scale_spectrum(lam, spec, 25, "J")

Scale the spectra for many stars to different H-band magnitudes:

>>> from simcado.source import SED, scale_spectrum
>>>
>>> star_list = ["A0V", "G2V", "M5V", "B6III", "O9I", "M2IV"]
>>> magnitudes = [ 20,  25.5,  29.1,      17,  14.3,   22   ]
>>> lam, spec = SED(star_list)
>>> lam, spec = scale_spectrum(lam, spec, magnitudes, "H")

Re-scale the above spectra to the same magnitudes in Pa-Beta:

>>> # Find which filters are in the simcado/data directory
>>>
>>> import simcado.optics as sim_op
>>> print(sim_op.get_filter_set())
['xH1', 'xY2', 'Spec_IJ', 'K-cont', 'I', 'xI2', 'Ks2', 'xY1', 'R',
'Y', 'Br-gamma', 'J-long', 'Pa-beta', 'H', 'I-long', 'H2_1-0S1',
'H-short', 'H-long', 'He-I', 'K-short', 'xJ2', 'J', 'xJ1', 'V', 'FeII',
'xI1', 'xK2', 'K-long', 'K-mid', 'J-short', 'H-cont', 'xK1', 'B', 'U',
'Ks', 'xH2', 'Spec_HK']
>>>
>>> lam, spec = scale_spectrum(lam, spec, magnitudes, "Pa-beta")
simcado.source.scale_spectrum_sb(lam, spec, mag_per_arcsec, pix_res=0.004, filter_name='Ks', return_ec=False)[source]

Scale a spectrum to be a certain magnitude per arcsec2

Parameters
lamnp.ndarray

[um] The wavelength bins for spectrum

specnp.ndarray

The spectrum to be scaled into [ph/s/m2] for the given broadband filter

mag_per_arcsecfloat

[mag/arcsec2] surface brightness of the source

pix_resfloat

[arcsec] the pixel resolution

filter_namestr, TransmissionCurve

Any filter name from SimCADO or a TransmissionCurve object (see get_filter_set())

return_ecbool, optional

If True, a simcado.spectral.EmissionCurve object is returned. Default is False

Returns
lamnp.ndarray

[um] The centres of the wavelength bins for the new spectrum

specnp.array

[ph/s/m2/pixel] The spectrum scaled to the specified magnitude

simcado.source.flat_spectrum(mag, filter_name='Ks', return_ec=False)[source]

Return a flat spectrum scaled to a certain magnitude

Parameters
magfloat

[mag] magnitude of the source

filter_namestr, TransmissionCurve, optional

str - filter name. See simcado.optics.get_filter_set(). Default: “Ks” TransmissionCurve - output of simcado.optics.get_filter_curve()

return_ecbool, optional

If True, a simcado.spectral.EmissionCurve object is returned. Default is False

Returns
lamnp.ndarray

[um] The centres of the wavelength bins for the new spectrum

specnp.array

[ph/s/m2/arcsec] The spectrum scaled to the specified magnitude

simcado.source.flat_spectrum_sb(mag_per_arcsec, filter_name='Ks', pix_res=0.004, return_ec=False)[source]

Return a flat spectrum for a certain magnitude per arcsec

Parameters
mag_per_arcsecfloat

[mag/arcsec2] surface brightness of the source

filter_namestr, TransmissionCurve, optional

str - filter name. See simcado.optics.get_filter_set(). Default: “Ks” TransmissionCurve - output of simcado.optics.get_filter_curve()

pix_resfloat

[arcsec] the pixel resolution. Default is 4mas (i.e. 0.004)

return_ecbool, optional

Default is False. If True, a simcado.spectral.EmissionCurve object is returned.

Returns
lamnp.ndarray

[um] The centres of the wavelength bins for the new spectrum

specnp.array

[ph/s/m2/arcsec] The spectrum scaled to the specified magnitude

simcado.source.value_at_lambda(lam_i, lam, val, return_index=False)[source]

Return the value at a certain wavelength - i.e. val[lam] = x

Parameters
lam_ifloat

the wavelength of interest

lamnp.ndarray

an array of wavelengths

valnp.ndarray

an array of values

return_indexbool, optional

If True, the index of the wavelength of interest is returned Default is False

simcado.source.BV_to_spec_type(B_V)[source]

Returns the latest main sequence spectral type(s) for (a) B-V colour

Parameters
B_Vfloat, array

[mag] B-V colour

Returns
spec_typeslist

A list of the spectral types corresponding to the B-V colours

Examples

>>> BV = np.arange(-0.3, 2.5, 0.5)
>>> spec_types = BV_to_spec_type(BV)
>>> print(BV)
>>> print(spec_types)
[-0.3  0.2  0.7  1.2  1.7  2.2]
['O9V', 'A8V', 'G2V', 'K5V', 'M3V', 'M8V']
simcado.source.zero_magnitude_photon_flux(filter_name)[source]

Return the number of photons for a m=0 star for a filter with synphot

Parameters
filter_namestr
filter name. See simcado.optics.get_filter_set()

Notes

units in [ph/s/m2]

simcado.source.mag_to_photons(filter_name, magnitude=0)[source]

Return the number of photons for a certain filter and magnitude

Parameters
filter_namestr

filter name. See simcado.optics.get_filter_set()

magnitudefloat

[mag] the source brightness

Returns
fluxfloat

[ph/s/m2] Photon flux in the given filter

simcado.source.photons_to_mag(filter_name, photons=1)[source]

Return the number of photons for a certain filter and magnitude

Parameters
filter_namestr

filter name. See simcado.optics.get_filter_set()

photonsfloat

[ph/s/m2] the integrated photon flux for the filter

Returns
magfloat

The magnitude of an object with the given photon flux through the filter