def test_earth_relief_fails(): "Make sure earth relief fails for invalid resolutions" resolutions = "1m 1d bla 60d 001m 03".split() resolutions.append(60) for resolution in resolutions: with pytest.raises(GMTInvalidInput): load_earth_relief(resolution=resolution)
def test_earth_relief_invalid_resolution_registration_combination(): """ Test loading earth relief with invalid combination of resolution and registration. """ for resolution, registration in [ ("15s", "gridline"), ("03s", "pixel"), ("01s", "pixel"), ]: with pytest.raises(GMTInvalidInput): load_earth_relief(resolution=resolution, registration=registration)
def test_grdinfo(): """ Make sure grd info works as expected. """ grid = load_earth_relief(registration="gridline") result = grdinfo(grid, L=0, C="n") assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1"
def fixture_dataarray(): """ Load the grid data from the sample earth_relief file. """ return load_earth_relief(registration="gridline").sel(lat=slice(-49, -42), lon=slice( -118, -107))
def fixture_grid(): """ Load the grid data from the sample earth_relief file. """ return load_earth_relief( resolution="01d", region=[-5, 5, -5, 5], registration="pixel" )
def test_earth_relief_30m(): "Test some properties of the earth relief 30m data" data = load_earth_relief(resolution="30m", registration="gridline") assert data.shape == (361, 721) npt.assert_allclose(data.lat, np.arange(-90, 90.5, 0.5)) npt.assert_allclose(data.lon, np.arange(-180, 180.5, 0.5)) npt.assert_allclose(data.min(), -9460.5) npt.assert_allclose(data.max(), 5887.5)
def test_earth_relief_01d(): "Test some properties of the earth relief 01d data" data = load_earth_relief(resolution="01d", registration="gridline") assert data.shape == (181, 361) npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -8592.5) npt.assert_allclose(data.max(), 5559.0)
def fixture_grid(): """ Load the grid data from the sample earth_relief file and set value(s) to NaN. """ grid = load_earth_relief(registration="pixel", region=[-5, 5, -5, 5]) grid[3:5, 3:5] = np.nan grid[5:7, 5:7] = np.inf return grid
def test_earth_relief_01d_with_region(): """ Test loading low-resolution earth relief with 'region'. """ data = load_earth_relief(resolution="01d", region=[-10, 10, -5, 5], registration="gridline") assert data.shape == (11, 21) npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5147) npt.assert_allclose(data.max(), 805.5)
def test_earth_relief_05m_with_region(): "Test loading a subregion of high-resolution earth relief grid" data = load_earth_relief(resolution="05m", region=[120, 160, 30, 60], registration="gridline") assert data.coords["lat"].data.min() == 30.0 assert data.coords["lat"].data.max() == 60.0 assert data.coords["lon"].data.min() == 120.0 assert data.coords["lon"].data.max() == 160.0 assert data.data.min() == -9633.0 assert data.data.max() == 2532.0 assert data.sizes["lat"] == 361 assert data.sizes["lon"] == 481
def test_earth_relief_03s_landonly_srtm(): """ Test loading original 3 arc-second land-only SRTM tiles. """ data = load_earth_relief("03s", region=[135, 136, 35, 36], registration="gridline", use_srtm=True) assert data.coords["lat"].data.min() == 35.0 assert data.coords["lat"].data.max() == 36.0 assert data.coords["lon"].data.min() == 135.0 assert data.coords["lon"].data.max() == 136.0 # data.data.min() == -305.51846 if use_srtm is False. assert data.data.min() == -6.0 assert data.data.max() == 1191.0 assert data.sizes["lat"] == 1201 assert data.sizes["lon"] == 1201
def test_earth_relief_05m_without_region(): """ Test loading high-resolution earth relief without passing 'region'. """ with pytest.raises(GMTInvalidInput): load_earth_relief("05m")
def test_earth_relief_incorrect_registration(): """ Test loading earth relief with incorrect registration type. """ with pytest.raises(GMTInvalidInput): load_earth_relief(registration="improper_type")
def fixture_grid(): "Load the grid data from the sample earth_relief file" return load_earth_relief(registration="gridline")
def fixture_grid(): """ Load the grid data from the sample earth_relief file. """ return load_earth_relief()
def fixture_grid(): """ Load the grid data from the sample earth_relief file. """ return load_earth_relief(resolution="01d", region=[-100, -95, 34, 39])
def fixture_grid(): """ Load the grid data from the sample earth_relief file. """ return load_earth_relief(registration="pixel")
def test_earth_relief_01d_with_region(): "Test loading low-resolution earth relief with 'region'" with pytest.raises(NotImplementedError): load_earth_relief("01d", region=[0, 180, 0, 90])