def test_is_eo3(sample_doc, sample_doc_180): identity = list(Affine.translation(0, 0)) assert is_doc_eo3(sample_doc) is True assert is_doc_eo3(sample_doc_180) is True # If there's no schema field at all, it's treated as legacy eo. assert is_doc_eo3({}) is False assert is_doc_eo3({'crs': 'EPSG:4326'}) is False assert is_doc_eo3({'crs': 'EPSG:4326', 'grids': {}}) is False with pytest.raises(ValueError, match="Unsupported dataset schema.*"): is_doc_eo3({'$schema': 'https://schemas.opendatacube.org/eo4'})
def get_dataset_file_offsets(dataset: Dataset) -> Dict[str, str]: """ Get (usually relative) paths for all known files of a dataset. Returns {name, url} """ # Get paths to measurements (usually relative, but may not be) uri_list = { name: m["path"] for name, m in dataset.measurements.items() if m.get("path") } # Add accessories too, if possible if is_doc_eo3(dataset.metadata_doc): dataset_doc = serialise.from_doc(dataset.metadata_doc, skip_validation=True) uri_list.update( {name: a.path for name, a in dataset_doc.accessories.items()}) return uri_list
def prepare_dataset_formatting( dataset: Dataset, include_source_url=False, include_locations=False, ) -> CommentedMap: """ Try to format a raw Dataset document for readability. This will change property order, add comments on the type & source url. """ doc = dict(dataset.metadata_doc) # If it's EO3, use eodatasets's formatting. It's better. if is_doc_eo3(doc): if include_locations: if len(dataset.uris) == 1: doc["location"] = dataset.uris[0] else: doc["locations"] = dataset.uris doc = eodatasets3.serialise.prepare_formatting(doc) if include_source_url: doc.yaml_set_comment_before_after_key( "$schema", before=f"url: {flask.request.url}", ) # Strip EO-legacy fields. undo_eo3_compatibility(doc) return doc else: return prepare_document_formatting( doc, # Label old-style datasets as old-style datasets. doc_friendly_label="EO1 Dataset", include_source_url=include_source_url, )