API

legacysim.survey module

Classes to extend legacypipe.survey.

class legacysim.survey.BaseSimSurvey(*args, injected=None, sim_stamp='tractor', add_sim_noise=False, image_eq_model=False, kwargs_simid=None, **kwargs)

Bases: object

Dumb class with legacysim attributes for future multiple inheritance.

injected

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_simid

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
  • injected (SimCatalog, default=None) – Catalog of sources to inject in a given brick (not CCD).

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

  • add_sim_noise (string, default=False) – Add noise related to 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.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys get_sim_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: - ‘injected’: injected sources - ‘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 legacysim.survey.CosmosSim(*args: Any, **kwargs: Any)

Bases: legacysim.survey.BaseSimSurvey, legacypipe.runcosmos.CosmosSurvey

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
  • injected (SimCatalog, default=None) – Catalog of sources to inject in a given brick (not CCD).

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

  • add_sim_noise (string, default=False) – Add noise related to 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.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys get_sim_id.keys().

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

class legacysim.survey.DecamSim(*args: Any, **kwargs: Any)

Bases: legacysim.survey.BaseSimSurvey, legacypipe.runs.DecamSurvey

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
  • injected (SimCatalog, default=None) – Catalog of sources to inject in a given brick (not CCD).

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

  • add_sim_noise (string, default=False) – Add noise related to 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.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys get_sim_id.keys().

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

class legacysim.survey.LegacySurveySim(*args: Any, **kwargs: Any)

Bases: legacysim.survey.BaseSimSurvey, legacypipe.survey.LegacySurveyData

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
  • injected (SimCatalog, default=None) – Catalog of sources to inject in a given brick (not CCD).

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

  • add_sim_noise (string, default=False) – Add noise related to 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.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys get_sim_id.keys().

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

class legacysim.survey.NinetyPrimeMosaicSim(*args: Any, **kwargs: Any)

Bases: legacysim.survey.BaseSimSurvey, legacypipe.runs.NinetyPrimeMosaic

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
  • injected (SimCatalog, default=None) – Catalog of sources to inject in a given brick (not CCD).

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

  • add_sim_noise (string, default=False) – Add noise related to 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.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys get_sim_id.keys().

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

legacysim.survey.find_file(base_dir=None, filetype=None, brickname=None, source='legacysim', **kwargs)

Return file name.

Shortcut to LegacySurveySim.find_file().

base_dirstring, default=None

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

filetypestring, default=None

Type of file to find.

bricknamestring, default=None

Brick name.

sourcestring, default=’legacysim’

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

kwargsdict

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

legacysim.survey.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_sim_id.keys()).

legacysim.survey.find_legacysim_file(output_dir, filetype, brickname=None, **kwargs)

Return legacysim output file name.

output_dirstring

legacysim output directory.

filetypestring

Type of file to find.

bricknamestring

Brick name.

kwargsdict

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

legacysim.survey.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 legacysim.survey.get_sim_id(**kwargs)

Bases: object

Handle identifier related to simulation: file id, row start, skip id.

Return string corresponding to sim id kwargs.

classmethod as_dict(**kwargs)

Return sim id kwargs corresponding to kwargs.

classmethod as_list(**kwargs)

Return list corresponding to sim 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 sim id in string and return sim id kwargs.

classmethod match_template()

Return match template.

classmethod template()

Return string template.

legacysim.survey.get_survey(name, **kwargs)

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

See legacysim.survey.runs dictionary.

legacysim.survey.get_version()

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

legacysim.image module

Classes to extend legacypipe.image.

class legacysim.image.BaseSimImage

Bases: object

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

get_zpscale()

Return zpscale for image units to nanomaggies conversion.

class legacysim.image.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 legacysim.image.BokSimImage(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.bok.BokImage

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 legacysim.image.DecamSimImage(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.decam.DecamImage

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 legacysim.image.DecamSimImagePlusNoise(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.runcosmos.DecamImagePlusNoise

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 legacysim.image.GSImage(*args: Any, **kwargs: Any)

Bases: galsim.Image

Extend galsim.Image, with other __setitem__ options.

class legacysim.image.GalSimStamp(tim, **attrs)

Bases: legacysim.image.BaseSimStamp

Extend BaseSimStamp with generation of galsim source stamps.

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 legacysim.image.MegaPrimeSimImage(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.cfht.MegaPrimeImage

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 legacysim.image.MosaicSimImage(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.mosaic.MosaicImage

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 legacysim.image.PtfSimImage(*args: Any, **kwargs: Any)

Bases: legacysim.image.BaseSimImage, legacypipe.ptf.PtfImage

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 legacysim.image.TractorSimStamp(tim, **attrs)

Bases: legacysim.image.BaseSimStamp

Extend BaseSimStamp with generation of Tractor source stamps.

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

legacysim.catalog module

Convenient classes to handle catalogs, bricks and runs.

class legacysim.catalog.BaseCatalog(*args: Any, **kwargs: Any)

Bases: astrometry.util.fits.tabledata

Extend tabledata, with convenient methods.

_length

Catalog length, also given by len() and size.

Type

int

_columns

Catalog columns, including internals (starting with _). Without internals: fields.

Type

list

Call astrometry.util.fits.fits_table().

For an empty catalog, one can provide size or length, to define len(), used in methods to build numpy arrays (e.g. zeros()). Otherwise, len() is set when the first column is added.

copy(fields=None)

Return a (deep) copy, keeping columns fields.

Parameters

fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

Returns

new – Copy.

Return type

BaseCatalog

Note

Contrary to astrometry.util.fits.tabledata, all internal (starting with ‘_’) values are (deep) copied.

delete_columns(*fields)

Delete columns fields.

falses()

Return array of size size filled with False.

property fields

Return fields = self.get_columns(internal=False).

fill(other, index_self=None, index_other=None, fields_other=None, fill_nan=True)

Fill (or create) columns with those of other catalog.

If a column of name field already exists in self (with a shape compatible with that of other), the values with indices index_self are replaced by those of other with indices index_other. Else, a new column is added to self, with default value given by numpy.zeros() (or numpy.nan if fill_nan == True). Again, the values with indices index_self are replaced by those of other with indices index_other.

Parameters
  • other (BaseCatalog) – Catalog to be merged to self.

  • index_self (slice, ndarray, string, default=None) – Indices (or bool mask) of self to fill with other. If None, all indices of self are considered. If before, other[index_other] rows are added at the beginning of self. If after, other[index_other] rows are added at the end of self.

  • index_other (slice, ndarray, default=None) – Indices (or bool mask) of other to fill self. If None, all indices of other are considered.

  • fields_other (list, default=None) – Fields of other to be added to self. If None, all fields of other are considered.

  • fill_nan (bool, default=True) – If True, default value for added column is numpy.nan instead of numpy.zeros().

classmethod from_dict(d)

Construct catalog from dictionary of (field, column).

full(fill_value, **kwargs)

Return array of size size filled with fill_value.

index()

Return zero-starting index.

isin(other, fields=None)

Return mask selecting rows that are in other for fields.

Parameters
  • other (BaseCatalog) – Other catalog.

  • fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

Returns

mask – Mask.

Return type

bool ndarray

keep_columns(*fields)

Keep only columns fields.

nans()

Return array of size size filled with numpy.nan.

ones(dtype=<class 'numpy.float64'>)

Return array of size size filled with one.

remove_duplicates(fields=None, copy=False)

Remove duplicate rows for fields.

Returned catalog has the same fields as self.

Parameters
  • fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

  • copy (bool, default=False) – Return copy?

Returns

se;f – Catalog without duplicate rows.

Return type

BaseCatalog

repeat(repeats, copy=True)

Apply numpy.repeat() to every column.

Parameters
  • repeats (int) – Number of repeats.

  • copy (bool, default=False) – Return copy?

Returns

new – Repeated catalog.

Return type

BaseCatalog

property size

Return len().

tile(repeats, copy=True)

Apply numpy.tile() to every column.

Parameters
  • repeats (int) – Number of repeats.

  • copy (bool, default=False) – Return copy?

Returns

new – Tiled catalog.

Return type

BaseCatalog

to_ndarray(fields=None)

Return numpy.ndarray representation for columns fields.

Parameters

fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

Returns

arraynumpy.ndarray instance.

Return type

ndarray

to_recarray(fields=None)

Return numpy.recarray representation for columns fields.

Parameters

fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

Returns

arraynumpy.recarray instance.

Return type

recarray

trues()

Return array of size size filled with True.

uniqid(fields=None)

Return unique id for fields.

Parameters

fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

Returns

arraynumpy.ndarray strings with shape size.

Return type

ndarray

unique(fields=None, sort_index=False, return_unique=True, **kwargs)

Return catalog with unique rows for columns fields.

Parameters
  • fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

  • sort_index (bool, default=False) – Sort by increasing index.

  • return_unique (bool, default=True) – Return catalog with unique rows for columns fields.

  • kwargs (dict) – Other arguments for numpy.unique().

Returns

unique – If return_unique == True, return catalog with unique rows. For other values see numpy.unique().

Return type

BaseCatalog

writeto(fn, *args, **kwargs)

Write to fn.

zeros(dtype=<class 'numpy.float64'>)

Return array of size size filled with zero.

class legacysim.catalog.BrickCatalog(*args: Any, **kwargs: Any)

Bases: legacysim.catalog.BaseCatalog

Extend BaseCatalog with convenient methods for bricks.

_rowmax, _colmax, _ncols

internals to grep brick from ra, dec (see get_by_radec()).

Type

int, int, ndarray

hash

Hash table to grep brick from ra, dec.

Type

ndarray

columns

brickname, brickid, etc.

Type

ndarray

Load bricks.

Parameters

survey (LegacySurveyData, string, default=None) – survey_dir or survey. If None, construct BrickCatalog from desiutil.brick.Bricks.

get_area(total=False)

Return area of individual bricks.

Calls utils.get_radecbox_area().

Parameters

total (bool, default=False) – If True, returns total area.

Returns

area – Area (degree^2).

Return type

float, ndarray

get_by_name(brickname)

Return bricks with name brickname.

Parameters

brickname (string, array-like) – If string, return a single-element BrickCatalog, else a BrickCatalog with defined size.

Returns

bricksself cut to brickname.

Return type

BrickCatalog

get_by_radec(ra, dec)

Return bricks containing ra, dec.

Parameters
  • ra (float, array-like) – Right ascension (degree).

  • dec (float, array-like) – Declination (degree).

Returns

bricksself cut to bricks containing ra, dec.

Return type

BrickCatalog

get_hash()

Return hash enforcing at least 1d (contrary to e.g. self[0].hash).

get_radecbox(total=False)

Return ra, dec box (ramin, ramax, decmin, decmax) of individual bricks.

Parameters

total (bool, default=False) – If True, returns the ra, dec box enclosing all bricks.

Returns

(ramin, ramax, decmin, decmax) – ra, dec box.

Return type

tuple of float, ndarray

get_xy_from_radec(ra, dec, brickname=None)

Returns brick bx, by given ra, dec.

Parameters
  • ra (float, array-like) – Right ascension (degree).

  • dec (float, array-like) – Declination (degree).

  • brickname (string, array-like, default=None) – Brick name. If array-like, should be of the same length as ra, dec. If None, will query the correct brickname given ra, dec.

Returns

  • bx (float, ndarray) – Brick x coordinate.

  • by (float, ndarray) – Brick y coordinate.

static read_list(bricklist, unique=True)

Read brick list and return list of (unique) brick names.

Parameters
  • bricklist (list, string) – List of strings (or one string) corresponding either brick names or ASCII files containing a column of brick names.

  • unique (bool, default=True) – Return unique brick names?

Returns

bricknames – List of (unique) brick names.

Return type

list

write_list(fn)

Write brick names to fn.

Parameters

fn (string) – Path to brick list.

class legacysim.catalog.ListStages(args=None)

Bases: collections.UserList

Handle list of unique stages.

args must be a list of stages.

append(*args, **kwargs)

Append stages, return current index.

index(stages)

Return index of stages if in self, else -1.

match(other)

Match list stages.

Parameters

other (Stages) – Other stages.

Returns

  • istages1 (list) –

    The list of indices in self matching other, such that::
    for iother,iself in enumerate(istages1):

    # iself is the index in self # iother is the corresponding index in other

  • istages2 (list) – The list of indices in other matching self.

without_versions()

Return copy with empty versions and its list of indices matching self,

Returns

  • new (ListStages) – Versions are all empty.

  • istages (list) –

    List of indices, such that:

    for iself,inew in enumerate(istages):
        # iself is the index in self
        # inew is the corresponding index in new
    

class legacysim.catalog.RunCatalog(*args: Any, **kwargs: Any)

Bases: legacysim.catalog.BaseCatalog

Extend BaseCatalog with convenient methods for run (defined by brick x sim id x stages id) lists.

Useful to schedule jobs and navigate through the legacysim or legacypipe file structure.

_list_stages

List of stages corresponding to indices in column stagesid.

Type

ListStages

Initialize RunCatalog from array or file name.

append(other)

Append other rows to self, taking care to update the column stagesid.

append_stages(*args, **kwargs)

Shortcut for self._list_stages.append(*args,**kwargs).

check()

Raise ValueError if there are rows with same (brickname x sim id) but different stagesid.

count_runs(*args, **kwargs)

Return the number of runs in input catalog cat (see iter_mask()).

property fields

Return fields.

classmethod from_brick_sim_id(bricknames=None, kwargs_simids=None, stages=None)

Initialize RunCatalog from a list of bricks, sim ids and stages id.

Parameters
  • bricknames (list, string, default=None) – Single brick name or list of brick names.

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys(). A run (row) is created for each brick name and each of these dictionaries.

  • stages (list, string, default=None) – Stages (same for each row of the output catalog).

Returns

self – New instance.

Return type

RunCatalog

classmethod from_catalog(cat, list_stages=None, stages=None)

Initialize RunCatalog from a catalog.

Parameters
  • cat (BaseCatalog) – Catalog containing brickname, keys() and stagesid columns.

  • list_stages (ListStages, default=None) – If None, call group_stages() on cat. Else, simply set _list_stages to list_stages, which should describe cat.stagesid.

  • stages (list, string, int, default=None) – Stages (same for each row of the output catalog). If not None, supersedes cat field stagesid. If list_stages is None and cat has no field stagesid, defaults to Stages.default().

Returns

self – New instance.

Return type

RunCatalog

classmethod from_input_cmdline(opt)

Initialize RunCatalog from command-line arguments of get_input_parser().

If ‘list’ is not None, create new instance with from_list(). and apply mask_cmdline() i.e. restrict to those runs corresponding to other arguments in opt (ignore if None). Else (‘list’ is None), create new instance with from_brick_sim_id() based on other command-line arguments.

Parameters

opt (argparse.Namespace, dict) – Holds options of get_input_parser().

Returns

self – New instance.

Return type

RunCatalog

classmethod from_list(fns)

Initialize RunCatalog from run list(s) in fns.

Parameters

fns (list, string) – Path to run list. If multiple paths are provided, catalogs are appended (see append()).

Returns

self – New instance corresponding to the input run list(s).

Return type

RunCatalog

Note

Column stagesid can be modified, in particular if more than one run lists are provided.

classmethod from_output_cmdline(opt, force_from_disk=False)

Initialize RunCatalog from command-line arguments of get_output_parser().

If all arguments of get_output_parser() are provided, create instance folowing from_input_cmdline(). If force_from_disk == True, further restrict to those runs for which catalogs are written on disk (default file type is ‘tractor’ except if ‘stages’ is not None, in which case default is ‘pickle’).

Else, explore the legacyipe or legacysim (default ‘source’) file structure to fill in the other command-line arguments; and return new instance.

Parameters
  • opt (argparse.Namespace, dict) – Holds options of get_output_parser().

  • force_from_disk (bool, default=False) – If True limit run list to files that exist on disk.

Returns

self – New instance.

Return type

RunCatalog

static get_input_parser(parser=None, add_stages=False)

Add parser arguments to define runs.

Parameters
  • parser (argparse.ArgumentParser, default=None) – Parser to add (in place) arguments to. If None, a new one is created.

  • add_stages (bool, default=False) – Add argument ‘–stages’?

Returns

parser – Parser with arguments.

Return type

argparse.ArgumentParser

get_list_stages()

Return _list_stages.

static get_output_parser(parser=None, add_stages=False, add_filetype=False, add_source=False)

Add parser arguments to reconstruct runs from legacypipe or legacysim file structure.

Parameters
  • parser (argparse.ArgumentParser, default=None) – Parser to add (in place) arguments to. If None, a new one is created.

  • add_stages (bool, default=False) – Add argument ‘–stages’ and ‘–pickle’?

  • add_filetype (bool, default=False) – Add argument ‘–filetype’?

  • add_source (bool, default=False) – Add argument ‘–source’?

Returns

parser – Parser with arguments.

Return type

argparse.ArgumentParser

group_stages(copy=False)

Start from catalog of (brickname x sim id x stage), group rows with same (brickname x sim id) together, stack their stages and add stages id in column stagesid.

List of stages _list_stages is cleared beforehand.

Parameters

copy (bool, default=False) – Return copy?

Returns

runcat – Catalog in correct format (brickname x sim id x stages id).

Return type

RunCatalog

isin(other, fields=None, ignore_stage_version=False)

Return mask selecting rows that are in other for fields.

Parameters
  • other (BaseCatalog) – Other catalog.

  • fields (string, list, default=None) – Single field or list of fields. If None, use all fields.

  • ignore_stage_version (bool, default=False) – Ignore stage versions for comparison of field stagesid. Only used if ‘stagesid’ is in fields.

Returns

mask – Mask.

Return type

bool ndarray

Note

For this comparison, the column stagesid of other is updated such that the mapping to stages in other _list_stages is the same as for self. Neither other nor self is modified in this process.

iter_index(*args, **kwargs)

Yield indices for the different runs in input catalog cat (see iter_mask()).

iter_mask(cat, fields=None)

Yield boolean mask for the different runs in input catalog cat.

Parameters
  • cat (BaseCatalog) – Catalog to be iterated over.

  • fields (string, list, default=None) – Single field or list of fields. If None, use all fields in self which are also in cat.

static kwargs_simids_from_cmdline(opt)

Return list of legacysim.survey.get_sim_id dictionaries from command-line arguments.

Parameters

opt (argparse.Namespace, dict) – Holds options of get_input_parser().

Returns

kwargs_simids – List of get_sim_id dictionaries with keys keys().

Return type

dict list

mask_cmdline(opt)

Return mask corresponding to command-line arguments in opt: ‘brick’, keys(), ‘stages’, ‘list’.

If an argument is not in opt or is None, no mask is applied.

Parameters

opt (argparse.Namespace, dict) – Holds command-line options.

Returns

mask – Mask.

Return type

Bool ndarray

replace_sim_id(copy=False, kwargs_simids=None)

Replace sim id by those in kwargs_simids.

Parameters
  • copy (bool, default=False) – Return copy?

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys(). A run (row) is created for each brick name and each of these dictionaries.

Returns

runcat – New instance.

Return type

RunCatalog

static set_default_output_cmdline(opt)

Set default output command-line options. Change opt in-place.

Parameters

opt (argparse.Namespace, dict) – Command-line options.

update_stages(copy=False)

Remove stages indices of _list_stages which are not in stagesid.

Hence, modify column stagesid.

Parameters

copy (bool, default=False) – Return copy?

Returns

runcat – New instance.

Return type

RunCatalog

without_stage_versions(copy=False)

Return catalog without caring for stage versions.

Namely, stages with same names but with different module versions are considered the same. Then, _list_stages is reduced to the unique stages, and column stagesid is updated.

Parameters

copy (bool, default=False) – Return copy?

Returns

runcat – Catalog without stage versions.

Return type

RunCatalog

write_list(fn)

Write run list to fn.

Parameters

fn (string) – Path to run list.

writeto(*args, primheader=None, **kwargs)

Write catalog, saving stages in header.

class legacysim.catalog.SimCatalog(*args: Any, **kwargs: Any)

Bases: legacysim.catalog.BaseCatalog

Extend BaseCatalog with convenient methods for handling sources injected by legacysim.

Call astrometry.util.fits.fits_table().

For an empty catalog, one can provide size or length, to define len(), used in methods to build numpy arrays (e.g. zeros()). Otherwise, len() is set when the first column is added.

fill_legacysim(survey=None, seed=None)

Add columns required for legacysim (if not already in self):

  • id : defaults to index()

  • brickname, (brick) bx, by coordinates: based on survey and ra, dec

  • seed: random seed based on seed.

Other columns required by legacysim are:

  • ra, dec : coordinates (degree)

  • flux_g, flux_r, flux_z : including galactic extinction (nanomaggies)

  • sersic : Sersic index

  • shape_r : half light radius (arcsecond)

  • shape_e1, shape_e2 : ellipticities.

Parameters
  • survey (LegacySurveyData, string, default=None) – survey_dir or survey. Used to determine brick-related quantities (brickname, bx, by). If None, brick-related quantities are inferred from desiutil.brick.Bricks (see BrickCatalog).

  • seed (int, default=None) – Used to fill or replace ‘seed’ column if not None.

References

https://en.wikipedia.org/wiki/Sersic_profile https://www.legacysurvey.org/dr8/catalogs

get_extinction(band, camera='DES')

Return SFD extinction given band and camera.

Calls utils.get_extinction().

Parameters
  • band (string) – Photometric band.

  • camera (string, default=`DES`) – camera.

Returns

extinction – Extinction (mag).

Return type

ndarray

mask_collisions(radius_in_degree=0.001388888888888889)

Return mask of collided objects.

Calls utils.mask_collisions().

Parameters

radius_in_degree (float, default=5./3600.) – Collision radius (degree).

Returns

mask – Mask of collided objects.

Return type

bool ndarray

match_radec(other, radius_in_degree=0.001388888888888889, **kwargs)

Match self and other ra, dec.

Calls utils.match_radec().

Parameters
  • other (SimCatalog) – Catalog to be matched against self.

  • radius_in_degree (float, default=5./3600.) – Collision radius (degree).

  • kwargs (dict) – Arguments for utils.match_radec().

Returns

  • index_self (ndarray) – Indices of matching points in self.

  • index_other (ndarray) – Indices of matching points in other.

class legacysim.catalog.Stages(stages=None)

Bases: collections.UserDict

Handle (stage,versions) mapping. Keys sorted in legacypipe.runbrick chronological order.

_all

All stages of legacypipe.runbrick.

Type

list

_default

Default stage name.

Type

string

If stages is None, include only stage ‘writecat’. Else, stages can be:

  • a dictionary of (key,value) = (stage,versions)

  • a list of tuples: ‘[(stage1,versions1), (stage2,versions2)]’

  • a list of strings: ‘[‘stage1:versions1’, ‘stage2:versions2’]’

  • a string: ‘stages1:versions1 stages2:versions2’

classmethod all()

Return _all.

classmethod default()

Return _default.

isin(other)

Return mask selecting stages of self that are in other.

Parameters

other (Stages) – Other stages.

Returns

mask – Mask.

Return type

list

keys()

Return keys sorted by chronological order in legacypipe.runbrick.

without_versions()

Return copy with empty versions.

class legacysim.catalog.Versions(*args, **kwargs)

Bases: collections.UserDict

Handle (module,version) mapping. No order relation.

If no args provided, kwargs should contain (module,version) mapping. If one args provided, can be:

  • a dictionary of (key,value) = (module,version)

  • a list of tuples: ‘[(module1,version1), (module2,version2)]’

  • a list of strings: ‘[‘module1:version1’, ‘module2:version2’]’

  • a string: ‘module1:version1,module2:version2’

keys()

Return keys sorted in alphabetical order.

legacysim.utils module

Convenient functions to handle legacysim inputs/outputs.

class legacysim.utils.MonkeyPatching

Bases: object

Class to add attributes to modules, e.g.:

import module
with MonkeyPatching() as mp:
    mp.add(module,'function',fun)
    # module.function is fun
# module.function is original function if exists
_old

Dictionary holding original attributes.

Type

dict

_new

Dictionary holding new (temporary) attributes.

Type

dict

Create internal dictionaries :attr:_old and :attr:_new.

add(mod, name, attr)

Add attribute attr with name name to module mod (and save mod.name if already exists).

clear()

Remove all added (module,name) ties.

keys()

Return (module,name) keys.

remove(mod, name)

Remove added tie of name to module mod and restores the old one if exists.

legacysim.utils.get_extinction(ra, dec, band=None, camera='DES')

Return SFD extinction given ra, dec, band and camera.

If band not provided, return EBV.

Parameters
  • ra (float, array-like) – Right ascension (degree).

  • dec (float, array-like) – Declination (degree).

  • band (string, default=None) – Photometric band. If not provided, returns EBV.

  • camera (string, default=`DES`) – Camera.

Returns

extinction – Extinction.

Return type

float, ndarray

legacysim.utils.get_parser_action_by_dest(parser, dest)

Return parser action corresponding to dest.

Parameters
  • parser (argparse.ArgumentParser) – Parser.

  • dest (string) – Parser destination argument.

Returns

act – Action.

Return type

argparse._StoreAction

legacysim.utils.get_parser_args(args=None)

Transform args (None, str, list, dict) to parser-compatible (list of strings) args.

Parameters

args (string, list, dict, default=None) – Arguments. If dict, ‘–’ are added in front and there should not be positional arguments.

Returns

args – Parser arguments.

Return type

None, list of strings.

Notes

All non-strings are converted to strings with str().

legacysim.utils.get_radecbox_area(ramin, ramax, decmin, decmax)

Return area of ra, dec box.

Parameters
  • ramin (float, array-like) – Minimum right ascension (degree).

  • ramax (float, array-like) – Maximum right ascension (degree).

  • decmin (float, array-like) – Minimum declination (degree).

  • decmax (float, array-like) – Maximum declination (degree).

Returns

area – Area (degree^2).

Return type

float, ndarray.

legacysim.utils.get_shape_ba(e)

Return minor-to-major axis ratio ba given ellipticity e.

Parameters

e (float, ndarray) – Ellipticity.

Returns

ba – Minor-to-major axis ratio (b/a).

Return type

float, ndarray

References

https://www.legacysurvey.org/dr8/catalogs/

legacysim.utils.get_shape_ba_phi(e1, e2)

Return minor-to-major axis ratio ba and angle phi given ellipticities e1, e2.

Parameters
  • e1 (float, ndarray) – Ellipticity component 1.

  • e2 (float, ndarray) – Ellipticity component 2.

Returns

  • ba (float, ndarray) – Minor-to-major axis ratio (b/a).

  • phi (float, ndarray) – Angle (radian).

References

https://www.legacysurvey.org/dr8/catalogs/

legacysim.utils.get_shape_e(ba)

Return ellipticity e given minor-to-major axis ratio ba.

Parameters

ba (float, ndarray) – Minor-to-major axis ratio (b/a).

Returns

e – Ellipticity.

Return type

float, ndarray

References

https://www.legacysurvey.org/dr8/catalogs/ Warning! Corresponds to g in: https://galsim-developers.github.io/GalSim/_build/html/shear.html#

legacysim.utils.get_shape_e1_e2(ba, phi)

Return ellipticities e1, e2 given minor-to-major axis ratio ba and angle phi.

Parameters
  • ba (float, ndarray) – Minor-to-major axis ratio (b/a).

  • phi (float, ndarray) – Angle in radians.

Returns

  • e1 (float, ndarray) – Ellipticity component 1.

  • e2 (float, ndarray) – Ellipticity component 2.

References

https://www.legacysurvey.org/dr8/catalogs/

legacysim.utils.list_parser_dest(parser, exclude=('help',))

Return parser list of dest.

Parameters
  • parser (argparse.ArgumentParser) – Parser.

  • exclude (list, tuple, default=('help',)) – Brick name.

Returns

args – Parser list of dest.

Return type

list

legacysim.utils.mag2nano(mag)

Convert magnitudes to nanomaggies.

legacysim.utils.mask_collisions(ra, dec, radius_in_degree=0.001388888888888889)

Return mask of collided objects.

Parameters
  • ra (array-like) – Right ascension (degree).

  • dec (array-like) – Declination (degree).

  • radius_in_degree (float, default=5./3600.) – Collision radius (degree).

Returns

mask – Mask of collided objects.

Return type

bool ndarray

legacysim.utils.match_id(id1, id2)

Match id2 to id1.

Parameters
  • id1 (array-like) – IDs 1, should be unique.

  • id2 (array-like) – IDs 2, should be unique.

Returns

  • index1 (ndarray) – Indices of matching id1.

  • index2 (ndarray) – Indices of matching id2.

Warning

Makes sense only if id1 and id2 elements are unique.

References

https://www.followthesheep.com/?p=1366

legacysim.utils.match_radec(ra1, dec1, ra2, dec2, radius_in_degree=None, return_distance=False, notself=False, nearest=True)

Match ra2,dec2 to ra1,dec1.

All quantities in degree. Uses https://github.com/dstndstn/astrometry.net/blob/master/libkd/spherematch.py.

Parameters
  • ra1 (array-like) – Right ascension 1 (degree).

  • dec1 (array-like) – Declination 1 (degree).

  • ra2 (array-like) – Right ascension 2 (degree).

  • dec2 (array-like) – Declination 2 (degree).

  • radius_in_degree (float,default=None) – If not None, maximum radius (degree) to match ra, dec pairs.

  • return_distance (bool, default=False) – If True, return distance.

  • notself (bool, default=False) – If True, avoids returning ‘identity’ matches, i.e. ra1,dec1 == ra2,dec2.

  • nearest (bool, default=True) – If True, returns only the nearest match in (ra2,dec2) for each point in (ra1,dec1). Else, returns all matches (index1 and index2 are not made of unique elements).

Returns

  • index1 (ndarray) – Indices of ra1,dec1 matching points.

  • index2 (ndarray) – Indices of ra2,dec2 matching points.

  • distance (ndarray) – Distance (degree).

legacysim.utils.mkdir(dirnm)

Try to create dirnm and catch OSError.

legacysim.utils.nano2mag(nano)

Convert nanomaggies to magnitudes.

legacysim.utils.sample_ra_dec(size=None, radecbox=(0.0, 360.0, - 90.0, 90.0), rng=None, seed=None)

Sample uniform ra, dec coordinates in radecbox.

Taken from https://github.com/desihub/imaginglss/blob/master/scripts/imglss-mpi-make-random.py.

Parameters
  • size (int, default=None) – Number of objects. If None, only a single tuple ra, dec will be sampled.

  • radecbox (list, tuple, default=(0.,360.,-90.,90.)) – ramin, ramax, decmin, decmax.

  • rng (np.random.RandomState, default=None) – Random state; If None, build RandomState from seed.

  • seed (int, default=None) – Random seed, only used if rng is None.

Returns

  • ra (float, ndarray) – Right ascension (degree).

  • dec (float, ndarray) – Declination (degree).

legacysim.utils.savefig(fn, bbox_inches='tight', pad_inches=0.1, dpi=200, **kwargs)

Save matplotlib figure to fn.

legacysim.utils.saveplot(giveax=True)

Decorate plotting methods, to achieve the following behaviour for the decorated method:

If ax is provided, add image to ax. Else, if fn is provided, save image to fn, with arguments kwargs_fig. Else, show image.

Parameters

giveax (bool, default=True) – If True, provide ax to decorated method. Else, ax is not provided.

legacysim.utils.setup_logging(level=20, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, filename=None, filemode='w', **kwargs)

Set up logging.

Parameters
  • level (string, int, default=logging.INFO) – Logging level.

  • stream (_io.TextIOWrapper, default=sys.stdout) – Where to stream.

  • filename (string, default=None) – If not None stream to file name.

  • filemode (string, default='w') – Mode to open file, only used if filename is not None.

  • kwargs (dict) – Other arguments for logging.basicConfig().

legacysim.runbrick module

legacysim main executable, extend legacypipe.runbrick.

legacysim.runbrick.get_parser()

Append legacysim arguments to those of legacypipe.runbrick.get_parser().

Returns

  • parser (argarse.ArgumentParser) – Parser.

  • args_runbrick (list) – List of legacypipe-specific arguments.

legacysim.runbrick.get_runbrick_kwargs(args_runbrick, **opt)

Convert legacysim.runbrick command line options into survey and **kwargs for run_brick().

Wraps legacypipe.runbrick.get_runbrick_kwargs().

Parameters
  • args_runbrick (list) – List of legacypipe-specific arguments.

  • opt (dict) – Dictionary of the command line options for legacysim.runbrick.

Returns

  • survey (LegacySurveySim instance) – Survey, without injected.

  • kwargs (dict) –

    Arguments for legacypipe.runbrick.run_brick() following:

    run_brick(brickname, survey, **kwargs)
    

legacysim.runbrick.main(args=None)

Main routine which parses the optional inputs.

Essentially copy-paste from legacypipe.runbrick.main(), main changes:

parser = get_parser()
survey, kwargs = get_runbrick_kwargs(**optdict)
run_brick(opt.brick, survey, **kwargs)

to:

parser, args_runbrick = get_parser()
survey, kwargs = get_runbrick_kwargs(args_runbrick,**optdict)
run_brick(opt, survey, **kwargs)
Parameters

args (list, default=None) – To overload command line arguments.

legacysim.runbrick.run_brick(opt, survey, **kwargs)

Add injected to survey, run brick, and saves injected.

Wraps legacypipe.runbrick.run_brick().

Parameters
  • opt (Namespace) – Command line options for legacysim.runbrick.

  • survey (LegacySurveySim instance) – Survey, without injected.

  • kwargs (dict, default={}) –

    Arguments for legacypipe.runbrick.run_brick() following:

    run_brick(brickname, survey, **kwargs)
    

Returns

toret – Dictionary returned by legacypipe.runbrick.run_brick().

Return type

dict

legacysim.runbrick.set_brick(opt)

If no brick name provided in opt (opt.radec == None), build it from ra, dec and update opt.brick.

Copy-pasted from legacypipe.runbrick.run_brick().

Parameters

opt (argparse.Namespace) – Command-line arguments.

legacysim.runbrick.wrapper_add_stage_version(legacypipe_add_stage_version)

Wrap legacypipe.runbrick._add_stage_version() to add legacysim stage version.

legacysim.runbrick.wrapper_get_dependency_versions(legacypipe_get_dependency_versions)

Wrap legacypipe.survey.get_dependency_versions() to add legacysim dependency versions (galsim).

legacysim.runbrick.wrapper_get_version_header(legacypipe_get_version_header)

Wrap legacypipe.survey.get_version_header() to add legacysim version.

legacysim.analysis module

Convenient classes to perform legacysim analysis: image cutouts, catalog merging, catalog matching, computing time.

class legacysim.analysis.BaseImage

Bases: object

Dumb class to read, slice and plot an image.

img

Image (indexed by img[y,x]), may be multi-dimensional.

Type

ndarray

xmin

x-coordinate of (0,0) corner.

Type

int, float

ymin

y-coordinate of (0,0) corner.

Type

int, float

isRGB()

Whether image is multi-dimensional.

plot(ax, cmap='gray', vmin=None, vmax=None, kwargs_range=None)

Plot image.

Parameters
  • ax (plt.axes.Axes) – Where to plot image. One can also provide figure file name fn. See utils.saveplot.

  • cmap (string, plt.Colormap, default='gray') – Color map for pyplot.imshow(), ignore in case of RGB(A) image.

  • vmin (float, default=None) – Minimum value for cmap.

  • vmax (float, default=None) – Maximum value for cmap.

  • kwargs_range (dict, default=None) – If provided, provided to Binning to determine vmin and vmax.

read_image(fn, fmt='jpeg', xmin=0, ymin=0, **kwargs)

Read image, either in ‘jpeg’ or ‘fits’ fmt and add img to self.

Parameters
  • fn (string) – Image filename.

  • fmt (string, defaut='jpeg') – Image format, ‘jpeg’ or ‘fits’. If ‘jpeg’, self.img will have shape (H,W,3). If ‘fits’, self.img will have shape (H,W).

  • xmin (int, float, default=0) – x-coordinate of (0,0) corner.

  • ymin (int, float, default=0) – y-coordinate of (0,0) corner.

  • kwargs (dict, default={}) – Arguments to be passed to pyplot.imread() or fitsio.read().

set_subimage(slicex=slice(0, None, None), slicey=slice(0, None, None))

Slice image and update xmin, ymin accordingly.

Slices should be zero-indexed, in the image coordinates (i.e. do not account for xmin and ymin).

Parameters
  • slicex (slice, default=slice(0,None)) – Slice along x-axis (second axis of img).

  • slicey (slice, default=slice(0,None)) – Slice along y-axis (first axis of img).

property shape

Return image shape (H,W).

If image does not exist, defaults to _shape_default.

class legacysim.analysis.Binning(samples=None, weights=None, edges=None, nbins=10, range=None, quantiles=None, scale='linear')

Bases: object

Create edges to bin samples.

edges

Edges to bin samples.

Type

ndarray

First set the total range, then the number of bins with numpy.histogram_bin_edges().

Parameters
  • samples (array-like) – Samples to be binned.

  • weights (array-like, default=None) – Weights associated to samples, used by numpy.histogram_bin_edges(). If None, defaults to 1.

  • edges (array-like, default=None) – If edges already provided, nothing to do!

  • nbins (int, string, default=None) – Number of bins. If int, used to define edges using scale. Else, passed on to numpy.histogram_bin_edges().

  • range (array-like, default=None) – Range, i.e. edges minimum and maximum boundaries. If not None, supersedes quantiles.

  • quantiles (array-like, default=None) – Quantiles (low,up) to define range. If None, set range to samples minimum and maximum.

  • scale (string, default='linear') – Used if nbins is int. If ‘linear’, use a linear binning. If ‘log’, use a logarithmic binning.

property centers

Return bin centers.

property nbins

Return number of bins.

property range

Return edges minimum and maximum boundaries.

class legacysim.analysis.CatalogMatching(base_dir='.', runcat=None, bricknames=None, kwargs_simids=None, source='legacysim', cats_dir=None, save_fn=None)

Bases: legacysim.analysis.CatalogMerging

Extend CatalogMerging with methods to match input and output catalogs.

input

Catalog of input sources.

Type

SimCatalog

output

Catalog of output sources.

Type

SimCatalog

Set legacysim or legacypipe file structure.

Parameters
  • base_dir (string, default='.') – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory.

  • runcat (RunCatalog, defaut=None) – Run catalog used to select files from legacysim or legacypipe data structure. If provided, supersedes bricknames and kwargs_simids.

  • bricknames (list, default=None) – List of brick names.

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file names, else legacypipe file names.

  • cats_dir (string, default=None) – Directory where to save merged catalogs.

  • save_fn (string, default=None) – File name where to save self.

export(base='input', key_input='input', key_output=None, key_distance='distance', key_matched='matched', key_injected='injected', injected=False, write=False, **kwargs_write)

Export the matched catalog obtained with match().

Parameters
  • base (string, default='input') – Base for matched catalog. Can be: - ‘input’: output columns are added to input - ‘output’: input columns are added to output - ‘inter’: as ‘input’, but matched sources only are kept - ‘extra’: keep only sources which could not be matched, in either input or output - ‘all’: stack all sources in both input and output

  • key_input (string, default='input') – If not None, prefix to add to input fields.

  • key_output (string, default=None) – If not None, prefix to add to output fields.

  • key_distance (string, default='distance') – If not None, field to save angular distance between matched input and output sources.

  • key_matched (string, default='matched') – If not None, field to save boolean mask identifying matched input and output sources.

  • key_injected (string, default='injected') – If not None, field to save boolean mask identifying injected sources.

  • injected (bool, default=False) – If True, restrict to injected sources.

  • write (bool, default=False) – Write catalog to disk.

  • kwargs_write (dict) – Arguments for write_catalog().

Returns

cat – Catalog of input - output sources.

Return type

SimCatalog

getstate()

Export self to dict.

match(radius_in_degree=0.0004166666666666667, add_input_tractor=False)

Match input to output.

Parameters
  • radius_in_degree (float, default=1.5/3600.) – Radius (degree) for input - output matching.

  • add_input_tractor (bool, string, default=False) – Passed on to setup().

plot_hist(ax, field, injected=True, xlabel=None, ylabel=None, divide_uncer=True, label_entries=True, label_mean_std=True, kwargs_xedges=None, kwargs_hist=None)

Histogram of output v.s. input differences.

Parameters
  • ax (plt.axes.Axes) – Where to plot.

  • field (string) – Name of catalog column to plot.

  • injected (bool, default=True) – If True, restrict to injected sources. Else all (actual and injected) sources are considered.

  • xlabel (string, default=None) – x-label, if None, defaults to 'input_%s' % field.

  • ylabel (string, default=None) – y-label, if None, defaults to 'output_%s' % field.

  • divide_uncer (bool, default=True) – If True, divide the difference output - input by the estimated uncertainty.

  • label_entries (bool, default=True) – If True, add the number of entries to the plot.

  • label_mean_std (bool, default=True) – If True, add the estimated mean, median, standard deviation to the plot.

  • kwargs_xedges (dict, default=None) – Arguments for Binning, to define the x-edges.

  • kwargs_hist (dict, default=None) – Extra arguments for pyplot.hist().

plot_scatter(ax, field, injected=True, xlabel=None, ylabel=None, square=False, regression=False, diagonal=False, label_entries=True, kwargs_xlim=None, kwargs_ylim=None, kwargs_scatter=None, kwargs_regression=None, kwargs_diagonal=None)

Scatter plot output v.s. input.

Parameters
  • ax (plt.axes.Axes) – Where to plot.

  • field (string) – Name of catalog column to plot.

  • injected (bool, default=True) – If True, restrict to injected sources. Else all (actual and injected) sources are considered.

  • xlabel (string, default=None) – x-label, if None, defaults to 'input_%s' % field.

  • ylabel (string, default=None) – y-label, if None, defaults to 'output_%s' % field.

  • square (bool, default=False) – If True, enforce square plot.

  • regression (bool, default=False) – If False, plot regression line.

  • diagonal (bool, default=False) – If False, plot diagonal line.

  • label_entries (bool, default=True) – If True, add the number of entries to the plot.

  • kwargs_xlim (dict, default=None) – Arguments for Binning, to define the x-range.

  • kwargs_ylim (dict, default=None) – Arguments for Binning, to define the y-range.

  • kwargs_scatter (dict, default=None) – Extra arguments for pyplot.scatter().

  • kwargs_regression (dict, default=None) – Extra arguments for pyplot.plot() regression line.

  • kwargs_diagonal (dict, default=None) – Extra arguments for pyplot.plot() diagonal line.

setstate(state)

Add state to self.

setup(add_input_tractor=False)

Add input and output Tractor catalog to self.

By default, only the sources injected by legacysim are considered for input. These can be merged to the sources detected by legacypipe by setting add_input_tractor.

Parameters

add_input_tractor (bool, string, default=False) – If True, legacypipe Tractor catalogs are added to input. In this case base_dir is considered as the legacyipe root directory. If string, specifies the path to the legacyipe root directory.

class legacysim.analysis.CatalogMerging(base_dir='.', runcat=None, bricknames=None, kwargs_simids=None, source='legacysim', cats_dir=None, save_fn=None)

Bases: object

Class to load, merge and save legacyipe and legacysim catalogs.

base_dir

See below.

Type

string

runcat

See below.

Type

RunCatalog

source

See below.

Type

string

cats

Dictionary holding catalogs.

Type

dict

cats_fn

Dictionary holdind catalog file names.

Type

dict

cats_dir

See below.

Type

string

save_fn

See below.

Type

string

Set legacysim or legacypipe file structure.

Parameters
  • base_dir (string, default='.') – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory.

  • runcat (RunCatalog, defaut=None) – Run catalog used to select files from legacysim or legacypipe data structure. If provided, supersedes bricknames and kwargs_simids.

  • bricknames (list, default=None) – List of brick names.

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file names, else legacypipe file names.

  • cats_dir (string, default=None) – Directory where to save merged catalogs.

  • save_fn (string, default=None) – File name where to save self.

get(*args, **kwargs)

Return self attribute.

get_key(filetype='tractor', source=None)

Return key to catalog in cats.

Parameters
  • filetype (string, default=None) – Type of file.

  • source (string, default=None) – If not None, supersedes self.source.

Returns

key – Key in cats.

Return type

string

getstate()

Export self to dict.

has(*args, **kwargs)

Has self this attribute?

classmethod load(save_fn)

Load self from disk.

Parameters

save_fn (string) – File name where self is saved.

merge(filetype='tractor', base_dir=None, source=None, keep_columns=None, add=False, write=False, **kwargs_write)

Merge catalogs, return the result and add to self (add == True) and/or directly write on disk (write == True).

Parameters
  • filetype (string, default='tractor') – Type of file to merge.

  • base_dir (string, default=None) – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory. If not None, supersedes base_dir.

  • source (string, default=None) – If ‘legacysim’, search for an legacysim file name, else a legacypipe file name. If not None, supersedes source.

  • keep_columns (list, default=None) – Keep only these columns.

  • add (bool, default=False) – Add merged catalog to self.

  • write (bool, default=False) – Write merged catalog to disk.

  • kwargs_write (bool) – If write, arguments to pick up catalog file name. See set_cat_fn().

Returns

cat – Merged catalog.

Return type

SimCatalog

read_catalog(add=False, **kwargs)

Read catalog from disk.

Parameters
  • add (bool, default=False) – Add catalog to self.

  • kwargs (dict) – Arguments for set_cat_fn(), to set catalog file name.

save(save_fn=None)

Save self to disk.

Parameters

save_fn (string, default=None) – File name where to save self. If not None, supersedes self.save_fn.

set(*args, **kwargs)

Set self attribute.

set_cat_fn(cat_base=None, cat_fn=None, **kwargs_key)

Set catalog file name.

Parameters
  • cat_base (string, default=None) – Catalog base name, added to cats_dir.

  • cat_fn (string, default=None) – Catalog full name. If provided, supersedes cat_base.

  • kwargs_key (bool, default={}) – Arguments to get_key().

Returns

key – Key to catalog file name in cats_fn.

Return type

string

set_catalog(name, filetype=None, source=None, **kwargs_merge)

Convenience function to add catalog to self with name name.

First try to get it from cats. Else if the file name is specified in cats_fn, read the merged catalog from disk. Else merge catalogs.

Parameters
  • name (string) – Name of the catalog to be added to self.

  • filetype (string, default=None) – Type of file to search for.

  • source (string, default=None) – If not None, supersedes source.

  • kwargs_merge (dict) – Extra arguments for merge().

setstate(state)

Add state to self.

write_catalog(cat=None, **kwargs)

Write catalog to disk.

Parameters
  • cat (SimCatalog, default=None) – Catalog to save. If None, is got from cats.

  • kwargs (dict) – Arguments for set_cat_fn(), to set catalog file name.

class legacysim.analysis.ImageAnalysis(base_dir='.', brickname=None, kwargs_simid=None, source='legacysim')

Bases: legacysim.analysis.BaseImage

Extend BaseImage with legacysim-related convenience functions.

_shape_default

Default shape.

Type

tuple

base_dir

See below.

Type

string

source

See below.

Type

string

sources

Injected sources, see read_sources().

Type

SimCatalog

Set legacysim or legacypipe file structure.

Parameters
  • base_dir (string, default='.') – legacysim or legacypipe root file directory.

  • brickname (string, default=None) – Brick name.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys keys().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file names, else legacypipe file names.

get_zooms(boxsize_in_pixels=None, full_only=False)

Return image cutouts around attr:sources.

Parameters
  • boxsize_in_pixels (int, default=None) – Box size (pixel) around the attr:sources. If None, defaults to image smaller side divided by 36.

  • full_only (bool, default=False) – Return only the cutouts which are not cropped in the edges.

Returns

  • slices (list) – List of slices (slicex,slicey), to be passed to set_subimage().

  • indices (ndarray) – If full_only == True, corresponding indices in sources.

plot_sources(ax, radius_in_pixel=11.450381679389313, dr=None, color='r')

Plot circles around sources.

Parameters
  • ax (plt.axes.Axes) – Where to plot sources.

  • radius_in_pixel (float, default=3./0.262) – Radius (pixel) around sources.

  • dr (float, default=None) – Circle width (pixel). If None, defaults to radius_in_pixel/20.

  • color (string, default='r') – Circle color.

read_image(filetype='image-jpeg', band=None)

Read legacysim image and add img to self.

Parameters
  • filetype (string, default='image-jpeg') – Image file type. See legacypipe.survey.LegacySurveyData.find_file().

  • band (list, tuple, string, default=None) – Image band(s). Only used in case the image is in ‘fits’ format. In this case, if band is a list, should be of length 3 to build up a RGB image with legacypipe.survey.get_rgb(). If None, defaults to ['g','r','z']. Else, only the image in the corresponding band is read.

read_image_wcs(filetype='image', band='g', ext=1)

Read image wcs.

Parameters
  • filetype (string, default='image-jpeg') – File type to read wcs from. See legacypipe.survey.LegacySurveyData.find_file().

  • band (string, default='g') – Image band(s). Shoud not matter.

  • ext (int, default=1) – FITS extension to read header from.

read_sources(base_dir=None, filetype='injected', source='legacysim')

Read sources in the image add sources to self.

Parameters
  • base_dir (string, defaut=None) – If not None, supersedes base_dir.

  • filetype (string, default='injected') – File type of sources. See legacysim.survey.find_file().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file name, else legacypipe file name. If not None, supersedes source.

suggest_zooms(boxsize_in_pixels=None, match_in_degree=2.777777777777778e-05, range_observed_injected_in_degree=(0.001388888888888889, 0.008333333333333333))

Suggest image cutouts around attr:sources and within some distance to Tractor sources.

Parameters
  • boxsize_in_pixels (int, default=None) – Box size (pixel) around the attr:sources; see get_zooms().

  • match_in_degree (float, default=0.1/3600) – Radius (degree) to match attr:sources to Tractor sources.

  • range_observed_injected_in_degree (tuple, list, default=(5./3600,30./3600)) – Range (degree) around the attr:sources where to find a Tractor source.

Returns

  • slices (list) – List of slices (slicex,slicey), to be passed to set_subimage().

  • indices (ndarray) – Corresponding indices in sources.

class legacysim.analysis.ResourceAnalysis(base_dir='.', runcat=None, bricknames=None, kwargs_simids=None, source='legacysim', cats_dir=None, save_fn=None)

Bases: legacysim.analysis.ResourceEventAnalysis

Extend events-only analyzes of ResourceEventAnalysis with analysis of full time series saved in ps files.

series

Concatenated time series read from ps files.

Type

SimCatalog

Set legacysim or legacypipe file structure.

Parameters
  • base_dir (string, default='.') – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory.

  • runcat (RunCatalog, defaut=None) – Run catalog used to select files from legacysim or legacypipe data structure. If provided, supersedes bricknames and kwargs_simids.

  • bricknames (list, default=None) – List of brick names.

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file names, else legacypipe file names.

  • cats_dir (string, default=None) – Directory where to save merged catalogs.

  • save_fn (string, default=None) – File name where to save self.

add_event_vlines(ax, events=None)

Plot vertical lines to indicate start of events.

Parameters
  • ax (plt.axes.Axes) – Where to plot events.

  • events (array-like, string, default=None) – Passed on to process_events().

plot_all_series(ax, events='stage', processes=None, label_entries=True, kwargs_plot=None)

Plot summary resources for all time series.

Parameters
  • ax (plt.axes.Axes) – Where to plot the time series. One can also provide figure file name fn. See legacysim.utils.saveplot().

  • events (array-like, string, default='stage') – Passed on to process_events().

  • processes (list, default=None) – Processes to plot. If None, defaults to ['main','workers']. If ‘all’, plot all processes of process_one_series().

  • label_entries (bool, default=True) – If True, add number of entries to plot.

  • kwargs_plot (dict, default=None) – Extra arguments for pyplot.plot().

plot_one_series(ax, series=None, events='stage', processes=None, kwargs_fig=None, kwargs_plot=None)

Plot resources for a single time series.

Parameters
  • ax (plt.axes.Axes) – Where to plot the time series. One can also provide figure file name fn. See legacysim.utils.saveplot().

  • series (SimCatalog, default=None) – Time series to analyze. If None, defaults to series.

  • events (array-like, string, default='stage') – Passed on to process_events().

  • processes (list, default=None) – Processes to plot. If None, defaults to ['main','workers']. If ‘all’, plot all processes of process_one_series().

  • kwargs_fig (dict, default=None) – Extra arguments for pyplot.savefig(). See legacysim.utils.saveplot().

  • kwargs_plot (dict, default=None) – Extra arguments for pyplot.plot().

process_all_series(quantities=None)

Compute average resources for all time series, split between the following categories: ‘ps’ (the process running ps), ‘main’ (the master process), ‘workers’ (non-zero in case of multithreading), ‘others’ (other processes).

Parameters

quantities (list, default=None) – Quantities to analyze. If None, defaults to ['proc_icpu','vsz'].

Returns

stats – A dictionary holding summary time series for each quantity and process category.

Return type

dict

static process_one_series(series, quantities=None)

Compute resources for a single time series, split between the following categories: ‘ps’ (the process running ps), ‘main’ (the master process), ‘workers’ (non-zero in case of multithreading), ‘others’ (other processes).

Parameters
  • series (SimCatalog) – Time series to analyze.

  • quantities (list, default=None) – Quantities to analyze. If None, defaults to ['proc_icpu','vsz'].

Returns

stats – A dictionary holding time series for each quantity and process category.

Return type

dict

class legacysim.analysis.ResourceEventAnalysis(base_dir='.', runcat=None, bricknames=None, kwargs_simids=None, source='legacysim', cats_dir=None, save_fn=None)

Bases: legacysim.analysis.CatalogMerging

Extend CatalogMerging with methods to analyze computing time based on events saved in ps files.

_sorted_events

Events sorted by chronological order.

Type

list

events

Concatenated events read from ps files.

Type

SimCatalog

Set legacysim or legacypipe file structure.

Parameters
  • base_dir (string, default='.') – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory.

  • runcat (RunCatalog, defaut=None) – Run catalog used to select files from legacysim or legacypipe data structure. If provided, supersedes bricknames and kwargs_simids.

  • bricknames (list, default=None) – List of brick names.

  • kwargs_simids (dict, list, default=None) – Single or list of get_sim_id dictionaries with keys keys().

  • source (string, default='legacysim') – If ‘legacysim’, search for legacysim file names, else legacypipe file names.

  • cats_dir (string, default=None) – Directory where to save merged catalogs.

  • save_fn (string, default=None) – File name where to save self.

plot_bar(ax, events='stage', label_entries=True, kwargs_bar=None)

Plot event mean and standard deviation in the form of a bar graph.

Parameters
  • ax (plt.axes.Axes) – Where to plot image. One can also provide figure file name fn. See legacysim.utils.saveplot().

  • events (array-like, string, default=None) – Passed on to process_events().

  • label_entries (bool, default=True) – If True, add the number of entries to the plot.

  • kwargs_bar (dict, default=None) – Extra arguments for pyplot.bar().

process_events(events=None, time='reltime', statistic='mean')

Return statistics about event durations. Assumes event are recorded at the beginning of the corresponding step.

Parameters
  • events (array-like, string, default=None) – List of events to get statistics from, e.g. ['stage_halos: starting']. See self._sorted_events. If None, consider all events. If stage, consider only starting stage events ('stage_xxx: starting').

  • time (string, default='reltime') – Time to consider for calculation. If ‘reltime’, consider the time at which events happens relative to the beginning of the run. Else, if ‘steptime’, consider the time duration of each event, i.e. the time difference between events, starting from the last time step registered for the run.

  • statistic (string, callable, default='mean') – Statistic to compute from event time, passed on to scipy.stats.binned_statistic().

Returns

events, values – Events and corresponding statistic.

Return type

ndarray

legacysim.analysis.estimate_std_outliers(samples)

Estimate the standard deviation of samples from the median of the folded distribution.

Less sensitive to outliers than standard deviation.

legacysim.scripts module

Script to check all runs have completed by verifying all files exist on disk (and optionally can be opened).

For details, run:

python check.py --help
legacysim.scripts.check.main(args=None)

Check runs.

Script to plot cpu and memory usage.

For details, run:

python resources.py --help
legacysim.scripts.resources.main(args=None)

Plot resources.

Script to merge catalogs of different bricks/runs together.

For details, run:

python merge.py --help
legacysim.scripts.merge.main(args=None)

Merge catalogs.

Script to match catalogs of input and output sources.

For details, run:

python match.py --help
legacysim.scripts.match.main(args=None)

Match input to output catalogs.

Script to produce image cutouts.

For details, run:

python cutout.py --help
legacysim.scripts.cutout.main(args=None)

Plot cutouts of sources.

Script to write run list (eventually accounting for module versions), useful when scheduling jobs.

For details, run:

python runlist.py --help
legacysim.scripts.runlist.main(args=None, force_write=False)

Produce list of runs.

legacysim.batch module

Task manager that run tasks in series.

class legacysim.batch.task_manager.BaseTaskManager

Bases: object

A dumb task manager, that simply iterates through the tasks in series.

iterate(tasks)

Iterate through a series of tasks.

Parameters

tasks (iterable) – An iterable of tasks that will be yielded.

Yields

task – The individual items of `tasks, iterated through in series.

map(function, tasks)

Apply a function to all of the values in a list and return the list of results.

If tasks contains tuples, the arguments are passed to function using the *args syntax.

Parameters
  • function (callable) – The function to apply to the list.

  • tasks (list) – The list of tasks.

Returns

results – The list of the return values of function.

Return type

list

legacysim.batch.task_manager.TaskManager(ntasks=None, **kwargs)

Switch between non-MPI (ntasks=1) and MPI task managers. To be called as:

with TaskManager(...) as tm:
    # do stuff
legacysim.batch.task_manager.run_shell(command, check=False)

Run a command in the shell, returning stdout and stderr combined.

Script to set up environment for legacysim runs.

For details, run:

python environment_manager.py --help
class legacysim.batch.environment_manager.EnvironmentManager(header=None, fn=None, base_dir=None, brickname=None, source='legacypipe', filetype=None, kwargs_simid=None, skip=False)

Bases: object

Set up environment variables for legacysim runs. To be called as:

with EnvironmentManager(...):
    # do legacysim-related stuff
header

See below.

Type

fitsio.FITSHDR

environ

Environment variables.

Type

dict

Note

Only legacypipe and legacysim versions are saved for every stage in catalog headers. Other package versions are saved at the beginning of each run (stage ‘tims’), and hence may not reflect the actual version used in any stage of the run. legacypipe catalog headers can be matched to a version of legacypipe Docker image (see get_module_version). However, for the same reason as above, this match may be ambiguous for any stage different than ‘tims’.

Initialize EnvironmentManager by reading the primary header of an output catalog.

Parameters
  • header (FITSHDR, default=None) – FITS header to read environment from. If not None, supersedes fn, base_dir, brickname, source, filetype, kwargs_simid. header is copied into header.

  • fn (string, default=None) – Name of Tractor file to read header from. If not None, supersedes base_dir, brickname, source, filetype, kwargs_simid.

  • base_dir (string, default=None) – legacysim (if source == 'legacysim') or legacypipe (if source == 'legacypipe') root file directory.

  • brickname (string, default=None) – Brick name.

  • source (string, default='legacysim') – If ‘legacysim’, search for an legacysim file name, else a legacypipe file name.

  • filetype (string, default=None) – File type to read primary header from. If None, defaults to ‘injected’ if source == 'legacysim', else ‘tractor’.

  • kwargs_simid (dict, default=None) – get_sim_id dictionary with keys keys().

  • skip (bool, default=False) – If True, do not set environment.

check_environ()

Check whether variables in environ are valid (typically if directory or file exists on disk); else fall back to os.environ.

:raises ValueError : If a variable in environ is not valid and there is no fallback value in os.environ.:

get_module_version(module, stage='writecat')

Return module version for stage.

legacypipe and legacysim runs are performed within a Docker container. To return (one of) the Docker image version that matches the module versions in the catalog header, pass module == 'docker'.

Parameters
  • module (string) – Module name. If ‘docker’, return a Docker image version by matching module versions to internal _docker_versions. If stage == 'tims' or legacypipe versions are the same for every stage up to stage, match all modules of _docker_versions; else only legacypipe version (at the given stage) is matched to _docker_versions, and the last Docker image version of the obtained matches is returned.

  • stage (string, default='writecat') – Stage name.

Returns

version – Module version.

Return type

string

get_stages_versions(modules)

Return a Stages instance with changes in module versions (at least including ‘writecat’).

Parameters

modules (list) – List of module names to get versions for.

Returns

stages – Stages with mapping (stage name, module versions).

Return type

Stages

set_environ()

Set environment variables environ.

legacysim.batch.environment_manager.get_pythonpath(module_dir='/src/', versions=(), full=False, as_string=False)

Return PYTHONPATH.

The path to ‘module’ is set to module_dir/module_version(/py for legacypipe and legacysim modules).

Parameters
  • module_dir (string, default='/src/') – Directory containing modules.

  • versions (Versions, dict, list of tuples, default=()) – (module, version) mapping.

  • full (bool, default=False) – By default, only PYTHONPATH to modules in versions is returned. If full == True, append other paths already in current PYTHONPATH.

  • as_string (bool, default=False) – By default, returned value is a list of paths. If as_string == True, return a string with paths separated by a colon ‘:’.

Returns

pythonpath – PYTHONPATH.

Return type

string, list of strings

legacysim.batch.environment_manager.main(args=None)

Print all module paths and environment variables used for the run(s).