Esempio n. 1
0
def test_interpolation_tables_agree_anywhere_for_dbarclays_data():
    # load data and initialize interpolator
    path = path_to_assets + '/BathyData_Mariana_500kmx500km.mat'
    bathy, lat, lon = load_data_from_file(path,
                                          lat_name='latgrat',
                                          lon_name='longrat',
                                          val_name='mat',
                                          lon_axis=0)
    ip = Interpolator2D(bathy, lat, lon)

    # --- at origo ---
    lat_c = ip.origin[0]
    lon_c = ip.origin[1]
    z_ll = ip.interp(lat=lat_c, lon=lon_c)  # interpolate using lat-lon
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=0, y=0)  # interpolate using x-y
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1E-3) or z_ll == pytest.approx(
        z_xy, abs=0.1)

    # --- at shifted origo ---
    bathy, lat, lon = load_data_from_file(path,
                                          lat_name='latgrat',
                                          lon_name='longrat',
                                          val_name='mat',
                                          lon_axis=0)
    ip = Interpolator2D(bathy, lat, lon, origin=(9., 140.))
    lat_c = ip.origin[0]
    lon_c = ip.origin[1]
    z_ll = ip.interp(lat=lat_c, lon=lon_c)  # interpolate using lat-lon
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=0, y=0)  # interpolate using x-y
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1E-3) or z_ll == pytest.approx(
        z_xy, abs=0.1)
Esempio n. 2
0
def test_interpolation_tables_agree_anywhere():
    # load data and initialize interpolator
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon)

    # --- at origo ---
    lat_c, lon_c = center_point(lat, lon)
    #lat_c = ip.origin.latitude
    #lon_c = ip.origin.longitude
    z_ll = ip.interp(lat=lat_c, lon=lon_c)  # interpolate using lat-lon
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=0, y=0)  # interpolate using x-y
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1e-3) or z_xy == pytest.approx(
        z_ll, abs=0.1)

    # --- 0.1 degrees north of origo ---
    lat = lat_c + 0.1
    lon = lon_c
    x, y = LLtoXY(lat=lat, lon=lon, lat_ref=lat_c, lon_ref=lon_c)
    z_ll = ip.interp(lat=lat, lon=lon)
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=x, y=y)
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1e-3) or z_xy == pytest.approx(
        z_ll, abs=0.1)

    # --- 0.08 degrees south of origo ---
    lat = lat_c - 0.08
    lon = lon_c
    x, y = LLtoXY(lat=lat, lon=lon, lat_ref=lat_c, lon_ref=lon_c)
    z_ll = ip.interp(lat=lat, lon=lon)
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=x, y=y)
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1e-3) or z_xy == pytest.approx(
        z_ll, abs=0.1)

    # --- at shifted origo ---
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon, origin=(55.30, 15.10))
    lat_c = ip.origin[0]
    lon_c = ip.origin[1]
    z_ll = ip.interp(lat=lat_c, lon=lon_c)  # interpolate using lat-lon
    z_ll = float(z_ll)
    z_xy = ip.interp_xy(x=0, y=0)  # interpolate using x-y
    z_xy = float(z_xy)
    assert z_ll == pytest.approx(z_xy, rel=1e-3) or z_xy == pytest.approx(
        z_ll, abs=0.1)
Esempio n. 3
0
def test_interpolation_tables_agree_on_ll_grid_for_dbarclays_data():
    # load data and initialize interpolator
    path = path_to_assets + '/BathyData_Mariana_500kmx500km.mat'
    bathy, lat, lon = load_data_from_file(path,
                                          lat_name='latgrat',
                                          lon_name='longrat',
                                          val_name='mat',
                                          lon_axis=0)
    ip = Interpolator2D(bathy, lat, lon)

    # lat fixed
    ilat = int(len(ip.lat_nodes) / 2)
    lat = ip.lat_nodes[ilat]
    for lon in ip.lon_nodes:
        bll = ip.interp(lat=lat, lon=lon)
        x, y = LLtoXY(lat=lat,
                      lon=lon,
                      lat_ref=ip.origin[0],
                      lon_ref=ip.origin[1])
        bxy = ip.interp_xy(x=x, y=y)
        assert bxy == pytest.approx(bll, rel=1e-3) or bxy == pytest.approx(
            bll, abs=0.1)

    # lon fixed
    ilon = int(len(ip.lon_nodes) / 2)
    lon = ip.lon_nodes[ilon]
    for lat in ip.lat_nodes:
        bll = ip.interp(lat=lat, lon=lon)
        x, y = LLtoXY(lat=lat,
                      lon=lon,
                      lat_ref=ip.origin[0],
                      lon_ref=ip.origin[1])
        bxy = ip.interp_xy(x=x, y=y)
        assert bxy == pytest.approx(bll, rel=1e-3) or bxy == pytest.approx(
            bll, abs=0.1)
