Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

- Add method `Query.results` for returning results as an iterator instead of sequence ([#37](https://github.com/nasa/python_cmr/issues/37))
- Support searching by multiple platforms for collections and granules ([#80](https://github.com/nasa/python_cmr/issues/80))

### Changed

Expand Down
9 changes: 6 additions & 3 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,18 +781,21 @@ def entry_title(self, entry_title: str) -> Self:

return self

def platform(self, platform: str) -> Self:
def platform(self, platform: Union[str, Sequence[str]]) -> Self:
"""
Filter by the satellite platform the granule came from.

:param platform: name of the satellite
:param platform: name of the satellite (single string) or sequence of satellite names
:returns: self
"""

if not platform:
raise ValueError("Please provide a value for platform")

self.params['platform'] = platform
self.params['platform'] = (
platform if isinstance(platform, str) else list(platform)
)

return self


Expand Down
14 changes: 14 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,26 @@ def test_platform(self):
self.assertIn("platform", query.params)
self.assertEqual(query.params["platform"], "1B")

def test_multiple_platforms(self):
query = CollectionQuery()

query.platform(["Terra", "Aqua"])

self.assertIn("platform", query.params)
self.assertEqual(query.params["platform"], ["Terra", "Aqua"])

def test_empty_platform(self):
query = CollectionQuery()

with self.assertRaises(ValueError):
query.platform(None) # type: ignore[arg-type]

def test_empty_platform_list(self):
query = CollectionQuery()

with self.assertRaises(ValueError):
query.platform([])

def test_revision_date(self):
query = CollectionQuery()
collections = query.short_name("SWOT_L2_HR_RiverSP_reach_2.0").revision_date("2022-05-16", "2024-06-30").get_all()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_granule.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def test_platform(self):
self.assertIn(self.platform, query.params)
self.assertEqual(query.params[self.platform], "1B")

def test_multiple_platforms(self):
query = GranuleQuery()

query.platform(["Terra", "Aqua"])

self.assertIn(self.platform, query.params)
self.assertEqual(query.params[self.platform], ["Terra", "Aqua"])

def test_sort_key(self):
query = GranuleQuery()
# Various sort keys using this as an example
Expand All @@ -363,6 +371,12 @@ def test_empty_platform(self):
with self.assertRaises(ValueError):
query.platform(None) # type: ignore[arg-type]

def test_empty_platform_list(self):
query = GranuleQuery()

with self.assertRaises(ValueError):
query.platform([])

def test_granule_ur(self):
query = GranuleQuery()

Expand Down