Compare profiles across calculations

All scripts below run against the example bundle. Unzip it, activate the environment where Postgkyl is installed, and run the commands from the extracted directory. The Python and CLI outputs below are both generated and compared when this website is built.

Compare density, parallel velocity, and two temperatures while retaining visibility into low-density tails. These are analytic synthetic profiles generated for plotting tests, not evidence of simulation convergence. The logarithmic side masks nonpositive values, including negative velocity.

Python script

python examples/scripts/mirror_comparison.py
import postgkyl as pg
from _example_paths import TEST_DATA, prepare_output_dir

DATA = TEST_DATA / "generated"
OUTPUT_DIR = prepare_output_dir()
figure_path = OUTPUT_DIR / "mirror_comparison.pdf"

high_alpha = pg.load(DATA /
                     "mirror_comparison_2em4_1d_ms_p1.gkyl").interpolate()
reference = pg.load(DATA / "mirror_comparison_2em5_1d_ms_p1.gkyl").interpolate()

fig = pg.plot(
    high_alpha,
    reference,
    figure=0,
    legend_labels=["2e-4", "2e-5"],
    no_legend=False,
    legend_subplot=0,
    legend_loc="best",
    title=r"Comparing $\alpha$ = 2e-4 to $\alpha$ = 2e-5",
    xlabel="z [m]",
    figsize="12,10",
    split_linear_log=True,
    split_point=0.0,
    split_log_side="right",
    split_width_ratios=(1.0, 1.0),
    split_gap=0.0,
    split_legend_side="log",
    split_log_nonpositive="mask",
    subplot_ylabels=(r"Density [$\mathrm{m}^{-3}$],"
                     r"$U_\parallel$ [m/s],"
                     r"$T_\parallel$ [keV],"
                     r"$T_\perp$ [keV]"),
    saveas=figure_path,
    no_show=True,
)
fig.savefig(OUTPUT_DIR / "mirror_comparison.png", dpi=150)

Equivalent CLI commands

Run from the extracted example bundle (or repository root). Create an output directory first:

mkdir -p output
pgkyl tests/test_data/generated/mirror_comparison_2em4_1d_ms_p1.gkyl \
    tests/test_data/generated/mirror_comparison_2em5_1d_ms_p1.gkyl interpolate plot \
    --figure 0 --legend_labels 2e-4 --legend_labels 2e-5 --legend_subplot 0 --legend_loc \
    best --title 'Comparing $\alpha$ = 2e-4 to $\alpha$ = 2e-5' --xlabel 'z [m]' --figsize \
    12 10 --split_linear_log --split_point 0 --split_log_side right --split_width_ratios 1 \
    1 --split_gap 0 --split_legend_side log --split_log_nonpositive mask --subplot_ylabels \
    'Density [$\mathrm{m}^{-3}$],$U_\parallel$ [m/s],$T_\parallel$ [keV],$T_\perp$ [keV]' \
    --no_show --dpi 150 --saveas output/mirror_comparison.png

mirror_comparison.png: Identical pixels (1 frame(s)) and timing.

Python and CLI outputs
Python output for mirror_comparison.png CLI output for mirror_comparison.png

Legend labels in the CLI and Python API

Pass a JSON array to --legend_labels, in dataset input order. Quote the entire array so the shell preserves the brackets and double quotes. For example, compare a new result with an older result in another directory:

pgkyl zzim-ion_BiMaxwellianMoments_65.gkyl \
  old-with-bug/zzim-ion_BiMaxwellianMoments_65.gkyl \
  interp pl -f0 --legend_labels '["new","old"]'

Spaces and commas within labels work naturally: --legend_labels '["new result","old, corrected"]'. Repeating the option also works: --legend_labels new --legend_labels old. Arrays and repeated options can be mixed; their entries are combined in order. --legend_labels "new,old" and --legend_labels "new","old" both supply one literal label containing a comma. Unquoted --legend_labels ["new","old"] is unreliable: shells strip the double quotes and may interpret the brackets as filename patterns. Use the outer single quotes shown above. To supply a literal label beginning with [, put it inside an array, for example --legend_labels '["[reference]"]'.

In Python, pass a list of strings:

import postgkyl as pg

new = pg.load("zzim-ion_BiMaxwellianMoments_65.gkyl").interpolate()
old = pg.load("old-with-bug/zzim-ion_BiMaxwellianMoments_65.gkyl").interpolate()
pg.plot(new, old, figure=0, legend_labels=["new", "old"])

Each explicit label is reused verbatim on every component subplot, without a component suffix. legend_subplot=0 (CLI: --legend_subplot 0) limits the legend to the first subplot; no_legend=True (CLI: --no_legend) hides it.

Without explicit legend labels, a figure with one dataset uses c0, c1, etc. A figure with multiple datasets uses <filename>_c0, <filename>_c1, etc., including for single-component data. Here, filename means the basename including its extension. Files with the same basename, as in this example, need explicit labels to distinguish them. In-memory datasets without a filename use their dataset label, or dataset 0, dataset 1, etc. if that is empty. If fewer legend labels than datasets are provided, the remaining datasets use these defaults. Subplot titles and axis labels do not change legend entries.