Wildest jobs
This example shows how to create some wildest jobs from a weather scenarios csv file.
Keep in mind, the api key, and file paths that you see here are specific to my machine and will need to be changed if you want to run this script.
Also, for the sake of the demonstration, it only loops through the first 5 weather scenarios. For real life usage you can just remove the stop index.
To summarize the script:
- reads weather scenarios from a .csv file
- creates a project and an initial "base job"
- binds input files to that base job and configures it with respect to wx001
- then loops through the weather scenarios. For each weahter scenario:
- duplicate the base job so that it has the proper inputs
- set the new job's config with respect to the current weather scenario
from typing import List
from pyro_dash_py import PyroDash
from pathlib import Path
import csv
from dataclasses import dataclass
import os
@dataclass
class WeatherScenario:
name: str
speed: int
direction: int
mc: int
wx_csv_path = Path(
"/Users/jack/code/pyro-flow/common/static_assets/weather_scenarios.csv"
)
wx_scenarios: List[WeatherScenario] = []
with open(wx_csv_path, "r") as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
scenario = WeatherScenario(
row["Scenario"],
int(row["WS"]),
int(row["WD"]),
int(row["MC"]),
)
wx_scenarios.append(scenario)
apikey = os.environ.get("PYRO_API_KEY")
assert apikey is not None
pyro = PyroDash(
host="http://localhost:8001",
email="jack.campanella@pyrologix.com",
apikey=apikey,
)
project = pyro.projects.create(name="My WildEST project")
print("created project: ", project.name)
base_job = pyro.jobs.create("wildest")
project.add_job(base_job.id)
first_wx = wx_scenarios[0]
base_job.set_name(first_wx.name)
base_job.use_weather_scenario(first_wx.speed, first_wx.direction, first_wx.mc)
print("created base job with wx: ", first_wx.name)
print("adding files")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/fm40.tif")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/cc.tif")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/ch.tif")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/cbh.tif")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/asp.tif")
base_job.add_file("/Users/jack/data/wildest_test/trinity_small/slp.tif")
# This only loops through the first couple of weather scenarios
# if you want to loop through them all, simply remove the stop index
for scenario in wx_scenarios[1:5]:
print("Creating job for wx: ", scenario.name)
other_job = base_job.duplicate()
other_job.set_name(scenario.name)
other_job.use_weather_scenario(scenario.speed, scenario.direction, scenario.mc)
project.add_job(other_job.id)