1.367. select

Full Name: herschel.ia.toolbox.spectrum.SelectSpectrumTask
Alias: select
Type: Java Task - Java Task
Import: from herschel.ia.toolbox.spectrum import SelectSpectrumTask



Task for selecting individual spectra and pack them in a new so called spectrum container.

The input data with the spectra to select from can be provided in different forms: Either any data object that implements SpectrumContainer (e.g. Spectrum1d, Spectrum2d, SpectralSimpleCube) or any array of such. SpectrumContainer's provides a uniform way to access spectrum data organized in quite different structures.

For a successful processing of the task, the data included in the containers should all be consistent. This means that the number of segments found in all the spectra in the containers and their lengths should be equal; furthermore, the segment indices should be the same for all the containers (check with ds.getSegmentIndices()). Otherwise an exception is thrown.

Different schemes are available for selecting the point spectra or the segments. The most simple scheme is to specify lists of point spectrum indices (selection=[1,3,4,2]). In this case, the point spectra with corresponding indices are selected. Instead of specifying a list of indices (which requires the knowledge of these) other recipes to specify a selection are available. Typical recipes test attribute values to match certain values (e.g. selection={"bbtype":[6031, 6032]}) or to be included in a given interval (e.g. selection={"LoFrequency":(999.98,1000.02)}). These recipes we refer to as selection models. See also the URM entries on SpectrumContainer and PointSpectrum for more information. The available attributes can be checked by writing print ds.getAttributeNames() on the command line. Selections can be formulated only for attributes with primitive data type (i.e. double, long, int or string).

The different options to specify selections can be combined. Here, an AND logic is adopted. See the parameter descriptions and the examples below for further detail. Yet another alternative is to use segments where you specify which subsegments are selected from all the input spectra.

Note that when a list of input spectrum container is specified and the segments and selection parameter refer to all containers. You cannot specify specific selection and segments parameters for each input container. Apply the task for each individual container if you want to do that.


Example 1: selection examples
global spectra # defined elsewhere
from herschel.ia.toolbox.spectrum import SelectSpectrumTask
from herschel.ia.toolbox.spectrum.selections.models import RangesSelectionModel
select = SelectSpectrumTask()
# select from all the spectra the segments, here we only ask for the first segment
selected = select(ds=spectra, segments=[0])
# select the spectra that have a 'bbtype' attribute set to 6031 or 6613 AND a 'buffer' attribute set to 2
selected = select(ds=spectra, selection={"bbtype":[6031, 6613], "buffer":[2]})
# select the first four spectra
selected = select(ds=spectra, selection=[0,2])
# select the spectra that have a 'LoFrequency' attribute in the range (550.0,570.0).
selected = select(ds=spectra, selection={"LoFrequency":(550.0,570.0)}) 
# select the spectra that have a 'Chopper' attribute centered within a tolerance of 0.1 around -4.4 or 5.9.
selected = select(ds=spectra, selection={"Chopper":([-4.4,5.9],0.1)})
from herschel.ia.toolbox.spectrum.selections.models import RangesSelectionModel
selected = select(ds=spectra, selection=RangesSelectionModel("Chopper", [-4.4,5.9], 0.1)) # same result as above
# note: for cubes you can specify the selection by spaxel coordinates - just pass a list of tuples (col,row) 
# where 'col' is the column and 'row' the row index:
## spectraOut = select(ds=spectra, selection=[(1,3),(0,4),(4,3)])

API details


Object ds [INPUT, OPTIONAL, default=no default value.]

Input data to be processed by the task. Several types are possible:

  • SpectrumContainer

  • Array of SpectrumContainer, i.e. SpectrumContainer[] (e.g. [ds1,ds2,ds3])

  • List of SpectrumContainer, i.e. List<SpectrumContainer>

  • (Any product with implementations of SpectrumContainer inside.)

Examples of SpectrumContainer are Spectrum1d, Spectrum2d, SpectralSimpleCube.

Object segments [INPUT, OPTIONAL, default=no default value.]

Specify what segments to restrict on. There are two options available:

  • Specify a PyList of segment indices or

  • pass an instance of a SegmentSelection which gives the information on what segments for each point spectrum included in the container.

Object selection [INPUT, OPTIONAL, default=None.]

Specification of what point spectra select. Different ways to specify these selections are possible:

  • Specify a list of indices (in jython) of the point spectra to select. For cubes, you can alternatively also pass a list of spaxel coordinates (a list of integer tuples (row,col)).

  • Use a dictionary (in jython) to specify a selection model (lookup for attributes, filter attributes to be included in ranges or intervals).

  • Pass a string representation of a jython list or a jython dictionary. The string will be parsed and the processing delegated to the two cases above.

  • Pass any java instance that implements the SelectionModel interface (for the advanced user).

See the examples below for how to specify selections according to the first two bullets.

PyDictionary|Map&amp;lt;String,Set&amp;lt;Object&amp;gt;&amp;gt; lookup_selection [INPUT, OPTIONAL, default=no default value.]

Specify a PyDictionary with keys given by the attribute name to look up and a list of admissible values. Behind the scenes, a DiscreteValueSelectionModel is instantiated. This parameter is actually obsolete but is kept for historical reasons (use selection).

PyList index_selection [INPUT, OPTIONAL, default=No default value.]

Specify a PyList with the indices of the point spectra to be considered. This parameter is actually obsolete but is kept for historical reasons (use selection).

PyDictionary meta_selection [INPUT, OPTIONAL, default=No default value.]

Specify criteria to restrict the operation on spectrum containers that have meta data matching given values. This only applies in case more than one container is passed as input data to the task.

SpectrumContainer result [OUTPUT, OPTIONAL, default=no default value ]

Result object containing the results of the operation applied.

See also


  • 2011-08-08 - melchior: renamed from SelectSpectrum
  • 2011-09-28 - melchior: add selection by spaxels - tuples (row,col).