LSSTApplications  16.0-1-gce273f5+18,16.0-10-gc1446dd+17,16.0-12-g569485f+1,16.0-12-g6065a46,16.0-13-g5e87145+1,16.0-13-g80874fd,16.0-13-gb122224+8,16.0-13-gd9b1b71+17,16.0-14-g08f9460,16.0-15-g77ef378+3,16.0-16-gf910c00+1,16.0-17-g0bdc215+10,16.0-17-g6a7bfb3b+17,16.0-2-g0febb12+14,16.0-2-g839ba83+55,16.0-2-g9d5294e+43,16.0-2-gc6e0ed0+1,16.0-21-g8fa7d5a4,16.0-3-g404ea43+10,16.0-3-gbc759ec+15,16.0-3-gcfd6c53+41,16.0-4-g03cf288+32,16.0-4-g13a27c5+18,16.0-4-g5f3a788+13,16.0-4-g8a0f11a+39,16.0-4-ga3eb747+3,16.0-5-g1991253+17,16.0-5-g1e9226d+1,16.0-5-g865efd9+18,16.0-5-gb3f8a4b+49,16.0-5-gd0f1235+7,16.0-51-gb4b4a8566,16.0-6-gf9cb114+19,16.0-7-g6043bfc+5,16.0-7-ga8e1655+13,16.0-7-gde5bd64,16.0-8-g4dec96c+30,16.0-8-gfd407c0+3,16.0-9-g2f60796,master-g5768c874b9+2,w.2018.41
LSSTDataManagementBasePackage
How to Write a Command-Line Task

This document describes how to write a command-line task, which is the LSST version of a complete data processing pipeline.

To create a command-line task you will benefit from some background:

Contents

Introduction

A command-line task is an enhanced version of a regular task (see How to Write a Task). Regular tasks are only intended to be used as relatively self-contained stages in data processing pipelines, whereas command-line tasks can also be used as complete pipelines. As such, command-line tasks include Run Script that run them as pipelines.

Command-line tasks have the following key attributes, in addition to the attributes for regular tasks:

Run Script

A command-line task can be run as a pipeline via run script. This is usually a trivial script which merely calls the task's parseAndRun method. parseAndRun does the following:

examples/exampleCmdLineTask.py, the runner script for ExampleCmdLineTask, is typical:

For most command-line tasks you should put the run script into your package's bin/ directory, so that it is on your $PATH when you setup your package with eups. We did not want the run script for ExampleCmdLineTask to be quite so accessible, so we placed it in the examples/ directory instead of bin/.

Remember to make your run script executable using chmod +x.

Reading and Writing Data

The runDataRef method typically receives a single data reference, as mentioned above. It read and writes data using this data reference (or the underlying butler, if necessary).

Adding Dataset Types

Every time you write a task that writes a new kind of data (a new "dataset type") you must tell the butler about it. Similarly, if you write a new task for which you want to save configuration and metadata (which is the case for most tasks that process data), you have to tell the butler about it.

To add a dataset, edit the mapper configuration file for each obs_ package on whose data the task can be run. If the task is of general interest (wanted for most or all obs_ packages) then this process of updating all the mapper configuration files can be time consuming.

There are plans to change how mappers are configured. But as of this writing, mapper configuration files are contained in the policy directory of the obs_ package. For instance the configuration for the lsstSim mapper is defined in obs_lsstSim/policy/LsstSimMapper.paf.

Persisting Config and Metadata

Normally when you run a task you want the configuration for the task and the metadata generated by the task to be saved to the data repository. By default, this is done automatically, using dataset types:

where _DefaultName is the value of the task's _DefaultName class variable.

Whether you use these default dataset types or customize the dataset types, you will have to add dataset types for the configuration and metadata.

Customizing Config and Metadata Dataset Types

Occasionally the default dataset types for configuration and metadata are not sufficient. For instance in the case of the pipe.tasks.MakeSkyMapTask and various co-addition tasks, the co-add type must be part of the config and metadata dataset type name. To customize the dataset type of a task's config or metadata, define task methods _getConfigName and _getMetadataName to return the desired names.

Prevent Saving Config and Metadata

For some tasks you may wish to not save config and metadata at all. This is appropriate for tasks that simply report information without saving data. To disable saving configuration and metadata, define task methods _getConfigName and _getMetadataName methods to return None.

Custom Argument Parser

The default argument parser returned by CmdLineTask._makeArgumentParser assumes that your task's run method processes raw or calibrated images. If this is not the case you can easily provide a modified argument parser.

Typically this consists of constructing an instance of lsst.pipe.base.ArgumentParser and then adding some ID arguments to it using ArgumentParser.add_id_argument. This is shown in several examples below. Please resist the urge to add other kinds of arguments to the argument parser unless truly needed. One strength of our tasks is how similar they are to each other. Learning one set of arguments suffices to use many tasks.

Warning
If your task requires a custom argument parser to do more than just change the type of the single data reference, then it also require a custom task runner, as well.

Here are some examples:

Custom Task Runner

The standard task runner is lsst.pipe.base.TaskRunner. It assumes that your task's runDataref method wants a single data reference and nothing else. If your task uses the pre-2018 naming convention and has a run method that operates on a data references instead of a runDataRef method, you can still use this as a CmdLineTask by using the lsst.pipe.base.LegacyTaskRunner, which will call your task's run method. If neither of those are the case then you will have to provide a custom task runner for your task. This involves writing a subclass of lsst.pipe.base.TaskRunner and specifying it in your task using the RunnerClass Class Variables" class variable".

Here are some situations where a custom task runner is required: