hardware_properties module

A module to load hardware properties from a json file. This information is then accessible through class attributes.

The json file contains an object for a corresponding physical device. Within these objects each property is characterized with an array containing the information in following order: [value, type, unit, comment]

Warning

Make sure that all keys within the json file are ‘legal’/valid variables names in Python! Else the property is going to be assigned to an attribute name that cannot be accessed with the instance.attribute syntax.

Example

A json file containing following information:

{...
    "device1":{
        "property1": [15, "int", "mm", "interesting comment and information"]
        "subdevice1": {
            "subproperty1": [0.6, "float", "hectopascal", "interesting comment and information2"]
            "subproperty2": ["foo", "str", "dimensionless", "interesting comment and information3"]
        }
    }
...}

would be accessible through:

>>> path = "path/to/hardware_properties.json"
>>> hw = HardwareProperties(path)
>>> hw.device1.property1
>>> hw.device1.subdevice1.subproperty2
class Attribute[source]

Bases: object

class HardwareProperties(path: Union[str, bytes, os.PathLike])[source]

Bases: object

This class has attributes containing attributes to relevant hardware properties.

Each json-object is instantiated as an Attribute-object. The properties/attributes of this json–object are then assigned as attribute to the instance.

Parameters

path (Path) – Path to json file containing properties of the hardware in the setup.

create_class_and_attributes(instance, dictionary: dict)[source]

Assigns the 0th entry of the values in dictionary as attributes to instance. The name of the attribute corresponds to the key of the value.

If the value itself is a dictionary a new object is instantiated to which the values of the dictionary within value are assigned. (recursive algorithm)

Parameters
  • instance (object) – Instance of an object to which the values should be assigned

  • dictionary (dict) –

    Dictionary containing the values that should be assigned as attributes to the instance. The keys are the names of the attribute.

    Warning:

    Make sure that all keys are valid python variable names! Spaces in keys will automatically be replaced with underscores.