Source code for sofia_redux.instruments.hawc.stepmiparent
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Pipeline step that processes multiple input objects."""
import os
import re
from astropy import log
from sofia_redux.instruments.hawc.dataparent import DataParent
from sofia_redux.instruments.hawc.stepparent import StepParent
__all__ = ['StepMIParent']
[docs]
class StepMIParent(StepParent):
"""
Pipeline step parent class for multiple input files.
This class defines a pipeline step that expects a list of
input data objects, and produces a single output data object
(multiple-in, single-out (MISO) mode).
"""
def __init__(self):
# call superclass constructor (calls setup)
super().__init__()
# Change datain
self.datain = [DataParent()]
# set iomode
self.iomode = 'MISO'
# add a filenum list, for output filenames
self.nfiles = 0
self.filenum = []
[docs]
def setup(self):
"""
Set parameters and metadata for the pipeline step.
See `sofia_redux.instruments.hawc.stepparent.StepParent.setup`
for more information.
"""
# Name of the pipeline reduction step
self.name = 'parentmi'
self.description = 'Multi-in Step Parent'
# Shortcut for pipeline reduction step and identifier for
# saved file names.
self.procname = 'unk'
# Clear Parameter list
self.paramlist = []
[docs]
def run(self):
"""Run the data reduction algorithm."""
# Return the first datain element
self.dataout = self.datain[0]
[docs]
def runstart(self, data, arglist):
"""
Initialize the pipeline step.
Checks the input data list, storing file numbers extracted
from the input file names, then calls the parent runstart
method.
Parameters
----------
data : DataFits or DataText
Input data to validate.
arglist : dict
Parameters to pass to the step.
"""
# Keep a list of input file numbers for output filename
self.filenum = []
# Check input data - should be a list/tuple with PipeData objects
if isinstance(data, (list, tuple)):
for d in data:
if not isinstance(d, DataParent):
msg = 'Invalid input data type: Pipe Data ' \
'object is required'
log.error(msg)
raise TypeError('Runstart: ' + msg)
# try to read numerical file number from input name
if '-' in str(d.filenum):
fn = str(d.filenum).split('-')
else:
fn = [d.filenum]
for f in fn:
try:
# test if it is a valid number
int(f)
# append the string version if it is
self.filenum.append(f)
except (ValueError, TypeError):
pass
else:
msg = 'Invalid input data type: List object is required'
log.error(msg)
raise TypeError('Runstart: ' + msg)
# Call parent runstart
super().runstart(data[0], arglist)