arts_agenda

pyarts.workspace.arts_agenda(func=None, *, ws=None, allow_callbacks=False, set_agenda=False)[source]

Decorator to parse a Python method as ARTS agenda

This decorator can be used to define ARTS agendas using python function syntax. The function should have one arguments which is assumed to be a Workspace instance. All expressions inside the function must be calls to ARTS WSMs. The function definition results in an Agenda object that can be copied into an ARTS agenda.

Example:

ws = pyarts.workspace.Workspace()

@pyarts.workspace.arts_agenda(ws=ws)
def iy_main_agenda_clearsky(ws):
    ws.ppathCalc()
    ws.iyClearsky()
    ws.VectorSet(ws.geo_pos, [])

ws.iy_main_agenda = iy_main_agenda_clearsky

Or, by passing set_agenda=True, write the agenda directly to the workspace (allowing initiating automatic checking if the agenda is a defined workspace agenda):

ws = pyarts.workspace.Workspace()

@pyarts.workspace.arts_agenda(ws=ws, set_agenda=True)
def iy_main_agenda(ws):
    ws.ppathCalc()
    ws.iyClearsky()
    ws.VectorSet(ws.geo_pos, [])

When the decorator is used with the allow_callbacks keyword argument set to True, arbitrary Python code can be executed within the callback. Note, however, that ARTS ignores exceptions occurring within the callback, so care must be taken that potentially silenced errors don’t interfere with simulation results.

Warning

Using allow_callbacks=True breaks the Agenda input-output control. It is therefore considered undefined behavior if you manipulate workspace variables that are neither in- nor output of the Agenda using callbacks. Do this at your own risk.

Example:

ws = pyarts.workspace.Workspace()

@pyarts.workspace.arts_agenda(ws=ws, allow_callbacks=True)
def python_agenda(ws):
    print("Python says 'hi'.")

A special INCLUDE(path) directive can be part of the function definitions to use the Arts parser of .arts files to be invoked on the file. All methods and invokations that are part of the .arts file are appended in place to the agenda

To predefine an agenda before a workspace is created, for instance for use with multiple workspaces later, use the DelayedAgenda class. A DelayedAgenda is created by omitting the ws keyword argument:

@pyarts.workspace.arts_agenda
def iy_main_agenda_clearsky(ws):
    ws.ppathCalc()
    ws.iyClearsky()
    ws.VectorSet(ws.geo_pos, [])

ws = pyarts.workspace.Workspace()
ws.iy_main_agenda = iy_main_agenda_clearsky