Skip to content

Commit 8fc2dad

Browse files
authored
Merge pull request #3 from punch-mission/0.0.3
0.0.3
2 parents b29b6aa + 9923937 commit 8fc2dad

29 files changed

+698
-185
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: |
2525
python -m pip install --upgrade pip
2626
python -m pip install flake8 pytest pytest-cov hypothesis
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
2828
- name: Lint with flake8
2929
run: |
3030
# stop the build if there are Python syntax errors or undefined names

README.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
[![DOI](https://zenodo.org/badge/555583385.svg)](https://zenodo.org/badge/latestdoi/555583385)
44
[![PyPI version](https://badge.fury.io/py/regularizepsf.svg)](https://badge.fury.io/py/regularizepsf)
55

6-
**UNDER DEVELOPMENT**
7-
86
A package for manipulating and correcting variable point spread functions.
97

108
Below is an example of correcting model data using the package. An initial image of a simplified starfield (a) is synthetically observed with a slowly
119
varying PSF (b), then regularized with this technique (c). The final image visually matches a direct convolution of
1210
the initial image with the target PSF (d). The panels are gamma-corrected to highlight the periphery of the model PSFs.
1311
![Example result image](model_example.png)
1412

15-
16-
1713
## Getting started
1814

1915
`pip install regularizepsf` and then follow along with the [Quickstart section](https://punch-mission.github.io/regularizepsf/quickstart.html).
@@ -24,6 +20,9 @@ We encourage all contributions. If you have a problem with the code or would lik
2420
## License
2521
See LICENSE for the MIT license
2622

23+
## Need help?
24+
Please contact Marcus Hughes at [[email protected]](mailto:[email protected]).
25+
2726
## Citation
2827
Please cite the associated paper if you use this technique:
2928

@@ -47,6 +46,3 @@ Please cite the associated paper if you use this technique:
4746
}
4847
4948
```
50-
51-
## Contact
52-
Please contact Marcus Hughes at [[email protected]](mailto:[email protected]) for any questions.

docs/_config.yml

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Book settings
22
# Learn more at https://jupyterbook.org/customize/config.html
33

4-
title: regularizepsf
4+
title: regularizePSF
55
author: PUNCH Science Operations Center
66

77
# Force re-execution of notebooks on each build.
88
# See https://jupyterbook.org/content/execute.html
99
execute:
1010
execute_notebooks: force
11+
timeout: 100
1112

1213
# Define the name of the latex output file for PDF builds
1314
latex:
@@ -20,10 +21,26 @@ bibtex_bibfiles:
2021

2122
# Information about where the book exists on the web
2223
repository:
23-
url: https://github.com/executablebooks/jupyter-book # Online location of your book
24+
url: https://github.com/punch-mission/regularizepsf # Online location of your book
2425
path_to_book: docs # Optional path to your book, relative to the repository root
2526
branch: main # Which branch of the repository should be used when creating links (optional)
2627

28+
parse:
29+
# default extensions to enable in the myst parser.
30+
# See https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html
31+
myst_enable_extensions:
32+
# - amsmath
33+
- colon_fence
34+
# - deflist
35+
- dollarmath
36+
- html_admonition
37+
# - html_image
38+
- linkify
39+
# - replacements
40+
# - smartquotes
41+
- substitution
42+
myst_url_schemes: [mailto, http, https] # URI schemes that will be recognised as external URLs in Markdown links
43+
2744
# Add GitHub buttons to your book
2845
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
2946
html:
@@ -36,7 +53,22 @@ sphinx:
3653
- 'sphinx.ext.napoleon'
3754
- 'sphinx.ext.viewcode'
3855
- 'sphinx.ext.autosummary'
56+
- 'sphinx.ext.inheritance_diagram'
57+
- 'autoapi.extension'
58+
- "myst_nb"
59+
# - 'sphinx_codeautolink'
3960
config:
61+
html_show_copyright: false
4062
add_module_names: False
41-
autosummary_generate: True
42-
63+
autoapi_dirs:
64+
- "../regularizepsf"
65+
autoapi_root: "api"
66+
autoapi_add_toctree_entry: false
67+
autoapi_keep_files: false
68+
autoapi_options:
69+
- "members"
70+
- "undoc-members"
71+
- "show-inheritance"
72+
- "special-members"
73+
- "imported-members"
74+
autoapi_python_class_content: "both"

docs/_toc.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ format: jb-book
55
root: intro
66
chapters:
77
- file: quickstart
8-
- file: array
98
- file: functional
109
- file: theory
11-
- file: cite
10+
- file: cite
11+
- file: help
12+
- file: api/regularizepsf/index
13+
title: API

docs/array.md

-1
This file was deleted.

docs/cite.md

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
# How to cite
22

3-
Use the following Bibtex citation:
3+
To cite the paper:
44
```
5-
@misc{https://doi.org/10.48550/arxiv.2212.02594,
6-
doi = {10.48550/ARXIV.2212.02594},
7-
8-
url = {https://arxiv.org/abs/2212.02594},
9-
10-
author = {Hughes, J. M. and DeForest, C. E. and Seaton, D. B.},
11-
12-
keywords = {Instrumentation and Methods for Astrophysics (astro-ph.IM), FOS: Physical sciences, FOS: Physical sciences},
13-
14-
title = {Coma Off It: Removing Variable Point Spread Functions from Astronomical Images},
15-
16-
publisher = {arXiv},
17-
18-
year = {2022},
19-
20-
copyright = {arXiv.org perpetual, non-exclusive license}
5+
@ARTICLE{2022arXiv221202594H,
6+
author = {{Hughes}, J.~M. and {DeForest}, C.~E. and {Seaton}, D.~B.},
7+
title = "{Coma Off It: Removing Variable Point Spread Functions from Astronomical Images}",
8+
journal = {arXiv e-prints},
9+
keywords = {Astrophysics - Instrumentation and Methods for Astrophysics},
10+
year = 2022,
11+
month = dec,
12+
eid = {arXiv:2212.02594},
13+
pages = {arXiv:2212.02594},
14+
archivePrefix = {arXiv},
15+
eprint = {2212.02594},
16+
primaryClass = {astro-ph.IM},
17+
adsurl = {https://ui.adsabs.harvard.edu/abs/2022arXiv221202594H},
18+
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
2119
}
20+
```
21+
2222

23+
To cite the software:
24+
```
25+
@software{marcus_hughes_2022_7392394,
26+
author = {Marcus Hughes},
27+
title = {punch-mission/regularizepsf: v0.0.3},
28+
month = dec,
29+
year = 2022,
30+
publisher = {Zenodo},
31+
version = {0.0.3},
32+
doi = {10.5281/zenodo.7392394},
33+
url = {https://doi.org/10.5281/zenodo.7392394}
34+
}
2335
```

docs/data/DASH.fits

12 MB
Binary file not shown.

docs/functional.md

+113-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
# Correct using `FunctionalCorrector`
1+
# Correct using `FunctionalCorrector`
2+
A functional corrector is defined by a set of equations instead of image arrays.
3+
The functional corrector can be helpful if you know the form of the PSF. You can directly define it.
4+
5+
```{note}
6+
To correct an image, a `FunctionalCorrector` will be converted to an `ArrayCorrector`.
7+
If you plan to save a model for many corrections, you may find it more convenient to manually convert to an `ArrayCorrector`
8+
and then save an `ArrayConverter` instead. This is because a `FunctionalCorrector` merely pickles the functions using
9+
`dill` while `ArrayCorrector` saves using HDF5. For more details, see the [Saving a corrector](save-corrector) section.
10+
```
11+
12+
## `simple_psf`: the starting point
13+
Every model begins with a `simple_psf`. It requires the first two arguments to be the `x` and `y` coordinates.
14+
These will often be passed in as arrays so your function should operate in a vectorized manner and be able to output an
15+
array as well.
16+
17+
```py
18+
from regularizepsf import simple_psf
19+
20+
@simple_psf
21+
def a_basic_example(x, y):
22+
return x + y
23+
```
24+
You can always evaluate your PSF at a single point to determine its value:
25+
```py
26+
print(a_basic_example(101, 204))
27+
```
28+
Or you can evaluate at a variety of `x` and `y` coordinates using a `numpy` array.
29+
```py
30+
print(a_basic_example(np.arange(100), np.arange(!00)))
31+
```
32+
33+
You can then supply additional arguments with default values set. We will see in the next section
34+
how to use a `varied_psf` to make them vary across the field-of-view (FOV) of the image.
35+
36+
```py
37+
38+
@simple_psf
39+
def with_default_arguments(x, y, width=100):
40+
return x + y + width
41+
```
42+
43+
## `varied_psf`: a more realistic model
44+
The purpose of this package is correct images with variable PSFs. Thus, we need a way to encode how the
45+
PSF varies across the FOV. That's where `varied_psf` helps. The decorator requires a `simple_psf` as an argument.
46+
We call this the base PSF.
47+
Then, the function takes `x` and `y` as parameters and returns a dictionary of how the defaulted parameters of the base PSF vary.
48+
49+
For example,
50+
```py
51+
from regularizepsf import simple_psf, varied_psf
52+
53+
@simple_psf
54+
def base_psf(x, y, width=100):
55+
return x + y + width
56+
57+
@varied_psf(base_psf)
58+
def complicated_psf(x, y):
59+
return {"width": x/(y+1)}
60+
```
61+
62+
Now, the PSF's width will vary across an image and have the width of `x` divided by `y+1`. (We add one to avoid division
63+
by zero errors.)
64+
65+
## Making a `FunctionalCorrector`
66+
Using these functionally defined examples, we can then create a `FunctionalCorrector` to correct an image.
67+
68+
```py
69+
from regularizepsf import FunctionalCorrector
70+
71+
my_simple_corrector = FunctionalCorrector(base_psf)
72+
my_complicated_corrector = FunctionalCorrector(complicated_psf)
73+
```
74+
75+
As discussed in the [Quickstart](quickstart.md), we often wish to correct our PSF to a uniform output by applying a
76+
target PSF. We can provide that too!
77+
78+
```py
79+
@simple_psf
80+
def target_psf(x, y):
81+
return np.ones_like(x)
82+
83+
my_corrector = FunctionalCorrector(complicated_psf, target_psf)
84+
```
85+
86+
## Correcting an image
87+
Correcting an image is now trivial. We just load the image and correct with a specified patch size, 256 in this case.
88+
```python
89+
from astropy.io import fits
90+
91+
with fits.open("path_to_image.fits") as hdul:
92+
data = hdul[0].data.astype(float)
93+
94+
my_corrector.correct_image(data, 256)
95+
```
96+
97+
```{note}
98+
If you're planning to do many corrections, you might first convert to an `ArrayCorrector`. The `FunctionalCorrector`'s
99+
`correct_image` function involves this step and would do it for each image.
100+
```
101+
102+
You can evaluate to an `ArrayCorrector` as shown below. The first argument is the `x`, then the `y`, and then the `size` of the patches.
103+
```python
104+
new_corrector = my_corrector.evaluate_to_array_form(np.arange(256), np.arange(256), 256)
105+
```
106+
107+
(save-corrector)=
108+
## Saving a corrector
109+
We can save a corrector in either its `FunctionalCorrector` form or its `ArrayCorrector` form.
110+
```python
111+
my_corrector.save("functional.psf")
112+
new_corrector.save("array.psf")
113+
```

docs/help.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Getting help
2+
3+
If you notice a bug, please open an issue on GitHub.
4+
5+
If you need help using this code, you can open an issue or contact Marcus Hughes directly at `[email protected]`.
6+
We want to make this code as user-friendly as possible. If you're encountering an issue, it's likely someone else is too
7+
and you can help everyone by speaking up. Thanks for your support!

docs/images/dash.png

275 KB
Loading

docs/intro.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# Welcome to regularizepsf
1+
# Welcome
22

33
`regularizepsf` is a Python package (with Cython speed improvements) for determining and correcting
44
point spread functions in astronomical images.
5-
It was originally developed for the [PUNCH](https://punch.space.swri.edu/) mission and is documented in an upcoming
6-
Astrophysical Journal paper. For now, see [the arXiv listing](https://arxiv.org/abs/2212.02594).
5+
It was originally developed for the [PUNCH](https://punch.space.swri.edu/) mission and is documented in a forthcoming
6+
Astrophysical Journal paper (see [arXiv version](https://arxiv.org/abs/2212.02594) until publication).
7+
8+
Below is an example of correcting model data using the package.
9+
An initial image of a simplified starfield (a) is synthetically observed with a slowly varying PSF (b),
10+
then regularized with this technique (c). The final image visually matches a direct convolution of the initial image
11+
with the target PSF (d). The panels are gamma-corrected to highlight the periphery of the model PSFs.
712

8-
Below is an example of correcting model data using the package. An initial image of a simplified starfield (a) is synthetically observed with a slowly
9-
varying PSF (b), then regularized with this technique (c). The final image visually matches a direct convolution of
10-
the initial image with the target PSF (d). The panels are gamma-corrected to highlight the periphery of the model PSFs.
1113
```{image} images/model.png
1214
:alt: example of correction
1315
:width: 800px

0 commit comments

Comments
 (0)