"Unsupervised galaxy masking to remove background source detections"
Project description
galmask
galmask is an open-source package written in Python that provides a simple way to remove unwanted background source detections from galaxy images.
It builds on top of astropy and photutils astronomical Python libraries and the opencv and skimage image processing libraries.
The main requirements of galmask are:
astropyfor handling FITS I/O and general-purpose astronomical routines.photutilsfor photometry purposes and deblending detected sources.opencv-pythonfor connected-component analysis.skimagefor general image processing functionalities.
Installation
Via pip
galmask can be installed from PyPI via pip by running::
pip install galmask
Alternative method
galmask can also be installed by cloning the repository and doing a pip install in the project directory::
git clone https://github.com/Yash-10/galmask
cd galmask
pip install .
It would be beneficial to create a python virtual environment and install the package within it, to prevent manipulating your global dependency versions.
Quick example
from astropy.io import fits
from astropy.visualization import AsinhStretch, ImageNormalize, ZScaleInterval, LogStretch
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
# Import galmask
from galmask.galmask import galmask
def axes_colorbar(ax):
divider = make_axes_locatable(ax)
cax = divider.append_axes('bottom', size='5%', pad=0.3)
return cax
filepath = 'example/gal1_G.fits'
image = fits.getdata(filepath)
npixels, nlevels, nsigma, contrast, min_distance, num_peaks, num_peaks_per_label, connectivity, remove_local_max = 5, 32, 2., 0.15, 1, 10, 3, 4, True # Parameters for galmask
seg_image = None # No segmentation map example
orig_segmap = fits.getdata('example/gal_seg1.fits')
galmasked, galsegmap = galmask(
image, npixels, nlevels, nsigma, contrast, min_distance, num_peaks, num_peaks_per_label,
connectivity=4, kernel=fits.getdata('kernel.fits'), seg_image=seg_image, mode="1",
remove_local_max=True, deblend=True
)
# Plotting result.
fig, ax = plt.subplots(1, 4, figsize=(24, 6))
# For keeping original and final images on same scale.
vmin = min(image.min(), galmasked.min())
vmax = max(image.max(), galmasked.max())
# fig.suptitle(filepath)
norm1 = ImageNormalize(image, vmin=vmin, vmax=vmax, interval=ZScaleInterval(), stretch=LogStretch())
im0 = ax[0].imshow(image, norm=norm1, origin='lower', cmap='gray')
ax[0].set_title("Original image")
cax0 = axes_colorbar(ax[0])
fig.colorbar(im0, cax=cax0, orientation='horizontal')
im1 = ax[1].imshow(orig_segmap, origin='lower')
ax[1].set_title("Original segmentation map (photutils)")
cax1 = axes_colorbar(ax[1])
fig.colorbar(im1, cax=cax1, orientation='horizontal')
im2 = ax[2].imshow(galsegmap, origin='lower', cmap='gray')
ax[2].set_title("Final segmentation map (galmask)")
cax2 = axes_colorbar(ax[2])
fig.colorbar(im2, cax=cax2, orientation='horizontal')
norm2 = ImageNormalize(galmasked, vmin=vmin, vmax=vmax, interval=ZScaleInterval(), stretch=LogStretch())
im3 = ax[3].imshow(galmasked, norm=norm2, origin='lower', cmap='gray')
ax[3].set_title("Final image (galmask)")
cax3 = axes_colorbar(ax[3])
fig.colorbar(im3, cax=cax3, orientation='horizontal')
plt.show()
Output:
NOTE:
orig_segmapis the original segmentation map - it is not returned by galmask. It is an intermediate result calculated inside galmask (if a pre-calculated segmentation map is not input). Here the original segmentation map was stored in a FITS file for demonstration purposes. So if you passseg_image=None(as done in the above example) and would like to create such four-column plots, you would need to edit the source code ofgalmask.pyto save the internally calculated segmentation map in a FITS file.
Documentation
The documentation is generated using the Sphinx documentation tool and hosted by Read the Docs. You can find the API reference and also some empirical tips to use galmask in the documentation.
Tests
For running the tests, you would need to install pytest. You can navigate to the tests/ directory and run:
pytest <name_of_file>
Contribute
Contributions are welcome! Currently, there seem to be a few inefficient ways of handling things within galmask, and we would like you to contribute and improve the package!
Please let us know of any bugs/issues by opening an issue in the issue tracker.
Citing
License and copyright
galmask is licensed under the MIT License.
Copyright (c) 2022 Yash Gondhalekar
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file galmask-0.2.0.tar.gz.
File metadata
- Download URL: galmask-0.2.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a66e12ecefa9fc99270cd2e33e133de14e160eb8ed69da5f07ce31f8739a1866
|
|
| MD5 |
8852320cb14bf588b0bb43a00934ec44
|
|
| BLAKE2b-256 |
720724f9cc390e08123a2203f1d4519ead9ce581cf1c07d784bde9c4b0a681d1
|
File details
Details for the file galmask-0.2.0-py3-none-any.whl.
File metadata
- Download URL: galmask-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1e0e16185f52902130c7cb878ab8b1391b691b783a9d531daee6bd3ec3c0600
|
|
| MD5 |
ebe86d8c7ffe1fc69396acffe1a7c5b1
|
|
| BLAKE2b-256 |
930a8e1e880beb4ce02b30a229b6dd466600ada9d035a1dcf89470610e4ac737
|