From 988b20810b92433dd7dbb337171a021a840e9c03 Mon Sep 17 00:00:00 2001 From: Manuel Huber Date: Mon, 3 Feb 2025 11:50:44 +0100 Subject: [PATCH] utils: make readddatafile usable on other packages --- src/legendoptics/utils.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/legendoptics/utils.py b/src/legendoptics/utils.py index e941734..895559b 100644 --- a/src/legendoptics/utils.py +++ b/src/legendoptics/utils.py @@ -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 :: @@ -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 @@ -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: