Skip to content

Commit

Permalink
FIX: ignore 'Meta' in Genesis4 4.6.7 particle HDF5 root
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-lauer committed Nov 19, 2024
1 parent 0a5625a commit eadb8f5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pmd_beamphysics/interfaces/genesis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import numpy as np
from h5py import File
from h5py import File, Group

from pmd_beamphysics.statistics import twiss_calc
from pmd_beamphysics.units import c_light, mec2, unit, write_unit_h5
Expand Down Expand Up @@ -438,8 +438,8 @@ def write_genesis4_distribution(particle_group, h5file, verbose=False):

def genesis4_par_to_data(h5, species="electron", smear=True):
"""
Converts elegant data from an h5 handle or file
to data for openPMD-beamphysics.
Converts Genesis 4 data from an h5 handle or file to data for
openPMD-beamphysics.
Genesis4 datasets in the HDF5 file are named:
'x'
Expand All @@ -460,19 +460,20 @@ def genesis4_par_to_data(h5, species="electron", smear=True):
Parameters
----------
h5: open h5py handle or str
h5 : open h5py handle or str
smear: bool:
species : str, default="electron"
smear : bool, default=True
Genesis4 often samples the beam by skipping slices
in a step called 'sample'.
This will smear out the theta coordinate over these slices,
preserving the modulus.
Returns
-------
data: dict for ParticleGroup
data : dict
For ParticleGroup
"""
# Allow for opening a file
if isinstance(h5, str):
Expand Down Expand Up @@ -515,8 +516,11 @@ def genesis4_par_to_data(h5, species="electron", smear=True):
weight = []

i0 = 0
for sname in sorted([g for g in h5 if g not in scalars]):
for sname in sorted(g for g in h5 if g not in scalars):
g = h5[sname]
if not isinstance(g, Group) or "current" not in g:
# Groups like 'Meta' do not contain slice data.
continue

current = g["current"][:] # I * s_spacing/c = Q
assert len(current) == 1
Expand Down

0 comments on commit eadb8f5

Please sign in to comment.