evefile 0.1.0rc2__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,6 +68,12 @@ documentation:
68
68
 
69
69
  * :class:`IntervalNormalizedChannelMetadata`
70
70
 
71
+ * :class:`ArrayChannelMetadata`
72
+
73
+ * :class:`MCAChannelMetadata`
74
+
75
+ * :class:`MCAChannelCalibration`
76
+
71
77
 
72
78
  Module documentation
73
79
  ====================
@@ -77,6 +83,8 @@ Module documentation
77
83
  import copy
78
84
  import logging
79
85
 
86
+ import numpy as np
87
+
80
88
  logger = logging.getLogger(__name__)
81
89
 
82
90
 
@@ -129,6 +137,7 @@ class Metadata:
129
137
  # string representation using self.__str__
130
138
  # Use only append or extend in subclasses!
131
139
  self._attributes = ["name"]
140
+ self._attribute_name_length = 0
132
141
 
133
142
  def __str__(self):
134
143
  """
@@ -141,12 +150,12 @@ class Metadata:
141
150
 
142
151
  """
143
152
  output = []
144
- attribute_name_length = max(
153
+ self._attribute_name_length = max(
145
154
  len(attribute) for attribute in self._attributes
146
155
  )
147
156
  for attribute in self._attributes:
148
157
  output.append(
149
- f"{attribute:>{attribute_name_length}}:"
158
+ f"{attribute:>{self._attribute_name_length}}:"
150
159
  f" {getattr(self, attribute)}"
151
160
  )
152
161
  if self.options:
@@ -590,3 +599,197 @@ class IntervalNormalizedChannelMetadata(
590
599
  def __init__(self):
591
600
  super().__init__()
592
601
  self._attributes.extend(["normalize_id"])
602
+
603
+
604
+ class ArrayChannelMetadata(ChannelMetadata):
605
+ """
606
+ Metadata for channels with numeric 1D data.
607
+
608
+ This class complements the class
609
+ :class:`evefile.entities.data.ArrayChannelData`.
610
+
611
+
612
+ Examples
613
+ --------
614
+ The :class:`ArrayChannelMetadata` class is not meant to be used
615
+ directly, as any entities, but rather indirectly by means of the
616
+ respective facades in the boundaries technical layer of the
617
+ ``evefile`` package. Hence, for the time being,
618
+ there are no dedicated examples how to use this class. Of course,
619
+ you can instantiate an object as usual.
620
+
621
+
622
+ .. versionadded:: 0.2
623
+
624
+ """
625
+
626
+
627
+ class MCAChannelMetadata(ArrayChannelMetadata):
628
+ """
629
+ Metadata for multichannel analyzer (MCA) channels.
630
+
631
+ This class complements the class
632
+ :class:`evefile.entities.data.MCAChannelData`.
633
+
634
+
635
+ Attributes
636
+ ----------
637
+ calibration : :class:`MCAChannelCalibration`
638
+ Metadata for the calibration of the MCA channel.
639
+
640
+ preset_life_time : :class:`float`
641
+ Preset life time
642
+
643
+ For how many seconds to acquire data, according to a clock which
644
+ counts only when the hardware is ready to accept data (live time).
645
+
646
+ preset_real_time : :class:`float`
647
+ Preset real time
648
+
649
+ For how many seconds to acquire data, according to a free running
650
+ clock (real time)
651
+
652
+
653
+ Examples
654
+ --------
655
+ The :class:`MCAChannelMetadata` class is not meant
656
+ to be used directly, as any entities, but rather indirectly by means
657
+ of the respective facades in the boundaries technical layer of the
658
+ ``evefile`` package. Hence, for the time being,
659
+ there are no dedicated examples how to use this class. Of course,
660
+ you can instantiate an object as usual.
661
+
662
+
663
+ .. versionadded:: 0.2
664
+
665
+ """
666
+
667
+ def __init__(self):
668
+ super().__init__()
669
+ self.calibration = MCAChannelCalibration()
670
+ self.preset_life_time = 0.0
671
+ self.preset_real_time = 0.0
672
+ # Note: calibration gets handled explicitly
673
+ self._attributes.extend(["preset_life_time", "preset_real_time"])
674
+
675
+ def __str__(self):
676
+ str_representation = super().__str__()
677
+ attribute = "calibration"
678
+ str_representation += (
679
+ f"\n{attribute:>{self._attribute_name_length}}:\n"
680
+ )
681
+ whitespace = " " * (self._attribute_name_length + 2)
682
+ calibration_parameters = [
683
+ f"{whitespace}{parameter}"
684
+ for parameter in self.calibration.__str__().split("\n")
685
+ ]
686
+ str_representation += "\n".join(calibration_parameters)
687
+ return str_representation
688
+
689
+
690
+ class MCAChannelCalibration:
691
+ """
692
+ Metadata for MCA channel calibration.
693
+
694
+ Many MCA channels need to be calibrated (with a second-order
695
+ polynomial) to convert the channel numbers to actual energies.
696
+
697
+ From the `EPICS MCA Record description
698
+ <https://millenia.cars.aps.anl.gov/software/epics/mcaRecord.html>`_:
699
+ "The relationship between calibrated units (cal) and channel number
700
+ (chan) is defined as ``cal=CALO + chan*CALS + chan^2*CALQ``. The first
701
+ channel in the spectrum is defined as chan=0." Here, ``CALO`` is the
702
+ offset, ``CALS`` the slope, and ``CALQ`` the quadratic term of the
703
+ polynomial.
704
+
705
+ Attributes
706
+ ----------
707
+ offset : :class:`float`
708
+ Calibration offset, *i.e.* 0th order coefficient of the polynomial.
709
+
710
+ slope : :class:`float`
711
+ Calibration slope, *i.e.* 1st order coefficient of the polynomial.
712
+
713
+ quadratic : :class:`float`
714
+ 2nd order coefficient of the polynomial.
715
+
716
+
717
+ Examples
718
+ --------
719
+ To calibrate your MCA with a number of channels with the given
720
+ calibration parameters (offset, slope, quadratic term), use:
721
+
722
+ .. code-block::
723
+
724
+ calibration = MCAChannelCalibration()
725
+ # Set the calibration parameters
726
+ calibrated_values = calibration.calibrate(n_channels=4096)
727
+
728
+ The :obj:`MCAChannelData <evefile.entities.data.MCAChannelData>`
729
+ object will usually perform the calibration transparently for you if
730
+ necessary. Even better, this object knows how many channels the MCA has.
731
+
732
+
733
+ .. versionadded:: 0.2
734
+
735
+ """
736
+
737
+ def __init__(self):
738
+ self.offset = 0.0
739
+ self.slope = 1.0
740
+ self.quadratic = 0.0
741
+
742
+ def __str__(self):
743
+ """
744
+ Human-readable representation of the metadata.
745
+
746
+ Returns
747
+ -------
748
+ output : :class:`str`
749
+ Multiline string with one attribute per line
750
+
751
+ """
752
+ output = []
753
+ attributes = [
754
+ item
755
+ for item in dir(self)
756
+ if not item.startswith("_") and not callable(getattr(self, item))
757
+ ]
758
+ attribute_name_length = max(
759
+ len(attribute) for attribute in attributes
760
+ )
761
+ for attribute in attributes:
762
+ output.append(
763
+ f"{attribute:>{attribute_name_length}}:"
764
+ f" {getattr(self, attribute)}"
765
+ )
766
+ return "\n".join(output)
767
+
768
+ def calibrate(self, n_channels=0):
769
+ """
770
+ Return calibrated values for given number of channels.
771
+
772
+ From the `EPICS MCA Record description
773
+ <https://millenia.cars.aps.anl.gov/software/epics/mcaRecord.html>`_:
774
+ "The relationship between calibrated units (cal) and channel number
775
+ (chan) is defined as ``cal=CALO + chan*CALS + chan^2*CALQ``. The first
776
+ channel in the spectrum is defined as chan=0." Here, ``CALO`` is the
777
+ offset, ``CALS`` the slope, and ``CALQ`` the quadratic term of the
778
+ polynomial.
779
+
780
+ Parameters
781
+ ----------
782
+ n_channels : :class:`int`
783
+ Number of channels of the MCA
784
+
785
+ Returns
786
+ -------
787
+ calibrated_values : :class:`numpy.ndarray`
788
+ Calibrated values for the given number of channels.
789
+
790
+ """
791
+ channels = np.arange(n_channels)
792
+ calibrated_values = (
793
+ self.offset + channels * self.slope + channels**2 * self.quadratic
794
+ )
795
+ return calibrated_values
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evefile
3
- Version: 0.1.0rc2
3
+ Version: 0.2.0
4
4
  Summary: Transitional package to read eveH5 files containing synchrotron radiometry data recorded at BESSY/MLS in Berlin
5
5
  Home-page: https://www.ptb.de/cms/en/ptb/fachabteilungen/abt7/ptb-sr.html
6
6
  Author: Till Biskup
@@ -64,18 +64,32 @@ evefile
64
64
 
65
65
  *Transitional package to read eveH5 files containing synchrotron radiometry data recorded at BESSY/MLS in Berlin.*
66
66
 
67
- Welcome! This is evefile, a Python package for **importing (synchrotron) radiometry data** obtained at one of the beamlines at **BESSY-II or MLS in Berlin**, mostly operated by the German National Metrology Institute, the `Physikalisch-Technische Bundesanstalt (PTB) <https://www.ptb.de/>`_. This package acts as transitional interface between the (eveH5) data files and the processing and analysis code. For related packages for importing, viewing, and analysing those data, have a look at the "related projects" section below.
67
+ Welcome! This is evefile, a Python package for **importing (synchrotron) radiometry data** obtained at one of the beamlines at **BESSY-II or MLS in Berlin**, mostly operated by the German National Metrology Institute, the `Physikalisch-Technische Bundesanstalt (PTB) <https://www.ptb.de/>`_. This package acts as *transitional* interface between the (eveH5) data files and the processing and analysis code. For related packages for importing, viewing, and analysing those data, have a look at the "related projects" section below.
68
+
69
+ Loading the contents of a data file of a measurement is as simple as::
70
+
71
+ import evefile
72
+
73
+ file = evefile.EveFile(filename="my_measurement_file.h5")
74
+
75
+ Here, ``file`` contains all the information contained in the data file as a hierarchy of Python objects.
68
76
 
69
77
 
70
78
  Features
71
79
  ========
72
80
 
73
- A list of (planned) features:
81
+ A list of features:
74
82
 
75
83
  * Importer for eve HDF5 files (used at PTB in Berlin, Germany)
76
84
 
77
85
  * Fully backwards-compatible to older eveH5 versions
78
86
 
87
+ * Complete information available that is contained in an eveH5 file
88
+
89
+ * Data are (only) loaded on demand, not when loading the file
90
+
91
+ * Powerful and intuitive abstractions, allowing for associative access to data and information – beyond a purely tabular view of the data
92
+
79
93
 
80
94
  And to make it even more convenient for users and future-proof:
81
95
 
@@ -0,0 +1,30 @@
1
+ evefile/__init__.py,sha256=DtUfummsLsWO7A-xiqL1hUEBll8Qc1z7829P9Sb0kOk,215
2
+ evefile/__pycache__/__init__.cpython-311.pyc,sha256=RkdWBYZ3wcT04KJ8H7KPKwhPhMc-GV9vbGSuOIOtqjE,398
3
+ evefile/boundaries/__init__.py,sha256=OKIxX1YeMY3Bda2g27xm-uQwH191EL6qLIHoPIoz_88,64
4
+ evefile/boundaries/evefile.py,sha256=brXK3bkuL4DEckaMsA6Kne8FvCw_Y2TQmTBDp-WTYRs,25038
5
+ evefile/boundaries/eveh5.py,sha256=u-aEXXBoQYCfKb7l7w1x2VVKlQ2mT5S8gMdLiHZteYU,29750
6
+ evefile/boundaries/__pycache__/__init__.cpython-311.pyc,sha256=GnLdTDzJRRVDQg_l9nctkGQs0GU8oILd3Lg1XY7kKhg,251
7
+ evefile/boundaries/__pycache__/evefile.cpython-311.pyc,sha256=m_tf3Q7SRWXJd-kpvxRCKzLjIbu7d8jAes820V61sZM,29953
8
+ evefile/boundaries/__pycache__/eveh5.cpython-311.pyc,sha256=IpaPRhZkmdR-z6x257TujkwRgAeyuhPwAn7NnvslNJM,35831
9
+ evefile/controllers/__init__.py,sha256=K4ysYHyf7p5dFDIppJyx8-ydZpLfwvjoikhUcOapKuQ,147
10
+ evefile/controllers/joining.py,sha256=GywsV8-Ah-jkvdN2GUiDZrhLoABR710MmkhS6ro8Qtk,42459
11
+ evefile/controllers/timestamp_mapping.py,sha256=mqD3bugpP68xFJa4yjgTgKJ6IXdIL7kcAjO_PdJNxoI,6886
12
+ evefile/controllers/version_mapping.py,sha256=CuaKQtFwVXBj-uEsrqYgff6hCokwvgNjxhL4-QRwivg,49602
13
+ evefile/controllers/__pycache__/__init__.cpython-311.pyc,sha256=OAlQR88n3ns13ecANQdSyPZ4w0F350NhCicFxjMAJmw,356
14
+ evefile/controllers/__pycache__/joining.cpython-311.pyc,sha256=TmQHb4_0TgAH6TjCSbA04Nx_5IrsDSl6RivXf2DjjF4,48362
15
+ evefile/controllers/__pycache__/timestamp_mapping.cpython-311.pyc,sha256=U2mJyG-MSaDfwtlsiDv9yGvJaaDFg00MatSW7-0Abp4,7772
16
+ evefile/controllers/__pycache__/version_mapping.cpython-311.pyc,sha256=jD6hwVO-sYPrneeonr9nJmRDrkc18NUjK2r8XH0VNhE,63323
17
+ evefile/entities/__init__.py,sha256=VfS-6fdCiqlYobw7gcCMcfdm8Fct_6AnSPw99JHV2bo,170
18
+ evefile/entities/data.py,sha256=b6TnGo68M-aM4U46Q3bVQ4bSPT0XrZXKSQkRWo7DaKg,76898
19
+ evefile/entities/file.py,sha256=grOHe2ONwieh58imbEq1ahLZyXooardctNanvcuWOJs,9816
20
+ evefile/entities/metadata.py,sha256=1_BZe3pXJ7UczvHn1QvlQDaFtmCF-LsDTrt8pX-7X70,24309
21
+ evefile/entities/__pycache__/__init__.cpython-311.pyc,sha256=Rc8OF9IeRYpJbN7Qw5AFn5qPxm7g_carXQKqnuZUHz4,380
22
+ evefile/entities/__pycache__/data.cpython-311.pyc,sha256=QkUi9-JSX9Tv2vIgpW_6Jq6oLAha-EucpG47Nd-nNlA,91357
23
+ evefile/entities/__pycache__/file.cpython-311.pyc,sha256=scDx1m5UN-HcCqAArH3Gzw-tSjE0fWSiiTzR8xTSlfg,11764
24
+ evefile/entities/__pycache__/metadata.cpython-311.pyc,sha256=yqIS_DWViW2XNQOH1y0FTPzT1_6DFxu_uZOwA9MD-b8,33039
25
+ evefile-0.2.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
26
+ evefile-0.2.0.dist-info/licenses/LICENSE,sha256=VYLxbjlmThdMWJAgeCXSLlcHUDR0kk0C40P92FH3o3M,766
27
+ evefile-0.2.0.dist-info/METADATA,sha256=mScSW0pFX1lfx4U82nKi_MPtOdCI59EhMubGtxjB3n4,5598
28
+ evefile-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
29
+ evefile-0.2.0.dist-info/top_level.txt,sha256=AiXT2Ch6ZWznVmfIXckmjoPXMfucyXMj4SP_46hKN7s,8
30
+ evefile-0.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,30 +0,0 @@
1
- evefile/__init__.py,sha256=DtUfummsLsWO7A-xiqL1hUEBll8Qc1z7829P9Sb0kOk,215
2
- evefile/__pycache__/__init__.cpython-311.pyc,sha256=RkdWBYZ3wcT04KJ8H7KPKwhPhMc-GV9vbGSuOIOtqjE,398
3
- evefile/boundaries/__init__.py,sha256=OKIxX1YeMY3Bda2g27xm-uQwH191EL6qLIHoPIoz_88,64
4
- evefile/boundaries/evefile.py,sha256=uVptvR2-1bvCjByxi4JNO45VkMyt7t6pYBwRa5vjO9w,18186
5
- evefile/boundaries/eveh5.py,sha256=u-aEXXBoQYCfKb7l7w1x2VVKlQ2mT5S8gMdLiHZteYU,29750
6
- evefile/boundaries/__pycache__/__init__.cpython-311.pyc,sha256=GnLdTDzJRRVDQg_l9nctkGQs0GU8oILd3Lg1XY7kKhg,251
7
- evefile/boundaries/__pycache__/evefile.cpython-311.pyc,sha256=n0oPx3nUc5SMzKGNektf1o4YBIuWllxQma9jd0bLKlE,22020
8
- evefile/boundaries/__pycache__/eveh5.cpython-311.pyc,sha256=IpaPRhZkmdR-z6x257TujkwRgAeyuhPwAn7NnvslNJM,35831
9
- evefile/controllers/__init__.py,sha256=K4ysYHyf7p5dFDIppJyx8-ydZpLfwvjoikhUcOapKuQ,147
10
- evefile/controllers/joining.py,sha256=o0GI6bBxtAU5uZkXoZ6JhgerZ_fgD3Y6IaoYt4UjSJI,42173
11
- evefile/controllers/timestamp_mapping.py,sha256=_plmzVtY_CaVp3wYy1VhfGenRwWLRJiIA6yw398r_Ec,4686
12
- evefile/controllers/version_mapping.py,sha256=zplXv7lKvvzd0NI1pMpavVFCdrkauXBnT_uvXTJu8PQ,41958
13
- evefile/controllers/__pycache__/__init__.cpython-311.pyc,sha256=OAlQR88n3ns13ecANQdSyPZ4w0F350NhCicFxjMAJmw,356
14
- evefile/controllers/__pycache__/joining.cpython-311.pyc,sha256=si4e2UAuNQrQ6fGp6vXf_a7MUimLLeKDDh148OUzwPo,48080
15
- evefile/controllers/__pycache__/timestamp_mapping.cpython-311.pyc,sha256=yDqvWtdJg9FfAoT3vSQ2jI9tuIslMZxGTNjCOXtPpRs,4898
16
- evefile/controllers/__pycache__/version_mapping.cpython-311.pyc,sha256=rQ-M_O5po_E3bwjbG200AdZBT_g8N0WShDX-BFpYKl4,52416
17
- evefile/entities/__init__.py,sha256=VfS-6fdCiqlYobw7gcCMcfdm8Fct_6AnSPw99JHV2bo,170
18
- evefile/entities/data.py,sha256=w6XMPqCtYqPGcRGmmZsWbOfT2WHsevc82Ws5uMB3tjc,54930
19
- evefile/entities/file.py,sha256=grOHe2ONwieh58imbEq1ahLZyXooardctNanvcuWOJs,9816
20
- evefile/entities/metadata.py,sha256=DVgLWM3bob2JWh_wpf6jGJ6LnIRsErB_AJmOx-u_P3E,18111
21
- evefile/entities/__pycache__/__init__.cpython-311.pyc,sha256=Rc8OF9IeRYpJbN7Qw5AFn5qPxm7g_carXQKqnuZUHz4,380
22
- evefile/entities/__pycache__/data.cpython-311.pyc,sha256=B_mzzKZ6uqGufF52z9I4jM8eIIMEEUF-zIVdSDEzS24,68181
23
- evefile/entities/__pycache__/file.cpython-311.pyc,sha256=scDx1m5UN-HcCqAArH3Gzw-tSjE0fWSiiTzR8xTSlfg,11764
24
- evefile/entities/__pycache__/metadata.cpython-311.pyc,sha256=AMbmJ_dJbM6fzzMw124sH6CYvUEaYNeV0vTn1CHEJEQ,24716
25
- evefile-0.1.0rc2.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
26
- evefile-0.1.0rc2.dist-info/licenses/LICENSE,sha256=VYLxbjlmThdMWJAgeCXSLlcHUDR0kk0C40P92FH3o3M,766
27
- evefile-0.1.0rc2.dist-info/METADATA,sha256=SLm_dKzLTvD7OxUUzKT9yzUOLxOr1_o9RaN1Wyfs5qQ,5075
28
- evefile-0.1.0rc2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
- evefile-0.1.0rc2.dist-info/top_level.txt,sha256=AiXT2Ch6ZWznVmfIXckmjoPXMfucyXMj4SP_46hKN7s,8
30
- evefile-0.1.0rc2.dist-info/RECORD,,