obiwan.kenobi

The Monte Carlo code that adds fake galaxiesto images from the Legacy Survey

Classes

BuildStamp(tim[, gain, seed]) Does the drawing of simulated sources on a single exposure

Functions

build_simcat([Samp, brickwcs, meta]) Creates the simulated source catalog for a given brick (not CCD).
create_ith_simcat([d]) Write ‘simcat’ and ‘skipped_ids’ tables for a given sample of sources
create_metadata([kwargs]) fits_table with configuration-like params for the simulated sources
do_ith_cleanup([d]) Moves all obiwan+legacypipe outputs to a new directory stucture
do_one_chunk([d]) Runs the legacypipe/Tractor pipeline on images with simulated sources
dobash(cmd)
flag_nearest_neighbors(Samp[, radius_in_deg]) Returns Sample indices to keep (have > dist separations) and indices to skip
get_checkpoint_fn(outdir, brick, rowstart)
get_e1_e2(q, beta) Given minor to major axis ratio (q) and postion angle (beta), Returns e1,e2 tuple
get_ellip(q) Given minor to major axis ratio (q) Returns ellipticity
get_fnsuffix(**kwargs)
get_parser() return parser object, tells it what options to look for options can come from a list of strings or command line
get_runbrick_setup(**kwargs) Convert runbrick.py cmd line options into **kwargs for run_brick()
get_sample(objtype, brick, randoms_db[, …]) Gets all simulated randoms for a brick from PSQl db, and applies all relevant cuts
get_skip_ids(decals_sim_dir, brickname, objtype)
get_srcimg_invvar(stamp_ivar, img_ivar) stamp_ivar, img_ivar – galsim Image objects
imshow_stamp(stamp[, fn, galsimobj])
ivar_for_galaxy(gal, nano2e) Adds gaussian noise to perfect source
ivar_to_var(ivar[, nano2e, camera])
main([args]) Main routine which parses the optional inputs.
noise_for_galaxy(gal, nano2e) Returns numpy array of noise in Img count units for gal in image cnt units
plot_radial_profs(fn, profs)
ptime(text, t0) Timer
read_dict(fn)
saturation_e(camera)
write_dict(fn, d) d – dictionary
class obiwan.kenobi.BuildStamp(tim, gain=4.0, seed=0)[source]

Does the drawing of simulated sources on a single exposure

Parameters:
  • tim – Tractor Image Object for a specific CCD
  • gain – gain of the CCD
band

g,r,z

gsparams

galsim object that configures how accurate simulated source will be

gsdeviate

galsim object that configures its random number generator

wcs

WCS from tim

psf

psf from tim

galsim_wcs

wcs repackaged into galsim compatible object

zpscale

conversion factor ‘nanomaggies’ to ‘ADU’

nano2e

conversion factor ‘nanomaggies’ to ‘e-‘

convolve_galaxy(gal)[source]

Convolve the object with the PSF and then draw it.

elg(obj)[source]

Create an ELG (disk-like) galaxy.

lrg(obj)[source]

Create an LRG just like did for ELG

qso(obj)[source]

Create a QSO just like a star

setlocal(obj)[source]

Get the pixel positions, local wcs, local PSF.

star(obj)[source]

Render a star (PSF).

obiwan.kenobi.build_simcat(Samp=None, brickwcs=None, meta=None)[source]

Creates the simulated source catalog for a given brick (not CCD).

The WCS for the brick (not CCD) is used to convert ra,dec of source
to x,y pixel location in brickspace
Parameters:
  • Samp – fits_table for the properties of sources in the brick usually a subset of all sources in the brick determined by rowstart (rs)
  • brickwcs – WCS object for the brick
  • meta – ‘metacat’ table fits_table with configuration-like params for the simulated sources
Returns:

tuple of cat: skipping_ids:

obiwan.kenobi.create_ith_simcat(d=None)[source]

Write ‘simcat’ and ‘skipped_ids’ tables for a given sample of sources

Parameters:d – {‘Samp’: fits_table for the properties of sources in the brick ‘brickwcs’: WCS object for the brick ‘metacat’: fits_table with configuration params for the simulated sources }
Returns:Nothing, saves the ‘simcat’ and ‘skipped_ids’ tables Adds ‘simcat’ table to dict ‘d’
obiwan.kenobi.create_metadata(kwargs=None)[source]

