-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal_hrrr.py
78 lines (53 loc) · 2.47 KB
/
modal_hrrr.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
# Everything till the `=======` is required to work, though it can be customized.
from datetime import timedelta
import modal
from modal_app import applib, driver
from src.lib import WriteMode, utcnow
from src.lib_modal import MODAL_FUNCTION_KWARGS
app = modal.App("hrrr-forecast-ingest")
app.include(applib) # necessary
@app.local_entrypoint()
def main(mode: str, toml_file: str, since: str, till: str | None = None):
if mode != "backfill":
raise ValueError("Only mode='backfill' is allowed.")
driver(mode=WriteMode.BACKFILL, toml_file_path=toml_file, since=since, till=till)
# =======
@app.function(**MODAL_FUNCTION_KWARGS)
def hrrr_backfill():
"""Run this "backfill" function wtih `modal run modal_hrrr.py::hrrr_backfill`."""
file = "src/configs/hrrr.toml"
mode = WriteMode.BACKFILL
since = utcnow() - timedelta(days=3)
till = utcnow() - timedelta(days=1, hours=12)
driver(mode=mode, toml_file_path=file, since=since, till=till)
@app.function(**MODAL_FUNCTION_KWARGS, schedule=modal.Cron("57 * * * *"), timeout=1200)
def hrrr_update_solar():
"""
*Deploy* this :update" function wtih `modal deploy modal_hrrr.py --name hrrr_update_solar`.
"""
driver(mode=WriteMode.UPDATE, toml_file_path="src/configs/hrrr.toml")
@app.function(**MODAL_FUNCTION_KWARGS, timeout=3600 * 3)
def hrrr_backfill_3d():
"""Run this "backfill" function wtih `modal run modal_hrrr.py::hrrr_backfill_3d`."""
import pandas as pd
file = "src/configs/hrrr-3d.toml"
mode = WriteMode.BACKFILL
since = pd.Timestamp("2022-01-01")
till = pd.Timestamp("2022-12-31 23:30")
driver(mode=mode, toml_file_path=file, since=since, till=till)
# @app.function(**MODAL_FUNCTION_KWARGS, timeout=3600, schedule=modal.Cron("57 * * * *"))
# def hrrr_update_3d():
# """
# *Deploy* this :update" function with `modal deploy modal_hrrr.py --name hrrr_update_3d`.
# """
# driver(mode=WriteMode.UPDATE, toml_file_path="src/configs/hrrr-3d.toml")
# @app.function(**MODAL_FUNCTION_KWARGS)
# def hrrr_backfill_rechunk():
# file = "src/configs/hrrr-demo.toml"
# mode = WriteMode.BACKFILL
# since = utcnow() - timedelta(days=3)
# till = utcnow() - timedelta(days=1, hours=12)
# driver(mode=mode, toml_file_path=file, since=since, till=till)
# @app.function(**MODAL_FUNCTION_KWARGS, timeout=3600, schedule=modal.Cron("57 * * * *"))
# def hrrr_update_rechunk():
# driver(mode=WriteMode.UPDATE, toml_file_path="src/configs/hrrr-demo.toml")