Skip to content
Snippets Groups Projects
Controller.py 1.29 KiB
Newer Older
"""Conrtoller class for geomag algorithms"""
class Controller(object):
    """Controller for geomag algorithms.

    Parameters
    ----------
Hal Simpson's avatar
Hal Simpson committed
    inputFactory: TimeseriesFactory
        the factory that will read in timeseries data
Hal Simpson's avatar
Hal Simpson committed
    outputFactory: TimeseriesFactory
        the factory that will output the timeseries data
    algorithm: the algorithm(s) that will take procees the timeseries data
    """
    def __init__(self, inputFactory, outputFactory, algorithm):
Hal Simpson's avatar
Hal Simpson committed
        self._inputFactory = inputFactory
        self._algorithm = algorithm
        self._outputFactory = outputFactory

    def run(self, starttime, endtime):
        """run an algorithm as setup up by the main script.

        Parameters
        ----------
        starttime : UTCDateTime
            time of first sample to be worked on.
        endtime : UTCDateTime
            time of last sample to be worked on.
        """
Hal Simpson's avatar
Hal Simpson committed
        input_channels = self._algorithm.get_input_channels()
        timeseries = self._inputFactory.get_timeseries(starttime, endtime,
                channels=input_channels)
        processed = self._algorithm.process(timeseries)
Hal Simpson's avatar
Hal Simpson committed
        output_channels = self._algorithm.get_output_channels()
        self._outputFactory.put_timeseries(timeseries=processed,
                channels=output_channels)