“Real” Galaxies

Individual Real Galaxies

The RealGalaxy class uses images of galaxies from real astrophysical data (e.g. the Hubble Space Telescope), along with a PSF model of the optical properties of the telescope that took these images, to simulate new galaxy images with a different (must be larger) telescope PSF. A description of the simulation method can be found in Section 5 of Mandelbaum et al. (2012; MNRAS, 540, 1518), although note that the details of the implementation in Section 7 of that work are not relevant to the more recent software used here.

The RealGalaxyCatalog class stores all required information about a real galaxy simulation training sample and accompanying PSF model. This modelling requires external data for the galaxy images and PSF models, which is read into a RealGalaxyCatalog object from FITS files. An example catalog of 100 real galaxies is in the repository itself at

GalSim/examples/data/real_galaxy_catalog_23.5_example.fits

For access to larger catalogs of objects, see Downloading the COSMOS Catalog below.

class galsim.RealGalaxy(real_galaxy_catalog, index=None, id=None, random=False, rng=None, x_interpolant=None, k_interpolant=None, flux=None, flux_rescale=None, pad_factor=4, noise_pad_size=0, area_norm=1.0, gsparams=None, logger=None)[source]

Bases: GSObject

A class describing real galaxies from some training dataset. Its underlying implementation uses a Convolution instance of an InterpolatedImage (for the observed galaxy) with a Deconvolution of another InterpolatedImage (for the PSF).

This class uses a catalog describing galaxies in some training data (for more details, see the RealGalaxyCatalog documentation) to read in data about realistic galaxies that can be used for simulations based on those galaxies. Also included in the class is additional information that might be needed to make or interpret the simulations, e.g., the noise properties of the training data. Users who wish to draw RealGalaxies that have well-defined flux scalings in various passbands, and/or parametric representations, should use the COSMOSGalaxy class.

Because RealGalaxy involves a Deconvolution, method = 'phot' is unavailable for the GSObject.drawImage function, and it is essential that users convolve each RealGalaxy with a PSF that is at least as large as the original HST PSF (stored as an attribute) before rendering any images. This is necessary to eliminate noise that was amplified due to deconvolution of the HST PSF.

Example:

>>> real_galaxy = galsim.RealGalaxy(real_galaxy_catalog, index=None, id=None, random=False,
...                                 rng=None, x_interpolant=None, k_interpolant=None,
...                                 flux=None, pad_factor=4, noise_pad_size=0,
...                                 gsparams=None)

This initializes real_galaxy with three InterpolatedImage objects (one for the deconvolved galaxy, and saved versions of the original HST image and PSF). Note that there are multiple keywords for choosing a galaxy; exactly one must be set.

Note that tests suggest that for optimal balance between accuracy and speed, k_interpolant and pad_factor should be kept at their default values. The user should be aware that significant inaccuracy can result from using other combinations of these parameters; more details can be found in http://arxiv.org/abs/1401.2636, especially table 1, and in comment https://github.com/GalSim-developers/GalSim/issues/389#issuecomment-26166621 and the following comments.

If you don’t set a flux, the flux of the returned object will be the flux of the original HST data, scaled to correspond to a 1 second HST exposure (though see the area_norm parameter below, and also caveats related to using the flux parameter). If you want a flux appropriate for a longer exposure, or for a telescope with a different collecting area than HST, you can either renormalize the object with the flux_rescale parameter, or by using the exptime and area parameters to GSObject.drawImage.

Note that RealGalaxy objects use arcsec for the units of their linear dimension. If you are using a different unit for other things (the PSF, WCS, etc.), then you should dilate the resulting object with gal.dilate(galsim.arcsec / scale_unit).

Parameters:
  • real_galaxy_catalog – A RealGalaxyCatalog object with basic information about where to find the data, etc.

  • index – Index of the desired galaxy in the catalog. [One of index, id, or random is required.]

  • id – Object ID for the desired galaxy in the catalog. [One of index, id, or random is required.]

  • random – If True, then select a random galaxy from the catalog. If the catalog has a ‘weight’ associated with it to allow for correction of selection effects in which galaxies were included, the ‘weight’ factor is used to remove those selection effects rather than selecting a completely random object. [One of index, id, or random is required.]

  • rng – A random number generator to use for selecting a random galaxy (may be any kind of BaseDeviate or None) and to use in generating any noise field when padding. [default: None]

  • x_interpolant – Either an Interpolant instance or a string indicating which real-space interpolant should be used. Options are ‘nearest’, ‘sinc’, ‘linear’, ‘cubic’, ‘quintic’, or ‘lanczosN’ where N should be the integer order to use. [default: galsim.Quintic()]

  • k_interpolant – Either an Interpolant instance or a string indicating which k-space interpolant should be used. Options are ‘nearest’, ‘sinc’, ‘linear’, ‘cubic’, ‘quintic’, or ‘lanczosN’ where N should be the integer order to use. We strongly recommend leaving this parameter at its default value; see text above for details. [default: galsim.Quintic()]

  • flux – Total flux, if None then original flux in image is adopted without change. Note that, technically, this parameter sets the flux of the postage stamp image and not the flux of the contained galaxy. These two values will be strongly correlated when the signal-to- noise ratio of the galaxy is large, but may be considerably different if the flux of the galaxy is small with respect to the noise variations in the postage stamp. To avoid complications with faint galaxies, consider using the flux_rescale parameter. [default: None]

  • flux_rescale – Flux rescaling factor; if None, then no rescaling is done. Either flux or flux_rescale may be set, but not both. [default: None]

  • pad_factor – Factor by which to pad the Image when creating the InterpolatedImage. We strongly recommend leaving this parameter at its default value; see text above for details. [default: 4]

  • noise_pad_size – If provided, the image will be padded out to this size (in arcsec) with the noise specified in the real galaxy catalog. This is important if you are planning to whiten the resulting image. You should make sure that the padded image is larger than the postage stamp onto which you are drawing this object. [default: None]

  • area_norm – Area in cm^2 by which to normalize the flux of the returned object. When area_norm=1 (the default), drawing with GSObject.drawImage keywords exptime=1 and area=1 will simulate an image with the appropriate number of counts for a 1 second exposure with the original telescope/camera (e.g., with HST when using the COSMOS catalog). If you would rather explicitly specify the collecting area of the telescope when using GSObject.drawImage with a RealGalaxy, then you should set area_norm equal to the collecting area of the source catalog telescope when creating the RealGalaxy (e.g., area_norm=45238.93416 for HST). [default: 1]

  • gsparams – An optional GSParams argument. [default: None]

  • logger – A logger object for output of progress statements if the user wants them. [default: None]

classmethod makeFromImage(image, PSF, xi, **kwargs)[source]

Create a RealGalaxy directly from image, PSF, and noise description.

Parameters:
  • imageImage of the galaxy you want to simulate.

  • PSFGSObject representing the PSF of the galaxy image. Note that this PSF should include the response of the pixel convolution.

  • xiBaseCorrelatedNoise object characterizing the noise correlations in the input image.

withGSParams(gsparams=None, **kwargs)[source]

Create a version of the current object with the given GSParams.

You may either provide a GSParams instance:

>>> gsparams = galsim.GSParams(folding_threshold=1.e-4, maxk_threshold=1.e-4)
>>> obj = obj.withGSParams(gsparams)

or one or more named parameters as keyword arguments:

>>> obj = obj.withGSParams(folding_threshold=1.e-4, maxk_threshold=1.e-4)

Note

The latter style will leave all non-named parameters at their current values. It only updates the named parameters to the given values.

class galsim.RealGalaxyCatalog(file_name=None, sample=None, dir=None, preload=False, logger=None)[source]

Class containing a catalog with information about real galaxy training data.

The RealGalaxyCatalog class reads in and stores information about a specific training sample of realistic galaxies. We assume that all files containing the images (galaxies and PSFs) live in one directory; they could be individual files, or multiple HDUs of the same file. Currently there is no functionality that lets this be a FITS data cube, because we assume that the object postage stamps will in general need to be different sizes depending on the galaxy size.

Note that when simulating galaxies based on HST but using either realistic or parametric galaxy models, the COSMOSCatalog class may be more useful. It allows the imposition of selection criteria and other subtleties that are more difficult to impose with RealGalaxyCatalog.

While you could create your own catalog to use with this class, the typical use cases would be to use one of the catalogs that we have created and distributed. There are three such catalogs currently, which can be use with one of the following initializations:

  1. A small example catalog is distributed with the GalSim distribution. This catalog only has 100 galaxies, so it is not terribly useful as a representative galaxy population. But for simplistic use cases, it might be sufficient. We use it for our unit tests and in some of the demo scripts (demo6, demo10, and demo11). To use this catalog, you would initialize with:

    >>> rgc = galsim.RealGalaxyCatalog('real_galaxy_catalog_23.5_example.fits',
                                       dir='path/to/GalSim/examples/data')
    
  2. There are two larger catalogs based on HST observations of the COSMOS field with around 26,000 and 56,000 galaxies each with a limiting magnitude of F814W=23.5. (The former is a subset of the latter.) For information about how to download these catalogs, see the RealGalaxy Data Download Page on the GalSim Wiki:

    https://github.com/GalSim-developers/GalSim/wiki/RealGalaxy%20Data

    Be warned that the catalogs are quite large. The larger one is around 11 GB after unpacking the tarball. To use one of these catalogs, you would initialize with:

    >>> rgc = galsim.RealGalaxyCatalog('real_galaxy_catalog_23.5.fits',
                                       dir='path/to/download/directory')
    
  3. There is a catalog containing a random subsample of the HST COSMOS images with a limiting magnitude of F814W=25.2. More information about downloading these catalogs can be found on the RealGalaxy Data Download page linked above.

  4. Finally, we provide a program that will download the large COSMOS sample for you and put it in the $PREFIX/share/galsim directory of your installation path. The program is:

    galsim_download_cosmos
    

    which gets installed in the $PREFIX/bin directory when you install GalSim. If you use this program to download the COSMOS catalog, then you can use it with:

    >>> rgc = galsim.RealGalaxyCatalog()
    

    GalSim knows the location of the installation share directory, so it will automatically look for it there.

Parameters:
  • file_name – The file containing the catalog. [default: None, which will look for the F814W<25.2 COSMOS catalog in $PREFIX/share/galsim. It will raise an exception if the catalog is not there telling you to run galsim_download_cosmos.]

  • sample – A keyword argument that can be used to specify the sample to use, i.e., “23.5” or “25.2”. At most one of file_name and sample should be specified. [default: None, which results in the same default as file_name=None.]

  • dir – The directory containing the catalog, image, and noise files, or symlinks to them. [default: None]

  • preload – Whether to preload the header information. If preload=True, the bulk of the I/O time is in the constructor. If preload=False, there is approximately the same total I/O time (assuming you eventually use most of the image files referenced in the catalog), but it is spread over the various calls to getGalImage and getPSFImage. [default: False]

  • logger – An optional logger object to log progress. [default: None]

getBandpass()[source]

Returns a Bandpass object for the catalog.

getGalImage(i)[source]

Returns the galaxy at index i as an Image object.

getIndexForID(id)[source]

Internal function to find which index number corresponds to the value ID in the ident field.

getNoise(i, rng=None, gsparams=None)[source]

Returns the noise correlation function at index i as a BaseCorrelatedNoise object.

getNoiseProperties(i)[source]

Returns the components needed to make the noise correlation function at index i. Specifically, the noise image (or None), the pixel_scale, and the noise variance, as a tuple (im, scale, var).

