Skip to content

Commit

Permalink
Merge pull request #19 from LSSTDESC/#16
Browse files Browse the repository at this point in the history
  • Loading branch information
sowmyakth authored Apr 5, 2019
2 parents 99c8a0b + 4ee33cc commit ace42fd
Show file tree
Hide file tree
Showing 20 changed files with 10,533 additions and 247 deletions.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,29 @@ Tools to create blend catalogs, produce training samples and implement blending
Documentation can be found at https://blendingtoolkit.readthedocs.io/en/latest/

## Workflow
- Step 1: import raw catalogs from CatSim or the DC2 catalogs
- Step 2: modify those catalogs to create catalogs of (multiple) blends and explore joint distributions (separation, magnitude difference)
- Step 3: generate PSF-convolved images and perform data augmentation
- Step 4: train deep-learning algorthms to do various blending-related tasks such as detection, segmentation, deblending and measurements
- Step 5: test algorithms with a set of low- and high-level performance metrics
<img src="docs/source/images/flow_chart.png" alt="btk workflow" width="450"/>


## Input Catalog
- Catsim like catalogs and pre-processed WeakLensingDeblending catlogs can be found [here](https://weaklensingdeblending.readthedocs.io/en/latest/products.html)
## Running BlendingToolKit
- BlendingToolKit (btk) requires an input catalog that contains information required to simulate galaxies and blends.
This repository includes sample input catalogs with small number of galaxies that can be used to draw blend images with btk. See [tutorials](https://github.com/LSSTDESC/BlendingToolKit/tree/master/notebooks) to learn how to run btk with these catalogs.
- Catalog corresponding to one square degree sky and pre-processed WeakLensingDeblending catalogs can be downloaded from [here](https://stanford.app.box.com/s/s1nzjlinejpqandudjyykjejyxtgylbk).

## Useful tools
## Requirements
The code is intended to run in python >=3.6.
To run btk you need to install
- [WeakLensingDeblending](https://github.com/LSSTDESC/WeakLensingDeblending)
- [GalSim](https://github.com/GalSim-developers/GalSim/)
- [Scarlet](https://github.com/fred3m/scarlet/)
- numpy
- astropy
- fitsio
- scipy
- lmfit

More detailed installation instructions can be found [here](https://blendingtoolkit.readthedocs.io/en/latest/install.html)

### Optional
The tutorials include examples of using btk with some packages like
- [scarlet](https://github.com/fred3m/scarlet/) (multi-band deblender)
- [sep](https://sep.readthedocs.io/en/v1.0.x/index.html)(Source Extraction and Photometry)
- [lsst](https://pipelines.lsst.io) science pipeline
12 changes: 8 additions & 4 deletions btk/create_blend_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import warnings


def get_random_center_shift(Args, number_of_objects, maxshift=None):
Expand Down Expand Up @@ -72,9 +73,12 @@ def generate(Args, catalog, sampling_function=None):
blend_catalog = default_sampling(Args, catalog)
if Args.verbose:
print("Default random sampling of objects from catalog")
np.testing.assert_array_less(
len(blend_catalog) - 1, Args.max_number, "Number of objects"
" per blend must be less than max_number: {0} <= {1}".format(
len(blend_catalog), Args.max_number))
if len(blend_catalog) > Args.max_number:
raise ValueError("Number of objects per blend must be less \
than max_number: {0} <= {1}".format(
len(blend_catalog), Args.max_number))
if (np.any(blend_catalog['ra'] > Args.stamp_size/2.) or
np.any(blend_catalog['dec'] > Args.stamp_size/2.)):
warnings.warn('Object center lies outside the stamp')
blend_catalogs.append(blend_catalog)
yield blend_catalogs
8 changes: 8 additions & 0 deletions btk/create_observing_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ def generate(Args, obs_function=None):
descwl_survey = descwl.survey.Survey(no_analysis=True,
survey_name=Args.survey_name,
filter_band=band, **survey)
if descwl_survey.pixel_scale != Args.pixel_scale:
raise ValueError("observing condition pixel scale does not \
match input pixel scale: {0} == {1}".format(
descwl_survey.pixel_scale, Args.pixel_scale))
if descwl_survey.filter_band != band:
raise ValueError("observing condition band does not \
match input band: {0} == {1}".format(
descwl_survey.filter_band, band))
observing_generator.append(descwl_survey)
yield observing_generator
7 changes: 0 additions & 7 deletions docs/api/btk.compute_metrics.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.config.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.create_blend_generator.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.create_observing_generator.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.draw_blends.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.get_input_catalog.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.measure.rst

This file was deleted.

27 changes: 0 additions & 27 deletions docs/api/btk.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.temp.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.test_btk.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/btk.utils.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Evaluate Metrics with btk (*evaluate_metrics.ipynb*)
----------------------------------------------------
This `notebook <https://github.com/LSSTDESC/BlendingToolKit/blob/%2315/notebooks/evaluate_metrics.ipynb>`_ shows how to test performance of different detection/deblending/measurement algorithms. At present this only assesses detection performance by returning the number of objects correctly detected, number undetected and number of spurious detections.

5. Draw blends (*create_blend_generator*): Simulates scene of overlapping objects, convolved by PSF and with pixel noise (option set in *config*). Scene image is generated in each observing band. Isolated image of each object is also drawn without pixel contributions from other objects, in each band.
Draw blends (*create_blend_generator*): Simulates scene of overlapping objects, convolved by PSF and with pixel noise (option set in *config*). Scene image is generated in each observing band. Isolated image of each object is also drawn without pixel contributions from other objects, in each band.


2 changes: 1 addition & 1 deletion docs/source/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ User Guide
This document gives a detailed look into the work-flow of *BlendingToolKit* (btk). For a quick tutorial on how to run btk, see the JuPyter notebook tutorials :doc:`here </tutorials>`. This page is especially useful if you plan on using btk with your own detection/deblending/measurement algorithm.


The work-flow of btk is shown below
The workflow of btk is shown below

.. image:: images/flow_chart.png
:align: center
Expand Down
10,565 changes: 10,451 additions & 114 deletions notebooks/custom_sampling_function.ipynb

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions notebooks/run_basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,22 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2019-04-01T21:21:30.475879Z",
"start_time": "2019-04-01T21:21:26.952434Z"
"end_time": "2019-04-04T22:45:18.600782Z",
"start_time": "2019-04-04T22:45:15.057320Z"
}
},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import galsim\n",
"import sys\n",
"import descwl\n",
"import argparse\n",
"\n",
"import copy\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import os\n",
"import sys\n",
"import numpy as np\n",
"\n",
"#importing scarlet to make RGB images\n",
"#import scarlet.display to plot RGB images if scarelt is installed\n",
"if 'scarlet' in sys.modules:\n",
" import scarlet.display\n",
"\n",
Expand All @@ -45,21 +40,22 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2019-04-01T21:21:30.563261Z",
"start_time": "2019-04-01T21:21:30.530562Z"
"end_time": "2019-04-04T22:45:18.635367Z",
"start_time": "2019-04-04T22:45:18.609382Z"
},
"code_folding": [
0,
13,
29,
67
1,
14,
31,
69
]
},
"outputs": [],
"source": [
"# Functions helpful for plotting blend images\n",
"def get_rgb(image, min_val=None, max_val=None):\n",
" \"\"\"Basic function to normalize 3 band input image to rgb 0-255 image\"\"\"\n",
" assert image.shape[0] == 3, \"must be 3 channel in dimension 1\"\n",
Expand Down
Loading

0 comments on commit ace42fd

Please sign in to comment.