From 728218d5e62213599e67df2e7573052c4db2e233 Mon Sep 17 00:00:00 2001 From: lgrcia Date: Fri, 5 Jan 2024 10:46:18 +0100 Subject: [PATCH 1/8] chore: add comparison dependencies and use hatch --- pyproject.toml | 47 +++++++++++++++++++++-------------------------- readme.md | 2 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4362d1a..c2a90cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,35 +1,30 @@ -[tool.poetry] +[project] name = "spotter" version = "0.0.4-beta" description = "Stellar contamination estimates from rotational light curves" -authors = ["Lionel Garcia", "Benjamin Rackham"] +authors = [{name="Lionel Garcia"}, {name="Benjamin Rackham"}] license = "MIT" readme = "readme.md" +requires-python = ">=3.9" packages = [{ include = "spotter" },] +dependencies = ["numpy<1.22", "healpy", "matplotlib", "jax", "jaxlib"] -[tool.poetry.dependencies] -python = "^3.9" -numpy = "^1.25.0" -healpy = "*" -matplotlib = "*" -jax = "*" -jaxlib = "*" - -[tool.poetry.group.dev.dependencies] -pytest = "*" -black = "*" - -[tool.poetry.group.docs.dependencies] -sphinx = "*" -docutils = "*" -jupyterlab = "*" -myst-parser = "*" -sphinx-book-theme = "^1.0.0" -myst-nb = "*" -sphinx-copybutton = "*" -toml = "*" -ipywidgets = "*" +[project.optional-dependencies] +dev = ["black", "pytest"] +test = ["pytest"] +comparison = ["starry", "tqdm", "xarray<2023.10.0"] +docs = [ + "sphinx", + "docutils", + "jupyterlab", + "myst-parser", + "sphinx-book-theme", + "myst-nb", + "sphinx-copybutton", + "toml", + "ipywidgets" + ] [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" \ No newline at end of file diff --git a/readme.md b/readme.md index 2397a2a..f5531be 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@

- github + github license From 69096db905d7218cc65349e0180c9e4ba355abc7 Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 14:46:05 -0500 Subject: [PATCH 2/8] tests: fix version + install non-existent --- .github/workflows/ci.yml | 2 +- noxfile.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a1749b..3ffcc4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.11"] session: - "test" include: diff --git a/noxfile.py b/noxfile.py index 5c6f173..ab516f7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,12 +2,12 @@ import nox -ALL_PYTHON_VS = ["3.9", "3.10", "3.11"] +ALL_PYTHON_VS = ["3.9", "3.11"] @nox.session(python=ALL_PYTHON_VS) def test(session): - session.install(".[test,test-math]") + session.install(".[test]") session.run("pytest", "-n", "auto", *session.posargs) From 57acdb1e1d0ee5047dc88029a09d3a9b614abe9a Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 14:48:19 -0500 Subject: [PATCH 3/8] fix: add pytest-xdist --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2294e7f..84ca745 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ dependencies = ["numpy<1.22", "healpy", "matplotlib", "jax", "jaxlib"] [project.optional-dependencies] dev = ["black", "pytest", "nox"] -test = ["pytest"] +test = ["pytest", "pytest-xdist"] comparison = ["starry", "tqdm", "xarray<2023.10.0"] docs = [ "sphinx", From b360a3e05dcaad2a93ea40e1df052abcc508ab1d Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 14:52:51 -0500 Subject: [PATCH 4/8] fix: starry tests path --- noxfile.py | 2 +- tests/{test_starry.py => starry/test_flux.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{test_starry.py => starry/test_flux.py} (100%) diff --git a/noxfile.py b/noxfile.py index ab516f7..b3ee668 100644 --- a/noxfile.py +++ b/noxfile.py @@ -19,7 +19,7 @@ def comparison(session): if session.posargs: args = session.posargs else: - args = ("tests/experimental/starry",) + args = ("tests/starry",) session.run( "pytest", "-n", diff --git a/tests/test_starry.py b/tests/starry/test_flux.py similarity index 100% rename from tests/test_starry.py rename to tests/starry/test_flux.py From 225a04e36f7eb595cdd008a423dcf3fd5bddb97b Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 14:55:47 -0500 Subject: [PATCH 5/8] fix: starry pytest import --- tests/starry/test_flux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/starry/test_flux.py b/tests/starry/test_flux.py index 7af13a7..c9f77ed 100644 --- a/tests/starry/test_flux.py +++ b/tests/starry/test_flux.py @@ -8,7 +8,7 @@ @pytest.mark.parametrize("deg", (3, 10)) @pytest.mark.parametrize("u", ([], [0.1, 0.4])) def test_starry(deg, u): - starry = pytest.importorskip("starry") + pytest.importorskip("starry") starry.config.lazy = False starry.config.quiet = True From 5ad3ad416253ecb744e2b647500241201f393df8 Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 15:03:52 -0500 Subject: [PATCH 6/8] fix: flux starry test + numpy version --- pyproject.toml | 4 ++-- spotter/star.py | 12 ++++++++---- tests/starry/test_flux.py | 8 +++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 84ca745..a1a09fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,12 +7,12 @@ license = "MIT" readme = "readme.md" requires-python = ">=3.9" packages = [{ include = "spotter" },] -dependencies = ["numpy<1.22", "healpy", "matplotlib", "jax", "jaxlib"] +dependencies = ["numpy", "healpy", "matplotlib", "jax", "jaxlib"] [project.optional-dependencies] dev = ["black", "pytest", "nox"] test = ["pytest", "pytest-xdist"] -comparison = ["starry", "tqdm", "xarray<2023.10.0"] +comparison = ["starry", "tqdm", "xarray<2023.10.0", "numpy<1.22"] docs = [ "sphinx", "docutils", diff --git a/spotter/star.py b/spotter/star.py index 3354eb2..13dc2b0 100644 --- a/spotter/star.py +++ b/spotter/star.py @@ -338,7 +338,9 @@ def jax_flux(self, phases): def flux(spot_map): _spot = (1 - spot_map) * limb_darkening _geometry = mask * projected_area - return (_spot * _geometry).sum(1) / (_geometry * limb_darkening).sum(1) + return ( + np.pi * (_spot * _geometry).sum(1) / (_geometry * limb_darkening).sum(1) + ) return flux @@ -460,9 +462,11 @@ def flux(self, phases): # faculae contribution, with same ld for now (TODO) _faculae = 0 # self.map_faculae * limb_darkening - return ((_spot + _faculae) * _geometry).sum(1) / ( - _geometry * limb_darkening - ).sum(1) + return ( + np.pi + * ((_spot + _faculae) * _geometry).sum(1) + / (_geometry * limb_darkening).sum(1) + ) def map(self, phase=None, limb_darkening=False): """ diff --git a/tests/starry/test_flux.py b/tests/starry/test_flux.py index c9f77ed..0babc5b 100644 --- a/tests/starry/test_flux.py +++ b/tests/starry/test_flux.py @@ -8,10 +8,8 @@ @pytest.mark.parametrize("deg", (3, 10)) @pytest.mark.parametrize("u", ([], [0.1, 0.4])) def test_starry(deg, u): - pytest.importorskip("starry") - + starry = pytest.importorskip("starry") starry.config.lazy = False - starry.config.quiet = True # starry map with random coefficients np.random.seed(deg + len(u)) @@ -73,7 +71,7 @@ def starry2healpy(y): # comparison phases = np.linspace(0, 2 * np.pi, 100) - expected = ms.flux(theta=np.rad2deg(phases)) - calc = np.pi * star.flux(phases) + expected = np.array(ms.flux(theta=np.rad2deg(phases))) + calc = star.flux(phases) np.testing.assert_allclose(calc, expected, atol=1e-4) From f6305a85edf1635f779849b39e0a759951fabbf1 Mon Sep 17 00:00:00 2001 From: lgrcia Date: Tue, 9 Jan 2024 15:23:49 -0500 Subject: [PATCH 7/8] fix: try non parallel --- .github/workflows/ci.yml | 2 +- noxfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ffcc4f..56a831a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: - uses: actions/setup-python@v5 name: Install Python with: - python-version: "3.10" + python-version: "3.11" - name: Install dependencies run: | python -m pip install -U pip diff --git a/noxfile.py b/noxfile.py index b3ee668..6847011 100644 --- a/noxfile.py +++ b/noxfile.py @@ -8,7 +8,7 @@ @nox.session(python=ALL_PYTHON_VS) def test(session): session.install(".[test]") - session.run("pytest", "-n", "auto", *session.posargs) + session.run("pytest", *session.posargs) @nox.session(python=["3.9"]) From 654842cade6893d1078cb83a3c9e6677dcbb6490 Mon Sep 17 00:00:00 2001 From: lgrcia Date: Wed, 10 Jan 2024 11:01:10 -0500 Subject: [PATCH 8/8] tests: fix bad import (due to parent folder name conflict 'starry') --- noxfile.py | 2 +- tests/{starry => starry_comparison}/test_flux.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) rename tests/{starry => starry_comparison}/test_flux.py (99%) diff --git a/noxfile.py b/noxfile.py index 6847011..14b8acd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -19,7 +19,7 @@ def comparison(session): if session.posargs: args = session.posargs else: - args = ("tests/starry",) + args = ("tests/starry_comparison",) session.run( "pytest", "-n", diff --git a/tests/starry/test_flux.py b/tests/starry_comparison/test_flux.py similarity index 99% rename from tests/starry/test_flux.py rename to tests/starry_comparison/test_flux.py index 0babc5b..127776e 100644 --- a/tests/starry/test_flux.py +++ b/tests/starry_comparison/test_flux.py @@ -1,8 +1,10 @@ -import pytest -import numpy as np -from spotter import Star from collections import defaultdict + import healpy as hp +import numpy as np +import pytest + +from spotter import Star @pytest.mark.parametrize("deg", (3, 10))