getPSF(i, x_interpolant=None, k_interpolant=None, gsparams=None)[source]

Returns the PSF at index i as a GSObject.

getPSFImage(i)[source]

Returns the PSF at index i as an Image object.

preload()[source]

Preload the files into memory.

There are memory implications to this, so we don’t do this by default. However, it can be a big speedup if memory isn’t an issue.

Realistic Scene

The COSMOSCatalog class is also based on the above RealGalaxyCatalog, and has functionality for defining a “sky scene”, i.e., a galaxy sample with reasonable properties that can then be placed throughout a large image. It can simulate either RealGalaxy objects using the HST images or parametric models based on those images.

Note

Currently, this only includes routines for making a COSMOS-based galaxy sample, but it could be expanded to include star samples as well.

class galsim.COSMOSCatalog(file_name=None, sample=None, dir=None, **kwargs)[source]

A class representing a random subsample of galaxies from the COSMOS sample with F814W<25.2 (default), or alternatively the entire sample with F814W<23.5.

Depending on the keyword arguments, particularly use_real, the catalog may be able to generate real galaxies, parametric galaxies, or both. To use this with either type of galaxies, you need to get the COSMOS datasets in the format that GalSim recognizes; see

https://github.com/GalSim-developers/GalSim/wiki/RealGalaxy-Data

option (1) for more information. Note that if you want to make real galaxies you need to download and store the full tarball with all galaxy images, whereas if you want to make parametric galaxies you only need the catalog real_galaxy_catalog_25.2_fits.fits (and the selection file real_galaxy_catalog_25.2_selection.fits if you want to place cuts on the postage stamp quality) and can delete the galaxy and PSF image files.

Finally, we provide a program that will download the large COSMOS sample for you and put it in the $PREFIX/share/galsim directory of your installation path. The program is:

galsim_download_cosmos

which gets installed in the $PREFIX/bin directory when you install GalSim. If you use this program to download the COSMOS catalog, then you can use it with:

cat = galsim.COSMOSCatalog()

GalSim knows the location of the installation share directory, so it will automatically look for it there.

In addition to the option of specifying catalog names, this class also accepts a keyword argument sample that can be used to switch between the samples with limiting magnitudes of 23.5 and 25.2.

After getting the catalogs, there is a method makeGalaxy() that can make a GSObject corresponding to any chosen galaxy in the catalog (whether real or parametric). See GalaxySample.makeGalaxy for more information. As an interesting application and example of the usage of these routines, consider the following code:

>>> im_size = 64
>>> pix_scale = 0.05
>>> bp_file = os.path.join(galsim.meta_data.share_dir, 'wfc_F814W.dat.gz')
>>> bandpass = galsim.Bandpass(bp_file, wave_type='ang').thin().withZeropoint(25.94)
>>> cosmos_cat = galsim.COSMOSCatalog()
>>> psf = galsim.OpticalPSF(diam=2.4, lam=1000.) # bigger than HST F814W PSF.
>>> indices = np.arange(10)
>>> real_gal_list = cosmos_cat.makeGalaxy(indices, gal_type='real',
...                                       noise_pad_size=im_size*pix_scale)
>>> param_gal_list = cosmos_cat.makeGalaxy(indices, gal_type='parametric', chromatic=True)
>>> for ind in indices:
>>>     real_gal = galsim.Convolve(real_gal_list[ind], psf)
>>>     param_gal = galsim.Convolve(param_gal_list[ind], psf)
>>>     im_real = galsim.Image(im_size, im_size)
>>>     im_param = galsim.Image(im_size, im_size)
>>>     real_gal.drawImage(image=im_real, scale=pix_scale)
>>>     param_gal.drawImage(bandpass, image=im_param, scale=pix_scale)
>>>     im_real.write('im_real_'+str(ind)+'.fits')
>>>     im_param.write('im_param_'+str(ind)+'.fits')

