rail.yaw_rail.utils module

This module implements some simple utility functions and logging facilites. Furthermore, it implements an extension to the default RailStage that simplfies safe access to optional stage inputs (handles/data) that is commonly used in the wrapper stages.

class rail.yaw_rail.utils.YawRailStage

Bases: ABC, RailStage

Base class for any RailStage used in this wrapper package.

It introduces a few quality-of-life improvements compared to the base RailStage when creating a sub-class. These include:

  • adding a methods to safely access optional stage inputs (handles/data),

  • setting the name attribute automatically to the class name,

  • copying the default RailStage.config_options,

  • providing an interface to directly register a dictionary of algorithm- specific stage parameters, and

  • automatically adding the “verbose” parameter to the stage, which controlls the log-level filtering for the yet_another_wizz logger.

The names of all algorithm-specific parameters are tracked in the special attribute algo_parameters. There is a special method to get a dictionary of just those parameters.

Examples

Create a new stage with one algorithm specific parameter called “param”. The resulting subclass will have the standard RailStage parameters and an additional parameter “verbose”.

>>> class MyStage(
...     YawRailStage,
...     config_items=dict(
...         param=StageParameter(dtype=int)
...     ),
... ):
algo_parameters: set[str]

Lists the names of all algorithm-specific parameters that were added when subclassing.

get_algo_config_dict(exclude=None)

Return the algorithm-specific configuration.

Same as get_config_dict, but only returns those parameters that are listed in algo_parameters, i.e. been added as stage parameters when creating the subclass.

Parameters:

exclude (Container of str, optional) – Listing of parameters not to include in the output.

Returns:

Dictionary containing pairs of parameter names and (default) values.

Return type:

dict

get_optional_data(tag, **kwargs)

Access the data of an optional handle and return None if it is not set.

Parameters:
  • tag (str) – The requested tag.

  • **kwargs (dict, optional) – Parameters passed on to get_data.

Returns:

The handle’s data or nothing if not set.

Return type:

Any or None

get_optional_handle(tag, **kwargs)

Access an optional handle an return None if it is not set.

Parameters:
  • tag (str) – The requested tag.

  • **kwargs (dict, optional) – Parameters passed on to get_handle.

Returns:

The handle or nothing if not set.

Return type:

DataHandle or None

abstractmethod run()

Run the stage and return the execution status.

Subclasses must implemented this method.

Return type:

None

set_optional_data(tag, value, **kwarg)

Set a handle’s data if the provided value is not None.

Parameters:
  • tag (str) – The requested tag.

  • value (Any or None) – The data to assing to the handle unless None is provided.

  • **kwargs (dict, optional) – Parameters passed on to set_data.

Return type:

None

rail.yaw_rail.utils.get_dc2_test_data()

Download a small dataset with positions and redshifts, derived from DC2.

Taken from 25 sqdeg, limited to 100k objects with redshifts 0.2 <= z < 1.8.

Returns:

Table containing right ascension (ra), declination (dec) and redshift (z).

Return type:

DataFrame

rail.yaw_rail.utils.yaw_logged(method)

Decorator that creates a temporary logger for a method of a YawRailStage that redirects messages emitted by yet_another_wizz to stdout.