Skip to content

Commit

Permalink
Revert some breaking API changes for the healpy compatible functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSa committed Apr 27, 2024
1 parent 13cf38d commit 824edbd
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 81 deletions.
56 changes: 28 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions tests/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ def frames(draw: DrawFn) -> type[coords.BaseCoordinateFrame]:
)


@composite
def coords_in(draw: DrawFn) -> str:
return draw(sampled_from(["E", "G", "C"]))


@composite
def sky_coords(draw: DrawFn) -> coords.SkyCoord:
theta_strategy = floats(min_value=0, max_value=360)
phi_strategy = floats(min_value=-90, max_value=90)

obs_time = draw(times())
shape = draw(integers(min_value=1, max_value=MAX_ANGELS_LEN))

theta_array_strategy = arrays(dtype=float, shape=shape, elements=theta_strategy).map(
Expand All @@ -107,7 +112,7 @@ def sky_coords(draw: DrawFn) -> coords.SkyCoord:
frame = draw(frames())
lon = draw(theta_array_strategy)
lat = draw(phi_array_strategy)
return coords.SkyCoord(lon, lat, frame=frame)
return coords.SkyCoord(lon, lat, frame=frame, obstime=obs_time)


@composite
Expand Down
50 changes: 42 additions & 8 deletions tests/test_get_emission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Literal

import astropy.coordinates as coords
import astropy.units as u
import healpy as hp
Expand All @@ -13,6 +15,7 @@

from ._strategies import (
angles,
coords_in,
freqs,
nsides,
obs_positions,
Expand All @@ -29,33 +32,55 @@
DIRBE_START_DAY = Time("1990-01-01")


@given(zodipy_models(), times(), sky_coords(), data())
@given(zodipy_models(), sky_coords(), data())
@settings(deadline=None)
def test_get_emission_skycoord(
model: Zodipy,
time: Time,
coordinates: coords.SkyCoord,
data: DataObject,
) -> None:
"""Property test for get_emission_skycoord."""
observer = data.draw(obs_positions(model, time))
observer = data.draw(obs_positions(model, coordinates.obstime))
frequency = data.draw(freqs(model))
emission = model.get_emission_skycoord(
coordinates,
freq=frequency,
obs_time=time,
obs_pos=observer,
)
assert emission.size == coordinates.size


@given(zodipy_models(), times(), nsides(), data())
@given(zodipy_models(), sky_coords(), nsides(), data())
@settings(deadline=None)
def test_get_binned_skycoord(
model: Zodipy,
coordinates: coords.SkyCoord,
nside: int,
data: DataObject,
) -> None:
"""Property test for get_binned_emission_pix."""
observer = data.draw(obs_positions(model, coordinates.obstime))
frequency = data.draw(freqs(model))
cut_solar = data.draw(booleans())

emission_binned = model.get_binned_emission_skycoord(
coordinates,
freq=frequency,
obs_pos=observer,
nside=nside,
solar_cut=data.draw(quantities(20, 50, u.deg)) if cut_solar else None,
)
assert emission_binned.shape == (hp.nside2npix(nside),)


@given(zodipy_models(), times(), nsides(), data(), coords_in())
@settings(deadline=None)
def test_get_emission_pix(
model: Zodipy,
time: Time,
nside: int,
data: DataObject,
coord_in: Literal["E", "G", "C"],
) -> None:
"""Property test for get_emission_pix."""
observer = data.draw(obs_positions(model, time))
Expand All @@ -67,17 +92,19 @@ def test_get_emission_pix(
freq=frequency,
obs_time=time,
obs_pos=observer,
coord_in=coord_in,
)
assert np.size(emission) == np.size(pix)


@given(zodipy_models(), times(), nsides(), data())
@given(zodipy_models(), times(), nsides(), data(), coords_in())
@settings(deadline=None)
def test_get_binned_emission_pix(
model: Zodipy,
time: Time,
nside: int,
data: DataObject,
coord_in: Literal["E", "G", "C"],
) -> None:
"""Property test for get_binned_emission_pix."""
observer = data.draw(obs_positions(model, time))
Expand All @@ -91,17 +118,19 @@ def test_get_binned_emission_pix(
obs_time=time,
obs_pos=observer,
solar_cut=data.draw(quantities(20, 50, u.deg)) if cut_solar else None,
coord_in=coord_in,
)
assert emission_binned.shape == (hp.nside2npix(nside),)


@given(zodipy_models(), times(), angles(), data())
@given(zodipy_models(), times(), angles(), data(), coords_in())
@settings(deadline=None)
def test_get_emission_ang(
model: Zodipy,
time: Time,
angles: tuple[u.Quantity[u.deg], u.Quantity[u.deg]],
data: DataObject,
coord_in: Literal["E", "G", "C"],
) -> None:
"""Property test for get_emission_ang."""
theta, phi = angles
Expand All @@ -115,24 +144,27 @@ def test_get_emission_ang(
freq=frequency,
obs_time=time,
obs_pos=observer,
coord_in=coord_in,
)
assert emission.size == theta.size == phi.size


@given(zodipy_models(), times(), nsides(), angles(), data())
@given(zodipy_models(), times(), nsides(), angles(), data(), coords_in())
@settings(deadline=None)
def test_get_binned_emission_ang(
model: Zodipy,
time: Time,
nside: int,
angles: tuple[u.Quantity[u.deg], u.Quantity[u.deg]],
data: DataObject,
coord_in: Literal["E", "G", "C"],
) -> None:
"""Property test for get_binned_emission_pix."""
theta, phi = angles

observer = data.draw(obs_positions(model, time))
frequency = data.draw(freqs(model))
cut_solar = data.draw(booleans())

emission_binned = model.get_binned_emission_ang(
theta,
Expand All @@ -141,6 +173,8 @@ def test_get_binned_emission_ang(
freq=frequency,
obs_time=time,
obs_pos=observer,
coord_in=coord_in,
solar_cut=data.draw(quantities(20, 50, u.deg)) if cut_solar else None,
)
assert emission_binned.shape == (hp.nside2npix(nside),)

Expand Down
2 changes: 1 addition & 1 deletion zodipy/_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_obs_skycoord(
raise TypeError(msg) from AttributeError


def get_frame_from_string(frame_literal: int) -> type[coords.BaseCoordinateFrame]:
def get_frame_from_string(frame_literal: str) -> type[coords.BaseCoordinateFrame]:
"""Return the appropriate astropy coordinate frame class from a string literal."""
if frame_literal == "E":
return coords.BarycentricMeanEcliptic
Expand Down
Loading

0 comments on commit 824edbd

Please sign in to comment.