Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add j2000 to datetime utility function #19

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
21 changes: 15 additions & 6 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_halo.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions wimprates/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading