Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rsbeams/rsdata/switchyard.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def read_opal(file_name, step_number=None, species_name='Species'):
particle_data = np.empty((mp_count, 6))
for i, coord in enumerate(['x', 'px', 'y', 'py', 'z', 'pz']):
particle_data[:, i] = pcdata[loc+'/'+coord]
total_charge = pcdata[loc].attrs['CHARGE']
total_charge = pcdata[loc].attrs['CHARGE'][0]


# TODO: This shouldn't be specific to electrons
Expand Down Expand Up @@ -185,6 +185,7 @@ def write_opal(self, file_name, species_name):
"""
coordinates = self.species[species_name].coordinates
N = self.species[species_name].macroparticle_count
coordinates[:, 4] -= np.mean(coordinates[:, 4])

np.savetxt(file_name, coordinates, header='{}'.format(N), comments='')
return 0
Expand Down Expand Up @@ -216,7 +217,7 @@ def write_genesis(self, file_name, species_name, version='2.0'):
P = self.species[species_name].pt

vers_str = '? VERSION = '+version
charge_str = '? CHARGE = '+str(self.species[species_name].total_charge)
charge_str = '? CHARGE = '+str(abs(self.species[species_name].total_charge))
size_str = '? SIZE = '+str(len(X))
clmns_str = '? COLUMNS X PX Y PY T P'

Expand Down Expand Up @@ -254,4 +255,4 @@ def write(self, filename, code, species_name=None, **kwargs):

def _get_step_number(key, prefix='Step#'):
result = key.split(prefix)[-1]
return result
return result