Readers
Lower-level routines for loading openPMD-beamphysics particle data.
Particles
load_bunch_data
load_bunch_data(h5: Group, include_time_offset: bool = True) -> dict
Load particles from the only species in this iteration of an OpenPMD BeamPhysics file into a dict of numpy arrays. Raises if more than one or no species.
Parameters:
-
h5(Group) –Particle group, one iteration holding either a single species subgroup or the records themselves (legacy).
-
include_time_offset(bool, default:True) –Add the "timeOffset" record to
t. The position and momentum offsets are always included. Default is True.
Returns:
-
dict–See
beamphysics.readers.load_species_data.
Source code in beamphysics/readers.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
load_species_data
load_species_data(h5: Group, include_time_offset: bool = True) -> dict
Load a single species into a dict of numpy arrays.
Parameters:
-
h5(Group) –Group holding the particle records.
-
include_time_offset(bool, default:True) –Add the "timeOffset" record to
t. The position and momentum offsets are always included. Default is True.
Returns:
-
dict–Keys 'x', 'px', 'y', 'py', 'z', 'pz', 't', 'status', 'weight' (arrays), 'species' (str), 'total_charge' (float), and whichever of the optional per-particle records in
OPTIONAL_PARTICLE_KEYS('id', 's', 'ix_branch', 'ix_ele', 'location', 'p0c', 'spin_x', 'spin_y', 'spin_z', 'charge_state') the group holds, as arrays.
Source code in beamphysics/readers.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
Time offsets
load_only_time_offset
load_only_time_offset(h5: str | Path | File | Group) -> float | ndarray
Load the time offset of the only species of the only iteration.
Parameters:
-
h5(str, pathlib.Path, h5py.File, or h5py.Group) –Filename of an openPMD file, or an open handle. A handle carrying the openPMD attributes is resolved to its single iteration; one that does not is taken to be the particle group itself.
Returns:
-
float or ndarray–See
load_time_offset.
Source code in beamphysics/readers.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
load_time_offset
load_time_offset(h5: Group) -> float | ndarray
Load the time offset of a single species.
Parameters:
-
h5(Group) –Group holding the particle records.
Returns:
-
float or ndarray–Offset in seconds: a float for a constant component, an array of length n_particle for a per-particle component, and 0.0 when the group has no "timeOffset" record.
Source code in beamphysics/readers.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
Navigation
particle_paths
particle_paths(h5, key='particlesPath')
Uses the basePath and particlesPath to find where openPMD particles should be
Source code in beamphysics/readers.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
particle_array
particle_array(h5, component, slice=slice(None), include_offset=True)
Main routine to return particle arrays in fixed units. All units are SI except momentum, which will be in eV/c.
Example: particle_array(h5['data/00001/particles/'], 'px') Will return the momentum/x + momentumOffset/x in eV/c.
Source code in beamphysics/readers.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |