Package: deepCR
deepCR: Deep Learning Based Cosmic Ray Removal for Astronomical ImagesIdentify and remove cosmic rays from astronomical images using trained convolutional neural networks.Documentation and tutorials:https://deepcr.readthedocs.io/This is the installable package which implements the methods described in the paper: Zhang & Bloom (2019), submitted.Code to reproduce benchmarking results in the paper is at:https://github.com/kmzzhang/deepCR-paperIf you use this package, please cite Zhang & Bloom (2019):https://arxiv.org/abs/1907.09500and consider including a
link to this repository.Note: the current release includes only model for HST ACS/WFC.InstallationpipinstalldeepCROr you can install from source:gitclonehttps://github.com/profjsb/deepCR.gitcddeepCR/
pythonsetup.pyinstallQuick StartQuick download of a HST ACS/WFC imagewget-Ojdba2sooq_flc.fitshttps://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/jdba2sooq_flc.fitsWith Python >=3.5:For smaller sized imagesfromdeepCRimportdeepCRfromastropy.ioimportfitsimage=fits.getdata("jdba2sooq_flc.fits")[:512,:512]# create an instance of deepCR with specified model configurationmdl=deepCR(mask="ACS-WFC-F606W-2-32",inpaint="ACS-WFC-F606W-2-32",device="CPU")# apply to input imagemask,cleaned_image=mdl.clean(image,threshold=0.5)# best threshold is highest value that generate mask covering full extent of CR# choose threshold by visualizing outputs.# note that deepCR-inpaint would overestimate if mask does not fully cover CR.# if you only need CR mask you may skip image inpainting for shorter runtimemask=mdl.clean(image,threshold=0.5,inpaint=False)# if you want probabilistic cosmic ray mask instead of binary maskprob_mask=mdl.clean(image,binary=False)For WFC full size images (4k * 2k), you should specifysegment = Trueto tell deepCR to segment the input image into 256*256 patches, and process one patch at a time.
Otherwise this would take up > 10gb memory. We recommended you use segment = True for images larger than 1k * 1k on CPU. GPU memory limits may be more strict.image=fits.getdata("jdba2sooq_flc.fits")mask,cleaned_image=mdl.clean(image,threshold=0.5,segment=True)(CPU only) In place ofsegment = True, you can also specifyparallel = Trueand invoke the multi-threaded version of segment mode. This will speed things up. You don't have to specify segment = True again.image=fits.getdata("jdba2sooq_flc.fits")mask,cleaned_image=mdl.clean(image,threshold=0.5,parallel=True,n_jobs=-1)n_jobs=-1makes use of all your CPU cores.Note that this won't speed things up if you're using GPU!Currently available modelsmask:ACS-WFC-F606W-2-4

ACS-WFC-F606W-2-32(*)inpaint:ACS-WFC-F606W-2-32(*)

ACS-WFC-F606W-3-32Recommended models are marked in (*). Larger number indicate larger capacity.Input images should come from_flc.fitsfiles which are in units of electrons.Limitations and CaveatsThe currently included models are trained and benchmarked on HST ACS/WFC images in the F606W filter.Visual inspection shows that these models also work well on filters from F435W to F814W. However, users should use a higher threshold (e.g. 0.9) for short wavelength filters to minimize false detections, if any.ContributingWe are very interested in getting bug fixes, new functionality, and new trained models from the community (especially for ground-based imaging and spectroscopy). Please fork this repo and issue a PR with your changes. It will be especially helpful if you add some tests for your changes.