Skip to content

Commit

Permalink
updated README and data preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
kmzzhang committed Jul 23, 2019
1 parent 913ad6b commit 3ee5217
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ which segments the input image into patches of 256*256, seperately perform CR re

### Currently available models

mask: ACS-WFC-F606W-2-4
ACS-WFC-F606W-2-32(*)
mask:
ACS-WFC-F606W-2-4
ACS-WFC-F606W-2-32(*)

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

The two numbers following instrument configuration specifies model size, with larger number indicating better performing model at the expense of runtime. Recommanded models are marked in (*). For benchmarking of these models, please refer to the original paper.

### API Documentation

Documentation is under development at: https://deepcr.readthedocs.io/en/latest/deepCR.html

### Limitations and Caveats

In the current release, the included models have been built and tested only on Hubble Space Telescope (HST) ACS/WFC images in the F606W filter. Application to native-spatial resolution (ie. not drizzled), calibrated images from ACS/F606W (`*_flc.fits`) is expected to work well. Use of these prepackaged models in other observing modes with HST or spectroscopy is not encouraged. We are planning hosting a "model zoo" that would allow deepCR to be adapted to a wide range of instrument configurations.
Expand Down
27 changes: 12 additions & 15 deletions deepCR/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
from os import path, mkdir
import math

import numpy as np
import joblib
import torch
Expand All @@ -24,7 +23,7 @@

class deepCR():

def __init__(self, mask=None, inpaint='medmask', device='CPU',
def __init__(self, mask='ACS-WFC-F606W-2-32', inpaint='medmask', device='CPU',
model_dir=default_model_path):

"""model class instantiation for deepCR. Here is the
Expand All @@ -34,7 +33,7 @@ def __init__(self, mask=None, inpaint='medmask', device='CPU',
Parameters
----------
mask : str
Name of the mask to use. This is one of the keys in
Name of deepCR-mask model to use. This is one of the keys in
`mask_dict`
inpaint : str
Name of the inpainting model to use. This is one of the keys in
Expand Down Expand Up @@ -89,17 +88,14 @@ def __init__(self, mask=None, inpaint='medmask', device='CPU',
def clean(self, img0, threshold=0.5, inpaint=True, binary=True,
seg=0, parallel=False, n_jobs=-1):
"""
helper function to pass img0 to either
self.clean_single()
or
self.clean_seg()
:param img0 (np.ndarray): 2D input image
:param threshold: for creating binary mask from probablistic mask
:param inpaint: return clean image only if True
:param binary: return binary mask if True. probabilistic mask otherwise.
:param seg: blocksize to apply models on
Identify cosmic rays in an input image, and (optionally) inpaint with the predicted cosmic ray mask
:param img0: (np.ndarray) 2D input image conforming to model requirements. For HST ACS/WFC, must be from _flc.fits and in units of electrons in native resolution.
:param threshold: (float) applied to probabilistic mask to generate binary mask
:param inpaint: (bool) return clean, inpainted image only if True
:param binary: return binary CR mask if True. probabilistic mask if False
:param seg: for large input images, blocksize to apply models on
:param parallel: run in parallel if True and seg > 0
:param n_jobs number of jobs to run in parallel, passed to `joblib`
:param n_jobs: number of jobs to run in parallel, passed to `joblib`
:return: mask or binary mask; or None if internal call
"""
if seg==0:
Expand Down Expand Up @@ -284,6 +280,8 @@ def inpaint(self, img0, mask):
:param mask (np.ndarray): 2D input mask
:return: inpainted image
"""
img0 = img0.astype(np.float32) / 100
mask = mask.astype(np.float32)
shape = img0.shape[-2:]
if self.inpaintNet is not None:
img0 = from_numpy(img0).type(self.dtype). \
Expand All @@ -299,6 +297,5 @@ def inpaint(self, img0, mask):
else:
img1 = medmask(img0, mask)
inpainted = img1 * mask + img0 * (1 - mask)

return inpainted
return inpainted * 100

0 comments on commit 3ee5217

Please sign in to comment.