parts.arts_object

The arts_object module provides meta-programming functionality that aims to simplify unified treatment of relevant ARTS variables. The basic idea is to provide so called ARTS properties, which are similar in concept to Python properties but extend their functionality to simplify handling of variables that should be passed to the ARTS workspace.

Concept

From the user perspective, the purpose of ARTS properties is to provide a simple interface to set ARTS parameters using attributes of Python objects, hiding away boilerplate code related to the management of these parameters. From the developer perspective they provide a unified way to treat these variables as well as default methods for the interaction with the ARTS workspace. The implementation of ARTS properties is based on the Descriptor protocol.

Usecase

The typical usage scenario is that a Python class is used to represent a conceptual unit grouping together various ARTS functionality and variables. An example of this is for example the Sensor class. In ARTS, the sensor is described through a set of WSVs. ARTS properties can then for example be used to expose the f_grid WSV as an attributes of the Sensor class.

class Sensor:
    @arts_property
    def f_grid(group = "Vector", shape = (Dimension.Frq), wsv = f_grid):
         return None # No default value

User perspective

Seen from the user perspective, ARTS properties provide the following functionality:

  1. Provision of default values
  2. A unified protocol for the setting of simulation parameters

ARTS properties can be set using Python assignment syntax, i.e.

sensor.f_grid = np.array([1.0, 2.0, 3.0])

or they may be obtained from the data_provider using the appropriate get method when a concrete simulation is run. ARTS properties impelement the required functionality to provide this functionality to the user in an opaque manner.

Developer perspective

For the developer, the purpose of ARTS properties is to provide meta-programming functionality to simplify the handling of ARTS-related variables. It provides default methods for the setting of ARTS properties as well as default setup and get_data methods.

Additionally, the arts_object provides functionality for the propagation of dimension information throughout parts. This is important to enable testing consistency of user-provided data.

Reference

class parts.arts_object.ArtsObject[source]

Bases: object

The :ArtsObject: class provides a base class for objects that bundle ARTS workspace variables and functionality into a conceptual unit. The class provides service functions that automate the handling of ARTS properties.

call_wsm(ws, wsm)[source]

Call workspace method on the given workspace.

This method replaces inputs of the workspace variable with the private WSMs of the object. After execution of the method the results are copied to the private WSMs of the object.

Parameters:

ws(typhon.arts.workspace.Workspace): The workspace on which to execute the method.

wsm(typhon.arts.workspace.WorkspaceMethod): The workspace method to execute.

get_data_arts_properties(ws, data_provider, *args, **kwargs)[source]

Run the get_data method for all ARTS properties of this object.

Parameters:

ws(typhon.arts.workspace): The workspace for which to setup the simulation.

data_provider(obj): The data_provider providing the data for the simulation.

*args: Additional parameters to be passed on to the data provider.

**kwargs: Additional keyword arguments to be passed to the data provider.

get_wsm_args(wsm)[source]

Generate a list of arguments to the given ARTS workspace method wsm for which the sensor related input parameters are replace by the ones of this sensor. This is done by checking whether the input argument name is in the sensors _wsv dictionary and if so replacing the argument.

Parameters:

wsm(typhon.arts.workspace.methods.Workspacemethod): The ARTS
workspace method object for which to generate the input argument list.

Returns:

The list of input arguments with sensor specific input arguments replaced by the corresponding WSVs of the sensor.
set_wsv(ws, wsv, value)[source]

Sets the given private WSV wsv of the object or if the object doesn’t have a private copy of wsv then sets wsv on the workspace ws.

Parameters:

ws(typhon.arts.workspace.Workspace): The workspace in which to set the WSV.

wsv(typhon.arts.workspace.variables.WorkspaceVariable): The variable to set.

value(obj): The value to set the WSV wsv to.

setup_arts_properties(ws)[source]

Run the setup method for all ARTS properties of the class.

Parameters:

ws(typhon.arts.workspace): The workspace for which to setup the simulation.
update_wsv(wsv, value)[source]

Updates the value of a given WSV considering private WSVs of the owner. This requires that the variable has already been set to a value during so that is contains a reference to the workspace in which it is used.

Parameters:

wsv(typhon.arts.workspace.variables.WorkspaceVariable): The variable to set.

value(obj): The value to set the WSV wsv to.

class parts.arts_object.ArtsProperty(fdefault, group, shape, wsv, optional)[source]

Bases: object

The ArtsProperty class that implements the main functionality of ARTS properties.

An ARTS property is an abstract representation of a parameter of an ARTS simulation. This parameter can be set to a fixed value by the user during the setting up of the simulation. In this case the property is said to be fixed. Otherwise, and if no default value for the parameter is set, the value will be requested from the data provider.

The :code: ArtsProperty class implements the follwing functionality:

1. Provide a default setter, that checks consistency with expected ARTS group and shape.

2. Provide a default setup method that sets the value of the corresponding ARTS WSV if the value of the property is set to fixed.

The ArtsProperty class is to be used through the :code: arts_property decorator, which returns a subclass of this class that fixes the group, shape and wsv values of the __init__ method.

check_and_broadcast(value, owner)[source]

check the shape of a given variable against a symbolic shape specification.

Parameters:

value(array or list): the object of which to check the shape.

who(str): name of the variable of which the shape is checked.

Raises:

Exception if the shape of value is inconsitent with the shape specification the ARTS property.
check_and_convert(value)[source]

Checks type of value against the group specification of this ARTS property contained in self.group.

The group specification can be a single string in which case this function will try to convert the provided value to the given group using the convert class method of typhon.arts.workspace.WorkspaceVariable.

It is also possible to specify a list of groups for the expected value. In this case this function simply checks whether the group inferred by WorkspaceVariable.get_group_id group of the :code:``

get_data(fget_data)[source]

Decorator to set the get_data method of the ARTS property. The expected call signature of the get_data method is get(self, obj, ws, *args, **args) where obj is the owner of the ARTS property. Providing of the obj argument of the setup method is currently necessary to allow the checking of dimensions.

Parameters:

fsetup(function): The customized get_data method to use for this ARTS property.
get_name(owner, separator='_')[source]

Return a qualified name of the ARTS property.

This return a name of the ARTS property prefixed by the name of the owner is this object possesses a name attribute.

Parameters:

owner: The object instance that this ARTS property belongs to.

separator(str): Char to use to separater the owners name and the name of the ARTS property.

setter(fset)[source]

Decorator to set the setter to set the value of this ARTS property. The expected call signature is set(self, value) and should set the value attribute of the ArtsProperty object self.

Parameters:

fset(function): The customized setter to use for this ArtsPorperty
setup(fsetup)[source]

Decorator to set the setup method of the ARTS property. The expected call signature of the setup method is setup(self, obj, ws) where obj is the owner of the ARTS property. Providing of the obj argument of the setup method is currently necessary to allow the checking of dimensions.

Parameters:

fsetup(function): The customized setup function to use for this ARTS property.
class parts.arts_object.Dimension[source]

Bases: object

Service class to keep track of related dimensions throughout an ARTS simulation.

A consistent ARTS simulation setup requires provided data to have the same sizes along related dimensions. The Dimensions class provides a symbolic representation of these dimensions and provides functionality to propagate information on the values of these dimensions as data is provided by the user.

class Atm[source]

Bases: object

Singleton class representing the number of dimensions of the Atmosphere.

class Frq[source]

Bases: object

Singleton class representing the number of frequencies.

class Joker[source]

Bases: object

Singleton class representing dimensions that can take an arbitrary value.

class Lat[source]

Bases: object

Singleton class representing the latitude dimension.

class Lon[source]

Bases: object

Singleton class representing the longitude dimension.

class Los[source]

Bases: object

Singleton class representing the line-of-sight dimension.

class Obs[source]

Bases: object

Singleton dimension representing the number of measurement blocks.

class P[source]

Bases: object

Singleton class representing the pressure dimension.

deduce(dim, value, who)[source]

Add a deduction of a value of a given dimension.

This function should be called when data has been provided by the user that allows the deduction of the size of a given dimension if no previous such value has been deduced, i.e. the infer method for the same dimension returns None

Parameters:

dim: Singleton class representing the dimension to lookup.

value(int): The value of the dimension that could be deduced.

who(str): Name of the variable from which the value has been
deduced.
infer(dim)[source]

Infer the value of a dimension.

Parameters:

dim: Singleton class representing the dimension to lookup.

Returns:

None if no value has been deduced for the requested dimension.

Otherwise a tuple (value, who) consisting of an integer value value representing the deduced value of the requested dimension as well as a string who indicating the variable from which the dimensions has been deduced

Link to Dimension objects.

This registers the self Dimension object as master of the other Dimensions object. Deduced dimensions values from the master dimension are propagated to the slave dimensions but not vice versa. This allows having dimensions with different values in the slave objects while still ensuring consistency with the master object.

Parameters:

other(Dimensions): The slave dimension to link to this dimension.
class parts.arts_object.PlaceHolder[source]

Bases: object

Data that is required for an ARTS simulation and can be set either to a fixed value, or taken from a data provider.

parts.arts_object.add_property(obj, name, dims, t)[source]

Add an ARTS property to an existing object.

Parameters:

obj(object): The object to add the property to.

name(:code: str): Name of the property to create

dims(tuple): Tuple describing the expected dimensions of the property.

t(type): The expected type of the property.

parts.arts_object.arts_property(group, shape=None, wsv=None, optional=False)[source]

The arts_property decorator.

This decorator turns a function defintion into an ARTS property. Its useage is similar to the @property decorator in Python. The ARTS property decorator provides default getter, setter, setup and get_data methods. The setter as well as the setup and get_data methods can be overwritten to allow specializing the handling of specific variables. For more details see the ArtsProperty class.

@arts_property
def f_grid:
    return np.array([187e9]) # The default value

@f_grid.setter
def set_f_grid(self, value):
    print("Setting the f_grid.")
    self.value = value

@f_grid.setter
def set_f_grid(self, value):
    print("Setting the f_grid.")
    self.value = value

@f_grid.setup
def setup_f_grid(self, value):
    print("Customg setup method.")

@f_grid.get_data
def get_data_f_grid(self, value):
    print("Customg setup method.")

Parameters:

group(str): The ARTS group to which the variable should belong.

shape(tuple): Tuple describing the expected shape of the variable.

wsv(typhon.arts.workspace.WorkspaceVariable): The workspace variable corresponding to the ARTS property.

parts.arts_object.broadcast(shape, obj)[source]

Broadcast an array or a list to a provided shape.

Parameters:

shape(tuple): Tuple of int describing the shape to broadcast the provided object to.

obj(object): The object to broadcast to the provided shape. Either a numpy array or a (nested) list.

parts.arts_object.get_shape(obj)[source]

Get the shape of a :code:’numpy.ndarray’ or of a nested list.

Parameters(obj):
obj: The object of which to determine the shape.

Returns:

A tuple describing the shape of the ndarray or the nested list or (1,)` if obj is not an instance of either of these types.