From c8a39d1d9e10b69f4e85bbbd0dc6a1a8b0c746b7 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 20 Aug 2020 14:13:27 +0200 Subject: [PATCH] temperature example --- docs/src/pyexamples.rst | 1 - python/examples/reading_temperature.py | 32 ++++++++++++++++++++++++++ python/slsdet/temperature.py | 8 +++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/src/pyexamples.rst b/docs/src/pyexamples.rst index 158410771..0facb94ff 100755 --- a/docs/src/pyexamples.rst +++ b/docs/src/pyexamples.rst @@ -143,7 +143,6 @@ Setting and getting times :: - import datetime as dt from slsdet import Detector from slsdet.utils import element_if_equal diff --git a/python/examples/reading_temperature.py b/python/examples/reading_temperature.py index d3afb32eb..e167e3860 100644 --- a/python/examples/reading_temperature.py +++ b/python/examples/reading_temperature.py @@ -11,3 +11,35 @@ print(f'fpga_temp: {fpga_temp}\n') e = Eiger() print("All temperatures for Eiger\n") print(e.temp) +# >>> e.temp +# temp_fpga : 54°C 60°C +# temp_fpgaext : 49°C 52°C +# temp_10ge : 47°C 45°C +# temp_dcdc : 52°C 53°C +# temp_sodl : 51°C 53°C +# temp_sodl : 51°C 51°C +# temp_fpgafl : 45°C 49°C +# temp_fpgafr : 39°C 42°C + +# The temperatures can also be returned in a dictionary +t = e.temp.to_dict() +print(t) +# >>> e.temp.to_dict() +# {'fpga': array([55, 60]), 'fpgaext': array([49, 52]), +# 't10ge': array([47, 45]), 'dcdc': array([52, 53]), +# 'sodl': array([51, 53]), 'sodr': array([51, 51]), ' +# temp_fpgafl': array([45, 49]), +# 'temp_fpgafr': array([39, 42])} + +# or in a numpy array +t = e.temp.to_array() +print(t) +# >>> e.temp.to_array() +# array([[55, 60], +# [49, 52], +# [47, 45], +# [52, 53], +# [51, 53], +# [51, 51], +# [45, 49], +# [40, 43]]) diff --git a/python/slsdet/temperature.py b/python/slsdet/temperature.py index ed30e70fe..ef609eeb8 100644 --- a/python/slsdet/temperature.py +++ b/python/slsdet/temperature.py @@ -1,5 +1,6 @@ from functools import partial from collections.abc import Iterable +import numpy as np class Temperature: degree_sign = u"\N{DEGREE SIGN}" @@ -39,4 +40,11 @@ class DetectorTemperature: r_str = '\n'.join([repr(temp) for temp in self]) return r_str + def to_dict(self): + """Get temperatures as a dictionary with numpy arrays""" + return {attr:np.array(value.get()) for attr, value in self.__dict__.items()} + def to_array(self): + """Get all temperatures as a numpy array""" + t = self.to_dict() + return np.vstack([value for key, value in t.items()])