Skip to content
Snippets Groups Projects
Commit 4d02725c authored by Danilo Ferreira de Lima's avatar Danilo Ferreira de Lima
Browse files

Fixes several points found by Cammille.

parent cc84e420
No related branches found
No related tags found
1 merge request!26Added example for SCS.
Pipeline #132020 passed
...@@ -43,7 +43,7 @@ class VSConfig(object): ...@@ -43,7 +43,7 @@ class VSConfig(object):
""" """
Receives an extra-data run and outputs the configuration. Receives an extra-data run and outputs the configuration.
""" """
out = VSConfig() out = cls()
if isinstance(runNumbers, int): if isinstance(runNumbers, int):
runNumbers = [runNumbers] runNumbers = [runNumbers]
assert isinstance(runNumbers, list), "The run numbers must be a list or an integer." assert isinstance(runNumbers, list), "The run numbers must be a list or an integer."
...@@ -58,21 +58,21 @@ class VSConfig(object): ...@@ -58,21 +58,21 @@ class VSConfig(object):
else: else:
run = run[0].union(*run[1:]) run = run[0].union(*run[1:])
# get details on the run configuration # get details on the run configuration
if VSConfig.pressure_source in run.all_sources: if cls.pressure_source in run.all_sources:
pressure = run[VSConfig.pressure_source, "value"].ndarray() pressure = run[cls.pressure_source, "value"].ndarray()
out.pressure = float(np.mean(pressure)) out.pressure = float(np.mean(pressure))
out.pressure_tol = float(np.std(pressure)) out.pressure_tol = float(np.std(pressure))
else: else:
raise ValueError(f"The input data does not contain the pressure source '{pressure_source}'.") raise ValueError(f"The input data does not contain the pressure source '{pressure_source}'.")
if VSConfig.voltage_source in run.all_sources: if cls.voltage_source in run.all_sources:
for key in run[VSConfig.voltage_source].keys(): for key in run[cls.voltage_source].keys():
m = re.match("^(u[0-9]+).value$", key) m = re.match("^(u[0-9]+).value$", key)
if m is not None and len(m.groups()) >= 1: if m is not None and len(m.groups()) >= 1:
name = m.groups()[0] name = m.groups()[0]
out.voltage[name] = run[VSConfig.voltage_source, f"{name}.value"].ndarray().mean() out.voltage[name] = run[cls.voltage_source, f"{name}.value"].ndarray().mean()
out.voltage_tol[name] = run[VSConfig.voltage_source, f"{name}.value"].ndarray().std() out.voltage_tol[name] = run[cls.voltage_source, f"{name}.value"].ndarray().std()
for gas in VSConfig.gas_sources: for gas in cls.gas_sources:
# check if this gas source is interlocked # check if this gas source is interlocked
if gas in run.all_sources and run[gas, "interlock.AActionState.value"].ndarray().sum() == 0: if gas in run.all_sources and run[gas, "interlock.AActionState.value"].ndarray().sum() == 0:
# it is not, so this gas was used # it is not, so this gas was used
...@@ -105,7 +105,7 @@ class VSConfig(object): ...@@ -105,7 +105,7 @@ class VSConfig(object):
for k, v in self.voltage.items()} for k, v in self.voltage.items()}
diff.pressure = self.pressure - other.pressure diff.pressure = self.pressure - other.pressure
diff.voltage_tol = {k: np.sqrt(v**2 + other.voltage_tol[k]**2) diff.voltage_tol = {k: np.sqrt(v**2 + other.voltage_tol[k]**2)
for k in self.voltage_tol.items()} for k, v in self.voltage_tol.items()}
diff.pressure_tol = np.sqrt(self.pressure_tol**2 + other.pressure_tol**2) diff.pressure_tol = np.sqrt(self.pressure_tol**2 + other.pressure_tol**2)
diff.gas = set(self.gas).difference(set(other.gas)) diff.gas = set(self.gas).difference(set(other.gas))
return diff return diff
...@@ -114,7 +114,7 @@ class VSConfig(object): ...@@ -114,7 +114,7 @@ class VSConfig(object):
""" """
Check if two configurations match. Check if two configurations match.
""" """
if not isinstance(other, VSConfig): if not isinstance(other, self.__class__):
raise ValueError("I can only check equality with another VSConfig object.") raise ValueError("I can only check equality with another VSConfig object.")
diff = self - other diff = self - other
for v in diff.voltage.values(): for v in diff.voltage.values():
...@@ -161,13 +161,13 @@ class VSConfig(object): ...@@ -161,13 +161,13 @@ class VSConfig(object):
""" """
Build from dictionary. Build from dictionary.
""" """
out = VSConfig() out = cls()
out.gas = {data['gas']} out.gas = {data['gas']}
out.pressure = data['pressure'] out.pressure = data['pressure']
out.voltage = {k: v for k, v in data.items() out.voltage = {k: v for k, v in data.items()
if k not in ('gas', 'pressure')} if k not in ('gas', 'pressure')}
if tolerance is None: if tolerance is None:
tolerance = {k: 0.0 for k, v in data.items() if k != 'gas'} tolerance = {k: 0.0 for k in data.keys() if k != 'gas'}
out.pressure_tol = tolerance['pressure'] out.pressure_tol = tolerance['pressure']
out.voltage_tol = {k: v for k, v in tolerance.items() out.voltage_tol = {k: v for k, v in tolerance.items()
if k not in ('gas', 'pressure')} if k not in ('gas', 'pressure')}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment