defmodule Microwaveprop.Weather.HrrrClimatology do @moduledoc """ Pre-computed mean and stddev of surface temperature from `hrrr_profiles`, keyed on `(lat, lon, month, hour)`. Used by Phase 6 to compute temperature anomaly: how much hotter (or cooler) a given hour is compared to the same grid cell's typical value for that month and time of day. The meteorologist noted that extremely hot days (~10°F above normal in summer) produce enhanced ducting even in the afternoon when the time-of-day factor normally suppresses the score. """ use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "hrrr_climatology" do field :lat, :float field :lon, :float field :month, :integer field :hour, :integer field :mean_surface_temp_c, :float field :stddev_surface_temp_c, :float field :sample_count, :integer end @type t :: %__MODULE__{ id: Ecto.UUID.t() | nil, lat: float() | nil, lon: float() | nil, month: 1..12 | nil, hour: 0..23 | nil, mean_surface_temp_c: float() | nil, stddev_surface_temp_c: float() | nil, sample_count: non_neg_integer() | nil } @spec changeset(t(), map()) :: Ecto.Changeset.t() def changeset(record, attrs) do record |> cast(attrs, [:lat, :lon, :month, :hour, :mean_surface_temp_c, :stddev_surface_temp_c, :sample_count]) |> validate_required([:lat, :lon, :month, :hour]) |> unique_constraint([:lat, :lon, :month, :hour]) end end