diff --git a/idstools/compute/core_sources.py b/idstools/compute/core_sources.py index 534900c6..cd194652 100644 --- a/idstools/compute/core_sources.py +++ b/idstools/compute/core_sources.py @@ -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" ] @@ -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 diff --git a/idstools/scripts/bin/plotcoresources b/idstools/scripts/bin/plotcoresources index c8f7a4b2..a4f9bbd0 100644 --- a/idstools/scripts/bin/plotcoresources +++ b/idstools/scripts/bin/plotcoresources @@ -5,6 +5,8 @@ import argparse import logging import os +import matplotlib + try: import imaspy as imas except ImportError: @@ -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) diff --git a/idstools/view/common.py b/idstools/view/common.py index e8ba5c3c..6b1fd801 100644 --- a/idstools/view/common.py +++ b/idstools/view/common.py @@ -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