def _process_datasets(output_dir, datasets, checksum): """ Wrapper function for processing multiple datasets """ for dataset in datasets: docs = process_datasets(dataset, Path(str(dataset) + ".xml")) outfile = output_dir / (dataset.stem + ".ga-md.yaml") serialise.dump_yaml(outfile, *docs)
def test_invalid_crs(input_doc_folder: Path): input_metadata_path = input_doc_folder.joinpath(ODC_METADATA_FILE) assert input_metadata_path.exists() input_doc = serialise.load_yaml(input_metadata_path) del input_doc["crs"] serialise.dump_yaml(input_metadata_path, input_doc) assert input_metadata_path.exists() with pytest.raises(RuntimeError) as exp: run_tostac(input_metadata_path) assert (str(exp.value) == "Expect string or any object with " "`.to_epsg()` or `.to_wkt()` method")
def test_add_property(input_doc_folder: Path): input_metadata_path = input_doc_folder.joinpath(ODC_METADATA_FILE) assert input_metadata_path.exists() input_doc = serialise.load_yaml(input_metadata_path) input_doc["properties"]["test"] = "testvalue" serialise.dump_yaml(input_metadata_path, input_doc) assert input_metadata_path.exists() run_tostac(input_metadata_path) name = input_metadata_path.stem.replace(".odc-metadata", "") actual_stac_path = input_metadata_path.with_name(f"{name}.stac-item.json") assert actual_stac_path.exists() actual_doc = json.load(actual_stac_path.open()) assert actual_doc["properties"]["test"] == input_doc["properties"]["test"]
def run_validate(self, docs: Sequence[Doc], suffix=".yaml"): __tracebackhide__ = operator.methodcaller("errisinstance", AssertionError) args = ("-f", "plain") if self.quiet: args += ("-q", ) if self.warnings_are_errors: args += ("-W", ) if self.thorough: args += ("--thorough", ) for i, doc in enumerate(docs): if isinstance(doc, Mapping): md_path = self.tmp_path / f"doc-{i}{suffix}" serialise.dump_yaml(md_path, doc) doc = md_path args += (doc, ) self.result = CliRunner(mix_stderr=False).invoke( validate.run, [str(a) for a in args], catch_exceptions=False)
def _write_yaml(self, doc, path, allow_external_paths=False): documents.make_paths_relative( doc, path.parent, allow_paths_outside_base=allow_external_paths ) serialise.dump_yaml(path, doc) self._checksum.add_file(path)
def l1_ls8_metadata_path(l1_ls8_folder: Path, l1_ls8_dataset: DatasetDoc) -> Path: path = l1_ls8_folder / f"{l1_ls8_dataset.label}.odc-metadata.yaml" serialise.dump_yaml(path, serialise.to_formatted_doc(l1_ls8_dataset)) return path