Analysing traces

Often the first step after running the simulation is to ensure that the simulation is converged.

xemc3 can be used to do this.

[1]:
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import xemc3
import glob

# Matplotlib setup
import setup_plt

%matplotlib inline
[2]:
# Use local helper function to get some data
from get_data import load_example_data

path = load_example_data(get_path=True)
# If you want to use your own data use something like
# path = "path/to/mydata/"

Reading some files

The fastest way is to load just a single iteration trace *_INFO file:

[3]:
ds = xemc3.load.file(path + "/ENERGY_INFO")
[4]:
plt.figure()
ds["Te_upstream"].plot()
[4]:
[<matplotlib.lines.Line2D at 0x7ce8a1015520>]
../_images/examples_info_5_1.png

However in most cases we are only interrested in the last points of the INFO file.

[5]:
plt.figure()
ds.Te_upstream[-50:].plot()
[5]:
[<matplotlib.lines.Line2D at 0x7ce89ffdcd70>]
../_images/examples_info_7_1.png

Reading all INFO files

Besides using xemc3.load.all(path) it is also simple to read just the *_INFO files:

[6]:
ds = xr.Dataset()
for file in glob.iglob(f"{path}/*_INFO"):
    ds = xemc3.load.file(file, ds)
ds
[6]:
<xarray.Dataset> Size: 232kB
Dimensions:                (iteration: 1000)
Coordinates:
  * iteration              (iteration) int64 8kB -999 -998 -997 -996 ... -2 -1 0
Data variables: (12/28)
    ionization_core        (iteration) float64 8kB nan nan ... 0.02528 0.02525
    ionization_edge        (iteration) float64 8kB nan nan nan ... 0.9747 0.9748
    ionization_electron    (iteration) float64 8kB nan nan nan ... -26.6 -26.6
    ionization_ion         (iteration) float64 8kB nan nan nan ... 7.404 7.399
    ionization_moment_fwd  (iteration) float64 8kB nan nan ... -6.671e-19
    ionization_moment_bwk  (iteration) float64 8kB nan nan ... 1.152e-18
    ...                     ...
    Ti_down_back           (iteration) float64 8kB nan nan nan ... 22.63 22.61
    Ti_down_mean           (iteration) float64 8kB nan nan nan ... 23.65 23.63
    Ti_down_fwd            (iteration) float64 8kB nan nan nan ... 26.55 26.52
    P_loss_gas             (iteration) float64 8kB nan nan ... 2.251e+04
    P_loss_imp             (iteration) float64 8kB nan nan ... 5.001e+04
    P_loss_target          (iteration) float64 8kB nan nan ... 1.618e+05
Attributes:
    title:             EMC3-EIRENE Simulation data
    software_name:     xemc3
    software_version:  1.0.1.dev35+gd8f5732cb
    date_created:      2026-04-29T08:20:47.600636
    id:                534641a4-43a4-11f1-aba2-4e480b78071a
    references:        https://doi.org/10.5281/zenodo.5562265

Again, the different traces can be plotted, to get an estimate of whether the simulation is converged:

[7]:
plt.figure()
ds.dens_change[-60:].plot()
[7]:
[<matplotlib.lines.Line2D at 0x7ce89d73c0b0>]
../_images/examples_info_11_1.png

Checking how much data

As numpy arrays need to be blocks, xemc3 uses nan-padding. np.isfinite can be used to check how much data we have

[8]:
np.isfinite(ds).sum()
[8]:
<xarray.Dataset> Size: 224B
Dimensions:                ()
Data variables: (12/28)
    ionization_core        int64 8B 206
    ionization_edge        int64 8B 206
    ionization_electron    int64 8B 206
    ionization_ion         int64 8B 206
    ionization_moment_fwd  int64 8B 206
    ionization_moment_bwk  int64 8B 206
    ...                     ...
    Ti_down_back           int64 8B 221
    Ti_down_mean           int64 8B 221
    Ti_down_fwd            int64 8B 221
    P_loss_gas             int64 8B 221
    P_loss_imp             int64 8B 221
    P_loss_target          int64 8B 221
Attributes:
    title:             EMC3-EIRENE Simulation data
    software_name:     xemc3
    software_version:  1.0.1.dev35+gd8f5732cb
    date_created:      2026-04-29T08:20:47.600636
    id:                534641a4-43a4-11f1-aba2-4e480b78071a
    references:        https://doi.org/10.5281/zenodo.5562265
[ ]: