opticam.reducer
Classes
Class for reducing OPTICAM data. |
Functions
|
Log the input parameters of a Reducer instance to file. |
|
Save the dark currents for each filter. |
|
Set the PSF parameters. |
|
Parse the alignment results. |
|
Save the median background and its RMS to a CSV 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. |
Module Contents
- class opticam.reducer.Reducer(out_directory, data_directory=None, c1_directory=None, c2_directory=None, c3_directory=None, rebin_factor=1, flat_corrector=None, background=None, finder=None, threshold=5, aperture_selector=np.median, remove_cosmic_rays=False, barycenter=True, number_of_processors=cpu_count() // 2, show_plots=True, verbose=True)
Class for reducing OPTICAM data.
- Parameters:
out_directory (str)
data_directory (None | str)
c1_directory (None | str)
c2_directory (None | str)
c3_directory (None | str)
rebin_factor (int)
flat_corrector (None | opticam.correctors.flat_field_corrector.FlatFieldCorrector)
background (opticam.background.global_background.BaseBackground | None)
finder (None | Callable)
threshold (float)
aperture_selector (Callable)
remove_cosmic_rays (bool)
barycenter (bool)
number_of_processors (int)
show_plots (bool)
verbose (bool)
- verbose = True
- out_directory
- logger
- data_directory = None
- c1_directory = None
- c2_directory = None
- c3_directory = None
- rebin_factor = 1
- flat_corrector = None
- aperture_selector
- threshold = 5
- remove_cosmic_rays = False
- barycenter = True
- number_of_processors
- show_plots = True
- reference_files
- transforms
- unaligned_files = []
- catalogs: Dict[str, astropy.table.QTable]
- psf_params
- 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
- 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-band’: [1, 2, 3], ‘r-band’: [1, 2, 3], ‘i-band’: [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/*-band_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-band’: [1, 2, 3], ‘r-band’: [1, 2, 3], ‘i-band’: [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
- opticam.reducer.log_reducer_params(reducer)
Log the input parameters of a Reducer instance to file.
Parameters
- reducerReducer
The Reducer instance.
- Parameters:
reducer (Reducer)
- Return type:
None
- opticam.reducer.log_dark_current(out_directory, dark_currs, bmjds, camera_files)
Save the dark currents for each filter.
Parameters
- out_directorystr
The path to the output directory.
- dark_currsDict[str, float]
The dark current for each file {file: dark current}.
- bmjdsDict[str, float]
The time stamp for each file {file: time stamp}.
- camera_filesDict[str, List[str]]
The files grouped by filter {filter: files}.
- Parameters:
out_directory (str)
dark_currs (Dict[str, float])
bmjds (Dict[str, float])
camera_files (Dict[str, List[str]])
- 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, verbose)
Parse the alignment results.
Parameters
- resultsTuple
The alignment results.
- camera_filesList[str]
The file paths for all files.
- transformsDict[str, List[float]]
The image-to-image alignments {file path: transform}.
- unaligned_filesList[str]
The paths of the files that could not be aligned.
- verbosebool
Whether to include output.
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[str])
transforms (Dict[str, List[float]])
unaligned_files (List[str])
verbose (bool)
- Return type:
Tuple[Dict[str, List[float]], List[str], numpy.typing.NDArray, Dict[str, Dict[str, float]]]
- opticam.reducer.save_background(out_directory, background, fltr, bmjds)
Save the median background and its RMS to a CSV file.
Parameters
- out_directorystr
The output directory.
- backgroundDict[str, Dict[str, float]]
The background values for each file.
- fltrstr
The corresponding filter.
- bmjdsDict[str, float]
The BMJD values for each file.
- Parameters:
out_directory (str)
background (Dict[str, Dict[str, float]])
fltr (str)
bmjds (Dict[str, float])
- Return type:
None
- opticam.reducer.get_random_image_for_each_filter(camera_files)
Choose a random image for each filter from a dictionary.
Parameters
- camera_filesDict[str, List[str]]
The filters and corresponding files in the data directory.
Returns
- Dict[str, NDArray]
A dictionary containing a random file for each filter
- Parameters:
camera_files (Dict[str, List[str]])
- 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, fltr)
Save the photometry results to disk.
Parameters
- resultsTuple[Dict]
The photometry results.
- catalogsDict[str, QTable]
The source catalogs.
- save_dirstr
The save directory path.
- fltrstr
The photometry filter.
- Parameters:
results (Tuple[Dict])
catalogs (Dict[str, astropy.table.QTable])
barycenter (bool)
save_dir (str)
fltr (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]]]