Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sowmyakth committed Sep 26, 2019
2 parents c2efa0e + c224d3c commit e536f79
Showing 1 changed file with 54 additions and 22 deletions.
76 changes: 54 additions & 22 deletions btk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ def get_deblended_images(self, data, index):


class Stack_params(measure.Measurement_params):
min_pix = 1
bkg_bin_size = 32
thr_value = 5
psf_stamp_size = 41
"""Class with functions that describe how LSST science pipeline can
perform measurements on the input data."""
min_pix = 1 # Minimum size in pixels to be considered a source
bkg_bin_size = 32 # Binning size of the local background
thr_value = 5 # SNR threshold for the detection
psf_stamp_size = 41 # size of pstamp to draw PSF on

def get_psf_sky(self, obs_cond):
"""Returns postage stamp image of the PSF and mean background sky
level value saved in the input obs_cond class
Args:
obs_cond:`descwl.survey.Survey` class describing observing
conditions.
"""
mean_sky_level = obs_cond.mean_sky_level
psf = obs_cond.psf_model
psf_image = psf.drawImage(
Expand All @@ -51,7 +60,15 @@ def get_psf_sky(self, obs_cond):

def make_measurement(self, data, index):
"""Perform detection, deblending and measurement on the i band image of
the blend image for input index in the batch.
the blend for input index entry in the batch.
Args:
data: Dictionary with blend images, isolated object images, blend
catalog, and observing conditions.
index: Position of the blend to measure in the batch.
Returns:
astropy.Table of the measurement results.
"""
image_array = data['blend_images'][index, :, :, 3].astype(np.float32)
psf_image, mean_sky_level = self.get_psf_sky(
Expand Down Expand Up @@ -135,14 +152,26 @@ def run_stack(image_array, variance_array, psf_array,


class Scarlet_params(measure.Measurement_params):
iters = 200
e_rel = .015
"""Class with functions that describe how scarlet should deblend images in
the input data"""
iters = 200 # Maximum number of iterations for scarlet to run
e_rel = .015 # Relative error for convergence
detect_centers = True

def make_measurement(self, data=None, index=None):
return None

def get_centers(self, image):
"""Returns centers from SEP detection on the band averaged mean of the
input image.
Args:
image: Numpy array of multi-band image to run scarlet on
[Number of bands, height, width].
Returns:
Array of x and y coordinate of centroids of objects in the image.
"""
sep = __import__('sep')
detect = image.mean(axis=0) # simple average for detection
bkg = sep.Background(detect)
Expand All @@ -159,7 +188,8 @@ def scarlet_initialize(self, images, peaks,
peaks: Array of x and y coordinate of centroids of objects in
the image [number of sources, 2].
bg_rms: Background RMS value of the images [Number of bands]
Returns
Returns:
blend: scarlet.Blend object for the initialized sources
rejected_sources: list of sources (if any) that scarlet was
unable to initialize the image with.
Expand All @@ -184,18 +214,19 @@ def get_deblended_images(self, data, index):
"""
Deblend input images with scarlet
Args:
images: Numpy array of multi-band image to run scarlet on
[Number of bands, height, width].
peaks: x and y coordinate of centroids of objects in the image.
[number of sources, 2]
bg_rms: Background RMS value of the images [Number of bands]
iters: Maximum number of iterations if scarlet doesn't converge
(Default: 200).
e_rel: Relative error for convergence (Default: 0.015)
Returns
blend: scarlet.Blend object for the initialized sources
rejected_sources: list of sources (if any) that scarlet was
unable to initialize the image with.
images: Numpy array of multi-band image to run scarlet on
[Number of bands, height, width].
peaks: x and y coordinate of centroids of objects in the image.
[number of sources, 2]
bg_rms: Background RMS value of the images [Number of bands]
iters: Maximum number of iterations if scarlet doesn't converge
(Default: 200).
e_rel: Relative error for convergence (Default: 0.015)
Returns:
blend: scarlet.Blend object for the initialized sources
rejected_sources: list of sources (if any) that scarlet was
unable to initialize the image with.
"""
images = np.transpose(data['blend_images'][index], axes=(2, 0, 1))
blend_cat = data['blend_list'][index]
Expand Down Expand Up @@ -223,6 +254,7 @@ def make_true_seg_map(image, threshold):
image: Image to estimate segmentation map of
threshold: Pixels above this threshold are marked as belonging to
segmentation map
Returns:
Boolean segmentation map of the image
"""
Expand Down Expand Up @@ -338,9 +370,9 @@ def get_centers(self, image):
is done on input image with SEP.
Args:
image: Image (single band) of galaxy to perform measurement on.
Returns:
centers: x and y coordinates of detected centroids
"""
# set detection threshold to 5 times std of image
threshold = 5*np.std(image)
Expand Down Expand Up @@ -398,7 +430,7 @@ def __init__(self, *args, **kwargs):
"""

def get_detections(self):
"""Returns blend catalog and detection catalog for detction performed
"""Returns blend catalog and detection catalog for detection performed
Returns:
Results of the detection algorithm are returned as:
Expand Down

0 comments on commit e536f79

Please sign in to comment.