Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiLehe committed Nov 8, 2017
2 parents 0eaec31 + 271dca2 commit be50542
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 83 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log / Release Log for openPMD-viewer

## 0.7.0

This version improves support for `ipywidgets` version 7, especially in
the layout of the slider.

In addition, with this version of `openPMD-viewer`, `matplotlib` is not a
strict requirement anymore. This allows lighter installation for users that
need `openPMD-viewer` only as a data reader.

Finally, the calculation of the laser envelope in 2D has been improved
(see [PR 170](https://github.com/openPMD/openPMD-viewer/pull/170)). Note
that the function `wstd` (which is not documented in the tutorial, but
which some users might still use) has been renamed to `w_std`.

## 0.6.0

This version improves the layout of the Jupyter GUI and allows the user to
Expand Down
9 changes: 4 additions & 5 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ username = <yourPypiUsername>

## Creating a release on Github

- Make sure that the version number in `opmd_viewer/__version__.py`
correspond to the new release, and that the corresponding changes have been
documented in `CHANGELOG.md`.
- Make sure that the version number in `opmd_viewer/__version__.py` **and**
in `conda_recipe/meta.yaml` correspond to the new release, and that
the corresponding changes have been documented in `CHANGELOG.md`.

- If everything works fine, then merge the `dev` version into `master`
and upload it to Github:
Expand All @@ -61,8 +61,7 @@ replace `pypi` by `pypitest` in the above set of commands)

## Uploading the package to Anaconda.org

- `cd` into the folder `conda_recipe` and make sure that the version
number in `meta.yaml` matches the current version.
- `cd` into the folder `conda_recipe`.

- Still in the folder `conda_recipe`, run
```
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.5.4" %}
{% set version = "0.7.0" %}

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.6.0"
__version__ = "0.7.0"
57 changes: 37 additions & 20 deletions opmd_viewer/addons/pic/lpa_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,16 @@ def get_laser_envelope( self, t=None, iteration=None, pol=None, m='all',
coord=pol, theta=theta, m=m,
slicing_dir=slicing_dir )
info = field[1]
if index == 'center':
# Get central slice
if index == 'all':
# Filter the full 2D array
envelope = self._fft_filter(field[0], freq_filter)
elif index == 'center':
# Filter the central slice (1D array)
field_slice = field[0][int( field[0].shape[0] / 2), :]
# Calculate inverse FFT of filtered FFT array
envelope = self._fft_filter(field_slice, freq_filter)
elif index == 'all':
envelope = np.array([ self._fft_filter(field[0][i, :], freq_filter)
for i in range(field[0].shape[0]) ])
else:
# Filter the requested slice (2D array)
field_slice = field[0][index, :]
# Calculate inverse FFT of filtered FFT array
envelope = self._fft_filter(field_slice, freq_filter)

# Restrict the metainformation to 1d if needed
Expand Down Expand Up @@ -475,24 +474,33 @@ def _fft_filter(self, field, freq_filter):
Parameters
----------
field : 1D array
field : 1D array or 2D array
Array with input data in time/space domain
When a 2D array is provided, filtering is performed along
the last dimension.
freq_filter : float
Frequency range in percent around the dominant frequency which will
not be filtered out
Returns
-------
A 1D array with filtered input data in time/space domain
A 1D array or 2D array with filtered input data in time/space domain
"""
# Number of sample points
N = field.size
# Fourier transform of the field slice
fft_field_slice = np.fft.fft(field)
# Number of sample points along the filtered direction
N = field.shape[-1]
fft_freqs = np.fft.fftfreq(N)
# Fourier transform of the field
fft_field = np.fft.fft(field, axis=-1)
# Find central frequency
central_freq_i = np.argmax(np.abs(fft_field_slice[:int(N / 2)]))
# (the code below works for both 1D and 2D arrays, and finds
# the global maximum across all dimensions in the case of the 2D array)
central_freq_i = np.unravel_index( np.argmax( np.abs(fft_field) ),
dims=fft_field.shape )[-1]
if central_freq_i > int( N / 2 ):
# Wrap index around, if it turns out to be in the
# negative-frequency part of the fft range
central_freq_i = N - central_freq_i
central_freq = fft_freqs[central_freq_i]
# Filter frequencies higher than central_freq * freq_filter/100
filter_bound = central_freq * freq_filter / 100.
Expand All @@ -501,12 +509,21 @@ def _fft_filter(self, field, freq_filter):
filter_freq_range_i = central_freq_i - filter_i
# Write filtered FFT array
filtered_fft = np.zeros_like( field, dtype=np.complex )
filtered_fft[int(N / 2) - filter_freq_range_i:
int(N / 2) + filter_freq_range_i] \
= fft_field_slice[central_freq_i - filter_freq_range_i:
central_freq_i + filter_freq_range_i]
# Calculate inverse FFT of filtered FFT array
envelope = np.abs(np.fft.ifft(np.fft.fftshift(2 * filtered_fft)))
# - Indices in the original fft array
i_fft_min = central_freq_i - filter_freq_range_i
i_fft_max = central_freq_i + filter_freq_range_i
# - Indices in the new filtered array
i_filter_min = int(N / 2) - filter_freq_range_i
i_filter_max = int(N / 2) + filter_freq_range_i
if field.ndim == 2:
filtered_fft[ :, i_filter_min:i_filter_max] = \
2 * fft_field[ :, i_fft_min:i_fft_max ]
elif field.ndim == 1:
filtered_fft[ i_filter_min:i_filter_max] = \
2 * fft_field[ i_fft_min:i_fft_max ]
# Calculate inverse FFT of filtered FFT array (along the last axis)
envelope = np.abs( np.fft.ifft(
np.fft.fftshift( filtered_fft, axes=-1 ), axis=-1 ) )

# Return the result
return( envelope )
Expand Down
Loading

0 comments on commit be50542

Please sign in to comment.