Skip to content

Commit

Permalink
Merge pull request #392 from AngelFP/add_r_particles
Browse files Browse the repository at this point in the history
Simplify names of radial particle components
  • Loading branch information
RemiLehe authored Sep 25, 2023
2 parents f6140de + 4e46b60 commit 3b38a54
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def read_species_data( self, iteration, species, record_comp, extensions):
record_comp: string
The record component to extract
Either 'x', 'y', 'z', 'ux', 'uy', 'uz', or 'w'
Either 'x', 'y', 'z', 'r', 'ux', 'uy', 'uz', 'ur', or 'w'
extensions: list of strings
The extensions that the current OpenPMDTimeSeries complies with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def simplify_record(record_comps):
record_comps.remove('position/z')
record_comps.remove('positionOffset/z')
record_comps.append('z')
if ('position/r' in record_comps) and ('positionOffset/r' in record_comps):
record_comps.remove('position/r')
record_comps.remove('positionOffset/r')
record_comps.append('r')

# Replace the names of the momenta
if 'momentum/x' in record_comps:
Expand All @@ -218,6 +222,9 @@ def simplify_record(record_comps):
if 'momentum/z' in record_comps:
record_comps.remove('momentum/z')
record_comps.append('uz')
if 'momentum/r' in record_comps:
record_comps.remove('momentum/r')
record_comps.append('ur')

# Replace the name for 'weights'
if 'weighting' in record_comps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read_species_data(filename, iteration, species, record_comp, extensions):
record_comp: string
The record component to extract
Either 'x', 'y', 'z', 'ux', 'uy', 'uz', or 'w'
Either 'x', 'y', 'z', 'r', 'ux', 'uy', 'uz', 'ur', or 'w'
extensions: list of strings
The extensions that the current OpenPMDTimeSeries complies with
Expand All @@ -43,9 +43,11 @@ def read_species_data(filename, iteration, species, record_comp, extensions):
dict_record_comp = {'x': 'position/x',
'y': 'position/y',
'z': 'position/z',
'r': 'position/r',
'ux': 'momentum/x',
'uy': 'momentum/y',
'uz': 'momentum/z',
'ur': 'momentum/r',
'w': 'weighting'}
if record_comp in dict_record_comp:
opmd_record_comp = dict_record_comp[record_comp]
Expand Down Expand Up @@ -78,11 +80,11 @@ def read_species_data(filename, iteration, species, record_comp, extensions):
data *= w ** (-weighting_power)

# - Return positions, with an offset
if record_comp in ['x', 'y', 'z']:
if record_comp in ['x', 'y', 'z', 'r']:
offset = get_data(species_grp['positionOffset/%s' % record_comp])
data += offset
# - Return momentum in normalized units
elif record_comp in ['ux', 'uy', 'uz' ]:
elif record_comp in ['ux', 'uy', 'uz', 'ur']:
m = get_data(species_grp['mass'])
# Normalize only if the particle mass is non-zero
if np.all( m != 0 ):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def simplify_record(record_comps):
record_comps.remove('position/z')
record_comps.remove('positionOffset/z')
record_comps.append('z')
if ('position/r' in record_comps) and ('positionOffset/r' in record_comps):
record_comps.remove('position/r')
record_comps.remove('positionOffset/r')
record_comps.append('r')

# Replace the names of the momenta
if 'momentum/x' in record_comps:
Expand All @@ -195,6 +199,9 @@ def simplify_record(record_comps):
if 'momentum/z' in record_comps:
record_comps.remove('momentum/z')
record_comps.append('uz')
if 'momentum/r' in record_comps:
record_comps.remove('momentum/r')
record_comps.append('ur')

# Replace the name for 'weights'
if 'weighting' in record_comps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read_species_data(series, iteration, species_name, component_name,
component_name: string
The record component to extract
Either 'x', 'y', 'z', 'ux', 'uy', 'uz', or 'w'
Either 'x', 'y', 'z', 'r', 'ux', 'uy', 'uz', 'ur', or 'w'
extensions: list of strings
The extensions that the current OpenPMDTimeSeries complies with
Expand All @@ -43,9 +43,11 @@ def read_species_data(series, iteration, species_name, component_name,
dict_record_comp = {'x': ['position', 'x'],
'y': ['position', 'y'],
'z': ['position', 'z'],
'r': ['position', 'r'],
'ux': ['momentum', 'x'],
'uy': ['momentum', 'y'],
'uz': ['momentum', 'z'],
'ur': ['momentum', 'r'],
'w': ['weighting', None]}

if component_name in dict_record_comp:
Expand Down Expand Up @@ -84,11 +86,11 @@ def read_species_data(series, iteration, species_name, component_name,
data *= w ** (-weighting_power)

# - Return positions, with an offset
if component_name in ['x', 'y', 'z']:
if component_name in ['x', 'y', 'z', 'r']:
offset = get_data(series, species['positionOffset'][component_name])
data += offset
# - Return momentum in normalized units
elif component_name in ['ux', 'uy', 'uz' ]:
elif component_name in ['ux', 'uy', 'uz', 'ur']:
mass_component = next(species['mass'].items())[1]
m = get_data(series, mass_component)
# Normalize only if the particle mass is non-zero
Expand Down

0 comments on commit 3b38a54

Please sign in to comment.