noisechisel-torch
A PyTorch port of Gnuastro's
NoiseChisel, which detects faint signal in noise and measures the Sky and
Sky STD. It runs on CPU or CUDA, and its detection mask, Sky and Sky STD are
bit-identical to astnoisechisel 0.24 with default options.
Scaling with CPU threads
Both programs gain little beyond about 6–10 threads (at most 2.4–2.5× over one thread), and noisechisel-torch is faster at every thread count. The CPU times in the bar chart above are taken from this test at 10 threads.
All benchmarks use simulated Roman WFI frames (4088×4088). CPU: Apple M3 Max,
median of 4 runs including FITS read and write. GPU: Colab T4 with CuPy.
Data: benchmarks/results/scaling_m3max.csv, made with benchmarks/scaling.py.
Install
pip install "noisechisel-torch[fits]" # CPU, with astropy for FITS I/O and the CLI
pip install "noisechisel-torch[fits,cuda12]" # + CuPy for GPU labelling (cuda13 for CUDA 13 drivers)
Install only one CuPy package, matched to your driver's CUDA version.
Usage
from astropy.io import fits
from noisechisel_torch import noisechisel, NoiseChisel
img = fits.getdata("image.fits", ext=0)
res = noisechisel(img, device="cuda") # or device="cpu", numthreads=8
res.detections # bool mask (H, W)
res.labels # int32 (H, W), 0 = sky, 1..N detections
res.sky, res.std # float32 (H, W) Sky and Sky STD (NaN where input is blank)
res.info() # detections, S/N threshold, Sky/STD summary
res.meta() # the same values as a dict
nc = NoiseChisel(device="cuda", tilesize=(64, 64), qthresh=0.3) # reuse on many images
res = nc(img)
noisechisel-torch image.fits -h 0 -o image_detected.fits --device cuda
noisechisel-torch image.fits -h 0 -o image_detected.fits --device cpu -N 8 # 8 CPU threads
The output file has the same HDUs as astnoisechisel, including the
sky-subtracted INPUT-NO-SKY, which exists only in the file (in Python,
subtract res.sky yourself). Add --oneelempertile to write Sky/STD with one
value per tile, which cuts a 4088² output from ~200 MB to ~85 MB.
Gnuastro options
Every astnoisechisel option is a keyword argument with the same name and
default. Values that Gnuastro writes as a,b are tuples in Python. Booleans
are True/False. The CLI takes the Gnuastro syntax unchanged, including the
short forms.
astnoisechisel img.fits -h0 --tilesize=50,40 -t0.35 -d0.8 --interponlyblank -k kernel.fits
noisechisel-torch img.fits -h0 --tilesize=50,40 -t0.35 -d0.8 --interponlyblank -k kernel.fits
from astropy.io import fits
from noisechisel_torch import noisechisel
res = noisechisel(img, tilesize=(40, 50), qthresh=0.35, detgrowquant=0.8,
interponlyblank=True, kernel=fits.getdata("kernel.fits", ext=1))
Tile sizes: Gnuastro gives --tilesize and --largetilesize in FITS
order (x, y). Python uses numpy order (rows, cols), so --tilesize=50,40 is
tilesize=(40, 50). The CLI converts for you.
| Gnuastro | Python keyword | Default |
|---|---|---|
-k, --kernel FILE (--khdu) |
kernel=fits.getdata(FILE); None = no convolution |
built-in FWHM=2 Gaussian |
--widekernel FILE (--whdu) |
widekernel=fits.getdata(FILE) |
None |
--tilesize |
tilesize |
(30, 30) |
--remainderfrac |
remainderfrac |
0.1 |
--largetilesize |
largetilesize |
(200, 200) |
--interpnumngb |
interpnumngb |
15 |
--interpmetric |
interpmetric ("radial" or "manhattan") |
"radial" |
--interponlyblank |
interponlyblank |
False |
--smoothwidth |
smoothwidth |
5 |
-Q, --meanmedqdiff |
meanmedqdiff |
0.01 |
-t, --qthresh |
qthresh |
0.3 |
--noerodequant |
noerodequant |
0.99 |
--outliernumngb |
outliernumngb |
15 |
--outliersigma |
outliersigma |
5.0 |
--outliersclip |
outliersclip |
(3.0, 0.2) |
-e, --erode |
erode |
2 |
--erodengb |
erodengb |
4 |
-p, --opening |
opening |
1 |
--openingngb |
openingngb |
8 |
-B, --minskyfrac |
minskyfrac |
0.7 |
--skyfracnoblank |
skyfracnoblank |
False |
-s, --sigmaclip |
sigmaclip |
(3.0, 0.2) |
-R, --dthresh |
dthresh |
0.0 |
--dopening |
dopening |
1 |
--dopeningngb |
dopeningngb |
4 |
--holengb |
holengb |
8 |
--pseudoconcomp |
pseudoconcomp |
4 |
-m, --snminarea |
snminarea |
10 |
--minnumfalse |
minnumfalse |
100 |
-c, --snquant |
snquant |
0.99 |
--snthresh |
snthresh (None = measure it) |
None |
-d, --detgrowquant |
detgrowquant |
0.9 |
--detgrowmaxholesize |
detgrowmaxholesize |
100 |
--cleangrowndet |
cleangrowndet |
False |
-N, --numthreads |
numthreads |
all cores |
Output options are on the CLI and on run_fits / write_fits: -h/--hdu,
-o/--output, --label (int32 labels instead of a 0/1 mask), --rawoutput
(no INPUT-NO-SKY) and --oneelempertile. Options only in this version:
device and ccl (labelling backend). NoiseChiselParams lists the options
in Python, and noisechisel-torch --help on the command line.
Not available: check images (--check*), --blankasforeground,
--numchannels other than 1, and --convolved.
Validation
- Identical masks, Sky and STD on 18 simulated Roman WFI detectors, on the frame shown above and on images with NaN regions.
benchmarks/compare_gnuastro.pyruns both programs on your images and reports pixel differences and timings.benchmarks/readme_figures.pymakes the output comparison figure andbenchmarks/scaling.pythe timing figures.- CI runs the tests on Linux, macOS and Windows (Python 3.11/3.12) and compares against Gnuastro 0.24 on Linux and macOS.
Development
mamba create -n noisechisel-dev -c conda-forge python=3.12 gnuastro=0.24 pytorch numpy scipy astropy pytest pip
mamba activate noisechisel-dev
pip install -e ".[test]"
pytest
To release, bump version in pyproject.toml, merge to main, then tag that
commit and push the tag:
git tag v0.1.0 && git push origin v0.1.0
The publish workflow checks the tag is on main and matches the version,
runs the tests, and uploads to PyPI.
Limitations
- 2D single-channel images only. NaN pixels are never detected, and check images are not written.
- Apple MPS has no float64, so
device="mps"runs on the CPU. - Without CuPy, labelling on CUDA goes through host memory (scipy), which is slower.
Citation
NoiseChisel is part of Gnuastro (NoiseChisel manual). If you use this package, please cite the NoiseChisel papers:
- Akhlaghi & Ichikawa (2015), Noise-based Detection and Segmentation of Nebulous Objects, ApJS 220, 1. doi:10.1088/0067-0049/220/1/1, arXiv:1505.01664
- Akhlaghi (2019), Carving out the low surface brightness universe with NoiseChisel. arXiv:1909.11230
astnoisechisel --cite prints the BibTeX for the Gnuastro version you have.
To cite this port, use CITATION.cff ("Cite this repository" on GitHub) or:
@software{noisechisel_torch,
author = {Sanchez Alarcon, Pablo M.},
title = {noisechisel-torch: a PyTorch (CPU/GPU) port of Gnuastro's NoiseChisel},
url = {https://github.com/PabloMSanAla/noisechisel},
version = {0.1.0},
year = {2026}
}
If this package is useful to you, please give the repository a ⭐ on GitHub.
License
GPL-3.0-or-later. This is a derivative of Gnuastro, © Free Software Foundation.
Metadata
Release files for noisechisel-torch 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| noisechisel_torch-0.1.0.tar.gz | 46.0 kB | With provenance | Details for noisechisel_torch-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| noisechisel_torch-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for noisechisel_torch-0.1.0-py3-none-any.whl |
Total release size: 86.2 kB
Release files / noisechisel_torch-0.1.0.tar.gz
| Download URL | noisechisel_torch-0.1.0.tar.gz |
|---|---|
| Size | 46.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0d218b0c20cfb961b5a7d19bd3df653f4bb5621db227683109f8d8da0081fd9
|
|
BLAKE2b-256 checksum How to use checksums |
666db548e95a6813aa64ee1ea765f7686eb2f566d03d55bd12673a952289901c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / noisechisel_torch-0.1.0-py3-none-any.whl
| Download URL | noisechisel_torch-0.1.0-py3-none-any.whl |
|---|---|
| Size | 40.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c453d9eb55a84610895187c41e86c9d3caeaa0225c17265f1dacecf34ce69c2
|
|
BLAKE2b-256 checksum How to use checksums |
c003562b837b29cad41ea18e0f2b6df6cc164a365f406221f2df9532e2671f0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for noisechisel-torch 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for noisechisel_torch-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.