-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from nansencenter/add_aviso_provider
Add AVISO provider
- Loading branch information
Showing
5 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Code for searching AVISO data (https://tds.aviso.altimetry.fr/thredds)""" | ||
from .base import Provider, TimeFilterMixin | ||
from ..arguments import StringArgument | ||
from ..crawlers import ThreddsCrawler | ||
|
||
|
||
class AVISOProvider(TimeFilterMixin, Provider): | ||
"""Provider for AVISO's Thredds""" | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.url = 'https://tds.aviso.altimetry.fr/thredds' | ||
self.search_parameters_parser.add_arguments([ | ||
StringArgument('directory', required=True), | ||
StringArgument('include'), | ||
]) | ||
|
||
def _make_crawler(self, parameters): | ||
return ThreddsCrawler( | ||
'/'.join((self.url, parameters['directory'].lstrip('/'))), | ||
time_range=(parameters['start_time'], parameters['end_time']), | ||
include=parameters.get('include'), | ||
max_threads=30, | ||
username=self.username, | ||
password=self.password, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# pylint: disable=protected-access | ||
"""Tests for the AVISO provider""" | ||
import unittest | ||
import unittest.mock as mock | ||
from datetime import datetime, timezone | ||
|
||
import geospaas_harvesting.crawlers as crawlers | ||
from geospaas_harvesting.providers.aviso import AVISOProvider | ||
|
||
|
||
class AVISOProviderTestCase(unittest.TestCase): | ||
"""Tests for AVISOProvider""" | ||
|
||
def test_make_crawler(self): | ||
"""Test creating a crawler from parameters""" | ||
provider = AVISOProvider(name='test', username='user', password='pass') | ||
parameters = { | ||
'start_time': datetime(2023, 1, 1, tzinfo=timezone.utc), | ||
'end_time': datetime(2023, 1, 2, tzinfo=timezone.utc), | ||
'directory': 'foo', | ||
'include': '.*' | ||
} | ||
self.assertEqual( | ||
provider._make_crawler(parameters), | ||
crawlers.ThreddsCrawler( | ||
'https://tds.aviso.altimetry.fr/thredds/foo', | ||
include='.*', | ||
time_range=(datetime(2023, 1, 1, tzinfo=timezone.utc), | ||
datetime(2023, 1, 2, tzinfo=timezone.utc)), | ||
username='user', password='pass')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters