opticam.reducer
Classes
Class for reducing astronomical images. |
Functions
|
Set the PSF parameters. |
|
Parse the alignment results. |
|
Write queued logs to file. |
|
Save the median background and its RMS to a CSV file. |
|
Save the unaligned files to a text file. |
|
Choose a random image for each filter from a dictionary. |
|
Create a dictionary of target IDs for all catalog sources. |
|
Save the photometry results to disk. |
|
Merge the multiprocessed photometry results into a single dictionary. |
|
Save a camera:filter catalog to file using astropy's ECSV format. |
Module Contents
- class opticam.reducer.Reducer(out_directory, data_directory, aperture_selector=np.median, background=None, barycenter=True, bias_corrector=None, dark_corrector=None, finder=None, flat_corrector=None, instrument=OPTICAM_MX(), number_of_processors=cpu_count() // 2, rebin_factor=1, remove_cosmic_rays=False, show_plots=True, threshold=5, verbose=True)
Class for reducing astronomical images.
- Parameters:
out_directory (pathlib.Path | str)
data_directory (pathlib.Path | str)
aperture_selector (Callable)
background (opticam.background.global_background.BaseBackground | None)
barycenter (bool)
bias_corrector (opticam.correctors.BiasCorrector | None)
dark_corrector (opticam.correctors.DarkNoiseCorrector | None)
finder (None | Callable)
flat_corrector (opticam.correctors.FlatFieldCorrector | None)
instrument (opticam.instruments.Instrument)
number_of_processors (int)
rebin_factor (int)
remove_cosmic_rays (bool)
show_plots (bool)
threshold (float)
verbose (bool)
- verbose = True
- out_directory
- logger
- data_directory
- rebin_factor = 1
- instrument
- aperture_selector
- threshold = 5
- remove_cosmic_rays = False
- barycenter = True
- number_of_processors
- show_plots = True
- bias_corrector = None
- dark_corrector = None
- flat_corrector = None
- reference_files
- transforms
- unaligned_files = []
- catalogs: dict[str, astropy.table.QTable]
- psf_params
- _log_params()
Log the input parameters of a Reducer instance to file.
Parameters
- reducerReducer
The Reducer instance.
- Return type:
None
- create_catalogs(max_catalog_sources=15, n_alignment_sources=15, transform_type='affine', rotation_limit=None, translation_limit=None, scale_limit=None, overwrite=False)
Initialise the source catalogs for each camera. Some aspects of this method are parallelised for speed.
Parameters
- max_catalog_sourcesint, optional
The maximum number of sources to include in the catalog, by default 30. Since source IDs are ordered by brightness, the brightest max_catalog_sources sources are included in the catalog.
- n_alignment_sourcesint, optional
The (maximum) number of sources to use for image alignment, by default 30. If transform_type=’translation’, n_alignment_sources must be >= 1, and the brightest n_alignment_sources sources are used for image alignment. If transform_type=’affine’, n_alignment_sources must be >= 3 and represents that maximum number of sources that may be used for image alignment.
- transform_typeLiteral[‘affine’, ‘translation’], optional
The type of transform to use for image alignment, by default ‘affine’. ‘translation’ performs simple x, y translations, while ‘affine’ uses astroalign.find_transform(). ‘affine’ is generally more robust (and is therefore the default) while ‘translation’ can work with fewer sources.
- rotation_limitfloat, optional
The maximum rotation limit (in degrees) for affine transformations, by default None (no limit).
- scale_limitfloat, optional
The maximum scale limit for affine transformations, by default None (no limit).
- translation_limitfloat | int | list[float | int] | None, optional
The maximum translation limit for both types of transformations, by default None (no limit). Can be a scalar value that applies to both x- and y-translations, or an iterable where the first value defines the x-translation limit and the second value defines the y-translation limit.
- overwritebool, optional
Whether to overwrite existing catalogs, by default False.
- Parameters:
max_catalog_sources (int)
n_alignment_sources (int)
transform_type (Literal['affine', 'translation'])
rotation_limit (float | None)
translation_limit (float | int | list[float | int] | None)
scale_limit (float | None)
overwrite (bool)
- Return type:
None
- _align_batch(batch, reference_image_shape, reference_coords, transform_type, rotation_limit, scale_limit, translation_limit, n_alignment_sources)
Align a batch of images with respect to some reference coordinates.
Parameters
- batch: list[MEFSlice]
The files.
- reference_image_shapetuple[int]
The reference image’s shape.
- reference_coordsNDArray
The source coordinates in the reference image.
- transform_typeLiteral[‘affine’, ‘translation’]
The type of transform to use for image alignment.
- rotation_limitfloat | None
The maximum rotation limit (in degrees) for image alignment.
- scale_limitfloat | None
The maximum scaling limit for image alignment.
- translation_limitlist[float] | None
The maximum translation limit for image alignment.
- n_alignment_sourcesint
The (maximum) number of sources to use for image alignment.
Returns
- tuple[NDArray[np.float64], dict[str, list[float]], dict[str, dict[str, float]], list[tuple[str, str]]]
The stacked image, transforms, background results, and log messages.
- Parameters:
batch (list[opticam.mef_slice.MEFSlice])
reference_image_shape (tuple[int])
reference_coords (numpy.typing.NDArray)
transform_type (Literal['affine', 'translation'])
rotation_limit (float | None)
scale_limit (float | None)
translation_limit (list[float] | None)
n_alignment_sources (int)
- Return type:
tuple[numpy.typing.NDArray[numpy.float64], dict[str, list[float]], dict[str, dict[str, float]], list[tuple[str, str]]]
- _valid_transform(file, transform, rotation_limit, scale_limit, translation_limit)
Find whether a transform is valid given some transform limits.
Parameters
- fileMEFSlice
The path to the file being transformed.
- transformSimilarityTransform
The transform.
- rotation_limitfloat | None
The rotation limit.
- scale_limitfloat | None
The scale limit.
- translation_limitlist[float] | None
The translation limit.
Returns
- tuple[bool, None | tuple[str, str]]
Whether the transform is valid. If not, a log message is also returned as a tuple: (log level, log string).
- Parameters:
file (opticam.mef_slice.MEFSlice)
transform (skimage.transform.SimilarityTransform)
rotation_limit (float | None)
scale_limit (float | None)
translation_limit (list[float] | None)
- Return type:
tuple[bool, None | tuple[str, str]]
- plot_background_meshes(save=False)
Plot the background mesh over an image from each filter to verify it’s appropriately sized. If stacked catalog images exist, those will be used. Otherwise, a random image will be chosen for each filter.
Parameters
- savebool, optional
Whether to save the plot, by default False.
- Parameters:
save (bool)
- Return type:
None
- plot_growth_curves(targets=None, save=False)
Plot the growth curves for the sources identified in the catalog images. The resulting plots are saved to out_directory/diag/growth_curves as PDF files.
Parameters
- targetsdict[str, int | list[int]] | None, optional
The targets for which growth curves will be created, by default None (growth curves are created for all catalog sources). To create growth curves for specific targets, pass a dictionary with keys listing the desired filters and values listing each filter’s correpsonding target(s). For example: ``` # plot growth curves for the three brightest sources in each catalog plot_growth_curves(
- targets = {
‘g’: [1, 2, 3], ‘r’: [1, 2, 3], ‘i’: [1, 2, 3], },
)
- savebool, optional
Whether to save the plots, by default False.
- Parameters:
targets (dict[str, int | list[int]] | None)
save (bool)
- Return type:
None
- plot_psfs()
Plot the PSFs for the catalog sources.
- Return type:
None
- plot_snrs(save=False)
Plot the signal-to-noise ratios for each catalogued source in the reference images.
Parameters
- savebool, optional
Whether to save the plot, by default False.
- Parameters:
save (bool)
- Return type:
None
- plot_noise(save=False)
Plot the noise characterisation for each reference image.
Parameters
- savebool, optional
Whether to save the plot, by default ‘False’.
- Parameters:
save (bool)
- Return type:
None
- create_gifs(keep_frames=True, overwrite=False)
Create alignment gifs for each camera. Some aspects of this method are parallelised for speed. The frames are saved in out_directory/diag/*_gif_frames and the GIFs are saved in out_directory/cat.
Parameters
- keep_framesbool, optional
Whether to save the GIF frames in out_directory/diag, by default True. If False, the frames will be deleted after the GIF is saved.
- overwritebool, optional
Whether to overwrite existing GIFs, by default False.
- Parameters:
keep_frames (bool)
overwrite (bool)
- Return type:
None
- plot_apertures(photometer, targets=None, save=False)
Plot the apertures over each source.
Parameters
- photometerAperturePhotometer
The AperturePhotometer instance. If a local background estimator has been defined, this will also be plotted.
- targetsdict[str, int] | dict[str, list[int]] | dict[str, list[int] | int] | None
The targets for which apertures will be plotted, by default None (apertures are plotted for all sources). To plot apertures for specific targets, pass a dictionary with keys listing the desired filters and values listing each filter’s correpsonding target(s). For example: ``` # plot apertures for the three brightest sources in each filter photometer = opticam.AperturePhotometer() plot_apertures(
photometer=photometer, targets = {
‘g’: [1, 2, 3], ‘r’: [1, 2, 3], ‘i’: [1, 2, 3], },
)
- savebool, optional
Whether to save the plots, by default False.
- Parameters:
photometer (opticam.photometers.AperturePhotometer)
targets (dict[str, int] | dict[str, list[int]] | dict[str, list[int] | int] | None)
save (bool)
- Return type:
None
- photometry(photometer, overwrite=False)
Perform photometry on the catalogs using the provided photometer.
Parameters
- photometerBasePhotometer
The photometer. Should be a subclass of BasePhotometer, or implement a compute method that follows the BasePhotometer interface.
- overwritebool, optional
Whether to overwrite any existing light curves files computed using the same photometer, by default False.
- Parameters:
photometer (opticam.photometers.BasePhotometer)
overwrite (bool)
- Return type:
None
- _perform_photometry(file, photometer, cat_coords, key)
Perform photometry on a file.
Parameters
- fileMEFSlice
The file.
- photometerBasePhotometer
The photometer to use.
- cat_coordsNDArray
The coordinates of the sources in the catalog.
- keystr
The camera:filter key.
Returns
- dict[str, list]
The photometry results.
- Parameters:
file (opticam.mef_slice.MEFSlice)
photometer (opticam.photometers.BasePhotometer)
cat_coords (numpy.typing.NDArray)
key (str)
- Return type:
dict[str, list]
- update_unaligned_files(files)
Add one or more files to the list of unaligned files. Unaligned files are skipped when performing photometry.
Parameters
- filesMEFSlice | list[MEFSlice]
The file or files.
- Parameters:
files (opticam.mef_slice.MEFSlice | list[opticam.mef_slice.MEFSlice])
- Return type:
None
- opticam.reducer.set_psf_params(aperture_selector, catalog)
Set the PSF parameters.
Parameters
- aperture_selectorCallable
The aperture selector (e.g., numpy.median).
- catalogQTable
The source catalog.
Returns
- dict[str, float]
The PSF parameters.
- Parameters:
aperture_selector (Callable)
catalog (astropy.table.QTable)
- Return type:
dict[str, float]
- opticam.reducer.parse_alignment_results(results, camera_files, transforms, unaligned_files, logger)
Parse the alignment results.
Parameters
- resultstuple
The alignment results.
- camera_fileslist[MEFSlice]
The files.
- transformsdict[Path, list[float]]
The image-to-image alignments {file path: transform}.
- unaligned_fileslist[MEFSlice]
The files that could not be aligned.
- loggerLogger
The logger.
Returns
- tuple[dict[str, list[float]], list[str], NDArray, dict[str, float], dict[str, float]]
The updated transforms, unaligned files, stacked image, median background values and median background RMS values.
- Parameters:
results (tuple)
camera_files (list[opticam.mef_slice.MEFSlice])
transforms (dict[str, list[float]])
unaligned_files (list[opticam.mef_slice.MEFSlice])
logger (logging.Logger)
- Return type:
tuple[dict[str, list[float]], list[opticam.mef_slice.MEFSlice], numpy.typing.NDArray[numpy.float64], dict[str, dict[str, float]]]
- opticam.reducer.write_queued_logs(queued_logs, logger)
Write queued logs to file.
Parameters
- queued_logslist[tuple[str, str]]
The queued logs (level, log).
- loggerLogger
The logger.
Raises
- ValueError
If the log level is not recognised.
- Parameters:
queued_logs (list[tuple[str, str]])
logger (logging.Logger)
- Return type:
None
- opticam.reducer.save_background(out_directory, background, key, bmjds)
Save the median background and its RMS to a CSV file.
Parameters
- out_directoryPath
The output directory.
- backgrounddict[Path, dict[str, float]]
The background values for each file.
- keystr
The camera:filter key.
- bmjdsdict[Path, float]
The BMJD values for each file {file path}.
- Parameters:
out_directory (pathlib.Path)
background (dict[str, dict[str, float]])
key (str)
bmjds (dict[str, float])
- Return type:
None
- opticam.reducer.save_unaligned_files(out_directory, unaligned_files)
Save the unaligned files to a text file.
Parameters
- out_directoryPath
The output directory.
- unaligned_fileslist[MEFSlice]
The list of unaligned files.
- Parameters:
out_directory (pathlib.Path)
unaligned_files (list[opticam.mef_slice.MEFSlice])
- Return type:
None
- opticam.reducer.get_random_image_for_each_filter(camera_files, instrument)
Choose a random image for each filter from a dictionary.
Parameters
- camera_filesdict[str, list[Path]]
The filters and corresponding files in the data directory {filter: [paths to images]}.
- instrumentInstrument
The instrument.
Returns
- dict[str, NDArray]
A dictionary containing a random file for each filter
- Parameters:
camera_files (dict[str, list[opticam.mef_slice.MEFSlice]])
instrument (opticam.instruments.Instrument)
- Return type:
dict[str, numpy.typing.NDArray]
- opticam.reducer.create_targets_dict(catalogs)
Create a dictionary of target IDs for all catalog sources.
Parameters
- catalogsdict[str, QTable]
The catalogs.
Returns
- dict[str, list[int]]
The target IDs for all catalog sources.
- Parameters:
catalogs (dict[str, astropy.table.QTable])
- Return type:
dict[str, list[int]]
- opticam.reducer.save_photometry_results(results, catalogs, barycenter, save_dir, key)
Save the photometry results to disk.
Parameters
- resultstuple[dict]
The photometry results.
- catalogsdict[str, QTable]
The source catalogs.
- save_dirPath
The save directory path.
- keystr
The camera:filter key.
- Parameters:
results (tuple[dict])
catalogs (dict[str, astropy.table.QTable])
barycenter (bool)
save_dir (pathlib.Path)
key (str)
- opticam.reducer.parse_photometry_results(results)
Merge the multiprocessed photometry results into a single dictionary.
Parameters
- resultstuple[dict[str, list]]
The multiprocessed photometry results.
Returns
- dict[str, list[list[float]]]
The photometry results in a single dictionary.
- Parameters:
results (tuple[dict[str, list]])
- Return type:
dict[str, list[list[float]]]
- opticam.reducer.save_catalog(catalog, key, out_directory)
Save a camera:filter catalog to file using astropy’s ECSV format.
Parameters
- catalogQTable
The catalog for a specific camera:filter combination.
- keystr
The camera:filter key.
- out_directoryPath
The output directory.
- Parameters:
catalog (astropy.table.QTable)
key (str)
out_directory (pathlib.Path)
- Return type:
None