Skip to content

Commit

Permalink
chore(combine): warn about vector formats and test against jpg
Browse files Browse the repository at this point in the history
  • Loading branch information
engeir committed Apr 29, 2024
1 parent 89610a7 commit 128bd85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cosmoplots/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# `Self` was introduced in 3.11, but returning the class type works from 3.7 onwards.
from __future__ import annotations
import warnings

import pathlib
import subprocess
Expand Down Expand Up @@ -155,6 +156,12 @@ def _check_params_before_save(
if output.name.endswith(self._ft)
else output.with_suffix(self._ft)
)
if self._ft in [".eps", ".pdf"]:
warnings.warn(
"The ImageMagick `convert` command does not work well with vector"
" formats. Consider combining the plots directly using matplotlib,"
" or change to a different format, such as 'png' or 'jpg'.",
)
if not self._output.parents[0].exists():
raise FileNotFoundError(
f"The file path {self._output.parents[0]} does not exist."
Expand Down
20 changes: 10 additions & 10 deletions tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,26 @@ def test_combine_ft(tmp_path: pathlib.Path) -> None:

def _combine() -> None:
plot()
plt.savefig(tmp_path / "test1.eps")
plt.savefig(tmp_path / "test1.jpg")
plot()
plt.savefig(tmp_path / "test2.eps")
plt.savefig(tmp_path / "test2.jpg")
plot()
plt.savefig(tmp_path / "test3.eps")
plt.savefig(tmp_path / "test3.jpg")
plot()
plt.savefig(tmp_path / "test4.eps")
plt.savefig(tmp_path / "test4.jpg")
cosmoplots.combine(
tmp_path / "test1.eps",
tmp_path / "test2.eps",
tmp_path / "test3.eps",
tmp_path / "test4.eps",
).in_grid(w=2, h=2).save(tmp_path / "out.eps")
tmp_path / "test1.jpg",
tmp_path / "test2.jpg",
tmp_path / "test3.jpg",
tmp_path / "test4.jpg",
).in_grid(w=2, h=2).save(tmp_path / "out.jpg")

if platform == "win32":
with pytest.raises(ChildProcessError):
_combine()
else:
_combine()
first_img = tmp_path / "out.eps"
first_img = tmp_path / "out.jpg"
assert first_img.exists()

def test_in_grid_not_specified(tmp_path: pathlib.Path) -> None:
Expand Down

0 comments on commit 128bd85

Please sign in to comment.