btk.sampling_functions module

The sampling_functions modules contains everything related to the SamplingFunction class.

Contains classes of function for extracing information from catalog in blend batches.

class btk.sampling_functions.BasicSampling(max_number: int = 4, min_number: int = 1, stamp_size: float = 24.0, mag_name: str = 'i_ab', seed: int = 0)

Bases: SamplingFunction

Example of basic sampling function features.

Includes magnitude cut, restriction on the shape, shift randomization.

__call__(table: Table) Table

Samples galaxies from input catalog to make blend scene.

Then number of galaxies in a blend are drawn from a uniform distribution of one up to self.max_number.

Function always selects one bright galaxy that is less than 24 mag. The other galaxies are selected from a sample with mag<25.3 90% of the times and the remaining 10% with mag<28.

All galaxies must have semi-major axis is between 0.2 and 2 arcsec.

The centers are randomly distributed within 1/30 * sqrt(N) of the postage stamp size, where N is the number of objects in the blend. (keeps density constant)

Parameters:

table – CatSim-like catalog from which to sample galaxies.

Returns:

Table with entries corresponding to one blend.

__init__(max_number: int = 4, min_number: int = 1, stamp_size: float = 24.0, mag_name: str = 'i_ab', seed: int = 0)

Initializes the basic sampling function.

Parameters:
  • max_number – Defined in parent class.

  • min_number – Defined in parent class.

  • stamp_size – Size of the desired stamp.

  • seed – Seed to initialize randomness for reproducibility.

  • mag_name – Name of the magnitude column in the catalog for cuts.

class btk.sampling_functions.DefaultSampling(max_number: int = 2, min_number: int = 1, stamp_size: float = 24.0, max_shift: float | None = None, seed: int = 0, max_mag: float = 25.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Bases: SamplingFunction

Default sampling function used for producing blend catalogs.

__call__(table: Table) Table

Applies default sampling to catalog.

Returns an astropy table with entries corresponding to a blend centered close to postage stamp center.

Number of objects per blend is set at a random integer between self.min_number and self.max_number. The blend table is then randomly sampled entries from the table after magnitude selection cuts. The centers are randomly distributed within self.max_shift of the center of the postage stamp.

Here even though the galaxies are sampled from a CatSim catalog, their spatial location are not representative of real blends.

Parameters:

table – Table containing entries corresponding to galaxies from which to sample.

Returns:

Astropy.table with entries corresponding to one blend.

__init__(max_number: int = 2, min_number: int = 1, stamp_size: float = 24.0, max_shift: float | None = None, seed: int = 0, max_mag: float = 25.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Initializes default sampling function.

Parameters:
  • max_number – Defined in parent class

  • min_number – Defined in parent class

  • stamp_size – Size of the desired stamp.

  • max_shift – Magnitude of maximum value of shift. If None then it is set as one-tenth the stamp size. (in arcseconds)

  • seed – Seed to initialize randomness for reproducibility.

  • min_mag – Minimum magnitude allowed in samples

  • max_mag – Maximum magnitude allowed in samples.

  • mag_name – Name of the magnitude column in the catalog.

class btk.sampling_functions.DefaultSamplingShear(max_number: int = 2, min_number: int = 1, stamp_size: float = 24.0, max_shift: float | None = None, seed=0, shear: Tuple[float, float] = (0.0, 0.0))

Bases: DefaultSampling

Same as DefaultSampling sampling function but includes shear.

__call__(table: Table, **kwargs) Table

Same as corresponding function for DefaultSampling but adds shear to output tables.

__init__(max_number: int = 2, min_number: int = 1, stamp_size: float = 24.0, max_shift: float | None = None, seed=0, shear: Tuple[float, float] = (0.0, 0.0))

Initializes default sampling function with shear.

Parameters:
  • max_number – Defined in parent class.

  • min_number – Defined in parent class.

  • stamp_size – Defined in parent class.

  • max_shift – Defined in parent class.

  • seed – Defined in parent class.

  • shear – Constant (g1,g2) shear to apply to every galaxy.

class btk.sampling_functions.DensitySampling(max_number: int = 40, min_number: int = 0, density: float = 185, stamp_size: float = 24.0, max_shift: float | None = None, seed: int = 0, max_mag: float = 27.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Bases: SamplingFunction

Sampling function that produces galaxy field with a specified density.

__call__(table: Table) Table

Applies default sampling to catalog.

Returns an astropy table with entries corresponding to a blend centered close to postage stamp center.

Number of objects per blend is set at a random integer between self.min_number and self.max_number. The blend table is then randomly sampled entries from the table after magnitude selection cuts. The centers are randomly distributed within self.max_shift of the center of the postage stamp.

Here even though the galaxies are sampled from a CatSim catalog, their spatial location are not representative of real blends.

Parameters:

table – Table containing entries corresponding to galaxies from which to sample.

Returns:

Astropy.table with entries corresponding to one blend.

__init__(max_number: int = 40, min_number: int = 0, density: float = 185, stamp_size: float = 24.0, max_shift: float | None = None, seed: int = 0, max_mag: float = 27.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Initializes default sampling function.

Parameters:
  • max_number – Defined in parent class

  • min_number – Defined in parent class

  • density – Density of galaxies, default corresponds to 27.3 i-band magnitude cut in CATSIM catalog. (in counts / sq. arcmin)

  • stamp_size – Size of the desired stamp (in arcseconds)

  • max_shift – Magnitude of maximum value of shift. If None, then centroids can fall anywhere within the image. (in arcseconds)

  • seed – Seed to initialize randomness for reproducibility.

  • min_mag – Minimum magnitude allowed in samples

  • max_mag – Maximum magnitude allowed in samples.

  • mag_name – Name of the magnitude column in the catalog.

class btk.sampling_functions.FriendsOfFriendsSampling(max_number: int = 10, min_number: int = 2, link_distance: int = 2.5, stamp_size: float = 24.0, seed: int = 0, min_mag: float = -inf, max_mag: float = 25.3, mag_name: str = 'i_ab')

Bases: SamplingFunction

Randomly selects galaxies using Friends Of Friends clustering algorithm.

Friends of friends clustering algorithm assigns a group of object same index if one can each member of the group is within link_distance of any other member in the group. This sampling function explicitly uses the spatial information in the input catalog to generate scenes of galaxies. However, blends might not always be returned as a result if the provided link_distance is too small.

__call__(table: Table)

Samples galaxies from input catalog to make scene.

We assume the input catalog has ra and dec in degrees, like CATSIM does.

__init__(max_number: int = 10, min_number: int = 2, link_distance: int = 2.5, stamp_size: float = 24.0, seed: int = 0, min_mag: float = -inf, max_mag: float = 25.3, mag_name: str = 'i_ab')

Initializes the FriendsOfFriendsSampling sampling function.

Parameters:
  • max_number – Defined in parent class

  • min_number – Defined in parent class

  • link_distance – Minimum linkage distance to form a group (arcsec).

  • stamp_size – Size of the desired stamp (arcsec).

  • seed – Seed to initialize randomness for reproducibility.

  • min_mag – Minimum magnitude allowed in samples

  • max_mag – Maximum magnitude allowed in samples.

  • mag_name – Name of the magnitude column in the catalog.

class btk.sampling_functions.PairSampling(stamp_size: float = 24.0, max_shift: float | None = None, mag_name: str = 'i_ab', seed: int = 0, bright_cut: float = 25.3, dim_cut: float = 28.0)

Bases: SamplingFunction

Sampling function for pairs of galaxies. Picks one centered bright galaxy and second dim.

The bright galaxy is centered at the center of the stamp and the dim galaxy is shifted. The bright galaxy is chosen with magnitude less than bright_cut and the dim galaxy is chosen with magnitude cut larger than bright_cut and less than dim_cut. The cuts can be customized by the user at initialization.

__call__(table: Table)

Samples galaxies from input catalog to make blend scene.

__init__(stamp_size: float = 24.0, max_shift: float | None = None, mag_name: str = 'i_ab', seed: int = 0, bright_cut: float = 25.3, dim_cut: float = 28.0)

Initializes the PairSampling function.

Parameters:
  • stamp_size – Size of the desired stamp (in arcseconds).

  • max_shift – Maximum value of shift from center. If None then its set as one-tenth the stamp size (in arcseconds).

  • mag_name – Name of the magnitude column in the catalog to be used.

  • seed – See parent class.

  • bright_cut – Magnitude cut for bright galaxy. (Default: 25.3)

  • dim_cut – Magnitude cut for dim galaxy. (Default: 28.0)

class btk.sampling_functions.RandomSquareSampling(max_number: int = 2, stamp_size: float = 24.0, seed: int = 0, max_mag: float = 25.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Bases: SamplingFunction

Randomly selects galaxies in square region of the input catalog.

This sampling function explicitly uses the spatial information in the input catalog to generate scenes of galaxies. However, blends might not always be returned as a result.

__call__(table: Table)

Samples galaxies from input catalog to make scene.

We assume the input catalog has ra and dec in degrees, like CATSIM does.

__init__(max_number: int = 2, stamp_size: float = 24.0, seed: int = 0, max_mag: float = 25.3, min_mag: float = -inf, mag_name: str = 'i_ab')

Initializes the RandomSquareSampling sampling function.

Parameters:
  • max_number – Defined in parent class

  • stamp_size – Size of the desired stamp (arcsec).

  • seed – Seed to initialize randomness for reproducibility.

  • min_mag – Minimum magnitude allowed in samples

  • max_mag – Maximum magnitude allowed in samples.

  • mag_name – Name of the magnitude column in the catalog.

class btk.sampling_functions.SamplingFunction(max_number: int, min_number: int = 1, seed=0)

Bases: ABC

Class representing sampling functions to sample input catalog from which to draw blends.

The object can be called to return an astropy table with entries corresponding to the galaxies chosen for the blend.

abstract __call__(table) Table

Outputs a sample from the given astropy table.

__init__(max_number: int, min_number: int = 1, seed=0)

Initializes the SamplingFunction.

Parameters:
  • max_number – maximum number of catalog entries returned from sample.

  • min_number – minimum number of catalog entries returned from sample. (Default: 1)

  • seed – Seed to initialize randomness for reproducibility. (Default: btk.DEFAULT_SEED)