def test_distances_from_cross_section_given_lonlat(test_cross_lonlat): """Test distances from cross section with lat/lon grid.""" x, y = distances_from_cross_section(test_cross_lonlat['u_wind']) true_x_values = np.array([-0., 252585.3108187, 505170.6216374, 757755.93245611, 1010341.24327481, 1262926.55409352, 1515511.86491222]) true_y_values = np.array([-0., 283412.80349716, 566825.60699432, 850238.41049148, 1133651.21398864, 1417064.0174858, 1700476.82098296]) index = xr.DataArray(range(7), name='index', dims=['index']) true_x = xr.DataArray( true_x_values * units.meters, coords={ 'crs': test_cross_lonlat['crs'], 'lat': test_cross_lonlat['lat'], 'lon': test_cross_lonlat['lon'], 'index': index, }, dims=['index'] ) true_y = xr.DataArray( true_y_values * units.meters, coords={ 'crs': test_cross_lonlat['crs'], 'lat': test_cross_lonlat['lat'], 'lon': test_cross_lonlat['lon'], 'index': index, }, dims=['index'] ) assert_xarray_allclose(x, true_x) assert_xarray_allclose(y, true_y)
def test_distances_from_cross_section_given_lonlat(test_cross_lonlat): """Test distances from cross section with lat/lon grid.""" x, y = distances_from_cross_section(test_cross_lonlat['u_wind']) true_x_values = np.array([-0., 252585.3108187, 505170.6216374, 757755.93245611, 1010341.24327481, 1262926.55409352, 1515511.86491222]) true_y_values = np.array([-0., 283412.80349716, 566825.60699432, 850238.41049148, 1133651.21398864, 1417064.0174858, 1700476.82098296]) index = xr.DataArray(range(7), name='index', dims=['index']) true_x = xr.DataArray( true_x_values, coords={ 'crs': test_cross_lonlat['crs'], 'lat': test_cross_lonlat['lat'], 'lon': test_cross_lonlat['lon'], 'index': index, }, dims=['index'], attrs={'units': 'meters'} ) true_y = xr.DataArray( true_y_values, coords={ 'crs': test_cross_lonlat['crs'], 'lat': test_cross_lonlat['lat'], 'lon': test_cross_lonlat['lon'], 'index': index, }, dims=['index'], attrs={'units': 'meters'} ) assert_xarray_allclose(x, true_x) assert_xarray_allclose(y, true_y)
def test_distances_from_cross_section_given_bad_coords(test_cross_xy): """Ensure an AttributeError is raised when the cross section lacks neeed coordinates.""" with pytest.raises(AttributeError): distances_from_cross_section(test_cross_xy['u_wind'].drop_vars('x'))
def test_distances_from_cross_section_given_xy(test_cross_xy): """Test distances from cross section with x/y grid.""" x, y = distances_from_cross_section(test_cross_xy['u_wind']) xr.testing.assert_identical(test_cross_xy['x'], x) xr.testing.assert_identical(test_cross_xy['y'], y)
def test_distances_from_cross_section_given_bad_coords(test_cross_xy): """Ensure an AttributeError is raised when the cross section lacks neeed coordinates.""" with pytest.raises(AttributeError): distances_from_cross_section(test_cross_xy['u_wind'].drop('x'))