A better notebook experience
Contents
[1]:
%reload_ext eradiate.notebook.tutorials
Last updated: 2022-10-05 13:35 (eradiate v0.22.4.post102+g84ef86b.d20221005)
A better notebook experience#
Overview
This tutorial demonstrates features which make the experience of using Eradiate in a Jupyter notebook more enjoyable.
What you will learn
How to load the Eradiate IPython extension.
How it improves the notebook experience.
First, we load Eradiate and select the CKD mode.
[2]:
import eradiate
eradiate.set_mode("ckd")
Let’s define a very simulation with a single spectral bin, then visualise it:
[3]:
# Basic behaviour: looks bad
exp = eradiate.experiments.OneDimExperiment(
measures={
"type": "mdistant",
"construct": "from_viewing_angles",
"zeniths": [-30, 0, 30],
"azimuths": 0,
"spectral_cfg": {
"bin_set": "10nm",
"bins": ["550"],
},
}
)
exp
[3]:
AtmosphereExperiment(measures=[MultiDistantMeasure(id='measure', results={}, spectral_cfg=CKDMeasureSpectralConfig(srf=UniformSpectrum(id=None, quantity=DIMENSIONLESS, value=1.0), bin_set=BinSet(id='10nm', quad=Quad(type=QuadType.GAUSS_LEGENDRE, n=16), bins=tuple<213>(Bin('280', ... ), Bin('290', ... ), ... , Bin('2390', ... ), Bin('2400', ... ))), _bins=['550']), spp=1000, split_spp=None, hplane=[0] deg, azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, directions=array([[ 5.00000000e-01, -6.12323400e-17, -8.66025404e-01],
[-0.00000000e+00, -0.00000000e+00, -1.00000000e+00],
[-5.00000000e-01, -0.00000000e+00, -8.66025404e-01]]), target=TargetPoint(xyz=[0.0 0.0 0.0] m), flags=<MeasureFlags.DISTANT: 1>)], illumination=DirectionalIllumination(id='illumination', zenith=0.0 deg, azimuth=0.0 deg, azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, irradiance=SolarIrradianceSpectrum(id=None, dataset=<xarray.Dataset>
Dimensions: (w: 2301, t: 0)
Coordinates:
* t (t) float64
* w (w) float64 200.0 201.0 202.0 203.0 ... 2.498e+03 2.499e+03 2.5e+03
Data variables:
ssi (w) float64 0.007729 0.008143 0.008756 ... 0.05694 0.05691 0.05687
Attributes:
convention: CF-1.8
title: Thuillier (2003) solar irradiance spectrum
history: 2020-12-15 11:50:46 - data set creation - eradiate-datasets_...
source: Combined observations from the SOLSPEC instrument during the...
references: https://doi.org/10.1023/A:1024048429145
obs_start: 1992-03-24
obs_end: 1993-07-01
url: original data available at https://oceancolor.gsfc.nasa.gov/...
comment: Original data set was extrapolated to 2500 nanometers. Extra..., scale=1.0, datetime=None)), geometry=PlaneParallelGeometry(width=AUTO), atmosphere=HomogeneousAtmosphere(id='atmosphere', geometry=None, _bottom=0.0 km, _top=10.0 km, sigma_s=AirScatteringCoefficientSpectrum(id=None), sigma_a=UniformSpectrum(id=None, quantity=COLLISION_COEFFICIENT, value=0.0 1/m), phase=RayleighPhaseFunction(id='phase_atmosphere')), surface=BasicSurface(id='surface', shape=None, bsdf=LambertianBSDF(id='bsdf', reflectance=UniformSpectrum(id=None, quantity=REFLECTANCE, value=0.5))), dem=None, _integrator=VolPathIntegrator(id='integrator', max_depth=None, rr_depth=None, hide_emitters=None))
Arguably, this ouput is impractical and makes the process of inspecting the contents of the OneDimExperiment
instance quite challenging. Anyway, let’s run the corresponding simulation:
[4]:
eradiate.run(exp);
The produced output is uncontrolled and mixes progress information coming from Eradiate (the “Spectral loop” progress bar), but also from the Mitsuba radiometric kernel (the “Rendering” progress bar). A notable consequence is that changing the progress level using config.progress
to suppress Mitsuba’s progress will not have the expected effect.
This can be improved by loading Eradiate’s IPython extension as follows:
[5]:
%load_ext eradiate
This automatically loads Rich’s “pretty” and “traceback” extensions, and it redirects Mitsuba’s logs and progress to, respectively, the standard Python logging framework and the tqdm library.
A first noticeable effect is that all objects created using the attrs framework are pretty-printed and are consequently much more readable:
[6]:
eradiate.experiments.OneDimExperiment()
AtmosphereExperiment( measures=[ MultiDistantMeasure( id='measure', results={}, spectral_cfg=CKDMeasureSpectralConfig( srf=UniformSpectrum(id=None, quantity=DIMENSIONLESS, value=1.0), bin_set=BinSet( id='10nm', quad=Quad(type=QuadType.GAUSS_LEGENDRE, n=16), bins=tuple<213>(Bin('280', ... ), Bin('290', ... ), ... , Bin('2390', ... ), Bin('2400', ... )) ), _bins=AUTO ), spp=1000, split_spp=None, hplane=None, azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, directions=array([[ 0., 0., -1.]]), target=TargetPoint(xyz=[0.0 0.0 0.0] m), flags=<MeasureFlags.DISTANT: 1> ) ], illumination=DirectionalIllumination( id='illumination', zenith=0.0 deg, azimuth=0.0 deg, azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, irradiance=SolarIrradianceSpectrum( id=None, dataset=<xarray.Dataset> Dimensions: (w: 2301, t: 0) Coordinates: * t (t) float64 * w (w) float64 200.0 201.0 202.0 203.0 ... 2.498e+03 2.499e+03 2.5e+03 Data variables: ssi (w) float64 0.007729 0.008143 0.008756 ... 0.05694 0.05691 0.05687 Attributes: convention: CF-1.8 title: Thuillier (2003) solar irradiance spectrum history: 2020-12-15 11:50:46 - data set creation - eradiate-datasets_... source: Combined observations from the SOLSPEC instrument during the... references: https://doi.org/10.1023/A:1024048429145 obs_start: 1992-03-24 obs_end: 1993-07-01 url: original data available at https://oceancolor.gsfc.nasa.gov/... comment: Original data set was extrapolated to 2500 nanometers. Extra..., scale=1.0, datetime=None ) ), geometry=PlaneParallelGeometry(width=AUTO), atmosphere=HomogeneousAtmosphere( id='atmosphere', geometry=None, _bottom=0.0 km, _top=10.0 km, sigma_s=AirScatteringCoefficientSpectrum(id=None), sigma_a=UniformSpectrum(id=None, quantity=COLLISION_COEFFICIENT, value=0.0 1/m), phase=RayleighPhaseFunction(id='phase_atmosphere') ), surface=BasicSurface( id='surface', shape=None, bsdf=LambertianBSDF( id='bsdf', reflectance=UniformSpectrum(id=None, quantity=REFLECTANCE, value=0.5) ) ), dem=None, _integrator=VolPathIntegrator(id='integrator', max_depth=None, rr_depth=None, hide_emitters=None) )
A second consequence is that progress display control now works as expected:
[7]:
eradiate.config.progress = "KERNEL"
eradiate.run(exp);
[8]:
eradiate.config.progress = "SPECTRAL_LOOP"
eradiate.run(exp);
Further reading#
The extension can also be activated by an explicit call to eradiate.notebook.install()
, which allows for further customisation.