-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path01_find_utility.py
182 lines (160 loc) · 4.9 KB
/
01_find_utility.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
# Copyright (c) 2022 Ghiggi Gionata
# goes_api is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# goes_api is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# goes_api. If not, see <http://www.gnu.org/licenses/>.
import datetime
from goes_api import (
find_closest_files,
find_closest_start_time,
find_files,
find_latest_files,
find_next_files,
find_previous_files,
)
###---------------------------------------------------------------------------.
#### Define protocol or local directory
# - If base_dir specified
# --> Search on local storage
# --> Protocol must be None (or "file" ... see ffspec.LocalFileSystem)
# - If protocol is specified
# --> base_dir must be None
# --> Search on cloud bucket
base_dir = None
protocol = "gcs"
protocol = "s3"
fs_args = {}
###---------------------------------------------------------------------------.
#### Define satellite, sensor, product_level and product
satellite = "GOES-16"
sensor = "ABI"
product_level = "L1B"
product = "Rad"
###---------------------------------------------------------------------------.
#### Define sector and filtering options
start_time = datetime.datetime(2019, 11, 17, 11, 30)
end_time = datetime.datetime(2019, 11, 17, 11, 40)
sector = "M"
scene_abbr = ["M1"] # None download and find both locations
scan_modes = None # select all scan modes (M3, M4, M6)
channels = None # select all channels
channels = ["C01", "C02"] # select channels subset
filter_parameters = {}
filter_parameters["scan_modes"] = scan_modes
filter_parameters["channels"] = channels
filter_parameters["scene_abbr"] = scene_abbr
####---------------------------------------------------------------------------.
#### Find files between start_time and end_time
fpaths = find_files(
base_dir=base_dir,
protocol=protocol,
fs_args=fs_args,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
start_time=start_time,
end_time=end_time,
filter_parameters=filter_parameters,
verbose=True,
)
print(fpaths)
####---------------------------------------------------------------------------.
#### Find files with start_time closest to a given time
fpaths = find_closest_files(
base_dir=base_dir,
protocol=protocol,
fs_args=fs_args,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
time=start_time,
filter_parameters=filter_parameters,
)
print(fpaths)
####---------------------------------------------------------------------------.
#### Find N files prior/after given time
# 1. Find file start_time close to a given time
start_time = find_closest_start_time(
time=start_time,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
protocol="s3",
filter_parameters=filter_parameters,
)
# 2. Define retrieval settings
N = 5
include_start_time = False
operational_checks = True
# 3. Retrieve previous files
fpaths = find_previous_files(
start_time=start_time,
N=N,
include_start_time=include_start_time,
operational_checks=operational_checks,
base_dir=base_dir,
protocol=protocol,
fs_args=fs_args,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
filter_parameters=filter_parameters,
)
print(fpaths)
assert len(fpaths) == N
# 4. Retrieve next files
fpaths = find_next_files(
start_time=start_time,
N=N,
include_start_time=include_start_time,
operational_checks=operational_checks,
base_dir=base_dir,
protocol=protocol,
fs_args=fs_args,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
filter_parameters=filter_parameters,
)
print(fpaths)
assert len(fpaths) == N
####---------------------------------------------------------------------------.
#### Find latest available files
# - By default it retrieve just the last timestep available
N = 2
operational_checks = True
fpaths = find_latest_files(
N=N,
operational_checks=operational_checks,
look_ahead_minutes=30,
base_dir=base_dir,
protocol=protocol,
fs_args=fs_args,
satellite=satellite,
sensor=sensor,
product_level=product_level,
product=product,
sector=sector,
filter_parameters=filter_parameters,
)
print(fpaths)
assert len(fpaths) == N
####---------------------------------------------------------------------------.