Skip to content

Commit

Permalink
Adding Jupyter Notebooks as tutorials:
Browse files Browse the repository at this point in the history
- new pictures in doc
- plantGL visualization feature
- adds s2v and s5 (there were lost ?)
- new examples (mainly for debugging notebooks)
- debugging src
  • Loading branch information
mwoussen committed Sep 18, 2023
1 parent b4e56cd commit cd11a85
Show file tree
Hide file tree
Showing 44 changed files with 7,493 additions and 43 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
s2v/*
s5/*
PyRATP/pyratp_wralea/*
PyRATP/__pycache__/*
PyRATP/__init__.py
Expand All @@ -26,8 +24,6 @@ LightVegeManager_Singularity.egg-info
build
dist
PyRATP/pyratp/pyratp.pyd
s2v
s5
.vscode
runscripts/legume/debug_tests.py
Run-tmp
Expand Down
Binary file added doc/_img/paraview_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_img/tesselation_voxels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_img/transform_geo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/plaque_ratp-caribu.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def simulation(geom, hour, situation, direct, diffus, ratp_mu, dv, folderout):
ratp_parameters["soil reflectance"] = [0., 0.]
ratp_parameters["reflectance coefficients"] = [[0.1, 0.05]]
ratp_parameters["mu"] = ratp_mu
ratp_parameters["tesselation level"] = 7
ratp_parameters["tesselation level"] = 5
ratp_parameters["angle distrib algo"] = "compute global"
ratp_parameters["nb angle classes"] = 45

Expand All @@ -53,7 +53,7 @@ def simulation(geom, hour, situation, direct, diffus, ratp_mu, dv, folderout):

# VTK de la scène avec x+ = North
path_out = folderout+"caribu_"+str(day)+"_"+str(hour)+"h"+"_"+situation
lghtcaribu.VTK_light(path_out)
# lghtcaribu.VTK_light(path_out)

# RATP
print("\n\t R A T P")
Expand All @@ -66,11 +66,11 @@ def simulation(geom, hour, situation, direct, diffus, ratp_mu, dv, folderout):

# VTK de la scène avec x+ = North
path_out = folderout+"ratp_"+str(day)+"_"+str(hour)+"h"+"_"+situation
lghtratp.VTK_light(path_out)
# lghtratp.VTK_light(path_out)


# ligne du soleil (rotation de 180° autour de z pour se mettre dans l'espace x+ = North)
lghtcaribu.VTK_sun(folderout+"sun_day"+str(day)+"_"+str(hour))
# lghtcaribu.VTK_sun(folderout+"sun_day"+str(day)+"_"+str(hour))
print("\n")

if __name__ == "__main__":
Expand Down
16 changes: 14 additions & 2 deletions examples/quick_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@

# compute lighting
energy = 500
hour = 15
hour = 12
day = 264 # 21st september
lighting.run(energy, hour, day)
lighting.run(energy=energy, hour=hour, day=day)

# output
print(lighting.elements_outputs)

# initialize the instance
lighting = LightVegeManager(lightmodel="ratp")

# build the scene
lighting.build(geometry=triangle_vertices)

# compute the lighting
lighting.run(energy=energy, hour=hour, day=day)

# print the outputs
print(lighting.elements_outputs)
print("--- END")
34 changes: 34 additions & 0 deletions examples/quick_test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from lightvegemanager.tool import LightVegeManager
import openalea.plantgl.all as pgl

print("--- START")

# one triangle as a geometric element
triangle_vertices_1 = [[(0.,0.,0.), (1.,0.,0.), (1.,1.,1.)]]
triangle_vertices_2 = [[(0.,2.,0.), (1.,2.,0.), (1.,3.,1.)]]
stems = [(0,1)]
geometry = {
"scenes" : [triangle_vertices_1, triangle_vertices_2],
"stems id" : stems
}

# surfacic lighting with CARIBU
lighting = LightVegeManager(lightmodel="caribu")

# build the scene
lighting.build(geometry=geometry)

# compute lighting
energy = 500
hour = 15
day = 264 # 21st september
lighting.run(energy, hour, day)

# output
print(lighting.elements_outputs)

# visualisation
pglscene = lighting.plantGL_light()
pgl.Viewer.display(pglscene)

print("--- END")
33 changes: 33 additions & 0 deletions examples/quick_test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# import the class tool
from lightvegemanager.tool import LightVegeManager
from lightvegemanager.trianglesmesh import random_triangle_generator
import openalea.plantgl.all as pgl
import random

spheres = []

for i in range(255):
x, y, z = [random.choice([-1, 1]) * random.randrange(0, int(255/2)) for i in range(3)]
m = pgl.Material(ambient=(x+int(255/2), y+int(255/2), z+int(255/2)), shininess=0.1, diffuse=1)
spheres.append(pgl.Shape(pgl.Translated(x, y, z, pgl.Sphere(random.randrange(1, 20), 20, 20)), m))

nb_triangles = 500
spheresize = (10., 2.)
triangles = []
for i in range(nb_triangles):
triangles.append(random_triangle_generator(spheresize=spheresize))

# initialize the instance
lighting = LightVegeManager(lightmodel="caribu")

# build the scene
lighting.build(geometry=triangles)

# compute the lighting
energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

pglscene = lighting.plantGL_light()
pgl.Viewer.display(pglscene)
67 changes: 67 additions & 0 deletions examples/quick_test4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
from lightvegemanager.tool import LightVegeManager
from openalea.plantgl.all import Scene, Viewer

fet_fgeom = os.path.join(os.path.abspath(""), "data", "Fet-LD-F2.bgeom")
luz_fgeom = os.path.join(os.path.abspath(""), "data", "LD-F1.bgeom")
bgeom_files = [fet_fgeom, luz_fgeom]

# setup environment
environment = {}
environment["coordinates"] = [48.8 ,2.3 ,1] # latitude, longitude, timezone

# we compute only sun light in a finite scene
environment["diffus"] = False
environment["direct"] = True
environment["reflected"] = False
environment["infinite"] = False

# CARIBU parameters
caribu_parameters = {}
caribu_parameters["sun algo"] = "caribu"
caribu_parameters["caribu opt"] = {}
caribu_parameters["caribu opt"]["par"] = (0.10, 0.05)

# inputs values for lighting
energy=500
day=264
hour=15

# scene generation parameters
nplants = 10
plant_density=130
var_plant_position=110

from lightvegemanager.trianglesmesh import create_heterogeneous_canopy

# Initializing the tool
lighting = LightVegeManager(lightmodel="caribu",
environment=environment,
lightmodel_parameters=caribu_parameters)

# 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)

# build the scene
geometry = {"scenes" : scenes }

lighting.build(geometry)

# compute lighting
lighting.run(energy=energy, hour=hour, day=day)

s = lighting.plantGL_light(printtriangles=True, printvoxels=False)

Viewer.display(s)
28 changes: 28 additions & 0 deletions examples/quick_test5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from lightvegemanager.tool import LightVegeManager
from lightvegemanager.trianglesmesh import random_triangle_generator
from openalea.plantgl.all import Viewer

# grid dimensions
dxyz = [1.] * 3
nxyz = [5, 5, 7]
orig = [0.] * 3

# random triangles
nb_triangles = 50
spheresize = (1., 0.3) # vertices of triangles are the sphere surface
triangles = []
for i in range(nb_triangles) :
triangles.append(random_triangle_generator(worldsize=(0., 5.), spheresize=spheresize))

caribu_args = { "sensors" : ["grid", dxyz, nxyz, orig] }

lighting = LightVegeManager(lightmodel="caribu", lightmodel_parameters=caribu_args, environment={"infinite":True})
lighting.build(geometry={"scenes" : [triangles]})

energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

s = lighting.plantGL_sensors(light=True)
Viewer.display(s)
44 changes: 44 additions & 0 deletions examples/quick_test6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from lightvegemanager.tool import LightVegeManager
from lightvegemanager.trianglesmesh import random_triangle_generator
import numpy

# grid dimensions
dxyz = [1.] * 3
nxyz = [7, 7, 7]
orig = [-1., -1., 0.]

spheresize = (1., 0.3) # vertices of triangles are the sphere surface
worldsize = (0., 5.)

nb_triangles = 10
triangles1 = [random_triangle_generator(worldsize=worldsize, spheresize=spheresize) for i in range(nb_triangles)]

nb_triangles = 9
triangles2 = [random_triangle_generator(worldsize=worldsize, spheresize=spheresize) for i in range(nb_triangles)]

nb_triangles = 8
triangles3 = [random_triangle_generator(worldsize=worldsize, spheresize=spheresize) for i in range(nb_triangles)]

scene = {0: triangles1, 1: triangles2, 2: triangles3}


ratp_parameters = { "voxel size" : dxyz,
"origin" : orig,
"number voxels" : nxyz,
"full grid" : True}

lighting = LightVegeManager(lightmodel="ratp", lightmodel_parameters=ratp_parameters)
lighting.build(geometry={"scenes" : [scene] })

energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

m_lais = numpy.zeros([1] + nxyz)
for row in lighting.voxels_outputs.itertuples():
m_lais[int(row.VegetationType)-1][row.Nz-1][row.Nx-1][row.Ny-1] = row.Area
res_abs_i, res_trans = lighting.to_l_egume(m_lais=m_lais)

print(res_abs_i[0])
print(res_trans)
Loading

0 comments on commit cd11a85

Please sign in to comment.