"""Tutorial 26 - Thermal infrared image of a forest with prescribed sunlit/shaded temperatures."""
import less

scene = less.Scene()
scene.size = 50.0
scene.terrain = less.Terrain(property=less.Lambertian(reflectance=0.15))
scene.terrain.set_property(less.ThermalProperty(emissivity=0.95, temperature_sunlit=312.0,
                                                temperature_shaded=303.0))
scene.illumination = less.Illumination(
    source=less.Sun(zenith=30, azimuth=150), atmosphere=less.PrescribedAtmosphere(sky_temperature=260.0))

tree = less.Object("ash", mesh=less.asset_path("FREX.obj"))
tree.set_property("leaves", less.Prospect(cab=40, car=10))
tree.set_property("stem_branch", less.Lambertian(reflectance=0.08))
tree.set_property("leaves", less.ThermalProperty(emissivity=0.98, temperature_sunlit=305.0,
                                                 temperature_shaded=300.0))
tree.set_property("stem_branch", less.ThermalProperty(emissivity=0.97, temperature=300.0))
positions = less.place.random(scene, n=40, min_dist=4.0, seed=42)
n = len(positions)
scene.add(tree, positions=positions, scales=less.place.uniform_scale(n, 0.7, 1.3, seed=42),
          rotations=less.place.random_rotation(n, seed=42))

radiance = scene.simulate(less.ThermalImager(less.Orthographic(image_size=128), bands=[10600], quality=32))
radiance.save("26_thermal.tif")
brightness = radiance.to_brightness_temperature(unit="K")
brightness.save("26_brightness_temperature.png")
print(f"Brightness temperature: {brightness.data.min():.1f} - {brightness.data.max():.1f} K")
