Skip to content

Commit

Permalink
Merge pull request #21 from ChristopherMayes/add_particlestatus_enum
Browse files Browse the repository at this point in the history
Add particlestatus enum
  • Loading branch information
ChristopherMayes authored Mar 23, 2022
2 parents 4b477c7 + cc02a9d commit 8c298f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pmd_beamphysics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .particles import ParticleGroup, single_particle
from .particles import ParticleGroup, single_particle
from .status import ParticleStatus
from .fields.fieldmesh import FieldMesh
from .readers import particle_paths
from .writers import pmd_init
Expand Down
8 changes: 6 additions & 2 deletions pmd_beamphysics/interfaces/astra.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from pmd_beamphysics.status import ParticleStatus
from pmd_beamphysics.readers import component_alias
import os

Expand Down Expand Up @@ -173,9 +174,12 @@ def vprint(*a, **k):
# Revese: 1->5, 2->1
status = particle_group.status
astra_status = status.copy()
astra_status[ np.where(status==1) ] = 5
astra_status[ np.where(status==2) ] = 1
astra_status[ np.where(status==1) ] = 5 # Astra normal (alive)
astra_status[ np.where(status==2) ] = 1 # Astra passive
astra_status[ np.where(status==ParticleStatus.CATHODE)] = -1 # Astra cathode

data['status'][i_start:] = astra_status

# Handle reference particle. If any -1 are found, assume we are starting at the cathode
if -1 in astra_status:
ref_particle['status']= -1 # At cathode
Expand Down
9 changes: 9 additions & 0 deletions pmd_beamphysics/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from enum import IntEnum

class ParticleStatus(IntEnum):
"""
Particle Status Enum
This is defined by the openPMD-beamphysics standard as integers.
"""
CATHODE = 0
ALIVE = 1

0 comments on commit 8c298f1

Please sign in to comment.