This code snippet will draw images of the first 10 entries in the COSMOS catalog, at slightly lower resolution than in COSMOS, with a real image and its parametric representation for each of those objects.

When using the ‘real’ rather than ‘parametric’ option, please read the documentation for the RealGalaxy class for additional caveats about the available drawing methods and the need to convolve with a suitable PSF.

Parameters:
  • file_name – The file containing the catalog. [default: None, which will look for the F814W<25.2 COSMOS catalog in $PREFIX/share/galsim. It will raise an exception if the catalog is not there telling you to run galsim_download_cosmos.]

  • sample – A keyword argument that can be used to specify the sample to use, i.e., “23.5” or “25.2”. At most one of file_name and sample should be specified. [default: None, which results in the same default as file_name=None.]

  • dir – The directory with the catalog file and, if making realistic galaxies, the image and noise files (or symlinks to them). [default: None, which will look in $PREFIX/share/galsim.]

  • preload – Keyword that is only used for real galaxies, not parametric ones, to choose whether to preload the header information. If preload=True, the bulk of the I/O time is in the constructor. If preload=False, there is approximately the same total I/O time (assuming you eventually use most of the image files referenced in the catalog), but it is spread over the calls to makeGalaxy(). [default: False]

  • use_real – Enable the use of realistic galaxies? [default: True] If this parameter is False, then makeGalaxy(gal_type='real') will not be allowed, and there will be a (modest) decrease in RAM and time spent on I/O when initializing the COSMOSCatalog. If the real catalog is not available for some reason, it will still be possible to make parametric images.

  • exclusion_level

    Level of additional cuts to make on the galaxies based on the quality of postage stamp definition and/or parametric fit quality [beyond the minimal cuts imposed when making the catalog - see Mandelbaum et al. (2012, MNRAS, 420, 1518) for details]. Options:

    • ”none”: No cuts.

    • ”bad_stamp”: Apply cuts to eliminate galaxies that have failures in postage stamp definition. These cuts may also eliminate a small subset of the good postage stamps as well.

    • ”bad_fits”: Apply cuts to eliminate galaxies that have failures in the parametric fits. These cuts may also eliminate a small subset of the good parametric fits as well.

    • ”marginal”: Apply the above cuts, plus ones that eliminate some more marginal cases.

    [default: “marginal”]

  • min_hlr – Exclude galaxies whose fitted half-light radius is smaller than this value (in arcsec). [default: 0, meaning no limit]

  • max_hlr – Exclude galaxies whose fitted half-light radius is larger than this value (in arcsec). [default: 0, meaning no limit]

  • min_flux – Exclude galaxies whose fitted flux is smaller than this value. [default: 0, meaning no limit]

  • max_flux – Exclude galaxies whose fitted flux is larger than this value. [default: 0, meaning no limit]

  • exptime

    The exposure time (in seconds) to assume when creating galaxies. .. note:

    The processed COSMOS ACS/HST science images have units of
    counts/second; i.e. they have an effective exposure time of 1
    second in terms of their flux levels. The default value
    corresponds to a 1 second exposure on HST, which will match
    these processed images.
    

    [default: 1]

  • area – The effective collecting area (in cm^2) to assume when creating galaxies. [default: None, which means to use the original HST collecting area = pi/4 * 240**2 * (1.-0.33**2)]

After construction, the following attributes are available:

Attributes:

nobjects – The number of objects in the catalog

class galsim.GalaxySample(file_name, dir=None, preload=False, orig_exptime=1.0, orig_area=1.0, use_real=True, exclusion_level='marginal', min_hlr=0, max_hlr=0.0, min_flux=0.0, max_flux=0.0, cut_ratio=0.8, sn_limit=10.0, min_mask_dist=11, exptime=None, area=None, _use_sample=None)[source]

A class representing a random subsample of galaxies from an arbitrary deep survey.

Depending on the keyword arguments, particularly use_real, a GalaxySample may be able to generate real galaxies, parametric galaxies, or both.

