temperature example

This commit is contained in:
Erik Frojdh 2020-08-20 14:13:27 +02:00
parent bd6d212f99
commit c8a39d1d9e
3 changed files with 40 additions and 1 deletions

View File

@ -143,7 +143,6 @@ Setting and getting times
:: ::
import datetime as dt import datetime as dt
from slsdet import Detector from slsdet import Detector
from slsdet.utils import element_if_equal from slsdet.utils import element_if_equal

View File

@ -11,3 +11,35 @@ print(f'fpga_temp: {fpga_temp}\n')
e = Eiger() e = Eiger()
print("All temperatures for Eiger\n") print("All temperatures for Eiger\n")
print(e.temp) 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]])

View File

@ -1,5 +1,6 @@
from functools import partial from functools import partial
from collections.abc import Iterable from collections.abc import Iterable
import numpy as np
class Temperature: class Temperature:
degree_sign = u"\N{DEGREE SIGN}" degree_sign = u"\N{DEGREE SIGN}"
@ -39,4 +40,11 @@ class DetectorTemperature:
r_str = '\n'.join([repr(temp) for temp in self]) r_str = '\n'.join([repr(temp) for temp in self])
return r_str 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()])