Skip to content

Commit

Permalink
Allow use of noninteractive backend for plot_detector_models. Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Nov 3, 2023
1 parent 4ad0ce5 commit 74dee5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/XXX.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``dxtbx.plot_detector_models``: use noninteractive matpotlib backend if using the pdf_file option
7 changes: 6 additions & 1 deletion src/dxtbx/command_line/plot_detector_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
from collections.abc import Sequence

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.patches import FancyArrowPatch
Expand Down Expand Up @@ -170,6 +169,12 @@ def run(args=None):
except Exception:
raise Sorry("Unrecognized argument %s" % arg)
params = phil_scope.fetch(sources=user_phil).extract()
if params.pdf_file:
import matplotlib

matplotlib.use("Agg")

import matplotlib.pyplot as plt

fig = plt.figure()
colormap = plt.cm.gist_ncar
Expand Down
17 changes: 17 additions & 0 deletions tests/command_line/test_plot_detector_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

import os.path
import shutil
import subprocess


def test_plot_models_noninteractive_to_pdf(dials_data, tmp_path):
ssx = dials_data("cunir_serial_processed", pathlib=True)
expts = str(ssx / "imported_no_ref_5.expt")
result = subprocess.run(
[shutil.which("dxtbx.plot_detector_models"), expts, "pdf_file=plot_test.pdf"],
cwd=tmp_path,
capture_output=True,
)
assert not result.returncode and not result.stderr
assert os.path.exists(tmp_path / "plot_test.pdf")

0 comments on commit 74dee5f

Please sign in to comment.