Esempio n. 4
0
def test_interpolation_tables_agree_on_latlon_grid():
    # load data and initialize interpolator
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon)

    # lat fixed
    ilat = int(len(ip.lat_nodes) / 2)
    lat = ip.lat_nodes[ilat]
    for lon in ip.lon_nodes:
        bll = ip.interp(lat=lat, lon=lon)
        #x, y = LLtoXY(lat=lat, lon=lon, lat_ref=ip.origin.latitude, lon_ref=ip.origin.longitude)
        x, y = LLtoXY(lat=lat,
                      lon=lon,
                      lat_ref=ip.origin[0],
                      lon_ref=ip.origin[1])
        bxy = ip.interp_xy(x=x, y=y)
        assert bxy == pytest.approx(bll, rel=1e-3) or bxy == pytest.approx(
            bll, abs=0.1)

    # lon fixed
    ilon = int(len(ip.lon_nodes) / 2)
    lon = ip.lon_nodes[ilon]
    for lat in ip.lat_nodes:
        bll = ip.interp(lat=lat, lon=lon)
        x, y = LLtoXY(lat=lat,
                      lon=lon,
                      lat_ref=ip.origin[0],
                      lon_ref=ip.origin[1])
        bxy = ip.interp_xy(x=x, y=y)
        assert bxy == pytest.approx(bll, rel=1e-3) or bxy == pytest.approx(
            bll, abs=0.1)
Esempio n. 5
0
def test_interpolation_grids_are_what_they_should_be():
    # load data and initialize interpolator
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon)
    lat_c = 0.5 * (lat[0] + lat[-1])
    lon_c = 0.5 * (lon[0] + lon[-1])
    assert lat_c, lon_c == center_point(lat, lon)
Esempio n. 6
0
def test_mariana_trench_is_in_correct_location():
    # load data and initialize interpolator
    path = path_to_assets + '/BathyData_Mariana_500kmx500km.mat'
    bathy, lat, lon = load_data_from_file(path,
                                          lat_name='latgrat',
                                          lon_name='longrat',
                                          val_name='mat',
                                          lon_axis=0)
    ip = Interpolator2D(bathy, lat, lon)
    d = ip.interp(lat=11.3733, lon=142.5917)
    assert d < -10770
    d = ip.interp(lat=12.0, lon=142.4)
    assert d > -3000
    d = ip.interp(lat=11.4, lon=143.1)
    assert d < -9000
Esempio n. 7
0
def test_interpolate_bathymetry_using_latlon_coordinates():

    # load bathy data
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)

    # initialize interpolator
    ip = Interpolator2D(bathy, lat, lon)

    # interpolate at a single point on the grid
    z = ip.interp(lat=lat[0], lon=lon[0])
    z = int(z)
    assert z == bathy[0, 0]

    # interpolate at a single point between two grid points
    x = (lat[1] + lat[2]) / 2
    z = ip.interp(lat=x, lon=lon[0])
    z = float(z)
    zmin = min(bathy[1, 0], bathy[2, 0])
    zmax = max(bathy[1, 0], bathy[2, 0])
    assert z >= zmin
    assert z <= zmax

    # interpolate at two points
    x1 = (lat[1] + lat[2]) / 2
    x2 = (lat[2] + lat[3]) / 2
    z = ip.interp(lat=[x1, x2], lon=lon[0])
    zmin = min(bathy[1, 0], bathy[2, 0])
    zmax = max(bathy[1, 0], bathy[2, 0])
    assert z[0] >= zmin
    assert z[0] <= zmax
    zmin = min(bathy[2, 0], bathy[3, 0])
    zmax = max(bathy[2, 0], bathy[3, 0])
    assert z[1] >= zmin
    assert z[1] <= zmax

    # interpolate with grid = True/False
    x1 = (lat[1] + lat[2]) / 2
    x2 = (lat[2] + lat[3]) / 2
    y1 = (lon[1] + lon[2]) / 2
    y2 = (lon[2] + lon[3]) / 2
    z = ip.interp(lat=[x1, x2], lon=[y1, y2], grid=False)
    assert np.ndim(z) == 1
    assert z.shape[0] == 2
    z = ip.interp(lat=[x1, x2], lon=[y1, y2], grid=True)
    assert np.ndim(z) == 2
    assert z.shape[0] == 2
    assert z.shape[1] == 2
Esempio n. 8
0
def test_can_interpolate_multiple_points_in_xx():
    # load data and initialize interpolator
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon)
    # --- 4 x coordinates ---
    xs = [0, 1000, -2000, 300]
    # --- 4 y coordinates ---
    ys = [0, 1500, 800, -120]
    # interpolate
    depths = ip.interp_xy(x=xs, y=ys)
    zi = list()
    for x, y in zip(xs, ys):
        zi.append(ip.interp_xy(x=x, y=y))
    for z, d in zip(zi, depths):
        assert z == pytest.approx(d, rel=1e-3)
Esempio n. 9
0
def test_can_interpolate_multiple_points_in_ll():
    # load data and initialize interpolator
    path = path_to_assets + '/bornholm.mat'
    bathy, lat, lon = load_data_from_file(path)
    ip = Interpolator2D(bathy, lat, lon)
    # coordinates of origin
    lat_c = ip.origin[0]
    lon_c = ip.origin[1]
    # --- 4 latitudes ---
    lats = [lat_c, lat_c + 0.1, lat_c - 0.2, lat_c + 0.03]
    # --- 4 longitudes ---
    lons = [lon_c, lon_c + 0.15, lon_c - 0.08, lon_c - 0.12]
    # interpolate
    depths = ip.interp(lat=lats, lon=lons)
    zi = list()
    for lat, lon in zip(lats, lons):
        zi.append(ip.interp(lat=lat, lon=lon))
    for z, d in zip(zi, depths):
        assert z == pytest.approx(d, rel=1e-3)