def test_verify_cube(self): cube = new_cube() self.assertEqual([], verify_cube(cube)) ds = cube.drop("time") self.assertEqual(["missing time coordinate variable"], verify_cube(ds)) ds = ds.drop("lat") self.assertEqual(["missing spatial x,y coordinate variables", "missing time coordinate variable"], verify_cube(ds))
def get_type_specifier(data: Any) -> Optional[TypeSpecifier]: if isinstance(data, MultiLevelDataset): if not verify_cube(data.get_dataset(0)): return TYPE_SPECIFIER_MULTILEVEL_CUBE return TYPE_SPECIFIER_MULTILEVEL_DATASET if isinstance(data, xr.Dataset): if not verify_cube(data): return TYPE_SPECIFIER_CUBE return TYPE_SPECIFIER_DATASET if isinstance(data, gpd.GeoDataFrame): return TYPE_SPECIFIER_GEODATAFRAME return None
def test_verify_cube_coord_equidistance_reverse_lat(self): ds = new_cube() ds['lat'] = np.flip(ds.lat) ds['lat_bnds'] = (['lat', 'bnds'], np.flip(ds.lat_bnds)) ds['lon'] = np.roll(ds.lon, 90) ds['lon_bnds'] = (['lon', 'bnds'], np.roll(ds.lon_bnds, 180)) self.assertEqual([], verify_cube(ds))
def test_verify_cube_coord_equidistance(self): ds = new_cube() ds['lat'] = ds['lat'] + np.random.rand(len(ds['lat'])) ds['lat_bnds'][:, 0] = ds['lat_bnds'][:, 0] + np.random.rand(len(ds['lat_bnds'][:, 0])) ds['lat_bnds'][:, 1] = ds['lat_bnds'][:, 1] + np.random.rand(len(ds['lat_bnds'][:, 1])) self.assertEqual(["coordinate variable 'lat' is not equidistant", "coordinate variable 'lat_bnds' is not equidistant"], verify_cube(ds))
def verify(self) -> List[str]: """ Verify that this dataset is a valid xcube dataset. Returns a list of issues, which is empty if this dataset is a valid xcube dataset. :return: List of issues or empty list. """ return verify_cube(self._dataset)
def test_verify_cube_coord_equidistance_reverse_lat(self): ds = new_cube() ds['lat'] = np.flip(ds.lat) ds['lat_bnds'] = xr.DataArray(np.flip(ds.lat_bnds.values), dims=['lat', 'bnds']) ds['lon'] = np.roll(ds.lon, 90) ds['lon_bnds'] = xr.DataArray(np.roll(ds.lon_bnds.values, 180), dims=['lon', 'bnds']) self.assertEqual([], verify_cube(ds))
def _verify(input_path: str = None, monitor=None): from xcube.core.dsio import open_dataset from xcube.core.verify import verify_cube monitor(f'Opening cube from {input_path!r}...') with open_dataset(input_path) as cube: report = verify_cube(cube) if not report: monitor("INPUT is a valid cube.") return monitor('INPUT is not a valid cube due to the following reasons:') monitor('- ' + '\n- '.join(report)) # According to http://tldp.org/LDP/abs/html/exitcodes.html, exit code 3 is not reserved sys.exit(3)