1. LightVegeManager first steps

1.1. Content:

  • One triangle

    • CARIBU

    • RATP

  • Set of triangles

    • CARIBU

    • RATP

1.2. Introduction

This notebook provides an introduction to the tool and its default parameters. Visualization is provided with PlantGL and and its adapation to jupyter notebook plantgl-jupyter.

The main methods of a LightVegeManager instance are : - constructor __init__: returns an instance and initialize static parameters such as sky and default parameters - build: build and arrange the geometric scene following the chosen light model format - run: compute lighting - DataFrame outputs are stored in triangles_ouputs, voxels_ouputs and elements_ouputs

[1]:
# imports the LightVegeManager object and SceneWidget for visual representation
from lightvegemanager.LVM import LightVegeManager
from pgljupyter import SceneWidget

1.3. One triangle

As a first example, we can compute lighting on a single 3D triangle. A triangle is reprented with a list of 3 cartesian points (x, y, z)

[2]:
t = [(0., 0., 0.), (1., 0., 0.), (1., 1., 1.)]

1.3.1. CARIBU (surfarcic modelling)

  1. Initialize the instance. The lightmodel must be entered, at the moment you can choose between "caribu", "ratp" and "riri5"

[3]:
# initialize the instance
lighting = LightVegeManager(lightmodel="caribu")
  1. Build the geometry. The triangle will be save inside the instance.

[4]:
# build the scene
lighting.build(geometry=t)

In order to visualize the scene in the instance, you can give a plantGL Scene in SceneWidget through two methods: - plantGL_nolight: plots only geometric elements - plantGL_light: plots geometric elements and colors the scene according to PAR values

[5]:
SceneWidget(lighting.to_plantGL(), size_display=(600, 400), plane=True, size_world = 4, axes_helper=True)
[5]:
  1. Compute the lighting. By default it will compute direct and diffuse lighting.

[6]:
energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

Then, you can print the Dataframe outputs

[7]:
# print the outputs
print(lighting.triangles_outputs)
   Day  Hour  Triangle  Organ  VegetationType      Area    par Eabs  \
0  264    15         0      0               0  0.707107  397.268686

       par Ei
0  467.374925

1.3.2. RATP

To use RATP, you need to create a new instance. The others methods can be used in the same way as with CARIBU

[7]:
# initialize the instance
lighting = LightVegeManager(lightmodel="ratp")

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

With plantGL_nolight you can precise if you want to plot the voxels. By default, if not precised, a voxel side is set as 3 times the longest triangle side.

[9]:
# visualisation
SceneWidget(lighting.to_plantGL(printvoxels=True),
            size_display=(600, 400),
            plane=True,
            size_world = 4,
            axes_helper=True)
[9]:
[12]:
# compute the lighting
energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

You can get the outputs of the voxels or the triangles

[13]:
# print the outputs
print(lighting.voxels_outputs)
   VegetationType    Day  Hour  Voxel  Nx  Ny  Nz   ShadedPAR   SunlitPAR  \
0             1.0  264.0  15.0    1.0   1   1   1  380.635895  473.640411

   ShadedArea  SunlitArea      Area        PARa  Intercepted  Transmitted
0    0.010761    0.696346  0.707107  472.225067     0.667827     8.742233
[14]:
# print the outputs
print(lighting.triangles_outputs)
   Triangle  Organ  Voxel  VegetationType  primitive_area    Day  Hour  Nx  \
0         0      0    1.0               1        0.707107  264.0  15.0   1

   Ny  Nz   ShadedPAR   SunlitPAR  ShadedArea  SunlitArea      Area  \
0   1   1  380.635895  473.640411    0.010761    0.696346  0.707107

         PARa  Intercepted  Transmitted
0  472.225067     0.667827     8.742233

1.4. Set of triangles

For this second example, we will generate a set of random 3D triangles. A function is already implemented in the package.

[10]:
from lightvegemanager.trianglesmesh import random_triangle_generator
[11]:
nb_triangles = 5000
spheresize = (10., 2.) # vertices of the triangles are on the sphere surface
triangles = []
for i in range(nb_triangles):
    triangles.append(random_triangle_generator(spheresize=spheresize))

1.4.1. CARIBU

We repeat the same steps as with one triangle

[12]:
# initialize the instance
lighting = LightVegeManager(lightmodel="caribu")

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

# visualisation
SceneWidget(lighting.to_plantGL(),
            position=(-50.0, -50.0, 0.0),
            size_display=(600, 400),
            plane=True,
            size_world = 100,
            axes_helper=True)
[12]:
[14]:
# compute the lighting
energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

# print the outputs
print(lighting.triangles_outputs)
      Day  Hour  Triangle  Organ  VegetationType       Area    par Eabs  \
0     264    15         0      0               0  78.834450  139.160806
1     264    15         1      0               0  47.966120    0.886467
2     264    15         2      0               0  13.309912   27.693806
3     264    15         3      0               0  52.267733    2.489935
4     264    15         4      0               0  12.524847    0.198283
...   ...   ...       ...    ...             ...        ...         ...
4995  264    15      4995      0               0  71.155347   17.388605
4996  264    15      4996      0               0  15.119594   67.661091
4997  264    15      4997      0               0  12.947871   57.176758
4998  264    15      4998      0               0  27.825938   28.413648
4999  264    15      4999      0               0  25.764540    2.044766

          par Ei
0     163.718595
1       1.042902
2      32.580948
3       2.929335
4       0.233274
...          ...
4995   20.457182
4996   79.601283
4997   67.266774
4998   33.427821
4999    2.405607

[5000 rows x 8 columns]
[13]:
SceneWidget(lighting.to_plantGL(),
            position=(-50.0, -50.0, 0.0),
            size_display=(600, 400),
            plane=True,
            size_world = 100,
            axes_helper=True)
[13]:

1.4.2. RATP

Now, we will set the voxels size. It needs to be specified in a dict which stores all RATP parameters. Here, you need to precise the length on each axis of one voxel.

[9]:
ratp_parameters = { "voxel size": [20.] * 3 }

Then, the dict is an argument in the instance creation.

[10]:
# initialize the instance
lighting = LightVegeManager(lightmodel="ratp", lightmodel_parameters=ratp_parameters)

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

# visualisation
SceneWidget(lighting.to_plantGL(printtriangles=True, printvoxels=True),
            position=(-50.0, -50.0, 0.0),
            size_display=(600, 400),
            plane=True,
            size_world = 100,
            axes_helper=True)
[10]:
[11]:
# compute the lighting
energy = 500.
hour = 15
day = 264
lighting.run(energy=energy, hour=hour, day=day)

# print the outputs
print(lighting.voxels_outputs)
     VegetationType    Day  Hour  Voxel  Nx  Ny  Nz   ShadedPAR   SunlitPAR  \
0               1.0  264.0  15.0    1.0   3   3   5   40.732689  136.623886
1               1.0  264.0  15.0    2.0   5   6   6   28.347637  124.238831
2               1.0  264.0  15.0    3.0   1   4   3  137.707138  233.598343
3               1.0  264.0  15.0    4.0   3   3   2  183.874008  279.765198
4               1.0  264.0  15.0    5.0   2   6   5   41.833862  137.725067
..              ...    ...   ...    ...  ..  ..  ..         ...         ...
213             1.0  264.0  15.0  214.0   4   2   4   63.669552  159.560745
214             1.0  264.0  15.0  215.0   1   7   6  146.115402  242.006592
215             1.0  264.0  15.0  216.0   6   3   7   82.600769  178.491959
216             1.0  264.0  15.0  217.0   1   7   2  339.311615  435.202850
217             1.0  264.0  15.0  218.0   4   5   1  375.165588  471.056763

      ShadedArea  SunlitArea         Area        PARa  Intercepted  \
