Skip to content

Feature/159 psf output from trained model#163

Open
jeipollack wants to merge 129 commits intodevelopfrom
feature/159-psf-output-from-trained-model
Open

Feature/159 psf output from trained model#163
jeipollack wants to merge 129 commits intodevelopfrom
feature/159-psf-output-from-trained-model

Conversation

@jeipollack
Copy link
Contributor

@jeipollack jeipollack commented May 13, 2025

This PR adds inference capabilities to the WaveDiff / WF-PSF framework, allowing the user to generate broadband (polychromatic) PSFs from a trained model, given a list of positions and SEDs.

It had a refactor PR merged into it in order to carry on with the development which is why it contains >100 commits (unfortunately and not a practice that will be repeated).

Closes #159 (Validation runs described there)

Key Changes

  • Introduced psf_inference.py and associated test_inference packages for PSF inference workflows
  • Refactored TFPhysicalPolychromatic and related modules to separate training vs. inference behaviour
  • Added PSFInferenceEngine class to centralise training, simulation, metrics, and inference logic
  • Moved model weights loading to psf_model_loader.py
  • Centralised PSF data extraction in data_handler
  • Updated configuration handling for inference (inference_config.yaml)
  • Updated documentation (small) to include inference package
  • Core Refactoring from PR 165 refactor tfphysicalpolychromatic to cleanly separate training vs inference behaviour #166:
    • New run_type attribute: Added to data_handler supporting training, simulation, metrics, and inference modes
    • ZernikeInputsFactory class: New factory class that builds ZernikeInputs instances based on the specified run type
    • Enhanced ZernikeInputs data class: Now intelligently assembles Zernike contribution lists based on run_type and available data (including priors and source positions for CCD misalignment corrections)
    • Hybrid loading pattern: Refactored to use eager loading in constructors combined with lazy-loading via property decorators, reducing constructor overhead and improving modularity
    • Code organization: Improved module structure including new tf_utils.py module in the psf_models sub-package
    • Bug fix: Fixed incorrect argument name in DataHandler class that prevented training dataset images from being converted to TensorFlow data type as expected
    • Helper Methods: Added several helper methods to assist with preparing datasets and ensure data type conversion is performed as expected
    • Deprecations: Removed get_obs_positions as it was no longer needed
  • Bug fix: Fix logger formatting for relative RMSE metrics in metrics.py (values were not being displayed)
  • Changelog Fragment added describing updates

Testing

  • CI tests pass successfully
  • Unit tests cover:
    • Loading trained models and other aspects of inference setup
    • Generating PSFs for multiple positions/SEDs and error handling
    • Consistency of outputs and tensor handling
    • Clearing cached values
  • Verified backward compatibility with existing develop code
  • Confirmed inferred PSFs from test datasets match expected results with high accuracy

@jeipollack jeipollack self-assigned this May 13, 2025
@jeipollack jeipollack added the enhancement New feature or request label May 13, 2025
@jeipollack jeipollack changed the title Feature/159 psf output from trained model Draft:Feature/159 psf output from trained model May 13, 2025
@jeipollack jeipollack changed the base branch from develop to case_study_psf_decontamination July 3, 2025 07:21
Base automatically changed from case_study_psf_decontamination to develop August 5, 2025 10:32
@jeipollack jeipollack force-pushed the feature/159-psf-output-from-trained-model branch from f15c0f2 to 89da2e0 Compare August 5, 2025 13:39
@jeipollack jeipollack changed the title Draft:Feature/159 psf output from trained model Feature/159 psf output from trained model Nov 12, 2025
@jeipollack jeipollack requested a review from sfarrens November 12, 2025 10:39
@jeipollack jeipollack added the documentation Improvements or additions to documentation label Nov 20, 2025
@jeipollack jeipollack changed the title Feature/159 psf output from trained model Draft: Feature/159 psf output from trained model Nov 20, 2025
@jeipollack jeipollack force-pushed the feature/159-psf-output-from-trained-model branch 2 times, most recently from c199e05 to 9f64df3 Compare December 8, 2025 12:21
@jeipollack jeipollack force-pushed the feature/159-psf-output-from-trained-model branch from e995e7c to 6b2a1fe Compare January 22, 2026 15:30
@jeipollack jeipollack changed the title Draft: Feature/159 psf output from trained model Feature/159 psf output from trained model Jan 26, 2026
@jeipollack
Copy link
Contributor Author

it would be very ideal to squash and merge this commit in order to simplify rebasing the other branches.

@jeipollack jeipollack removed the request for review from sfarrens January 26, 2026 12:12
@jeipollack jeipollack changed the title Feature/159 psf output from trained model DRAFT: Feature/159 psf output from trained model Jan 26, 2026
@jeipollack jeipollack changed the title DRAFT: Feature/159 psf output from trained model Feature/159 psf output from trained model Jan 26, 2026
Jennifer Pollack added 6 commits February 2, 2026 16:32
…ean up submodule docs, update conf.py, and update pyproject.toml version
- Removed old auto-generated wf_psf.rst from _autosummary
- Updated toc.rst (fixed tab issues, reference api.rst)
- Added api.rst with :recursive: directive and wf_psf.run entrypoint
- Refined __init__.py docstrings for all subpackages for clarity and consistency
- Updated module-level docstrings (purpose, authors, TensorFlow notes, etc.)
- Shorten sections to make developer-friendly
- Added new structure for each section: Purppose, Key Fields, Notes, General Notes, etc, where applicable
- Partial completion - new PR is required to verify optional versus required settings
Jennifer Pollack and others added 28 commits February 2, 2026 16:46
- Add status handling to model.load_weights() call
- Use expect_partial() to suppress warnings about unused optimizer state
- Allows successful weight loading for metrics evaluation when checkpoint contains training artifacts
- Delete model reference and run garbage collection
- Clear TensorFlow session to free GPU memory
- Prevents OOM issues in subsequent operations or multiple training runs
- Introduce unified `get_data_array` for training/metrics/inference access
- Add helpers `extract_star_data` and `_get_inference_data`
- Remove redundant `get_np_obs_positions`
- Move data handling logic out of `compute_centroid_corrections`
- Standardise `centroid_dataset` as dict (stamps + optional masks)
- Support optional keys (masks, priors) via `allow_missing`
- Improve and unify docstrings for data extraction utilities
- Add optional "sources" and "masks" attributes to `PSFInference
- Add `correct_centroids` and `add_ccd_misalignments` as options to
  inference_config.yaml
- Updated classes and methods with complete doc strings
- Added two cache clearing methods to PSFInference and PSFInferenceEngine classes
Rebase dropped commits that removed weights_path from the metrics interface.
Cleaning up remaining references in docstrings and tests.
Use f-strings instead of %-formatting to properly display percent symbols
in metric output.
@jeipollack jeipollack force-pushed the feature/159-psf-output-from-trained-model branch from 8ea2ede to 0c74bfe Compare February 2, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

Add function to output PSF for shape measurement given a trained model

2 participants