The original version of this functionality is now in the subclass COSMOSCatalog, which specializes to HST observations of the COSMOS field. GalaxySample is a generalization of that, which works for arbitrary data sets, although the user is responsible for building the appropriate input files to use with it.

Unlike COSMOSCatalog, which has easy options for picking out one of the two galaxy subsets that are available for download using galsim_download_cosmos, for this class you need to manually specify the file name.

>>> sample = galsim.GalaxySample(file_name)

Other than this difference, the functionality of this class is the same as COSMOSCatalog. See the documentation of that function for more detail.

Parameters:
  • file_name – The file containing the catalog.

  • dir – The directory with the catalog file and, if making realistic galaxies, the image and noise files (or symlinks to them). [default: None, which will look in $PREFIX/share/galsim.]

  • preload – Keyword that is only used for real galaxies, not parametric ones, to choose whether to preload the header information. If preload=True, the bulk of the I/O time is in the constructor. If preload=False, there is approximately the same total I/O time (assuming you eventually use most of the image files referenced in the catalog), but it is spread over the calls to makeGalaxy(). [default: False]

  • orig_exptime – The exposure time (in seconds) of the original observations. [default: 1]

  • orig_area – The effective collecting area (in cm^2) of the original observations. [default: 1]

  • use_real – Enable the use of realistic galaxies? [default: True] If this parameter is False, then makeGalaxy(gal_type='real') will not be allowed, and there will be a (modest) decrease in RAM and time spent on I/O when initializing the COSMOSCatalog. If the real catalog is not available for some reason, it will still be possible to make parametric images.

  • exclusion_level

    Level of additional cuts to make on the galaxies based on the quality of postage stamp definition and/or parametric fit quality [beyond the minimal cuts imposed when making the catalog - see Mandelbaum et al. (2012, MNRAS, 420, 1518) for details]. Options:

    • ”none”: No cuts.

    • ”bad_stamp”: Apply cuts to eliminate galaxies that have failures in postage stamp definition. These cuts may also eliminate a small subset of the good postage stamps as well.

    • ”bad_fits”: Apply cuts to eliminate galaxies that have failures in the parametric fits. These cuts may also eliminate a small subset of the good parametric fits as well.

    • ”marginal”: Apply the above cuts, plus ones that eliminate some more marginal cases.

    Use of “bad_stamp” or “marginal” requires a CATALOG_selection.fits file (where CATALOG is file_name without the “.fits” extension). [default: “none”]

  • min_hlr – Exclude galaxies whose fitted half-light radius is smaller than this value (in arcsec). [default: 0, meaning no limit]

  • max_hlr – Exclude galaxies whose fitted half-light radius is larger than this value (in arcsec). [default: 0, meaning no limit]

  • min_flux – Exclude galaxies whose fitted flux is smaller than this value. [default: 0, meaning no limit]

  • max_flux – Exclude galaxies whose fitted flux is larger than this value. [default: 0, meaning no limit]

  • cut_ratio – For the “bad_stamp” exclusions, cut out any stamps with average adjacent pixels larger than this fraction of the peak pixel count. [default: 0.8]

  • sn_limit – For the “bad_stamp” exclusions, cut out any stamps with estimated S/N for an elliptical Gaussian less than this limit. [default: 10.]

  • min_mask_dist – For the “bad_stamp” exclusions, remove any stamps that have some masked pixels closer to the center than this minimum distance (in pixels). [default: 10]

  • exptime – The exposure time (in seconds) to assume when creating galaxies. [default: None, which means to use orig_exptime]

  • area – The effective collecting area (in cm^2) to assume when creating galaxies. [default: None, which means to use orig_area]

After construction, the following attributes are available:

Attributes:

nobjects – The number of objects in the sample

canMakeReal()[source]

Is it permissible to call makeGalaxy with gal_type=’real’?

getParametricRecord(index)[source]

