Skip to content

Parser

riweather.parser.ISDRecord pydantic-model

Bases: BaseModel

ISD data record.

Show JSON schema:
{
  "$defs": {
    "AdditionalData": {
      "description": "Additional data section.\n\n!!! warning\n    Not yet implemented. Reserved for future use.",
      "properties": {},
      "title": "AdditionalData",
      "type": "object"
    },
    "AirTemperatureObservation": {
      "description": "An observation of current air temperature.",
      "properties": {
        "temperature_c": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Temperature C"
        },
        "quality_code": {
          "maxLength": 1,
          "title": "Quality Code",
          "type": "string"
        }
      },
      "required": [
        "temperature_c",
        "quality_code"
      ],
      "title": "AirTemperatureObservation",
      "type": "object"
    },
    "AtmosphericPressureObservation": {
      "description": "An observation of current atmospheric pressure.",
      "properties": {
        "pressure": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Pressure"
        },
        "quality_code": {
          "maxLength": 1,
          "title": "Quality Code",
          "type": "string"
        }
      },
      "required": [
        "pressure",
        "quality_code"
      ],
      "title": "AtmosphericPressureObservation",
      "type": "object"
    },
    "ControlData": {
      "description": "Control data section.\n\n!!! usage\n    [Control Data](../about/integrated_surface_dataset.md#control-data)",
      "properties": {
        "total_variable_characters": {
          "title": "Total Variable Characters",
          "type": "integer"
        },
        "usaf_id": {
          "maxLength": 6,
          "minLength": 6,
          "pattern": "^\\w*$",
          "title": "Usaf Id",
          "type": "string"
        },
        "wban_id": {
          "maxLength": 5,
          "minLength": 5,
          "pattern": "^\\d*$",
          "title": "Wban Id",
          "type": "string"
        },
        "dt": {
          "format": "date-time",
          "title": "Dt",
          "type": "string"
        },
        "data_source_flag": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Data Source Flag"
        },
        "latitude": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Latitude"
        },
        "longitude": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Longitude"
        },
        "report_type_code": {
          "anyOf": [
            {
              "maxLength": 5,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Report Type Code"
        },
        "elevation": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Elevation"
        },
        "call_letter_id": {
          "anyOf": [
            {
              "maxLength": 5,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Call Letter Id"
        },
        "qc_process_name": {
          "maxLength": 4,
          "title": "Qc Process Name",
          "type": "string"
        }
      },
      "required": [
        "total_variable_characters",
        "usaf_id",
        "wban_id",
        "dt",
        "data_source_flag",
        "latitude",
        "longitude",
        "report_type_code",
        "elevation",
        "call_letter_id",
        "qc_process_name"
      ],
      "title": "ControlData",
      "type": "object"
    },
    "MandatoryData": {
      "description": "Mandatory data section.",
      "properties": {
        "wind": {
          "$ref": "#/$defs/WindObservation"
        },
        "ceiling": {
          "$ref": "#/$defs/SkyConditionObservation"
        },
        "visibility": {
          "$ref": "#/$defs/VisibilityObservation"
        },
        "air_temperature": {
          "$ref": "#/$defs/AirTemperatureObservation"
        },
        "dew_point": {
          "$ref": "#/$defs/AirTemperatureObservation"
        },
        "sea_level_pressure": {
          "$ref": "#/$defs/AtmosphericPressureObservation"
        }
      },
      "required": [
        "wind",
        "ceiling",
        "visibility",
        "air_temperature",
        "dew_point",
        "sea_level_pressure"
      ],
      "title": "MandatoryData",
      "type": "object"
    },
    "SkyConditionObservation": {
      "description": "An observation of current sky condition.",
      "properties": {
        "ceiling_height": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ceiling Height"
        },
        "ceiling_quality_code": {
          "maxLength": 1,
          "title": "Ceiling Quality Code",
          "type": "string"
        },
        "ceiling_determination_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ceiling Determination Code"
        },
        "cavok_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Cavok Code"
        }
      },
      "required": [
        "ceiling_height",
        "ceiling_quality_code",
        "ceiling_determination_code",
        "cavok_code"
      ],
      "title": "SkyConditionObservation",
      "type": "object"
    },
    "VisibilityObservation": {
      "description": "An observation of current sky visibility.",
      "properties": {
        "distance": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Distance"
        },
        "distance_quality_code": {
          "maxLength": 1,
          "title": "Distance Quality Code",
          "type": "string"
        },
        "variability_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Variability Code"
        },
        "variability_quality_code": {
          "maxLength": 1,
          "title": "Variability Quality Code",
          "type": "string"
        }
      },
      "required": [
        "distance",
        "distance_quality_code",
        "variability_code",
        "variability_quality_code"
      ],
      "title": "VisibilityObservation",
      "type": "object"
    },
    "WindObservation": {
      "description": "An observation of current wind speed and direction.",
      "properties": {
        "direction_angle": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Direction Angle"
        },
        "direction_quality_code": {
          "maxLength": 1,
          "title": "Direction Quality Code",
          "type": "string"
        },
        "type_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Type Code"
        },
        "speed_rate": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Speed Rate"
        },
        "speed_quality_code": {
          "maxLength": 1,
          "title": "Speed Quality Code",
          "type": "string"
        }
      },
      "required": [
        "direction_angle",
        "direction_quality_code",
        "type_code",
        "speed_rate",
        "speed_quality_code"
      ],
      "title": "WindObservation",
      "type": "object"
    }
  },
  "description": "ISD data record.",
  "properties": {
    "control": {
      "$ref": "#/$defs/ControlData"
    },
    "mandatory": {
      "$ref": "#/$defs/MandatoryData"
    },
    "additional": {
      "items": {
        "$ref": "#/$defs/AdditionalData"
      },
      "title": "Additional",
      "type": "array"
    }
  },
  "required": [
    "control",
    "mandatory"
  ],
  "title": "ISDRecord",
  "type": "object"
}

