scarlet.initialization¶
- scarlet.initialization.build_initialization_image(observations, spectra=None)[source]¶
Build a spectrum-weighted image from all observations.
- Parameters:
- observations: list of `~scarlet.observation.Observation`
Every observation with a suitable renderer will contribute to the initialization image, according to its noise level.
- spectra: list of arrays
for every observation: source spectrum to optimize for. If not set, assumes flat spectrum.
- Returns:
- image: array
image created by weighting all channels by spectrum
- std: array
the effective noise standard deviation of image
- scarlet.initialization.get_pixel_spectrum(sky_coord, observations, correct_psf=False, models=None, concat=True)[source]¶
Get the spectrum at sky_coord in observation.
Yields the spectrum of a single-pixel source with flux 1 in every channel, concatenated for all observations.
If correct_psf, it homogenizes the PSFs of the observations, which yields the correct spectrum for a flux=1 point source.
If model is set, it reads of the value of the model at sky_coord and yields the spectrum for that model.
- Parameters:
- sky_coord: tuple
Position in the observation
- observations: instance or list of `~scarlet.Observation`
Observation to extract SED from.
- correct_psf: bool
If PSF shape variations in the observations should be corrected.
- models: instance or list of arrays
Rendered models for this source in every observation
- concat: bool
Whether spectra from multiple observations are flattened
- Returns:
- spectrum: ~numpy.array
- scarlet.initialization.get_psf_spectrum(sky_coord, observations, compute_snr=False, concat=True)[source]¶
Get spectrum for a point source at sky_coord in observation
Equivalent to point source photometry for isolated sources. For extended source, this will underestimate the actual source flux in every channel. In case of crowding, the resulting photometry is likely contaminated by neighbors.
Yields the spectrum of a PSF-homogenized source of flux 1 in every channel, concatenated for all observations.
- Parameters:
- sky_coord: tuple
Position in the observation
- observations: instance or list of `~scarlet.Observation`
Observation to extract the spectrum from.
- compute_snr: bool
Whether the compute the SNR of a PSF at sky_coord
- concat: bool
Whether spectra from multiple observations are flattened
- Returns:
- spectrum: ~numpy.array`
- scarlet.initialization.init_all_sources(frame, centers, observations, thresh=1, max_components=1, min_components=1, min_snr=50, shifting=False, resizing=True, boxsize=None, fallback=True, silent=False, set_spectra=True)[source]¶
Initialize all sources in a blend
Seeks to initialize sources at the sky positions of centers with multiple components of type ExtendedSource. If each component has sufficient SNR, the model will be kept, otherwise one component is removed and the source reinitialized. If a source cannot be initialized, its index is returned in skipped.
See ~init_source for a description of the arguments
- Parameters:
- centerslist of tuples
(y, x) center location for each source in sky coordinates
- silent: bool
If set to True, will prevent exceptions from being thrown abd register the source index in a list of skipped sources.
- set_spectra: bool
If set to True, will solve for the best spectra of all sources given the observations. See set_spectra_to_match for details.
- Returns:
- sources: list
List of intialized sources, where each source derives from the ~scarlet.Component class.
- skipped: list
This list contains sources that failed to initialize with silent = True
- scarlet.initialization.init_source(frame, center, observations, thresh=1, max_components=1, min_components=1, min_snr=50, shifting=False, resizing=True, boxsize=None, fallback=True)[source]¶
Initialize a Source
The user can specify the number of desired components for the modeled source. If scarlet cannot initialize a model with the desired number of components it continues to attempt initialization of one fewer component until it finds a model that can be initialized. It is possible that scarlet will be unable to initialize a source with the desired number of components, for example a two component source might have degenerate components, a single component source might not have enough signal in the joint coadd (all bands combined together into single signal-to-noise weighted image for initialization) to initialize, and a true spurious detection will not have enough signal to initialize as a point source. If all of the models fail, including a CompactExtendedSource model, then this source is skipped.
- Parameters:
- frame~scarlet.Frame
The model frame for the scene
- centertuple of float`
(y, x) location for the center of the source.
- observationsinstance or list of ~scarlet.Observation
The Observation that contains the images, weights, and PSF used to generate the model.
- threshfloat
Multiple of the backround RMS used as a flux cutoff for morphology initialization
- max_componentsint
The maximum number of components in a source. If fallback is True then when a source fails to initialize with max_components it will continue to subtract one from the number of components until it reaches zero (which fits a CompactExtendedSource). If a point source cannot be fit then the source is skipped.
- min_componentsint
The minimum number of components in a source. Only relevent for fallback=True.
- min_snr: float
Mininmum SNR per component of a multi-component source. If fallback=True, every component needs to have at least min_snr, otherwise the component number will be reduced At last resort, the component is initialized with a PointSource morphology
- shiftingbool
Whether or not to fit the position of a source. This is an expensive operation and is typically only used when a source is on the edge of the detector.
- resizingbool
Whether or not to change the size of the source box.
- boxsize: int or None
Spatial size of the source box
- fallbackbool
Whether to reduce the number of components if the model cannot be initialized with max_components. Fallback = False is unlikely to be used in production but can be useful for troubleshooting when an error can cause a particular source class to fail every time.
- prerender: bool
Whether to initialize the source with pre-rendered observations. This is an experimental feature, which may be removed in the future.
- scarlet.initialization.set_spectra_to_match(sources, observations)[source]¶
Sets the spectra of any FactorizedComponent to match the Observations.
Computes the best-fit amplitude of the rendered model of the sources in every channel of every observation as a linear inverse problem.
- Parameters:
- sources: list of sources
Only FactorizedComponent or CombinedComponent will be considered
- observations: `scarlet.Observation` or list thereof