Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Ludwig committed Feb 11, 2023
1 parent c8b7762 commit 54345a3
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 12 deletions.
6 changes: 3 additions & 3 deletions panama/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ def read_DAT(
)

pdgids = df_particles["pdgid"].unique()

mass_map = dict()
for pdgid in pdgids:
if pdgid == pdg_error_val:
mass_map[pdgid] = 0
else:
mass = Particle.from_pdgid(pdgid).mass
mass_map[pdgid] = mass / 1000 if mass is not None else 0 # GeV
mass_map[pdgid] = mass / 1000 if mass is not None else 0 # GeV

df_particles["mass"] = df_particles["pdgid"].map(mass_map, na_action=None)
df_particles["energy"] = df_particles.eval("sqrt(mass**2+px**2+py**2+pz**2)")
df_particles["zenith"] = df_particles.eval("arccos(pz/sqrt(px**2+py**2+pz**2))")
Expand Down
162 changes: 161 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ crflux = "^1.0.6"
black = "^22.10.0"
pytest = "^7.2.0"
coverage = "^7.1.0"
pre-commit = "^3.0.4"

[tool.poetry.scripts]
panama = 'panama.cli:cli'
Expand Down
19 changes: 11 additions & 8 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from click.testing import CliRunner
from panama import read_DAT


def test_run_fail(
test_file_path=Path(__file__).parent / "files" / "example_corsika.template",
):
Expand Down Expand Up @@ -46,34 +47,36 @@ def test_cli_missing_executable(

def test_cli(
test_file_path=Path(__file__).parent / "files" / "example_corsika.template",
corsika_path=Path(__file__).parent.parent / "corsika-77420" / "run" / "corsika77420Linux_SIBYLL_urqmd",
compare_files=Path(__file__).parent / "files" / "compare" / "DAT*"
corsika_path=Path(__file__).parent.parent
/ "corsika-77420"
/ "run"
/ "corsika77420Linux_SIBYLL_urqmd",
compare_files=Path(__file__).parent / "files" / "compare" / "DAT*",
):
runner = CliRunner()
result = runner.invoke(
cli,
[
f"{test_file_path}",
"--primary",
"{2212: 1, 1000260560: 1}", # proton and iron
"{2212: 1, 1000260560: 1}", # proton and iron
"--corsika",
f"{corsika_path}",
"--output",
"corsika_output",
"--seed",
"137",
"--jobs",
"1" # this also tests multi threading since we have one job per primary
]
"1", # this also tests multi threading since we have one job per primary
],
)

assert "cleanup now" in result.output
assert result.exit_code == 0

run_header, event_header, ps = read_DAT(glob=compare_files)
run_header_2, event_header_2, ps_2 = read_DAT(glob="corsika_output/DAT*")

assert run_header.equals(run_header_2)
assert event_header.equals(event_header_2)
assert ps.equals(ps_2)

0 comments on commit 54345a3

Please sign in to comment.