LSSTApplications  11.0-22-g33de520,13.0+130,14.0+24,14.0+27,14.0-1-g013352c+7,14.0-1-g13ef843+8,14.0-1-g4b114ac+9,14.0-1-g7257b6a+8,14.0-1-g8b7e855+23,14.0-10-ga7aaa25+4,14.0-12-g233aa8e+5,14.0-14-g87d16e8+5,14.0-18-g0eec5f5+6,14.0-2-g0af5a6c+23,14.0-2-g319577b+6,14.0-2-g8373656+6,14.0-2-ga5af9b6+6,14.0-25-g0e8fc950e+7,14.0-29-g442e3e1b,14.0-4-g4cc409d+13,14.0-4-ge2d7f21+6,14.0-5-g86eb1bd+3,14.0-6-g4f52afe+5,14.0-6-ge2c9487+14,14.0-6-gf4bc96c+23,14.0-8-g7f6dd6b+5,14.0-8-gf6dacf9e+1
LSSTDataManagementBasePackage
lsst::pipe::base; Base package for pipeline tasks

Contents

Introduction

lsst::pipe::base provides a data processing pipeline infrastructure. Data processing is performed by "tasks", which are instances of Task or CmdLineTask. Tasks perform a wide range of data processing operations, from basic operations such as assembling raw images into CCD images (trimming overscan), fitting a WCS or detecting sources on an image, to complex combinations of such operations.

Tasks are hierarchical. Each task may may call other tasks to perform some of its data processing; we say that a "parent task" calls a "subtask". The highest-level task is called the "top-level task". To call a subtask, the parent task constructs the subtask and then calls methods on it. Thus data transfer between tasks is simply a matter of passing the data as arguments to function calls.

Command-line tasks are tasks that can be run from the command line. You might think of them as the LSST equivalent of a data processing pipeline. Despite their extra capabilities, command-line tasks can also be used as ordinary tasks and called as subtasks by other tasks. Command-line tasks are subclasses of CmdLineTask.

Each task is configured using the pex_config package, using a task-specific subclass of pex.config.config.Config. The task's configuration includes all subtasks that the task may call. As a result, it is easy to replace (or "retarget") one subtask with another. A common use for this is to provide a camera-specific variant of a particular task, e.g. use one version for SDSS imager data and another version for Subaru Hyper Suprime-Cam data).

Tasks may process multiple items of data in parallel, using Python's multiprocessing library. Support for this is built into the ArgumentParser and TaskRunner.

Most tasks have a run method that performs the primary data processing. Each task's run method should return a Struct. This allows named access to returned data, which provides safer evolution than relying on the order of returned values. All task methods that return more than one or two items of data should return the data in a Struct.

Many tasks are found in the pipe_tasks package, especially tasks that use many different packages and don't seem to belong in any one of them. Tasks that are associated with a particular package should be in that package; for example the instrument signature removal task ip.isr.isrTask.IsrTask is in the ip_isr package.

pipe_base is written purely in Python. The most important contents are:

Running Command-Line Tasks

Each command-line task typically has a short "task runner script" to run the task in the bin/ directory of whatever package the task is defined in. This section deals with the command-line options of these task runner scripts.

Specify --help to print help. When in doubt give this a try.

The first argument to a task must be the path to the input repository (or --help). For example:

--output specifies the path to the output repository. Some tasks also support --calib: the path to input calibration data. To shorten input, output and calib paths see Environment Variables.

Data is usually specified by the --id argument with key=value pairs as the value, where the keys depend on the camera and type of data. If you run the task and specify both an input data repository and --help then the printed help will show you valid keys (the input repository tells the task what kind of camera data is being processed). See Specifying Data IDs for more information about data IDs. A few tasks take more than one kind of data ID, or have renamed the --id argument; run the task with --help or see the task's documentation for details.

You may show the config, subtasks and/or data using --show. By default --show quits after printing the information, but --show run allows the task to run. For example:

For long or repetitive command lines you may wish to specify some arguments in separate text files. See Argument Files for details.

Specifying Data IDs

--id and other data identifier arguments are used to specify IDs for input and output data. The ID keys depend on the camera and on the kind of data being processed. For example, lsstSim calibrated exposures are identified by the following keys: visit, filter, raft and sensor (and a given visit has exactly one filter).

Omit a key to specify all values of that key. For example, for lsstSim calibrated exposures:

To specify multiple data IDs you may separate values with ^ (a character that does not have special meaning to the unix command parser). The result is the outer product (all possible combinations). For example:

You may specify a data identifier argument as many times as you like. Each one is treated independently. Thus the following example specifies all sensors for four combinations of visit and raft, plus all sensors for one raft of two other visits for calibrated lsstSim data:

The --rerun Option

The --rerun option is an alternate way to specify the output and, optionally, input repositories for a command line task. Unlike --output, the value supplied to --rerun is relative to the rerun directory of the root input data repository (i.e. follow the chain of parent repositories—indicated by files in the repository root named _parent—all the way back, then add rerun to that). --rerun saves the user from typing in the input repository twice. For example,

processCcd.py $root/hsc --output $root/hsc/rerun/Vishal/aRerun

which (for some semantically insignificant version of $root) will run processCcd.py on the data in $root/hsc and put the output in $root/hsc/rerun/Vishal/aRerun, can be shortened by using --rerun to

processCcd.py $root/hsc --rerun Vishal/aRerun

This is useful because outputs from the pipeline are conventionally placed in a subdirectory of a "rerun" directory present in a per-camera root repository. For example:

Additionally, --rerun path1:path2 will read from the rerun specified by path1 and write to the rerun specified by path2. This is referred to as "chaining" reruns. For example:

processCcd.py $root/hsc --rerun Paul/procCcds ... # Paul processes some CCDs.
makeCoaddTempExp.py $root/hsc --rerun Paul/procCcds:Jim/coaddRerun ... # Jim uses Paul's CCD processing
# to start building a coadd.

Note that:

Argument Files

You may specify long or repetitive command-line arguments in text files and reference those files using @path.

The contents of the files are identical to the command line, except that long lines must not have a \ continuation character. For example if the file foo.txt contains:

--id visit=54123^55523 raft=1,1^2,1
--config someParam=someValue --configfile configOverrideFilePath

you can then reference it with @foo.txt and mix that with other command-line arguments (including --id and --config):

myTask.py inputPath @foo.txt --config anotherParam=anotherValue --output outputPath

Overriding Configuration Parameters

The argument parser automatically loads specific configuration override files based on the camera name and its obs_ package. See Automatically Loaded Config Override Files. The format of a configuration override file matches the configuration shown using --show config (in particular, note that config in a configuration override file is the word that matches self.config in a task when the task uses its config).

In addition, you can specify configuration override files on the command line using --configfile and override some (but not all) configuration parameters directly on the command line using --config, as shown in these examples:

Note
config in a configuration override file is equivalent to self.config in a task.

You can use a config file (e.g. as specified by --configfile) to override any config parameter, but the simpler --config command-line option has significant limitations:

See Retargeting Subtasks for more information about overriding configuration parmaters in subtasks.

Retargeting Subtasks

As a special case of overriding configuration parameters, users may replace one subtask with another; this is called "retargeting" the subtask. One common use case is to use a camera-specific variant of a subtask. Examples include:

How you retarget a subtask and override its config parameters depends on whether the task is specified as an lsst.pex.config.ConfigurableField (the most common case, and the source of the term "retarget") or as an lsst.pex.config.RegistryField.

To override a subtask specified as an lsst.pex.config.ConfigurableField use retarget method of the field. To override config parameters use simple dotted notation. Here is an example:

    # Example of retargeting a subtask and overriding its configuration
    # for a subtask specified by an lsst.pex.config.ConfigurableField
    # import the task and then retarget it
    from ... import FooTask
    config.configurableSubtask.retarget(FooTask)
    # override a config parameter
    config.configurableSubtask.subtaskParam1 = newValue
Warning
when you retarget a task specified by an lsst.pex.config.ConfigurableField you lose all configuration overrides for both the old and new task. This limitation is not shared by lsst.pex.config.RegistryField.

To retarget a subtask specified as an lsst.pex.config.RegistryField set the name property of the field. There are two ways to override configuration parameters for tasks in a registry: you may set parameters for the active task using the registry field's active parameter, and you may set parameters for any registered task using dictionary notation and the name by which the task is registered. Here is an example that assumes a task FooTask is defined in module .../foo.py and registered using name "foo". :

    # Example of retargeting a subtask and overriding its configuration
    # for a subtask specified by an lsst.pex.config.RegistryField
    # Import the task's module, so the task registers itself,
    # then set the name property of the field to the name by which FooTask is registered:
    import .../foo.py
    config.registrySubtask.name = "foo"
    # You can override the active subtask's configuration using attribute `active`
    config.registrySubtask.active.subtaskParam1 = newValue
    # Such overrides can also be specified on the command line, e.g.
    # --config registrySubtask.active.subtaskParam1 = newValue
    # You can also override parameters in any subtask in the registry using dictionary access,
    # but this can only be done in a config override file, not on the command line:
    config.registrySubtask["foo"].subtaskParam1 = newValue

Specifying Debug Variables

Some tasks support debug variables that can be set, while running from the command line, to display additional information. Each task documents which debug variables it supports. See Using lsstDebug to control debugging output for information about how to enable specific debug variables while running from the command line.

Automatically Loaded Config Override Files

When a pipeline task is run, two camera-specific configuration override files are loaded, if found; first one for the obs_ package then one for the camera. (There are two because some obs_ packages contain data for multiple cameras). These files may override configuration parameters or even retarget subtasks with camera-specific variants (e.g. for instrument signature removal). The configuration override files are, in order:

where the path elements are:

Here are two examples:

Environment Variables

The command parser uses environment variables PIPE_INPUT_ROOT, PIPE_CALIB_ROOT, and PIPE_OUTPUT_ROOT, if available, to make it easier to specify the input, calib and output data repositories. Each environment variable is used as a root directory for relative paths and ignored for absolute paths. The default value for each of these environment variables is the current working directory. For example:

Other Resources

pipe_tasks introduction includes links to: