|
| 1 | +""" |
| 2 | +Test basic functionality for loading IGPP Earth east-west and south-north deflection |
| 3 | +datasets. |
| 4 | +""" |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +import numpy.testing as npt |
| 8 | +from pygmt.datasets import load_earth_deflection |
| 9 | + |
| 10 | + |
| 11 | +def test_earth_edefl_01d(): |
| 12 | + """ |
| 13 | + Test some properties of the Earth east-west deflection 01d data. |
| 14 | + """ |
| 15 | + data = load_earth_deflection(resolution="01d") |
| 16 | + assert data.name == "z" |
| 17 | + assert data.attrs["long_name"] == "edefl (microradians)" |
| 18 | + assert data.attrs["description"] == "IGPP Earth east-west deflection" |
| 19 | + assert data.attrs["units"] == "micro-radians" |
| 20 | + assert data.attrs["horizontal_datum"] == "WGS84" |
| 21 | + assert data.shape == (181, 361) |
| 22 | + assert data.gmt.registration == 0 |
| 23 | + npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) |
| 24 | + npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) |
| 25 | + npt.assert_allclose(data.min(), -142.64, atol=0.04) |
| 26 | + npt.assert_allclose(data.max(), 178.32, atol=0.04) |
| 27 | + |
| 28 | + |
| 29 | +def test_earth_edefl_01d_with_region(): |
| 30 | + """ |
| 31 | + Test loading low-resolution Earth east-west deflection with "region". |
| 32 | + """ |
| 33 | + data = load_earth_deflection(resolution="01d", region=[-10, 10, -5, 5]) |
| 34 | + assert data.shape == (11, 21) |
| 35 | + assert data.gmt.registration == 0 |
| 36 | + npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) |
| 37 | + npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) |
| 38 | + npt.assert_allclose(data.min(), -28.92, atol=0.04) |
| 39 | + npt.assert_allclose(data.max(), 24.72, atol=0.04) |
| 40 | + |
| 41 | + |
| 42 | +def test_earth_edefl_01m_default_registration(): |
| 43 | + """ |
| 44 | + Test that the grid returned by default for the 1 arc-minute resolution has a "pixel" |
| 45 | + registration. |
| 46 | + """ |
| 47 | + data = load_earth_deflection(resolution="01m", region=[-10, -9, 3, 5]) |
| 48 | + assert data.shape == (120, 60) |
| 49 | + assert data.gmt.registration == 1 |
| 50 | + npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) |
| 51 | + npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) |
| 52 | + npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) |
| 53 | + npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333) |
| 54 | + npt.assert_allclose(data.min(), -62.24, atol=0.04) |
| 55 | + npt.assert_allclose(data.max(), 15.52, atol=0.04) |
| 56 | + |
| 57 | + |
| 58 | +def test_earth_ndefl_01d(): |
| 59 | + """ |
| 60 | + Test some properties of the Earth north-south deflection 01d data. |
| 61 | + """ |
| 62 | + data = load_earth_deflection(resolution="01d", component="north") |
| 63 | + assert data.name == "z" |
| 64 | + assert data.attrs["long_name"] == "ndefl (microradians)" |
| 65 | + assert data.attrs["description"] == "IGPP Earth north-south deflection" |
| 66 | + assert data.attrs["units"] == "micro-radians" |
| 67 | + assert data.attrs["horizontal_datum"] == "WGS84" |
| 68 | + assert data.shape == (181, 361) |
| 69 | + assert data.gmt.registration == 0 |
| 70 | + npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) |
| 71 | + npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) |
| 72 | + npt.assert_allclose(data.min(), -214.8, atol=0.04) |
| 73 | + npt.assert_allclose(data.max(), 163.04, atol=0.04) |
| 74 | + |
| 75 | + |
| 76 | +def test_earth_ndefl_01d_with_region(): |
| 77 | + """ |
| 78 | + Test loading low-resolution Earth north-south deflection with "region". |
| 79 | + """ |
| 80 | + data = load_earth_deflection( |
| 81 | + resolution="01d", region=[-10, 10, -5, 5], component="north" |
| 82 | + ) |
| 83 | + assert data.shape == (11, 21) |
| 84 | + assert data.gmt.registration == 0 |
| 85 | + npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) |
| 86 | + npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) |
| 87 | + npt.assert_allclose(data.min(), -48.08, atol=0.04) |
| 88 | + npt.assert_allclose(data.max(), 18.92, atol=0.04) |
| 89 | + |
| 90 | + |
| 91 | +def test_earth_ndefl_01m_default_registration(): |
| 92 | + """ |
| 93 | + Test that the grid returned by default for the 1 arc-minute resolution has a "pixel" |
| 94 | + registration. |
| 95 | + """ |
| 96 | + data = load_earth_deflection( |
| 97 | + resolution="01m", region=[-10, -9, 3, 5], component="north" |
| 98 | + ) |
| 99 | + assert data.shape == (120, 60) |
| 100 | + assert data.gmt.registration == 1 |
| 101 | + npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) |
| 102 | + npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) |
| 103 | + npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) |
| 104 | + npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333) |
| 105 | + npt.assert_allclose(data.min(), -107.04, atol=0.04) |
| 106 | + npt.assert_allclose(data.max(), 20.28, atol=0.04) |
0 commit comments