nenupy.io.tf.TFPipeline

class nenupy.io.tf.TFPipeline(data_obj, *tasks)[source]

Bases: object

Class to manage the series of tasks designed to be applied to time-frequency data.

__init__(data_obj, *tasks)[source]

Generate an instance of TFPipeline.

Parameters:
  • data_obj (Spectra) – An instance of Spectra needed to determine the properties of the corresponding data file.

  • *tasks (TFTask) – A sequence of tasks that will be applied when the run() method is called.

Methods

__init__(data_obj, *tasks)

Generate an instance of TFPipeline.

append(operation)

Append a pipeline task at the end of the list of planned tasks.

contains(task_name)

Check if the pipeline contains a TFTask named task_name.

info([return_str])

Display the current pipeline configuration.

insert(operation, index)

Insert a pipeline task at a given position among the list of planned tasks.

remove(*args)

Remove a task from the list.

run(time_unix, frequency_hz, data)

Run all the tasks registered in the pipeline.

set_default()

Set the default pipeline.

Attributes

parameters

Attribute listing all the available parameters.

append(operation)[source]

Append a pipeline task at the end of the list of planned tasks.

Parameters:

operation (TFTask) – The task to perform.

Raises:

TypeError – If operation is not a TFTask.

contains(task_name)[source]

Check if the pipeline contains a TFTask named task_name.

Parameters:

task_name (str) – Name of the TFTask.

Returns:

Whether the task is present or not.

Return type:

bool

Example

>>> from nenupy.io.tf import Spectra, TFPipeline
>>> pipeline = TFPipeline( Spectra("/my/file.spectra") )
>>> pipeline.contains("Correct bandpass")
True
info(return_str=False)[source]

Display the current pipeline configuration. The tasks are ordered as they will be applied. Tasks in parenthesis are not considered ‘activated’. This can happen because the task is looking for an argument in parameters whose value does not fulfill the requirements.

Parameters:

return_str (bool, optional) – Return the information message as a string variable, by default False.

Returns:

If return_str is set to True, the message is returned as a string variable.

Return type:

str

Example

>>> from nenupy.io.tf import Spectra, TFPipeline, TFTask
>>> sp = Spectra("/my/file.spectra")
>>> pipeline = TFPipeline(sp, TFTask.correct_bandpass(), TFTask.correct_faraday_rotation())
>>> pipeline.info()
Pipeline configuration:
    0 - Correct bandpass
    (1 - Correct faraday rotation)
insert(operation, index)[source]

Insert a pipeline task at a given position among the list of planned tasks.

Parameters:
  • operation (TFTask) – The task to perform.

  • index (int) – Index at which the operation should be inserted (see list.insert()).

Raises:

TypeError – If operation is not a TFTask.

property parameters

Attribute listing all the available parameters. Each time a TFTask is run, its update() method is called and this parameter list is passed.

Returns:

Pipeline parameters.

Return type:

TFPipelineParameters

remove(*args)[source]

Remove a task from the list.

Parameters:

*args (str or int) – If an integer is found, the task indexed at the corresponding value will be removed. If a string is found, the first instance of the TFTask whose name corresponds to arg will be removed.

Raises:

TypeError – If args contains any item that is neither int nor str.

Example

>>> from nenupy.io.tf import Spectra, TFPipeline, TFTask
>>> pipeline = TFPipeline( Spectra("/my/file.spectra") )
>>> pipeline.set_default()
>>> pipeline.info()
Pipeline configuration:
    0 - Correct bandpass
    (1 - Remove subband channels)
    (2 - Rebin in time)
    (3 - Rebin in frequency)
    4 - Compute Stokes parameters
>>> pipeline.remove("Rebin in frequency", 1)
>>> pipeline.info()
Pipeline configuration:
    0 - Correct bandpass
    (1 - Rebin in time)
    2 - Compute Stokes parameters
run(time_unix, frequency_hz, data)[source]

Run all the tasks registered in the pipeline.

Parameters:
  • time_unix (ndarray) – Original array of time samples in Unix format (should match the first dimension of data).

  • frequency_hz (ndarray) – Original array of frequency samples in Hz (should match the second dimension of data)

  • data (Array) – Original data array, its shape should be (time, frequency, 2, 2).

Returns:

Returns quantities equivalent to the inputs. The sizes of time_unix and frequency_hz may have change (if rebinning steps have been included in the pipeline for instance). The first two dimensions of data should still match those of time_unix and frequency_hz. The last dimensions depend on the polarization computation.

Return type:

(ndarray, ndarray, Array)

set_default()[source]

Set the default pipeline. This will reset any existing list of TFTask. This method also reset the parameters configuration (listed in parameters). The list of tasks is: