imaging module

This modules contains classes for simulating Imaging and Mosaicing modes

class pista.imaging.Imager(df, coords=None, tel_params=None, n_x=1000, n_y=1000, exp_time=100, plot_bandpass=False, user_profiles=None)[source]

Bases: Analyzer

Imager class uses dataframe containing position and magntidue information to simulate image based on user defined telescope and detector characteristics

add_cosmic_rays(data)[source]
add_distortion(xmap, ymap)[source]

Function for addition distortion using x and y mappings

add_stars(image_array, zero_flux, df)[source]
property bias_frame
calc_zp(plot=False)[source]
check_df()[source]
compute_DC()[source]
compute_coeff_arrays()[source]

Computed coefficients based on input parameters :rtype: None.

compute_shot_noise(array, type_='Poisson')[source]
Parameters:
  • array (numpy.ndarray) – input array

  • type (str, optional) – The default is ‘Poisson’.

Returns:

shot_noise – Return array with shot noise

Return type:

numpy.ndarray

create_wcs(n_x, n_y, ra, dec, pixel_scale, theta=0)[source]
Parameters:
  • n_x (int) – number of pixels in RA direction

  • n_y (int) – number of pixels in Dec direction

  • ra (float (degrees)) – right ascension of center of image.

  • dec (float (degrees)) – declination of center of image.

  • pixel_scale (floats) – arcsecs/pixel.

Returns:

w

Return type:

wcs object

dark_current(T, DFM, pixel_area)[source]
Parameters:
  • T (float) – Detector Temperature

  • DFM (float) – Dark current figure of merit

  • pixel_area (float) – Area of pixel

Returns:

DR – Dark current rate e/s/pixels

Return type:

float

property dark_frame
property flat_frame
generate_photons(image, patch_width, df, zero_flux)[source]

This function creates sims based on ABmag on a small patch (2D array) of size n_pix_s*n_pix_s.

The patch with the sim is then added to the image array of size n_pix_m*n_pix_m using wcs object.

Parameters:
  • image (numpy.ndarray) – base image array for inserting star sims

  • patch_width (int) – number of pixels (length) in sim patch image

  • df (pandas.dataframe) – Dataframe containing source list

Returns:

image – Array with sims added based on df

Return type:

numpy.ndarray

generate_sim_field(plot)[source]

This function creates array with FoV a bit wider than user defined size for flux conservation

init_df(df, wcs, x_left, x_right, y_left, y_right)[source]

Bounds sources to boundary defined by x and y limits

init_image_array(return_img=False)[source]

Creates a base image array for adding photons

Parameters:

return_img (bool, optional) – DESCRIPTION. The default is False.

Returns:

if return_img is true return base image array

Return type:

numpy.ndarray

init_psf_patch(return_psf=False)[source]

Creates PSF array from NPY or fits files

make_ccd_image(light_array)[source]
remove_distortion()[source]

Function for returning the image to state before adding distortion

xy_to_radec()[source]
class pista.imaging.Mosaic(df=None, coords=None, ras=None, decs=None, tel_params=None, exp_time=100, n_x=1000, n_y=1000, mos_n=1, mos_m=1, **kwargs)[source]

Bases: Imager

A class to split bigger images to tiles and stitch them together

df_split(df, n, m, n_x, n_y, wcs)[source]

Function to split dataframe based shape and number of tiles

Parameters:
  • n (int,) – number of tiles in RA direction

  • m (int,) – number of tiles in Dec direction

  • n_x (int,) – number of pixels in RA direction

  • n_y (int,) – number of pixels in Dec direction

make_mosaic()[source]

Combine individual tile FITS files into a single mosaic.

Uses reproject utilities to find an optimal WCS for the set of HDUs and coadds them into self.digital with an output self.wcs. The footprint is stored in self.footprint.

analysis module

This module contains classes that can be utilized for visualizing and analyzing the simulated images and spectra

class pista.analysis.Analyzer[source]

Bases: object

aper_photometry(data, wcs, df, fwhm, sigma, ZP, detect)[source]

Function to perform Aperture photometry

Parameters:
  • data (np.ndarray,) – image to perform photometry on

  • wcs (astropy.wcs.WCS) – WCS object of the image

  • df (pandas.DataFrame,) – Source catalog of source in the image from simulation for reference

  • fwhm (float, pixels) – During aperture photometry, fwhm corresponds to FWHM circular aperture for aperture photometry During PSF photometry, fwhm corresponds FWHM kernel to use for PSF photometry

  • sigma (float,) – The numbers of standard deviations above which source has to be detected

  • detect (bool,) –

    If true, DARStarFinder is used to detect sources for aperture photometry

    if false, input catalog is used for getting positions of sources for aperture photometry

  • ZP (float,) – zero point of the telescope.

Returns:

phot_table – table containing photometry of the souces

Columns

’x-centeroid’ ‘y-centeroid’ ‘sky’ ‘flux’ ‘mag_in’ ‘mag_out’ ‘mag_err’ ‘SNR’

Return type:

astropy.table.Table

getImage(source='Digital')[source]

Function of retrieving image array at different stages of simulation.

Parameters:

Source (str,) –

Choose from

’Digital’ : Final digial image ‘Charge’ : electrons, Light(Source + sky)

  • Dark Current + Noises

’Source’ : Source + Sky + Noises ‘Sky’ : Sky + shot_noise ‘DC’ : Dark Current + DNFP ‘QE’ : Quantum efficiency fluctuation across

detector

’Bias’ : Charge offset ‘PRNU’ : Photon Response Non-Uniformity ‘DNFP’ : Dark Noise Fixed Pattern ‘QN’ : Quantization Noise

psf_photometry(data, wcs, df, fwhm, sigma, ZP, detect=True)[source]

Perform PSF photometry.

Parameters:
  • data (ndarray) – Image data.

  • wcs (astropy.wcs.WCS) – WCS object.

  • df (pandas.DataFrame) – Input catalog.

  • fwhm (float) – PSF FWHM in pixels.

  • sigma (float) – Detection threshold in sigma.

  • ZP (float) – Photometric zeropoint.

  • detect_source (bool) – If True, detect sources using DAOStarFinder. If False, use input catalog positions.

show_field(figsize=(12, 10), marker='.', cmap='jet')[source]

Function for creating a scatter plot of sources within the FoV

Parameters:

figsize (tuple,) – Figure size

Return type:

fig, ax

show_hist(source='Digital', bins=None, fig=None, ax=None, figsize=(15, 8))[source]

Function for plotting histogram of various stages of simulation

Parameters:
  • Source (str,) –

    Choose from

    ’Digital’ : Final digial image ‘Charge’ : electrons, Light(Source + sky)

    • Dark Current + Noises

    ’Source’ : Source + Sky + Noises ‘Sky’ : Sky + shot_noise ‘DC’ : Dark Current + DNFP ‘QE’ : Quantum efficiency fluctuation across

    detector

    ’Bias’ : Charge offset ‘PRNU’ : Photon Response Non-Uniformity ‘DNFP’ : Dark Noise Fixed Pattern ‘QN’ : Quantization Noise

  • bins (numpy.array,) – bins for making histogram

  • fig (matplotlib.pyplot.figure) – User defined figure

  • ax (matplotlib.pyplot.axes) – User defined axes

  • figsize (tuple)

show_image(source='Digital', fig=None, ax=None, cmap='jet', figsize=(15, 10), download=False, show_wcs=True, overlay_apertures=False)[source]

Function for plotting the simulated field image

Source: str,
Choose from

‘Digital’ : Final digial image ‘Charge’ : electrons, Light(Source + sky) +

Dark Current + Noises

‘Source’ : Source + Sky + Noises ‘Sky’ : Sky + shot_noise ‘DC’ : Dark Current + DNFP ‘QE’ : Quantum efficiency fluctuation across

detector

‘Bias’ : Charge offset ‘PRNU’ : Photon Response Non-Uniformity ‘DNFP’ : Dark Noise Fixed Pattern ‘QN’ : Quantization Noise ‘Resid’ : Residual Image If PSF Photometry

was performed

figmatplotlib.pyplot.figure

User defined figure

axmatplotlib.pyplot.axes

User defined axes

cmapstr,

matplotlib.pyplot colormap

figsize : tuple download : bool show_wcs : bool

If true adds WCS projection to the image

Returns:

  • Image

  • fig, ax

writecomp(name)[source]
writeto(name, source='Digital', user_source=None, with_dark_flat=False)[source]

Function for downloading a fits file of simulated field image

Parameters:
  • name (str) – filename, Example : simulation.fits

  • Source (str,) –

    Choose from

    ’Digital’ : Final digial image ‘Charge’ : electrons, Light(Source + sky)

    • Dark Current + Noises

    ’Source’ : Source + Sky + Noises ‘Sky’ : Sky + shot_noise ‘DC’ : Dark Current + DNFP ‘Bias’ : Charge offset ‘PRNU’ : Photon Response Non-Uniformity ‘DNFP’ : Dark Noise Fixed Pattern ‘QN’ : Quantization Noise

  • user_source (numpy.ndarray) – 2D numpy array user wants to save as FITS

  • with_dark_flat (bool) – True : Output fits will provide dark and flat frames

class pista.analysis.SpecAnalyzer[source]

Bases: object

cal_flux(flux, A=0, B=0.15)[source]

Calibrate Flux by converting flux in counts to ergs/s/cm2/A

extract(data, wcs, df, width=50, sep=5)[source]

Extracts Spectra for Slitless Spectroscopy

utils module

This module contains additional functions for the package

pista.utils.Xmatch(df1, df2, r=1)[source]

Function for crossmatching two catalogs using RAs and Decs

pista.utils.bandpass(wav, flux, inputs, plot=True, fig=None, ax=None)[source]

Function to convolve response functions

Parameters:
  • wav (numpy.ndarray) – wavelenth in angstrom

  • flux (numpy.ndarray) – flux normalized to [0,1]

  • plot (bool,) – If true shows plots with input and convolved response functions

  • fig (matplotlib.pyplot.figure) – User defined figure

  • ax (matplotlib.pyplot.axes) – User defined axes

Returns:

  • fig, ax, data, params

  • data (tuple,) – (wavelenth array, flux_array, convolved flux array)

  • params (tuple,) – (effective wavelength, integrated flux, Effective Width)

pista.utils.calc_mos_size(L, B, PA, lw)[source]

Function to calculate minimum size of a Multi-object Spectrometer (MOS) detector based on it’s orientation and shape

Parameters:
  • L (float,) – Length of MOS Field of View (FoV).

  • B (float,) – Breadth of MOS FoV.

  • PA (float,) – Orientation of MOS FoV with respect to sky plane. (degrees)

  • lw (int,) – Number of pixels in dispersion direction.

Returns:

x_size, y_size – (int,int)

Return type:

tuple

pista.utils.count_sources_within_radius(catalog, radius)[source]

Function for counting the number of source around each stat within a given radius using KDTree

Parameters:
  • catalog ((np.ndarray, np.ndarray),) – source coordinates

  • radius (float,) – radius of circle to count sources within

Returns:

counts – number density of sources around each star

Return type:

list,

pista.utils.distance_transform(ras, decs, cen_ra, cen_dec, d1, d2)[source]

Function for distance transformation of sources scattered around a point.

ras: np.ndarray,

Right Ascension of sources.

decs: np.ndarray,

Declination of sources.

cen_ra: float,

Reference Right Ascension

cen_dec: float,

Reference Declination

d1: astropy.units.ly, astropy.units.pc, astropy.units.Mpc

d2: astropy.units.ly, astropy.units.pc, astropy.units.Mpc

new_star_coords.ra.value, new_star_coords.ra.value: np.ndarray, np.ndarray

pista.utils.generate_psf(npix, params, function='Gaussian')[source]

Function for generating user defined PSF

npixint,

number of pixels along one axis for pixel array

sigma: float,

standard deviation of the PSF in pixels

function: str,

type of PSF function

Return type:

numpy.ndarray

pista.utils.redshift_corr(df)[source]

Function for redshift correction of input data

Parameters:

df (astropy.table.Table or pandas.DataFrame) –

table with columns ‘wav’, ‘flux’, ‘z1’ and ‘z2’

wav: numpy.ndarray

wavelength in Angstrom

flux: numpy.ndarray

flux in ergs/s/cm2/A

z1: float,

Original redshift to star

z2: float,

New redshift to star

Return type:

astropy.table.Table or pandas.DataFrame

pista.utils.select_mos(df, cen_x, cen_y, radius=10, min_sep=10, ny=1000)[source]

Function to select sources from a given database such that overlap of spectra is minimum :param df1: :type df1: astropy.table.Table, :param table with columns ‘ra’ and ‘dec’: :param ra: Right Ascension in degrees :type ra: float, :param dec: Declnation in degrees :type dec: float, :param cen_x: Reference x position in pixel coordinates :param float: Reference x position in pixel coordinates :param : Reference x position in pixel coordinates :param cen_y: Reference x position in pixel coordinates :type cen_y: float, :param radius: Radius of circle to count stars within. :type radius: float, :param min_sep: minimum separation between stars in the spatial axis, :type min_sep: float,

ny: int,

length of spatial axis in pixels

Returns:

  • mos_df (astropy.table.Table,) – table containing list of selected sources

  • res_df (astropy.table.Table,) – table containing list of remaining sources

pista.utils.spectra_to_mags(wav, flux, inputs, z1=None, z2=None, d1=None, d2=None)[source]

Function to convert spectra to magnitude using telescope response functions Using Astropy Table

Parameters:
  • wav (list of numpy.ndarray) – wavelength in Angstrom

  • flux (list of numpy.ndarray) – flux in ergs/s/cm2/A

  • inputs (list,) – list of path to response functions

  • d1 (float,) – Original distance to star.

  • d2 (float) – New distance to star

  • z1 (float,) – Original redshift to star

  • z2 (float,) – New redshift to star

Returns:

ABmag – magnitude of stars from spectra

Return type:

numpy.ndarray

pista.utils.spectra_to_mags_df(df, inputs)[source]

Function to convert spectra to magnitude using telescope response functions Using Astropy Table

Parameters:
  • df (astropy.table.Table) –

    table with columns ‘wav’, ‘flux’, ‘d1’ and ‘d2’ or ‘z1’ or ‘z2’

    wav: numpy.ndarray

    wavelength in Angstrom

    flux: numpy.ndarray

    flux in ergs/s/cm2/A

    d1: float,

    Original distance to star.

    d2: float

    New distance to star

    z1: float,

    Original redshift to star

    z2: float,

    New redshift to star

  • inputs (list,) – list of path to response functions

Return type:

astropy.table.Table