Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/source/jupyter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#######################
Jupyter notebook usage
#######################

IDStools command-line tools can also be used directly from Jupyter notebooks.
Import ``idstools`` once in the notebook kernel to register the IDStools
commands as IPython line magics:

.. code-block:: python

import idstools

After that, commands such as ``idsprint`` and ``plotequilibrium`` can be
called with ``%``:

.. code-block:: python

%idsprint -u "imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#core_profiles/profiles_1d[0]/electrons/temperature" -p

.. code-block:: python

%plotequilibrium -u "imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/100507/5"


******************************
Interactive Matplotlib plots
******************************

For interactive Matplotlib figures in Jupyter, use the ``ipympl`` backend. If
``ipympl`` is installed in the same Python environment as IDStools, the backend
can be selected with Matplotlib's notebook magic before plotting:

.. code-block:: python

%matplotlib widget
import idstools

%idsprint -u "imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#core_profiles/profiles_1d[0]/electrons/temperature" -p

Alternatively, the backend can be selected through the IDStools ``--rc``
option before Matplotlib has been imported in the current kernel:

.. code-block:: python

import idstools

%idsprint -u "imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#core_profiles/profiles_1d[0]/electrons/temperature" -p --rc "backend='module://ipympl.backend_nbagg'"

.. code-block:: python

%plotequilibrium -u "imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/100507/5" --rc "backend='module://ipympl.backend_nbagg'"
1 change: 1 addition & 0 deletions docs/source/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Following are the different command line tools available in the
ids_manipulation_tools
database_tools
scenariodb_tools
jupyter
2 changes: 1 addition & 1 deletion idstools/compute/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def get_profiles_1d_quantities(self, time_slice, attributes=None):
if ids_field.has_value:
quantities[attribute] = eval(f"self.ids.time_slice[{time_slice}].profiles_1d.{attribute}")
else:
logger.error(f"self.ids.time_slice[{time_slice}].profiles_1d.{attribute} not found")
logger.warning(f"self.ids.time_slice[{time_slice}].profiles_1d.{attribute} not found")
return quantities