Fields:

riweather.parser.ControlData pydantic-model

Bases: BaseModel

Control data section.

Usage

Control Data

Show JSON schema:
{
  "description": "Control data section.\n\n!!! usage\n    [Control Data](../about/integrated_surface_dataset.md#control-data)",
  "properties": {
    "total_variable_characters": {
      "title": "Total Variable Characters",
      "type": "integer"
    },
    "usaf_id": {
      "maxLength": 6,
      "minLength": 6,
      "pattern": "^\\w*$",
      "title": "Usaf Id",
      "type": "string"
    },
    "wban_id": {
      "maxLength": 5,
      "minLength": 5,
      "pattern": "^\\d*$",
      "title": "Wban Id",
      "type": "string"
    },
    "dt": {
      "format": "date-time",
      "title": "Dt",
      "type": "string"
    },
    "data_source_flag": {
      "anyOf": [
        {
          "maxLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Data Source Flag"
    },
    "latitude": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Latitude"
    },
    "longitude": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Longitude"
    },
    "report_type_code": {
      "anyOf": [
        {
          "maxLength": 5,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Report Type Code"
    },
    "elevation": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Elevation"
    },
    "call_letter_id": {
      "anyOf": [
        {
          "maxLength": 5,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Call Letter Id"
    },
    "qc_process_name": {
      "maxLength": 4,
      "title": "Qc Process Name",
      "type": "string"
    }
  },
  "required": [
    "total_variable_characters",
    "usaf_id",
    "wban_id",
    "dt",
    "data_source_flag",
    "latitude",
    "longitude",
    "report_type_code",
    "elevation",
    "call_letter_id",
    "qc_process_name"
  ],
  "title": "ControlData",
  "type": "object"
}

Fields:

Validators:

total_variable_characters pydantic-field

total_variable_characters

Total number of characters in the variable length section. The total record length equals 105 plus the value stored in this field.

usaf_id pydantic-field

usaf_id

United States Air Force (USAF) Master Station Catalog identifier. For United States stations, this is a value between 720000 and 799999.

wban_id pydantic-field

wban_id

NCEI Weather Bureau Army-Navy (WBAN) identifier.

dt pydantic-field

dt

The date and time of the observation, based on Coordinated Universal Time (UTC).

data_source_flag pydantic-field

data_source_flag

A flag indicating the source or combination of sources used in creating the observation.

latitude pydantic-field

latitude

The latitude coordinate of the observation. Negative values are located in the southern hemisphere.

longitude pydantic-field

longitude

The longitude coordinate of the observation. Negative values are located in the western hemisphere.

report_type_code pydantic-field

report_type_code

A flag indicating the type of geophysical surface observation.

elevation pydantic-field

elevation

The elevation of the observation relative to Mean Sea Level, in meters.

call_letter_id pydantic-field

call_letter_id

The call letters associated with the station.

qc_process_name pydantic-field

qc_process_name

Quality control process applied to the observation.

parse_datetime pydantic-validator

parse_datetime(value)

Parse dates and times as they appear in ISD to a tz-aware datetime object.

This is a Pydantic validator, users shouldn’t need to call this directly (though they can).

Parameters:

  • value (Any) –

    The portion of the record in the data file corresponding to the date and time fields, characters 16-27. This is always in the form YYYYMMDDHHMM.

Returns:

  • datetime

    A timezone-aware datetime object representing the date and time, set to UTC.

Examples:

>>> ControlData.parse_datetime("201809220115")
datetime.datetime(2018, 9, 22, 1, 15, tzinfo=datetime.timezone.utc)
>>> ControlData.parse_datetime("201809310115")
Traceback (most recent call last):
ValueError: day is out of range for month
Source code in src/riweather/parser.py
@field_validator("dt", mode="before")
@classmethod
def parse_datetime(cls, value: Any) -> datetime:
    """Parse dates and times as they appear in ISD to a tz-aware datetime object.

    This is a [Pydantic validator](https://docs.pydantic.dev/latest/concepts/validators/), users
    shouldn't need to call this directly (though they can).

    Args:
        value: The portion of the record in the data file corresponding to the date and
            time fields, characters 16-27. This is always in the form `YYYYMMDDHHMM`.

    Returns:
        A timezone-aware datetime object representing the date and time, set to UTC.

    Examples:
        >>> ControlData.parse_datetime("201809220115")
        datetime.datetime(2018, 9, 22, 1, 15, tzinfo=datetime.timezone.utc)

        >>> ControlData.parse_datetime("201809310115")
        Traceback (most recent call last):
        ValueError: day is out of range for month
    """
    return datetime.strptime(value, "%Y%m%d%H%M").replace(tzinfo=timezone.utc)

riweather.parser.MandatoryData pydantic-model

Bases: BaseModel

Mandatory data section.

Show JSON schema:
{
  "$defs": {
    "AirTemperatureObservation": {
      "description": "An observation of current air temperature.",
      "properties": {
        "temperature_c": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Temperature C"
        },
        "quality_code": {
          "maxLength": 1,
          "title": "Quality Code",
          "type": "string"
        }
      },
      "required": [
        "temperature_c",
        "quality_code"
      ],
      "title": "AirTemperatureObservation",
      "type": "object"
    },
    "AtmosphericPressureObservation": {
      "description": "An observation of current atmospheric pressure.",
      "properties": {
        "pressure": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Pressure"
        },
        "quality_code": {
          "maxLength": 1,
          "title": "Quality Code",
          "type": "string"
        }
      },
      "required": [
        "pressure",
        "quality_code"
      ],
      "title": "AtmosphericPressureObservation",
      "type": "object"
    },
    "SkyConditionObservation": {
      "description": "An observation of current sky condition.",
      "properties": {
        "ceiling_height": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ceiling Height"
        },
        "ceiling_quality_code": {
          "maxLength": 1,
          "title": "Ceiling Quality Code",
          "type": "string"
        },
        "ceiling_determination_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ceiling Determination Code"
        },
        "cavok_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Cavok Code"
        }
      },
      "required": [
        "ceiling_height",
        "ceiling_quality_code",
        "ceiling_determination_code",
        "cavok_code"
      ],
      "title": "SkyConditionObservation",
      "type": "object"
    },
    "VisibilityObservation": {
      "description": "An observation of current sky visibility.",
      "properties": {
        "distance": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Distance"
        },
        "distance_quality_code": {
          "maxLength": 1,
          "title": "Distance Quality Code",
          "type": "string"
        },
        "variability_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Variability Code"
        },
        "variability_quality_code": {
          "maxLength": 1,
          "title": "Variability Quality Code",
          "type": "string"
        }
      },
      "required": [
        "distance",
        "distance_quality_code",
        "variability_code",
        "variability_quality_code"
      ],
      "title": "VisibilityObservation",
      "type": "object"
    },
    "WindObservation": {
      "description": "An observation of current wind speed and direction.",
      "properties": {
        "direction_angle": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Direction Angle"
        },
        "direction_quality_code": {
          "maxLength": 1,
          "title": "Direction Quality Code",
          "type": "string"
        },
        "type_code": {
          "anyOf": [
            {
              "maxLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Type Code"
        },
        "speed_rate": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Speed Rate"
        },
        "speed_quality_code": {
          "maxLength": 1,
          "title": "Speed Quality Code",
          "type": "string"
        }
      },
      "required": [
        "direction_angle",
        "direction_quality_code",
        "type_code",
        "speed_rate",
        "speed_quality_code"
      ],
      "title": "WindObservation",
      "type": "object"
    }
  },
  "description": "Mandatory data section.",
  "properties": {
    "wind": {
      "$ref": "#/$defs/WindObservation"
    },
    "ceiling": {
      "$ref": "#/$defs/SkyConditionObservation"
    },
    "visibility": {
      "$ref": "#/$defs/VisibilityObservation"
    },
    "air_temperature": {
      "$ref": "#/$defs/AirTemperatureObservation"
    },
    "dew_point": {
      "$ref": "#/$defs/AirTemperatureObservation"
    },
    "sea_level_pressure": {
      "$ref": "#/$defs/AtmosphericPressureObservation"
    }
  },
  "required": [
    "wind",
    "ceiling",
    "visibility",
    "air_temperature",
    "dew_point",
    "sea_level_pressure"
  ],
  "title": "MandatoryData",
  "type": "object"
}

