From 28c0e6a026a9d66d5add1986d5e44e4da464b861 Mon Sep 17 00:00:00 2001 From: Danilo Ferreira de Lima <danilo.enoque.ferreira.de.lima@xfel.de> Date: Tue, 20 Feb 2024 14:35:34 +0100 Subject: [PATCH] Created VS configuration. --- pes_to_spec/config.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pes_to_spec/config.py b/pes_to_spec/config.py index d51c58c..379cd27 100644 --- a/pes_to_spec/config.py +++ b/pes_to_spec/config.py @@ -7,6 +7,7 @@ from extra_data import open_run import re import numpy as np from copy import deepcopy +import json class VSConfig(object): """ @@ -114,5 +115,40 @@ class VSConfig(object): if len(diff.gas_active) > 0: return False + def to_dict(self) -> Dict[str, Union[List[float], float, List[str]]]: + """ + Return as a dictionary. + """ + out = dict( + voltage_mean=self.voltage_mean, + voltage_std=self.voltage_std, + pressure_mean=self.pressure_mean, + pressure_std=self.pressure_std, + gas_active=list(self.gas_active)) + return out + + @staticmethod + def from_dict(data: Dict[str, Union[List[float], float, List[str]]]) -> 'VSConfig': + """ + Build from dictionary. + """ + out = VSConfig() + out.voltage_mean = data['voltage_mean'] + out.voltage_std = data['voltage_std'] + out.pressure_mean = data['pressure_mean'] + out.pressure_std = data['pressure_std'] + out.gas_active = set(data['gas_active']) + return out + def __str__(self) -> str: + """ + Dump as string. + """ + return json.dumps(self.to_dict()) + + def __repr__(self) -> str: + """ + Dump as string. + """ + return json.dumps(self.to_dict()) -- GitLab