Retargeting subtasks of tasks¶
Subtasks of tasks are dynamically retargetable, meaning that you can configure which task class is run by a parent class. Subtask retargeting is a special case of task configuration.
A common use of retargeting is to change a default subtask for a camera-specific one. For example:
lsst.obs.subaru.ampOffset.SubaruAmpOffsetTask
: a version of correcting amplifier offsets during instrument signature removal that is specific to Hyper Suprime-Cam.lsst.meas.extensions.scarlet.ScarletDeblendTask
: a multi-band deblender.
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) or as an lsst.pex.config.RegistryField
.
Both scenarios are described on this page.
How to retarget a subtask configured as a ConfigurableField with a configuration file¶
To retarget a subtask specified as an lsst.pex.config.ConfigurableField
, you must use a configuration file.
Inside a configuration file, retargeting is done in two steps:
- Import the Task class you intend to use.
- Assign that class to to the subtask configuration using the
retarget
method.
For example, to retarget the subtask named configurableSubtask
with a class FooTask
, this configuration file should contain:
from ... import FooTask
config.configurableSubtask.retarget(FooTask)
Once a subtask is retargeted, you can configure it as normal by setting attributes to configuration parameters. For example:
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
.
How to retarget a subtask configured as a RegistryField with a configuration file¶
To retarget a subtask specified as an lsst.pex.config.RegistryField
, set the field’s name
attribute in a configuration file.
Here is an example that assumes a task FooTask
is defined in module .../foo.py
and registered using name foo
:
import .../foo.py
config.registrySubtask.name = "foo"
Besides retargeting the registry subtask, there are two ways to configure parameters for tasks in a registry:
- Set parameters for the active subtask using the
RegistryField
’sactive
attribute. - Set parameters for any registered task using dictionary notation and the subtask’s registered name.
These configuration methods are described next.
Configure the active subtask configured as a RegistryField¶
You may configure the retargeted subtask in a configuration file by setting the subtask configuration’s active
attribute.
For example:
config.registrySubtask.active.subtaskParam1 = newValue
These configurations can also be specified directly on the command line if using pipetask
as a --config
argument.
For example:
--config registrySubtask.active.subtaskParam1=newValue
Configure any subtask in a registry¶
Alternatively, you can then configure parameters for any subtask in the registry using key-value access. For example:
config.registrySubtask["foo"].subtaskParam1 = newValue