Skip to content

Commit

Permalink
fix: add matplotlib as optional dependency for skymaps plots
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Oct 15, 2024
1 parent b03c5ab commit cd08ca8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* `nested.healpix_to_lonlat`, failed into rust panic for `dx=1` or `dy=1`. This is
now indicated in the documentation and is catched in a `ValueError` on the python side.

### Changed

* `matplotlib` is now an optional dependency, to plot previews of skymaps.

## 0.6.5

Released 2023-11-28
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ description = "A healpix manipulation library."
readme = "README.md"
keywords = ["astronomy", "healpix"]

[project.optional-dependencies]
plot = ["matplotlib"]

[project.urls]
repository = "https://github.com/cds-astro/cds-healpix-python"
documentation = "https://cds-astro.github.io/cds-healpix-python/"
Expand Down
11 changes: 10 additions & 1 deletion python/cdshealpix/skymap/skymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from pathlib import Path
from typing import Union

import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ImportError:
_matplotlib_missing = True
import numpy as np


Expand Down Expand Up @@ -140,6 +143,12 @@ def quick_plot(self, *, size=256, convert_to_gal=True, path=None):
If different from none, the image will not only be displayed, but also saved
at the given location. By default None
"""
if _matplotlib_missing:
raise ModuleNotFoundError(
"matplotlib is mandatory to use 'quick_plot'. "
"See https://matplotlib.org/ for installation "
"instructions."
)
img = cdshealpix.pixels_skymap(self.values, size, convert_to_gal)
fig = plt.imshow(img)
plt.axis("off")
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
astropy<5.3; python_version == '3.8'
astropy; python_version > '3.8'
astropy_healpix
matplotlib
pre-commit==2.21.*
pytest
astropy_healpix

0 comments on commit cd08ca8

Please sign in to comment.