From 2e90a7cfc8ac23267f99a70903fa85a2bfd5e871 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 24 Jun 2024 11:39:08 +0800 Subject: [PATCH 1/2] add unit test with numeric comparison + tests.grid/point.py: add numeric comparison between the calcualted results and the hardcored numpy array + pyproject.toml: revert back to the simple readme under [project], attempt to fix the `long_description` syntax error while uploading to PyPI [without understanding the logic behind] --- pyproject.toml | 6 +++--- tests/grid.py | 33 +++++++++++++++++++++++++++++++++ tests/point.py | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b1454bc..30a90ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ authors = [ {name="Zhang Yunjun", email="yunjunz@outlook.com"}, {name="Dennis Milbert"}, ] +readme = "README.md" requires-python = ">=3.8" keywords = ["solid Earth tides", "deformation", "geodesy", "geophysics"] @@ -25,7 +26,7 @@ classifiers = [ # see section: setuptools_scm # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata # dependencies will be read from text files -dynamic = ["version", "readme", "dependencies", "optional-dependencies"] +dynamic = ["version", "dependencies", "optional-dependencies"] [project.urls] "Homepage" = "https://github.com/insarlab/PySolid" @@ -36,8 +37,7 @@ include-package-data = true zip-safe = false [tool.setuptools.dynamic] -dependencies = { file = ["requirements.txt"] } -readme = { file = ["README.md"], content-type = "text/markdown" } +dependencies = {file = ["requirements.txt"]} # extra requirements: `pip install pysolid[docs]` or `pip install .[docs,test]` # note: the [docs] syntax requires setuptools>=64.0, thus, not working yet. diff --git a/tests/grid.py b/tests/grid.py index f6e6f1b..35e92c9 100755 --- a/tests/grid.py +++ b/tests/grid.py @@ -7,6 +7,8 @@ import sys import datetime as dt +import numpy as np + import pysolid @@ -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) diff --git a/tests/point.py b/tests/point.py index 231b716..d17686d 100755 --- a/tests/point.py +++ b/tests/point.py @@ -7,6 +7,8 @@ import sys import datetime as dt +import numpy as np + import pysolid @@ -18,8 +20,37 @@ # 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, @@ -27,6 +58,12 @@ 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) From 1ffd7aa79557b0cd94a1c0f95125aa8bdb617492 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 24 Jun 2024 15:02:44 +0800 Subject: [PATCH 2/2] Update pyproject.toml --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 30a90ec..3353df7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ authors = [ {name="Zhang Yunjun", email="yunjunz@outlook.com"}, {name="Dennis Milbert"}, ] -readme = "README.md" requires-python = ">=3.8" keywords = ["solid Earth tides", "deformation", "geodesy", "geophysics"] @@ -26,7 +25,7 @@ classifiers = [ # see section: setuptools_scm # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata # dependencies will be read from text files -dynamic = ["version", "dependencies", "optional-dependencies"] +dynamic = ["version", "readme", "dependencies", "optional-dependencies"] [project.urls] "Homepage" = "https://github.com/insarlab/PySolid" @@ -37,7 +36,8 @@ include-package-data = true zip-safe = false [tool.setuptools.dynamic] -dependencies = {file = ["requirements.txt"]} +dependencies = { file = ["requirements.txt"] } +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.