Fergui / m2m-api

API to search and download data using Machine-to-Machine (M2M) API from USGS.
MIT License
12 stars 4 forks source link

Download not working #3

Closed lizxl2 closed 11 months ago

lizxl2 commented 11 months ago

I tried to use download in test m2m.retrieveScenes(params['datasetName'],scenes)

M2MError Traceback (most recent call last) Cell In[89], line 19 16 m2m = M2M() 18 scenes = m2m.searchScenes(**params) ---> 19 downloadMeta = m2m.retrieveScenes(params['datasetName'],scenes)

File ~/SageMaker/api.py:182, in M2M.retrieveScenes(self, datasetName, scenes, filterOptions, label) 180 logging.info('M2M.retrieveScenes - No download options found') 181 for label in labels: --> 182 self.downloadOrderRemove(label) 183 return downloadMeta

File ~/SageMaker/api.py:137, in M2M.downloadOrderRemove(self, label) 136 def downloadOrderRemove(self, label): --> 137 self.sendRequest('download-order-remove', label)

File ~/SageMaker/api.py:56, in M2M.sendRequest(self, endpoint, data, max_retries) 54 else: 55 msg = "{} - {}".format(status,output) ---> 56 raise M2MError(msg) 57 else: 58 if isinstance(output,dict):

M2MError: 500 - INPUT_PARAMETER_REQUIRED - The parameter label is required and was not supplied

Also do you know why the return of dowload option for me is always empty?

Fergui commented 11 months ago

The error was corrected in the last commit 85f1ad8246a81ab4b75042aba2b728825948d1f3

The problem with having empty download options is that all results were filtered out. The default filter is updated and works with most USGS datasets.

For the future, if you need to modify the filter, you can do so by using the parameter filterOptions of the retrieveScenes method. For instance, you can do:

filterOptions = {'downloadSystem': lambda x: x in ['dds', 'ls_zip'], 'available': lambda x: x}
downloadMeta = m2m.retrieveScenes(datasetName, scenes, filterOptions=filterOptions)

If you don't want to filter the download options, you can do:

downloadMeta = m2m.retrieveScenes(datasetName, scenes, filterOptions={})

But it will likely download duplicates of the dataset in different forms.

lizxl2 commented 11 months ago

I think the download option in API missed entityIds as argment? Otherwise, the return seems empty.

def downloadOptions(self, datasetName, entityIds, filterOptions={}, **args):
    if datasetName not in self.datasetNames:
        raise M2MError("Dataset {} not one of the available datasets {}".format(datasetName,self.datasetNames))
    args['datasetName'] = datasetName
    args['entityIds'] = entityIds
    downloadOptions = self.sendRequest('download-options', args)
    filteredOptions = apply_filter(downloadOptions, filterOptions)
    return filteredOptions
Fergui commented 11 months ago

In the download-options endpoint, the entityIds is an optional parameter. In this case, it was more consistent to get all download options from the dataset and then parse the entityIds in the options. But, you are more than welcome to create your own call to the download-options endpoint, including the entityIds returned by the searchScenes call.

Thank you,

Angel