Get the parametric record for a given index

getRealParams(index)[source]

Get the parameters needed to make a RealGalaxy for a given index.

getValue(key, index)[source]

Get the value in the parametric catalog at the given key and index

makeGalaxy(index=None, gal_type=None, chromatic=False, noise_pad_size=5, deep=False, sersic_prec=0.05, rng=None, n_random=None, gsparams=None)[source]

Routine to construct one or more GSObject instances corresponding to the catalog entry with a particular index or indices.

The flux of the galaxy corresponds to a 1 second exposure time with the Hubble Space Telescope. Users who wish to simulate F814W images with a different telescope and an exposure time longer than 1 second should multiply by that exposure time, and by the square of the ratio of the effective diameter of their telescope compared to that of HST. (Effective diameter may differ from the actual diameter if there is significant obscuration.) See demo11.py for an example that explicitly takes this normalization into account.

Due to the adopted flux normalization, drawing into an image with the COSMOS bandpass, zeropoint of 25.94, and pixel scale should give the right pixel values to mimic the actual COSMOS science images. The COSMOS science images that we use are normalized to a count rate of 1 second, which is why there is no need to rescale to account for the COSMOS exposure time.

There is an option to make chromatic objects (chromatic=True); however, it is important to bear in mind that we do not actually have spatially-resolved color information for these galaxies, so this keyword can only be True if we are using parametric galaxies. Even then, we simply do the most arbitrary thing possible, which is to assign bulges an elliptical SED, disks a disk-like SED, and Sersic galaxies with intermediate values of n some intermediate SED. We assume that the photometric redshift is the correct redshift for these galaxies (which is a good assumption for COSMOS 30-band photo-z for these bright galaxies). For the given SED and redshift, we then normalize to give the right (observed) flux in F814W. Note that for a mock “deep” sample, the redshift distributions of the galaxies would be modified, which is not included here.

For this chromatic option, it is still the case that the output flux normalization is appropriate for the HST effective telescope diameter and a 1 second exposure time, so users who are simulating another scenario should account for this.

Note that the returned objects use arcsec for the units of their linear dimension. If you are using a different unit for other things (the PSF, WCS, etc.), then you should dilate the resulting object with gal.dilate(galsim.arcsec / scale_unit).

Parameters:
  • index – Index of the desired galaxy in the catalog for which a GSObject should be constructed. You may also provide a list or array of indices, in which case a list of objects is returned. If None, then a random galaxy (or more: see n_random kwarg) is chosen, correcting for catalog-level selection effects if weights are available. [default: None]

  • gal_type – Either ‘real’ or ‘parametric’. This determines which kind of galaxy model is made. [If catalog was loaded with use_real=False, then this defaults to ‘parametric’, and in fact ‘real’ is not allowed. If catalog was loaded with use_real=True, then this defaults to ‘real’.]

  • chromatic – Make this a chromatic object, or not? [default: False]

  • noise_pad_size – For realistic galaxies, the size of region to pad with noise, in arcsec. [default: 5, an arbitrary, but not completely ridiculous choice.]

  • deep – Modify fluxes and sizes of galaxies from the F814W<23.5 sample in order to roughly simulate an F814W<25 sample but with higher S/N, as in GREAT3? [default: False] Note that this keyword will be ignored (except for issuing a warning) if the input catalog already represents the F814W<25.2 sample.

  • sersic_prec – The desired precision on the Sersic index n in parametric galaxies. GalSim is significantly faster if it gets a smallish number of Sersic values, so it can cache some of the calculations and use them again the next time it gets a galaxy with the same index. If sersic_prec is 0.0, then use the exact value of index n from the catalog. But if it is >0, then round the index to that precision. [default: 0.05]

  • rng – A random number generator to use for selecting a random galaxy (may be any kind of BaseDeviate or None) and to use in generating any noise field when padding. [default: None]

  • n_random – The number of random galaxies to build, if ‘index’ is None. [default: 1]

  • gsparams – An optional GSParams argument. [default: None]