Fields:

riweather.parser.AdditionalData pydantic-model

Bases: BaseModel

Additional data section.

Warning

Not yet implemented. Reserved for future use.

Show JSON schema:
{
  "description": "Additional data section.\n\n!!! warning\n    Not yet implemented. Reserved for future use.",
  "properties": {},
  "title": "AdditionalData",
  "type": "object"
}

riweather.parser.WindObservation pydantic-model

Bases: BaseModel

An observation of current wind speed and direction.

Show JSON schema:
{
  "description": "An observation of current wind speed and direction.",
  "properties": {
    "direction_angle": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Direction Angle"
    },
    "direction_quality_code": {
      "maxLength": 1,
      "title": "Direction Quality Code",
      "type": "string"
    },
    "type_code": {
      "anyOf": [
        {
          "maxLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Type Code"
    },
    "speed_rate": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Speed Rate"
    },
    "speed_quality_code": {
      "maxLength": 1,
      "title": "Speed Quality Code",
      "type": "string"
    }
  },
  "required": [
    "direction_angle",
    "direction_quality_code",
    "type_code",
    "speed_rate",
    "speed_quality_code"
  ],
  "title": "WindObservation",
  "type": "object"
}

Fields:

direction_angle pydantic-field

direction_angle

The angle, measured in angular degrees in a clockwise direction, between true north and the direction from which the wind is blowing.

