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 0x7dfeb0348560>]
../_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 0x7dfeafb24380>]
../_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)
    Te_change              (iteration) float64 8kB nan nan nan ... 0.012 0.012
    Te_upstream            (iteration) float64 8kB nan nan nan ... 208.3 208.6
    Te_down_back           (iteration) float64 8kB nan nan nan ... 17.58 17.56
    Te_down_mean           (iteration) float64 8kB nan nan nan ... 16.55 16.53
    Te_down_fwd            (iteration) float64 8kB nan nan nan ... 13.65 13.64
    Ti_change              (iteration) float64 8kB nan nan nan ... 0.018 0.018
    ...                     ...
    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
Attributes:
    title:             EMC3-EIRENE Simulation data
    software_name:     xemc3
    software_version:  1.1.2.dev9+g1ef0093f4
    date_created:      2026-05-07T04:22:28.676494
    id:                5bc1960c-49cc-11f1-8efb-96ce9cbe9ff3
    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 0x7dfeafb76de0>]
../_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)
    Te_change              int64 8B 221
    Te_upstream            int64 8B 221
    Te_down_back           int64 8B 221
    Te_down_mean           int64 8B 221
    Te_down_fwd            int64 8B 221
    Ti_change              int64 8B 221
    ...                     ...
    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
Attributes:
    title:             EMC3-EIRENE Simulation data
    software_name:     xemc3
    software_version:  1.1.2.dev9+g1ef0093f4
    date_created:      2026-05-07T04:22:28.676494
    id:                5bc1960c-49cc-11f1-8efb-96ce9cbe9ff3
    references:        https://doi.org/10.5281/zenodo.5562265
[ ]: