diff --git a/CHANGELOG.md b/CHANGELOG.md index e910ca5..55661bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Support multi-point searches ([#72](https://github.com/nasa/python_cmr/issues/72)) - Support `processing_level_id` in `CollectionQuery` ([#76](https://github.com/nasa/python_cmr/issues/76)) - Support `platform` in `CollectionQuery` ([#77](https://github.com/nasa/python_cmr/issues/77)) +- Support searching by instance format for `VariableQuery` ([#59]https://github.com/nasa/python_cmr/issues/59) ### Fixed - Setup vcrpy for new `revision_date` unit tests ([#70](https://github.com/nasa/python_cmr/issues/70)) diff --git a/README.md b/README.md index b014f2f..0b9bd03 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,9 @@ api.name('/AMR_Side_1/acc_lat') # Search via concept_id api.concept_id('V2112019824-POCLOUD') + +# Search via instance format +query.instance_format(["zarr", "kerchunk"]) ``` As an alternative to chaining methods together to set the parameters of your query, a method exists to allow you to pass diff --git a/cmr/queries.py b/cmr/queries.py index 4c1487f..df5cd6c 100644 --- a/cmr/queries.py +++ b/cmr/queries.py @@ -1210,6 +1210,21 @@ def __init__(self, mode: str = CMR_OPS): "dif", "dif10", "opendata", "umm_json", "umm_json_v[0-9]_[0-9]" ]) + def instance_format(self, format: Union[str, Sequence[str]]) -> Self: + """ + Filter by instance format(s), matching any one of the specified formats. + Does nothing if `format` is an empty string or an empty sequence. + + :param format: format(s) for variable instance (a single string, or sequence of + strings) + :returns: self + """ + + if format: + # Assume we have non-empty string or sequence of strings (list, tuple, etc.) + self.params['instance_format'] = [format] if isinstance(format, str) else format + + return self @override def _valid_state(self) -> bool: return True diff --git a/tests/test_variable.py b/tests/test_variable.py index ca6963a..cf9fc15 100644 --- a/tests/test_variable.py +++ b/tests/test_variable.py @@ -85,3 +85,17 @@ def bearer_test_token(self): self.assertIn("Authorization", query.headers) self.assertEqual(query.headers["Authorization"], "Bearer 123TOKEN") + + def test_instance_format(self): + query = VariableQuery() + query.instance_format("zarr") + + self.assertIn("instance_format", query.params) + self.assertEqual(query.params["instance_format"], ["zarr"]) + + def test_instance_formats(self): + query = VariableQuery() + query.instance_format(["zarr", "kerchunk"]) + + self.assertIn("instance_format", query.params) + self.assertEqual(query.params["instance_format"], ["zarr", "kerchunk"])