prop/lib/microwaveprop/weather/surface_observation.ex
Graham McIntire 6489f08138
Add weather data schema, context, sounding params, and IEM ingestion
Store surface observations (ASOS) and upper-air soundings (RAOB) alongside
QSOs for atmospheric propagation correlation. Three new tables: weather_stations,
surface_observations, and soundings with JSONB profiles and pre-computed derived
parameters (refractivity, gradients, duct detection, stability indices).

Includes IEM API client for historical data import and import script seeded
with 95 ASOS + 9 sounding stations from PropCast coverage area.
2026-03-28 15:57:19 -05:00

35 lines
1.1 KiB
Elixir

defmodule Microwaveprop.Weather.SurfaceObservation do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "surface_observations" do
belongs_to :station, Microwaveprop.Weather.Station
field :observed_at, :utc_datetime
field :temp_f, :float
field :dewpoint_f, :float
field :relative_humidity, :float
field :wind_speed_kts, :float
field :wind_direction_deg, :integer
field :sea_level_pressure_mb, :float
field :altimeter_setting, :float
field :sky_condition, :string
timestamps(type: :utc_datetime)
end
@required_fields ~w(station_id observed_at)a
@optional_fields ~w(temp_f dewpoint_f relative_humidity wind_speed_kts wind_direction_deg sea_level_pressure_mb altimeter_setting sky_condition)a
def changeset(observation, attrs) do
observation
|> cast(attrs, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
|> foreign_key_constraint(:station_id)
|> unique_constraint([:station_id, :observed_at])
end
end