Skip to content

Commit

Permalink
unit test: add numeric comparison (#90)
Browse files Browse the repository at this point in the history
+ `tests.grid/point.py`: add numeric comparisons between the calculated results and the hardcore numpy array

+ `pyproject.toml`: attempt to fix [the `long_description` syntax error](https://github.com/insarlab/PySolid/actions/runs/9626458068/job/26552735067) while uploading to PyPI, without understanding the logic behind.
  • Loading branch information
yunjunz committed Jun 24, 2024
1 parent de3dd3a commit 101e0a5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ zip-safe = false

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
readme = { file = ["README.md"], content-type = "text/markdown" }
readme = { file = "README.md", content-type = "text/markdown" }

# extra requirements: `pip install pysolid[docs]` or `pip install .[docs,test]`
# note: the [docs] syntax requires setuptools>=64.0, thus, not working yet.
Expand Down
33 changes: 33 additions & 0 deletions tests/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
import datetime as dt

import numpy as np

import pysolid


Expand All @@ -27,11 +29,42 @@
'Y_STEP' : -0.000833333,
}

# reference
# calculated based on version 0.3.2.post6 on Jun 24, 2024
# env: macOS with python-3.10, numpy-1.24
# install: manual compilation via f2py
tide_e_80_100 = np.array(
[[0.01628786, 0.01630887, 0.01633078, 0.01635247, 0.01637394],
[0.01633248, 0.01635348, 0.01637538, 0.01639706, 0.01641851],
[0.01638009, 0.01640107, 0.01642296, 0.01644462, 0.01646606],
[0.01642767, 0.01644864, 0.01647052, 0.01649217, 0.01651359],
[0.01647523, 0.01649619, 0.01651805, 0.01653968, 0.01656109]],
)
tide_n_80_100 = np.array(
[[-0.02406203, -0.02412341, -0.02418807, -0.02425273, -0.0243174 ],
[-0.02407558, -0.02413699, -0.02420168, -0.02426637, -0.02433107],
[-0.02408992, -0.02415136, -0.02421608, -0.02428081, -0.02434554],
[-0.02410413, -0.0241656 , -0.02423036, -0.02429511, -0.02435988],
[-0.02411821, -0.02417972, -0.0242445 , -0.02430929, -0.02437408]],
)
tide_u_80_100 = np.array(
[[-0.05548462, -0.05533455, -0.05517631, -0.05501789, -0.05485928],
[-0.05529561, -0.0551451 , -0.05498639, -0.0548275 , -0.05466843],
[-0.05509374, -0.05494276, -0.05478355, -0.05462417, -0.05446461],
[-0.05489176, -0.05474031, -0.05458061, -0.05442073, -0.05426067],
[-0.05468968, -0.05453776, -0.05437757, -0.05421719, -0.05405664]],
)

# calculate
(tide_e,
tide_n,
tide_u) = pysolid.calc_solid_earth_tides_grid(dt_obj, atr, verbose=True)

# compare
assert np.allclose(tide_e[::80, ::100], tide_e_80_100)
assert np.allclose(tide_n[::80, ::100], tide_n_80_100)
assert np.allclose(tide_u[::80, ::100], tide_u_80_100)

# plot
out_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'pic'))
os.makedirs(out_dir, exist_ok=True)
Expand Down
41 changes: 39 additions & 2 deletions tests/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
import datetime as dt

import numpy as np

import pysolid


Expand All @@ -18,15 +20,50 @@

# prepare inputs
lat, lon = 34.0, -118.0 # Los Angles, CA
dt_obj0 = dt.datetime(2020, 11, 1, 4, 0, 0)
dt_obj1 = dt.datetime(2020, 12, 31, 2, 0, 0)
dt_obj0 = dt.datetime(2020, 11, 5, 12, 0, 0)
dt_obj1 = dt.datetime(2020, 12, 31, 0, 0, 0)

# reference
# calculated based on version 0.3.2.post6 on Jun 24, 2024
# env: macOS with python-3.10, numpy-1.24
# install: manual compilation via f2py
dt_out_8000 = np.array(
[dt.datetime(2020, 11, 5, 12, 0),
dt.datetime(2020, 11, 11, 1, 20),
dt.datetime(2020, 11, 16, 14, 40),
dt.datetime(2020, 11, 22, 4, 0),
dt.datetime(2020, 11, 27, 17, 20),
dt.datetime(2020, 12, 3, 6, 40),
dt.datetime(2020, 12, 8, 20, 0),
dt.datetime(2020, 12, 14, 9, 20),
dt.datetime(2020, 12, 19, 22, 40),
dt.datetime(2020, 12, 25, 12, 0)], dtype=object,
)
tide_e_8000 = np.array(
[-0.02975027, 0.04146837, -0.02690945, -0.00019223, 0.01624152,
0.0532655 , -0.02140918, -0.05554432, 0.01371739, -0.00516968],
)
tide_n_8000 = np.array(
[-0.01275229, -0.02834036, 0.00886857, -0.03247227, -0.05237735,
-0.00590791, -0.01990448, -0.01964124, -0.04439581, -0.00410378],
)
tide_u_8000 = np.array(
[ 0.16008235, -0.05721991, -0.15654693, -0.00041214, 0.03041098,
0.13082217, -0.1006462 , 0.24870719, -0.02648802, -0.08420228],
)

# calculate
(dt_out,
tide_e,
tide_n,
tide_u) = pysolid.calc_solid_earth_tides_point(lat, lon, dt_obj0, dt_obj1, verbose=False)

# compare
assert all(dt_out[::8000] == dt_out_8000)
assert np.allclose(tide_e[::8000], tide_e_8000)
assert np.allclose(tide_n[::8000], tide_n_8000)
assert np.allclose(tide_u[::8000], tide_u_8000)

# plot
out_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'pic'))
os.makedirs(out_dir, exist_ok=True)
Expand Down

0 comments on commit 101e0a5

Please sign in to comment.