[1]:
%reload_ext eradiate.notebook.tutorials
Last updated: 2024-11-27 11:44 (eradiate v0.29.3.dev0)
Variance Report#
Overview
In this tutorial, we introduce variance report in Eradiate.
Prerequisites
Ability to run 1D simulations and visualize the results (see eradiate_quickstart).
What you will learn
How to turn on variance report for a simulation.
How to access and visualize the variance reported by a simulation.
In this tutorial, we will show you how to use Eradiate to retrieve the variance of the results of your simulations. Let’s start by running a simple 1D simulation and viewing its result.
[2]:
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
import eradiate
from eradiate import unit_registry as ureg
from eradiate import scenes as ertsc
eradiate.set_mode("mono")
[3]:
def run_exp(spp=10000, integrator=None):
"""
Generate and run an atmosphere experiment over a hemisphere plane cut.
"""
if integrator is None:
integrator = ertsc.integrators.VolPathIntegrator()
exp = eradiate.experiments.AtmosphereExperiment(
surface={
"type":"lambertian",
"reflectance":0.5
},
illumination={
"type": "directional",
"zenith": 30,
"azimuth": 0,
},
atmosphere={
"type": "molecular",
"has_absorption":False
},
measures= ertsc.measure.MultiDistantMeasure.hplane(
zeniths=np.arange(-85,86,5),
azimuth=0.,
spp = spp,
srf={"type": "multi_delta", "wavelengths": 550*ureg.nm},
),
integrator=integrator,
)
return eradiate.run(exp,spp)
result = run_exp(spp=10000)
result
[3]:
<xarray.Dataset> Size: 2kB Dimensions: (sza: 1, saa: 1, w: 1, y_index: 1, x_index: 35) Coordinates: * sza (sza) int64 8B 30 * saa (saa) int64 8B 0 * w (w) float64 8B 550.0 * y_index (y_index) int64 8B 0 y (y_index) float64 8B 0.0 * x_index (x_index) int64 280B 0 1 2 3 4 5 6 7 ... 27 28 29 30 31 32 33 34 x (x_index) float64 280B 0.0 0.02941 0.05882 ... 0.9412 0.9706 1.0 vza (x_index, y_index) int64 280B -85 -80 -75 -70 ... 70 75 80 85 vaa (x_index, y_index) int64 280B 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 Data variables: radiance (w, y_index, x_index, saa, sza) float64 280B 0.2736 ... 0.2856 brdf (w, y_index, x_index, saa, sza) float64 280B 0.1656 ... 0.1728 brf (w, y_index, x_index, saa, sza) float64 280B 0.5202 ... 0.543 irradiance (sza, saa, w) float64 8B 1.652
By default, variance is not available in the results. Variance report can be activated by setting the moment
parameter of any integrator to True
:
[10]:
integrator = ertsc.integrators.PiecewiseVolPathIntegrator(moment=True)
We can now run the simulations again, with our new integrator.
[11]:
var_result = run_exp(spp=10000, integrator=integrator)
var_result
[11]:
<xarray.Dataset> Size: 2kB Dimensions: (sza: 1, saa: 1, w: 1, y_index: 1, x_index: 35) Coordinates: * sza (sza) int64 8B 30 * saa (saa) int64 8B 0 * w (w) float64 8B 550.0 * y_index (y_index) int64 8B 0 y (y_index) float64 8B 0.0 * x_index (x_index) int64 280B 0 1 2 3 4 5 6 7 ... 28 29 30 31 32 33 34 x (x_index) float64 280B 0.0 0.02941 0.05882 ... 0.9706 1.0 vza (x_index, y_index) int64 280B -85 -80 -75 -70 ... 70 75 80 85 vaa (x_index, y_index) int64 280B 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 Data variables: radiance (w, y_index, x_index, saa, sza) float64 280B 0.277 ... 0.2866 radiance_var (w, y_index, x_index, saa, sza) float64 280B 1.768e-06 ... ... brdf (w, y_index, x_index, saa, sza) float64 280B 0.1677 ... 0.1735 brf (w, y_index, x_index, saa, sza) float64 280B 0.5267 ... 0.545 irradiance (sza, saa, w) float64 8B 1.652
Note the new radiance_var
data variable, which is the radiance variance of our simulation. We can visualize it by plotting two standard deviations around the resulting radiance.
[19]:
# Get the standard deviation from the variance.
std = np.sqrt(var_result.radiance_var)
[23]:
fig, ax = plt.subplots(1,1,figsize=(1*4.5,4), layout="constrained")
upper = (var_result.radiance + 2*std).squeeze()
lower = (var_result.radiance - 2*std).squeeze()
vza = var_result.vza.squeeze()
ax.plot(var_result.vza, var_result.radiance.squeeze().values, linestyle=":", marker=".")
ax.set_xlabel("viewing zenith angle [deg]")
ax.ticklabel_format(axis='y', scilimits=[-1,1])
ax.fill_between(vza, upper, lower, alpha=0.2, color="C0")
ax.set_ylabel("radiance")
plt.show()
plt.close()

We can repeat this process a final time with a higher sample count and see the variance go down.
[9]:
var_result = run_exp(spp=100000, integrator = integrator)
std = np.sqrt(var_result.radiance_var)
fig, ax = plt.subplots(1,1,figsize=(1*4.5,4), layout="constrained")
upper = (var_result.radiance + 2*std).squeeze()
lower = (var_result.radiance - 2*std).squeeze()
vza = var_result.vza.squeeze()
ax.plot(var_result.vza, var_result.radiance.squeeze().values, linestyle=":", marker=".")
ax.set_xlabel("viewing zenith angle [deg]")
ax.ticklabel_format(axis='y', scilimits=[-1,1])
ax.fill_between(vza, upper, lower, alpha=0.2, color="C0")
ax.set_ylabel("radiance")
plt.show()
plt.close()

Final words#
In this tutorial, you have learned how to turn on variance report and access and visualize radiance variance. Note that variance is also available for Stokes vectors when running in polarization mode (see polarization).