Skip to content

Commit

Permalink
utils: make readddatafile usable on other packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu authored Feb 3, 2025
1 parent d15dad5 commit 988b208
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/legendoptics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
u = pint.get_application_registry()


def readdatafile(filename: str) -> tuple[Quantity, Quantity]:
def readdatafile(
filename: str, pkg: str = "legendoptics.data"
) -> tuple[Quantity, Quantity]:
"""Read ``(x, y)`` data points from `filename` with units.
Accepted file format ::
Expand All @@ -26,10 +28,18 @@ def readdatafile(filename: str) -> tuple[Quantity, Quantity]:
After the first line, comments are also allowed after a ``#`` character.
Units in the header must be parseable as :mod:`pint` units.
Parameters
----------
filename
(relative) file name of the data file, including extension.
pkg
python package name used to access data files. Only needs to be set to access
data files in other packages.
"""
x = []
y = []
lines = files("legendoptics.data").joinpath(filename).read_text().split("\n")
lines = files(pkg).joinpath(filename).read_text().split("\n")
lines = [line.strip() for line in lines]

# parse header
Expand Down Expand Up @@ -118,7 +128,7 @@ def g4gps_write_emission_spectrum(
scint_em: Quantity,
quantity_name: str,
) -> None:
"""Write a energy spectrum for use with G4GeneralParticleSource
"""Write a energy spectrum for use with G4GeneralParticleSource.
It can be used like this in a Geant4 macro:
Expand Down

0 comments on commit 988b208

Please sign in to comment.