<jupyter_start><jupyter_text>COSMOS image generation tutorial Setup<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
import sys

import btk
import btk.plot_utils
import btk.survey
import btk.draw_blends
import btk.catalog
import btk.sampling_functions
import astropy.table

# Here we use a small sample of the real COSMOS catalog; feel free to fill in the correct path
# if you have the complete catalog on your computer
COSMOS_CATALOG_PATHS = [
    "../data/cosmos/real_galaxy_catalog_23.5_example.fits",
    "../data/cosmos/real_galaxy_catalog_23.5_example_fits.fits",
]<jupyter_output><empty_output><jupyter_text>Drawing blendsWe assume that you have already gone over the "intro" tutorial. You will find that generating images with COSMOS is very similar to generating images with Catsim. Let's start with the catalog and sampling function.<jupyter_code>stamp_size = 24.0
batch_size = 8
catalog = btk.catalog.CosmosCatalog.from_file(COSMOS_CATALOG_PATHS)
sampling_function = btk.sampling_functions.DefaultSampling(stamp_size=stamp_size)
survey = btk.survey.get_surveys("Rubin")<jupyter_output><empty_output><jupyter_text>We can now create the corresponding instance of DrawBlendsGenerator. There is an important caveat here: as in the other tutorial, we use the Rubin survey. However, the COSMOS catalog only contains images from the f814w band; thus, when simulating images, the same magnitude is used to compute the galaxy fluxes across all bands.There is one way to circumvent this limitation in BTK: by providing a custom COSMOS catalog containing multiband magnitude information, one can compute more realistic source fluxes in each band. Such COSMOS catalogs containing multiband magnitudes for the HSC survey are available in the repository at "../data/cosmos" as "real_galaxy_catalog_26_extension_example.fits" and "real_galaxy_catalog_26_extension_example_fits.fits". Feel free to check the documentation for more information about COSMOS catalogs.<jupyter_code>draw_generator = btk.draw_blends.CosmosGenerator(
        catalog,
        sampling_function,
        survey,
        batch_size=batch_size,
        stamp_size=stamp_size,
        cpus=1,
        add_noise=True,
        verbose=False,
    )
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))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06308506308506308, 'fraction_numerical': 0.008954008954008955, 'mean_word_length': 5.468421052631579, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '114617', 'license': 'MIT', 'n_tokens_mistral': 768, 'n_tokens_neox': 737, 'n_words': 240, 'path': 'notebooks/01a-cosmos_tutorial.ipynb', 'repo_name': 'LSSTDESC/BlendingToolK', 'size': '2457'}