Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can read the introduction here: Input Preprocessor

  1. Create the script mentioned in the chimera_config.yaml file under the preprocessor.module_path.

  2. In the script, declare the subclass mentioned in the chimera_config.yaml file under the preprocessor.class_name

  3. Start with the following code snippet:

    Code Block
    languagepy
    # import the parent class from chimera
    from chimera.precondition_functions import PreConditionFunctions
    
    # declare the sub class
    class <class_name>(PreConditionFunctions):
        def __init__(self, context, pge_config, settings, job_params):
            PreConditionFunctions.__init__(self, context, pge_config, settings, job_params)

    The variables you have available throughout this subclass are:

    • Context - contents of _context.json of the SciFlo job. You can access it as self._context in the precondition functions

    • PGE’s configuration - contents of the respective PGE’s configuration file. Can be accessed as self._pge_config

    • Settings file - content of settings.yaml file accessible as self._settings

    • Job Params - This is a dictionary that stores all the information gathered during preconditions evaluation. How to utilize it will be described soon. It can be accessed as self._job_params

...

  1. Make sure to import the constants files

    Code Block
    from commons.constants import product_metadata
    from nisar_chimera.constants.nisar_chimera_const import NisarChimeraConstants as nc_const
  2. Use self as the input parameter for every function, so you have access to everything coming into  the preconditions subclass

  3. Implement code evaluate the precondition:

    1. Gather the information you need to construct your condition:

      If you need to utilize information from the sciflo context
      e.g. if you need to get the range beginning and ending times of the input product then use the self._context dict and the key from the Products Metadata constants file you need like, product_metadata.RANGE_BEGINNING_DATETIME  to retrieve the value: self._context.get(product_metadata.RANGE_BEGINNING_DATETIME)

      If you need to use information retrieved by a previously executed precondition, it will be available in the job_params, so use the key name mentioned in the Chimera Constants File or Products Metadata file that matches the key name in the job_params dict and access it as:
      self._job_params.get(key_name)

      If you need information from the PGE Config File then you can access it with the key name found in the Chimera Constants File as: self._pge_config.get(nc_const.KEY_NAME)

      If you need to get information from the settings file, for example getting the CRID:
      then you can do something like crid = self._settings.get(nc_const.CRID)

    2. For executing queries, construct the ES query and execute it by calling the requires ES function available through the ancillary utilities <link>.

      Process the results of the executed query as needed.

  4. The return statement of the precondition is very important. You must return a dictionary. This dictionary gets appended to the self._job_params variable. The job params is the dictionary that is used to fill up the null fields of the runconfig.

    The keys of the dictionary must match the field name in the runconfig exactly.