[1]:
%reload_ext eradiate.notebook.tutorials
Last updated: 2023-01-26 09:34 (eradiate v0.22.6.dev24+ge8e434d7.d20221118)
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.AtmosphereExperiment(
measures={
"type": "mdistant",
"construct": "hplane",
"zeniths": [-30, 0, 30],
"azimuth": 0,
"spectral_cfg": {
"bin_set": "10nm",
"bins": ["550"],
},
}
)
exp
[3]:
AtmosphereExperiment(measures=[MultiDistantMeasure(id='measure', mi_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']), sampler='independent', spp=1000, target=TargetPoint(xyz=[0.0 0.0 0.0] m), ray_offset=None, direction_layout=HemispherePlaneLayout(azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, zeniths=[-30 0 30] deg, azimuth=0 deg))], extra_objects={}, 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: 25281, t: 0)
Coordinates:
* w (w) float32 202.0 202.1 202.2 202.3 ... 2.73e+03 2.73e+03 2.73e+03
* t (t) float64
Data variables:
ssi (w) float32 0.007832 0.007816 0.007791 ... 0.03707 0.03707 0.03707
Attributes:
Conventions: CF-1.10
title: Total and Spectral Solar Irradiance Sensor-1 (TSIS-1)...
institution: Laboratory for Atmospheric and Space Physics
source: TSIS-1 Spectral Irradiance Monitor (SIM), CubeSat Com...
references: https://doi.org/10.1029/2020GL091709
history: 2023-01-17T10:37:35 - data set creation by tengen, ve...
data_url: https://lasp.colorado.edu/lisird/resources/lasp/hsrs/v1/
data_url_datetime: 2023-01-17T10:37:35, scale=1.0, datetime=None)), geometry=PlaneParallelGeometry(width=1000000.0 km), atmosphere=HomogeneousAtmosphere(id='atmosphere', geometry=PlaneParallelGeometry(width=1000000.0 km), _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))), _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.AtmosphereExperiment()
AtmosphereExperiment( measures=[ MultiDistantMeasure( id='measure', mi_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 ), sampler='independent', spp=1000, target=TargetPoint(xyz=[0.0 0.0 0.0] m), ray_offset=None, direction_layout=DirectionLayout( azimuth_convention=<AzimuthConvention.EAST_RIGHT: (0.0, 1)>, _directions=array([[0, 0, 1]]) ) ) ], extra_objects={}, 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: 25281, t: 0) Coordinates: * w (w) float32 202.0 202.1 202.2 202.3 ... 2.73e+03 2.73e+03 2.73e+03 * t (t) float64 Data variables: ssi (w) float32 0.007832 0.007816 0.007791 ... 0.03707 0.03707 0.03707 Attributes: Conventions: CF-1.10 title: Total and Spectral Solar Irradiance Sensor-1 (TSIS-1)... institution: Laboratory for Atmospheric and Space Physics source: TSIS-1 Spectral Irradiance Monitor (SIM), CubeSat Com... references: https://doi.org/10.1029/2020GL091709 history: 2023-01-17T10:37:35 - data set creation by tengen, ve... data_url: https://lasp.colorado.edu/lisird/resources/lasp/hsrs/v1/ data_url_datetime: 2023-01-17T10:37:35, scale=1.0, datetime=None ) ), geometry=PlaneParallelGeometry(width=1000000.0 km), atmosphere=HomogeneousAtmosphere( id='atmosphere', geometry=PlaneParallelGeometry(width=1000000.0 km), _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) ) ), _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.