diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 402bbaf..ecb4de8 100755 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -19,27 +19,36 @@ 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 with: python-version: ${{ matrix.python-version }} - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + submodules: 'recursive' - 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 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 - python setup.py develop + pip install -e . + pip install seaborn matplotlib - name: Test package if: matrix.test == 'pytest' run: 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 diff --git a/wimprates/halo.py b/wimprates/halo.py index 4f943da..6be8351 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).round("s") @export def earth_velocity(t, v_0 = None):