Stochastic physics
Stochastic physics introduces stochasticity into the parameterizations of physical process. There is conceptually several classes of how this can be done
Stochastic perturbations of the tendencies
Stochastic parameter perturbations
Stochastic perturbations to the inputs of parameterizations
all of these use random numbers created from some random processes (white noise or with some autocorrelation in space or time or sampled from some other distribution) and are applied additive or multiplicative.
Separate from this is the StochasticLeapfrog that integrates the complete model as a SDE with a Wiener noise process added to the tendencies.
Random processes
The random numbers for stochastic physics come from a random process, a model component model.random_process (nothing by default, i.e. no random numbers are drawn). Once per time step the random process draws a new random pattern after update_random! is called. The stochastic physics then read it from simulation.variables.grid.random_pattern. Currently implemented are
using SpeedyWeather
subtypes(SpeedyWeather.AbstractRandomProcess)2-element Vector{Any}:
GridWhiteNoiseProcess
SpectralAR1ProcessAll of them have the following options
standard_deviationof the pattern at every grid point, by default so that values beyond( ) are rare, seedfor reproducibility,seed = 0(default) takes a new random seed at everyinitialize!,n_patternsthe number of independent patterns (default 1),draw_on_cpu = trueto draw the random numbers on the CPU also if the model runs on GPU (slower, but the same random numbers on every architecture).
First-order autoregressive process (AR1)
SpectralAR1Process is a random process with memory. Every time step
with new (complex) standard normal random numbers time_scale
so that the pattern is also correlated in space: scales larger than the wavenumber wavenumber = 0 stands for clamp = (-1, 1) (default), as required for SPPT.
White noise in spectral space
SpectralWhiteNoiseProcess is the AR1 process above with time_scale = 0, so that
With wavenumber = 0 (default) wavenumber clamp = (-Inf, Inf)) to keep the pattern Gaussian, use e.g. clamp = (-1, 1) together with SPPT.
White noise in grid space
GridWhiteNoiseProcess draws an independent normal random number with standard deviation
Stochastic physics implementations
Currently implemented is
using SpeedyWeather
subtypes(SpeedyWeather.AbstractStochasticPhysics)1-element Vector{Any}:
StochasticallyPerturbedParameterizationTendenciesStochastically perturbed parameterization tendencies (SPPT)
SPPT is based on the idea that the dynamics
with the parameterizations being a function of the atmospheric state (column only for the single column parameterizations in SpeedyWeather), time
with
the sign up the tendencies
is never reversed the tendencies
are at most 2x larger after perturbation
So the stochasticity is multiplicative, in regions/times when the parameterizations are small, so is the perturbation, but with larger tendencies form parameterizations the perturbation is also stronger; satisfying the conceptual idea of uncertainty from the parameterizations scaling with the size of those.
You can use SPPT as follows. Start by defining a random_process, this controls how the random values
using SpeedyWeather
spectral_grid = SpectralGrid()
random_process = SpectralAR1Process(spectral_grid)SpectralAR1Process{Float32, Vector{Float32}, Int...} <: SpeedyWeather.AbstractRandomProcess
├ truncation::Int64 = 32
├ time_scale::Second = 21600 seconds
├ wavenumber::Int64 = 12
├ n_patterns::Int64 = 1
├ standard_deviation::Float32 = 0.33333334
├ clamp::Tuple{Float32, Float32} = (-1.0f0, 1.0f0)
├ seed::Int64 = 0
├ random_number_generator::Random.Xoshiro = Random.Xoshiro(0xdb2fa90498613fdf...
├ autoregressive_factor::Base.RefValue{Float32} = Base.RefValue{Float32}(0.0f...
└ arrays: noise_factors, random_numbersand you could change the length scale via wavenumber the time_scale or set a seed for reproducibility. seed=0 (default) means that a random seed is taken from Julia's global random number generator. Now we define SPPT as
stochastic_physics = StochasticallyPerturbedParameterizationTendencies(spectral_grid)StochasticallyPerturbedParameterizationTendencies{SpeedyWeather.var"#Stochastic...} <: SpeedyWeather.AbstractStochasticPhysics
├ tapering::SpeedyWeather.var"#StochasticallyPerturbedParameterizationTendenc...
└ arrays: tapertapering (by default an anonymous function hence it looks like var"#269#273" = #269 as the compiler assigns a "name") can be used to change vertically the amplitude of r, e.g tapering = σ -> σ < 0.8 ? 1 : 1 - (σ - 0.8)/0.2 (in Sigma coordinates) could be passed on a (keyword) arugment to reduce the SPPT perturbation towards the surface. A tapering
Now we pass these on to the model constructor and run a simulation
model = PrimitiveWetModel(spectral_grid; random_process, stochastic_physics)
simulation = initialize!(model)
run!(simulation, period=Day(10))
# surface humidity, kg/kg -> g/kg
k = spectral_grid.nlayers # surface layer
humid = get_step(simulation.variables.grid.humidity)[:, k]*1000
using CairoMakie
heatmap(humid, title="Surface humidity [g/kg], with SPPT", colormap=:oslo)
if we now run the same simulation again (but with a different seed for the random process, that's randomly drawn at initialize!)
simulation = initialize!(model)
run!(simulation, period=Day(10))
# surface humidity, kg/kg -> g/kg
humid = get_step(simulation.variables.grid.humidity)[:, k]*1000
heatmap(humid, title="Surface humidity [g/kg], with SPPT, other seed", colormap=:oslo)
Implementing your stochastic parameterizations with their own random processes
If you want to implement a new stochastic parameterization with an independent noise realization, you can just make a random process one of the fields of your parameterization. In this case however, you have to manually update/draw new numbers with update_random! within your parameterization, e.g. in its parameterization!(vars, ...) method that is called once per time step before the column parameterizations. A minimal example that heats or cools the surface layer randomly (see Define your own parameterizations for the general interface)
using SpeedyWeather
struct StochasticHeating{NF, RP} <: SpeedyWeather.AbstractStochasticPhysics
amplitude::NF # heating amplitude [K/s]
random_process::RP # its own random process
end
StochasticHeating(SG::SpectralGrid; amplitude = 1.0e-4) =
StochasticHeating(SG.NF(amplitude), GridWhiteNoiseProcess(SG))
# its own pattern to draw into, separate from the `random_pattern` of `model.random_process`
SpeedyWeather.variables(::StochasticHeating) =
(ParameterizationVariable(:heating_noise, SpeedyWeather.Grid2D(), desc = "Random heating pattern", units = "1"),)
# initialize (and seed) the random process with the parameterization
SpeedyWeather.initialize!(heating::StochasticHeating, model::PrimitiveEquation) =
SpeedyWeather.initialize!(heating.random_process, model)
# draw new random numbers once per time step
SpeedyWeather.parameterization!(vars::Variables, heating::StochasticHeating, model::PrimitiveEquation) =
SpeedyWeather.update_random!(vars.parameterizations.heating_noise, heating.random_process)
# then use them in every column
Base.@propagate_inbounds function SpeedyWeather.parameterization!(ij, vars::Variables, heating::StochasticHeating, model)
surface = size(vars.tendencies.grid.temperature, 2)
vars.tendencies.grid.temperature[ij, surface] += heating.amplitude * vars.parameterizations.heating_noise[ij]
end
spectral_grid = SpectralGrid(truncation = 32, nlayers = 8)
stochastic_physics = StochasticHeating(spectral_grid)
model = PrimitiveWetModel(spectral_grid; stochastic_physics)
simulation = initialize!(model)
run!(simulation, period = Day(1)) Surface vorticity [1/s]
┌────────────────────────────────────────────────────────────┐1.0f-5
90│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄│┌──┐
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
˚N│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄││▄▄│
-90│▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄│└──┘
└────────────────────────────────────────────────────────────┘-1.0f-5
0 ˚E 360Passed on as stochastic_physics it is initialized and executed (after all other parameterizations) by default. It does not need a model.random_process, and with one, both draw independent noise (unless given the same seed).