Skip to content

Commit

Permalink
Merge branch 'main' into fix/xr_image_fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Jan 8, 2024
2 parents 64cd663 + b31671e commit b80652f
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 55 deletions.
1 change: 1 addition & 0 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
np.float64: "GMT_DOUBLE",
np.str_: "GMT_TEXT",
np.datetime64: "GMT_DATETIME",
np.timedelta64: "GMT_LONG",
}

# Load the GMT library outside the Session class to avoid repeated loading.
Expand Down
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 3cf01816fa5dd3fbc1adc602557bb032
size: 6187
- md5: a0c8f76cac48621f24a14b2c6fa26d09
size: 6260
path: test_basemap.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_compass.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 0dc332834d1c765b51d93f1a4f7254e8
size: 71151
- md5: 3e0d9c5fbedf71d7bb0315797e7d0493
size: 71791
path: test_basemap_compass.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_loglog.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 37c36d4fa4524260ea43c6757a3140a1
size: 24475
- md5: 01ea1c00700565057596c12d18c7146d
size: 24551
path: test_basemap_loglog.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_map_scale.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: e88925c5053369eb516757ec963d691d
size: 31044
- md5: 0660d501d81ef890a9cf94bd92e0673e
size: 31423
path: test_basemap_map_scale.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_polar.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: ded4dba2d1c780b85f256eaad2e268f5
size: 31886
- md5: e4bc1a90f4f25220fe759cdb0a709db8
size: 31915
path: test_basemap_polar.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_power_axis.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: d42769c9b2a802788ac3b3fd0c193c26
size: 16446
- md5: f3151c1afe508404fc9c2cafcd34535d
size: 16272
path: test_basemap_power_axis.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_rose.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: f14e2aaafe4667b2dc06ad1684f7a7ee
size: 32442
- md5: 86acd995f29f961bdf86afc22e2afff6
size: 32873
path: test_basemap_rose.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_subplot.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 1b4ae53658eec125ebf8ab4eac78d729
size: 8733
- md5: d7049472c881d3a567e8e583b6ff54e1
size: 8752
path: test_basemap_subplot.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_utm_projection.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 05267ec2d3c26463c79603a2527cc5a9
size: 9070
- md5: 5ac71f946749a8c4786416d780ba9ccf
size: 9719
path: test_basemap_utm_projection.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_basemap_winkel_tripel.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 128e58b420ec614da56fd273c4f4c1ea
size: 62767
- md5: 23ae073b94dd213d02dc689fb867c230
size: 62561
path: test_basemap_winkel_tripel.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_coast_dcw_list.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: f2b5e260c880ee65c1da003715a48985
size: 89438
- md5: 8ba6d6b9f0b7771fb78fcf5544a4aa42
size: 89807
path: test_coast_dcw_list.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_coast_dcw_single.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 4ac010bb7791c4d972fdf7d22deef73f
size: 79609
- md5: a170637bdd47946399013fba43098f98
size: 80182
path: test_coast_dcw_single.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_coast_region.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 211a3f5d1a3f84db2ca592f501d9066b
size: 77711
- md5: 86bee0e5c92b6d5813cb8fac55ec6593
size: 77964
path: test_coast_region.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_coast_world_mercator.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 2b78b937f6d799908bd9425b332d2244
size: 114193
- md5: 9d4b8ad917870dacd0cbbb06da6cc765
size: 115070
path: test_coast_world_mercator.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_meca_dict_offset_eventname.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 67decf4bcb2cf5cd15152e937c709858
size: 11364
- md5: 3ec9fb5ea39e00552b26116d0275ed66
size: 11328
path: test_meca_dict_offset_eventname.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_meca_eventname.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 81203f9e3a43ec235cf4b5068f928b56
size: 10689
- md5: 6d8b48d9c7ddc07923f6c04e7aeed6e2
size: 10600
path: test_meca_eventname.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_meca_offset.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 6f800af07e13d59e4927b499cf3d035e
size: 10027
- md5: a7c9e10a59030c98581d91c6e92a9f35
size: 9988
path: test_meca_offset.png
hash: md5
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 1469301865b97d4a95bdc26a89ae7df5
size: 13936
- md5: 3ce57fca619482344cd1f4c55c4004d3
size: 13904
path: test_meca_spec_multiple_focalmecha.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_meca_spec_single_focalmecha.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: fc7c271049fc8583914b508c4bee08fe
size: 9830
- md5: 48cfe4ad779d7694b4b4743320b30b61
size: 9902
path: test_meca_spec_single_focalmecha.png
hash: md5
5 changes: 5 additions & 0 deletions pygmt/tests/baseline/test_plot_timedelta64.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
outs:
- md5: 8edddcec764d244053c4d675e98732b9
size: 13201
path: test_plot_timedelta64.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_2d_array_multiple.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 3671f1aaf04909fb5e8b1ee672b4744c
size: 36648
- md5: bf8a48349d1af0029dce3f21dd740fbe
size: 36599
path: test_rose_2d_array_multiple.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_2d_array_single.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 6e32468355cb1582b584fff989ecce58
size: 34730
- md5: 0e8aceb803dab08caac392a6dd1cf997
size: 34355
path: test_rose_2d_array_single.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_bools.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 8757835301c781f1309113b21d4f94b3
size: 59516
- md5: 1e12ca9c45c0ab27621f7455318855d7
size: 59907
path: test_rose_bools.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_data_file.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: c01637915fe1fd8c36150dfa9ee974f8
size: 32114
- md5: d3f789296b8b43457897af84511dcef4
size: 31827
path: test_rose_data_file.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_no_sectors.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: ce2d5cd1415b7c7bbeea5bf6ff39c480
size: 150288
- md5: 470dcb51dfb1573827803730cb3c4005
size: 150500
path: test_rose_no_sectors.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_plot_data_using_cpt.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 42314fb23e4a6002e38812f66b316825
size: 39249
- md5: cfbe8a6396e10461fb8f2bb7c0de8112
size: 38924
path: test_rose_plot_data_using_cpt.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_rose_plot_with_transparency.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 8d8adbe565623420f7211ecd97b02db2
size: 58333
- md5: 991da190e85635e2b9bf6d38bcf7ae61
size: 58215
path: test_rose_plot_with_transparency.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_timestamp_offset.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: be0021731b881e32e3d8a46d6fa8abc3
size: 9450
- md5: c9274f7984b0c3f7228dd758d45d93b6
size: 12286
path: test_timestamp_offset.png
hash: md5
31 changes: 31 additions & 0 deletions pygmt/tests/test_clib_put_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,37 @@ def test_put_vector_string_dtype():
npt.assert_array_equal(output["y"], expected_vectors[j])


def test_put_vector_timedelta64_dtype():
"""
Passing timedelta64 type vectors with various time units (year, month,
week, day, hour, minute, second, millisecond, microsecond) to a dataset.
"""
for unit in ["Y", "M", "W", "D", "h", "m", "s", "ms", "μs"]:
with clib.Session() as lib, GMTTempFile() as tmp_file:
dataset = lib.create_data(
family="GMT_IS_DATASET|GMT_VIA_VECTOR",
geometry="GMT_IS_POINT",
mode="GMT_CONTAINER_ONLY",
dim=[1, 5, 1, 0], # columns, rows, layers, dtype
)
timedata = np.arange(np.timedelta64(0, unit), np.timedelta64(5, unit))
lib.put_vector(dataset, column=0, vector=timedata)
# Turns out wesn doesn't matter for Datasets
wesn = [0] * 6
# Save the data to a file to see if it's being accessed correctly
lib.write_data(
family="GMT_IS_VECTOR",
geometry="GMT_IS_POINT",
mode="GMT_WRITE_SET",
wesn=wesn,
output=tmp_file.name,
data=dataset,
)
# Load the data and check that it's correct
newtimedata = tmp_file.loadtxt(unpack=True, dtype=f"timedelta64[{unit}]")
npt.assert_equal(actual=newtimedata, desired=timedata)


def test_put_vector_invalid_dtype():
"""
Check that it fails with an exception for invalid data types.
Expand Down
20 changes: 20 additions & 0 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,26 @@ def test_plot_datetime():
return fig


@pytest.mark.mpl_image_compare
def test_plot_timedelta64():
"""
Test plotting numpy.timedelta64 input data.
"""
fig = Figure()
fig.basemap(
projection="X8c/5c",
region=[0, 8, 0, 10],
frame=["WSne", "xaf+lForecast Days", "yaf+lRMSE"],
)
fig.plot(
x=np.arange(np.timedelta64(0, "D"), np.timedelta64(8, "D")),
y=np.geomspace(start=0.1, stop=9, num=8),
style="c0.2c",
pen="1p",
)
return fig


@pytest.mark.mpl_image_compare(
filename="test_plot_ogrgmt_file_multipoint_default_style.png"
)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_timestamp_offset():
"""
fig = Figure()
fig.basemap(projection="X10c/5c", region=[0, 10, 0, 5], frame="g1")
for offset in ["1c", "1c/2c", ("1c", "3c")]:
for offset in ["1c", "1c/2c", ("1c", "3c"), 4, (4, 1)]:
fig.timestamp(offset=offset, timefmt=f"offset={offset}")
return fig

Expand Down

0 comments on commit b80652f

Please sign in to comment.