-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
145 lines (113 loc) · 3.96 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Contain test functions for the GOES-DL project.
These functions are responsible for testing the functionality of the
downloader objects with different product locators and datasources.
Attributes
----------
DATE_FORMAT : str
The date format specification used for parsing dates.
REPO_GRISAT_B1 : str
The repository path for GridSat-B1 data.
REPO_GRISAT_GOES : str
The repository path for GridSat-GOES/CONUS data.
REPO_GOES : str
The repository path for GOES-16 data.
Functions
---------
test(dl: Downloader, start: str, end: str = "")
Test the downloader object by downloading files within a date range.
test_gridsat_aws()
Test the downloader object with GridSat-B1 data and AWS datasource.
test_gridsat_http()
Test the downloader object with GridSat-B1 data and HTTP datasource.
test_gridsat_goes()
Test the downloader object with GridSat-GOES/CONUS data and HTTP
datasource.
test_goes()
Test the downloader object with GOES-16 data and AWS datasource.
"""
from GOES_DL.dataset.goes import GOESProductLocatorABIPP as ProductLocatorGOES
from GOES_DL.dataset.gridsat import GridSatProductLocatorB1 as ProductLocatorB1
from GOES_DL.dataset.gridsat import GridSatProductLocatorGC as ProductLocatorGC
from GOES_DL.datasource import DatasourceAWS, DatasourceHTTP
from GOES_DL.downloader import Downloader
DATE_FORMAT = "%Y-%m-%dT%H:%M%z"
REPO_GRISAT_B1 = "../temp/gridsat/B1"
REPO_GRISAT_GOES = "../temp/gridsat/goes-conus"
REPO_GOES = "../temp/GOES-16"
def test(dl: Downloader, start: str, end: str = "") -> list[str]:
"""
Test the downloader object by downloading files within a date range.
Parameters
----------
dl : Downloader
The downloader object to test.
start : str
The start date of the download range.
end : str, optional
The end date of the download range.
Returns
-------
list[str]
The list of downloaded files.
"""
if end:
print(f"Downloading data from {start} to {end}")
else:
print(f"Downloading data from {start}")
files: list[str] = dl.download_files(start=start, end=end)
return files
def test_gridsat_aws() -> None:
"""
Test the downloader object with GridSat-B1 data and AWS datasource.
"""
pd = ProductLocatorB1()
ds = DatasourceAWS(pd.get_base_url("AWS"), REPO_GRISAT_B1)
dl = Downloader(datasource=ds, locator=pd, date_format=DATE_FORMAT)
test(dl, "1984-08-23T00:00Z")
def test_gridsat_http() -> None:
"""
Test the downloader object with GridSat-B1 data and HTTP datasource.
"""
pd = ProductLocatorB1()
ds = DatasourceHTTP(pd, REPO_GRISAT_B1)
dl = Downloader(datasource=ds, locator=pd, date_format=DATE_FORMAT)
test(dl, "1984-08-23T00:00Z")
test(dl, "1982-08-23T00:00Z")
def test_gridsat_goes() -> None:
"""
Test the downloader object with GridSat-GOES/CONUS data and HTTP
datasource.
"""
pd = ProductLocatorGC("F", "G12")
ds = DatasourceHTTP(pd, REPO_GRISAT_GOES)
dl = Downloader(datasource=ds, locator=pd, date_format=DATE_FORMAT)
test(dl, "2008-11-09T14:00+0000")
def test_goes() -> list[str]:
"""
Test the downloader object with GOES-16 data and AWS datasource.
Returns
-------
list[str]
The list of downloaded files.
"""
pd = ProductLocatorGOES("CMIP", "F", "C13", "G16")
# GOES-16 data is updated every 10 minutes. If you are downloading
# old data, you may leave the refresh rate as default.
REPO_GOES = "C:/Projects/TFG/source/tutorials/repository/20201114T20"
ds = DatasourceAWS(pd, REPO_GOES, 10 * 60)
dl = Downloader(datasource=ds, locator=pd)
files1 = test(dl, "2020-11-14T20:00:00Z")
files2 = test(dl, "2020-11-14T20:00:00Z", "2020-11-15T19:00:00Z")
return files2
def main() -> None:
"""
Run all test functions.
"""
files = test_goes()
print(files)
test_gridsat_goes()
test_gridsat_aws()
test_gridsat_http()
if __name__ == "__main__":
main()