opticam.reducer =============== .. py:module:: opticam.reducer Classes ------- .. autoapisummary:: opticam.reducer.Reducer Functions --------- .. autoapisummary:: opticam.reducer.log_reducer_params opticam.reducer.set_psf_params opticam.reducer.parse_alignment_results opticam.reducer.create_targets_dict opticam.reducer.save_photometry_results opticam.reducer.parse_photometry_results Module Contents --------------- .. py:class:: 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. .. py:attribute:: verbose :value: True .. py:attribute:: out_directory .. py:attribute:: logger .. py:attribute:: data_directory :value: None .. py:attribute:: c1_directory :value: None .. py:attribute:: c2_directory :value: None .. py:attribute:: c3_directory :value: None .. py:attribute:: rebin_factor :value: 1 .. py:attribute:: flat_corrector :value: None .. py:attribute:: aperture_selector .. py:attribute:: threshold :value: 5 .. py:attribute:: remove_cosmic_rays :value: False .. py:attribute:: barycenter :value: True .. py:attribute:: number_of_processors .. py:attribute:: show_plots :value: True .. py:attribute:: reference_files .. py:attribute:: transforms .. py:attribute:: unaligned_files :value: [] .. py:attribute:: catalogs :type: Dict[str, astropy.table.QTable] .. py:attribute:: psf_params .. py:method:: create_catalogs(max_catalog_sources = 15, n_alignment_sources = 15, transform_type = 'affine', rotation_limit = None, translation_limit = None, scale_limit = None, overwrite = False, show_diagnostic_plots = False) Initialise the source catalogs for each camera. Some aspects of this method are parallelised for speed. Parameters ---------- max_catalog_sources : int, 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_sources : int, 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_type : Literal['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_limit : float, optional The maximum rotation limit (in degrees) for affine transformations, by default `None` (no limit). scale_limit : float, optional The maximum scale limit for affine transformations, by default `None` (no limit). translation_limit : float | 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. overwrite : bool, optional Whether to overwrite existing catalogs, by default False. show_diagnostic_plots : bool, optional Whether to show diagnostic plots, by default False. Diagnostic plots are saved to out_directory, so this parameter only affects whether the plots are displayed in the console. .. py:method:: plot_growth_curves(targets = None, show = True) 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 ---------- targets : Dict[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], }, ) ``` show : bool, optional Whether to show the plots, by default `True`. The resulting plots are saved regardless of this value. .. py:method:: plot_psfs() Plot the PSFs for the catalog sources. .. py:method:: 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_frames : bool, 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. overwrite : bool, optional Whether to overwrite existing GIFs, by default False. .. py:method:: photometry(photometer, overwrite = False) Perform photometry on the catalogs using the provided photometer. Parameters ---------- photometer : BasePhotometer The photometer. Should be a subclass of `BasePhotometer`, or implement a `compute` method that follows the `BasePhotometer` interface. overwrite : bool, optional Whether to overwrite any existing light curves files computed using the same photometer, by default `False`. .. py:function:: log_reducer_params(reducer) .. py:function:: set_psf_params(aperture_selector, catalog) Set the PSF parameters. Parameters ---------- aperture_selector : Callable The aperture selector (e.g., `numpy.median`). catalog : QTable The source catalog. Returns ------- Dict[str, float] The PSF parameters. .. py:function:: parse_alignment_results(results, camera_files, transforms, unaligned_files, verbose) Parse the alignment results. Parameters ---------- results : Tuple The alignment results. camera_files : List[str] The file paths for all files. transforms : Dict[str, List[float]] The image-to-image alignments {file path: transform}. unaligned_files : List[str] The paths of the files that could not be aligned. verbose : bool 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. .. py:function:: create_targets_dict(catalogs) Create a dictionary of target IDs for all catalog sources. Parameters ---------- catalogs : Dict[str, QTable] The catalogs. Returns ------- Dict[str, List[int]] The target IDs for all catalog sources. .. py:function:: save_photometry_results(results, catalogs, barycenter, save_dir, fltr) Save the photometry results to disk. Parameters ---------- results : Tuple[Dict] The photometry results. catalogs : Dict[str, QTable] The source catalogs. save_dir : str The save directory path. fltr : str The photometry filter. .. py:function:: parse_photometry_results(results) Merge the multiprocessed photometry results into a single dictionary. Parameters ---------- results : Tuple[Dict[str, List]] The multiprocessed photometry results. Returns ------- Dict[str, List[List[float]]] The photometry results in a single dictionary.