Skip to content
Snippets Groups Projects
Select Git revision
  • b2310c31ae80add8ae9ba2870ca0fa3a7dfdfa1d
  • master default protected
  • gec-94-bdaddecal-fixes
  • gec-94-changelog
  • integrate_predict_library
  • svp_cobalt
  • merl-112-python-release-the-gil
  • gec-94-total-bda-factor
  • merl-105-dp3-python-move-not-copy
  • rap-1132-create-dynspec-step
  • padre-filestream-input
  • ast-1238-use-xtensor-char
  • gec-110-step-infoin
  • new-everybeam-interface
  • rap-1044-data-interpolation-step
  • fix-ddecal-docs
  • two-step-faraday-constraint
  • line-search
  • azelgeo-revised
  • SVP
  • test_everybeam_multifreq
  • v6.4.1
  • v6.4
  • v6.3
  • v6.2.1
  • v6.2
  • v6.1
  • v6.0.1
  • v6.0
  • v5.3
  • v5.2
  • v5.1
  • v5.0
  • v4.2
  • v4.1
  • v4.0
  • LOFAR-Release-3_1_0
  • LOFAR-Release-3_1_1
  • LOFAR-Release-3_1_2
  • LOFAR-Release-3_1_3
  • LOFAR-Release-3_1_4
41 results

mockpystep.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    mockpystep.py 2.34 KiB
    # Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
    # SPDX-License-Identifier: GPL-3.0-or-later
    
    # MockPyStep.py: simple python step, where the MockPyStep inherits from
    # the (py)dp3.DPStep class.
    
    from dp3 import parameterset
    from dp3 import Step, Fields
    import numpy as np
    
    
    class MockPyStep(Step):
        """Example python DPStep that multiplies DATA and WEIGHT_SPECTRUM"""
    
        def __init__(self, parset, prefix):
            """
            Set up the step (constructor). Read the parset here.
    
            Args:
              parset: Parameter set for the entire pipeline
              prefix: Prefix for this step, e.g. "thisstepname."
            """
            super().__init__()
            self.datafactor = parset.getDouble(prefix + "datafactor")
            self.weightsfactor = parset.getDouble(prefix + "weightsfactor")
    
        def update_info(self, dpinfo):
            """
            Process metadata. This will be called before any call to process.
    
            Args:
              dpinfo: DPInfo object with all metadata, see docs in pydp3.cc
            """
            super().update_info(dpinfo)
    
            # Make sure data is read
            self.info().set_need_vis_data()
    
        def show(self):
            """Print a summary of the step and its settings"""
            print("\nMockPyStep")
            print(f"  data factor:    {self.datafactor}")
            print(f"  weights factor: {self.weightsfactor}")
    
        def get_required_fields(self):
            return Fields.DATA | Fields.WEIGHTS
    
        def get_provided_fields(self):
            # The Flags field is added as provided fields only for testing purposes.
            return Fields.DATA | Fields.FLAGS | Fields.WEIGHTS
    
        def process(self, dpbuffer):
            """
            Process one time slot of data. This function MUST call process_next_step.
    
            Args:
              dpbuffer: DPBuffer object which can contain data, flags and weights
                        for one time slot.
            """
    
            data = np.array(dpbuffer.get_data(), copy=False)
            weights = np.array(dpbuffer.get_weights(), copy=False)
    
            # Do the operation on data
            data *= self.datafactor
            weights *= self.weightsfactor
    
            # Send processed data to the next step
            self.process_next_step(dpbuffer)
    
        def finish(self):
            """
            If there is any remaining data, process it. This can be useful if the
            step accumulates multiple time slots.
            """
            pass