Simulator

class specsim.simulator.Simulator(config, num_fibers=2, camera_output=True, verbose=False)[source] [edit on github]

Bases: object

Manage the simulation of a source, atmosphere and instrument.

A simulator has no configuration parameters of its own.

Parameters:
configspecsim.config.Configuration or str

A configuration object or configuration name.

num_fibersint

Number of fibers to simulate.

camera_outputbool

Include per-camera output tables in simulation results when True. When this is False, our camera_output attribute will return an empty list and the num_source_electrons_* columns in our simulated table will not be resolution convolved. Setting this parameter to False will save memory and time when per-camera outputs are not needed.

verbosebool

Print information about the simulation progress.

Attributes Summary

camera_output

list: List of per-camera simulation output tables.

num_fibers

Number of fibers being simulated.

simulated

astropy.table.Table: Table of high-resolution simulation results.

Methods Summary

generate_random_noise([random_state, ...])

Generate a random noise realization for the most recent simulation.

plot([fiber, wavelength_min, ...])

Plot results of the last simulation for a single fiber.

save(filename[, clobber])

Save results of the last simulation to a FITS file.

simulate([sky_positions, focal_positions, ...])

Simulate a single exposure.

Attributes Documentation

camera_output

list: List of per-camera simulation output tables.

Tables are listed in order of increasing wavelength and tabulated using the output pixels defined for each camera. Tables are overwritten during each call to simulate(). See Simulation Outputs for details of the contents of each table in this list.

Returns an empty list if this Simulator was initialized with camera_output False.

num_fibers

Number of fibers being simulated.

simulated

astropy.table.Table: Table of high-resolution simulation results.

This table is tabulated using the high-resolution wavelength used for internal calclulations and overwritten during each call to simulate(). See Simulation Outputs for details of this table’s contents.

Methods Documentation

generate_random_noise(random_state=None, use_poisson=True)[source] [edit on github]

Generate a random noise realization for the most recent simulation.

Fills the “random_noise_electrons” column in each camera’s output table, which is zeroed after each call to simulate(). Can be called repeatedly for the same simulated response to generate different noise realizations.

Noise is modeled as a Poisson fluctuation of the mean number of detected electrons from the source + sky + dark current, combined with a Gaussian fluctuation of the mean read noise.

The noise is generated in units of detected electrons. To propagate the generated noise to a corresponding calibrated flux noise, use:

output['flux_calibration'] * output['random_noise_electrons']
Parameters:
random_statenumpy.random.RandomState or None

The random number generation state to use for reproducible noise realizations. A new state will be created with a randomized seed if None is specified.

use_poissonbool

If False, use numpy.random.normal instead of numpy.random.poisson. This is useful for simulations where one wants the same noise realization for varying average flux (numpy.random.poisson uses a varying number of random numbers depending on the mean).

plot(fiber=0, wavelength_min=None, wavelength_max=None, title=None, min_electrons=2.5)[source] [edit on github]

Plot results of the last simulation for a single fiber.

Uses the contents of the simulated and camera_output astropy tables to plot the results of the last call to simulate(). See plot_simulation() for details.

Parameters:
fiberint

Fiber index to plot. Must be less than self.num_fibers.

wavelength_minquantity or None

Clip the plot below this wavelength, or show the full extent.

wavelength_maxquantity or None

Clip the plot above this wavelength, or show the full extent.

titlestr or None

Plot title to use. If None is specified, a title will be automatically generated using the source name, airmass and exposure time.

save(filename, clobber=True)[source] [edit on github]

Save results of the last simulation to a FITS file.

Parameters:
filenamestr

Name of the file where results should be saved. Must use the .fits extension.

clobberbool

Any existing file will be silently overwritten when clobber is True.

simulate(sky_positions=None, focal_positions=None, fiber_acceptance_fraction=None, source_fluxes=None, source_types=None, source_fraction=None, source_half_light_radius=None, source_minor_major_axis_ratio=None, source_position_angle=None, calibration_surface_brightness=None, save_fiberloss=None)[source] [edit on github]

Simulate a single exposure.

Simulation results are written to internal tables that are overwritten each time this method is called. Some metadata is also saved as attributes of this object: focal_x, focal_y, fiber_area.

The positions and properties of each source can optionally be specified individually for each fiber via array arguments. Any parameters that are not specified this way will use the same value for each fiber taken from the configuration data, as noted below.

Fibers are positioned using either (x,y) focal-plane coordinates or else (ra,dec) sky coordinates. The first available item on this list will be used: - focal_positions argument. - sky_positions argument. - source.location.constants.focal_x,y config data. - source.location.sky config data. When config data is used, it is duplicated for all fibers. Use the verbose mode to see details on how fibers are being positioned. Note that the observing airmass will be calculated when positioning with sky coordinates, and then available via self.observation.airmass.

Calibration exposures can be simulated by providing an array of calibration_surface_brightness values to use. In this case, the source and fiberloss inputs are ignored, and no atmospheric emission or extinction are applied.

Per-camera output tables will not be filled if this Simulator was initialized with camera_output False.

Parameters:
sky_positionsastropy.units.Quantity or None

Sky positions of each object. Must have a length equal to num_fibers. Defaults to source.location.sky when None.

focal_positionsastropy.units.Quantity or None

Focal-plane coordinates of each object relative to the plate center, with length units. Must have a length equal to num_fibers. Defaults to source.location.constants.focal_x,y when None.

fiber_acceptance_fractionarray or None

Array of shape (num_fibers, num_wlen) giving the fiber acceptance fraction to use for each fiber. Defaults to calling fiberloss.calculate_fiber_acceptance_fraction() when None.

source_fluxesarray or None

Array of shape (num_fibers, num_wlen) giving the source flux above the atmosphere illuminating each fiber. Defaults to source.table when None.

source_typesarray or None

Array of strings with length num_fibers. Each string must have a corresponding pre-loaded fiberloss file in the configuration. Defaults to source.type when None.

source_fractionarray or None

Array of shape (num_fibers, 2) giving the disk and bulge fractions for each source. Fractions must be in the range [0, 1] and their sum must be <= 1. If their sum is <1, the remainder is modeled as a point-like component. Defaults to source.profile.disk,bulge_fraction when None.

source_half_light_radiusarray or None

Array of shape (num_fibers, 2) giving the disk and bulge half-light radii in on-sky angular units. Defaults to values in source.profile.disk,bulge_shape when None.

source_minor_major_axis_ratioarray or None

Array of shape (num_fibers, 2) giving the disk and bulge minor/major axis ratios, in the range (0,1]. Defaults to values in source.profile.disk,bulge_shape when None.

source_position_anglearray or None

Array of shape (num_fibers, 2) giving the disk and bulge major axis alignments, expressed as a clockwise rotation from the +x axis, with angular units. Defaults to values in source.profile.disk,bulge_shape when None.

calibration_surface_brightnessarray or None

Array of shape (num_fibers, num_wlen) giving the calibration source surface brightness illuminating each fiber. When this is set, all source parameters (those beginning with source_) and fiber_acceptance_fraction are ignored and this is assumed to be a calibration exposure.

save_fiberlossstr or None

Basename for saving FITS images and tabulated fiberloss. Ignored unless instrument.fiberloss.method is galsim.