Loading of data

The most convinient way of working with EMC3 data is from netcdf files. This way all metadata and all available fields are known, and are loaded into memory as needed.

Netcdf files are also beneficial for sharing simulation results, as they contain metadata and are thus easy to use. While xemc3 only exists for python, netcdf library implementation are present in most languages, so you can easily do your analysis in your preferred language.

[1]:
import xemc3

import xarray as xr
import numpy as np

# Matplotlib setup
import setup_plt
[2]:
%%time

ds = xr.open_dataset("../../example-data/emc3_example.nc")
CPU times: user 38.2 ms, sys: 10 ms, total: 48.2 ms
Wall time: 51.2 ms

Checking the present data

xarray is nicely integrated in jupyter notebook and many IDEs, so it is easy to check what quantities are included as well as units and so on.

Note that for this view the data does not need to recide in memory, which is especially beneficial for high-resolution grids or large parameter scans.

[3]:
ds
[3]:
<xarray.Dataset> Size: 2GB
Dimensions:                       (r: 139, theta: 512, phi: 36, delta_r: 2,
                                   delta_theta: 2, delta_phi: 2,
                                   iteration: 1000, plate_ind: 22,
                                   plate_phi_plus1: 57, r_plus1: 140,
                                   theta_plus1: 513, phi_plus1: 37,
                                   plate_phi: 560, plate_x: 100,
                                   plate_x_plus1: 50, delta_plate_phi: 2,
                                   delta_plate_x: 2)
Coordinates:
    R_bounds                      (r, theta, phi, delta_r, delta_theta, delta_phi) float64 164MB ...
    z_bounds                      (r, theta, phi, delta_r, delta_theta, delta_phi) float64 164MB ...
    phi_bounds                    (phi, delta_phi) float64 576B ...
  * iteration                     (iteration) int64 8kB -999 -998 -997 ... -1 0
    plate_phi                     (plate_ind, plate_phi_plus1) float64 10kB ...
    plate_z                       (plate_ind, plate_phi_plus1, plate_x_plus1) float64 502kB ...
    plate_R                       (plate_ind, plate_phi_plus1, plate_x_plus1) float64 502kB ...
    plate_z_bounds                (plate_ind, plate_phi, plate_x, delta_plate_phi, delta_plate_x) float64 39MB ...
    plate_phi_bounds              (plate_ind, plate_phi, plate_x, delta_plate_phi, delta_plate_x) float64 39MB ...
    plate_R_bounds                (plate_ind, plate_phi, plate_x, delta_plate_phi, delta_plate_x) float64 39MB ...
Dimensions without coordinates: r, theta, phi, delta_r, delta_theta, delta_phi,
                                plate_ind, plate_phi_plus1, r_plus1,
                                theta_plus1, phi_plus1, plate_x, plate_x_plus1,
                                delta_plate_phi, delta_plate_x
Data variables: (12/93)
    _plasma_map                   (r, theta, phi) int64 20MB ...
    ne                            (r, theta, phi) float64 20MB ...
    nZ1                           (r, theta, phi) float64 20MB ...
    nZ2                           (r, theta, phi) float64 20MB ...
    nZ3                           (r, theta, phi) float64 20MB ...
    nZ4                           (r, theta, phi) float64 20MB ...
    ...                            ...
    f_E                           (plate_ind, plate_phi, plate_x) float64 10MB ...
    avg_n                         (plate_ind, plate_phi, plate_x) float64 10MB ...
    avg_Te                        (plate_ind, plate_phi, plate_x) float64 10MB ...
    avg_Ti                        (plate_ind, plate_phi, plate_x) float64 10MB ...
    tot_n                         (plate_ind) float64 176B ...
    tot_P                         (plate_ind) float64 176B ...
Attributes:
    title:             EMC3-EIRENE Simulation data
    software_name:     xemc3
    software_version:  0.2.2.dev5+g7311151
    date_created:      2022-10-27T13:16:46.836400
    id:                9bda9808-55f9-11ed-9228-00001029fe80
    references:        https://doi.org/10.5281/zenodo.5562265

Quantities can be accessed either by the [] operator like ["nZ3"] or by .nZ3. Note that assigning new quantities is only possible with the [] notation.

[4]:
ds.nZ3
[4]:
<xarray.DataArray 'nZ3' (r: 139, theta: 512, phi: 36)> Size: 20MB
[2562048 values with dtype=float64]
Dimensions without coordinates: r, theta, phi
Attributes:
    print_before:             4\n
    xemc3_type:    mapped
    units:         m$^{-3}$
[5]:
ds.nZ3.isel(r=-2).plot()
[5]:
<matplotlib.collections.QuadMesh at 0x7ac960b47620>
../_images/examples_load2_7_1.png
[6]:
ds.emc3.plot_rz("nZ3", phi=np.pi / 5)
[6]:
<matplotlib.collections.QuadMesh at 0x7ac960bf3d10>
../_images/examples_load2_8_1.png