diff --git a/btk/create_blend_generator.py b/btk/create_blend_generator.py index 089003d5e..aacb33c9b 100644 --- a/btk/create_blend_generator.py +++ b/btk/create_blend_generator.py @@ -23,9 +23,10 @@ def __init__( batch_size (int): Size of batches returned. shifts (list): Contains arbitrary shifts to be applied instead of random shifts. Must be of length batch_size. Must be used - with indexes. + with indexes. Used mostly for internal testing purposes. indexes (list): Contains the ids of the galaxies to use in the stamp. Must be of length batch_size. Must be used with shifts. + Used mostly for internal testing purposes. verbose (bool): Whether to print additional information. """ self.catalog = catalog diff --git a/btk/draw_blends.py b/btk/draw_blends.py index dbe6dc1c0..da3ed4748 100644 --- a/btk/draw_blends.py +++ b/btk/draw_blends.py @@ -150,9 +150,10 @@ def __init__( add_noise (bool): Indicates if the blends should be generated with noise shifts (list): Contains arbitrary shifts to be applied instead of random shifts. Must be of length batch_size. Must be used - with indexes. + with indexes. Used mostly for internal testing purposes. indexes (list): Contains the ids of the galaxies to use in the stamp. Must be of length batch_size. Must be used with shifts. + Used mostly for internal testing purposes. channels_last (bool): Whether to return images as numpy arrays with the channel (band) dimension as the last dimension or before the pixels dimensions (default). diff --git a/docs/source/tutorials.rst b/docs/source/tutorials.rst index a199187b7..8c8edeb58 100644 --- a/docs/source/tutorials.rst +++ b/docs/source/tutorials.rst @@ -83,7 +83,7 @@ which galaxies are drawn, with what shifts, etc. This is achieved using the ``Sa max_shift = 3.0 # Maximum shift of the galaxies, in arcseconds sampling_function = btk.sampling_functions.DefaultSampling(max_number=max_number, stamp_size=stamp_size, maxshift=max_shift, seed=seed) -As a reference, here is the code for this sampling function: +As a reference, here is a (slightly) simplified version of the code for this sampling function: .. jupyter-execute:: @@ -106,7 +106,7 @@ As a reference, here is the code for this sampling function: def compatible_catalogs(self): return "CatsimCatalog", "CosmosCatalog" - def __call__(self, table, shifts=None, indexes=None): + def __call__(self, table): """Applies default sampling to the input CatSim-like catalog and returns an astropy table with entries corresponding to a blend centered close to postage stamp center. @@ -122,10 +122,6 @@ As a reference, here is the code for this sampling function: Args: table (astropy.table): Table containing entries corresponding to galaxies from which to sample. - shifts (list): Contains arbitrary shifts to be applied instead of random ones. - Should of the form [x_peak,y_peak] where x_peak and y_peak are the lists - containing the x and y shifts. - indexes (list): Contains the indexes of the galaxies to use. Returns: Astropy.table with entries corresponding to one blend. @@ -133,16 +129,9 @@ As a reference, here is the code for this sampling function: number_of_objects = np.random.randint(1, self.max_number + 1) (q,) = np.where(table["ref_mag"] <= 25.3) - if indexes is None: - blend_table = table[np.random.choice(q, size=number_of_objects)] - else: - blend_table = table[indexes] + blend_table = table[np.random.choice(q, size=number_of_objects)] blend_table["ra"] = 0.0 blend_table["dec"] = 0.0 - if shifts is None: - x_peak, y_peak = _get_random_center_shift(number_of_objects, self.maxshift) - else: - x_peak, y_peak = shifts blend_table["ra"] += x_peak blend_table["dec"] += y_peak @@ -296,8 +285,6 @@ Now that we have all the objects at our disposal, we can create the DrawBlendsGe [Rubin], batch_size=8, stamp_size=stamp_size, - shifts=None, - indexes=None, cpus=1, add_noise=True, seed=seed @@ -464,8 +451,6 @@ Saving the results can be automatically achieved by providing the save_path argu Rubin, batch_size=100, stamp_size=stamp_size, - shifts=None, - indexes=None, cpus=1, add_noise=True, save_path=save_path diff --git a/notebooks/00-intro.ipynb b/notebooks/00-intro.ipynb index 929aba060..d7919a34a 100644 --- a/notebooks/00-intro.ipynb +++ b/notebooks/00-intro.ipynb @@ -200,7 +200,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As a reference, here is the code for this sampling function." + "As a reference, here is a (slightly) simplified version of the code for this sampling function." ] }, { @@ -234,7 +234,7 @@ " def compatible_catalogs(self):\n", " return \"CatsimCatalog\", \"CosmosCatalog\"\n", "\n", - " def __call__(self, table, shifts=None, indexes=None):\n", + " def __call__(self, table):\n", " \"\"\"Applies default sampling to the input CatSim-like catalog and returns an\n", " astropy table with entries corresponding to a blend centered close to postage\n", " stamp center.\n", @@ -250,10 +250,6 @@ " Args:\n", " table (astropy.table): Table containing entries corresponding to galaxies\n", " from which to sample.\n", - " shifts (list): Contains arbitrary shifts to be applied instead of random ones.\n", - " Should of the form [x_peak,y_peak] where x_peak and y_peak are the lists\n", - " containing the x and y shifts.\n", - " indexes (list): Contains the indexes of the galaxies to use.\n", "\n", " Returns:\n", " Astropy.table with entries corresponding to one blend.\n", @@ -261,16 +257,10 @@ " number_of_objects = np.random.randint(1, self.max_number + 1)\n", " (q,) = np.where(table[\"ref_mag\"] <= 25.3)\n", "\n", - " if indexes is None:\n", - " blend_table = table[np.random.choice(q, size=number_of_objects)]\n", - " else:\n", - " blend_table = table[indexes]\n", + " blend_table = table[np.random.choice(q, size=number_of_objects)]\n", " blend_table[\"ra\"] = 0.0\n", " blend_table[\"dec\"] = 0.0\n", - " if shifts is None:\n", - " x_peak, y_peak = _get_random_center_shift(number_of_objects, self.maxshift)\n", - " else:\n", - " x_peak, y_peak = shifts\n", + " x_peak, y_peak = _get_random_center_shift(number_of_objects, self.maxshift)\n", " blend_table[\"ra\"] += x_peak\n", " blend_table[\"dec\"] += y_peak\n", "\n", @@ -500,8 +490,6 @@ " Rubin,\n", " batch_size=100,\n", " stamp_size=stamp_size,\n", - " shifts=None,\n", - " indexes=None,\n", " cpus=1,\n", " add_noise=True,\n", " seed=seed, # same random seed is used here too!\n", @@ -970,8 +958,6 @@ " Rubin,\n", " batch_size=100,\n", " stamp_size=stamp_size,\n", - " shifts=None,\n", - " indexes=None,\n", " cpus=1,\n", " add_noise=True,\n", " save_path=save_path\n", diff --git a/notebooks/01c-galsim_hub_tutorial.ipynb b/notebooks/01c-galsim_hub_tutorial.ipynb index c3f4cf11a..880cdb6dc 100644 --- a/notebooks/01c-galsim_hub_tutorial.ipynb +++ b/notebooks/01c-galsim_hub_tutorial.ipynb @@ -139,8 +139,6 @@ " survey,\n", " batch_size=8,\n", " stamp_size=stamp_size,\n", - " shifts=None,\n", - " indexes=None,\n", " cpus=1,\n", " add_noise=True,\n", " galsim_hub_model=\"hub:Lanusse2020\", #May be replaced by any model compatible with galsim_hub\n", diff --git a/notebooks/02b-custom-tutorial.ipynb b/notebooks/02b-custom-tutorial.ipynb index 5e50b9200..0b06fe8cf 100644 --- a/notebooks/02b-custom-tutorial.ipynb +++ b/notebooks/02b-custom-tutorial.ipynb @@ -21,7 +21,8 @@ "import os\n", "import sys\n", "import btk\n", - "import galsim" + "import galsim\n", + "import warnings" ] }, { @@ -79,7 +80,7 @@ " def compatible_catalogs(self):\n", " return \"CatsimCatalog\", \"CosmosCatalog\"\n", "\n", - " def __call__(self, table, shifts=None, indexes=None):\n", + " def __call__(self, table):\n", " \"\"\"Applies default sampling to the input CatSim-like catalog and returns an\n", " astropy table with entries corresponding to a blend centered close to postage\n", " stamp center.\n", @@ -95,10 +96,6 @@ " Args:\n", " table (astropy.table): Table containing entries corresponding to galaxies\n", " from which to sample.\n", - " shifts (list): Contains arbitrary shifts to be applied instead of random ones.\n", - " Should of the form [x_peak,y_peak] where x_peak and y_peak are the lists\n", - " containing the x and y shifts.\n", - " indexes (list): Contains the indexes of the galaxies to use.\n", "\n", " Returns:\n", " Astropy.table with entries corresponding to one blend.\n", @@ -106,16 +103,10 @@ " number_of_objects = np.random.randint(1, self.max_number + 1)\n", " (q,) = np.where(table[\"ref_mag\"] <= 25.3)\n", "\n", - " if indexes is None:\n", - " blend_table = table[np.random.choice(q, size=number_of_objects)]\n", - " else:\n", - " blend_table = table[indexes]\n", + " blend_table = table[np.random.choice(q, size=number_of_objects)]\n", " blend_table[\"ra\"] = 0.0\n", " blend_table[\"dec\"] = 0.0\n", - " if shifts is None:\n", - " x_peak, y_peak = _get_random_center_shift(number_of_objects, self.maxshift)\n", - " else:\n", - " x_peak, y_peak = shifts\n", + " x_peak, y_peak = _get_random_center_shift(number_of_objects, self.maxshift)\n", " blend_table[\"ra\"] += x_peak\n", " blend_table[\"dec\"] += y_peak\n", "\n", @@ -170,7 +161,6 @@ " return \"CatsimCatalog\", \"CosmosCatalog\"\n", "\n", " def __call__(self,table):\n", - " number_of_objects = np.random.randint(1, self.max_number + 1)\n", " (q_bright,) = np.where(table[\"ref_mag\"] <= 25.3)\n", " (q_dim,) = np.where((table[\"ref_mag\"] > 25.3) & (table[\"ref_mag\"] <= 28))\n", " \n",