def test_argsel2d(): """Check that function returns correct indices. This compares with previous calculation.""" lon0, lat0 = -95.8, 27.1 assert xroms.argsel2d(ds.lon_rho, ds.lat_rho, lon0, lat0) == (0, 1) assert xroms.argsel2d(ds.lon_psi, ds.lat_psi, lon0, lat0) == (0, 0) assert xroms.argsel2d(ds.lon_u, ds.lat_u, lon0, lat0) == (0, 0) assert xroms.argsel2d(ds.lon_v, ds.lat_v, lon0, lat0) == (0, 1) assert xroms.argsel2d(ds.lon_vert, ds.lat_vert, lon0, lat0) == (1, 1)
def test_argsel2d(): '''Check that function returns correct indices. This compares with previous calculation.''' lon0, lat0 = -95.8, 27.1 assert xroms.argsel2d(grid, lon0, lat0, whichgrid='rho') == (0, 1) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='psi') == (0, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='u') == (0, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='v') == (0, 1) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='vert') == (1, 1)
def test_argsel2d_exact(): """test for exact index.""" lon0, lat0 = -95.928571, 27.166685 # one corner of grid assert xroms.argsel2d(ds.lon_rho, ds.lat_rho, lon0, lat0) == (0, 0) assert xroms.argsel2d(ds.lon_psi, ds.lat_psi, lon0, lat0) == (0, 0) assert xroms.argsel2d(ds.lon_u, ds.lat_u, lon0, lat0) == (1, 0) assert xroms.argsel2d(ds.lon_v, ds.lat_v, lon0, lat0) == (0, 0) assert xroms.argsel2d(ds.lon_vert, ds.lat_vert, lon0, lat0) == (1, 1) lon0, lat0 = -94.071429, 28.333351 # other corner of grid assert xroms.argsel2d(ds.lon_rho, ds.lat_rho, lon0, lat0) == (7, 13) assert xroms.argsel2d(ds.lon_psi, ds.lat_psi, lon0, lat0) == (7, 12) assert xroms.argsel2d(ds.lon_u, ds.lat_u, lon0, lat0) == (8, 12) assert xroms.argsel2d(ds.lon_v, ds.lat_v, lon0, lat0) == (7, 13) assert xroms.argsel2d(ds.lon_vert, ds.lat_vert, lon0, lat0) == (8, 13)
def argsel2d(self, lon0, lat0): """Find the indices of coordinate pair closest to another point. Inputs ------ lon0: float, int Longitude of comparison point. lat0: float, int Latitude of comparison point. Returns ------- Indices in eta, xi of closest location to lon0, lat0. Notes ----- This function uses Great Circle distance to calculate distances assuming longitudes and latitudes as point coordinates. Uses cartopy function `Geodesic`: https://scitools.org.uk/cartopy/docs/latest/cartopy/geodesic.html Example usage ------------- >>> ds.temp.xroms.argsel2d(-96, 27) """ return xroms.argsel2d(self.da.cf["longitude"], self.da.cf["latitude"], lon0, lat0)
def test_argsel2d_exact(): '''test for exact index.''' lon0, lat0 = -95.928571, 27.166685 # one corner of grid assert xroms.argsel2d(grid, lon0, lat0, whichgrid='rho') == (1, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='psi') == (0, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='u') == (1, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='v') == (0, 0) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='vert') == (1, 1) lon0, lat0 = -94.071429, 28.333351 # other corner of grid assert xroms.argsel2d(grid, lon0, lat0, whichgrid='rho') == (8, 13) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='psi') == (7, 12) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='u') == (8, 12) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='v') == (7, 13) assert xroms.argsel2d(grid, lon0, lat0, whichgrid='vert') == (8, 13)
def test_argsel2d(): lon0, lat0 = -94.8, 28.0 testvars = ["salt", "u", "v", "z_w"] for testvar in testvars: inds = ds[testvar].xroms.argsel2d(lon0, lat0) outinds = xroms.argsel2d(ds[testvar].cf["longitude"], ds[testvar].cf["latitude"], lon0, lat0) assert np.allclose(inds, outinds)