Esempio n. 1
0
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:
        # Fetch data
        data = result.fetchall()

        # Export data dump
        export_csv(
Esempio n. 2
0
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"
            req = request.Request(
                url, headers={"User-Agent": "meteostat.net [email protected]"}
            )
Esempio n. 3
0
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 = 10

# Create Jasper instance
jsp = Jasper("export.bulk.daily")

# Get weather station(s)
stations = get_stations(jsp, read_file("daily_stations.sql"),
                        STATIONS_PER_CYCLE)

# Export data for each weather station
for station in stations:
    result = jsp.query(read_file("daily.sql"), {
        "station": station[0],
        "timezone": station[1]
    })

    if result.rowcount > 0:
        # Fetch data
        data = result.fetchall()

        # Export data dump
        export_csv(jsp, list(map(lambda d: d[:11], data)),
Esempio n. 4
0
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])
        except BaseException:
Esempio n. 5
0
        "sleetandthunder": 25,
        "sleetshowers": 19,
        "sleetshowersandthunder": 25,
        "snow": 15,
        "snowandthunder": 25,
        "snowshowers": 21,
        "snowshowersandthunder": 25,
    }

    return condicodes.get(str(code).split("_")[0], None)


# Get weather stations
stations = get_stations(
    jsp,
    read_file("model_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 = (
                "https://api.met.no/weatherapi/locationforecast/2.0/complete.json?"
                + f"altitude={station[3]}&lat={station[1]}&lon={station[2]}")
            req = request.Request(
Esempio n. 6
0
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"
        }

        jsp.query(
            read_file("stations_import.sql"),
            {
                "id":
                data["id"],
                "country":
                data["country"],
                "region":
                data["region"],
                "name":
                data["name"]["en"],
                "name_alt":
                json.dumps(name_alt, ensure_ascii=False, sort_keys=True),
                "national_id":
                data["identifiers"]["national"] if
                ("national" in data["identifiers"]) else None,
                "wmo":
                data["identifiers"]["wmo"]
                if "wmo" in data["identifiers"] else None,
                "icao":
                data["identifiers"]["icao"]
                if "icao" in data["identifiers"] else None,
                "iata":
                data["identifiers"]["iata"]
                if "iata" in data["identifiers"] else None,
                "ghcn":
                data["identifiers"]["ghcn"]
                if "ghcn" in data["identifiers"] else None,
                "wban":
                data["identifiers"]["wban"]
                if "wban" in data["identifiers"] else None,
                "usaf":
                data["identifiers"]["usaf"]
                if "usaf" in data["identifiers"] else None,
                "mosmix":
                data["identifiers"]["mosmix"]
                if "mosmix" in data["identifiers"] else None,
                "lat":
                data["location"]["latitude"],
                "lon":
                data["location"]["longitude"],
                "elevation":
                data["location"]["elevation"],
                "tz":
                data["timezone"],
            },
        )

    except BaseException:
        pass
Esempio n. 7
0
                    [
                        "".join(sorted(list(set(flag)))) if flag is not None else None
                        for flag in d[13:]
                    ]
                ),
                data,
            )
        ),
        f"{path}/{station}.map.csv.gz",
    )


# Get weather stations
stations = get_stations(
    jsp,
    read_file(f"hourly_stations_{MODE}.sql"),
    STATIONS_PER_CYCLE,
)

# Start & end year
now = datetime.now()
start_year = now.year - 1 if MODE in ("recent", "live") else 1890
end_year = now.year + 1

# Export data for each weather station
for station in stations:
    result = jsp.query(
        read_file("hourly.sql"),
        {
            "station": station[0],
            "start_datetime": f"{start_year}-01-01 00:00:00",