Skip to content

WCS/catalog refactor, photometry and zeropoint reliability, and FITS header fixes#83

Merged
charliekilpatrick merged 11 commits into
mainfrom
dev
Jun 9, 2026
Merged

WCS/catalog refactor, photometry and zeropoint reliability, and FITS header fixes#83
charliekilpatrick merged 11 commits into
mainfrom
dev

Conversation

@charliekilpatrick

@charliekilpatrick charliekilpatrick commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

This release merges dev into main with pipeline hardening across WCS, catalogs, photometry, and absolute photometric calibration.

  • WCS & astrometry

    • Validate existing celestial WCS in headers; add --skip-external-astrometry to bypass astrometry.net when WCS is already usable.
    • Refactor fine alignment around centralized catalog utilities; add --fine-align-catalog and related CLI options.
    • Normalize deprecated FITS WCS/time keywords (RADECSYSRADESYS, MJD-OBS / DATE-OBS) to avoid astropy WCS warnings; apply on GMOS extension load.
    • Improve sky-frame stacking for small frame counts and degenerate sigma-clipping edge cases.
  • Catalogs

    • Add potpyri/utils/catalogs.py as shared Vizier/catalog logic for WCS alignment and zeropoint fitting; slim down utilities.py re-exports.
  • Photometry & zeropoint

    • Introduce PhotometryError and clearer logging in photloop / do_phot when star detection or PSF photometry fails (no silent exit without APPPHOT).
    • Support photutils API changes: normalize DAOStarFinder x_centroid/y_centroid columns; improve compatibility across photutils versions.
    • Harden absphot.find_zeropoint when APPPHOT is missing or incomplete; return bool and emit actionable log messages instead of raising KeyError.
  • Tests

    • Add BINOSPEC FRB stack integration test (test_binspec_frb_stack_photometry.py) for photometry + zeropoint on a real stack (skips if local FITS absent).
    • Extend WCS, photometry, absphot, and instrument tests for new behavior.

Test plan

  • pytest tests/test_wcs.py tests/test_photometry.py tests/test_absphot.py tests/test_instruments.py
  • pytest tests/test_calibration.py (GMOS calibration integration)
  • Optional integration (requires local stack + network):
    POTPYRI_FRB_STACK_TEST=/path/to/FRB20260213A.r.ut260322.2.11.stk.fits pytest tests/test_binspec_frb_stack_photometry.py -v
  • Smoke-test main_pipeline on a small BINOSPEC or GMOS dataset through photometry and zeropoint steps
  • Confirm --skip-external-astrometry and --fine-align-catalog behave as expected on stacks with pre-existing WCS

Notes

  • Zeropoint step still requires network access to Vizier (e.g. PS1) unless a catalog is supplied externally.
  • Large example stacks under examples/ remain gitignored (local-only).

- Introduced `validate_existing_wcs_header` function to check for valid celestial WCS in FITS headers, ensuring required keywords are present and usable.
- Added `--skip-external-astrometry` option to command-line arguments, allowing users to bypass astrometry.net and Gaia if a valid WCS is already defined in the header.
- Updated `test_for_dependencies` to conditionally check for astrometry.net based on the new option.
- Enhanced `align_images` and `image_proc` functions to support the new external astrometry skipping behavior, including appropriate logging and header validation.
- Added unit tests for the new WCS validation functionality to ensure robustness and correctness.
- Updated the `utilities.py` module to re-export catalog-related functions for better organization and backward compatibility.
- Refactored `absphot.py` and `solve_wcs.py` to utilize the new catalog functions, enhancing clarity and maintainability.
- Introduced new command-line options for fine WCS alignment, allowing users to specify the reference catalog and skip alignment if desired.
- Updated tests to reflect changes in function names and ensure robust coverage for the new alignment process.
- Enhanced documentation to include new functions and options related to fine alignment.
- Introduced `fix_deprecated_wcs_header_cards` function to normalize WCS-related FITS header cards, addressing deprecated keywords like `RADECSYS` and `MJD-OBS`.
- Updated the `import_image` method in the `GMOS` class to utilize the new header normalization function, preventing warnings during WCS parsing.
- Enhanced sky frame processing logic to handle varying numbers of frames more robustly, ensuring proper median calculation and masking.
- Added unit tests for the new header normalization functionality to ensure correctness and prevent regressions.
- Introduced a new `PhotometryError` exception to handle cases where photometry fails due to insufficient star detection or S/N threshold issues.
- Updated the `do_phot` and `photloop` functions to raise `PhotometryError` with informative messages when no stars are detected or when photometry cannot be completed.
- Enhanced logging to provide detailed feedback during photometry attempts, including the S/N thresholds tried and the reasons for failure.
- Refactored the `find_zeropoint` function to improve error handling when the APPPHOT extension is missing from the FITS file.
- Added unit tests to ensure proper handling of missing APPPHOT scenarios and validate the new error messages.
- Introduced `_normalize_daofind_catalog` function to ensure compatibility with different versions of photutils by mapping `x_centroid` and `y_centroid` to `xcentroid` and `ycentroid`.
- Enhanced error handling in `get_star_catalog` to raise `PhotometryError` when no stars are detected.
- Added unit tests for the new normalization function to validate behavior across various input scenarios, including legacy column names and missing centroid columns.
- Improved the `PhotometryError` exception handling to provide clearer messages for various failure scenarios in photometry.
- Updated the `do_phot` and `photloop` functions to ensure informative error reporting when star detection fails or photometry cannot be completed.
- Enhanced logging capabilities to give detailed feedback during photometry attempts, including S/N thresholds and reasons for failure.
- Refactored the `find_zeropoint` function to better manage errors related to missing APPPHOT extensions in FITS files.
- Added unit tests to validate the new error handling and logging improvements.
- Enhanced the `photometry.py` module to support both photutils 1.x and 2.x by conditionally importing `PSFPhotometry` and providing a fallback to `BasicPSFPhotometry`.
- Improved the `_normalize_daofind_catalog` function to handle deprecated column names and ensure compatibility with different photutils versions.
- Added defensive checks in `extract_aperture_stats` and `get_star_catalog` to manage variations in star catalog outputs.
- Updated unit tests to validate the new functionality and ensure proper handling of legacy and current column names.
…ndling

- Updated the `extract_aperture_stats` and `get_star_catalog` functions to enhance compatibility with varying star catalog outputs.
- Improved error handling in the `do_phot` and `photloop` functions to provide clearer messages for photometry failures.
- Added unit tests to validate the changes and ensure robust handling of different input scenarios.
- Added `.coverage` to the `.gitignore` file to prevent coverage report files from being tracked in the repository.
…bility

- Updated `do_phot` and `photloop` functions to provide clearer error messages for photometry failures.
- Refactored `extract_aperture_stats` and `get_star_catalog` functions to improve compatibility with varying star catalog outputs.
- Added unit tests to validate the changes and ensure robust handling of different input scenarios.
- Updated `extract_fwhm_from_epsf` to work with ePSF-like arrays instead of EPSFModel, enhancing compatibility with photutils 3.x.
- Introduced helper functions `_apstats_attr` and `_apstats_float` to streamline attribute access and type coercion for `ApertureStats`.
- Enhanced `_make_psf_residual_image` to support both photutils 2.x and 3.x keyword names for residual image generation.
- Refactored `extract_aperture_stats` to utilize the new helper functions for improved clarity and maintainability.
@charliekilpatrick charliekilpatrick merged commit a7b71a8 into main Jun 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant