Skip to content

Commit

Permalink
Merge pull request #36 from raphaelrpl/b-0.4
Browse files Browse the repository at this point in the history
Fix support for MYD
  • Loading branch information
raphaelrpl authored May 7, 2021
2 parents 923ce92 + 365ee05 commit 0cd6e86
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions bdc_collectors/modis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, username, password, **kwargs):
self.directory = self._tmp.name

self.collections['MOD13Q1.006'] = ModisCollection
self.collections['MYD13Q1.006'] = ModisCollection

def get_collector(self, collection: str) -> Type[BaseCollection]:
"""Represent the structure to deal with Provider API."""
Expand All @@ -56,6 +57,10 @@ def search(self, query, *args, **kwargs) -> SceneResults:
options = dict(
product=query
)
path = kwargs.get('path')
if path is None:
path = self._guess_path(query)
options['path'] = path

if kwargs.get('start_date'):
options['today'] = self._parse_date(kwargs['start_date']).strftime('%Y-%m-%d')
Expand Down Expand Up @@ -106,6 +111,7 @@ def download(self, scene_id: str, *args, **kwargs) -> str:
**kwargs - Extra parameters used to download
"""
dataset = self._guess_dataset(scene_id, **kwargs)
path = self._guess_path(dataset)
scene = self.search(dataset, scene_id=scene_id)[0]
output = kwargs.get('output')

Expand All @@ -114,7 +120,8 @@ def download(self, scene_id: str, *args, **kwargs) -> str:
options = dict(
today=parse.sensing_date().strftime('%Y-%m-%d'),
tiles=parse.tile_id(),
product=dataset
product=dataset,
path=path
)
options['enddate'] = options['today']

Expand Down Expand Up @@ -166,6 +173,21 @@ def _guess_dataset(self, scene_id, **kwargs):

return f'{scene.source()}.{scene.version()}'

def _guess_path(self, dataset: str):
"""Try to identify remote server path prefix according to data set information.
TODO: We should list all entries and filter on remote host.
"""
if dataset.startswith('MYD'):
return 'MOLA'
if dataset.startswith('MOD'):
return 'MOLT'
if dataset.startswith('MCD'):
return 'MOTA'
if dataset.startswith('VNP'):
return 'VIIRS'
raise RuntimeError(f'Dataset {dataset} not supported.')

def _search(self, date_reference, api, **kwargs):
files = api.getFilesList(date_reference)

Expand All @@ -185,7 +207,6 @@ def _search(self, date_reference, api, **kwargs):
scenes.append(
SceneResult(scene, cloud_cover=float(meta['QAPercentCloudCover']), link=link, **meta)
)

return scenes

def _read_meta(self, meta_file: str):
Expand Down

0 comments on commit 0cd6e86

Please sign in to comment.