eye-patch 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eye_patch/__init__.py +11 -0
- eye_patch/_version.py +24 -0
- eye_patch/_version.pyi +2 -0
- eye_patch/masking.py +1174 -0
- eye_patch/naming.py +40 -0
- eye_patch/pixel_utils.py +101 -0
- eye_patch/py.typed +0 -0
- eye_patch-1.0.0.dist-info/METADATA +60 -0
- eye_patch-1.0.0.dist-info/RECORD +12 -0
- eye_patch-1.0.0.dist-info/WHEEL +4 -0
- eye_patch-1.0.0.dist-info/entry_points.txt +2 -0
- eye_patch-1.0.0.dist-info/licenses/LICENSE +28 -0
eye_patch/naming.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import NamedTuple
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FITSMaskNames(NamedTuple):
|
|
6
|
+
"""Contains the names of the FITS images created when creating a mask image/
|
|
7
|
+
These are only the names, and do not mean that they are necessarily created.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
mask_fits: Path
|
|
11
|
+
"""Name of the mask FITS file"""
|
|
12
|
+
signal_fits: Path | None = None
|
|
13
|
+
"""Name of the signal FITS file"""
|
|
14
|
+
scale_mask_fits: Path | None = None
|
|
15
|
+
"""Path to a FITS file that describes per-scale clean masks. Scales are represented with a bit-mapped values,"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def create_fits_mask_names(
|
|
19
|
+
fits_image: str | Path, include_signal_path: bool = False
|
|
20
|
+
) -> FITSMaskNames:
|
|
21
|
+
"""Create the names that will be used when generate FITS mask products
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
fits_image (Union[str,]Path): Base name of the output files
|
|
25
|
+
include_signal_path (bool, optional): If True, also include ``signal_fits`` in the output. Defaults to False.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
FITSMaskNames: collection of names used for the signal and mask FITS images
|
|
29
|
+
"""
|
|
30
|
+
fits_image = Path(fits_image)
|
|
31
|
+
|
|
32
|
+
fits_signal = (
|
|
33
|
+
fits_image.with_suffix(".signal.fits") if include_signal_path else None
|
|
34
|
+
)
|
|
35
|
+
fits_mask = fits_image.with_suffix(".mask.fits")
|
|
36
|
+
fits_scale_mask = fits_image.with_suffix(".scalemask.fits")
|
|
37
|
+
|
|
38
|
+
return FITSMaskNames(
|
|
39
|
+
signal_fits=fits_signal, mask_fits=fits_mask, scale_mask_fits=fits_scale_mask
|
|
40
|
+
)
|
eye_patch/pixel_utils.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
import astropy.units as u
|
|
7
|
+
import numpy as np
|
|
8
|
+
from astropy.io import fits
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from radio_beam import Beam
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class BeamShape:
|
|
18
|
+
"""A simple container to represent a fitted 2D gaussian,
|
|
19
|
+
intended for the main lobe of the synthesised beam. This
|
|
20
|
+
class has been defined to avoid issues with the serialisation
|
|
21
|
+
of astropy.units, which can cause strange and wonderful
|
|
22
|
+
errors when being sent over the wire to workers."""
|
|
23
|
+
|
|
24
|
+
bmaj_arcsec: float
|
|
25
|
+
"""The size of the major-axis of the beam, in arcseconds."""
|
|
26
|
+
bmin_arcsec: float
|
|
27
|
+
"""The size of the minor-axis of the beam, in arcseconds."""
|
|
28
|
+
bpa_deg: float
|
|
29
|
+
"""Rotation of the beam, in degrees."""
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def from_radio_beam(cls, radio_beam: Beam) -> BeamShape:
|
|
33
|
+
"""A helper function to convert a radio_beam.Beam into a
|
|
34
|
+
BeamShape. This is prinicpally intended to be used when
|
|
35
|
+
there is a need to exchange a Beam between processes
|
|
36
|
+
that would need to serialise the object.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
radio_beam (Beam): The Beam to convert to normalised and known units
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
BeamShape: The normalised container without astropy units.
|
|
43
|
+
"""
|
|
44
|
+
return cls(
|
|
45
|
+
bmaj_arcsec=radio_beam.major.to(u.arcsecond).value,
|
|
46
|
+
bmin_arcsec=radio_beam.minor.to(u.arcsecond).value,
|
|
47
|
+
bpa_deg=radio_beam.pa.to(u.degree).value,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_beam_shape(fits_path: Path) -> BeamShape | None:
|
|
52
|
+
"""Construct and return a beam shape from the fields in a FITS image
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
fits_path (Path): FITS image to extract the beam information from
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Optional[BeamShape]: Shape of the beam stored in the FITS image. None is returned if the beam is not found.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
header = fits.getheader(filename=fits_path)
|
|
62
|
+
|
|
63
|
+
if not all(key in header for key in ("BMAJ", "BMIN", "BPA")):
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
return BeamShape(
|
|
67
|
+
bmaj_arcsec=header["BMAJ"] * 3600,
|
|
68
|
+
bmin_arcsec=header["BMIN"] * 3600,
|
|
69
|
+
bpa_deg=header["BPA"],
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_pixels_per_beam(fits_path: Path) -> float | None:
|
|
74
|
+
"""Given a image with beam information, return the number of pixels
|
|
75
|
+
per beam. The beam is taken from the FITS header. This is evaluated
|
|
76
|
+
for pixels at the reference pixel position.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
fits_path (Path): FITS image to consideer
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
float | None: Number of pixels per beam. If beam is not in header then None is returned.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
beam_shape = get_beam_shape(fits_path=fits_path)
|
|
86
|
+
|
|
87
|
+
if beam_shape is None:
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
header = fits.getheader(filename=fits_path)
|
|
91
|
+
|
|
92
|
+
pixel_ra = np.abs(header["CDELT1"] * 3600)
|
|
93
|
+
pixel_dec = np.abs(header["CDELT2"] * 3600)
|
|
94
|
+
|
|
95
|
+
assert isinstance(beam_shape, BeamShape), (
|
|
96
|
+
f"Expected type of Beamshape, but have {type(beam_shape)}"
|
|
97
|
+
)
|
|
98
|
+
beam_area = beam_shape.bmaj_arcsec * beam_shape.bmin_arcsec * np.pi
|
|
99
|
+
pixel_area = pixel_ra * pixel_dec
|
|
100
|
+
|
|
101
|
+
return float(beam_area / pixel_area)
|
eye_patch/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eye-patch
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: The pirate mask.
|
|
5
|
+
Project-URL: Homepage, https://github.com/flint-crew/eye-patch
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/flint-crew/eye-patch/issues
|
|
7
|
+
Project-URL: Discussions, https://github.com/flint-crew/eye-patch/discussions
|
|
8
|
+
Project-URL: Changelog, https://github.com/flint-crew/eye-patch/releases
|
|
9
|
+
Author-email: Alec Thomson <alec.thomson@skao.int>, Tim Galvin <tim.galvin@csiro.au>
|
|
10
|
+
License-Expression: BSD-3-Clause
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 1 - Planning
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: astropy>=7.2.0
|
|
28
|
+
Requires-Dist: capn-crunch>=1.1.0
|
|
29
|
+
Requires-Dist: numpy>=2.4.3
|
|
30
|
+
Requires-Dist: radio-beam>=0.3.9
|
|
31
|
+
Requires-Dist: reproject>=0.19.0
|
|
32
|
+
Requires-Dist: scipy
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# Eye Patch
|
|
36
|
+
|
|
37
|
+
The pirate mask!
|
|
38
|
+
|
|
39
|
+
<img width="256" height="256" alt="image" src="https://github.com/user-attachments/assets/2a8e442c-036b-4d78-8370-180c02588c95" />
|
|
40
|
+
|
|
41
|
+
[![Actions Status][actions-badge]][actions-link]
|
|
42
|
+
[![Documentation Status][rtd-badge]][rtd-link]
|
|
43
|
+
[![PyPI version][pypi-version]][pypi-link]
|
|
44
|
+
[![PyPI platforms][pypi-platforms]][pypi-link]
|
|
45
|
+
[![Coverage][coverage-badge]][coverage-link]
|
|
46
|
+
|
|
47
|
+
<!-- SPHINX-START -->
|
|
48
|
+
|
|
49
|
+
<!-- prettier-ignore-start -->
|
|
50
|
+
[actions-badge]: https://github.com/flint-crew/eye-patch/workflows/CI/badge.svg
|
|
51
|
+
[actions-link]: https://github.com/flint-crew/eye-patch/actions
|
|
52
|
+
[pypi-link]: https://pypi.org/project/eye-patch/
|
|
53
|
+
[pypi-platforms]: https://img.shields.io/pypi/pyversions/eye-patch
|
|
54
|
+
[pypi-version]: https://img.shields.io/pypi/v/eye-patch
|
|
55
|
+
[rtd-badge]: https://readthedocs.org/projects/eye-patch/badge/?version=latest
|
|
56
|
+
[rtd-link]: https://eye-patch.readthedocs.io/en/latest/?badge=latest
|
|
57
|
+
[coverage-badge]: https://codecov.io/github/flint-crew/eye-patch/branch/main/graph/badge.svg
|
|
58
|
+
[coverage-link]: https://codecov.io/github/flint-crew/eye-patch
|
|
59
|
+
|
|
60
|
+
<!-- prettier-ignore-end -->
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
eye_patch/__init__.py,sha256=jtfBWiVBoQK4SZa31vnjnSf_E7MIWA-gOG0iNisCRYs,200
|
|
2
|
+
eye_patch/_version.py,sha256=JAAyU3al4wmBf3BF-Umm1J_GrCIT-yS_yWEGHqKRVHc,520
|
|
3
|
+
eye_patch/_version.pyi,sha256=o7uNL6MhuJoiqpEnriU7rBT6TmkJZA-i2qMoNz9YcgQ,82
|
|
4
|
+
eye_patch/masking.py,sha256=cgphN8ouM6ncWmzbMLt7zfqXxTa9W0diPAe68722494,47897
|
|
5
|
+
eye_patch/naming.py,sha256=GsI_790GsJXepqyW5nDLu2o29f8DLtabOI837D81be8,1417
|
|
6
|
+
eye_patch/pixel_utils.py,sha256=QRU6qHovnkvEgOvRvTRQY5Scvlse4RRL0aquNwjlBgA,3162
|
|
7
|
+
eye_patch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
eye_patch-1.0.0.dist-info/METADATA,sha256=Os3xd5KXMM9iHUh6IFkCH3JmOTxI8sc9Ea47jgJ5tqs,2623
|
|
9
|
+
eye_patch-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
10
|
+
eye_patch-1.0.0.dist-info/entry_points.txt,sha256=ZO0hTfwwiKjRaNpR2msrhkvJ44dVdwAApV97QtX1vn4,52
|
|
11
|
+
eye_patch-1.0.0.dist-info/licenses/LICENSE,sha256=_jZTapMIOcgi0WpoRQsrKqfiwecDD_c2I9ZI93GQUUE,1497
|
|
12
|
+
eye_patch-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, flint-crew
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|