Returns:

Either a GSObject or a ChromaticObject depending on the value of chromatic, or a list of them if index is an iterable.

selectRandomIndex(n_random=1, rng=None, _n_rng_calls=False)[source]

Routine to select random indices out of the catalog. This routine does a weighted random selection with replacement (i.e., there is no guarantee of uniqueness of the selected indices). Weighting uses the weight factors available in the catalog, if any; these weights are typically meant to remove any selection effects in the catalog creation process.

Parameters:
  • n_random – Number of random indices to return. [default: 1]

  • rng – A random number generator to use for selecting a random galaxy (may be any kind of BaseDeviate or None). [default: None]

Returns:

A single index if n_random==1 or a NumPy array containing the randomly-selected indices if n_random>1.

Downloading the COSMOS Catalog

A set of ~56 000 real galaxy images with I<23.5, or another set of ~87 000 with I<25.2, with original PSFs, can be downloaded from Zenodo:

https://zenodo.org/record/3242143

The tar ball for the I<23.5 sample (COSMOS_23.5_training_sample.tar.gz) is roughly 4 GB and contains catalogs and images with a README. The tar ball for the I<25.2 sample (COSMOS_25.2_training_sample.tar.gz) is of similar size and format.

GalSim also comes with a script galsim_download_cosmos that downloads the I<23.5 sample. It works with both samples, with the I<25.2 sample being the default but with keyword arguments to choose between the two:

usage: galsim_download_cosmos [-h] [-v {0,1,2,3}] [-f] [-q] [-u] [--save]
                              [-d DIR] [-s {23.5,25.2}] [--nolink]

This program will download the COSMOS RealGalaxy catalog and images and place
them in the GalSim share directory so they can be used as the default files
for the RealGalaxyCatalog class. See https://github.com/GalSim-
developers/GalSim/wiki/RealGalaxy%20Data for more details about the files
being downloaded.

optional arguments:
  -h, --help            show this help message and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Integer verbosity level: min=0, max=3 [default=2]
  -f, --force           Force overwriting the current file if one exists
  -q, --quiet           Don't ask about re-downloading an existing file.
                        (implied by verbosity=0)
  -u, --unpack          Re-unpack the tar file if not downloading
  --save                Save the tarball after unpacking.
  -d DIR, --dir DIR     Install into an alternate directory and link from the
                        share/galsim directory
  -s {23.5,25.2}, --sample {23.5,25.2}
                        Flux limit for sample to download; either 23.5 or 25.2
  --nolink              Don't link to the alternate directory from
                        share/galsim

Note: The unpacked files total almost 6 GB in size!

Note

The galsim_download_cosmos program will put the downloaded files into a subdirectory of the galsim.meta_data.share_dir directory. (cf. Shared Data) This is normally convenient for access, since classes such as RealGalaxyCatalog and COSMOSCatalog will look in this directory automatically for you. However, if you reinstall GalSim, everything in this directory will be removed and overwritten. Therefore, we normally recommend using the -d DIR option to place the downloaded files into another location. E.g.:

galsim_download_cosmos -d ~/share

It will still be required to rerun this after reinstalling GalSim, but it will notice that you already have the files downloaded and merely update the symbolic link.

Instructions for how to download a copy of the GREAT3 data are found at

https://github.com/barnabytprowe/great3-public#how-to-get-the-data

HSC Postage Stamp Data

The HST postage stamp data from

http://adsabs.harvard.edu/abs/2017arXiv171000885M

which includes studies of the impact of blending on shear estimation in HSC, was released as part of the HSC survey’s second incremental data release. The sample is larger than the above, goes to the depth of COSMOS, and does not have nearby objects masked.

The links to download it and the instructions on its use are at

https://hsc-release.mtk.nao.ac.jp/doc/index.php/weak-lensing-simulation-catalog-pdr1/