0    1024.282715   10.943428  1035.226196   41.746357    86.433853
1    1377.175171  283.350006  1660.525146   44.710396   148.485474
2     172.634308  291.246674   463.880981  197.912231   183.615433
3     486.705994  360.075684   846.781677  224.649658   380.458435
4    1375.770874   41.413651  1417.184570   44.636040   126.515022
..           ...         ...          ...         ...          ...
213   626.312683  157.908005   784.220703   82.977875   130.145935
214    57.020470   86.957054   143.977524  204.030106    58.751499
215   197.366257  156.226395   353.592651  124.967972    88.375519
216     4.840422   17.089012    21.929434  414.037079    18.159195
217     0.815029   39.664459    40.479488  469.126038    37.979965

     Transmitted
0      31.874031
1      18.599306
2     119.887787
3     101.195755
4      33.631508
..           ...
213    52.329762
214   128.099014
215    82.136887
216   328.422760
217   385.791229

[218 rows x 15 columns]
[23]:
# print the outputs
print(lighting.triangles_outputs)
      Triangle  Organ  Voxel  VegetationType  primitive_area    Day  Hour  Nx  \
0            0      0    1.0               1        6.008933  264.0  15.0   5
49           1      0    2.0               1       64.911050  264.0  15.0   4
77           2      0    3.0               1       48.494517  264.0  15.0   3
84           3      0    4.0               1        5.762879  264.0  15.0   1
91           4      0    5.0               1       21.321846  264.0  15.0   3
...        ...    ...    ...             ...             ...    ...   ...  ..
586       4995      0   21.0               1       21.090689  264.0  15.0   5
3641      4996      0  136.0               1       32.577000  264.0  15.0   4
1051      4997      0   37.0               1       76.699258  264.0  15.0   6
1822      4998      0   63.0               1        1.464895  264.0  15.0   2
3443      4999      0  129.0               1       51.065793  264.0  15.0   5

      Ny  Nz   ShadedPAR   SunlitPAR   ShadedArea  SunlitArea         Area  \
0      6   3   48.783260  144.457764  1669.359253  307.066376  1976.425659
49     2   6   50.222652  145.897171   639.340942  467.153961  1106.494873
77     7   7   76.529640  172.204147   131.880585   49.266487   181.147064
84     7   4  162.029709  257.704224   114.480240  108.982895   223.463135
91     5   5   36.165016  131.839523  1061.264648    3.100358  1064.364990
...   ..  ..         ...         ...          ...         ...          ...
586    4   6   28.958939  124.633453   982.723572  278.425110  1261.148682
3641   4   4   20.419191  116.093712  1379.531006   34.760368  1414.291382
1051   6   5   68.352638  164.027176  1125.141846    1.110655  1126.252441
1822   5   5   39.313770  134.988281  1225.665894   14.276536  1239.942383
3443   2   6   60.735207  156.409714   431.796021  383.754333   815.550354

            PARa  Intercepted  Transmitted
0      63.647678   251.589828    31.452011
49     90.615723   200.531677    35.146641
77    102.550201    37.153339    72.656891
84    208.690125    93.269104   155.314255
91     36.443703    77.578804    28.307266
...          ...          ...          ...
586    50.081097   126.319427    21.615057
3641   22.770676    64.408737    13.644242
1051   68.446991   154.177170    60.248528
1822   40.415356   100.225418    28.215555
3443  105.754509   172.496262    47.396954

[5000 rows x 18 columns]
[13]:
# visualisation
SceneWidget(lighting.to_plantGL(lighting=True, printtriangles=True, printvoxels=False),
            position=(-50.0, -50.0, 0.0),
            size_display=(600, 400),
            plane=True,
            size_world = 100,
            axes_helper=True)
[13]:
[14]:
# visualisation
SceneWidget(lighting.to_plantGL(lighting=True, printtriangles=False, printvoxels=True),
            position=(-50.0, -50.0, 0.0),
            size_display=(600, 400),
            plane=True,
            size_world = 100,
            axes_helper=True)
[14]: