amityping 1.3.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.
amitypes/__init__.py ADDED
@@ -0,0 +1,79 @@
1
+ import sys
2
+ import json
3
+ import numpy
4
+ import typing
5
+ import inspect
6
+ import importlib
7
+
8
+ from amitypes.array import NumPyTypeDict
9
+ from amitypes.array import * # noqa ignore=F405
10
+ from amitypes.hsd import * # noqa ignore=F405
11
+ from amitypes.waveform import * # noqa ignore=F405
12
+ from amitypes.source import * # noqa ignore=F405
13
+ from amitypes.scan import * # noqa ignore=F405
14
+
15
+
16
+ __version__ = '1.3.0'
17
+
18
+
19
+ def dumps(cls):
20
+ if inspect.isclass(cls):
21
+ if isinstance(cls, typing.GenericAlias):
22
+ return str(cls)
23
+ elif cls.__module__ in ['builtins']:
24
+ return cls.__name__
25
+ else:
26
+ return "%s.%s" % (cls.__module__, cls.__name__)
27
+ elif isinstance(cls, typing.TypeVar):
28
+ return "%s.%s" % (cls.__module__, cls.__name__)
29
+ else:
30
+ return str(cls)
31
+
32
+
33
+ def loads(type_str):
34
+ parts = type_str.split('.')
35
+ if len(parts) > 1 and parts[0] != __name__:
36
+ try:
37
+ mod = importlib.import_module(parts[0])
38
+ setattr(sys.modules[__name__], mod.__name__, mod)
39
+ except ModuleNotFoundError:
40
+ pass
41
+
42
+ cls = eval(type_str.replace('amitypes.', ''))
43
+
44
+ return cls
45
+
46
+
47
+ class TypeDumper(object):
48
+
49
+ def __init__(self, ttype):
50
+ self.ttype = ttype
51
+
52
+ def __repr__(self):
53
+ return dumps(self.ttype)
54
+
55
+
56
+ class TypeEncoder(json.JSONEncoder):
57
+
58
+ def default(self, obj):
59
+ nptopy = NumPyTypeDict.get(type(obj))
60
+ if nptopy is not None:
61
+ return nptopy(obj)
62
+ elif isinstance(obj, numpy.ndarray):
63
+ return obj.tolist()
64
+ elif inspect.isclass(obj):
65
+ if isinstance(obj, typing.GenericAlias):
66
+ return str(obj)
67
+ elif obj.__module__ in ['builtins']:
68
+ return obj.__name__
69
+ else:
70
+ return "%s.%s" % (obj.__module__, obj.__name__)
71
+ elif isinstance(obj, typing.TypeVar):
72
+ return "%s.%s" % (obj.__module__, obj.__name__)
73
+ elif isinstance(obj, (typing._GenericAlias, typing._SpecialForm, typing.GenericAlias)):
74
+ return str(obj)
75
+ else:
76
+ return json.JSONEncoder.default(self, obj)
77
+
78
+
79
+ T = typing.TypeVar('T')
amitypes/array.py ADDED
@@ -0,0 +1,93 @@
1
+ import numpy
2
+ import typing
3
+ import inspect
4
+
5
+
6
+ __all__ = [
7
+ 'NumPyTypeDict',
8
+ 'Array',
9
+ 'ArrayMeta',
10
+ 'Array1d',
11
+ 'Array2d',
12
+ 'Array3d',
13
+ ]
14
+
15
+
16
+ def _map_numpy_types():
17
+ nptypemap = {}
18
+ for name, dtype in inspect.getmembers(numpy, lambda x: inspect.isclass(x) and issubclass(x, numpy.generic)):
19
+ try:
20
+ ptype = None
21
+ if 'time' in name:
22
+ ptype = type(dtype(0, 'D').item())
23
+ elif 'object' not in name:
24
+ ptype = type(dtype(0).item())
25
+
26
+ # if it is still a numpy dtype don't make a mapping
27
+ if not issubclass(ptype, numpy.generic):
28
+ nptypemap[dtype] = ptype
29
+ except TypeError:
30
+ pass
31
+
32
+ return nptypemap
33
+
34
+
35
+ NumPyTypeDict = _map_numpy_types()
36
+
37
+
38
+ class ArrayMeta(type):
39
+ pass
40
+
41
+
42
+ class Array1dMeta(ArrayMeta):
43
+
44
+ @classmethod
45
+ def __instancecheck__(cls, inst) -> bool:
46
+ if not isinstance(inst, numpy.ndarray):
47
+ return False
48
+
49
+ if inst.ndim != 1:
50
+ return False
51
+
52
+ return True
53
+
54
+
55
+ class Array2dMeta(ArrayMeta):
56
+
57
+ @classmethod
58
+ def __instancecheck__(cls, inst) -> bool:
59
+ if not isinstance(inst, numpy.ndarray):
60
+ return False
61
+
62
+ if inst.ndim != 2:
63
+ return False
64
+
65
+ return True
66
+
67
+
68
+ class Array3dMeta(ArrayMeta):
69
+
70
+ @classmethod
71
+ def __instancecheck__(cls, inst) -> bool:
72
+ if not isinstance(inst, numpy.ndarray):
73
+ return False
74
+
75
+ if inst.ndim != 3:
76
+ return False
77
+
78
+ return True
79
+
80
+
81
+ class Array1d(metaclass=Array1dMeta):
82
+ pass
83
+
84
+
85
+ class Array2d(metaclass=Array2dMeta):
86
+ pass
87
+
88
+
89
+ class Array3d(metaclass=Array3dMeta):
90
+ pass
91
+
92
+
93
+ Array = typing.Union[Array3d, Array2d, Array1d, list[float], tuple[float]]
amitypes/hsd.py ADDED
@@ -0,0 +1,108 @@
1
+ import typing
2
+ from mypy_extensions import TypedDict
3
+ from amitypes.array import Array1d
4
+
5
+
6
+ __all__ = [
7
+ 'TypedDict',
8
+ 'PeakTimes',
9
+ 'HSDSegementPeakTimes',
10
+ 'HSDPeakTimes',
11
+ 'Peaks',
12
+ 'HSDSegmentPeaks',
13
+ 'HSDPeaks',
14
+ 'HSDSegmentWaveforms',
15
+ 'HSDWaveforms',
16
+ 'HSDAssemblies',
17
+ 'HSDTypes',
18
+ ]
19
+
20
+
21
+ PeakTimes = list[Array1d]
22
+
23
+
24
+ HSDSegementPeakTimes = TypedDict(
25
+ "HSDSegementPeakTimes",
26
+ {
27
+ '0': PeakTimes,
28
+ '1': PeakTimes,
29
+ '2': PeakTimes,
30
+ '3': PeakTimes,
31
+ '4': PeakTimes,
32
+ '5': PeakTimes,
33
+ '6': PeakTimes,
34
+ '7': PeakTimes,
35
+ '8': PeakTimes,
36
+ '9': PeakTimes,
37
+ '10': PeakTimes,
38
+ '11': PeakTimes,
39
+ '12': PeakTimes,
40
+ '13': PeakTimes,
41
+ '14': PeakTimes,
42
+ '15': PeakTimes,
43
+ },
44
+ total=False)
45
+
46
+
47
+ HSDPeakTimes = dict[int, HSDSegementPeakTimes]
48
+
49
+ Peaks = tuple[list[int], list[Array1d]]
50
+
51
+
52
+ HSDSegmentPeaks = TypedDict(
53
+ "HSDSegmentPeaks",
54
+ {
55
+ '0': Peaks,
56
+ '1': Peaks,
57
+ '2': Peaks,
58
+ '3': Peaks,
59
+ '4': Peaks,
60
+ '5': Peaks,
61
+ '6': Peaks,
62
+ '7': Peaks,
63
+ '8': Peaks,
64
+ '9': Peaks,
65
+ '10': Peaks,
66
+ '11': Peaks,
67
+ '12': Peaks,
68
+ '13': Peaks,
69
+ '14': Peaks,
70
+ '15': Peaks,
71
+ },
72
+ total=False)
73
+
74
+
75
+ HSDPeaks = dict[int, HSDSegmentPeaks]
76
+
77
+
78
+ HSDSegmentWaveforms = TypedDict(
79
+ "HSDSegmentWaveforms",
80
+ {
81
+ 'times': Array1d,
82
+ '0': Array1d,
83
+ '1': Array1d,
84
+ '2': Array1d,
85
+ '3': Array1d,
86
+ '4': Array1d,
87
+ '5': Array1d,
88
+ '6': Array1d,
89
+ '7': Array1d,
90
+ '8': Array1d,
91
+ '9': Array1d,
92
+ '10': Array1d,
93
+ '11': Array1d,
94
+ '12': Array1d,
95
+ '13': Array1d,
96
+ '14': Array1d,
97
+ '15': Array1d,
98
+ },
99
+ total=False)
100
+
101
+
102
+ HSDWaveforms = dict[int, HSDSegmentWaveforms]
103
+
104
+
105
+ HSDAssemblies = typing.TypeVar('HSDAssemblies')
106
+
107
+
108
+ HSDTypes = {HSDPeakTimes, HSDPeaks, HSDWaveforms, HSDAssemblies}
amitypes/py.typed ADDED
File without changes
amitypes/scan.py ADDED
@@ -0,0 +1,46 @@
1
+ from amitypes.array import Array1d
2
+
3
+
4
+ __all__ = [
5
+ 'ScanControls',
6
+ 'ScanMonitors',
7
+ 'ScanLabels',
8
+ 'ScanTypes',
9
+ 'ScanControlType',
10
+ 'ScanMonitorType',
11
+ 'ScanLabelType',
12
+ ]
13
+
14
+
15
+ class ScanMeta(type):
16
+
17
+ @classmethod
18
+ def __instancecheck__(cls, inst) -> bool:
19
+ if not isinstance(inst, list) and not isinstance(inst, Array1d):
20
+ return False
21
+
22
+ return True
23
+
24
+
25
+ class ScanControls(metaclass=ScanMeta):
26
+ pass
27
+
28
+
29
+ class ScanMonitors(metaclass=ScanMeta):
30
+ pass
31
+
32
+
33
+ class ScanLabels(metaclass=ScanMeta):
34
+ pass
35
+
36
+
37
+ ScanTypes = {ScanControls, ScanMonitors, ScanLabels}
38
+
39
+
40
+ ScanControlType = float
41
+
42
+
43
+ ScanMonitorType = tuple[float, float]
44
+
45
+
46
+ ScanLabelType = str
amitypes/source.py ADDED
@@ -0,0 +1,85 @@
1
+ import typing
2
+ import dataclasses
3
+ import collections.abc
4
+
5
+
6
+ __all__ = [
7
+ 'Detector',
8
+ 'Group',
9
+ 'DataSource',
10
+ 'PyArrowTypes',
11
+ ]
12
+
13
+
14
+ T = typing.TypeVar('T', bound='Serializable')
15
+
16
+
17
+ class Serializable:
18
+ @property
19
+ def fields(self) -> typing.Iterable[dataclasses.Field]:
20
+ return dataclasses.fields(self)
21
+
22
+ def _dropped(self) -> typing.Generator[dataclasses.Field, None, None]:
23
+ for field in self.fields:
24
+ if field.metadata.get('drop', False):
25
+ yield field
26
+
27
+ def _undropped(self) -> typing.Generator[dataclasses.Field, None, None]:
28
+ for field in self.fields:
29
+ if not field.metadata.get('drop', False):
30
+ yield field
31
+
32
+ def _serialize(self) -> dict:
33
+ state = self.__dict__.copy()
34
+ for field in self._dropped():
35
+ del state[field.name]
36
+ return state
37
+
38
+ @classmethod
39
+ def _deserialize(cls: typing.Type[T], data: dict) -> T:
40
+ return cls(**data)
41
+
42
+ def __getstate__(self) -> dict:
43
+ return self._serialize()
44
+
45
+ def __setstate__(self, state: dict) -> None:
46
+ for field in self._dropped():
47
+ state[field.name] = field.default
48
+ self.__dict__.update(state)
49
+
50
+
51
+ @dataclasses.dataclass
52
+ class Detector(Serializable):
53
+ name: str
54
+ src: str
55
+ type: str
56
+ det: typing.Any = dataclasses.field(default=None, metadata={'drop': True})
57
+
58
+
59
+ @dataclasses.dataclass
60
+ class Group(Serializable, collections.abc.Mapping):
61
+ name: str
62
+ src: str
63
+ type: str
64
+ data: dict = dataclasses.field(default_factory=dict)
65
+
66
+ def __getitem__(self, key):
67
+ return self.data[key]
68
+
69
+ def __iter__(self):
70
+ return iter(self.data)
71
+
72
+ def __len__(self):
73
+ return len(self.data)
74
+
75
+
76
+ @dataclasses.dataclass
77
+ class DataSource(Serializable):
78
+ cfg: dict
79
+ key: int = 0
80
+ run: typing.Any = dataclasses.field(default=None, metadata={'drop': True})
81
+ step: typing.Any = dataclasses.field(default=None, metadata={'drop': True})
82
+ evt: typing.Any = dataclasses.field(default=None, metadata={'drop': True})
83
+
84
+
85
+ PyArrowTypes = {Detector, Group, DataSource}
amitypes/waveform.py ADDED
@@ -0,0 +1,66 @@
1
+ import typing
2
+ from amitypes.array import Array1d, Array2d
3
+
4
+
5
+ __all__ = [
6
+ 'MultiChannelInt',
7
+ 'MultiChannelFloat',
8
+ 'MultiChannelScalar',
9
+ 'MultiChannelScalarTypes',
10
+ 'AcqirisTimes',
11
+ 'AcqirisWaveforms',
12
+ 'AcqirisChannel',
13
+ 'AcqirisTypes',
14
+ 'GenericWfTimes',
15
+ 'GenericWfWaveforms',
16
+ 'GenericWfChannel',
17
+ 'GenericWfTypes',
18
+ 'MultiChannelWaveform',
19
+ 'MultiChannelWaveformTypes',
20
+ ]
21
+
22
+
23
+ class MultiChannelInt(Array1d):
24
+ pass
25
+
26
+
27
+ class MultiChannelFloat(Array1d):
28
+ pass
29
+
30
+
31
+ MultiChannelScalar = typing.Union[MultiChannelInt, MultiChannelFloat, Array1d]
32
+
33
+
34
+ MultiChannelScalarTypes = {MultiChannelInt, MultiChannelFloat}
35
+
36
+
37
+ class AcqirisTimes(Array2d):
38
+ pass
39
+
40
+
41
+ class AcqirisWaveforms(Array2d):
42
+ pass
43
+
44
+
45
+ AcqirisChannel = Array1d
46
+
47
+
48
+ AcqirisTypes = {AcqirisTimes, AcqirisWaveforms}
49
+
50
+
51
+ GenericWfTimes = list[Array1d]
52
+
53
+
54
+ GenericWfWaveforms = list[Array1d]
55
+
56
+
57
+ GenericWfChannel = Array1d
58
+
59
+
60
+ GenericWfTypes = {GenericWfTimes, GenericWfWaveforms}
61
+
62
+
63
+ MultiChannelWaveform = typing.Union[AcqirisTimes, AcqirisWaveforms, GenericWfTimes, GenericWfWaveforms, Array2d]
64
+
65
+
66
+ MultiChannelWaveformTypes = AcqirisTypes | GenericWfTypes
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: amityping
3
+ Version: 1.3.0
4
+ Summary: LCLS analysis monitoring type annotations
5
+ Author: Seshu Yamajala, Daniel Damiani
6
+ License:
7
+ Copyright (c) 2019, The Board of Trustees of the Leland Stanford Junior
8
+ University, through SLAC National Accelerator Laboratory (subject to receipt
9
+ of any required approvals from the U.S. Dept. of Energy). All rights reserved.
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ (1) Redistributions of source code must retain the above copyright notice,
14
+ this list of conditions and the following disclaimer.
15
+
16
+ (2) Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ (3) Neither the name of the Leland Stanford Junior University, SLAC National
21
+ Accelerator Laboratory, U.S. Dept. of Energy nor the names of its
22
+ contributors may be used to endorse or promote products derived from this
23
+ software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT,
29
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ OF SUCH DAMAGE.
36
+
37
+ You are under no obligation whatsoever to provide any bug fixes, patches, or
38
+ upgrades to the features, functionality or performance of the source code
39
+ ("Enhancements") to anyone; however, if you choose to make your Enhancements
40
+ available either publicly, or directly to SLAC National Accelerator Laboratory,
41
+ without imposing a separate written license agreement for such Enhancements,
42
+ then you hereby grant the following license: a non-exclusive, royalty-free
43
+ perpetual license to install, use, modify, prepare derivative works, incorporate
44
+ into other computer software, distribute, and sublicense such Enhancements or
45
+ derivative works thereof, in binary and source code form.
46
+
47
+ Project-URL: Homepage, https://github.com/slac-lcls/amityping
48
+ Classifier: Development Status :: 1 - Planning
49
+ Classifier: Intended Audience :: Science/Research
50
+ Classifier: License :: OSI Approved :: BSD License
51
+ Classifier: Operating System :: MacOS :: MacOS X
52
+ Classifier: Operating System :: Microsoft :: Windows
53
+ Classifier: Operating System :: POSIX
54
+ Classifier: Programming Language :: Python :: 3
55
+ Classifier: Programming Language :: Python :: 3.9
56
+ Classifier: Topic :: Utilities
57
+ Requires-Python: >=3.9
58
+ Description-Content-Type: text/markdown
59
+ License-File: LICENSE.md
60
+ Requires-Dist: numpy
61
+ Requires-Dist: mypy_extensions
62
+ Dynamic: license-file
63
+
64
+ # amityping
65
+ Provides typing hints to be shared between LCLS-II analysis packages.
@@ -0,0 +1,12 @@
1
+ amitypes/__init__.py,sha256=9jFzhIxYOoQDFxRM0QSmlZ3rENQ6KRappP-ZLjht6nI,2170
2
+ amitypes/array.py,sha256=m3VeNgQs3z6M1bXDF9FwBQTGy9Y7RV725PW7SjDFjQg,1765
3
+ amitypes/hsd.py,sha256=xxlI45DvwWXjafc8i3pjliEDuLdvc1UKtshQaApkROQ,2704
4
+ amitypes/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ amitypes/scan.py,sha256=DWkxvRpweRKl_N1fzO9N0bPBQNgBe5kwxhjBHnvlcPo,694
6
+ amitypes/source.py,sha256=bs_NNiWGnYaWD4Kls9RbtGkfIT34fcuhnHlBee8mv8g,2111
7
+ amitypes/waveform.py,sha256=aodDK-wuNfOdBFefrCcmp50t2P1CKWL7Hf8iryO7WjA,1145
8
+ amityping-1.3.0.dist-info/licenses/LICENSE.md,sha256=8hRJDTIZbSOBPwZ2Qus_Nx-OT1bZDHWirO4-RvMaFGQ,2500
9
+ amityping-1.3.0.dist-info/METADATA,sha256=Vl20HCFNvyCwmGS5nRU1RNkUa0YyCmwrw_0JVCDLxfY,3697
10
+ amityping-1.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
11
+ amityping-1.3.0.dist-info/top_level.txt,sha256=SGGFo32pTkEfBNEzaSS60FZmpAPHiuulYfRoWetZKMM,9
12
+ amityping-1.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,40 @@
1
+
2
+ Copyright (c) 2019, The Board of Trustees of the Leland Stanford Junior
3
+ University, through SLAC National Accelerator Laboratory (subject to receipt
4
+ of any required approvals from the U.S. Dept. of Energy). All rights reserved.
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ (1) Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ (3) Neither the name of the Leland Stanford Junior University, SLAC National
16
+ Accelerator Laboratory, U.S. Dept. of Energy nor the names of its
17
+ contributors may be used to endorse or promote products derived from this
18
+ software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT,
24
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30
+ OF SUCH DAMAGE.
31
+
32
+ You are under no obligation whatsoever to provide any bug fixes, patches, or
33
+ upgrades to the features, functionality or performance of the source code
34
+ ("Enhancements") to anyone; however, if you choose to make your Enhancements
35
+ available either publicly, or directly to SLAC National Accelerator Laboratory,
36
+ without imposing a separate written license agreement for such Enhancements,
37
+ then you hereby grant the following license: a non-exclusive, royalty-free
38
+ perpetual license to install, use, modify, prepare derivative works, incorporate
39
+ into other computer software, distribute, and sublicense such Enhancements or
40
+ derivative works thereof, in binary and source code form.
@@ -0,0 +1 @@
1
+ amitypes