6. Example of use
Here is an example with a more “realistic” canopy. We start from a single fescue and alfafa stored in .bgeom files, then we will generate copies in random positions, in order to make a canopy.
[1]:
import os
from lightvegemanager.LVM import LightVegeManager
from pgljupyter import SceneWidget
from openalea.plantgl.all import Scene
6.1. Canopy generation
Load the .bgeom files
[2]:
fet_fgeom = os.path.join(os.path.dirname(os.path.abspath("")), "data", "Fet-LD-F2.bgeom")
luz_fgeom = os.path.join(os.path.dirname(os.path.abspath("")), "data", "LD-F1.bgeom")
bgeom_files = [fet_fgeom, luz_fgeom]
bgeom_files
[2]:
['C:\\Users\\mwoussen\\cdd\\codes\\dev\\lightvegemanager\\data\\Fet-LD-F2.bgeom',
'C:\\Users\\mwoussen\\cdd\\codes\\dev\\lightvegemanager\\data\\LD-F1.bgeom']
Generate copies in random position
[3]:
from lightvegemanager.trianglesmesh import create_heterogeneous_canopy
# scene generation parameters
nplants = 50
plant_density=130
var_plant_position=110
# generate random canopy from plant examples
if not isinstance(bgeom_files, list): bgeom_files = [bgeom_files]
scenes = []
for f in bgeom_files :
plant_scene = Scene()
plant_scene.read(f, 'BGEOM')
# multiply a plant with variations
canopy, domain = create_heterogeneous_canopy(plant_scene,
nplants=nplants,
plant_density=plant_density,
var_plant_position=var_plant_position)
scenes.append(canopy)
6.2. Lighting simulation
Set simulation parameters
[4]:
# setup environment
environment = {}
environment["coordinates"] = [48.8 ,2.3 ,1] # latitude, longitude, timezone
# we compute only sun light in an infinite scene
environment["diffus"] = False
environment["direct"] = True
environment["reflected"] = False
environment["infinite"] = True
# CARIBU parameters
caribu_parameters = {
"sun algo": "caribu",
"caribu opt" : { "par": (0.10, 0.05) }
}
# inputs values for lighting
energy=500
day=264
hour=15
Run the simulation
[5]:
# Initializing the tool
lighting = LightVegeManager(lightmodel="caribu",
environment=environment,
lightmodel_parameters=caribu_parameters)
# build the scene
geometry = {"scenes" : scenes }
lighting.build(geometry)
# compute lighting
lighting.run(energy=energy, hour=hour, day=day)
# print results gathered by elements (Shapes in the plantGL Scene)
print(lighting.elements_outputs)
Day Hour Organ VegetationType Area par Eabs par Ei
0 264 15 825510368 0 83.332180 76.246899 89.702234
1 264 15 825501440 0 75.958035 212.034963 249.452897
2 264 15 825503168 0 4.520565 108.134153 127.216650
3 264 15 825503824 0 57.771363 79.214402 93.193414
4 264 15 825498448 0 5.711880 97.236152 114.395473
.. ... ... ... ... ... ... ...
321 264 15 825485200 1 2.625990 287.633701 338.392589
322 264 15 825485904 1 18.000312 82.696127 97.289562
323 264 15 825486976 1 12.152513 78.609077 92.481268
324 264 15 825488784 1 9.200676 519.140172 610.753143
325 264 15 825489120 1 9.200676 424.977325 499.973324
[326 rows x 7 columns]
[6]:
# visualisation
SceneWidget(lighting.to_plantGL(lighting=True, printtriangles=True, printvoxels=False),
position=(0.0, 0.0, 0.0),
size_display=(600, 400),
plane=True,
size_world = 100,
axes_helper=True)
[6]: