Package: galmask
galmaskgalmaskis 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 ofastropyandphotutilsastronomical Python libraries and theopencvandskimageimage processing libraries.The main requirements ofgalmaskare: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.InstallationViapipgalmaskcan be installed from PyPI viapipby running::pip install galmaskAlternative methodgalmaskcan 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 examplefromastropy.ioimportfitsfromastropy.visualizationimportAsinhStretch,ImageNormalize,ZScaleInterval,LogStretchimportmatplotlib.pyplotaspltfrommpl_toolkits.axes_grid1importmake_axes_locatable# Import galmaskfromgalmask.galmaskimportgalmaskdefaxes_colorbar(ax):divider=make_axes_locatable(ax)cax=divider.append_axes('bottom',size='5%',pad=0.3)returncaxfilepath='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 galmaskseg_image=None# No segmentation map exampleorig_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.DocumentationThe documentation is generated using theSphinxdocumentation tool and hosted byRead the Docs.
You can find the API reference and also some empirical tips to use galmask in thedocumentation.TestsFor running the tests, you would need to installpytest. You can navigate to thetests/directory and run:pytest <name_of_file>ContributeContributions 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 theissue tracker.CitingLicense and copyrightgalmask is licensed under theMIT License.Copyright (c) 2022 Yash Gondhalekar