direction_quality_code pydantic-field

direction_quality_code

Quality status of the reported wind direction angle.

type_code pydantic-field

type_code

Code that denotes the character of the wind observation.

speed_rate pydantic-field

speed_rate

The rate of horizontal travel of air past a fixed point, in meters per second.

speed_quality_code pydantic-field

speed_quality_code

Quality status of the reported wind speed rate.

riweather.parser.SkyConditionObservation pydantic-model

Bases: BaseModel

An observation of current sky condition.

Show JSON schema:
{
  "description": "An observation of current sky condition.",
  "properties": {
    "ceiling_height": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Ceiling Height"
    },
    "ceiling_quality_code": {
      "maxLength": 1,
      "title": "Ceiling Quality Code",
      "type": "string"
    },
    "ceiling_determination_code": {
      "anyOf": [
        {
          "maxLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Ceiling Determination Code"
    },
    "cavok_code": {
      "anyOf": [
        {
          "maxLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Cavok Code"
    }
  },
  "required": [
    "ceiling_height",
    "ceiling_quality_code",
    "ceiling_determination_code",
    "cavok_code"
  ],
  "title": "SkyConditionObservation",
  "type": "object"
}

Fields:

ceiling_height pydantic-field

ceiling_height

The height above ground level (AGL) of the lowest cloud or obscuring phenomena layer aloft with 5/8 or more summation total sky cover, which may be predominantly opaque, or the vertical visibility into a surface-based obstruction.

Note

Unlimited ceiling height coded as 22000.

ceiling_quality_code pydantic-field

ceiling_quality_code

Quality status of the reported ceiling height.

ceiling_determination_code pydantic-field

ceiling_determination_code

Code that denotes the method used to determine the ceiling.

cavok_code pydantic-field

cavok_code

Code that represents whether the “Ceiling and Visibility Okay” (CAVOK) condition has been reported.

Value Description
N No
Y Yes
9 Missing

riweather.parser.VisibilityObservation pydantic-model

Bases: BaseModel

An observation of current sky visibility.

Show JSON schema:
{
  "description": "An observation of current sky visibility.",
  "properties": {
    "distance": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Distance"
    },
    "distance_quality_code": {
      "maxLength": 1,
      "title": "Distance Quality Code",
      "type": "string"
    },
    "variability_code": {
      "anyOf": [
        {
          "maxLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Variability Code"
    },
    "variability_quality_code": {
      "maxLength": 1,
      "title": "Variability Quality Code",
      "type": "string"
    }
  },
  "required": [
    "distance",
    "distance_quality_code",
    "variability_code",
    "variability_quality_code"
  ],
  "title": "VisibilityObservation",
  "type": "object"
}

Fields:

distance pydantic-field

distance

The horizontal distance, in meters, at which an object can be seen and identified. Values greater than 160,000m are entered as 160000.

distance_quality_code pydantic-field

distance_quality_code

Quality status of the reported visibility distance.

variability_code pydantic-field

variability_code

Code that denotes whether or not the reported visibility is variable.

Value Description
N Not variable
V Variable
9 Missing

variability_quality_code pydantic-field

variability_quality_code

Quality status of the reported variability code.

riweather.parser.AirTemperatureObservation pydantic-model

Bases: BaseModel

An observation of current air temperature.

Show JSON schema:
{
  "description": "An observation of current air temperature.",
  "properties": {
    "temperature_c": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Temperature C"
    },
    "quality_code": {
      "maxLength": 1,
      "title": "Quality Code",
      "type": "string"
    }
  },
  "required": [
    "temperature_c",
    "quality_code"
  ],
  "title": "AirTemperatureObservation",
  "type": "object"
}

Fields:

temperature_c pydantic-field

temperature_c

Temperature in degrees Celsius.

quality_code pydantic-field

quality_code

Quality status of the reported temperature.

temperature_f

temperature_f()

The temperature of the air, in degrees Fahrenheit.

Source code in src/riweather/parser.py
@computed_field
def temperature_f(self) -> float | None:
    """The temperature of the air, in degrees Fahrenheit."""
    return self.temperature_c * 1.8 + 32 if self.temperature_c is not None else None

riweather.parser.AtmosphericPressureObservation pydantic-model

Bases: BaseModel

An observation of current atmospheric pressure.

Show JSON schema:
{
  "description": "An observation of current atmospheric pressure.",
  "properties": {
    "pressure": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Pressure"
    },
    "quality_code": {
      "maxLength": 1,
      "title": "Quality Code",
      "type": "string"
    }
  },
  "required": [
    "pressure",
    "quality_code"
  ],
  "title": "AtmosphericPressureObservation",
  "type": "object"
}

Fields:

pressure pydantic-field

pressure

Air pressure relative to Mean Sea Level (MSL).

quality_code pydantic-field

quality_code

Quality status of the reported atmospheric pressure.