{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Analysing traces\n", "\n", "Often the first step after running the simulation is to ensure that the simulation is converged.\n", "\n", "xemc3 can be used to do this." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import xemc3\n", "import glob\n", "\n", "# Matplotlib setup\n", "import setup_plt\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Use local helper function to get some data\n", "from get_data import load_example_data\n", "\n", "path = load_example_data(get_path=True)\n", "# If you want to use your own data use something like\n", "# path = \"path/to/mydata/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reading some files\n", "\n", "The fastest way is to load just a single iteration trace `*_INFO` file:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = xemc3.load.file(path + \"/ENERGY_INFO\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [], "source": [ "plt.figure()\n", "ds[\"Te_upstream\"].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However in most cases we are only interrested in the last points of the INFO file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "ds.Te_upstream[-50:].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reading all INFO files\n", "\n", "Besides using `xemc3.load.all(path)` it is also simple to read just the `*_INFO` files:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = xr.Dataset()\n", "for file in glob.iglob(f\"{path}/*_INFO\"):\n", " ds = xemc3.load.file(file, ds)\n", "ds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, the different traces can be plotted, to get an estimate of whether the simulation is converged:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "ds.dens_change[-60:].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Checking how much data\n", "\n", "As numpy arrays need to be blocks, xemc3 uses nan-padding. `np.isfinite` can be used to check how much data we have" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.isfinite(ds).sum()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" } }, "nbformat": 4, "nbformat_minor": 5 }