diff --git a/docs/src/pyexamples.rst b/docs/src/pyexamples.rst index 5685040e6..40fd10536 100755 --- a/docs/src/pyexamples.rst +++ b/docs/src/pyexamples.rst @@ -145,6 +145,7 @@ Setting and getting times import datetime as dt from slsdet import Detector + from slsdet.utils import element_if_equal d = Detector() @@ -155,7 +156,6 @@ Setting and getting times # exptime also accepts a python datetime.timedelta # which can be used to set the time in almost any unit - t = dt.timedelta(milliseconds = 2.3) d.exptime = t @@ -163,6 +163,57 @@ Setting and getting times t = dt.timedelta(minutes = 3, seconds = 1.23) d.exptime = t - #exptime however always returns the time in seconds + # exptime however always returns the time in seconds >>> d.exptime - 181.23 \ No newline at end of file + 181.23 + + # To get back the exposure time for each module + # it's possible to use getExptime, this also returns + # the values as datetime.timedelta + + >>> d.getExptime() + [datetime.timedelta(seconds=181, microseconds=230000), datetime.timedelta(seconds=181, microseconds=230000)] + + # In case the values are the same it's possible to use the + # element_if_equal function to reduce the values to a single + # value + + >>> t = d.getExptime() + >>> element_if_equal(t) + datetime.timedelta(seconds=1) + +-------------- +Reading dacs +-------------- + +:: + + from slsdet import Detector, Eiger, dacIndex + + #using the specialized class + e = Eiger() + >>> e.dacs + ========== DACS ========= + vsvp : 0 0 + vtrim : 2480 2480 + vrpreamp : 3300 3300 + vrshaper : 1400 1400 + vsvn : 4000 4000 + vtgstv : 2556 2556 + vcmp_ll : 1000 1000 + vcmp_lr : 1000 1000 + vcal : 0 0 + vcmp_rl : 1000 1000 + rxb_rb : 1100 1100 + rxb_lb : 1100 1100 + vcmp_rr : 1000 1000 + vcp : 1000 1000 + vcn : 2000 2000 + vishaper : 1550 1550 + iodelay : 650 650 + + # or using the general class and the list + d = Detector() + for dac in d.daclist: + r = d.getDAC(dac, False) + print(f'{dac.name:10s} {r}') diff --git a/python/examples/exposure_time.py b/python/examples/exposure_time.py index 05ad9b14f..eab8c12f0 100644 --- a/python/examples/exposure_time.py +++ b/python/examples/exposure_time.py @@ -4,12 +4,10 @@ Example showing how to set and get exposure times import datetime as dt from slsdet import Detector - - +from slsdet.utils import element_if_equal d = Detector() - # The simplest way is to set the exposure time in # seconds by using the exptime property # This sets the exposure time for all modules @@ -17,7 +15,6 @@ d.exptime = 0.5 # exptime also accepts a python datetime.timedelta # which can be used to set the time in almost any unit - t = dt.timedelta(milliseconds = 2.3) d.exptime = t @@ -27,4 +24,19 @@ d.exptime = t #exptime however always returns the time in seconds # >>> d.exptime -# 181.23 \ No newline at end of file +# 181.23 + +# To get back the exposure time for each module +# it's possible to use getExptime, this also returns +# the values as datetime.timedelta + +# >>> d.getExptime() +# [datetime.timedelta(seconds=181, microseconds=230000), datetime.timedelta(seconds=181, microseconds=230000)] + +# In case the values are the same it's possible to use the +# element_if_equal function to reduce the values to a single +# value + +# >>> t = d.getExptime() +# >>> element_if_equal(t) +# datetime.timedelta(seconds=1) \ No newline at end of file diff --git a/python/examples/reading_dacs.py b/python/examples/reading_dacs.py new file mode 100644 index 000000000..8a17b1b61 --- /dev/null +++ b/python/examples/reading_dacs.py @@ -0,0 +1,32 @@ +from slsdet import Detector, Eiger, dacIndex + + +#using the specialized class + +e = Eiger() +e.dacs +# >>> e.dacs +# ========== DACS ========= +# vsvp : 0 0 +# vtrim : 2480 2480 +# vrpreamp : 3300 3300 +# vrshaper : 1400 1400 +# vsvn : 4000 4000 +# vtgstv : 2556 2556 +# vcmp_ll : 1000 1000 +# vcmp_lr : 1000 1000 +# vcal : 0 0 +# vcmp_rl : 1000 1000 +# rxb_rb : 1100 1100 +# rxb_lb : 1100 1100 +# vcmp_rr : 1000 1000 +# vcp : 1000 1000 +# vcn : 2000 2000 +# vishaper : 1550 1550 +# iodelay : 650 650 + +# or using the general class and the list +d = Detector() +for dac in d.daclist: + r = d.getDAC(dac, False) + print(f'{dac.name:10s} {r}') 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/dacs.py b/python/slsdet/dacs.py index 2a083b727..345648b3e 100755 --- a/python/slsdet/dacs.py +++ b/python/slsdet/dacs.py @@ -92,6 +92,9 @@ class DetectorDacs: dac_array[i,:] = _d[:] return dac_array + def to_array(self): + return self.get_asarray() + def set_from_array(self, dac_array): """ Set the dacs from an numpy array with dac values. [ndacs, nmodules] diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 78e6a418a..bcf1be0b5 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -637,6 +637,18 @@ class Detector(CppDetectorApi): def reg(self): return self._register + @property + def daclist(self): + return self.getDacList() + + @property + def timinglist(self): + return self.getTimingModeList() + + @property + def settingslist(self): + return self.getSettingsList() + @property def adcreg(self): """[Jungfrau][Ctb][Moench][Gotthard] Writes to an adc register 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()])