CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-meteostat

Access and analyze historical weather and climate data with Python.

Pending
Overview
Eval results
Files

hourly-data.mddocs/

Hourly Weather Data

The Hourly class provides access to hourly meteorological observations including temperature, humidity, precipitation, wind conditions, pressure, and weather codes. It supports timezone localization and includes both observational and model data sources.

Capabilities

Hourly Data Initialization

Create an hourly time series for weather stations or geographic points with flexible time range and data source options.

class Hourly:
    def __init__(self, loc: Union[pd.DataFrame, Point, list, str], start=datetime(1890, 1, 1, 0, 0, 0), end=datetime.combine(datetime.today().date() + timedelta(days=10), datetime.max.time()), timezone: Optional[str] = None, model=True, flags=False) -> None:
        """
        Initialize hourly weather data retrieval.
        
        Parameters:
        - loc: Union[pd.DataFrame, Point, list, str]
            - pd.DataFrame: Station data from Stations.fetch()
            - Point: Geographic point for automatic station selection
            - list: List of station IDs  
            - str: Single station ID
        - start: datetime, start of time period (default: 1890-01-01)
        - end: datetime, end of time period (default: 10 days from today)
        - timezone: str, optional IANA timezone name for localization
        - model: bool, whether to include model/forecast data (default: True)
        - flags: bool, whether to include data source flags (default: False)
        """

Row Count Estimation

Calculate expected number of hourly observations for the defined time period.

def expected_rows(self) -> int:
    """
    Return expected number of hourly rows for the date range.
    
    Returns:
    int, expected number of hourly observations
    """

Data Columns

Hourly data includes the following meteorological parameters:

# Temperature measurements (°C)
temp: float       # Air temperature 
dwpt: float       # Dew point temperature

# Humidity and precipitation
rhum: float       # Relative humidity (%)
prcp: float       # Precipitation amount (mm)

# Snow and winter weather  
snow: float       # Snow depth (mm)

# Wind measurements
wdir: float       # Wind direction (degrees, 0-360)
wspd: float       # Wind speed (km/h)
wpgt: float       # Wind gust speed (km/h)

# Atmospheric pressure
pres: float       # Sea level pressure (hPa)

# Solar and weather conditions
tsun: float       # Sunshine duration (minutes)
coco: float       # Weather condition code (1-27)

# Data quality flags (when flags=True)
temp_flag: str    # Temperature data source flag
dwpt_flag: str    # Dew point data source flag
# ... (additional _flag columns for each parameter)

Usage Examples

Basic Hourly Data Retrieval

from datetime import datetime
from meteostat import Point, Hourly

# Set time period
start = datetime(2020, 1, 1)
end = datetime(2020, 1, 31)

# Create point for Vancouver, BC
vancouver = Point(49.2497, -123.1193, 70)

# Get hourly data
data = Hourly(vancouver, start, end)
hourly_data = data.fetch()

print(f"Retrieved {len(hourly_data)} hourly observations")
print(hourly_data[['temp', 'rhum', 'prcp', 'wspd']].head())

Station-Based Hourly Data

from datetime import datetime
from meteostat import Stations, Hourly

# Select stations in New York area
stations = Stations().nearby(40.7128, -74.0060, 50000).fetch(5)

# Get hourly data for multiple stations
start = datetime(2020, 6, 1)
end = datetime(2020, 6, 7)

data = Hourly(stations, start, end)
hourly_data = data.fetch()

# Data includes station column for multi-station queries
print(hourly_data.groupby('station')['temp'].mean())

Timezone Localization

from datetime import datetime
from meteostat import Point, Hourly

# Create point for Tokyo
tokyo = Point(35.6762, 139.6503)

# Get hourly data with Tokyo timezone
start = datetime(2020, 7, 1, 0, 0, 0)
end = datetime(2020, 7, 1, 23, 59, 59)

data = Hourly(tokyo, start, end, timezone='Asia/Tokyo')
hourly_data = data.fetch()

print("Hourly temperatures in Tokyo (JST):")
print(hourly_data[['temp']].head(10))

Including Data Source Flags

from datetime import datetime
from meteostat import Point, Hourly

# Get hourly data with source quality flags
location = Point(52.5200, 13.4050)  # Berlin
start = datetime(2020, 12, 1)  
end = datetime(2020, 12, 7)

data = Hourly(location, start, end, flags=True)
hourly_data = data.fetch()

# Examine data sources
print("Data source flags:")
print(hourly_data[['temp', 'temp_flag', 'prcp', 'prcp_flag']].head())

Excluding Model Data

from datetime import datetime
from meteostat import Point, Hourly

# Get only observational data (no model/forecast data)
location = Point(41.8781, -87.6298)  # Chicago
start = datetime(2019, 1, 1)
end = datetime(2019, 1, 31)

data = Hourly(location, start, end, model=False)
observational_data = data.fetch()

print(f"Observational data points: {len(observational_data)}")

Data Source Flags

When flags=True, each meteorological parameter includes a corresponding source flag indicating data origin:

# Source flag meanings
"A": str  # High-quality government weather service data
"B": str  # ISD Lite observational data  
"C": str  # SYNOP observational data
"D": str  # METAR aviation weather reports
"E": str  # Model/forecast data (reanalysis, numerical weather prediction)

Weather Condition Codes

The coco parameter uses Meteostat's standardized condition codes:

# Condition code ranges
1-4:   Clear to overcast conditions
5-6:   Fog conditions  
7-13:  Rain and freezing rain
14-16: Snow conditions
17-22: Shower conditions
23-27: Thunderstorm and severe weather

Use the units.condition() function to convert codes to descriptive strings:

from meteostat import units

# Convert condition code to description
condition_desc = hourly_data['coco'].apply(units.condition)
print(condition_desc.value_counts())

Time Series Processing

Hourly data objects inherit all time series processing methods:

# Data retrieval and analysis
def fetch(self) -> pd.DataFrame: ...
def count(self) -> int: ...
def coverage(self): ...

# Data processing
def normalize(self): ...
def interpolate(self, limit: int = 3): ...
def aggregate(self, freq: str, spatial: bool = False): ...
def convert(self, units: dict): ...

# Utility methods
def stations(self) -> pd.Index: ...
def clear_cache(self): ...

Install with Tessl CLI

npx tessl i tessl/pypi-meteostat

docs

climate-normals.md

daily-data.md

data-processing.md

geographic-points.md

hourly-data.md

index.md

monthly-data.md

unit-conversions.md

weather-stations.md

tile.json