Skip to content

Commit

Permalink
add scripts/plot_look_all
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 24, 2023
1 parent b2b6c67 commit 2944ccb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scripts/plot_all_subdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def main(top: Path, resume: bool) -> None:
"""

dirs = (d for d in top.iterdir() if d.is_dir())
N = os.cpu_count()

N = os.cpu_count()
if N is None:
N = 2
else:
Expand All @@ -56,7 +56,10 @@ def main(top: Path, resume: bool) -> None:
p = argparse.ArgumentParser()
p.add_argument("top_dir", help="Top level directory to look one level below")
p.add_argument(
"-r", "--resume", help="skip directories that already have plots", action="store_true"
"-r",
"--resume",
help="skip directories that already have plots",
action="store_true",
)
P = p.parse_args()

Expand Down
64 changes: 64 additions & 0 deletions scripts/plot_look_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""
Look at specific pairs of plots between a reference directory and a "new" directory.
All subdirectories one level below the specified directory.
This is useful if making a change in PyGemini or Gemini3D, to plot many simulations
to visually check for something unexpected.
"""

from pathlib import Path
import argparse
from matplotlib.pyplot import figure, draw, pause
from matplotlib.image import imread
from datetime import datetime


var = {"ne", "Te", "Ti", "J1", "J2", "J3", "v1", "v2", "v3"}
fs = 8

p = argparse.ArgumentParser(
description="Look at specific pairs of plots between a reference directory and a new directory."
)
p.add_argument("ref_dir", help="Reference: top level directory to look one level below")
p.add_argument("new_dir", help="New: top level directory to look one level below")
P = p.parse_args()

ref_dir = Path(P.ref_dir).expanduser().resolve()
new_dir = Path(P.new_dir).expanduser().resolve()

if not ref_dir.is_dir():
raise NotADirectoryError(ref_dir)
if not new_dir.is_dir():
raise NotADirectoryError(new_dir)
if ref_dir.samefile(new_dir):
raise ValueError("ref_dir and new_dir must be different")


new_sims = (d for d in new_dir.iterdir() if d.is_dir())
ref_sims = (d for d in ref_dir.iterdir() if d.is_dir())

fg = figure()
axs = fg.subplots(2, 1, sharex=True, sharey=True)

for new_sim in new_sims:
new_name = new_sim.name
if not (ref_dir / new_name).is_dir():
raise NotADirectoryError(ref_dir / new_name)

for v in var:
plot_name = sorted((new_sim / "plots").glob(f"{v}-*.png"))[-1].name
ref_file = ref_dir / new_name / "plots" / plot_name
new_file = new_sim / "plots" / plot_name

if not ref_file.is_file():
raise FileNotFoundError(ref_file)

axs[0].imshow(imread(ref_file))
axs[0].set_title(ref_file, fontsize=fs)
axs[0].set_xlabel(datetime.utcfromtimestamp(ref_file.stat().st_ctime))

axs[1].imshow(imread(new_file))
axs[1].set_title(new_file, fontsize=fs)
axs[1].set_xlabel(datetime.utcfromtimestamp(new_file.stat().st_ctime))
draw()
pause(0.1)

0 comments on commit 2944ccb

Please sign in to comment.