API

obiwan.runbrick module

obiwan.kenobi module

Classes to extend legacypipe.

class obiwan.kenobi.BaseSimImage

Bases: object

Dumb class that extends get_tractor_image() for future multiple inheritance.

get_zpscale()

Return zpscale for image units to nanomaggies conversion.

class obiwan.kenobi.BaseSimStamp(tim, **attrs)

Bases: object

Draw model galaxies for a single image.

Parent class to be inherited from to build different galaxy models.

tim

Tractor image.

Type

tractor.Image

band

Image band.

Type

string

xcen

x center of the source in subimage pixel coordinates.

Type

float

ycen

y center of the source in subimage pixel coordinates.

Type

float

attrs

Other attributes.

Type

dict

Parameters
  • tim (tractor.Image) – Current tractor.Image.

  • attrs (dict) – Other attributes useful to define patches (e.g. nx, ny).

set_local(ra, dec)

Set local xcen, self.ycen coordinates.

Parameters
  • ra (float) – Right ascension (degree).

  • dec (float) – Declination (degree).

class obiwan.kenobi.BaseSimSurvey(*args, simcat=None, sim_stamp='tractor', add_sim_noise=False, image_eq_model=False, seed=0, kwargs_file=None, **kwargs)

Bases: object

Dumb class with Obiwan attributes for future multiple inheritance.

simcat

See below.

Type

SimCatalog

sim_stamp

See below.

Type

string

add_sim_noise

See below.

Type

string

image_eq_model

See below.

Type

bool

kwargs_file

See below.

Type

dict

rng

