Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move platform() into GranuleCollectionBaseQuery #78

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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 @@ -16,6 +16,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
other parameter options that are not covered in that particular section of the
documentation. ([#74](https://github.com/nasa/python_cmr/issues/74))
- Support multi-point searches ([#72](https://github.com/nasa/python_cmr/issues/72))
- Support `platform` in `CollectionQuery` ([#77](https://github.com/nasa/python_cmr/issues/77))

### Fixed
- Setup vcrpy for new `revision_date` unit tests ([#70](https://github.com/nasa/python_cmr/issues/70))
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ api.downloadable()
# only include granules that are unavailable for download
api.online_only()

# filter by specific satellite platform
api.platform("Terra")

# search for collections/granules associated with or identified by concept IDs
# note: often the ECHO collection ID can be used here as well
# note: when using CollectionQuery, only collection concept IDs can be passed
Expand Down Expand Up @@ -143,9 +146,8 @@ api.day_night_flag("day")
# filter by cloud cover percentage range
api.cloud_cover(25, 75)

# filter by specific instrument or platform
# filter by specific instrument
api.instrument("MODIS")
api.platform("Terra")

# filter by a sort_key note: sort_keys are require some other fields to find
# some existing granules before they can be sorted
Expand Down
28 changes: 14 additions & 14 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,20 @@ def entry_title(self, entry_title: str) -> Self:

return self

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

:param platform: name of the satellite
:returns: self
"""

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

self.params['platform'] = platform
return self


class GranuleQuery(GranuleCollectionBaseQuery):
"""
Expand Down Expand Up @@ -813,20 +827,6 @@ def instrument(self, instrument: str) -> Self:
self.params['instrument'] = instrument
return self

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

:param platform: name of the satellite
:returns: self
"""

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

self.params['platform'] = platform
return self

def sort_key(self, sort_key: str) -> Self:
"""
See
Expand Down
14 changes: 14 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ def test_invalid_cloud_hosted(self):
with self.assertRaises(TypeError):
query.cloud_hosted("Test_string_for_cloud_hosted_param") # type: ignore[arg-type]

def test_platform(self):
query = CollectionQuery()

query.platform("1B")

self.assertIn("platform", query.params)
self.assertEqual(query.params["platform"], "1B")

def test_empty_platform(self):
query = CollectionQuery()

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

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