-
Notifications
You must be signed in to change notification settings - Fork 1
/
pace_update_all.py
43 lines (33 loc) · 1.25 KB
/
pace_update_all.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
import hypercoast
import earthaccess
import leafmap
import datetime
import shutil
auth = earthaccess.login(strategy="environment")
end_date = datetime.date.today()
start_date = end_date - datetime.timedelta(days=300)
start_date = start_date.strftime("%Y-%m-%d")
end_date = end_date.strftime("%Y-%m-%d")
results = earthaccess.search_data(
short_name="PACE_OCI_L3M_CHL_NRT",
temporal=(start_date, end_date),
granule_name="*.DAY.*.0p1deg.*",
)
hypercoast.download_nasa_data(results, "data")
files = leafmap.find_files("data", "*.nc")
for index, file in enumerate(files[6:]):
data = files[index : index + 7]
array = hypercoast.read_pace_chla(data)
date = array.date.max().values.tolist()
mean_array = array.mean(dim="date")
filename = f"chla/chla_{date}.tif"
latest = "chla/latest.tif"
hypercoast.pace_chla_to_image(mean_array, filename)
# shutil.copy(filename, latest)
# print(f"Updated chla image: {filename}")
# username = "opengeos"
# repository = "pace-data"
# tag_name = "chla"
# release_id = leafmap.github_get_release_id_by_tag(username, repository, tag_name)
# leafmap.github_upload_asset_to_release(username, repository, release_id, filename)
# leafmap.github_upload_asset_to_release(username, repository, release_id, latest)