Package: jetto-tools
jetto-pythontoolsPython tools for plotting and manipulating JETTO runs.A word of cautionThese tools are a community collaboration under development, and probably always will be.
If you want to report a problem or ask for a feature, pleaseopen an issue at JETorgitlab.com,
so the responsible person can be identified and notified.  On gitlab.com please ping a developer since it
may not be actively monitored.PrerequisitesWe try to keep jetto-pythontools modular and easy-to-install. However, to
keep our sanity, we request at least a recent version of:python >= 3.7.0pip >= 20.0.0Different scripts might require different dependecies. Whenever a module is
missing, not provided by the default environment of the machine you are at,
and not installed by ourpip installprocess, please open an issue.Installation (user)Install thelatest relase from PyPi,
including the plotting GUIjpyplotsudo apt-get install python3-tk idle3  # On Ubuntu, tk is not always installed
sudo pip install jetto-tools[gui,tests]Or for a lightweight install without the plotting GUIpip install jetto-toolsInstallation (developer)An easy way to get up and running is to install from the git repository in developer mode.python--version# Make sure you have at least python3.7pip--version# Make sure you have at least version 20.0 of pip to read pyproject.toml filesgitclonegit@git.ccfe.ac.uk:jintrac/jetto-pythontools.git# Clone from JET repository if you have access# Or git clone https://gitlab.com/jintrac/jetto-pythontools.git # for the public versionpipinstall-ejetto-pythontools
python-c"import jetto_tools; print(jetto_tools.__version__)"# Check if you indeed installed the right version and can call it in pythonHowever, on Heimdall / Freia, editable mode does not always work, unless pip is updated.  For Freia testing of GUI changes, usemodule unload jintrac-pythontools
pip install --user --upgrade pip
cd jetto-pythontools
python -m pip install --user -e .
python -m pip install --user -e .[gui,tests]  #GUI needs to be installed explicitlyIn some cases, you might also need toexport PATH=$HOME/.local/bin:$PATH
export PYTHONPATH=$HOME/.local/lib/python3.7/site-packages:$PYTHONPATHto make your local install take precedence over the central installation.  (Note: in some versions of Python, local installs take precedence over the default installed version in PYTHONPATH (via importlib) -
but this is not the case with the importlib in Python version 3.7.1 on Heimdall - hence the need for explicit PYTHONPATH modification).You can then launch the scripts or gui of your local install directly from PATH e.g.jpyplot.Non-pip builds (e.g. pure setuptools)It is possible to build and install this package with other tool. In that case,
make sure your tools can readpyproject.tomlfiles, and be able to generate
a version number somehow. For setuptools, that means:setuptools >=40.8.0setuptools_scm[toml]>=3.4Developer notesDo not add JET or other tokamak data to this repository! This repository is synced to
an open gitlab repository ongitlab.comOpen Issues and MRs at JET if you have access, or on gitlab.com if you don't.  On gitlab.com please ping a developer since it
may not be actively monitored.We try to follow the Python Package Authority recommendations. A full guide to
install Python packages can be foundon their websiteIn some cases the editable install does not pickup changes (?), in which case prepending the working dir to PYTHONPATH can be a workaround - SeeEditable install requires python/3.7.9(not yet in Heimdall site packages so you would need a venv for this)If you are making more major changes, you may prefer to use a venv, following theexpert install procedureFeatures and ExamplesJETTO scan APITo progamatically generate JETTO runs from python, most useful for scans.SeeAPI docsdeployed on gitlab pagesJETTO plotting GUIThejpyplottool allows to load and plot runs from either the command line or a GUI.
If you launch it from a run directory it loads that case automatically.Particularly useful is to specify run dirs and plot variables from the CLI e.g.jpyplot --plotvars=TI,TE,NE run1 run1 runwild*Overview of jpyplot designalsohereSeethis commentto change default linestylesJETTO binary toolsThe binary tools (injetto_tools/binary.py) reads native JETTO outputs and can write JETTO inputs (exfiles)convert_binary_file(input_file,output_file):    Converts .ex,.ext,.jsp,.jst,.jse files into ASCII equivalent for easy readingread_binary_file(input_file):                   Reads .ex,.ext,.jsp,.jst,.jse files into memory (specific structure) for further processing in Pythonwrite_binary_exfile(data,output_file):          Writes data (specific structure) into binary file according to .ex formatmodify_entry(data,key,moddata):                 Modifies entry under key in data (specific structure), replacing it with moddata and updating trackingOne use is to read an existing ex-file into memory to
generate the specific structure needed, modifying it as required using
the function as it preserves some degree of providence, and writing it
back out as a binary for use in JETTO. The tracking is updated simply by
erasing all DDA/DTYPE/SEQ tags and replacing the DDA tag with the string
"Python modification tool" and setting seq=0.Units can be accessed from jetto_tools dictionary viadict['INFO'][<var>]['UNITS']Simple exampleto expose what the low level functions do (don't actually make plots like this, use the JETTO class - see below...!):from jetto_tools.binary import *
import matplotlib.pyplot as plt

jst = read_binary_file('jetto.jst')
time = jst['TVEC1'][0,:] # First index is rho-index,
                         # but since this is a time trace,
                         # dimension is singular
Teax = jst['TEAX'][0,:]

plt.figure()
plt.plot(time,Teax,label='Simulation')
plt.legend()
plt.xlabel('Time [s]')
plt.ylabel('Te,core [eV]')
plt.show()JETTO classThe JETTO class reads all data into a structure which drives the results_gui (jpyplot).For more information:Overview of class designhereTry using the docstrings...Try browsing or searching the gitlabissuesand merge requests.Example(cut down fromhere) - untested...from pathlib import Path

import numpy as np
import xarray as xr
import matplotlib.pyplot as plt

from jetto_tools.classes import JETTO, ODS
from jetto_tools.results_gui import run_list_to_runs, slice_plotter

from IPython import embed

# Read runs
run_list = ['run1','run2']
runs = run_list_to_runs(run_list)

# For convenience, extract a JINTRAC run
jrun = runs[list(runs.keys())[0]]
jsp = jrun['JSP']

# Set plot variables
yvar = 'TE'
file = 'JSP'
# Find the max time in all JSPs
max_time = np.max([run[file]['time'].max() for run in runs.values()])
time = max_time

# Use GUI scripts to make a plot
fig, axes = plt.subplots(3)
ax0, ax1, ax2 = axes
xvar = 'XRHO'
for ax, yvar in zip(axes, ['TE', 'TI', 'NE']):
    slice_plotter(ax, None, runs, file, xvar, yvar, zslice=('time', time), verbosity=1)

ax0.legend([Path(k).name for k in runs.keys()])
plt.show()Adding DocumentationSome external user docs are maintained on the JINTRAC pages (WIP: merging here):https://users.euro-fusion.org/pages/data-cmg/wiki/JETTO_python_tool.htmlDeveloper API docs are deployed on gitlab pages via gitlab CI:https://jintrac.gitlab.io/jetto-pythontools/The API documentation is written using reStructuredText and Sphinx. In order to build the
documentation, run the commands:$ cd docs/
$ make htmlThey can then be viewed in the browser of your choice e.g.$ firefox docs/_build/html/index.htmlThe packages required to build the documentation are listed inrequirements_docs.txt.
If this pakage was installed viapip, as above, then the prerequisites should have
been installed automatically.