Skip to content

Commit

Permalink
remove test utility module
Browse files Browse the repository at this point in the history
  • Loading branch information
tnakazato committed Jan 25, 2025
1 parent 00b58fd commit 14e3a3e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 64 deletions.
12 changes: 11 additions & 1 deletion src/nro45data/psw/ms2/_casa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@
from ._casa6 import convert_str_angle_to_rad
from ._casa6 import put_table_keyword
from ._casa6 import datestr2mjd
from ._casa6 import mjd2datetime
elif _is_casacore_available:
from ._casacore import build_table
from ._casacore import open_table
from ._casacore import _table
from ._casacore import convert_str_angle_to_rad
from ._casacore import put_table_keyword
from ._casacore import datestr2mjd
from ._casacore import mjd2datetime
else:
raise ModuleNotFoundError("Neither casatools or python-casacore is available")

__all__ = ["build_table", "open_table", "_table", "convert_str_angle_to_rad", "put_table_keyword"]
__all__ = [
"build_table",
"open_table",
"_table",
"convert_str_angle_to_rad",
"put_table_keyword",
"datestr2mjd",
"mjd2datetime"
]
26 changes: 26 additions & 0 deletions src/nro45data/psw/ms2/_casa/_casa6.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import datetime
from typing import Any

try:
Expand Down Expand Up @@ -61,3 +62,28 @@ def datestr2mjd(date_str: str) -> float:
"""
q = _quanta.quantity(date_str)
return _quanta.convert(q, "s")["value"]


def mjd2datetime(mjd: float) -> datetime.datetime:
"""Convert MJD time in sec to datetime object.
Args:
mjd: MJD time in sec
Returns:
datetime object
"""
qa = _quanta
qtime = qa.quantity(mjd, "s")
dtdict = qa.splitdate(qtime)
dtobj = datetime.datetime(
dtdict["year"],
dtdict["month"],
dtdict["monthday"],
dtdict["hour"],
dtdict["min"],
dtdict["sec"],
dtdict["usec"]
)

return dtobj
17 changes: 17 additions & 0 deletions src/nro45data/psw/ms2/_casa/_casacore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import datetime
from typing import Any

try:
Expand Down Expand Up @@ -56,3 +57,19 @@ def datestr2mjd(date_str: str) -> float:
"""
q = _quanta.quantity(date_str)
return q.get("s").get_value()


def mjd2datetime(mjd: float) -> datetime.datetime:
"""Convert MJD time in sec to datetime object.
Args:
mjd: MJD time in sec
Returns:
datetime object
"""
qa = _quanta
qtime = qa.quantity(mjd, "s")
dtobj = datetime.datetime.fromtimestamp(qtime.to_unix_time())

return dtobj
52 changes: 0 additions & 52 deletions tests/_utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def unit_test_mocks(monkeypatch: None):
pass


@pytest.fixture
@pytest.fixture(scope="session")
def data_dir() -> str:
"""Return the path to the data directory."""
return os.path.join(os.path.dirname(__file__), "data")
18 changes: 8 additions & 10 deletions tests/ms2_filler/test_h40.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os
import shutil
import time

import numpy as np
import pytest
Expand All @@ -11,20 +12,17 @@
_ms = None

import nro45data.psw as psw
from nro45data.psw.ms2._casa import open_table

from .. import _utils
from nro45data.psw.ms2._casa import open_table, mjd2datetime


@pytest.fixture(scope="module")
def msfile():
def msfile(data_dir):
# input nqm file
data_dir = _utils._get_data_dir()
nqmfile = "nmlh40.240926005833.01.nqm"

# generate MS
msfile = _utils._generate_random_name()
nqmpath = os.path.join(data_dir, nqmfile)
msfile = ".".join([nqmpath, time.strftime("%Y%M%dT%H%M%S"), 'ms'])
try:
psw.nqm2ms2(nqmpath, msfile)
except Exception as e:
Expand Down Expand Up @@ -60,11 +58,11 @@ def test_ms2_structure_h40(msfile):
# start time: 2024/09/26 00:58:54
# end time: 2024/09/26 01:03:50
start_expected = datetime.datetime(2024, 9, 26, 0, 58, 54)
start_time = _utils.mjd2datetime(time_range[0])
start_time = mjd2datetime(time_range[0])
assert start_time == start_expected

Check failure on line 62 in tests/ms2_filler/test_h40.py

View workflow job for this annotation

GitHub Actions / testing

test_ms2_structure_h40 assert datetime.datetime(2024, 9, 25, 15, 58, 54) == datetime.datetime(2024, 9, 26, 0, 58, 54)

end_expected = datetime.datetime(2024, 9, 26, 1, 3, 50)
end_time = _utils.mjd2datetime(time_range[1])
end_time = mjd2datetime(time_range[1])
assert end_time == end_expected

with open_table(os.path.join(msfile, "SPECTRAL_WINDOW")) as tb:
Expand Down Expand Up @@ -109,12 +107,12 @@ def test_ms2_structure_h40(msfile):

# start time: 2024/9/26 0:59:19, integration time 1sec
start_expected = datetime.datetime(2024, 9, 26, 0, 59, 19, 500000)
start_time = _utils.mjd2datetime(tb.getcell("TIME", 0))
start_time = mjd2datetime(tb.getcell("TIME", 0))
assert start_time == start_expected

# end time: 2024/9/26 1:3:50, integration time 5sec
end_expected = datetime.datetime(2024, 9, 26, 1, 3, 47, 500000)
end_time = _utils.mjd2datetime(tb.getcell("TIME", nrows - 1))
end_time = mjd2datetime(tb.getcell("TIME", nrows - 1))
assert end_time == end_expected

# data cell shape
Expand Down

0 comments on commit 14e3a3e

Please sign in to comment.