def get_global_quantities(self, time_slice=None, attributes=None):
Expand Down
20 changes: 18 additions & 2 deletions idstools/scripts/bin/dblist
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,15 @@ def print_times(dbs, args, print_times=False, pulse_number=None, run_number=None
print(TAB * 4 + " Run: " + extended(str(run), RUN_STR_LEN))
available_ids_and_times = get_available_ids_and_times(connection)
for idsname, times in available_ids_and_times:
if len(times) == 1 and np.isnan(times[0]):
if times is None:
print(
TAB * 5
+ extended(idsname, IDSNAME_STR_LEN)
+ ": "
+ extended("N/A", SLICENUM_STR_LEN)
+ " slices ( time unavailable )"
)
elif len(times) == 1 and np.isnan(times[0]):
print(
TAB * 5
+ extended(idsname, IDSNAME_STR_LEN)
Expand Down Expand Up @@ -311,7 +319,15 @@ def print_times_with_folder(dbs, print_times=False, pulse_number=None, run_numbe
continue
available_ids_and_times = get_available_ids_and_times(connection)
for idsname, times in available_ids_and_times:
if times is not None:
if times is None:
print(
TAB * 15
+ extended(idsname, IDSNAME_STR_LEN)
+ ": "
+ extended("N/A", SLICENUM_STR_LEN)
+ " slices ( time unavailable )"
)
else:
if len(times) == 1 and np.isnan(times[0]):
print(
TAB * 15
Expand Down
10 changes: 5 additions & 5 deletions idstools/scripts/bin/idsdiff
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sys
import time
from io import BytesIO

from idstools.view.common import PlotCanvas
import matplotlib.pyplot as plt
import numpy as np
import rich
Expand Down Expand Up @@ -43,8 +44,6 @@ slicing_methods = {


def view_plot(ax, field, coordinate, field_name="", coordinate_name="", field_unit="", coordinate_unit="", **kwargs):
from idstools.view.common import PlotCanvas

if not isinstance(field, (imas.ids_primitive.IDSNumericArray, np.ndarray)):
print("Not a numeric array, Please select ids path")
return
Expand Down Expand Up @@ -506,7 +505,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down Expand Up @@ -702,8 +704,6 @@ if __name__ == "__main__":
] = compare_data

if args.plot and not args.html:
from idstools.view.common import PlotCanvas

canvas = PlotCanvas(1, 1)
canvas.update_style(args.rc)
ax = canvas.add_axes(title="", xlabel="", row=0, col=0)
Expand Down
4 changes: 2 additions & 2 deletions idstools/scripts/bin/idslist
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ if __name__ == "__main__":
type = time_array
elif time_array is None:
value = f"{not_applicable}"
type = "unknown"
table.add_row(ids_name, value, Pretty(type))
type = not_applicable
table.add_row(ids_name, value, type if isinstance(type, str) else Pretty(type))
if args.fullarray is True:
with np.printoptions(threshold=sys.maxsize, linewidth=1024, precision=4):
console.print(table)
Expand Down
10 changes: 8 additions & 2 deletions idstools/scripts/bin/idsprint
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down Expand Up @@ -559,7 +562,10 @@ if __name__ == "__main__":
table.add_column("SLICES", style="green")
table.add_column("TIME", style="green")
for ids_name, time_array in available_ids_and_times:
if len(time_array) == 1 and np.isnan(time_array[0]):
if time_array is None:
value = "N/A"
type = "unknown"
elif len(time_array) == 1 and np.isnan(time_array[0]):
value = f"{question_string}"
type = "heterogeneous IDS"
elif len(time_array) == 1 and time_array[0] == -np.inf:
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotcoresources
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ if __name__ == "__main__":
parser.add_argument("-t", "--time", help="time", required=False, type=float, default=-99.0)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotcoretransport
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/ploteccomposition
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotecray
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ if __name__ == "__main__":

parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotecstrayradiation
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotedgeprofiles
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
9 changes: 7 additions & 2 deletions idstools/scripts/bin/plotequicomp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ try:
except ImportError:
import imas
import numpy as np

# PlotCanvas configures a --rc backend before Matplotlib is imported.
from idstools.view.common import PROVENANCE_TITLE_STYLE, PlotCanvas
from matplotlib.animation import FuncAnimation
from matplotlib.widgets import Slider
from rich_argparse import RichHelpFormatter
Expand All @@ -20,7 +23,6 @@ from idstools.utils.clihelper import (
rcparam_parser,
)
from idstools.utils.idslogger import setup_logger
from idstools.view.common import PROVENANCE_TITLE_STYLE, PlotCanvas
from idstools.view.equilibrium import EquilibriumView
from idstools.view.wall import WallView

Expand Down Expand Up @@ -58,7 +60,10 @@ if __name__ == "__main__":

parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
8 changes: 6 additions & 2 deletions idstools/scripts/bin/plotequilibrium
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ try:
import imaspy as imas
except ImportError:
import imas
# PlotCanvas configures a --rc backend before mpl_toolkits imports Matplotlib.
from idstools.view.common import PlotCanvas
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from rich_argparse import RichHelpFormatter

Expand All @@ -27,7 +29,6 @@ from idstools.utils.clihelper import (
rcparam_parser,
)
from idstools.utils.idslogger import setup_logger
from idstools.view.common import PlotCanvas
from idstools.view.domain.mdplot import plot_machine_description
from idstools.view.equilibrium import EquilibriumView

Expand Down Expand Up @@ -86,7 +87,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plothcd
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plothcddistributions
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ if __name__ == "__main__":

parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plothcdwaves
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ if __name__ == "__main__":
parser.add_argument("-l", "--hide_legend", help="remove the legend from graphs", action="store_true")
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotkineticprofiles
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotmachinedescription
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ if __name__ == "__main__":
)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotneutron
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ if __name__ == "__main__":
parser.add_argument("-t", "--time", help="Time", required=False, type=float, default=-99.0)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotpressure
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ if __name__ == "__main__":
parser.add_argument("-t", "--time", type=float, help="Time", default=-99)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/plotrotation
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ if __name__ == "__main__":
parser.add_argument("-t", "--time", help="Time", required=False, type=float, default=99.0)
parser.add_argument(
"--save",
help="Save figure at default location",
help=(
"Save the plot to a file instead of opening a window. "
"If no plot window is available, it is saved automatically."
),
action="store_true",
)
parser.add_argument(
Expand Down
Loading