Skip to content

Commit

Permalink
Merge pull request #21 from eodms-sgdot/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
keballantyne committed Oct 13, 2022
2 parents a3d03f2 + 2c32491 commit 8398a49
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 27 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2020-2022 Her Majesty the Queen in Right of Canada, as
represented by the President of the Treasury Board
Copyright (c) His Majesty the King in Right of Canada, as
represented by the Minister of Natural Resources, 2022.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
5 changes: 3 additions & 2 deletions eodms_rapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
__title__ = 'py-eodms-rapi'
__name__ = 'eodms_rapi'
__author__ = 'Kevin Ballantyne'
__copyright__ = 'Copyright 2020-2022 Her Majesty the Queen in Right of Canada'
__copyright__ = 'Copyright (c) His Majesty the King in Right of Canada, ' \
'as represented by the Minister of Natural Resources, 2022'
__license__ = 'MIT License'
__description__ = 'A Python package to access the EODMS RAPI service.'
__version__ = '1.5.1'
__version__ = '1.5.2'
__maintainer__ = 'Kevin Ballantyne'
__email__ = 'eodms-sgdot@nrcan-rncan.gc.ca'

Expand Down
76 changes: 61 additions & 15 deletions eodms_rapi/eodms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##############################################################################
# MIT License
#
# Copyright (c) 2020-2022 Her Majesty the Queen in Right of Canada, as
# represented by the President of the Treasury Board
# Copyright (c) His Majesty the King in Right of Canada, as
# represented by the Minister of Natural Resources, 2022
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -129,6 +129,8 @@ def __init__(self, username, password, show_timestamp=True):
:type username: str
:param password: The password of an EODMS account.
:type password: str
:param show_timestamp: Determines whether to show a timestamp
:type show_timestamp: bool
"""

# Create session
Expand Down Expand Up @@ -179,6 +181,13 @@ def __init__(self, username, password, show_timestamp=True):
'AWAITING_PAYMENT']

self.ui_field_map = {
'ALOS-2': ['Look Direction',
'SENSOR_BEAM.SPATIAL_RESOLUTION',
'ARCHIVE_IMAGE.PRODUCT_TYPE',
'PRODUCT_FORMAT.FORMAT_NAME_E', 'sarsat.SBEAM',
'sarsat.REC_POL', 'sarsat.TR_POL',
'SENSOR_BEAM_CONFIG.INCIDENCE_HIGH',
'SENSOR_BEAM_CONFIG.INCIDENCE_LOW'],
'COSMO-SkyMed1': ['ARCHIVE_IMAGE.ORDER_KEY',
'SENSOR_BEAM.SPATIAL_RESOLUTION',
'csmed.ORBIT_ABS'],
Expand Down Expand Up @@ -512,10 +521,12 @@ def _fetch_metadata(self, max_workers=4, len_timeout=20.0,
:param max_workers: The number of threads used for retrieving the
metadata.
:type max_workers: int
:param len_timeout: The length of
time in seconds before the thread returns a timeout warning.
:type
len_timeout: float
:param len_timeout: The length of time in seconds before the thread
returns a timeout warning.
:type len_timeout: float
:param show_progress: Determines whether to show the progress
(use tqdm) when fetching the metadata
:type show_progress: bool
:return: A list containing the metadata for all items in the
self.results
Expand All @@ -537,12 +548,6 @@ def _fetch_metadata(self, max_workers=4, len_timeout=20.0,
with ThreadPoolExecutor(max_workers=max_workers) as executor:
out_results = list(
tqdm(
# executor.map(
# self._fetch_single_record_metadata,
# self.results,
# [len_timeout] * n_urls,
# [metadata_fields] * n_urls,
# ),
executor.map(
self._fetch_single_record_metadata,
self.results,
Expand Down Expand Up @@ -1281,6 +1286,17 @@ def _submit_search(self):
return self._submit_search()

def _check_http(self, err_msg):
"""
Checks an error message for the HTTP code and returns a more
appropriate message.
:param err_msg: The error message from the response.
:type err_msg: str
:return: The new error message (or None is no error).
:rtype: str (or None)
"""

if err_msg.find('404 Client Error') > -1 or \
err_msg.find('404 for url') > -1:
msg = f"404 Client Error: Could not find {self._rapi_url}."
Expand Down Expand Up @@ -1309,6 +1325,10 @@ def _submit(self, query_url, request_type='get', post_data=None,
:param record_name: A string used to supply information for the record
in a print statement.
:type record_name: str
:param quiet: Determines whether to ignore log printing.
:type quiet: bool
:param as_json: Determines whether to return results in JSON format.
:type as_json: bool
:return: The response returned from the RAPI.
:rtype: request.Response
Expand Down Expand Up @@ -1559,6 +1579,13 @@ def get_collection_id(self, coll):
return k

def get_err_msg(self):
"""
Gets the error message of this class after an error occurred.
:return: The error message
:rtype: str
"""

return self.err_msg

def set_query_timeout(self, timeout):
Expand Down Expand Up @@ -1603,7 +1630,6 @@ def set_field_convention(self, convention):
'camelCase'.
- ``upper``: The format will be all uppercase with
underscore for spaces.
:type convention: str
"""
Expand Down Expand Up @@ -1636,6 +1662,9 @@ def download_image(self, url, dest_fn, fsize, show_progress=True):
:type dest_fn: str
:param fsize: The total filesize of the image.
:type fsize: int
:param show_progress: Determines whether to show progress while
downloading an image
:type show_progress: bool
"""

# If we have an existing local file, check the filesize against the
Expand Down Expand Up @@ -1719,6 +1748,9 @@ def download(self, items, dest, wait=10.0, max_attempts=None,
downloads. If None, the script will continue to check and download
orders until all orders have been downloaded.
:type max_attempts: int
:param show_progress: Determines whether to show progress while
downloading an image
:type show_progress: bool
:return: A list of the download (completed) items.
:rtype: list
Expand Down Expand Up @@ -1865,8 +1897,13 @@ def download(self, items, dest, wait=10.0, max_attempts=None,
if not os.path.exists(dest):
os.makedirs(dest, exist_ok=True)

self.download_image(url, out_fn, fsize,
show_progress=show_progress)
try:
self.download_image(url, out_fn, fsize,
show_progress=show_progress)
except Exception as e:
self.log_msg(e, 'warning')
continue

print('')

# Record the URL and downloaded file to a dictionary
Expand Down Expand Up @@ -3065,6 +3102,12 @@ def search(self, collection, filters=None, features=None, dates=None,
self.results += self.search_results

def clear_results(self):
"""
Clears the cumulative results.
:return: n/a
"""

self.results = []

def get_results(self, form='raw', show_progress=True):
Expand All @@ -3083,6 +3126,9 @@ def get_results(self, form='raw', show_progress=True):
(requires geojson package).
:type form: str
:param show_progress: Determines whether to show progress while
fetching metadata
:type show_progress: bool
:return: A dictionary of the results from self.results variable.
:rtype: dict
Expand Down
4 changes: 2 additions & 2 deletions eodms_rapi/geo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##############################################################################
# MIT License
#
# Copyright (c) 2020-2021 Her Majesty the Queen in Right of Canada, as
# represented by the President of the Treasury Board
# Copyright (c) His Majesty the King in Right of Canada, as
# represented by the Minister of Natural Resources, 2022
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[metadata]
name = py-eodms-rapi
version = 1.5.1
version = 1.5.2
author = Kevin Ballantyne (Natural Resources Canada)
author_email = kevin.ballantyne@nrcan-rncan.gc.ca
description = EODMS RAPI Client is a Python3 package used to access the REST API service provided by the Earth Observation Data Management System (EODMS) from Natural Resources Canada.
description-file = README.md
description_file = README.md
long_description = file: README.md
long_description_content_type = text/markdown
url = https://py-eodms-rapi.readthedocs.io/en/latest/
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='py-eodms-rapi',
version='1.5.1',
version='1.5.2',
author='Kevin Ballantyne (Natural Resources Canada)',
author_email='kevin.ballantyne@nrcan-rncan.gc.ca',
packages=find_packages(),
Expand Down
7 changes: 4 additions & 3 deletions test/test_pyeodmsrapi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##############################################################################
# MIT License
#
# Copyright (c) 2020-2022 Her Majesty the Queen in Right of Canada, as
# represented by the President of the Treasury Board
# Copyright (c) His Majesty the King in Right of Canada, as
# represented by the Minister of Natural Resources, 2022.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand All @@ -26,7 +26,8 @@

__title__ = 'py-eodms-rapi Tester'
__author__ = 'Kevin Ballantyne'
__copyright__ = 'Copyright 2020-2022 Her Majesty the Queen in Right of Canada'
__copyright__ = 'Copyright (c) His Majesty the King in Right of Canada, ' \
'as represented by the Minister of Natural Resources, 2022'
__license__ = 'MIT License'
__description__ = 'Performs various tests of the py-eodms-rapi Python package.'
__email__ = 'eodms-sgdot@nrcan-rncan.gc.ca'
Expand Down

0 comments on commit 8398a49

Please sign in to comment.