From 062f66b3cf1a33f1098d5a424a5d12b3ba4b7b07 Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:18:44 +0200 Subject: [PATCH 01/11] Add j2000 to datetime utility function --- wimprates/halo.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wimprates/halo.py b/wimprates/halo.py index 4f943da..bf6b33b 100644 --- a/wimprates/halo.py +++ b/wimprates/halo.py @@ -67,6 +67,17 @@ def j2000_from_ymd(year, month, day_of_month): + np.floor(30.61 * (m + 1)) + day_of_month - 730563.5) +@export +def j2000_to_datetime(j2000_date): + """ + Returns date in np.datetime64 instance from the fractional number of days since J2000.0 epoch. + It is effectively the inverse of the j2000 function. + """ + zero_value = pd.to_datetime("2000-01-01T12:00").value + + nanoseconds_per_day = nu.day / nu.ns + _date = pd.to_datetime(j2000_date * nanoseconds_per_day).value + return pd.to_datetime(_date + zero_value) @export def earth_velocity(t, v_0 = None): From 3bf17b67ca480b4df7c1e5890a5b60dcffcfffdb Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:44:03 +0200 Subject: [PATCH 02/11] Add j2000_to_datetime pytest --- tests/test_halo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_halo.py b/tests/test_halo.py index bee71a5..782e1f8 100644 --- a/tests/test_halo.py +++ b/tests/test_halo.py @@ -1,7 +1,7 @@ from datetime import datetime import pandas as pd -from wimprates import j2000, StandardHaloModel, j2000_from_ymd +from wimprates import j2000, StandardHaloModel, j2000_from_ymd, j2000_to_datetime import numericalunits as nu import numpy as np @@ -21,6 +21,11 @@ def test_j2000_datetime(): assert j2000(date) == 3318.25 +def test_datetime_j2000(): + date = 3318.25 + assert j2000_to_datetime(date) == datetime(year=2009, month=1, day=31, hour=18) + + def test_j2000_ns_int(): date = datetime(year=2009, month=1, day=31, hour=18) value = pd.to_datetime(date).value From 1679466bcd3967d53cfb203f5d236f299adeec77 Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:37:49 +0200 Subject: [PATCH 03/11] Update pytest.yml --- .github/workflows/pytest.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 402bbaf..48cc63d 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -19,19 +19,21 @@ jobs: # Test coveralls (with numba disabled) and normal pytest test: [ 'coveralls', 'pytest', ] # Only do coveralls once; pytest on all python versions - python-version: [3.8, 3.9, "3.10"] + python-version: [3.9, "3.10", "3.11", "3.12"] exclude: - - python-version: 3.8 + - python-version: 3.10 test: coveralls - - python-version: 3.9 + - python-version: 3.11 + test: coveralls + - python-version: 3.12 test: coveralls steps: - name: Setup python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5.1.1 with: python-version: ${{ matrix.python-version }} - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4.1.7 - name: Install requirements for tests run: | # Requirements for running the notebooks as a pytest From 97fcd2567e1028d4487c7791190e100b49dcde0d Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:03:39 +0200 Subject: [PATCH 04/11] Update pytest.yml + fix test Bump action versions. Use `pip install -e .` instead of `python setup.py develop` as the latter is now deprecated. Trying to fix issue with jinja2 being deprecated. --- .github/workflows/pytest.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 48cc63d..3094b2d 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -29,19 +29,23 @@ jobs: test: coveralls steps: - name: Setup python - uses: actions/setup-python@v5.1.1 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Checkout repo - uses: actions/checkout@v4.1.7 + uses: actions/checkout@v4 - name: Install requirements for tests run: | + pip install --upgrade pip + # Require setuptools for python3.12 as well + pip install setuptools # Requirements for running the notebooks as a pytest pip install cython ipython pip install nbconvert nbmake pytest-xdist pytest coverage coveralls pytest-cov pytest-notebook ipython_genutils # Several optional packages that are imported in the notebooks pip install git+https://github.com/XENON1T/laidbax - python setup.py develop + pip install -e . + pip install -U jinja2 - name: Test package if: matrix.test == 'pytest' run: From 03f61dd5c4f3bbca965e4886766ddc69f41ad856 Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:07:51 +0200 Subject: [PATCH 05/11] Downgrade jinja for pytest.yml The following error arises while `Test package` executes in the workflow. The following suggestion was followed: https://github.com/d2l-ai/d2l-book/issues/46#issuecomment-1262704457 --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 3094b2d..bb381c7 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -41,11 +41,11 @@ jobs: pip install setuptools # Requirements for running the notebooks as a pytest pip install cython ipython + pip install jinja2==3.0.3 pip install nbconvert nbmake pytest-xdist pytest coverage coveralls pytest-cov pytest-notebook ipython_genutils # Several optional packages that are imported in the notebooks pip install git+https://github.com/XENON1T/laidbax pip install -e . - pip install -U jinja2 - name: Test package if: matrix.test == 'pytest' run: From f5db5f7fbae54db66641dade8fece964a2764b2a Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:13:29 +0200 Subject: [PATCH 06/11] Update pytest.yml Recursively checkout submodules --- .github/workflows/pytest.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index bb381c7..709af4e 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -34,6 +34,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Checkout repo uses: actions/checkout@v4 + with: + submodules: 'recursive' - name: Install requirements for tests run: | pip install --upgrade pip From 8866e901156457031a84b4cf817753edf475375c Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:55:40 +0200 Subject: [PATCH 07/11] Update pytest.yml Add libraries for notebooks --- .github/workflows/pytest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 709af4e..ecb4de8 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -48,6 +48,7 @@ jobs: # Several optional packages that are imported in the notebooks pip install git+https://github.com/XENON1T/laidbax pip install -e . + pip install seaborn matplotlib - name: Test package if: matrix.test == 'pytest' run: From 0aeec6830cc6f045d55a28dc9879e35c9453496c Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:18:44 +0200 Subject: [PATCH 08/11] Add j2000 to datetime utility function --- wimprates/halo.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wimprates/halo.py b/wimprates/halo.py index 4f943da..bf6b33b 100644 --- a/wimprates/halo.py +++ b/wimprates/halo.py @@ -67,6 +67,17 @@ def j2000_from_ymd(year, month, day_of_month): + np.floor(30.61 * (m + 1)) + day_of_month - 730563.5) +@export +def j2000_to_datetime(j2000_date): + """ + Returns date in np.datetime64 instance from the fractional number of days since J2000.0 epoch. + It is effectively the inverse of the j2000 function. + """ + zero_value = pd.to_datetime("2000-01-01T12:00").value + + nanoseconds_per_day = nu.day / nu.ns + _date = pd.to_datetime(j2000_date * nanoseconds_per_day).value + return pd.to_datetime(_date + zero_value) @export def earth_velocity(t, v_0 = None): From 9088162e18d01581d03d4c0a906b70ba9e8a849a Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:44:03 +0200 Subject: [PATCH 09/11] Add j2000_to_datetime pytest --- tests/test_halo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_halo.py b/tests/test_halo.py index bee71a5..782e1f8 100644 --- a/tests/test_halo.py +++ b/tests/test_halo.py @@ -1,7 +1,7 @@ from datetime import datetime import pandas as pd -from wimprates import j2000, StandardHaloModel, j2000_from_ymd +from wimprates import j2000, StandardHaloModel, j2000_from_ymd, j2000_to_datetime import numericalunits as nu import numpy as np @@ -21,6 +21,11 @@ def test_j2000_datetime(): assert j2000(date) == 3318.25 +def test_datetime_j2000(): + date = 3318.25 + assert j2000_to_datetime(date) == datetime(year=2009, month=1, day=31, hour=18) + + def test_j2000_ns_int(): date = datetime(year=2009, month=1, day=31, hour=18) value = pd.to_datetime(date).value From 3996166735436aff37cbb9fa39470946c5f5eda9 Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:00:54 +0200 Subject: [PATCH 10/11] Round j2000_to_datetime output to fix pytest --- wimprates/halo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wimprates/halo.py b/wimprates/halo.py index bf6b33b..78110db 100644 --- a/wimprates/halo.py +++ b/wimprates/halo.py @@ -77,7 +77,7 @@ def j2000_to_datetime(j2000_date): nanoseconds_per_day = nu.day / nu.ns _date = pd.to_datetime(j2000_date * nanoseconds_per_day).value - return pd.to_datetime(_date + zero_value) + return pd.to_datetime(_date + zero_value).round("ns") @export def earth_velocity(t, v_0 = None): From 98c52f5dab95a2b06db8598251961ef73b761ede Mon Sep 17 00:00:00 2001 From: Lorenzo Principe <28869147+lorenzomag@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:14:03 +0200 Subject: [PATCH 11/11] Reduce precision of j2000_to_datetime return to seconds --- wimprates/halo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wimprates/halo.py b/wimprates/halo.py index 78110db..6be8351 100644 --- a/wimprates/halo.py +++ b/wimprates/halo.py @@ -77,7 +77,7 @@ def j2000_to_datetime(j2000_date): nanoseconds_per_day = nu.day / nu.ns _date = pd.to_datetime(j2000_date * nanoseconds_per_day).value - return pd.to_datetime(_date + zero_value).round("ns") + return pd.to_datetime(_date + zero_value).round("s") @export def earth_velocity(t, v_0 = None):