Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: adds a Skymap submodule #29

Merged
merged 13 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
#os: [windows-latest, macOS-latest, ubuntu-latest]
#python-version: [3.8, 3.9, 3.10]
os: [ubuntu-latest]
python-version: [3.8]
python-version: [3.12]
steps:
- name: "Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}"
uses: actions/setup-python@v4
Expand Down
27 changes: 7 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ jobs:
maturin build --release --compatibility manylinux2014
maturin develop --release
pip install -r requirements-dev.txt
python -m pytest python/cdshealpix/tests/test_nested_healpix.py
python -m pytest python/cdshealpix/tests/test_ring_healpix.py
python -m pytest -v
deactivate
rm -r cdshealpixenv
done
Expand Down Expand Up @@ -96,10 +95,8 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
# Checkout the project
- name: "Checkout branch ${{ github.head_ref }}"
- name: "Checkout branch"
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
# Test Rust code
#- name: Run rust wrapper tests
# run: cargo test --verbose -- --nocapture
Expand All @@ -125,10 +122,7 @@ jobs:
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
cd python
python -m pytest -v -s cdshealpix/tests/test_nested_healpix.py
python -m pytest -v -s cdshealpix/tests/test_ring_healpix.py
cd ..
python -m pytest -v
# Clean
#pip freeze > requirements-uninstall.txt
#pip uninstall -r requirements-uninstall.txt -y
Expand All @@ -142,10 +136,8 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
# Checkout the project
- name: "Checkout branch ${{ github.head_ref }}"
- name: "Checkout branch"
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
# Test Rust code
#- name: Run rust wrapper tests
# run: cargo test --verbose -- --nocapture
Expand All @@ -170,20 +162,15 @@ jobs:
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
cd python
python -m pytest -v "cdshealpix\tests\test_nested_healpix.py"
python -m pytest -v "cdshealpix\tests\test_ring_healpix.py"
cd ..
python -m pytest -v
deactivate

# Build the doc and run the tests in the doc (only for python 3.9 on ubuntu)
# Build the doc and run the tests in the doc (only for python 3.11 on ubuntu)
test-doc:
runs-on: ubuntu-latest
steps:
- name: "Checkout branch ${{ github.head_ref }}"
- name: "Checkout branch"
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: "Set up Python 3.11 on Ubuntu"
uses: actions/setup-python@v4
with:
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ repos:
rev: 'v1.10.0'
hooks:
- id: python-no-eval
- id: rst-backticks
# For python files
- repo: https://github.com/psf/black
# Code style
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* new features `box_search` and `zone_search` in `cdshealpix.nested`
* `cdshaelpix.nested.vertices` can now take depth as a `numpy.ndarray` instead of only
accepting a single depth
* new module `skymap` added.
* read/write, and plot nested all-sky skymaps in the implicit scheme from fits files with
`Skymap.from_fits`, `Skymap.from_array`, `Skymap.quick_plot`, and `Skymap.to_fits`

### Fixed

Expand All @@ -18,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
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ name = "cdshealpix"
crate-type = ["cdylib"]

[dependencies]
healpix = { package = "cdshealpix", version = "0.6" }
healpix = { rev="5ab172b4d1d206c973f9f170b14509f4982e0090", package = "cdshealpix", git = 'https://github.com/cds-astro/cds-healpix-rust' }
mapproj = "0.3.0"
rayon = "1.10"

[dependencies.numpy]
version = "0.20"
version = "0.22"

[dependencies.pyo3]
version = "0.20"
version = "0.22"
features = ["extension-module"]

[dependencies.ndarray]
version = "0.15"
version = "0.16"
default-features = false # do not include the default features, and optionally
# cherry-pick individual features
features = ["rayon"]
Expand Down
10 changes: 10 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ While in the nested scheme, ``nside`` is a power of two
vertices
vertices_skycoord

cdshealpix.skymap
~~~~~~~~~~~~~~~~~

This module provides a minimal interface to interact with Skymaps, as defined in the
`data format for gamma ray astronomy specification
<https://gamma-astro-data-formats.readthedocs.io/en/latest/skymaps/healpix/index.html#skymap-hdu>`_.

.. autoclass:: cdshealpix.skymap.Skymap
:members:

.. _cdshealpix: https://github.com/cds-astro/cds-healpix-python
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
]
default_role = "py:obj"
numpydoc_class_members_toctree = False
numpydoc_show_class_members = False
autosummary_generate = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
bibtex_bibfiles = ["references.bib"]
Expand Down
14 changes: 13 additions & 1 deletion docs/examples/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,23 @@ Zone search
-----------

In this example, we get the ``ipix`` and ``depth`` in a zone and plot them by combining
:external:ref:`~cdshealpix.nested.vertices`_ with :external:ref:`~matplotlib.path.Polygon`_
`cdshealpix.nested.vertices` with `matplotlib.path.Polygon`

.. plot:: examples/search_methods/zone_search.py
:include-source:

Skymaps
=======

The skymap sub-module allows to manipulate easily all-sky skymaps in the nested ordering
and implicit schema.
The class can be instantiated either from a fits file, with `Skymap.from_fits`, or
directly with a numpy `numpy.array` containing the values associated to each HEALPix
pixel.

.. plot:: examples/skymaps/skymaps.py
:include-source:

Notebook examples
=================

Expand Down
Binary file added docs/examples/skymaps/skymap.fits
Binary file not shown.
7 changes: 7 additions & 0 deletions docs/examples/skymaps/skymaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Read and plots a quick preview of a skymap in a FITS file."""

from cdshealpix.skymap import Skymap

skymap = Skymap.from_fits("skymap.fits")
print(skymap.depth)
skymap.quick_plot()
21 changes: 17 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@
[project]
name = "cdshealpix"
requires-python = ">=3.8"
# https://numpy.org/neps/nep-0029-deprecation_policy.html
# https://docs.astropy.org/en/stable/changelog.html
dependencies = [
"astropy<5.3; python_version == '3.8'",
"astropy; python_version > '3.8'"
]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
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/"
issues = "https://github.com/cds-astro/cds-healpix-python/issues"
changelog = "https://github.com/cds-astro/cds-healpix-python/blob/master/CHANGELOG.md"


# Build a cdshealpix-x.x.x.tar.gz containing sources (from maturin).
[build-system]
Expand Down Expand Up @@ -44,7 +57,7 @@ output-format = "grouped"
show-source = true
ignore-init-module-imports = true
target-version = "py37"
extend-select = ["SIM", "D", "UP", "N", "S", "B", "A", "C4", "ICN", "RET", "ARG", "PD", "PGH", "RUF"]
extend-select = ["SIM", "D", "UP", "N", "S", "B", "A", "C4", "ICN", "RET", "ARG", "PGH", "RUF"]
extend-ignore = ["E501"]
# E501: line length (done by black in our case)
exclude = ["conf.py"]
Expand All @@ -67,6 +80,6 @@ max-string-length = 20
convention = "numpy" # Accepts: "google", "numpy", or "pep257"

[tool.pytest.ini_options]
addopts = "--doctest-modules"
addopts = "--doctest-modules --ignore-glob=python/cdshealpix/tests/test_bench*"
doctest_optionflags = "NORMALIZE_WHITESPACE"
testpaths = "python"
1 change: 1 addition & 0 deletions python/cdshealpix/skymap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .skymap import Skymap # noqa: F401
Loading
Loading