SimEx.Analysis package

SimEx.Analysis.AbstractAnalysis module

module AbstractAnalysis

Hosts the abstract base class for all analysis classes.

class SimEx.Analysis.AbstractAnalysis.AbstractAnalysis(input_path=None)[source]

Bases: object

Class AbstractAnalysis

Abstract base class for all data analysis classes.

Parameters

input_path (str) – Path to hdf5 file holding the data to analyze. Single file or directory.

classmethod dumpLoader(fname)[source]

Creates calculator object from a dump file

Parameters

fname – path to the dump file.

Returns

Created calculator object.

Raises

RuntimeError – if cannot create object.

dumpToFile(fname)[source]

dump class instance to file.

Parameters

fname – Path to file to dump.

property input_path

Query for the input file path(s).

classmethod runFromCLI()[source]

Method to start calculator computations from command line.

Returns

exit with status code

SimEx.Analysis.AbstractAnalysis.checkAndSetBaseCalculator(var=None, default=None)[source]

Check if passed object is an AbstractAnalysis instance. If non is given, set to given default.

Parameters
  • var – The object to check.

  • default – The default to use.

Returns

The checked object.

Raises

RuntimeError – if no valid Analysis object was given.

SimEx.Analysis.DiffractionAnalysis module

module DiffractionAnalysis

Module that hosts the DiffractionAnalysis class.

class SimEx.Analysis.DiffractionAnalysis.DiffractionAnalysis(input_path=None, pattern_indices=None, poissonize=True, mask=None)[source]

Bases: SimEx.Analysis.AbstractAnalysis.AbstractAnalysis

Class DiffractionAnalysis

Class that implements common data analysis tasks for diffraction data.

Parameters
  • input_path (str) – Name of file or directory that contains data to analyse.

  • pattern_indices (int || sequence of int || "all") – Identify which patterns to include in the analysis (default “all”).

  • poissonize (bool) – Whether to add Poisson noise to the integer photon numbers (default True).

  • mask (numpy.array) – Mask to multiply on each pattern.

Example pattern_indices

pattern_indices=1

pattern_indices=[1,2,3]

pattern_indices=range(1,10)

pattern_indices=”all”

animatePatterns(output_path=None, logscale=False, offset=0.1)[source]

Make an animated gif out of the given patterns.

Parameters
  • output_path (str) – Where to save the animated git.

  • logscale (bool) – Whether to apply logarithmic scaling to the z axis (color).

  • offset (float) – Offset to apply if logarithmic scaling is on.

Raises

IOError – File exists or parent directory not found.

property mask

Query the mask.

property npattern

get the number of the selected patterns in this analysis object

numpyPattern(operation=None)[source]

Return the pattern after opentation over the patterns defined in DiffractionAnalysis class.

Parameters

operation (python function) – Operation to apply to selected patterns (default none).

Note operation

Operation must accept a 3D numpy.array as first input argument and the “axis” keyword-argument. Operation must return a 2D numpy.array. Axis will always be chosen as axis=0.

Example operation

numpy.mean, numpy.std, numpy.sum

property parameters
patternGenerator()[source]

Yield an iterator over a given pattern sequence from a diffraction file.

property pattern_indices

Query pattern indices attribute.

property patterns_iterator
plotPattern(operation=None, logscale=False, offset=0.1, symlog=False, *argv, **kwargs)[source]

Plot a pattern.

Parameters
  • operation (python function) – Operation to apply to selected patterns (default numpy.sum).

  • logscale (bool) – Whether to plot the intensity on a logarithmic scale (z-axis) (default False).

  • offset (float) – Offset to apply if logarithmic scaling is on.

Note operation

Operation must accept a 3D numpy.array as first input argument and the “axis” keyword-argument. Operation must return a 2D numpy.array. Axis will always be chosen as axis=0.

Example operation

numpy.mean, numpy.std, numpy.sum

plotRadialProjection(operation=None, logscale=False, offset=1e-05, unit='q_nm^-1')[source]

Plot the radial projection of a pattern.

Parameters
  • operation (python function) – Operation to apply to selected patterns (default numpy.sum).

  • logscale (bool) – Whether to plot the intensity on a logarithmic scale (z-axis) (default False).

Note operation

Operation must accept a 3D numpy.array as first input argument and the “axis” keyword-argument. Operation must return a 2D numpy.array. Axis will always be chosen as axis=0.

Example operation

numpy.mean, numpy.std, numpy.sum

:param unit:can be “q_nm^-1”, “q_A^-1”, “2th_deg”, “2th_rad”, “r_mm”. :type unit: str

property poissonize

Query whether to read data with (True) or without (False) Poisson noise.

property qMap

q of each pixel

shannonPixelPhoton(resolution)[source]

Get the average number of photons per shannon pixel

Parameters

resolution (float) – The full periodic resolution (A) for shannon pixels

property solidAngles

Solid angle of each pixel

statistics()[source]

Get statistics of photon numbers per pattern (mean and rms) over selected patterns and plot a historgram.

SimEx.Analysis.DiffractionAnalysis.azimuthalIntegration(pattern, parameters, unit='q_nm^-1')[source]
SimEx.Analysis.DiffractionAnalysis.diffractionParameters(path)[source]

Extract beam parameters and geometry from given file or directory.

Parameters

path (str) – Path to file that holds the parameters to extract.

SimEx.Analysis.DiffractionAnalysis.photonStatistics(stack)[source]
SimEx.Analysis.DiffractionAnalysis.plotImage(pattern, logscale=False, offset=0.1, symlog=False, *argv, **kwargs)[source]

Workhorse function to plot an image

Parameters
  • logscale (bool) – Whether to show the data on logarithmic scale (z axis) (default False).

  • offset (float) – Offset to apply if logarithmic scaling is on.

  • symlog (bool) – If logscale is True, to show the data on symlogarithmic scale (z axis) (default False).

Returns

the handles of figure and axis

Return type

figure,axis

SimEx.Analysis.DiffractionAnalysis.plotRadialProjection(pattern, parameters, logscale=True, offset=1e-05, unit='q_nm^-1')[source]

Perform integration over azimuthal angle and plot as function of radius.

:param unit:can be “q_nm^-1”, “q_A^-1”, “2th_deg”, “2th_rad”, “r_mm”. :type unit: str

SimEx.Analysis.DiffractionAnalysis.plotResolutionRings(parameters, rings=(10, 5.0, 3.5), half=True)[source]

Show resolution rings on current plot.

Parameters
  • parameters (dict) – Parameters needed to construct the resolution rings.

  • rings (list) – the rings shown on the figure

  • half (bool) – show half period resolution (True, default) or full period resolution (False)

SimEx.Analysis.DiffractionAnalysis.totalNPattern(input_path)[source]

get the number of the diffraction patterns in the h5file

SimEx.Analysis.XFELPhotonAnalysis module

module XFELPhotonAnalysis

Module that hosts the XFELPhotonAnalysis class.

class SimEx.Analysis.XFELPhotonAnalysis.XFELPhotonAnalysis(input_path=None)[source]

Bases: SimEx.Analysis.AbstractAnalysis.AbstractAnalysis

Class XFELPhotonAnalysis

Class that implements common data analysis tasks for wavefront (radiation field) data.

Parameters

input_path (str) – Name of file or directory that contains data to analyse.

animate(qspace=False, logscale=False)[source]

Generate an animated gif from the wavefront data.

property intensity

Query for the intensity.

numpyTotalPower(spectrum=False, all=False)[source]

Method to dump meaningful total power.

Parameters
  • spectrum (bool) – Whether to dump the power density in energy domain (True) or time domain (False, default).

  • all (bool) – True to extract all the points, False to extract only meaningful points

plotIntensityMap(qspace=False, logscale=False)[source]

