def __init__(self, player1, player2): if player1 == 1: self.character1 = Agate() elif player1 == 2: self.character1 = Jasper() else: self.character1 = Beryl() if player2 == 1: self.character2 = Agate() elif player2 == 2: self.character2 = Jasper() else: self.character2 = Beryl() self.current_round = 0 self.round_winners = []
""" Export meta data for weather stations The code is licensed under the MIT license. """ import json from jasper import Jasper from jasper.helpers import read_file from jasper.actions import export_csv, export_json # Create Jasper instance jsp = Jasper("export.bulk.stations.meta") # Export data for all weather stations result = jsp.query(read_file("meta.sql")) if result.rowcount > 0: # Fetch data data = result.fetchall() # Data lists full = [] lite = [] slim = [] for record in data: # Create dict of names try: names = json.loads(record[2])
"Okt": "tsun10", "Nov": "tsun11", "Dez": "tsun12", }, }, ] # Variables ftp: Union[FTP, None] = None # FTP server connection counter = 0 # The task's counter skip = 3 # How many lines to skip stations = [] # List of weather stations df_full: Union[pd.DataFrame, None] = None # DataFrame which holds all data # Create Jasper instance jsp = Jasper(f"import.dwd.monthly.global.{MODE}") def find_file(path: str, needle: str): """ Find file in directory """ match = None try: ftp.cwd( "/climate_environment/CDC/observations_global/CLIMAT/monthly/qc/" + path) files = ftp.nlst() matching = [f for f in files if needle in f] match = matching[0]
Update daily inventory The code is licensed under the MIT license. """ from datetime import datetime from meteostat import Daily from jasper import Jasper from jasper.helpers import get_stations # General configuration Daily.max_age = 0 STATIONS_PER_CYCLE = 10 # Create Jasper instance jsp = Jasper("task.inventory.daily") # Get stations stations = get_stations(jsp, "SELECT `id` FROM `stations`", STATIONS_PER_CYCLE) if len(stations) > 0: for station in stations: try: # Get daily data from Meteostat data = Daily(station[0], model=False).fetch() # Get start & end dates of time series start = data.index.min().strftime("%Y-%m-%d") end = data.index.max().strftime("%Y-%m-%d") if len(start) == 10 and len(end) == 10:
""" from urllib import request, error import json import pandas as pd from jasper import Jasper from jasper.actions import persist from jasper.helpers import get_stations, read_file from jasper.schema import hourly_national # General configuration STATIONS_PER_CYCLE = 36 # Create Jasper instance jsp = Jasper("import.noaa.hourly.national_metar") # Get weather stations stations = get_stations( jsp, read_file("national_metar_stations.sql"), STATIONS_PER_CYCLE ) # DataFrame which holds all data df_full = None # Import data for each weather station if len(stations) > 0: for station in stations: try: # Create request for JSON file url = f"https://api.weather.gov/stations/{station['icao']}/observations/latest"
""" Update normals inventory The code is licensed under the MIT license. """ from meteostat import Normals from jasper import Jasper from jasper.helpers import get_stations # General configuration Normals.max_age = 0 STATIONS_PER_CYCLE = 10 # Create Jasper instance jsp = Jasper("task.inventory.normals") stations = get_stations( jsp, "SELECT `id` FROM `stations`", STATIONS_PER_CYCLE, ) if len(stations) > 0: for station in stations: try: # Get daily data from Meteostat data = Normals(station[0], "all").fetch() # Get start & end dates of time series start = data.index.get_level_values("start").min()
import datetime import numpy as np import pandas as pd import pyproj import verde as vd from jasper import Jasper # General configuration PARAMETERS = ["tavg", "tmin", "tmax", "prcp", "wspd", "pres"] # Get task mode # 'historical' or 'recent' MODE = sys.argv[1] # Create Jasper instance jsp = Jasper(f"export.bulk.gridded.daily.{MODE}") # Variables modified: bool = None raw: pd.DataFrame # Get time delta if MODE == "historical": # We'll need to run at least twice a day # Otherwise this is stuck delta = jsp.get_var("date_offset", 0, int) if delta > 18493: jsp.set_var("date_offset", 0) sys.exit() jsp.set_var("date_offset", delta + 1) else:
""" Export monthly bulk data The code is licensed under the MIT license. """ from jasper import Jasper from jasper.helpers import read_file, get_stations from jasper.actions import export_csv # General configuration STATIONS_PER_CYCLE = 11 # Create Jasper instance jsp = Jasper("export.bulk.monthly") # Get weather station(s) stations = get_stations( jsp, read_file("monthly_stations.sql"), STATIONS_PER_CYCLE, ) # Export data for each weather station for station in stations: result = jsp.query( read_file("monthly.sql"), {"station": station[0], "timezone": station[1]} ) if result.rowcount > 0:
from time import sleep from typing import Union from urllib import request, error import json import pandas as pd from jasper import Jasper from jasper.actions import persist from jasper.helpers import get_stations, read_file from jasper.schema import hourly_model # General configuration STATIONS_PER_CYCLE = 42 SLEEP_TIME = 0.2 # Create Jasper instance jsp = Jasper("import.metno.hourly.model") def get_condicode(code: str) -> Union[int, None]: """ Map Met.no symbol codes to Meteostat condicodes https://api.met.no/weatherapi/weathericon/2.0/documentation """ condicodes = { "clearsky": 1, "cloudy": 3, "fair": 2, "fog": 5, "heavyrain": 9, "heavyrainandthunder": 26,
from sys import argv from datetime import datetime from jasper import Jasper from jasper.helpers import get_stations from jasper.actions import export_csv # Task mode # 'all' or 'recent' MODE = argv[1] # General configuration STATIONS_PER_CYCLE = 8 if MODE == "recent" else 1 # Create Jasper instance jsp = Jasper(f"export.bulk.hourly.legacy.{MODE}") def write_dump(data: list, station: str, year: int = None) -> None: """ Convert DataFrame to CSV and export to bulk server """ # The file path path = "/hourly/obs" # Filter rows by year if set if year is not None: path += f"/{year}" data = list(filter(lambda row: int(row[0].year) == year, data)) # Export data dump
import pandas as pd from jasper import Jasper from jasper.convert import kelvin_to_celsius, ms_to_kmh, temp_dwpt_to_rhum from jasper.helpers import get_stations, read_file from jasper.schema import hourly_model from jasper.actions import persist # General configuration STATIONS_PER_CYCLE = 6 # Number of stations per execution # Variables df_full: Union[pd.DataFrame, None] = None # DataFrame which holds all data # Create Jasper instance jsp = Jasper("import.dwd.hourly.model") def get_condicode(code: str) -> Union[int, None]: """ Map DWD codes to Meteostat condicodes """ condicodes = { "0": 1, "1": 2, "2": 3, "3": 4, "45": 5, "49": 5, "61": 7, "63": 8,
""" Get latest weather station meta data from GitHub The code is licensed under the MIT license. """ import json import re import urllib.request as request import zipfile from jasper import Jasper from jasper.helpers import read_file # Create Jasper instance jsp = Jasper("import.internal.github.stations") def write_station(data: dict) -> None: """ Add a new weather station or update existing """ try: # Break if invalid data if len(data["id"]) != 5 or len(data["country"]) != 2: return None # Extract alternate names name_alt = { key: data["name"][key] for key in data["name"] if key != "en" }
def setUp(self): self.profile = DEFAULT_PROFILE self.send = False self.persona = "Jasper" self.jasper = Jasper() self.mic = self.jasper.mic
""" Update hourly inventory The code is licensed under the MIT license. """ from jasper import Jasper # Create Jasper instance jsp = Jasper("task.inventory.hourly") jsp.query(""" INSERT INTO `inventory`(`station`, `mode`, `start`) SELECT `station`, 'H' AS `mode`, MIN(`mindate`) AS `start` FROM ( (SELECT `station`, DATE(MIN(`time`)) as `mindate` FROM `hourly_synop` GROUP BY `station`) UNION ALL (SELECT `station`, DATE(MIN(`time`)) as `mindate` FROM `hourly_metar` GROUP BY `station`) UNION ALL (SELECT
"names": { "SD_SO": "tsun" }, "convert": {}, }, ] # Variables ftp: Union[FTP, None] = None # FTP server connection counter = 0 # The task's counter skip = 3 # How many lines to skip stations = [] # List of weather stations df_full: Union[pd.DataFrame, None] = None # DataFrame which holds all data # Create Jasper instance jsp = Jasper(f"import.dwd.hourly.national.{MODE}") def dateparser(value): """ Custom Pandas date parser """ return datetime.strptime(value, "%Y%m%d%H") def find_file(path: str, needle: str): """ Find file in directory """ match = None
"Windgeschwindigkeit": "wspd", "Windboen (letzte Stunde)": "wpgt", "Niederschlag (letzte Stunde)": "prcp", "Relative Feuchte": "rhum", "Windrichtung": "wdir", "Druck (auf Meereshoehe)": "pres", "Sonnenscheindauer (letzte Stunde)": "tsun", "aktuelles Wetter": "coco", "Schneehoehe": "snow", } # Variables stations: Union[pd.DataFrame, None] = None # DataFrame of weather stations # Create Jasper instance jsp = Jasper("import.dwd.hourly.synop") def dateparser(date, hour): """ Custom Pandas date parser """ return datetime.strptime(f"{date} {hour}", "%d.%m.%y %H:%M") def get_condicode(code: str) -> Union[int, None]: """ Map DWD codes to Meteostat condicodes Check docs/dwd_poi_codes.pdf for more information """
"/ghcn.csv") NAMES = { "MM/DD/YYYY": "time", "TMAX": "tmax", "TMIN": "tmin", "TAVG": "tavg", "PRCP": "prcp", "SNWD": "snow", "AWDR": "wdir", "AWND": "wspd", "TSUN": "tsun", "WSFG": "wpgt", } # Create Jasper instance jsp = Jasper("import.noaa.daily.global") # Weather stations stations: Union[pd.DataFrame, None] = None # Get counter value skip = jsp.get_var("station_counter", 0, int) # Get GHCN stations try: stations = pd.read_csv( GHCN_PATH, dtype="str", skiprows=skip, nrows=STATIONS_PER_CYCLE, names=["id", "ghcn"],
Observation data needs to be exported in a legacy script Also, review time zones and flags on .sql files The code is licensed under the MIT license. """ from jasper import Jasper from jasper.helpers import get_stations from jasper.actions import export_csv # General configuration STATIONS_PER_CYCLE = 10 # Create Jasper instance jsp = Jasper("export.bulk.daily.legacy") # Get weather station(s) stations = get_stations( jsp, """ SELECT `stations`.`id` AS `id`, `stations`.`tz` AS `tz` FROM `stations` WHERE `stations`.`id` IN ( SELECT DISTINCT `station` FROM `inventory` WHERE `mode` IN ('D', 'H')
"Jun": "tsun6", "Jul": "tsun7", "Aug": "tsun8", "Sep": "tsun9", "Okt": "tsun10", "Nov": "tsun11", "Dez": "tsun12", }, }, ] # Variables df_full = None # DataFrame which holds all data # Create Jasper instance jsp = Jasper("import.dwd.normals.global") for parameter in PARAMETERS: # Read CSV df = pd.read_csv( f'{ENDPOINT}{parameter["dir"]}{START}_{END}.txt', sep=";", dtype={"Station": "object"}, ) # Rename columns df = df.rename(columns=parameter["stubnames"]) # Translate from wide to long df = pd.wide_to_long(df, stubnames=parameter["name"],
(0, 4), (5, 7), (8, 10), (11, 13), (13, 19), (19, 25), (25, 31), (31, 37), (37, 43), (49, 55), ] # Column names NAMES = ["time", "temp", "dwpt", "pres", "wdir", "wspd", "prcp"] # Create Jasper instance jsp = Jasper(f"import.noaa.hourly.global.{MODE}") # Weather stations stations: Union[pd.DataFrame, None] = None # Get counter value skip = jsp.get_var("station_counter", 0, int) # Get year if MODE == "historical": year = jsp.get_var("year", 1901, int) # Get ISD Lite stations try: stations = pd.read_csv( USAF_WBAN_PATH,
The code is licensed under the MIT license. """ from typing import Union from datetime import datetime, timedelta from urllib import request import pandas as pd from metar import Metar from jasper import Jasper from jasper.actions import persist from jasper.convert import temp_dwpt_to_rhum from jasper.schema import hourly_metar # Create Jasper instance jsp = Jasper("import.noaa.hourly.metar") def get_condicode(weather: list) -> Union[int, None]: """ Map METAR codes to Meteostat condicodes """ try: code = weather[0][3] condicodes = { "RA": 8, "SHRA": 17, "DZ": 7, "DZRA": 7, "FZRA": 10,
"?format=csv&time=UTC&timeframe=1&submit=Download+Data") FIRST_YEAR = datetime.now().year - 1 # Start year CURRENT_YEAR = datetime.now().year # Current year STATIONS_PER_CYCLE = 1 # How many stations per cycle? # Which parameters should be included? PARAMETERS = { "Temp (°C)": "temp", "Rel Hum (%)": "rhum", "Precip. Amount (mm)": "prcp", "Wind Dir (10s deg)": "wdir", "Wind Spd (km/h)": "wspd", "Stn Press (kPa)": "pres", } # Create Jasper instance jsp = Jasper("import.eccc.hourly.national") def load(station: str, year: int, month: int) -> pd.DataFrame(): """ Load dataset into DataFrame """ try: # CSV URL url = ( BASE_URL + f'&stationID={station["national_id"]}&Year={str(year)}&Month={str(month)}' ) # Read into DataFrame df = pd.read_csv(url, parse_dates={"time": [4]}) # Rename columns
from sys import argv from datetime import datetime from jasper import Jasper from jasper.helpers import read_file, get_stations from jasper.actions import export_csv # Task mode # 'all', 'recent' or 'live' MODE = argv[1] # General configuration STATIONS_PER_CYCLE = {"live": 60, "recent": 36, "all": 1}[MODE] # Create Jasper instance jsp = Jasper(f"export.bulk.hourly.{MODE}") def write_dump(data: list, station: str, year: int = None) -> None: """ Convert DataFrame to CSV and export to bulk server """ # The file path path = "/hourly" # Filter rows by year if set if year is not None: path += f"/{year}" data = list(filter(lambda row: int(row[0].year) == year, data)) # Export data dump