atlas-schema 0.2.1__py3-none-any.whl → 0.2.2__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.
atlas_schema/__init__.py CHANGED
@@ -10,7 +10,8 @@ import warnings
10
10
 
11
11
  from atlas_schema._version import version as __version__
12
12
  from atlas_schema.enums import ParticleOrigin, PhotonID
13
+ from atlas_schema.utils import isin
13
14
 
14
15
  warnings.filterwarnings("ignore", module="coffea.*")
15
16
 
16
- __all__ = ["ParticleOrigin", "PhotonID", "__version__"]
17
+ __all__ = ["ParticleOrigin", "PhotonID", "__version__", "isin"]
atlas_schema/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.2.1'
16
- __version_tuple__ = version_tuple = (0, 2, 1)
15
+ __version__ = version = '0.2.2'
16
+ __version_tuple__ = version_tuple = (0, 2, 2)
atlas_schema/enums.py CHANGED
@@ -1,9 +1,31 @@
1
1
  from __future__ import annotations
2
2
 
3
- from enum import IntEnum
3
+ import sys
4
+ from enum import Enum, IntEnum
4
5
 
6
+ if sys.version_info >= (3, 11):
7
+ from enum import EnumType
8
+ else:
9
+ from enum import EnumMeta as EnumType
5
10
 
6
- class ParticleType(IntEnum):
11
+ from typing import Callable, TypeVar, cast
12
+
13
+ _E = TypeVar("_E", bound=Enum)
14
+
15
+
16
+ class MultipleEnumAccessMeta(EnumType):
17
+ """
18
+ Enum Metaclass to provide a way to access multiple values all at once.
19
+ """
20
+
21
+ def __getitem__(self: type[_E], key: str | tuple[str]) -> _E | list[_E]: # type:ignore[misc,override]
22
+ getitem = cast(Callable[[str], _E], super().__getitem__) # type:ignore[misc]
23
+ if isinstance(key, tuple):
24
+ return [getitem(name) for name in key]
25
+ return getitem(key)
26
+
27
+
28
+ class ParticleType(IntEnum, metaclass=MultipleEnumAccessMeta):
7
29
  """
8
30
  Taken from `ATLAS Truth Utilities for ParticleType <https://gitlab.cern.ch/atlas/athena/-/blob/74f43ff0910edb2a2bd3778880ccbdad648dc037/Generators/TruthUtils/TruthUtils/TruthClasses.h#L8-49>`_.
9
31
  """
@@ -50,7 +72,7 @@ class ParticleType(IntEnum):
50
72
  UnknownJet = 38
51
73
 
52
74
 
53
- class ParticleOrigin(IntEnum):
75
+ class ParticleOrigin(IntEnum, metaclass=MultipleEnumAccessMeta):
54
76
  """
55
77
  Taken from `ATLAS Truth Utilities for ParticleOrigin <https://gitlab.cern.ch/atlas/athena/-/blob/74f43ff0910edb2a2bd3778880ccbdad648dc037/Generators/TruthUtils/TruthUtils/TruthClasses.h#L51-103>`_.
56
78
  """
@@ -105,7 +127,7 @@ class ParticleOrigin(IntEnum):
105
127
  QCD = 45
106
128
 
107
129
 
108
- class PhotonID(IntEnum):
130
+ class PhotonID(IntEnum, metaclass=MultipleEnumAccessMeta):
109
131
  """
110
132
  Taken from the `EGamma Identification CP group's twiki <https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/EGammaIdentificationRun2#Photon_isEM_word>`_.
111
133
  """
atlas_schema/utils.py ADDED
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+ from typing import TypeVar, Union, cast
5
+
6
+ import awkward as ak
7
+ import dask_awkward as dak
8
+
9
+ Array = TypeVar("Array", bound=Union[dak.Array, ak.Array])
10
+ _E = TypeVar("_E", bound=Enum)
11
+
12
+
13
+ def isin(haystack: Array, needles: dak.Array | ak.Array, axis: int = -1) -> Array:
14
+ """
15
+ Find needles in haystack.
16
+
17
+ This works by first transforming needles to an array with one more
18
+ dimension than the haystack, placing the needles at axis, and then doing a
19
+ comparison.
20
+
21
+ Args:
22
+ haystack (dak.Array or ak.Array): haystack of values.
23
+ needles (dak.Array or ak.Array): one-dimensional set of needles to find in haystack.
24
+ axis (int): the axis along which the comparison is performed
25
+
26
+ Returns:
27
+ dak.Array or ak.Array: result of comparison for needles in haystack
28
+ """
29
+ assert needles.ndim == 1, "Needles must be one-dimensional"
30
+ assert axis >= -1, "axis must be -1 or positive-valued"
31
+ assert axis < haystack.ndim + 1, "axis too large for the haystack"
32
+
33
+ # First, build up the transformation, with slice(None) indicating where to stick the needles
34
+ reshaper: list[None | slice] = [None] * haystack.ndim
35
+ axis = haystack.ndim if axis == -1 else axis
36
+ reshaper.insert(axis, slice(None))
37
+
38
+ # Note: reshaper needs to be a tuple for indexing purposes
39
+ return cast(Array, ak.any(haystack == needles[tuple(reshaper)], axis=-1))
@@ -1,11 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atlas-schema
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Helper python package for ATLAS Common NTuple Analysis work.
5
5
  Project-URL: Homepage, https://github.com/scipp-atlas/atlas-schema
