Skip to main content

A high-performance Python package for cosmic ray removal following the original paper by van Dokkum 2001.

Project description

dfcosmic

Tests Documentation Status

A high-performance Python package for cosmic ray removal strictly following the procedure outlined in van Dokkum 2001. Although several other implementations exist, their procedures differ slightly from that described in van Dokkum 2001. In this package, we use PyTorch to achieve considerable speedup over the original implementation while retaining fidelity to the algorithmic choices presented in the original paper.

Installation

Using PyPi

If you want to install using PyPi (which is certainly the easiest way), you can simply run

pip install dfcosmic

Installing from Source

For the latest development version, install directly from the GitHub repository:

git clone https://github.com/DragonflyTelescope/dfcosmic.git
cd dfcosmic
pip install -e .

Note: the CPU extensions (median filter + dilation) are compiled during install for speed. This requires a working C++ toolchain. If you need to pass custom OpenMP flags, you can do so via environment variables, for example:

export CXXFLAGS="-O3 -fopenmp -march=native"
export LDFLAGS="-fopenmp"
pip install -e .

For development installation with documentation dependencies:

pip install -e ".[docs]"

Basic Usage

We follow the same parameter naming conventions presented in the original IRAF code.

  • objlim: The contrast limit between CR and underlying objects
  • sigfrac: The fractional detection limit for neighboring pixels
  • sigclip: The detection limit for cosmic rays
from dfcosmic import lacosmic

clean_image, crmask = lacosmic(
    image=original_data,
    objlim=2,
    sigfrac=1,
    sigclip=6,
    gain=1,
    readnoise=10,
    niter=1,
    device="cuda",
)

If you are unsure of either the gain or the readnoise you can leave them blank or set to 0. If so, then the gain will be estimated at each iteration.

Simple Example

Example

Timing Comparisons

We compare our pytorch implementation running on either a CPU (torch), CPU (torch & c++) or GPU with two popular cosmic ray removal codes: lacosmic and astroscrappy.

In order to run this timing comparison, we use the synthetic data described (and created) in the astroscrappy testing suite. The full notebook can be found in demos/Comparison.ipynb.

Timing Comparisons

Running Tests

The unit tests can be run using the following command:

pytest

The default settings are in the pytest.ini file.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Citation

License

The License for all past and present versions is the GPL-3.0.

AI Disclosure

Claude code was used to help with the unit tests only. ChatGPT was used to create only the c++ code for the median filter and dilation - these were thoroughly reviewed by the authors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dfcosmic-0.0.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dfcosmic-0.0.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file dfcosmic-0.0.1.tar.gz.

File metadata

  • Download URL: dfcosmic-0.0.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for dfcosmic-0.0.1.tar.gz
Algorithm Hash digest
SHA256 61f82fac286b13e6a8d1534dbed7a115e6759e2761b79e60d8ee036c7af5b78e
MD5 a54976fea0270b9d197d18425a09f1d5
BLAKE2b-256 2387a32096a2be91c2263d3e7d5a5c6d3b822dbccaec77787328165bbe0262d7

See more details on using hashes here.

File details

Details for the file dfcosmic-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dfcosmic-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for dfcosmic-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9ddade9f4a055783deb25ec9339452f778f3e70f822a0843caa4e22fbb45b99
MD5 e5a57fdbfe5f3b1cf126062378cf0a43
BLAKE2b-256 6614f465ba8056ba8d1193b13717f4cb75631b95334e0092f842e01af6014890

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page