fpfs.simutil#

class fpfs.simutil.CosmosCatalog(filename=None, max_mag=None, min_mag=None, max_hlr=None, min_hlr=None, gal_type='mixed')[source]#

Bases: object

make_catalog(rng, n)[source]#
class fpfs.simutil.LensTransform1(gamma1, gamma2, kappa)[source]#

Bases: object

transform(coords)[source]#

transform the center of pixels from lensed plane to pre-lensed plane :param coords: coordinates (x, y) of the pixel centers [arcsec]

class fpfs.simutil.Stamp(coords=None, nn=32, scale=0.2)[source]#

Bases: object

sample_galaxy(gal_obj)[source]#

Sample the surface density field of a galaxy at the grids This function only conduct sampling; PSF and pixel response are not included.

Parameters:

gal_obj (galsim) – Galsim galaxy object to sample on the grids

Returns:

outcome (ndarray) – 2D galaxy image on the grids

transform_grids(transform_obj)[source]#
fpfs.simutil.coord_distort_1(x, y, xref, yref, gamma1, gamma2, kappa=0.0, inverse=False)[source]#

Distorts coordinates by shear

Parameters:
  • x (ndarray) – input coordinates [x]

  • y (ndarray) – input coordinates [y]

  • xref (float) – reference point [x]

  • yref (float) – reference point [y]

  • gamma1 (float) – first component of shear distortion

  • gamma2 (float) – second component of shear distortion

  • kappa (float) – kappa distortion [default: 0]

  • inverse (bool) – if true, from source to lens; else, from lens to source

Returns:
  • x2 (ndarray) – distorted coordiantes [x]

  • y2 (ndarray) – distorted coordiantes [y]

fpfs.simutil.coord_rotate(x, y, xref, yref, theta)[source]#

Rotates coordinates by an angle theta (anticlockwise)

Parameters:
  • x (ndarray) – input coordinates [x]

  • y (ndarray) – input coordinates [y]

  • xref (float) – reference point [x]

  • yref (float) – reference point [y]

  • theta (float) – rotation angle [rads]

Returns:
  • x2 (ndarray) – rotated coordiantes [x]

  • y2 (ndarray) – rotated coordiantes [y]

fpfs.simutil.generate_cosmos_gal(record, trunc_ratio=5.0, gsparams=None)[source]#

Generates COSMOS galaxies; modified version of GalSim-developers/GalSim

Parameters:
  • record (ndarray) – one row of the COSMOS galaxy catalog

  • trunc_ratio (float) – truncation ratio

  • gsparams – An GSParams argument.

Returns:

gal – Galsim galaxy

fpfs.simutil.make_cosmo_sim(out_dir, psf_obj, gname, ind0, catname=None, ny=5000, nx=5000, rfrac=0.46, scale=0.168, do_write=True, return_array=False, magzero=27.0, rot_field=0.0, shear_value=0.02, nrot=4, rescale_min_max=None)[source]#

Makes cosmo-like blended galaxy image simulations.

Parameters:
  • out_dir (str) – output directory

  • psf_obj (PSF) – input PSF object of galsim

  • gname (str) – shear distortion setup

  • ind0 (int) – index of the simulation

  • catname (str) – input catalog Name [default: COSMOS 25.2 catalog]

  • ny (int) – number of galaxies in y direction [default: 5000]

  • nx (int) – number of galaxies in x direction [default: 5000]

  • rfrac (float) – fraction of radius to minimum between nx and ny

  • do_write (bool) – whether write output [default: True]

  • return_array (bool) – whether return galaxy array [default: False]

  • magzero (float) – magnitude zero point

  • rot_field (float) – additional rotational angle [in units of radians]

  • shear_value (float) – amplitude of the input shear

  • nrot (int) – number of rotation, optional

  • rescale_min_max (list|ndarray) – lower and upper bounds of galaxy size rescaling factor, optional

fpfs.simutil.make_exposure_stamp(sim_method, rng, magzero, psf_obj, scale, cat_input, ngalx, ngaly, ngrid, rot_field, g1, g2, nrot_per_gal, do_shift, buff=0, draw_method='auto')[source]#
fpfs.simutil.make_gal_ssbg(shear, psf, rng, r1, r0=20.0)[source]#

This function is for the simulation for source photon noise. It simulates an exponential object with moffat PSF, given a SNR [r0] and a source background noise ratio [r0].

Parameters:
  • shear (tuple) – [g1, g2]. The shear in each component

  • rng (randState) – The random number generator

  • r1 (float) – The source background noise variance ratio

  • r0 (float) – The SNR of galaxy

  • psf (galsim.Moffat) – a Moffat PSF

Returns:

img (ndarray) – noisy image array

fpfs.simutil.make_isolate_sim(ny, nx, psf_obj, gname, seed, catname=None, scale=0.168, magzero=27.0, rot_field=None, shear_value=0.02, ngrid=64, nrot_per_gal=4, max_mag=None, min_mag=None, max_hlr=None, min_hlr=None, gal_type='mixed', do_shift=False, npoints=30, sim_method='fft', buff=0, draw_method='auto')[source]#

Makes basic isolated galaxy image simulation.

Parameters:
  • ny (int) – number of pixels in y direction

  • nx (int) – number of pixels in y direction

  • psf_obj (PSF) – input PSF object of galsim

  • gname (str) – shear distortion setup

  • seed (int) – index of the simulation

  • catname (str) – input catalog name

  • scale (float) – pixel scale

  • magzero (float) – magnitude zero point [27 for HSC]

  • rot_field (list) – additional rotation angle

  • shear_value (float) – shear distortion amplitude

  • ngrid (int) – stampe size

  • nrot_per_gal (int) – number of rotations

  • max_mag (float) – maximum magnitude cut

  • min_mag (float) – minimum magnitude cut

  • max_hlr (float) – maximum half light radius cut [arcsec]

  • min_hlr (float) – minimum half light radius cut [arcsec]

  • gal_type (float) – galaxy morphology (mixed, sersic, or bulgedisk)

  • do_shift (bool) – whether do shfits

  • npoints (int) – number of random points when

  • sim_method (str) – galaxy tpye (“fft” or “mc”)

  • buff (int) – buff size (zero padding near boundaries)

fpfs.simutil.make_noise_sim(out_dir, infname, ind0, ny=6400, nx=6400, scale=0.168, do_write=True, return_array=False)[source]#

Makes pure noise for galaxy image simulation.

Parameters:
  • out_dir (str) – output directory

  • ind0 (int) – index of the simulation

  • ny (int) – number of pixels in y direction

  • nx (int) – number of pixels in x direction

  • do_write (bool) – whether write output [default: True]

  • return_array (bool) – whether return galaxy array [default: False]

fpfs.simutil.make_ringrot_radians(nord=8)[source]#

Generates rotation angle array for ring test

Parameters:

nord (int) – up to 1/2**nord*pi rotation

Returns:

rot_array (ndarray) – rotation array [in units of radians]

fpfs.simutil.read_cosmos_catalog(filename=None)[source]#
class fpfs.simutil.sim_test(shear, rng, scale=0.263, psf_fwhm=0.9, gal_hlr=0.5, ngrid=32)[source]#

Bases: object

make_image(noise, psf_noise=0.0, do_shift=False)[source]#

Generates a galaxy image

Parameters:
  • noise (float) – Noise for the image

  • psf_noise (float) – Noise for the PSF [defalut: 0.]

  • do_shift (bool) – whether shift the galaxy [default: False]

Returns:
  • im (ndarray) – galaxy image

  • psf_im (ndarray) – PSF image