LBCgo.lbcproc ============= .. py:module:: LBCgo.lbcproc Functions --------- .. autoapisummary:: LBCgo.lbcproc.check_external_dependencies LBCgo.lbcproc.go_overscan LBCgo.lbcproc.make_bias LBCgo.lbcproc.go_bias LBCgo.lbcproc.make_flatfield LBCgo.lbcproc.go_flatfield LBCgo.lbcproc.go_cleancosmic LBCgo.lbcproc.make_targetdirectories LBCgo.lbcproc.go_extractchips LBCgo.lbcproc.go_scrub LBCgo.lbcproc.lbcgo Module Contents --------------- .. py:function:: check_external_dependencies() Check if required external tools are available. .. py:function:: go_overscan(image_collection, lbc_chips=True, objects_only=True, image_directory='./', raw_directory='./raw/', verbose=True, return_files=True) Remove overscan and trim LBC object images. Fits a 4th-order polynomial to each chip's overscan strip (``BIASSEC``), subtracts it, then trims to the science region (``TRIMSEC``). Also removes LBC header keywords that confuse downstream astrometric tools (``BIASSEC``, ``TRIMSEC``, ``DATASEC``, ``ROTANGLE``, ``PARANGLE``, and all duplicate keywords ending in ``A``). By default only processes frames with ``IMAGETYP=object``; calibration frames are handled internally by :func:`make_bias` and :func:`make_flatfield`. :param image_collection: Collection of raw LBC FITS files. :type image_collection: ccdproc.ImageFileCollection :param lbc_chips: Chips to process. If True, processes all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param objects_only: If True, restrict to ``IMAGETYP=object`` frames. Default: True :type objects_only: bool, optional :param image_directory: Output directory for overscan-corrected files. Default: './' :type image_directory: str, optional :param raw_directory: Directory containing raw input files. Default: './raw/' :type raw_directory: str, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :param return_files: Return a list of output filenames. Default: True :type return_files: bool, optional :returns: Paths to overscan-corrected, trimmed FITS files (``*_over.fits``), or None if ``return_files=False``. :rtype: list of str or None .. py:function:: make_bias(image_collection, bias_filename=None, lbc_chips=True, image_directory='./', raw_directory='./raw/', verbose=True) Create a master bias frame from a collection of zero frames. Overscan-subtracts and trims each bias frame, then median-combines with 3-sigma clipping. The result is written as a multi-extension FITS file (one extension per chip). The number of combined frames is recorded in each chip header as ``NCOMBINE``. :param image_collection: Collection containing raw bias frames (``IMAGETYP=zero``). :type image_collection: ccdproc.ImageFileCollection :param bias_filename: Output filename for the master bias. Default: ``'zero.fits'`` :type bias_filename: str or None, optional :param lbc_chips: Chips to process. If True, processes all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param image_directory: Output directory for the master bias. Default: './' :type image_directory: str, optional :param raw_directory: Directory containing raw bias frames. Default: './raw/' :type raw_directory: str, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional .. py:function:: go_bias(image_collection, bias_file=None, image_directory='./', input_directory='./', bias_directory='./', lbc_chips=True, verbose=True, return_files=False) Apply a master bias frame to multi-extension FITS object data. :param image_collection: Collection or list of filenames for the overscan-corrected object frames. :type image_collection: ccdproc.ImageFileCollection or list of str :param bias_file: Filename of the master bias. Default: ``'zero.fits'`` :type bias_file: str or None, optional :param image_directory: Output directory for bias-subtracted files. Default: './' :type image_directory: str, optional :param input_directory: Directory containing the input object frames. Default: './' :type input_directory: str, optional :param bias_directory: Directory containing the master bias file. Default: './' :type bias_directory: str, optional :param lbc_chips: Chips to process. If True, processes all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :param return_files: Return a list of output filenames. Default: False :type return_files: bool, optional :returns: Paths to bias-subtracted FITS files (``*_zero.fits``), or None if ``return_files=False``. :rtype: list of str or None .. py:function:: make_flatfield(image_collection, filter_name=None, lbc_chips=True, image_directory='./', raw_directory='./raw/', cosmiccorrect=False, verbose=True) Create a master sky flat field for a single filter. Overscan-subtracts and trims each sky flat (``IMAGETYP=flat``, ``OBJECT=SkyFlat``), rejects frames with mean counts above 55,000 ADU as saturated, normalises the remaining frames to a common level, and median-combines with 3-sigma clipping. The number of combined frames is stored as ``NCOMBINE`` in the primary header. :param image_collection: Collection containing raw sky flat frames. :type image_collection: ccdproc.ImageFileCollection :param filter_name: Filter to process. If None, uses the first filter found in the collection summary. Default: None :type filter_name: str or None, optional :param lbc_chips: Chips to process. If True, processes all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param image_directory: Output directory for the master flat. Default: './' :type image_directory: str, optional :param raw_directory: Directory containing raw flat frames. Default: './raw/' :type raw_directory: str, optional :param cosmiccorrect: Apply cosmic-ray cleaning to individual flats before combining. Default: False :type cosmiccorrect: bool, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :returns: Writes ``flat..fits`` to ``image_directory``. Returns None if no usable flat frames are found. :rtype: None .. py:function:: go_flatfield(image_collection, flat_file=None, filter_names=None, image_directory='./', input_directory='./', flat_directory='./', lbc_chips=True, cosmiccorrect=True, verbose=True, return_files=False) Apply master flat fields to multi-extension FITS object data. Loops over filters, reads the corresponding master flat, and divides each object frame by it. Pre-flat-fielded files are moved to a ``data/`` subdirectory. Output files carry the ``_flat.fits`` suffix. :param image_collection: Collection of bias-corrected (or overscan-only) object frames. :type image_collection: ccdproc.ImageFileCollection :param flat_file: Override flat filename. If None, expects ``flat..fits`` in ``flat_directory``. Default: None :type flat_file: str or None, optional :param filter_names: Filters to process. If None, all filters in the collection are used. Default: None :type filter_names: list of str or None, optional :param image_directory: Output directory for flat-fielded files. Default: './' :type image_directory: str, optional :param input_directory: Directory containing input object frames. Default: './' :type input_directory: str, optional :param flat_directory: Directory containing master flat files. Default: './' :type flat_directory: str, optional :param lbc_chips: Chips to process. If True, processes all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param cosmiccorrect: Apply cosmic-ray cleaning before flat fielding. Default: True :type cosmiccorrect: bool, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :param return_files: Return a list of output filenames. Default: False :type return_files: bool, optional :returns: Paths to flat-fielded FITS files (``*_flat.fits``), or None if ``return_files=False``. :rtype: list of str or None .. py:function:: go_cleancosmic(ccd, mbox=15, rbox=15, gbox=11, sigclip=5, cleantype='medmask', cosmic_method='lacosmic') .. py:function:: make_targetdirectories(image_collection, image_directory='./', object_names=None, verbose=True) Organise flat-fielded files into per-target and per-filter subdirectories. Creates ``/`` and ``//`` subdirectories and moves files into them. Spaces in object names are stripped (``NGC 891`` → ``NGC891``). Existing directories are silently reused. :param image_collection: Collection of flat-fielded object frames to organise. :type image_collection: ccdproc.ImageFileCollection :param image_directory: Root output directory under which target subdirectories are created. Default: './' :type image_directory: str, optional :param object_names: Restrict processing to these object names. If None, all unique ``OBJECT`` values in the collection are used. Default: None :type object_names: list of str or None, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :returns: * **object_directories** (*list of str*) -- Paths to the per-target directories that were created or reused. * **filter_directories** (*list of str*) -- Paths to the per-filter subdirectories within each target directory. .. py:function:: go_extractchips(filter_directories, lbc_chips=True, verbose=True, return_files=False) Split multi-extension flat-fielded files into single-chip FITS files. For each ``*_flat.fits`` file found in the supplied filter directories, writes one output file per chip named ``_.fits``, each containing a single image extension. The original multi-extension file is moved to a ``data/`` subdirectory. Output files are the direct inputs to the astrometric registration step. :param filter_directories: Directory path(s) containing ``*_flat.fits`` multi-extension files. :type filter_directories: str or list of str :param lbc_chips: Chips to extract. If True, extracts all 4 chips. Default: True :type lbc_chips: bool or list of int, optional :param verbose: Print progress messages. Default: True :type verbose: bool, optional :param return_files: Return a list of output filenames. Default: False :type return_files: bool, optional :returns: Paths to per-chip FITS files (e.g. ``*_1.fits`` … ``*_4.fits``), or None if ``return_files=False``. :rtype: list of str or None .. py:function:: go_scrub() .. py:function:: lbcgo(raw_directory='./raw/', image_directory='./', lbc_chips=True, lbcr=True, lbcb=True, filter_names=None, bias_proc=False, do_astrometry=True, astrometric_catalog='GAIA-DR3', scamp_iterations=3, verbose=True, clean=True) Process a directory of LBC (Large Binocular Camera) data through the complete reduction pipeline. This function performs comprehensive data reduction for LBT LBC observations, including overscan subtraction, flat fielding, cosmic ray removal, chip extraction, astrometric calibration, and final image combination. The pipeline processes multi-extension FITS files from both LBC-Blue and LBC-Red cameras. Detailed Processing Steps: 1. Collect and filter raw image files by camera and filter 2. Create master bias frames (optional) 3. Create master flat field frames per filter 4. Remove overscan regions and trim images 5. Apply bias correction (optional) 6. Apply flat field correction 7. Organize data by target and filter into subdirectories 8. Extract individual CCD chips for astrometric processing 9. Perform astrometric calibration using SExtractor/SCAMP (optional) 10. Co-add registered images using SWARP (optional) :param raw_directory: Path to directory containing raw LBC FITS files. Files should follow the naming convention 'lbc[br].YYYYMMDD.NNNNNN.fits'. Default: './raw/' :type raw_directory: str, optional :param image_directory: Output directory for processed images and intermediate files. Default: './' :type image_directory: str, optional :param lbc_chips: CCD chips to process. If True, processes all 4 chips [1,2,3,4]. Can specify subset as list (e.g., [1,3]). Default: True :type lbc_chips: bool or list, optional :param lbcr: Process LBC-Red camera data. Default: True :type lbcr: bool, optional :param lbcb: Process LBC-Blue camera data. Default: True :type lbcb: bool, optional :param filter_names: List of filter names to process (e.g., ['g-SLOAN', 'r-SLOAN']). If None, processes all filters found in data. Default: None :type filter_names: list or None, optional :param bias_proc: Apply bias frame correction. Requires bias frames in raw data. Default: False :type bias_proc: bool, optional :param do_astrometry: Perform astrometric calibration and image registration using SExtractor, SCAMP, and SWARP. Requires external tools to be installed. Default: True :type do_astrometry: bool, optional :param astrometric_catalog: Astrometric reference catalog to use for SCAMP calibration. Common options include 'GAIA-DR3', 'SDSS-R12', '2MASS', etc. Default: 'GAIA-DR3' :type astrometric_catalog: str, optional :param scamp_iterations: Number of SCAMP iterations for astrometric solution refinement. Minimum of 2 iterations recommended. Default: 3 :type scamp_iterations: int, optional :param verbose: Print detailed processing information and progress. Default: True :type verbose: bool, optional :param clean: Clean up intermediate files after processing. If True, removes intermediate files and diagnostic outputs. If False, preserves catalog files in 'cat/' directory for inspection. Default: True :type clean: bool, optional :returns: Function performs file operations and creates output images in specified directories. Final products include flat-fielded individual chip images and (if do_astrometry=True) astrometrically-calibrated combined images. :rtype: None .. rubric:: Notes - Raw files are expected to be multi-extension FITS with 4 CCD extensions - SkyFlatTest images are automatically excluded from processing - External dependencies (SExtractor, SCAMP, SWARP) are required if do_astrometry=True - For nights with V-band observations from both cameras, run separately with lbcr=False then lbcb=False to avoid inappropriate co-addition - Processing creates subdirectories organized by target name and filter - Intermediate files are moved to a 'data/' subdirectory during processing .. rubric:: Examples Basic processing with astrometry: >>> lbcgo() Process only g-band data from LBC-Blue: >>> lbcgo(lbcb=True, lbcr=False, filter_names=['g-SLOAN']) Process without astrometric calibration: >>> lbcgo(do_astrometry=False) Custom directories and bias correction: >>> lbcgo(raw_directory='/data/lbc/raw/', ... image_directory='/data/lbc/reduced/', ... bias_proc=True)