def _prepared_file(mapchete_config, input_file): """ Returns validated, absolute paths or Mapchete process objects from input files at zoom. """ if not input_file in mapchete_config.prepared_input_files: if not input_file: prepared = { "file": None, "area": None } else: abs_path = os.path.join(mapchete_config.config_dir, input_file) try: # Sentinel-2 datasets can be in directories as well assert os.path.isfile(abs_path) or os.path.isdir(abs_path) except AssertionError: raise IOError("no such file", abs_path) extension = os.path.splitext(abs_path)[1] if extension == ".mapchete": mapchete_process = Mapchete(MapcheteConfig(abs_path)) prepared = { "file": mapchete_process, "area": reproject_geometry( mapchete_process.config.process_area(), mapchete_process.tile_pyramid.crs, mapchete_config.tile_pyramid.crs ) } elif extension in [".SAFE", ".zip", ".ZIP"]: prepared = { "file": _prepare_sentinel2(SentinelDataSet(input_file)), "area": file_bbox(abs_path, mapchete_config.tile_pyramid) } else: prepared = { "file": abs_path, "area": file_bbox(abs_path, mapchete_config.tile_pyramid) } mapchete_config.prepared_input_files[input_file] = prepared return mapchete_config.prepared_input_files[input_file]
def is_empty(self, indexes=None): """ Returns true if all items are masked. """ band_indexes = _get_band_indexes(self, indexes) src_bbox = file_bbox(self.input_file, self.tile_pyramid) tile_geom = self.tile.bbox(pixelbuffer=self.pixelbuffer) # empty if tile does not intersect with file bounding box if not tile_geom.intersects(src_bbox): return True # empty if source band(s) are empty all_bands_empty = True for band in _bands_from_cache(self, band_indexes): if not band.mask.all(): all_bands_empty = False break return all_bands_empty