def test_count(): cfg = get_config() lyr = list(cfg.product_index.values())[0] with cube() as dc: count = mv_search_datasets(dc.index, MVSelectOpts.COUNT, layer=lyr) ids = mv_search_datasets(dc.index, MVSelectOpts.IDS, layer=lyr) assert len(ids) == count
def subsets( self, space=SpaceRequestType.CENTRAL_SUBSET_FOR_TIMES, time=TimeRequestTypes.LAST, ): ext_times = time.slice(self.layer.ranges["times"]) search_times = [self.layer.search_times(t) for t in ext_times] with cube() as dc: if space.needs_full_extent() and not self.full_extent: self.full_extent = mv_search_datasets(dc.index, layer=self.layer, sel=MVSelectOpts.EXTENT) if space.needs_time_extent(): time_extent = mv_search_datasets( dc.index, layer=self.layer, sel=MVSelectOpts.EXTENT, times=search_times, ) else: time_extent = None extent = space.subset(time_extent, self.full_extent) return extent, ext_times
def test_datasets(): cfg = get_config() lyr = list(cfg.product_index.values())[0] with cube() as dc: dss = mv_search_datasets(dc.index, MVSelectOpts.DATASETS, layer=lyr) ids = mv_search_datasets(dc.index, MVSelectOpts.IDS, layer=lyr) assert len(ids) == len(dss) for ds in dss: assert str(ds.id) in ids
def datasets(self, index, mask=False, all_time=False, point=None, mode=MVSelectOpts.DATASETS): # Return datasets as a time-grouped xarray DataArray. (or None if no datasets) # No PQ product, so no PQ datasets. if not self._product.pq_name and mask: return None if point: geom = point else: geom = self._geobox.extent if all_time: times = None else: times = self._times result = mv_search_datasets(index, mode, layer=self._product, times=times, geom=geom, mask=mask) if mode == MVSelectOpts.DATASETS: return datacube.Datacube.group_datasets(result, self.group_by) else: return result
def test_extent_and_spatial(): cfg = get_config() lyr = list(cfg.product_index.values())[0] layer_ext_bbx = ( lyr.bboxes["EPSG:4326"]["left"], lyr.bboxes["EPSG:4326"]["bottom"], lyr.bboxes["EPSG:4326"]["right"], lyr.bboxes["EPSG:4326"]["top"], ) small_bbox = pytest.helpers.enclosed_bbox(layer_ext_bbx) layer_ext_geom = box( layer_ext_bbx[0], layer_ext_bbx[1], layer_ext_bbx[2], layer_ext_bbx[3], "EPSG:4326", ) small_geom = box(small_bbox[0], small_bbox[1], small_bbox[2], small_bbox[3], "EPSG:4326") with cube() as dc: all_ext = mv_search_datasets(dc.index, MVSelectOpts.EXTENT, geom=layer_ext_geom, layer=lyr) small_ext = mv_search_datasets(dc.index, MVSelectOpts.EXTENT, geom=small_geom, layer=lyr) assert layer_ext_geom.contains(all_ext) assert small_geom.contains(small_ext) assert all_ext.contains(small_ext) assert small_ext.area < all_ext.area all_count = mv_search_datasets(dc.index, MVSelectOpts.COUNT, geom=layer_ext_geom, layer=lyr) small_count = mv_search_datasets(dc.index, MVSelectOpts.COUNT, geom=small_geom, layer=lyr) assert small_count <= all_count
def test_time_search(): cfg = get_config() lyr = list(cfg.product_index.values())[0] time = lyr.ranges["times"][-1] geom = box(lyr.bboxes["EPSG:4326"]["bottom"], lyr.bboxes["EPSG:4326"]["left"], lyr.bboxes["EPSG:4326"]["top"], lyr.bboxes["EPSG:4326"]["right"], "EPSG:4326") time_rng = local_solar_date_range(MockGeobox(geom), time) with cube() as dc: sel = mv_search_datasets(dc.index, MVSelectOpts.COUNT, times=[time_rng], layer=lyr) assert sel > 0
def test_full_layer(): cfg = get_config() lyr = list(cfg.product_index.values())[0] with cube() as dc: sel = mv_search_datasets(dc.index, MVSelectOpts.COUNT, layer=lyr) assert sel > 0