Skip to content

Commit

Permalink
Allow use of noninteractive backend for dxtbx.plot_detector_models (c…
Browse files Browse the repository at this point in the history
…ctbx#664)

* Allow use of noninteractive backend for plot_detector_models. Add test

* Rename newsfragments/XXX.bugfix to newsfragments/664.bugfix

* Don't fail on warnings

---------

Co-authored-by: DiamondLightSource-build-server <[email protected]>
  • Loading branch information
1 parent 05b7806 commit 40327dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/664.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
16 changes: 16 additions & 0 deletions tests/command_line/test_plot_detector_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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")
subprocess.run(
[shutil.which("dxtbx.plot_detector_models"), expts, "pdf_file=plot_test.pdf"],
cwd=tmp_path,
capture_output=True,
)
assert os.path.exists(tmp_path / "plot_test.pdf")

0 comments on commit 40327dd

Please sign in to comment.