emout.core.backtrace package¶
Submodules¶
emout.core.backtrace.backtrace_result module¶
Single-particle backtrace result container.
BacktraceResult stores the trajectory and field values along a
single particle backtrace and provides attribute-based column access.
- class emout.core.backtrace.backtrace_result.BacktraceResult(ts, probability, positions, velocities, unit=None)[source]¶
Bases:
objectContainer for a single-particle backtrace result.
Attributes (all NumPy arrays):
ts– shape(N_steps,)probability– shape(N_steps,)positions– shape(N_steps, 3)(x, y, z)velocities– shape(N_steps, 3)(vx, vy, vz)
Usage:
ts, prob, pos, vel = result # tuple unpacking result.pair("x", "y").plot() # x vs y result.pair("t", "x").plot() # t vs x result.tx.plot() # shorthand for pair("t", "x") result.yvz.plot() # shorthand for pair("y", "vz")
emout.core.backtrace.multi_backtrace_result module¶
Multi-particle backtrace result container.
MultiBacktraceResult aggregates multiple BacktraceResult
instances and supports sampling, iteration, and statistical queries.
- class emout.core.backtrace.multi_backtrace_result.MultiBacktraceResult(ts_list, probabilities, positions_list, velocities_list, last_indexes, unit=None)[source]¶
Bases:
objectContainer for multiple particle backtrace results.
Attributes (all NumPy arrays):
ts_list– shape(N_traj, N_steps)probabilities– shape(N_traj,)positions_list– shape(N_traj, N_steps, 3)velocities_list– shape(N_traj, N_steps, 3)last_indexes– shape(N_traj,)
Usage:
ts_list, probs, pos_list, vel_list = result # tuple unpacking result.pair("x", "y") # MultiXYData: x vs y per trajectory result.pair("t", "x") # t vs x per trajectory result.tvx # shorthand for pair("t", "vx") result.sample(10) # randomly sample 10 trajectories result.sample([0,2,5]) # pick specific trajectory indices result.yvz.plot()
- pair(var1, var2)[source]¶
Extract two variables and return a MultiXYData.
Parameters var1 and var2 must each be one of
't','x','y','z','vx','vy','vz'.Examples:
result.pair("x", "y") # x vs y per trajectory result.pair("t", "x") # t vs x per trajectory result.tvy # shorthand for pair("t", "vy")
- Return type:
emout.core.backtrace.probability_result module¶
Energy-flux probability distribution results.
ProbabilityResult computes and visualises energy-resolved pitch-angle
distributions, while HeatmapData wraps 2-D histogram payloads.
- class emout.core.backtrace.probability_result.HeatmapData(X, Y, Z, xlabel='X', ylabel='Y', title='Heatmap', units=None)[source]¶
Bases:
object2-D histogram data with axis labels and a plot helper.
Stores bin edges, counts, and axis metadata produced by
ProbabilityResultcomputations.- plot(ax=None, cmap='viridis', use_si=True, offsets=None, **plot_kwargs)[source]¶
Plot the heatmap with
pcolormesh().- Parameters:
ax (matplotlib.axes.Axes, optional) – Target axes. If
None, uses the current axes.cmap (str, default
"viridis") – Colormap name.use_si (bool, default True) – Convert axes to SI units when unit info is available.
offsets (tuple of (float or str), optional) –
(x_offset, y_offset)applied to the grid axes. Accepts"left","center","right"or a numeric shift.**plot_kwargs – Forwarded to
matplotlib.axes.Axes.pcolormesh().
- Return type:
- class emout.core.backtrace.probability_result.ProbabilityResult(phases, probabilities, dims, ret_particles, particles, ispec, inp, unit=None)[source]¶
Bases:
objectPhase-space probability distribution result.
Stores a 6-D grid of arrival probabilities and provides methods to project onto any 2-variable plane
(var1, var2)as aHeatmapData.- pair(var1, var2)[source]¶
Project onto a 2-variable plane and return a HeatmapData.
Parameters var1 and var2 must each be one of
'x','y','z','vx','vy','vz'. Axes not selected are integrated out using the trapezoidal rule.- Return type:
emout.core.backtrace.solver_wrapper module¶
High-level wrapper for particle backtrace solvers.
BacktraceWrapper configures field interpolation, integrator
parameters, and optional Dask-based remote execution, then delegates
to the underlying ODE solver.
- class emout.core.backtrace.solver_wrapper.BacktraceWrapper(directory, inp, unit, remote_open_kwargs=None)[source]¶
Bases:
objectHigh-level wrapper for particle backtrace solvers.
Configures field interpolation, integrator parameters, and optional Dask-based remote execution, then delegates to the underlying ODE solver. Input positions, velocities, phase-space axes, and
dtare forwarded tovdsolverfin EMSES simulation units; convert SI values before calling these APIs.- get_backtrace(position, velocity, ispec=0, istep=-1, dt=None, max_step=30000, output_interval=1, use_adaptive_dt=False, **kwargs)[source]¶
Run a single-particle backtrace and return the trajectory.
- Parameters:
position (np.ndarray) – Initial particle position in EMSES simulation units.
velocity (np.ndarray) – Initial particle velocity in EMSES simulation units.
ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
output_interval (int, optional) – Output interval in steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Trajectory data containing times, probability, positions, and velocities.
- Return type:
- get_backtraces(positions, velocities, ispec=0, istep=-1, dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, **kwargs)[source]¶
Run backtraces for multiple particles and return aggregated results.
- Parameters:
positions (np.ndarray) – Particle position array in EMSES simulation units, shape
(N, 3).velocities (np.ndarray) – Particle velocity array in EMSES simulation units, shape
(N, 3).ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
output_interval (int, optional) – Output interval in steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
n_threads (int, optional) – Number of parallel threads
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Aggregated trajectory data for all particles.
- Return type:
- get_backtraces_from_particles(particles, ispec=0, istep=-1, dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, **kwargs)[source]¶
Run backtraces from pre-built Particle objects.
- Parameters:
particles (Sequence[Any]) – Collection of
vdsolverf.core.Particleobjects whose positions and velocities are already in EMSES simulation units.ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
output_interval (int, optional) – Output interval in steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
n_threads (int, optional) – Number of parallel threads
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Aggregated trajectory data for all particles.
- Return type:
- get_probabilities(x, y, z, vx, vy, vz, ispec=0, istep=-1, dt=None, max_step=10000, use_adaptive_dt=False, n_threads=4, remote=True, **kwargs)[source]¶
Compute arrival probabilities over a 6-D phase-space grid.
- Parameters:
x (tuple of (float, float, int) or sequence of float) – X coordinates or grid specification
(start, stop, n)in EMSES simulation units.y (tuple of (float, float, int) or sequence of float) – Y coordinates or grid specification in EMSES simulation units.
z (tuple of (float, float, int) or sequence of float) – Z coordinates or grid specification in EMSES simulation units.
vx (tuple of (float, float, int) or sequence of float) – Velocity x-component values or grid specification in EMSES simulation units.
vy (tuple of (float, float, int) or sequence of float) – Velocity y-component values or grid specification in EMSES simulation units.
vz (tuple of (float, float, int) or sequence of float) – Velocity z-component values or grid specification in EMSES simulation units.
ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
n_threads (int, optional) – Number of parallel threads
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Phase-space probability distribution.
- Return type:
- get_probabilities_from_array(positions, velocities, ispec=0, istep=-1, dt=None, max_step=10000, use_adaptive_dt=False, n_threads=4, **kwargs)[source]¶
Compute arrival probabilities from position/velocity arrays.
- Parameters:
positions (np.ndarray) – Particle position array in EMSES simulation units, shape
(N, 3).velocities (np.ndarray) – Particle velocity array in EMSES simulation units, shape
(N, 3).ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
n_threads (int, optional) – Number of parallel threads
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Raw probability array returned by the backend.
- Return type:
Any
- get_probabilities_from_particles(particles, ispec=0, istep=-1, dt=None, max_step=10000, use_adaptive_dt=False, n_threads=4, **kwargs)[source]¶
Compute arrival probabilities from pre-built Particle objects.
- Parameters:
particles (Sequence[Any]) – Collection of
vdsolverf.core.Particleobjects whose positions and velocities are already in EMSES simulation units.ispec (int, optional) – Particle species index (0-based)
istep (int, optional) – Starting time-step index
dt (float or None, optional) – Time step size in EMSES simulation units. The value is forwarded unchanged; passing a negative value such as
-data.inp.dtruns the solver in the opposite integration direction.max_step (int, optional) – Maximum number of backtrace steps
use_adaptive_dt (bool, optional) – If True, use adaptive time stepping during backtrace
n_threads (int, optional) – Number of parallel threads
**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Raw probability array returned by the backend.
- Return type:
Any
emout.core.backtrace.trace_result module¶
Integrated trace workflow result containers.
- class emout.core.backtrace.trace_result.TraceResult(direction, probabilities=None, backward_traces=None, forward_traces=None, phases=None, dims=None, particles=None, unit=None)[source]¶
Bases:
objectIntegrated result returned by the high-level
data.traceAPI.The object always has the same shape regardless of which payloads were requested. Probability and trajectory payloads that were not requested are stored as
None.- property alpha¶
Return probability-derived alpha values, or
Noneif unavailable.
- plot(var1='vx', var2='vz', kind='auto', direction=None, **plot_kwargs)[source]¶
Plot probabilities when available, otherwise plot trajectories.
- plot3d(direction=None, plotter=None, use_si=True, offsets=None, show=False, alpha='auto', color='white', line_width=2.0, tube_radius=None, **mesh_kwargs)[source]¶
Draw trajectories on a PyVista plotter and return it.
Passing an existing
plotteroverlays the trajectories on the caller’s current 3-D field or boundary view.
- plot_probabilities(var1='vx', var2='vz', **plot_kwargs)[source]¶
Plot the probability projection for
var1andvar2.
- plot_traces(var1='x', var2='z', direction=None, alpha='auto', **plot_kwargs)[source]¶
Plot trajectory pairs with optional probability-derived alpha.
- property traces¶
Return the unambiguous trajectory payload.
both()results contain two trajectory payloads, so callers must usebackward_tracesorforward_tracesexplicitly.
emout.core.backtrace.trace_wrapper module¶
High-level trace workflow facade built on top of backtrace solvers.
- class emout.core.backtrace.trace_wrapper.TraceWrapper(directory, inp, unit, remote_open_kwargs=None)[source]¶
Bases:
objectHigh-level trace API exposed as
data.trace.- backward(x, y, z, vx, vy, vz, ispec=0, istep=-1, dt=None, probability_dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, get_trace=False, get_probabilities=True, remote=True, **kwargs)[source]¶
Compute a backward trace workflow over a phase-space grid.
- Return type:
- both(x, y, z, vx, vy, vz, ispec=0, istep=-1, dt=None, probability_dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, get_trace=False, get_probabilities=True, remote=True, **kwargs)[source]¶
Compute backward and forward trajectories from one phase-space grid.
- Return type:
emout.core.backtrace.xy_data module¶
Lightweight x-y pair data containers for backtrace visualisation.
XYData holds a single named curve, while MultiXYData
groups several curves for overlay plotting.
- class emout.core.backtrace.xy_data.MultiXYData(x, y, last_indexes, xlabel='x', ylabel='y', title=None, units=None)[source]¶
Bases:
objectCollection of
XYDatacurves for overlay plotting.- plot(ax=None, use_si=True, gap=None, offsets=None, **plot_kwargs)[source]¶
Plot all series as overlaid line plots.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Target axes.
use_si (bool, default True) – Convert to SI units when available.
gap (float, optional) – Insert NaN breaks where consecutive-point distance exceeds gap.
offsets (tuple of (float or str), optional) –
(x_offset, y_offset)applied after unit conversion.**plot_kwargs – Forwarded to
matplotlib.axes.Axes.plot().alphamay be a scalar or a per-series array of length N.
- Return type:
- class emout.core.backtrace.xy_data.XYData(x, y, xlabel='x', ylabel='y', title=None, units=None)[source]¶
Bases:
objectNamed x-y curve with optional unit labels and a plot helper.
- plot(ax=None, use_si=True, gap=None, offsets=None, **plot_kwargs)[source]¶
Plot the x-y curve.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Target axes. If
None, uses the current axes.use_si (bool, default True) – Convert to SI units when available.
gap (float, optional) – Insert NaN breaks where consecutive-point distance exceeds gap.
offsets (tuple of (float or str), optional) –
(x_offset, y_offset)applied after unit conversion.**plot_kwargs – Forwarded to
matplotlib.axes.Axes.plot().
- Return type:
Module contents¶
Backtrace analysis subpackage.
Provides solvers and result containers for computing particle backtraces and energy-flux probability distributions from EMSES output.
- class emout.core.backtrace.TraceResult(direction, probabilities=None, backward_traces=None, forward_traces=None, phases=None, dims=None, particles=None, unit=None)[source]¶
Bases:
objectIntegrated result returned by the high-level
data.traceAPI.The object always has the same shape regardless of which payloads were requested. Probability and trajectory payloads that were not requested are stored as
None.- property alpha¶
Return probability-derived alpha values, or
Noneif unavailable.
- plot(var1='vx', var2='vz', kind='auto', direction=None, **plot_kwargs)[source]¶
Plot probabilities when available, otherwise plot trajectories.
- plot3d(direction=None, plotter=None, use_si=True, offsets=None, show=False, alpha='auto', color='white', line_width=2.0, tube_radius=None, **mesh_kwargs)[source]¶
Draw trajectories on a PyVista plotter and return it.
Passing an existing
plotteroverlays the trajectories on the caller’s current 3-D field or boundary view.
- plot_probabilities(var1='vx', var2='vz', **plot_kwargs)[source]¶
Plot the probability projection for
var1andvar2.
- plot_traces(var1='x', var2='z', direction=None, alpha='auto', **plot_kwargs)[source]¶
Plot trajectory pairs with optional probability-derived alpha.
- property traces¶
Return the unambiguous trajectory payload.
both()results contain two trajectory payloads, so callers must usebackward_tracesorforward_tracesexplicitly.
- class emout.core.backtrace.TraceWrapper(directory, inp, unit, remote_open_kwargs=None)[source]¶
Bases:
objectHigh-level trace API exposed as
data.trace.- backward(x, y, z, vx, vy, vz, ispec=0, istep=-1, dt=None, probability_dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, get_trace=False, get_probabilities=True, remote=True, **kwargs)[source]¶
Compute a backward trace workflow over a phase-space grid.
- Return type:
- both(x, y, z, vx, vy, vz, ispec=0, istep=-1, dt=None, probability_dt=None, max_step=10000, output_interval=1, use_adaptive_dt=False, n_threads=4, get_trace=False, get_probabilities=True, remote=True, **kwargs)[source]¶
Compute backward and forward trajectories from one phase-space grid.
- Return type: