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
3 changes: 1 addition & 2 deletions idstools/compute/core_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ def get_single_and_total_electrons_ions_waveforms(self, time_slice):
single_power_waveform = {}
single_particles_waveform = {}
dict_single_and_total_electrons_waveforms = self.get_single_and_total_electrons_waveforms(time_slice)
total_electron_power_waveform = dict_single_and_total_electrons_waveforms["total_electron_power_waveform"]
total_electron_particles_waveform = dict_single_and_total_electrons_waveforms[
"total_electron_particles_waveform"
]
Expand Down Expand Up @@ -399,7 +398,7 @@ def get_single_and_total_electrons_ions_waveforms(self, time_slice):
total_ion_power = 0.0

total_power_waveform[time_index] = (
total_electron_power_waveform[time_index] + electrons_power + total_ion_power
total_power_waveform[time_index] + electrons_power + total_ion_power
)
total_particles_waveform[time_index] = (
total_electron_particles_waveform[time_index] + electrons_particles
Expand Down
4 changes: 4 additions & 0 deletions idstools/scripts/bin/plotcoresources
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import argparse
import logging
import os

import matplotlib

try:
import imaspy as imas
except ImportError:
Expand Down Expand Up @@ -72,9 +74,11 @@ if __name__ == "__main__":
time_slice, time_value = get_nearest_time(time_array, args.time)
ntime = len(time_array)
nsources = len(core_sources.source)
logger.info(f"ntime={ntime}, nsources={nsources}, backend={matplotlib.get_backend()}")

core_source_view = CoreSourcesView(core_sources)

logger.info("Creating plot canvas")
canvas = PlotCanvas(2, 4)
canvas.update_style(args.rc)
ret = ax_power_profiles = canvas.add_axes(title=r"Power Profiles [MW/M3]", row=0, col=0)
Expand Down
23 changes: 12 additions & 11 deletions idstools/view/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ def _is_jupyter() -> bool:
return False


# Select the appropriate matplotlib backend
if _is_jupyter():
if "matplotlib.pyplot" not in sys.modules:
# Select the appropriate matplotlib backend.
# Honour an explicit MPLBACKEND env var set by CI/scripts — never override it.
if not os.environ.get("MPLBACKEND") and "matplotlib.pyplot" not in sys.modules:
if _is_jupyter():
try:
import ipympl # noqa: F401 - imported to check availability

matplotlib.use("widget")
except ImportError:
matplotlib.use("agg")
elif sys.platform.startswith("win") or "DISPLAY" in os.environ:

try:
import tkinter # noqa: F401 - imported to check availability
elif sys.platform.startswith("win") or "DISPLAY" in os.environ:
try:
import tkinter # noqa: F401 - imported to check availability

matplotlib.use("TkAgg")
except (ImportError, ModuleNotFoundError):
matplotlib.use("TkAgg")
except Exception:
# ImportError, ModuleNotFoundError, TclError, or SIGILL-prone libs
matplotlib.use("agg")
else:
matplotlib.use("agg")
else:
matplotlib.use("agg")

import matplotlib.pyplot as plt # noqa: E402

Expand Down
Loading