Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework tutorials #161

Merged
merged 9 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repos:
args:
- --markdown-linebreak-ext=md
- id: check-added-large-files
args:
- "--maxkb=5000"
- id: check-merge-conflict
- id: end-of-file-fixer
exclude: ^.*fits
Expand Down
6 changes: 3 additions & 3 deletions btk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,15 @@ def auc(metrics_results, measure_name, n_meas, plot=False, ax=None):
# The integral is from zero to one
recalls = np.insert(recalls, 0, 0)
precisions = np.insert(precisions, 0, precisions[0])
recalls = np.insert(recalls, -1, 1)
precisions = np.insert(precisions, -1, precisions[-1])
recalls = np.append(recalls, 1)
precisions = np.append(precisions, precisions[-1])

for i in range(1, n_meas):
average_precision += precisions[i] * (recalls[i] - recalls[i - 1])

if plot:
ax = plt.gca() if ax is None else ax
ax.scatter(recalls, precisions, label=measure_name)
ax.plot(recalls, precisions, label=measure_name, marker="x")
ax.set_xlabel("Recall")
ax.set_ylabel("Precision")

Expand Down
2 changes: 1 addition & 1 deletion btk/sampling_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, max_number=2, stamp_size=24.0, maxshift=None):
@property
def compatible_catalogs(self):
"""Defined in parent class."""
return "CatsimCatalog", "CosmosCatalog"
return "CosmosCatalog"

def __call__(self, table, shifts=None, indexes=None):
"""Method returning a blend sample from table.
Expand Down
42 changes: 4 additions & 38 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,44 +451,10 @@ BTK supports galaxy image generation with galsim_hub ; please refer to :ref:`thi

You can find a notebook version of this tutorial in the notebooks folder.

First, you should use the ``CosmosCatalog`` catalog instead of the Catsim one. While galsim_hub only require parameters for the image generation, we have chosen to use COSMOS as the source of those parameters so as to get a realistic distribution of those parameters. We have included a small sample of the catalog in BTK, and advise you to download the full catalog (see:ref:`COSMOS`) for better results.
.. Add notes on how to install galsim hub with pip extras
ismael-mendoza marked this conversation as resolved.
Show resolved Hide resolved

.. jupyter-execute::

COSMOS_CATALOG_PATHS = [
ismael-mendoza marked this conversation as resolved.
Show resolved Hide resolved
"../data/cosmos/real_galaxy_catalog_23.5_example.fits",
"../data/cosmos/real_galaxy_catalog_23.5_example_fits.fits",
]
catalog = btk.catalog.CosmosCatalog.from_file(COSMOS_CATALOG_PATHS)

We then instantiate the sampling function ; you should use the one specific for galsim_hub, which includes a cut on the size of the galaxies, as artifacts tend to appear when trying to generate galaxies which are too big.

.. jupyter-execute::
Advanced features
------------------

stamp_size = 24.0
sampling_function = btk.sampling_functions.DefaultSamplingGalsimHub(stamp_size=stamp_size)

Then we can instantiate the ``DrawBlendsGenerator`` with the survey of your choice. Please bear in mind that while BTK will draw the images in any band you desire, galsim_hub does not generate a SED for the galaxy ; this means that the magnitude will be inacurrate in any other band than the one generated by the galsim_hub model you use (by default ``"hub:Lanusse2020"``).

.. .. jupyter-execute::

.. draw_generator = btk.draw_blends.GalsimHubGenerator(
.. catalog,
.. sampling_function,
.. [Rubin],
.. batch_size=8,
.. stamp_size=stamp_size,
.. shifts=None,
.. indexes=None,
.. cpus=1,
.. add_noise=True,
.. galsim_hub_model="hub:Lanusse2020", #May be replaced by any model compatible with galsim_hub
.. param_names=["flux_radius", "mag_auto", "zphot"], #Name of the parameters ; they must match with the model you provide
.. )

.. jupyter-execute::

batch = next(draw_generator)
blend_images = batch['blend_images']
blend_list = batch['blend_list']
btk.plot_utils.plot_blends(blend_images, blend_list, limits=(30,90))
You can find a detailed tutorial on several more advanced feature of BTK in this `notebook <https://github.com/LSSTDESC/BlendingToolKit/blob/main/notebooks/intro.ipynb>`_, including how to write your own measure function which should be interesting to most user. You will also see how to use the multiresolution, write your own sampling function or survey, use several measure functions and use of the measure_kwargs feature.
ismael-mendoza marked this conversation as resolved.
Show resolved Hide resolved
Loading