Random state, from seed`.

Type

numpy.random.RandomState

image_typemap

Mapping (camera,class) used by legacypipe.survey.LegacySurveyData.

Type

dict

survey_dir

Directory containing input imaging data.

Type

string

output_dir

Directory containing output catalogs.

Type

string

kwargs are to be passed on to legacypipe.survey.LegacySurveyData-inherited classes, other arguments are specific to BaseSimSurvey. Only survey_dir must be specified to obtain bricks through get_brick_by_name().

Parameters
  • simcat (SimCatalog, default=None) – Simulated source catalog for a given brick (not CCD).

  • sim_stamp (string, default='tractor') – Method to simulate objects, either ‘tractor’ (TractorSimStamp) or ‘galsim’ (GalSimStamp).

  • add_sim_noise (string, default=False) – Add noise from the simulated source to the image. Choices: [‘gaussian’,’poisson’].

  • image_eq_model (bool, default=False) – Wherever add a simulated source, replace both image and inverse variance of the image with that of the simulated source only.

  • seed (int, default=0) – For random number generators.

  • kwargs_file (dict, default=None) – Extra arguments to file paths (e.g. get_randoms_id.keys()).

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.

find_file(filetype, brick=None, output=False, stage=None, **kwargs)

Return the file name of a Legacy Survey file.

Parameters
  • filetype (string) – Type of file to find, including: - ‘randoms’: input random catalogues - ‘pickle’: pickle files - ‘checkpoint’: checkpoint files - ‘log’ : log files - ‘ps’ : ps (resources time series) catalogs - ‘tractor’: Tractor catalogs - ‘depth’: PSF depth maps - ‘galdepth’: canonical galaxy depth maps - ‘nexp’: number-of-exposure maps.

  • brick (string, defaut=None) – Brick name.

  • output (bool, default=False) – Whether we are about to write this file; will use output_dir as the base directory rather than survey_dir.

  • stage (string, default=None) – Stage, only used if filetype == 'pickle'.

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.find_file().

Returns

fn – Path to the specified file (whether or not it exists).

Return type

string

class obiwan.kenobi.BokSimImage(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.bok.

Extend BaseSimImage with legacypipe.bok.BokImage.

Note

Image unit is electrons/second (x exptime -> electrons).

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.CosmosSim(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimSurvey, legacypipe.runcosmos.

Extend BaseSimSurvey with a filter for cosmos CCDs.

Call with BaseSimSurvey arguments plus additional CosmosSurvey argument subset.

kwargs are to be passed on to legacypipe.survey.LegacySurveyData-inherited classes, other arguments are specific to BaseSimSurvey. Only survey_dir must be specified to obtain bricks through get_brick_by_name().

Parameters
  • simcat (SimCatalog, default=None) – Simulated source catalog for a given brick (not CCD).

  • sim_stamp (string, default='tractor') – Method to simulate objects, either ‘tractor’ (TractorSimStamp) or ‘galsim’ (GalSimStamp).

  • add_sim_noise (string, default=False) – Add noise from the simulated source to the image. Choices: [‘gaussian’,’poisson’].

  • image_eq_model (bool, default=False) – Wherever add a simulated source, replace both image and inverse variance of the image with that of the simulated source only.

  • seed (int, default=0) – For random number generators.

  • kwargs_file (dict, default=None) – Extra arguments to file paths (e.g. get_randoms_id.keys()).

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.

class obiwan.kenobi.DecamSim(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimSurvey, legacypipe.runs.

Extend BaseSimSurvey with a filter for DECam CCDs.

kwargs are to be passed on to legacypipe.survey.LegacySurveyData-inherited classes, other arguments are specific to BaseSimSurvey. Only survey_dir must be specified to obtain bricks through get_brick_by_name().

Parameters
  • simcat (SimCatalog, default=None) – Simulated source catalog for a given brick (not CCD).

  • sim_stamp (string, default='tractor') – Method to simulate objects, either ‘tractor’ (TractorSimStamp) or ‘galsim’ (GalSimStamp).

  • add_sim_noise (string, default=False) – Add noise from the simulated source to the image. Choices: [‘gaussian’,’poisson’].

  • image_eq_model (bool, default=False) – Wherever add a simulated source, replace both image and inverse variance of the image with that of the simulated source only.

  • seed (int, default=0) – For random number generators.

  • kwargs_file (dict, default=None) – Extra arguments to file paths (e.g. get_randoms_id.keys()).

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.

class obiwan.kenobi.DecamSimImage(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.decam.

Extend BaseSimImage with legacypipe.decam.DecamImage.

Note

Image unit is ADU (x gain -> electrons).

References

http://ast.noao.edu/sites/default/files/NOAO_DHB_v2.2.pdf

get_gain(tim, x, y)

Return gain at the one-indexed pixel position x, y in the tim subimage.

Parameters
  • tim (tractor.Image) – Current tractor.Image.

  • x (int, array-like) – Pixel one-indexed x-position in the tim subimage, 1-dim.

  • y (int, array-like) – Pixel one-indexed y-position in the tim subimage, 1-dim.

Returns

gain – Gain (ADU x gain -> electrons).

Return type

float, array-like

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.DecamSimImagePlusNoise(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.runcosmos.

Extend BaseSimImage with DecamImagePlusNoise.

Note

Image unit is ADU (x gain -> electrons).

Warning

Conversion should be checked further!

get_gain(*args, **kwargs)

Return gain.

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.GSImage(*args: Any, **kwargs: Any)

Bases: galsim.

Extend galsim.Image, with other __setitem__ options.

class obiwan.kenobi.GalSimStamp(tim, **attrs)

Bases: obiwan.kenobi.BaseSimStamp

Extend BaseSimStamp with generation of galsim objects.

scale

Pixel scale.

Type

float

psf

PSF.

Type

GSImage

offsetint

Integer position of object in subimage.

Type

galsim.PositionI

offsetfrac

Fractional position of object in subimage.

Type

galsim.PositionD

Parameters
  • tim (tractor.Image) – Current tractor.Image.

  • attrs (dict) – Other attributes useful to define patches (e.g. nx, ny).

draw(obj)

Return a GSImage with obj in the center.

If either obj.sersic or obj.shape_r is 0, a point source is drawn. Else a Sersic profile is used.

Parameters

obj (SimCatalog row) – An object with attributes ra, dec, sersic, shape_r, shape_e1, shape_e2, 'flux_'+self.band.

Returns

gim – Image with obj.

Return type

GSImage

set_local(ra, dec)

Extend BaseSimStamp.set_local() by setting pixel scale, psf and object integer and fractional positions offsetint and offsetfrac.

Parameters
  • ra (float) – Right ascension (degree).

  • dec (float) – Declination (degree).

class obiwan.kenobi.LegacySurveySim(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimSurvey, legacypipe.survey.

Extend BaseSimSurvey with legacypipe.survey.LegacySurveyData.

kwargs are to be passed on to legacypipe.survey.LegacySurveyData-inherited classes, other arguments are specific to BaseSimSurvey. Only survey_dir must be specified to obtain bricks through get_brick_by_name().

Parameters
  • simcat (SimCatalog, default=None) – Simulated source catalog for a given brick (not CCD).

  • sim_stamp (string, default='tractor') – Method to simulate objects, either ‘tractor’ (TractorSimStamp) or ‘galsim’ (GalSimStamp).

  • add_sim_noise (string, default=False) – Add noise from the simulated source to the image. Choices: [‘gaussian’,’poisson’].

  • image_eq_model (bool, default=False) – Wherever add a simulated source, replace both image and inverse variance of the image with that of the simulated source only.

  • seed (int, default=0) – For random number generators.

  • kwargs_file (dict, default=None) – Extra arguments to file paths (e.g. get_randoms_id.keys()).

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.

class obiwan.kenobi.MegaPrimeSimImage(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.cfht.

Extend BaseSimImage with legacypipe.cfht.MegaPrimeImage.

Note

Image unit is ADU (x gain -> electrons).

References

https://www.cfht.hawaii.edu/Instruments/Imaging/MegaPrime/rawdata.html#P2

get_gain(tim, x, y)

Return gain at the one-indexed pixel position x, y in the tim subimage.

Parameters
  • tim (tractor.Image) – Current tractor.Image.

  • x (int, array-like) – Pixel one-indexed x-position in the tim subimage, 1-dim.

  • y (int, array-like) – Pixel one-indexed y-position in the tim subimage, 1-dim.

Returns

gain – Gain (ADU x gain -> electrons).

Return type

float, array-like

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.MosaicSimImage(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.mosaic.

Extend BaseSimImage with legacypipe.mosaic.MosaicImage.

Note

Image unit is electrons/second (x exptime -> electrons).

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.NinetyPrimeMosaicSim(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimSurvey, legacypipe.runs.

Extend BaseSimSurvey with a filter for mosaic or 90prime CCDs.

kwargs are to be passed on to legacypipe.survey.LegacySurveyData-inherited classes, other arguments are specific to BaseSimSurvey. Only survey_dir must be specified to obtain bricks through get_brick_by_name().

Parameters
  • simcat (SimCatalog, default=None) – Simulated source catalog for a given brick (not CCD).

  • sim_stamp (string, default='tractor') – Method to simulate objects, either ‘tractor’ (TractorSimStamp) or ‘galsim’ (GalSimStamp).

  • add_sim_noise (string, default=False) – Add noise from the simulated source to the image. Choices: [‘gaussian’,’poisson’].

  • image_eq_model (bool, default=False) – Wherever add a simulated source, replace both image and inverse variance of the image with that of the simulated source only.

  • seed (int, default=0) – For random number generators.

  • kwargs_file (dict, default=None) – Extra arguments to file paths (e.g. get_randoms_id.keys()).

  • kwargs (dict) – Arguments for legacypipe.survey.LegacySurveyData.

class obiwan.kenobi.PtfSimImage(*args: Any, **kwargs: Any)

Bases: obiwan.kenobi.BaseSimImage, legacypipe.ptf.

Extend BaseSimImage with legacypipe.ptf.PtfImage.

Note

Image unit is ADU (x gain -> electrons).

get_gain(tim, *args, **kwargs)

Return gain.

get_nano2e(*args, **kwargs)

Return nanomaggies to electron counts conversion.

class obiwan.kenobi.TractorSimStamp(tim, **attrs)

Bases: obiwan.kenobi.BaseSimStamp

Extend BaseSimStamp with generation of Tractor objects.

slcx

x slice of the subimage where object will be generated.

Type

tuple

slcy

y slice.

Type

tuple

Parameters
  • tim (tractor.Image) – Current tractor.Image.

  • attrs (dict) – Other attributes useful to define patches (e.g. nx, ny).

draw(obj)

Return a GSImage with obj in the center.

If either obj.sersic or obj.shape_r is 0, a point source is drawn. Else a Sersic profile is used.

Parameters

obj (SimCatalog row) – An object with attributes ra, dec, sersic, shape_r, shape_e1, shape_e2, 'flux_%s' % self.band.

Returns

gim – Image with obj if the stamp overlaps the tim, else None.

Return type

GSImage, None

get_subimage()

Return a subimage around xcen, ycen.

Parameters

obj (SimCatalog row) – An object with attributes ra, dec.

Returns

tim – Subimage.

Return type

tractor.Image

obiwan.kenobi.find_file(base_dir=None, filetype=None, brickname=None, source='obiwan', **kwargs)

Return file name.

Shortcut to LegacySurveySim.find_file().

base_dirstring, default=None

Obiwan (if source == 'obiwan') or legacypipe (if source == 'legacypipe') root file directory.

filetypestring, default=None

Type of file to find.

bricknamestring, default=None

Brick name.

sourcestring, default=’obiwan’

If ‘obiwan’, return an Obiwan output file name, else a legacypipe file name.

kwargsdict

Other arguments to file paths (e.g. get_randoms_id.keys()).

obiwan.kenobi.find_legacypipe_file(survey_dir, filetype, brickname=None, **kwargs)

Return legacypipe file name.

survey_dirstring

Survey directory.

filetypestring

Type of file to find.

bricknamestring

Brick name.

kwargsdict

Other arguments to file paths (e.g. get_randoms_id.keys()).

obiwan.kenobi.find_obiwan_file(output_dir, filetype, brickname=None, **kwargs)

Return Obiwan output file name.

output_dirstring

Obiwan output directory.

filetypestring

Type of file to find.

bricknamestring

Brick name.

kwargsdict

Other arguments to file paths (e.g. get_randoms_id.keys()).

obiwan.kenobi.get_git_version(dirnm=None)

Run ‘git describe’ in the current directory (or given dir) and return the result as a string.

Parameters

dirnm (string, default=None) – If not None, ‘cd’ to the given directory before running ‘git describe’.

Returns

version – Git version.

Return type

string

Notes

Taken from https://github.com/legacysurvey/legacypipe/blob/master/py/legacypipe/survey.py

class obiwan.kenobi.get_randoms_id(**kwargs)

Bases: object

Handle identifier related to input random catalog: file id, row start, skip id.

Return string corresponding to randoms id kwargs.

classmethod as_dict(**kwargs)

Return randoms id kwargs corresponding to kwargs.

classmethod as_list(**kwargs)

Return list corresponding to randoms id kwargs.

classmethod default()

Return default values.

classmethod keys()

Return keys.

classmethod kwargs_match_template()

Return kwargs to reconstruct match template.

classmethod match(string)

Match randoms id in string and return randoms id kwargs.

classmethod match_template()

Return match template.

classmethod template()

Return string template.

obiwan.kenobi.get_survey(name, **kwargs)

Return an instance of the BaseSimSurvey-inherited class given by name.

See obiwan.kenobi.runs dictionary.

obiwan.kenobi.get_version()

Return get_git_version() if not empty, else obiwan.__version__.

obiwan.catalog module

obiwan.utils module

obiwan.analysis module

obiwan.scripts module

obiwan.batch module