6
6
  Project-URL: Bug Tracker, https://github.com/scipp-atlas/atlas-schema/issues
7
7
  Project-URL: Discussions, https://github.com/scipp-atlas/atlas-schema/discussions
8
- Project-URL: Changelog, https://github.com/scipp-atlas/atlas-schema/releases
8
+ Project-URL: Documentation, https://atlas-schema.readthedocs.io/en/v0.2.2/
9
+ Project-URL: Releases, https://github.com/scipp-atlas/atlas-schema/releases
10
+ Project-URL: Release Notes, https://atlas-schema.readthedocs.io/en/latest/history.html
9
11
  Author-email: Giordon Stark <kratsg@gmail.com>
10
12
  License:
11
13
  Apache License
@@ -249,7 +251,7 @@ Requires-Dist: tbump>=6.7.0; extra == 'test'
249
251
  Requires-Dist: twine; extra == 'test'
250
252
  Description-Content-Type: text/markdown
251
253
 
252
- # atlas-schema v0.2.1
254
+ # atlas-schema v0.2.2
253
255
 
254
256
  [![Actions Status][actions-badge]][actions-link]
255
257
  [![Documentation Status][rtd-badge]][rtd-link]
@@ -0,0 +1,13 @@
1
+ atlas_schema/__init__.py,sha256=ebY-rTiwSGnfvt1yWATze2GE7K3fVgJj6fT64Sl4sH8,469
2
+ atlas_schema/_version.py,sha256=RrHB9KG1O3GPm--rbTedqmZbdDrbgeRLXBmT4OBUqqI,411
3
+ atlas_schema/_version.pyi,sha256=j5kbzfm6lOn8BzASXWjGIA1yT0OlHTWqlbyZ8Si_o0E,118
4
+ atlas_schema/enums.py,sha256=hwgOvFBmITNxL0MQkrNpbiPv9VMezFoE-eyGgjzem8E,3688
5
+ atlas_schema/methods.py,sha256=K7u6HGKXrtpMg7jjCjKPwIEnknOShUH4HQ1ibKBzkZ0,6832
6
+ atlas_schema/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ atlas_schema/schema.py,sha256=YRVaiDa5Evl2HZ9CzH23d0-TLkvxqyvFQhn0ixyWCcw,7668
8
+ atlas_schema/typing_compat.py,sha256=RwkxiiYbXO9yxkeaL8CdRaOHH7wq6vO_epg1YD7RbRs,439
9
+ atlas_schema/utils.py,sha256=Oe2G3pe009Uhawsdk9e0MuqOHbAa5vZ8F2F9pOmz_Ok,1442
10
+ atlas_schema-0.2.2.dist-info/METADATA,sha256=QeHezHbhZY-hA2xdVlrQNeZN2OSCA8hn24jzoMUZDX8,16823
11
+ atlas_schema-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ atlas_schema-0.2.2.dist-info/licenses/LICENSE,sha256=snem82NV8fgAi4DKaaUIfReaM5RqIWbH5OOXOvy40_w,11344
13
+ atlas_schema-0.2.2.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- atlas_schema/__init__.py,sha256=mwY_EsW32pdZxihzpAg_enYPl7S-_d27idXKIlYvVqE,425
2
- atlas_schema/_version.py,sha256=MxUhzLJIZQfEpDTTcKSxciTGrMLd5v2VmMlHa2HGeo0,411
3
- atlas_schema/_version.pyi,sha256=j5kbzfm6lOn8BzASXWjGIA1yT0OlHTWqlbyZ8Si_o0E,118
4
- atlas_schema/enums.py,sha256=a44N1UbUA4K1y6wzK7zBUxbw4xT02J7vLeSqT03dFaU,2941
5
- atlas_schema/methods.py,sha256=K7u6HGKXrtpMg7jjCjKPwIEnknOShUH4HQ1ibKBzkZ0,6832
6
- atlas_schema/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- atlas_schema/schema.py,sha256=YRVaiDa5Evl2HZ9CzH23d0-TLkvxqyvFQhn0ixyWCcw,7668
8
- atlas_schema/typing_compat.py,sha256=RwkxiiYbXO9yxkeaL8CdRaOHH7wq6vO_epg1YD7RbRs,439
9
- atlas_schema-0.2.1.dist-info/METADATA,sha256=KFUTH5W2HUx8wJOzznaalEqLc9frqeMcbPJ1TmNyTYc,16662
10
- atlas_schema-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- atlas_schema-0.2.1.dist-info/licenses/LICENSE,sha256=snem82NV8fgAi4DKaaUIfReaM5RqIWbH5OOXOvy40_w,11344
12
- atlas_schema-0.2.1.dist-info/RECORD,,