diff --git a/pyproject.toml b/pyproject.toml index dcdb8b7..e819ab6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,6 +91,7 @@ dependencies = [ "w3lib", "typing-extensions>=4.12.0", "StrEnum>=0.4.0", + "numpy", ] dynamic = ["version"] @@ -103,7 +104,6 @@ dev = [ "tox", "build", "ruff", - "numpy", ] [project.urls] diff --git a/src/czml3/examples/simple.py b/src/czml3/examples/simple.py index 46c9fde..453b8f6 100644 --- a/src/czml3/examples/simple.py +++ b/src/czml3/examples/simple.py @@ -693,7 +693,7 @@ -5993978.3578334, 3085604.46208182, -2127529.51573296, - 37792.10937600001, + 37792.0, -6130101.19290489, 3515932.23049969, 9264.18885075031, @@ -1177,7 +1177,7 @@ -6161212.76191318, 3460356.43482851, -87207.9167899129, - 73212.755328, + 73212.0, -6154907.45142338, 3472367.94593854, 7596.60346604248, @@ -1341,7 +1341,7 @@ -6177229.98169397, 3320382.63185734, -879217.258095039, - 85019.62118399999, + 85019.0, -6162999.06701901, 3457830.12375349, 7561.5554257676, diff --git a/src/czml3/types.py b/src/czml3/types.py index 0601e21..de21723 100644 --- a/src/czml3/types.py +++ b/src/czml3/types.py @@ -3,6 +3,7 @@ import sys from typing import Any +import numpy as np from dateutil.parser import isoparse as parse_iso_date from pydantic import ( Field, @@ -81,6 +82,8 @@ def check_values(num_points: int, values: list[Any]): raise TypeError( f"Input values must have either {num_points} or N * {num_points + 1} values, where N is the number of time-tagged samples." ) + if len(values) % (num_points + 1) == 0 and np.any(np.diff(values[::4]) <= 0): + raise TypeError("Time values must be increasing.") def check_reference(r): diff --git a/tests/simple.czml b/tests/simple.czml index 095f156..6e24b9d 100644 --- a/tests/simple.czml +++ b/tests/simple.czml @@ -810,7 +810,7 @@ 36900,-3994146.68251508,1353941.93189576,-5674612.94646658, 37200,-5258447.49803637,2337295.48282856,-4108116.98999385, 37500,-5993978.3578334,3085604.46208182,-2127529.51573296, - 37792.10937600001,-6130101.19290489,3515932.23049969,9264.18885075031, + 37792.0,-6130101.19290489,3515932.23049969,9264.18885075031, 37792.10937600001,-6130384.46590958,3515584.20899647,6695.95297313175, 37800,-6125874.41162028,3522668.06783492,65343.2925253213, 38100,-5639991.96555162,3604984.9649137,2253983.5554605, @@ -931,7 +931,7 @@ 72600,-5202391.35629523,2238791.87144665,-4232583.77922341, 72900,-5983183.28985049,3000731.20227799,-2274741.09719522, 73200,-6161212.76191318,3460356.43482851,-87207.9167899129, - 73212.755328,-6154907.45142338,3472367.94593854,7596.60346604248, + 73212.0,-6154907.45142338,3472367.94593854,7596.60346604248, 73212.755328,-6154869.70054271,3472314.27813954,7580.8794079691, 73500,-5717448.81578568,3570745.1629146,2109098.31104496, 73800,-4696169.83114091,3320482.84120077,4091785.03705666, @@ -972,7 +972,7 @@ 84300,-4796522.04551855,1896876.29005214,-4836079.84361999, 84600,-5777706.24779571,2746906.16140639,-3009492.61314694, 84900,-6177229.98169397,3320382.63185734,-879217.258095039, - 85019.62118399999,-6162999.06701901,3457830.12375349,7561.5554257676, + 85019.0,-6162999.06701901,3457830.12375349,7561.5554257676, 85019.62118399999,-6162974.43645965,3457855.60563033,7854.92641443949, 85200,-5953637.85681474,3558954.7436216,1340197.97209599, 85500,-5128782.17352735,3438064.29435161,3423588.54273433, diff --git a/tests/test_properties.py b/tests/test_properties.py index c91c61d..2a18569 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1648,3 +1648,8 @@ def test_position_list_of_lists_with_bad_references(): values=[["1#this"], ["1#this", "2#this"]] ), ) + + +def test_check_increasing_time(): + with pytest.raises(TypeError): + Cartesian3Value(values=[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])