Plot the integrated intensity as function of x,y or qx, qy on a colormap.

Parameters
  • qspace (bool) – Whether to plot the reciprocal space intensity map (default False).

  • logscale (bool) – Whether to plot the intensity on a logarithmic scale (z-axis) (default False).

plotOnAxisPowerDensity(spectrum=False)[source]

Method to plot the on-axis power density.

Parameters

spectrum (bool) – Whether to plot the power density in energy domain (True) or time domain (False, default).

plotTotalPower(spectrum=False)[source]

Method to plot the total power.

Parameters

spectrum (bool) – Whether to plot the power density in energy domain (True) or time domain (False, default).

property wavefront

Query for the wavefront.

SimEx.Analysis.XFELPhotonAnalysis.calculate_fwhm(wfr)[source]

Calculate FWHM of the beam calculating number of point bigger then max/2 throuhgt center of the image

Parameters

wfr – wavefront

Returns

{‘fwhm_x’:fwhm_x, ‘fwhm_y’: fwhm_y} in [m]

SimEx.Analysis.XFELPhotonAnalysis.mask_nans(a, replacement=0.0)[source]

Find nans in an array and replace. :param a: Array to mask. :type a: numpy.array

Parameters

replacement (numeric) – The value to replace nans.

Returns

The array of booleans indicating which values of a are nan, numpy.isnan(a)

Return type

numpy.array(dtype=bool)

SimEx.Analysis.XMDYNPhotonMatterAnalysis module

module XMDYNPhotonMatterAnalysis

Hosting utilities to analyse and visualize photon-matter trajectories generated by XMDYN.

class SimEx.Analysis.XMDYNPhotonMatterAnalysis.XMDYNPhotonMatterAnalysis(input_path=None, snapshot_indices=None, elements=None, sample_path=None)[source]

Bases: SimEx.Analysis.AbstractAnalysis.AbstractAnalysis

Class XMDYNPhotonMatterAnalysis

Class to encapsulate diagnostics of photon matter interaction trajectories.

Parameters
  • input_path (str) – Path to the data to analyze.

  • snapshot_indices (list) – Snapshot (indices or IDs) to analyze (Default: All).

  • elements (list) – Which elements to include in the analysis (Default: All).

animate()[source]

Generate an animation of atom trajectories and their ionization.

property elements

Query the elements to include.

property input_path

Query the input path.

load_snapshot(snapshot_index)[source]

Load snapshot data from hdf5 file into memory.

load_trajectory()[source]

Load the selected snapshots and extract data to analyze.

number_of_snapshots()[source]

Get number of valid snapshots.

plot_charge()[source]

Plot the average number of electrons per atom per atomic species as function of time.

plot_displacement()[source]

Plot the average displacement per atomic species as function of time.

plot_energies()[source]

Plot the evolution of MD energies over the simulation time.

property sample_path

Query the sample path.

property snapshot_indices

Query the snapshot indices.

SimEx.Analysis.XMDYNPhotonMatterAnalysis.calculate_displacement(snapshot, r0, sample)[source]

Calculate the average displacement per atomic species in a snapshot.

Parameters
  • snapshot (dict) – The snapshot to analyze

  • r0 (numpy.array (shape=(Natoms, 3))) – Unperturbed positions of the sample atoms.

### CHECKME: Can’t we read r0 from the sample dict?

Parameters

sample (dict) – Sample data

SimEx.Analysis.XMDYNPhotonMatterAnalysis.calculate_ion_charge(snapshot, sample)[source]

Calculate the remaining electric charge per atomic species of a given snapshot.

Parameters
  • snapshot (dict) – The snapshot to analyze

  • sample (dict) – The sample data.

SimEx.Analysis.XMDYNPhotonMatterAnalysis.load_sample(sample_path)[source]

Load a sample file into memory.

SimEx.Analysis.XMDYNPhotonMatterAnalysis.read_h5_dataset(path, dataset)[source]

Read a dataset from hdf5 file.