Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiLehe committed Jan 16, 2020
2 parents c11e1d8 + db7f9ee commit 7935632
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 245 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ matrix:
include:
- os: linux
python: "2.7"
- os: linux
python: "3.4"
- os: linux
python: "3.5"
- os: linux
python: "3.6"
- os: linux
python: "3.7"
- os: linux
python: "3.8"

before_install:
# Setup anaconda
Expand Down
2 changes: 1 addition & 1 deletion conda_recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "0.9.0" %}
{% set version = "0.9.1" %}

package:
name: openpmd_viewer
Expand Down
2 changes: 1 addition & 1 deletion opmd_viewer/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.0"
__version__ = "0.9.1"
27 changes: 18 additions & 9 deletions opmd_viewer/addons/pic/lpa_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,28 @@ def get_current( self, t=None, iteration=None, species=None, select=None,
var_list=['z', 'uz', 'uy', 'ux', 'w', 'charge'],
t=t, iteration=iteration,
species=species, select=select )
# Calculate Lorentz factor for all particles
gamma = np.sqrt(1 + ux ** 2 + uy ** 2 + uz ** 2)
# Calculate particle velocities
vz = uz / gamma * const.c
# Length to be seperated in bins
len_z = np.max(z) - np.min(z)
vzq_sum, _ = np.histogram(z, bins=bins, weights=(vz * w * q))
# Calculete the current in each bin
current = np.abs(vzq_sum * bins / (len_z * 1.e-6))

if w.size > 0:
min_z = np.min(z)
len_z = np.max(z) - min_z
# Calculate Lorentz factor for all particles
gamma = np.sqrt(1 + ux ** 2 + uy ** 2 + uz ** 2)
# Calculate particle velocities
vz = uz / gamma * const.c
# Length to be seperated in bins
len_z = np.max(z) - np.min(z)
vzq_sum, _ = np.histogram(z, bins=bins, weights=(vz * w * q))
# Calculate the current in each bin
current = np.abs(vzq_sum * bins / (len_z * 1.e-6))
else:
current = np.zeros(bins)
len_z = 0
min_z = 0
# Info object with central position of the bins
info = FieldMetaInformation( {0: 'z'}, current.shape,
grid_spacing=(len_z / bins, ), grid_unitSI=1,
global_offset=(np.min(z) + len_z / bins / 2,), position=(0,))
global_offset=(min_z + len_z / bins / 2,), position=(0,))
# Plot the result if needed
if plot:
check_matplotlib()
Expand Down
7 changes: 5 additions & 2 deletions opmd_viewer/openpmd_timeseries/data_reader/params_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def read_openPMD_params(filename, extract_parameters=True):
bpath = f[get_bpath(f)]
t = bpath.attrs["time"] * bpath.attrs["timeUnitSI"]

# If the user did not request more parameters, exit now.
# If the user did not request more parameters, close file and exit
if not extract_parameters:
f.close()
return(t, None)

# Otherwise, extract the rest of the parameters
Expand Down Expand Up @@ -123,7 +124,9 @@ def read_openPMD_params(filename, extract_parameters=True):
if ('particlesPath' in f.attrs): # Check for openPMD 1.1 files
particle_path = f.attrs['particlesPath'].decode().strip('/')
if particle_path in bpath.keys(): # Check for openPMD 1.0 files
particles_available = True
# Check that there is at least one species
if len(bpath[particle_path].keys()) > 0:
particles_available = True
if particles_available:
# Particles are present ; extract the species
params['avail_species'] = []
Expand Down
10 changes: 10 additions & 0 deletions opmd_viewer/openpmd_timeseries/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def get_particle(self, var_list=None, species=None, t=None, iteration=None,
hist_range = [[None, None], [None, None]]
for i_data in range(len(data_list)):
data = data_list[i_data]

# Check if the user specified a value
if (plot_range[i_data][0] is not None) and \
(plot_range[i_data][1] is not None):
Expand All @@ -307,6 +308,15 @@ def get_particle(self, var_list=None, species=None, t=None, iteration=None,
hist_range[i_data] = [ data.min(), data.max() ]
else:
hist_range[i_data] = [ -1., 1. ]

# Avoid error when the min and max are equal
if hist_range[i_data][0] == hist_range[i_data][1]:
if hist_range[i_data][0] == 0:
hist_range[i_data] = [ -1., 1. ]
else:
hist_range[i_data][0] *= 0.99
hist_range[i_data][1] *= 1.01

hist_bins = [ nbins for i_data in range(len(data_list)) ]
# - Then, if required by the user, modify this values by
# fitting them to the spatial grid
Expand Down
272 changes: 42 additions & 230 deletions tutorials/5_Laser-plasma_tools.ipynb

Large diffs are not rendered by default.

0 comments on commit 7935632

Please sign in to comment.