Skip to content

Commit

Permalink
Merge pull request #95 from cds-astro/develop
Browse files Browse the repository at this point in the history
v0.12.3
  • Loading branch information
fxpineau authored Mar 6, 2023
2 parents f5852e4 + 35c0392 commit d2833c0
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ jobs:
echo "Loop on PYBIN: $PYBIN"
"${PYBIN}/pip" install maturin
"${PYBIN}/maturin" -V
"${PYBIN}/maturin" publish -i "${PYBIN}/python" --skip-existing --compatibility manylinux2014 --username "$MATURIN_USERNAME" --target aarch64-unknown-linux-gnu --config "net.git-fetch-with-cli = true"
"${PYBIN}/maturin" publish -i "${PYBIN}/python" --skip-existing --compatibility musllinux_1_2 --username "$MATURIN_USERNAME" --target aarch64-unknown-linux-gnu --config "net.git-fetch-with-cli = true"
"${PYBIN}/maturin" publish -i "${PYBIN}/python" --no-sdist --skip-existing --compatibility manylinux2014 --username "$MATURIN_USERNAME" --target aarch64-unknown-linux-gnu --config "net.git-fetch-with-cli = true"
"${PYBIN}/maturin" publish -i "${PYBIN}/python" --no-sdist --skip-existing --compatibility musllinux_1_2 --username "$MATURIN_USERNAME" --target aarch64-unknown-linux-gnu --config "net.git-fetch-with-cli = true"
done'
build-windows-wheels:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [0.12.3]

### Added

* `MOC.__init__` and `STMOC.__init__` raise `PermissionError` if user tries to modify order manually

### Fixed

* :bug: position angle limited to PI/2 instead of PI in `MOC.from_elliptical_cone`

## [0.12.2]

### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "MOCPy"
version = "0.12.2"
version = "0.12.3"
authors = [
"Matthieu Baumann <[email protected]>",
"Thomas Boch <[email protected]>",
Expand All @@ -27,7 +27,7 @@ bench = true
crate-type = ["cdylib"]

[dependencies]
moc = { version = "0.11", features = ["storage"] }
moc = { version = "0.11.2", features = ["storage"] }
healpix = { package = "cdshealpix", version = "0.6" }
# moc = { git = 'https://github.com/cds-astro/cds-moc-rust', branch = 'main', features = ["storage"] }
# healpix = { package = "cdshealpix", git = 'https://github.com/cds-astro/cds-healpix-rust', branch = 'master' }
Expand Down
8 changes: 8 additions & 0 deletions docs/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Now build package
This step will inform you of any issue in the rust part.

- After a new version of mocpy goes out, if a `maturin develop --release` does not actualise your `Cargo.toml` file, you might need to before executing the `maturin` command again::

rm Cargo.lock && cargo clean

Running the python tests
------------------------
Expand All @@ -97,6 +100,11 @@ Once your environment is set up and activated you can run the tests

python -m pytest -v python/mocpy --cov-report=term --cov=python/mocpy

- When contributing to the notebooks::

python -m pip install -r requirements/notebooks.txt
python -m pytest --nbmake -n=auto "./notebooks"

You also can have a html output of the coverage. For that set `--cov-report=html`,
this will generate an `htmlcov` folder where all the static html files can be found.

Expand Down
15 changes: 6 additions & 9 deletions python/mocpy/moc/boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
pass

from astropy.coordinates import ICRS, SkyCoord
from astropy.wcs.utils import skycoord_to_pixel
import astropy.units as u

from .. import mocpy


class Boundaries:
Expand All @@ -25,7 +23,7 @@ def get(moc, order):

# Split the global MOC graph into all its non connected subgraphs.
graph_boundaries = Boundaries._compute_graph_HEALPix_boundaries(
max_order, ipixels
max_order, ipixels,
)
boundaries_l.extend(Boundaries._retrieve_skycoords(graph_boundaries))

Expand All @@ -34,17 +32,16 @@ def get(moc, order):
@staticmethod
def _compute_HEALPix_indices(m, order):
moc = m
if order:
if m.max_order > order:
moc = m.degrade_to_order(order)
if order and m.max_order > order:
moc = m.degrade_to_order(order)

max_order = moc.max_order
ipixels = moc.flatten()

# Take the complement if the MOC covers more than half of the sky => the perimeter(MOC) = perimeter(complement(MOC))
# but we process less hpx cells
num_ipixels = 3 << (2 * (max_order + 1))
sky_fraction = ipixels.shape[0] / float(num_ipixels)
ipixels.shape[0] / float(num_ipixels)

# if sky_fraction > 0.5:
# ipixels_all = np.arange(num_ipixels)
Expand Down Expand Up @@ -111,10 +108,10 @@ def insert_edge(G, l1, l2, p1_lon, p1_lat, p2_lon, p2_lat):
ipix_lat_deg = ipix_lat.to_value(u.deg)

ipix_lon_repr = np.around(
np.asarray(ipix_lon.reshape((1, -1))[0]), decimals=3
np.asarray(ipix_lon.reshape((1, -1))[0]), decimals=3,
).tolist()
ipix_lat_repr = np.around(
np.asarray(ipix_lat.reshape((1, -1))[0]), decimals=3
np.asarray(ipix_lat.reshape((1, -1))[0]), decimals=3,
).tolist()

west_border = ~isin_border[0, :]
Expand Down
8 changes: 4 additions & 4 deletions python/mocpy/moc/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ def from_healpix_cells(cls, ipix, depth, max_depth):
def from_depth29_ranges(cls, max_depth, ranges):
"""
Create a MOC from a set of ranges of HEALPix Nested indices at order 29.
For each range, the lower bound is inclusive and the upper bound is exclusive.
The range `[0, 12*4^29[` represents the full-sky.
Expand Down Expand Up @@ -1217,15 +1218,12 @@ def _query(self, resource_id, max_rows=100000, timeout=1000):
votable.write(r.content)

return parse_single_table(votable).to_table()

# note to devs: performing function call in function definition won't bring a bug
# only because this defines a constant. ignoring BugBear warning B008 here. Do not reproduce.
def wcs(
self,
fig,
coordsys="icrs",
projection="AIT",
rotation=Angle(0, u.radian),
rotation=None,
):
"""
Get a wcs that can be given to matplotlib to plot the MOC.
Expand Down Expand Up @@ -1269,6 +1267,8 @@ def wcs(
>>> plt.ylabel('dec')
>>> plt.grid(color="black", linestyle="dotted")
"""
if rotation is None:
rotation = Angle(0, u.radian)
# The center is set to the barycenter of all its HEALPix cells
center = self.barycenter()
# The fov is computed from the largest distance between the center and any cells of it
Expand Down
64 changes: 30 additions & 34 deletions python/mocpy/stmoc/stmoc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import numpy as np

Expand Down Expand Up @@ -27,20 +25,21 @@ def __init__(self, create_key, store_index):
create_key: Object ensure __init__ is called by super-class/class-methods only
store_index: index of the ST-MOC in the rust-side storage
"""
super(STMOC, self).__init__(
AbstractMOC._create_key, STMOC.__create_key, store_index
super().__init__(
AbstractMOC._create_key, STMOC.__create_key, store_index,
)
assert (
create_key == STMOC.__create_key
), "ST-MOC instantiation is only allowed by class or super-class methods"
if create_key != STMOC.__create_key:
raise PermissionError(
"ST-MOC instantiation is only allowed by class or super-class methods",
)

def __del__(self):
"""Erase STMOC."""
super(STMOC, self).__del__()
super().__del__()

def __eq__(self, other):
"""Assert equality between MOCs."""
return super(STMOC, self).__eq__(other)
return super().__eq__(other)

@property
def max_depth(self):
Expand Down Expand Up @@ -98,13 +97,12 @@ def from_times_positions(cls, times, time_depth, lon, lat, spatial_depth):
raise ValueError("Times and positions must be 1D arrays.")

index = mocpy.from_time_lonlat(times, time_depth, lon, lat, spatial_depth)
result = cls(cls.__create_key, index)

return result
return cls(cls.__create_key, index)

@classmethod
def from_time_ranges_positions(
cls, times_start, times_end, lon, lat, time_depth=61, spatial_depth=29
cls, times_start, times_end, lon, lat, time_depth=61, spatial_depth=29,
):
"""
Create a 2D Coverage from a set of times and positions associated to each time.
Expand Down Expand Up @@ -152,15 +150,14 @@ def from_time_ranges_positions(
raise ValueError("Times and positions must be 1D arrays.")

index = mocpy.from_time_ranges_lonlat(
times_start, times_end, time_depth, lon, lat, spatial_depth
times_start, times_end, time_depth, lon, lat, spatial_depth,
)
result = cls(cls.__create_key, index)

return result
return cls(cls.__create_key, index)

@classmethod
def from_spatial_coverages(
cls, times_start, times_end, spatial_coverages, time_depth=61
cls, times_start, times_end, spatial_coverages, time_depth=61,
):
"""
Create a 2D Coverage from a set of time ranges and spatial coverages associated to them.
Expand All @@ -187,25 +184,24 @@ def from_spatial_coverages(
times_end = times_to_microseconds(times_end)

if times_start.shape != times_end.shape or times_start.shape[0] != len(
spatial_coverages
spatial_coverages,
):
raise ValueError(
"Time ranges and spatial coverages must have the same length"
"Time ranges and spatial coverages must have the same length",
)

if times_start.ndim != 1:
raise ValueError("Times and spatial coverages must be 1D arrays")


spatial_coverages_indices = np.fromiter(
(arg._store_index for arg in spatial_coverages), dtype=AbstractMOC.store_index_dtype()
(arg._store_index for arg in spatial_coverages), dtype=AbstractMOC.store_index_dtype(),
)
index = mocpy.from_time_ranges_spatial_coverages(
times_start, times_end, time_depth, spatial_coverages_indices
times_start, times_end, time_depth, spatial_coverages_indices,
)
result = cls(cls.__create_key, index)

return result
return cls(cls.__create_key, index)

def query_by_time(self, tmoc):
"""
Expand Down Expand Up @@ -295,10 +291,11 @@ def contains(self, times, lon, lat, inside=True):
if not inside:
result = ~result

return result
return result # noqa: RET504

@classmethod
def load(cls, path, format="fits"):
# A002: Argument `format` is shadowing a python function
def load(cls, path, format="fits"): # noqa: A002
"""
Load the Spatial MOC from a file.
Expand All @@ -317,15 +314,14 @@ def load(cls, path, format="fits"):
if format == "fits":
index = mocpy.coverage_2d_from_fits_file(path)
return cls(cls.__create_key, index)
elif format == "ascii":
if format == "ascii":
index = mocpy.coverage_2d_from_ascii_file(path)
return cls(cls.__create_key, index)
elif format == "json":
if format == "json":
index = mocpy.coverage_2d_from_json_file(path)
return cls(cls.__create_key, index)
else:
formats = ("fits", "ascii", "json")
raise ValueError("format should be one of %s" % (str(formats)))
formats = ("fits", "ascii", "json")
raise ValueError("format should be one of %s" % (str(formats)))

@classmethod
def _from_fits_raw_bytes(cls, raw_bytes):
Expand All @@ -334,7 +330,8 @@ def _from_fits_raw_bytes(cls, raw_bytes):
return cls(cls.__create_key, index)

@classmethod
def from_string(cls, value, format="ascii"):
# A002: Argument `format` is shadowing a python function
def from_string(cls, value, format="ascii"): # noqa: A002
"""
Deserialize the Spatial MOC from the given string.
Expand All @@ -350,9 +347,8 @@ def from_string(cls, value, format="ascii"):
if format == "ascii":
index = mocpy.coverage_2d_from_ascii_str(value)
return cls(cls.__create_key, index)
elif format == "json":
if format == "json":
index = mocpy.coverage_2d_from_json_str(value)
return cls(cls.__create_key, index)
else:
formats = ("ascii", "json")
raise ValueError("format should be one of %s" % (str(formats)))
formats = ("ascii", "json")
raise ValueError("format should be one of %s" % (str(formats)))
2 changes: 1 addition & 1 deletion python/mocpy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.12.2"
__version__ = "0.12.3"

0 comments on commit d2833c0

Please sign in to comment.