Skip to content

Commit

Permalink
Merge pull request #186 from jacanchaplais/feature/pdg-latex-184
Browse files Browse the repository at this point in the history
Added LaTeX output for PdgArray
  • Loading branch information
jacanchaplais authored Sep 11, 2024
2 parents 9ecf4de + 284e90b commit d6e1a1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
22 changes: 12 additions & 10 deletions graphicle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import numpy as np
import numpy.typing as npt
import typing_extensions as tyx

__all__ = [
"DoubleVector",
Expand All @@ -31,16 +32,17 @@
"NumericalStabilityWarning",
]

DoubleVector = npt.NDArray[np.float64]
FloatVector = npt.NDArray[np.float32]
ComplexVector = npt.NDArray[np.complex128]
BoolVector = npt.NDArray[np.bool_]
IntVector = npt.NDArray[np.int32]
HalfIntVector = npt.NDArray[np.int16]
ObjVector = npt.NDArray[np.object_]
AnyVector = npt.NDArray[ty.Any]
VoidVector = npt.NDArray[np.void]
MaskLike = ty.Union["MaskBase", BoolVector]
DoubleVector: tyx.TypeAlias = npt.NDArray[np.float64]
FloatVector: tyx.TypeAlias = npt.NDArray[np.float32]
ComplexVector: tyx.TypeAlias = npt.NDArray[np.complex128]
BoolVector: tyx.TypeAlias = npt.NDArray[np.bool_]
IntVector: tyx.TypeAlias = npt.NDArray[np.int32]
HalfIntVector: tyx.TypeAlias = npt.NDArray[np.int16]
ObjVector: tyx.TypeAlias = npt.NDArray[np.object_]
StringVector: tyx.TypeAlias = npt.NDArray[np.str_]
AnyVector: tyx.TypeAlias = npt.NDArray[ty.Any]
VoidVector: tyx.TypeAlias = npt.NDArray[np.void]
MaskLike: tyx.TypeAlias = ty.Union["MaskBase", BoolVector]
DoubleUfunc = ty.TypeVar("DoubleUfunc", DoubleVector, np.float64)
DataType = ty.TypeVar("DataType")

Expand Down
21 changes: 16 additions & 5 deletions graphicle/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,17 @@ class PdgArray(base.ArrayBase):
.. versionchanged:: 0.2.0
Added internal numpy interfaces for greater interoperability.
.. versionchanged:: 0.4.1
``name`` property now gives unicode array. latex property added.
Parameters
----------
data : sequence[int]
The PDG codes for each particle in the point cloud.
Attributes
----------
name : ndarray[object]
name : ndarray[unicode]
String representation of particle names.
charge : ndarray[float64]
Charge for each particle in elementary units.
Expand All @@ -1069,6 +1072,8 @@ class PdgArray(base.ArrayBase):
Spatial parity for each particle.
charge_parity : ndarray[float64]
Charge parity for each particle.
latex : list[str]
LaTeX compatible representation of particle names.
Methods
-------
Expand Down Expand Up @@ -1234,8 +1239,14 @@ def __get_prop_range(self, field: str) -> base.VoidVector:
return props # type: ignore

@property
def name(self) -> base.ObjVector:
return self.__get_prop("name")
def name(self) -> base.StringVector:
# 19 is the length of longest name
return self.__get_prop("name").astype(np.str_)

@property
def latex(self) -> base.StringVector:
# 32 is the length of longest name
return self.__get_prop("latex").astype(np.str_)

@property
def charge(self) -> base.DoubleVector:
Expand All @@ -1254,8 +1265,8 @@ def mass_bounds(self) -> base.VoidVector:
return range_arr

@property
def quarks(self) -> base.ObjVector:
return self.__get_prop("quarks")
def quarks(self) -> base.StringVector:
return self.__get_prop("quarks").astype(np.str_)

@property
def width(self) -> base.DoubleVector:
Expand Down

0 comments on commit d6e1a1a

Please sign in to comment.