opticam.reducer =============== .. py:module:: opticam.reducer Classes ------- .. autoapisummary:: opticam.reducer.Reducer Functions --------- .. autoapisummary:: opticam.reducer.log_reducer_params opticam.reducer.log_dark_current opticam.reducer.set_psf_params opticam.reducer.parse_alignment_results opticam.reducer.save_background opticam.reducer.save_unaligned_files opticam.reducer.get_random_image_for_each_filter 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) 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. .. py:method:: 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 ---------- save : bool, optional Whether to save the plot, by default `False`. .. py:method:: 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 ---------- 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], }, ) ``` save : bool, optional Whether to save the plots, by default `False`. .. py:method:: plot_psfs() Plot the PSFs for the catalog sources. .. py:method:: plot_snrs(save = False) Plot the signal-to-noise ratios for each catalogued source in the reference images. Parameters ---------- save : bool, optional Whether to save the plot, by default `False`. .. py:method:: plot_noise(save = False) Plot the noise characterisation for each reference image. Parameters ---------- save : bool, optional Whether to save the plot, by default 'False'. .. 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:: plot_apertures(photometer, targets = None, save = False) Plot the apertures over each source. Parameters ---------- photometer : AperturePhotometer The `AperturePhotometer` instance. If a local background estimator has been defined, this will also be plotted. targets : Dict[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], }, ) ``` save : bool, optional Whether to save the plots, 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:method:: update_unaligned_files(files) Add one or more files to the list of unaligned files. Unaligned files are skipped when performing photometry. Parameters ---------- files : str | List[str] The file or files. .. py:function:: log_reducer_params(reducer) Log the input parameters of a `Reducer` instance to file. Parameters ---------- reducer : Reducer The `Reducer` instance. .. py:function:: log_dark_current(out_directory, dark_currs, bmjds, camera_files) Save the dark currents for each filter. Parameters ---------- out_directory : str The path to the output directory. dark_currs : Dict[str, float] The dark current for each file {file: dark current}. bmjds : Dict[str, float] The time stamp for each file {file: time stamp}. camera_files : Dict[str, List[str]] The files grouped by filter {filter: files}. .. 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:: save_background(out_directory, background, fltr, bmjds) Save the median background and its RMS to a CSV file. Parameters ---------- out_directory : str The output directory. background : Dict[str, Dict[str, float]] The background values for each file. fltr : str The corresponding filter. bmjds : Dict[str, float] The BMJD values for each file. .. py:function:: save_unaligned_files(out_directory, unaligned_files) Save the unaligned files to a text file. Parameters ---------- out_directory : str The output directory. unaligned_files : List[str] The list of unaligned files. .. py:function:: get_random_image_for_each_filter(camera_files) Choose a random image for each filter from a dictionary. Parameters ---------- camera_files : Dict[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 .. 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.