Skip to content

Commit 6358cfe

Browse files
authored
Merge pull request #209 from punch-mission/rework
Full rewrite for speed and logical simplicity
2 parents badbeef + d137039 commit 6358cfe

39 files changed

+1986
-2459
lines changed

.codespellignore

Whitespace-only changes.

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ jobs:
3535
- name: Lint with ruff
3636
run: |
3737
ruff check .
38+
- name: Run codespell on source code
39+
uses: codespell-project/actions-codespell@v2
40+
with:
41+
skip: '*.fits,*.ipynb'
42+
ignore_words_file: .codespellignore
43+
path: punchbowl
44+
- name: Run codespell on documentation
45+
uses: codespell-project/actions-codespell@v2
46+
with:
47+
skip: '*.fits,*.ipynb'
48+
ignore_words_file: .codespellignore
49+
path: docs/source
3850
- name: Test with pytest
3951
run: |
4052
coverage run -m pytest
Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,36 @@
1-
name: Build and upload to PyPI
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
23

3-
on:
4-
workflow_dispatch:
5-
# pull_request:
6-
# push:
7-
# branches:
8-
# - main
9-
release:
10-
types:
11-
- published
12-
13-
jobs:
14-
build_wheels:
15-
name: Build wheels on ${{ matrix.os }}
16-
runs-on: ${{ matrix.os }}
17-
strategy:
18-
matrix:
19-
# macos-13 is an intel runner, macos-14 is apple silicon
20-
os: [ubuntu-latest, macos-13, macos-14]
21-
22-
steps:
23-
- uses: actions/checkout@v4
24-
25-
- name: Build wheels
26-
uses: pypa/[email protected]
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
278

28-
- uses: actions/upload-artifact@v4
29-
with:
30-
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
31-
path: ./wheelhouse/*.whl
9+
name: Upload Python Package
3210

33-
build_sdist:
34-
name: Build source distribution
35-
runs-on: ubuntu-latest
36-
steps:
37-
- uses: actions/checkout@v4
38-
39-
- name: Build sdist
40-
run: pipx run build --sdist
11+
on:
12+
release:
13+
types: [published]
4114

42-
- uses: actions/upload-artifact@v4
43-
with:
44-
name: cibw-sdist
45-
path: dist/*.tar.gz
15+
permissions:
16+
contents: read
4617

47-
upload_pypi:
48-
needs: [build_wheels, build_sdist]
18+
jobs:
19+
deploy:
4920
runs-on: ubuntu-latest
50-
environment: pypi
5121
permissions:
52-
id-token: write
53-
if: github.event_name == 'release' && github.event.action == 'published'
54-
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
55-
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
22+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
5623
steps:
57-
- uses: actions/download-artifact@v4
58-
with:
59-
# unpacks all CIBW artifacts into dist/
60-
pattern: cibw-*
61-
path: dist
62-
merge-multiple: true
63-
64-
- uses: pypa/gh-action-pypi-publish@release/v1
65-
# with:
66-
# To test: repository-url: https://test.pypi.org/legacy/
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build -s
35+
- name: Publish package distributions to PyPI
36+
uses: pypa/gh-action-pypi-publish@release/v1

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ repos:
1111
hooks:
1212
- id: isort
1313
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|sunpy/extern)$"
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.1.0
16+
hooks:
17+
- id: codespell
18+
files: ^.*\.(py|c|h|md|rst|yml)$
19+
args: [ "--ignore-words", ".codespellignore" ]
1420
- repo: https://github.com/pre-commit/pre-commit-hooks
1521
rev: v5.0.0
1622
hooks:

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ authors:
1919
given-names: "Daniel"
2020
orcid: "https://orcid.org/0000-0002-0494-2025"
2121
title: "regularizepsf"
22-
version: 0.4.0
22+
version: 1.0.0
2323
doi: 10.5281/zenodo.7392170
24-
date-released: 2024-08-18
24+
date-released: 2024-09-09
2525
url: "https://github.com/punch-mission/regularizepsf"

docs/source/cite.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ To cite `the associated paper <https://iopscience.iop.org/article/10.3847/1538-3
1919

2020

2121
If you use this software, please also cite the package with the specific version used.
22-
`Zenodo always has the most up-to-date citation. <https://zenodo.org/records/10066960>`
22+
`Zenodo always has the most up-to-date citation. <https://zenodo.org/records/10066960>`_

docs/source/concepts.rst

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,24 @@ A point spread function (PSF) describes how the optical system spreads light fro
99
The basic premise of this technique is to model the point spread function of an imager using stars as our point sources.
1010
Then, we calculate the inverse PSF and apply it. We could directly convolve the inverse PSF but convolutions are slow.
1111
A convolution in the image is the same as multiplying in Fourier space, a much faster operation, so we do that instead.
12-
Instead of simply calculating the inverse PSF directly, we also include a *target PSF* model to make the resulting corrected
13-
stars uniform. This target is typically a Gaussian as shown below in the :doc:`examples`.
12+
This package supports defining a PSF transformation from any input PSF to any target PSF.
1413

1514
Since the PSF can vary across the image, we create many local models that apply only in smaller regions of the image.
1615
These regions overlap so the correction is smooth without hard transition edges.
1716

18-
Purpose of the target PSF
19-
~~~~~~~~~~~~~~~~~~~~~~~~~~
20-
We need a target PSF because we not only correct the PSF but homogenize to a standard PSF.
21-
This is necessary because a correction without applying a target could result in different PSFs across the image,
22-
e.g. you might correct the center of the image much better than the edges because the center was more well behaved to begin with.
23-
For our purposes on the PUNCH mission, we need the resulting PSF to be the same everywhere.
24-
Thus, we apply a standardized target PSF as well as inverting the observed PSF.
25-
2617
Overview of the package
2718
------------------------
2819
The package has a few main components:
2920

30-
1. Fitting routines in ``regularizepsf.fitter``
31-
2. PSF correction tools in ``regularizepsf.corrector``
32-
3. Visualization utilities in ``regularizepsf.visualize``
21+
1. Representations of PSFs in ``regularizepsf.psf``
22+
2. A method of transforming a PSF from one to another in ``regularizepsf.transform``
23+
3. Routines to model a PSF from data in ``regularizepsf.builder``
24+
4. Extra visualization tools in ``regularizepsf.visualize``
25+
26+
PSFs can be represented in three ways:
3327

34-
The most commonly used fitting routine is ``CoordinatePatchCollection.find_stars_and_average`` as demonstrated in :doc:`examples`.
35-
This can then be converted to an ``ArrayCorrector``, the most commonly used PSF correction tool, by adding the target PSF.
36-
This ``ArrayCorrector`` then can be applied to any new image using the associated ``correct_image`` method on it.
37-
Finally, there are many visualizations to assist in understanding the results and derived PSF models. These are
38-
outlined in :doc:`visualization`.
28+
1. `simple_functional_psf`: the PSF is described as a mathematical function that doesn't vary across an image
29+
2. `varied_functional_psf`: the PSF is described as a mathematical function that varies across the image
30+
3. `ArrayPSF`: the PSF is described using many small arrays, avoiding the need to find an expressive functional model
3931

40-
To speed up computation of the many FFTs, the correction is done in Cython in the ``helper.pyx`` file.
32+
Using a set of images, we can extract `ArrayPSF`s directly and quickly correct an image.

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
extensions = ["autoapi.extension",
2929
"sphinx.ext.autodoc",
30-
"sphinx.ext.napoleon"]
30+
"sphinx.ext.napoleon",
31+
"nbsphinx",
32+
"IPython.sphinxext.ipython_console_highlighting"]
3133

3234
templates_path = ["_templates"]
3335
exclude_patterns = []

docs/source/development.rst

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,30 @@ We encourage all contributions. Please see our `contribution guide first <https:
44

55
We recommend working in a virtual environment.
66
This can be created by running ``python -m venv venv``. Then, activate the environment with ``source venv/bin/activate``.
7-
You can then install the required packages with ``pip install ".[test]"``.
7+
You can then install the required packages with ``pip install ".[dev]"``.
88

99
If at any time you run into issues, please contact us by :doc:`following the guidelines here <help>`.
1010

1111
Setting up pre-commit
1212
----------------------
1313

1414
The first time you develop code, you'll need to install the pre-commit. This checks that our style is consistent.
15-
It gets installed when you do ``pip install ".[test]"`` but then requires you to activate them by
16-
running ``pre-commit install``. Now everytime you commit, our checks will run first.
15+
It gets installed when you do ``pip install ".[dev]"`` but then requires you to activate them by
16+
running ``pre-commit install``. Now every time you commit, our checks will run first.
1717

1818
Building the docs
1919
------------------
2020
The docs are built using ``sphinx``. First, you must install it and the other documentation requirements with ::
2121

22-
pip install -r ./docs/requirements.txt
23-
pip install ".[test]"
24-
python setup.py build_ext --inplace
22+
pip install ".[docs]"
2523

2624
Then, navigate to the ``docs`` directory and run ``make html`` to build the docs.
2725

26+
We use ReadTheDocs, so a preview of the docs are built with each PR.
27+
That makes it easier to check updates without manually building.
28+
2829
Running tests
2930
-------------
3031
To run the tests for this package, run ``pytest`` in the repository base directory.
3132

32-
This repository includes tests for the plotting utilities which compare generated plots to reference images saved in
33-
``tests/baseline``.
34-
To include these image-comparison tests, run ``pytest --mpl``.
35-
To update these reference images, run ``pytest --mpl --mpl-generate-path=tests/baseline``.
36-
37-
If the image-comparison tests are failing,
38-
run ``pytest --mpl --mpl-generate-summary=html`` to generate a summary page showing the generated and reference images.
39-
The location of the generated file will be shown at the end of ``pytest``'s command-line output.
33+
Tests are automatically run for pull requests.

docs/source/example.ipynb

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)