maskfits 1.0.0__tar.gz
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.
- maskfits-1.0.0/.gitignore +14 -0
- maskfits-1.0.0/LICENSE +21 -0
- maskfits-1.0.0/PKG-INFO +59 -0
- maskfits-1.0.0/README.md +31 -0
- maskfits-1.0.0/pyproject.toml +48 -0
- maskfits-1.0.0/src/maskfits/__init__.py +15 -0
- maskfits-1.0.0/src/maskfits/assets/icon.ico +0 -0
- maskfits-1.0.0/src/maskfits/assets/icon.png +0 -0
- maskfits-1.0.0/src/maskfits/automask.py +179 -0
- maskfits-1.0.0/src/maskfits/automask_window.py +498 -0
- maskfits-1.0.0/src/maskfits/binning.py +57 -0
- maskfits-1.0.0/src/maskfits/cli.py +95 -0
- maskfits-1.0.0/src/maskfits/colormaps.py +204 -0
- maskfits-1.0.0/src/maskfits/custom_themes.py +106 -0
- maskfits-1.0.0/src/maskfits/cuts_histogram.py +375 -0
- maskfits-1.0.0/src/maskfits/gui.py +2099 -0
- maskfits-1.0.0/src/maskfits/imagedata.py +229 -0
- maskfits-1.0.0/src/maskfits/layouts.py +126 -0
- maskfits-1.0.0/src/maskfits/masking.py +177 -0
- maskfits-1.0.0/src/maskfits/settings.py +103 -0
- maskfits-1.0.0/src/maskfits/settings_window.py +445 -0
- maskfits-1.0.0/src/maskfits/theme.py +540 -0
- maskfits-1.0.0/src/maskfits/theme_editor_window.py +221 -0
- maskfits-1.0.0/src/maskfits/update_check.py +202 -0
- maskfits-1.0.0/src/maskfits/update_dialog.py +85 -0
- maskfits-1.0.0/src/maskfits/widgets.py +426 -0
- maskfits-1.0.0/tests/test_automask.py +176 -0
- maskfits-1.0.0/tests/test_cli.py +27 -0
- maskfits-1.0.0/tests/test_colormaps.py +53 -0
- maskfits-1.0.0/tests/test_custom_themes.py +91 -0
- maskfits-1.0.0/tests/test_gui_render.py +91 -0
- maskfits-1.0.0/tests/test_imagedata.py +108 -0
- maskfits-1.0.0/tests/test_masking.py +74 -0
- maskfits-1.0.0/tests/test_settings.py +66 -0
- maskfits-1.0.0/tests/test_theme.py +78 -0
- maskfits-1.0.0/tests/test_update_check.py +289 -0
- maskfits-1.0.0/tests/test_update_dialog.py +77 -0
maskfits-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jan-Niklas Pippert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
maskfits-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: maskfits
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A PySide6 GUI for masking pixels in FITS astronomical images.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jnpippert/maskfits
|
|
6
|
+
Project-URL: Repository, https://github.com/jnpippert/maskfits
|
|
7
|
+
Project-URL: Issues, https://github.com/jnpippert/maskfits/issues
|
|
8
|
+
Author-email: Jan-Niklas Pippert <pippertjanniklas@googlemail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: astronomy,fits,gui,masking,photometry
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: astropy>=6.0
|
|
21
|
+
Requires-Dist: numpy>=1.24
|
|
22
|
+
Requires-Dist: pillow>=10.0
|
|
23
|
+
Requires-Dist: pyside6>=6.11.0
|
|
24
|
+
Requires-Dist: scipy>=1.10
|
|
25
|
+
Provides-Extra: macos
|
|
26
|
+
Requires-Dist: pyobjc-framework-cocoa; extra == 'macos'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# maskfits
|
|
30
|
+
|
|
31
|
+
A PySide6 GUI for masking pixels in FITS astronomical images.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install maskfits
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This puts the `maskfits` command on your PATH.
|
|
40
|
+
|
|
41
|
+
### From source
|
|
42
|
+
|
|
43
|
+
To work on maskfits itself, clone the repo and install it editable
|
|
44
|
+
(recommended: inside a virtual environment) instead:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/jnpippert/maskfits.git
|
|
48
|
+
cd maskfits
|
|
49
|
+
python3 -m venv .venv # optional
|
|
50
|
+
source .venv/bin/activate # optional
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
maskfits image1 image2 ...
|
|
58
|
+
maskfits -m s -z 2 # starts in satellite mode and 2x zoom
|
|
59
|
+
```
|
maskfits-1.0.0/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# maskfits
|
|
2
|
+
|
|
3
|
+
A PySide6 GUI for masking pixels in FITS astronomical images.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install maskfits
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This puts the `maskfits` command on your PATH.
|
|
12
|
+
|
|
13
|
+
### From source
|
|
14
|
+
|
|
15
|
+
To work on maskfits itself, clone the repo and install it editable
|
|
16
|
+
(recommended: inside a virtual environment) instead:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/jnpippert/maskfits.git
|
|
20
|
+
cd maskfits
|
|
21
|
+
python3 -m venv .venv # optional
|
|
22
|
+
source .venv/bin/activate # optional
|
|
23
|
+
pip install -e .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
maskfits image1 image2 ...
|
|
30
|
+
maskfits -m s -z 2 # starts in satellite mode and 2x zoom
|
|
31
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "maskfits"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A PySide6 GUI for masking pixels in FITS astronomical images."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Jan-Niklas Pippert", email = "pippertjanniklas@googlemail.com" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["fits", "astronomy", "masking", "photometry", "gui"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Environment :: X11 Applications :: Qt",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Astronomy",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"astropy>=6.0",
|
|
28
|
+
"numpy>=1.24",
|
|
29
|
+
"pillow>=10.0",
|
|
30
|
+
"PySide6>=6.11.0",
|
|
31
|
+
"scipy>=1.10",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/jnpippert/maskfits"
|
|
36
|
+
Repository = "https://github.com/jnpippert/maskfits"
|
|
37
|
+
Issues = "https://github.com/jnpippert/maskfits/issues"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
# Lets the macOS Dock icon be set at runtime (see maskfits.gui._apply_icon).
|
|
41
|
+
# Without it the app still runs fine - the Dock just shows the generic Python icon.
|
|
42
|
+
macos = ["pyobjc-framework-Cocoa"]
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
maskfits = "maskfits.cli:main"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/maskfits"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""maskfits package version - resolved from installed package metadata
|
|
2
|
+
(itself generated from pyproject.toml's `version` at install time), so this
|
|
3
|
+
never has to be hand-kept in sync with pyproject.toml. After bumping the
|
|
4
|
+
version there, re-run `pip install -e .` for this to pick it up - normal for
|
|
5
|
+
any Python package, not something maskfits-specific.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("maskfits")
|
|
12
|
+
except PackageNotFoundError:
|
|
13
|
+
# Running from source without an install (e.g. a plain git clone that
|
|
14
|
+
# was never `pip install -e .`'d) - fall back rather than crash import.
|
|
15
|
+
__version__ = "0.0.0+unknown"
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""Threshold-based automatic source masking: background level + iterative
|
|
2
|
+
sigma-clipping to isolate background-only pixels, then a kappa-sigma cut
|
|
3
|
+
above that background flags source pixels for masking.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from scipy.ndimage import binary_closing, binary_dilation, label
|
|
10
|
+
from scipy.optimize import curve_fit
|
|
11
|
+
|
|
12
|
+
ERROR_METHODS = ["sigma", "sem"]
|
|
13
|
+
BG_METHODS = ["constant"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def valid_pixels(data: np.ndarray) -> np.ndarray:
|
|
17
|
+
"""Boolean mask of pixels eligible for background/threshold work at all -
|
|
18
|
+
excludes NaN and exact-zero (no-data/padding) pixels."""
|
|
19
|
+
return np.isfinite(data) & (data != 0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def sigma_clip_mask(data: np.ndarray, valid: np.ndarray, kappa: float, max_iter: int = 10) -> np.ndarray:
|
|
23
|
+
"""Iteratively sigma-clip `data` (restricted to `valid`) at `kappa` sigma
|
|
24
|
+
around the surviving set's mean, converging (or stopping at max_iter) once
|
|
25
|
+
a pass removes nothing more - this is the "clean up" clip that strips
|
|
26
|
+
bright source pixels out so only background-like pixels remain.
|
|
27
|
+
|
|
28
|
+
Returns a boolean mask of the surviving ("background candidate") pixels.
|
|
29
|
+
"""
|
|
30
|
+
kept = valid.copy()
|
|
31
|
+
if kappa <= 0:
|
|
32
|
+
return kept
|
|
33
|
+
for _ in range(max_iter):
|
|
34
|
+
vals = data[kept]
|
|
35
|
+
if vals.size == 0:
|
|
36
|
+
break
|
|
37
|
+
mean = float(vals.mean())
|
|
38
|
+
std = float(vals.std())
|
|
39
|
+
if std == 0:
|
|
40
|
+
break
|
|
41
|
+
lo, hi = mean - kappa * std, mean + kappa * std
|
|
42
|
+
new_kept = valid & (data >= lo) & (data <= hi)
|
|
43
|
+
if int(new_kept.sum()) == int(kept.sum()):
|
|
44
|
+
kept = new_kept
|
|
45
|
+
break
|
|
46
|
+
kept = new_kept
|
|
47
|
+
return kept
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def background_stats(data: np.ndarray, kept: np.ndarray, error_method: str) -> tuple[float, float]:
|
|
51
|
+
"""Mean background level and its error (plain sigma, or the standard
|
|
52
|
+
error of the mean = sigma / sqrt(n)) over the surviving `kept` pixels."""
|
|
53
|
+
vals = data[kept]
|
|
54
|
+
if vals.size == 0:
|
|
55
|
+
return 0.0, 0.0
|
|
56
|
+
bg = float(vals.mean())
|
|
57
|
+
sigma = float(vals.std())
|
|
58
|
+
if error_method == "sem":
|
|
59
|
+
err = sigma / np.sqrt(vals.size) if vals.size > 0 else 0.0
|
|
60
|
+
else:
|
|
61
|
+
err = sigma
|
|
62
|
+
return bg, err
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _gaussian(x: np.ndarray, amplitude: float, mu: float, sigma: float) -> np.ndarray:
|
|
66
|
+
return amplitude * np.exp(-0.5 * ((x - mu) / sigma) ** 2)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def fit_gaussian_to_histogram(
|
|
70
|
+
values: np.ndarray, bins: int, hist_range: tuple[float, float]
|
|
71
|
+
) -> Optional[tuple[float, float, float]]:
|
|
72
|
+
"""Least-squares gaussian fit (amplitude, mu, sigma) to a histogram of
|
|
73
|
+
`values` binned over `hist_range` - for overlaying a fitted curve on the
|
|
74
|
+
auto-mask background histogram.
|
|
75
|
+
|
|
76
|
+
Falls back to the sample mean/std (a cruder, but still valid, gaussian
|
|
77
|
+
estimate via moment-matching) if the least-squares fit fails to
|
|
78
|
+
converge or lands on a degenerate result; returns None only when there's
|
|
79
|
+
nothing at all to fit.
|
|
80
|
+
"""
|
|
81
|
+
if values.size < 3:
|
|
82
|
+
return None
|
|
83
|
+
counts, edges = np.histogram(values, bins=bins, range=hist_range)
|
|
84
|
+
centers = (edges[:-1] + edges[1:]) / 2.0
|
|
85
|
+
mean = float(values.mean())
|
|
86
|
+
std = float(values.std()) or 1.0
|
|
87
|
+
try:
|
|
88
|
+
popt, _ = curve_fit(
|
|
89
|
+
_gaussian, centers, counts.astype(np.float64),
|
|
90
|
+
p0=[float(counts.max()), mean, std], maxfev=2000,
|
|
91
|
+
)
|
|
92
|
+
amplitude, mu, sigma = float(popt[0]), float(popt[1]), abs(float(popt[2]))
|
|
93
|
+
if sigma <= 0 or not np.isfinite(amplitude) or not np.isfinite(mu):
|
|
94
|
+
raise ValueError("degenerate gaussian fit")
|
|
95
|
+
except Exception:
|
|
96
|
+
amplitude, mu, sigma = float(counts.max()), mean, std
|
|
97
|
+
return amplitude, mu, sigma
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def auto_mask_preview(data: np.ndarray, valid: np.ndarray, bg: float, bg_err: float, kappa: float) -> np.ndarray:
|
|
101
|
+
"""Boolean mask of pixels to flag: `valid` pixels whose value exceeds
|
|
102
|
+
bg + kappa * bg_err. `valid` decides what's even eligible to be flagged -
|
|
103
|
+
pass valid_pixels(data) intersected with anything else that should be
|
|
104
|
+
excluded (e.g. pixels already masked manually - see AutoMaskWindow)."""
|
|
105
|
+
threshold = bg + kappa * bg_err
|
|
106
|
+
return valid & (data > threshold)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _disk_footprint(radius: int) -> np.ndarray:
|
|
110
|
+
yy, xx = np.mgrid[-radius:radius + 1, -radius:radius + 1]
|
|
111
|
+
return (xx ** 2 + yy ** 2) <= radius ** 2 + 1e-9
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# How far apart (in pixels) two flagged specks can be and still count as
|
|
115
|
+
# "the same object" for group-size filtering - see filter_by_group_size.
|
|
116
|
+
# Not user-facing: it's just large enough to bridge the sub-threshold noise
|
|
117
|
+
# gaps a real, noisy extended source leaves in its own thresholding, while
|
|
118
|
+
# staying far too small to merge genuinely separate point sources.
|
|
119
|
+
GROUP_BRIDGE_RADIUS = 4
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def filter_by_group_size(mask: np.ndarray, max_size: int) -> np.ndarray:
|
|
123
|
+
"""Drop any connected group of flagged pixels larger than `max_size` -
|
|
124
|
+
keeps compact, point-like detections (small background sources) while
|
|
125
|
+
dropping extended ones (satellite trails, big galaxies, artifacts).
|
|
126
|
+
Applied to the RAW threshold flags, before expand_mask pads whatever
|
|
127
|
+
survives - padding first would inflate every group's size and defeat the
|
|
128
|
+
point of this filter. max_size <= 0 disables filtering (nothing dropped).
|
|
129
|
+
|
|
130
|
+
Group membership is measured on a version of `mask` with small gaps
|
|
131
|
+
closed (binary_closing, radius=GROUP_BRIDGE_RADIUS) first, NOT on the raw
|
|
132
|
+
mask directly. A real extended source (a galaxy, a trail) practically
|
|
133
|
+
never thresholds into one solid blob - sky noise pushes individual
|
|
134
|
+
pixels within it below the cut too, fragmenting it into many small,
|
|
135
|
+
disconnected specks that would each individually slip under any size
|
|
136
|
+
limit on their own. Closing small gaps first recognizes that scattered
|
|
137
|
+
cluster of specks as the one big object it actually is, without merging
|
|
138
|
+
genuinely separate, well-spaced point sources (which stay distinct
|
|
139
|
+
groups, since they're farther apart than the bridging radius).
|
|
140
|
+
"""
|
|
141
|
+
if max_size <= 0 or not mask.any():
|
|
142
|
+
return mask
|
|
143
|
+
structure = np.ones((3, 3), dtype=bool)
|
|
144
|
+
bridged = binary_closing(mask, structure=_disk_footprint(GROUP_BRIDGE_RADIUS))
|
|
145
|
+
labeled, num = label(bridged, structure=structure)
|
|
146
|
+
if num == 0:
|
|
147
|
+
return mask
|
|
148
|
+
sizes = np.bincount(labeled.ravel())
|
|
149
|
+
too_big = np.nonzero(sizes > max_size)[0]
|
|
150
|
+
if too_big.size == 0:
|
|
151
|
+
return mask
|
|
152
|
+
return mask & ~np.isin(labeled, too_big)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def expand_mask(mask: np.ndarray, radius: float) -> np.ndarray:
|
|
156
|
+
"""Pad each flagged region out by `radius` pixels (a disk-shaped dilation)
|
|
157
|
+
so a thin/eroded detection still covers a source's faint wings. radius <=
|
|
158
|
+
0 leaves the mask unchanged."""
|
|
159
|
+
r = int(round(radius))
|
|
160
|
+
if r <= 0:
|
|
161
|
+
return mask
|
|
162
|
+
return binary_dilation(mask, structure=_disk_footprint(r))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def neural_network_mask(data: np.ndarray, model_path: str) -> np.ndarray:
|
|
166
|
+
"""Placeholder interface for a future neural-network-based source/
|
|
167
|
+
satellite masker (e.g. a model trained to flag sources or satellite
|
|
168
|
+
trails directly from pixel data). Not implemented yet - deliberately not
|
|
169
|
+
wired to any inference framework here, so this project doesn't pick up a
|
|
170
|
+
heavy ML dependency just for a stub. Fixing the interface now (a model
|
|
171
|
+
path in, a boolean mask matching `data`'s shape out) means a real
|
|
172
|
+
implementation can be dropped in later - by this project or another user
|
|
173
|
+
- without any GUI-side changes: AutoMaskWindow already calls this and
|
|
174
|
+
handles the NotImplementedError gracefully.
|
|
175
|
+
"""
|
|
176
|
+
raise NotImplementedError(
|
|
177
|
+
"Neural network masking is not implemented yet - this is a placeholder interface "
|
|
178
|
+
"for a future model."
|
|
179
|
+
)
|