fits_table with configuration-like params for the simulated sources

TODO: Should metacat table have a rowstart column? TODO: One metacat table per brick, instead of one per rs* directory?

Parameters:kwargs – configuration-like params for the simulated sources {‘brickname’: which chunk of sky ‘objtype’: star,elg,lrg,qso ‘nobj’: number of simulated sources for this run }
Returns:Nothing writes the ‘metacat’ fits_table to disk and stores it in the kwargs input arg
obiwan.kenobi.do_ith_cleanup(d=None)[source]

Moves all obiwan+legacypipe outputs to a new directory stucture

Uses rsync to move everthing, if all the rsync’s succeed then all the
original files and directories are removed
Parameters:d – dict with keys brickname, simcat_dir
obiwan.kenobi.do_one_chunk(d=None)[source]

Runs the legacypipe/Tractor pipeline on images with simulated sources

Parameters:d – {‘args’: obiwan.kenobi.py cmd line argparse.Namespace object ‘brickname’: chunk of sky ‘metacat’: fits_table configuration params for the simulated sources ‘simcat’: fits_table simulated source catalog for a given brick (not CCD).

Note

runb_brick() is ‘main’ for the legacypipe/Tractor pipeline

Returns:Nothing, but this func end ups writing out all the obiwan results
obiwan.kenobi.flag_nearest_neighbors(Samp, radius_in_deg=0.001388888888888889)[source]

Returns Sample indices to keep (have > dist separations) and indices to skip

Returns:keep,skip: indices of Samp to keep and skip
Return type:tuple
obiwan.kenobi.get_e1_e2(q, beta)[source]

Given minor to major axis ratio (q) and postion angle (beta), Returns e1,e2 tuple

obiwan.kenobi.get_ellip(q)[source]

Given minor to major axis ratio (q) Returns ellipticity

obiwan.kenobi.get_parser()[source]

return parser object, tells it what options to look for options can come from a list of strings or command line

obiwan.kenobi.get_runbrick_setup(**kwargs)[source]

Convert runbrick.py cmd line options into **kwargs for run_brick()

The command line options depend on the Data Release (e.g. the
legacypipe code version. The cmd line options associated with each DR get modified and repackaged into a dict in legacypipe.runbrick so this converter is required to call run_brick appropriately
Parameters:**kwargs – dict of the cmd line options to obiwan.kenobi.py
Returns:
dict to use when calling legacypipe.runbrick.run_brick like
run_brick(brickname, survey, **dict)
obiwan.kenobi.get_sample(objtype, brick, randoms_db, minid=None, randoms_from_fits='', do_skipids='no', outdir=None, dont_sort_sampleid=False)[source]

Gets all simulated randoms for a brick from PSQl db, and applies all relevant cuts

Parameters:
  • objtype – elg,lrg
  • brick
  • randoms_db – name of PSQL db for randoms, e.g. obiwan_elg_ra175
  • minid – None, unless do_more == yes then it is an integer for the randoms id to start from
  • randoms_from_fits – None or filename of fits_table to use for randoms
  • do_skipids – yes or no, rerunning on all skipped randoms?
  • outdir – None if do_skipids=’no’; otherwise path like $CSCRATCH/obiwan_out/elg_9deg2_ra175
  • dont_sort_sampleid – False to sort sample by id
Returns:

sample fits_table, seed

Return type:

tupe

obiwan.kenobi.get_srcimg_invvar(stamp_ivar, img_ivar)[source]

stamp_ivar, img_ivar – galsim Image objects

obiwan.kenobi.ivar_for_galaxy(gal, nano2e)[source]

Adds gaussian noise to perfect source

Parameters:
  • gal – galsim.Image() for source, UNITS: nanomags
  • nano2e – factor to convert to e- (gal * nano2e has units e-)
Returns:

nanomags

Return type:

galsim.Image() of invvar for the source, UNITS

obiwan.kenobi.main(args=None)[source]

Main routine which parses the optional inputs.

obiwan.kenobi.noise_for_galaxy(gal, nano2e)[source]

Returns numpy array of noise in Img count units for gal in image cnt units

obiwan.kenobi.ptime(text, t0)[source]

Timer

obiwan.kenobi.write_dict(fn, d)[source]

d – dictionary