Skip to content

Error During Simulation with Batch Processing and DTM Mesh: 'NoneType' Object Issue #4

@katjakroener

Description

@katjakroener

When running my python code (see below) integrating both a DTM mesh and batch processing into the LESS simulation, I encounter the following error message during the simulation process (sim.start()): "Error occurred during iteration 0: 'NoneType' object has no attribute 'getID'". Somehow, it seems that the simulation loses the DTM during the batch iterations.

Interestingly, the code runs correctly if I outcomment the line:
sim.enable_runtime_modification_of_properties(True)
However, disabling this feature causes all tree objects to be reloaded in every iteration, resulting in approx. doubled simulation times.

Therefore, I would greatly appreciate any insights or assistance in resolving this issue.

`#coding: utf-8

Initialization

#This script is automatically generated from the GUI
#It can generate the same simulation project with the GUI one you created
#You can customize this script for usages such as batch processing
#The generated code may not cover all functionalities from GUI, please refer to the API for more details.
import sys
sys.path.append(r"C:\Users\K\AppData\Local\LESS\app\Python_script\pyLessSDK")
from SimulationHelper import SimulationHelper
from Simulation import Simulation
from Terrain import TERRAIN_TYPE, TERRAIN_BRDF_TYPE
from OpticalProperty import OpticalItem
from SceneObjects import SceneObject
from Sensor import *
from Observation import *
from LiDAR import ALSLiDAR, TLSLiDAR, LiDARSimMode, MonoPulseLiDAR
from Illumination import Illumination, Atmosphere6S
import glob
import os
import re

sim_helper = SimulationHelper(r"C:\Users\K\AppData\Local\LESS") # Create SimulationHelper, the parameters is the path to LESS installation folder
sim_helper.create_new_sim(r"C:\Users\K\Documents\LESS\sim_ashapes_SB") # Create a new simulation, if already exists, it skips
sim = Simulation(r"C:\Users\K\Documents\LESS\sim_ashapes_SB", sim_helper) # Initialize a Simulation
sim.read_sim_project() # Read the content of the simulation
scene = sim.get_scene() # Read the scene
landscape = scene.get_landscape() # Get the Landscape
#If you want to keep scene structures unchanged, you should comment out the following line
landscape.clear_landscape_elements() # Clear existing objects and instances(must be run when you want change scene structures)
#landscape.clear_user_defined_optical_properties() # Clear optical properties defined by users

#When you want to do batch-processing by changing optical properties and sun/obs geometries,
#you can use sim.enable_runtime_modification_of_properties(True),
#and then modify the optical properties in a loop to do simulation, which avoids the reload of the
#obj files to save overall time. Please refer to Ex07 in the pyLessSDK folder for more details.
#If you want also loop structural properties (e.g., tree positions,) when enable_runtime_modification_of_properties(True) is set,
#you should also invoke sim.reload_runtime_structural_properties() after you add and place objects

Optical properties

op_item = OpticalItem("fagus_bark", "0.0666,0.0666,0.0667,0.0669,0.0670,0.0671,0.0673,0.0674,0.0675,0.0676,0.0678,0.0679,0.0680,0.0681,0.0683,0.0684,0.0685,0.0686,0.0688,0.0689,0.0690,0.0691,0.0693,0.0694,0.0695,0.0696,0.0698,0.0699,0.0700,0.0701,0.0702,0.0703,0.0704,0.0705,0.0705,0.0706,0.0707,0.0708,0.0708,0.0709,0.0710,0.0711,0.0711,0.0712,0.0713,0.0714,0.0714,0.0715,0.0716,0.0717,0.0717,0.0718,0.0719,0.0720,0.0720,0.0721,0.0722,0.0723,0.0724,0.0724,0.0725,0.0726,0.0727,0.0727,0.0728,0.0730,0.0732,0.0735,0.0737,0.0739,0.0742,0.0744,0.0746,0.0749,0.0751,0.0753,0.0756,0.0758,0.0760,0.0763,0.0765,0.0767,0.0770,0.0772,0.0774,0.0777,0.0779,0.0781,0.0784,0.0786,0.0788,0.0791,0.0793,0.0795,0.0798,0.0800,0.0802,0.0805,0.0807,0.0809,0.0812,0.0814,0.0816,0.0819,0.0821,0.0826,0.0831,0.0837,0.0843,0.0848,0.0854,0.0860,0.0865,0.0871,0.0877,0.0882,0.0888,0.0894,0.0899,0.0905,0.0911,0.0916,0.0922,0.0927,0.0933,0.0939,0.0944,0.0950,0.0956,0.0961,0.0967,0.0973,0.0978,0.0984,0.0990,0.0995,0.1001,0.1007,0.1012,0.1018,0.1024,0.1029,0.1035,0.1041,0.1046,0.1052,0.1058,0.1063,0.1069,0.1075,0.1080,0.1086,0.1092,0.1098,0.1103,0.1109,0.1115,0.1120,0.1126,0.1132,0.1137,0.1143,0.1149,0.1154,0.1159,0.1163,0.1167,0.1171,0.1175,0.1179,0.1183,0.1187,0.1191,0.1195,0.1199,0.1203,0.1207,0.1211,0.1216,0.1220,0.1224,0.1228,0.1232,0.1236,0.1240,0.1244,0.1248,0.1252,0.1256,0.1260,0.1264,0.1268,0.1273,0.1277,0.1281,0.1285,0.1289,0.1293,0.1297,0.1301,0.1305,0.1309,0.1313,0.1317,0.1321,0.1325,0.1329,0.1333,0.1337,0.1341,0.1346,0.1350,0.1354,0.1358,0.1362,0.1366,0.1370,0.1374,0.1378,0.1382,0.1386,0.1390,0.1394,0.1398,0.1402,0.1406,0.1410,0.1414,0.1418,0.1422,0.1427,0.1431,0.1435,0.1439,0.1443,0.1447,0.1451,0.1455,0.1459,0.1463,0.1467,0.1471,0.1475,0.1479,0.1483,0.1487,0.1491,0.1495,0.1499,0.1504,0.1508,0.1512,0.1515,0.1519,0.1522,0.1525,0.1528,0.1531,0.1535,0.1538,0.1541,0.1544,0.1547,0.1551,0.1554,0.1557,0.1560,0.1563,0.1567,0.1570,0.1573,0.1576,0.1579,0.1583,0.1586,0.1589,0.1592,0.1595,0.1599,0.1602,0.1605,0.1608,0.1611,0.1619,0.1628,0.1637,0.1646,0.1655,0.1665,0.1674,0.1683,0.1692,0.1701,0.1710,0.1730,0.1750,0.1771,0.1791,0.1811,0.1831,0.1852;0.0666,0.0666,0.0667,0.0669,0.0670,0.0671,0.0673,0.0674,0.0675,0.0676,0.0678,0.0679,0.0680,0.0681,0.0683,0.0684,0.0685,0.0686,0.0688,0.0689,0.0690,0.0691,0.0693,0.0694,0.0695,0.0696,0.0698,0.0699,0.0700,0.0701,0.0702,0.0703,0.0704,0.0705,0.0705,0.0706,0.0707,0.0708,0.0708,0.0709,0.0710,0.0711,0.0711,0.0712,0.0713,0.0714,0.0714,0.0715,0.0716,0.0717,0.0717,0.0718,0.0719,0.0720,0.0720,0.0721,0.0722,0.0723,0.0724,0.0724,0.0725,0.0726,0.0727,0.0727,0.0728,0.0730,0.0732,0.0735,0.0737,0.0739,0.0742,0.0744,0.0746,0.0749,0.0751,0.0753,0.0756,0.0758,0.0760,0.0763,0.0765,0.0767,0.0770,0.0772,0.0774,0.0777,0.0779,0.0781,0.0784,0.0786,0.0788,0.0791,0.0793,0.0795,0.0798,0.0800,0.0802,0.0805,0.0807,0.0809,0.0812,0.0814,0.0816,0.0819,0.0821,0.0826,0.0831,0.0837,0.0843,0.0848,0.0854,0.0860,0.0865,0.0871,0.0877,0.0882,0.0888,0.0894,0.0899,0.0905,0.0911,0.0916,0.0922,0.0927,0.0933,0.0939,0.0944,0.0950,0.0956,0.0961,0.0967,0.0973,0.0978,0.0984,0.0990,0.0995,0.1001,0.1007,0.1012,0.1018,0.1024,0.1029,0.1035,0.1041,0.1046,0.1052,0.1058,0.1063,0.1069,0.1075,0.1080,0.1086,0.1092,0.1098,0.1103,0.1109,0.1115,0.1120,0.1126,0.1132,0.1137,0.1143,0.1149,0.1154,0.1159,0.1163,0.1167,0.1171,0.1175,0.1179,0.1183,0.1187,0.1191,0.1195,0.1199,0.1203,0.1207,0.1211,0.1216,0.1220,0.1224,0.1228,0.1232,0.1236,0.1240,0.1244,0.1248,0.1252,0.1256,0.1260,0.1264,0.1268,0.1273,0.1277,0.1281,0.1285,0.1289,0.1293,0.1297,0.1301,0.1305,0.1309,0.1313,0.1317,0.1321,0.1325,0.1329,0.1333,0.1337,0.1341,0.1346,0.1350,0.1354,0.1358,0.1362,0.1366,0.1370,0.1374,0.1378,0.1382,0.1386,0.1390,0.1394,0.1398,0.1402,0.1406,0.1410,0.1414,0.1418,0.1422,0.1427,0.1431,0.1435,0.1439,0.1443,0.1447,0.1451,0.1455,0.1459,0.1463,0.1467,0.1471,0.1475,0.1479,0.1483,0.1487,0.1491,0.1495,0.1499,0.1504,0.1508,0.1512,0.1515,0.1519,0.1522,0.1525,0.1528,0.1531,0.1535,0.1538,0.1541,0.1544,0.1547,0.1551,0.1554,0.1557,0.1560,0.1563,0.1567,0.1570,0.1573,0.1576,0.1579,0.1583,0.1586,0.1589,0.1592,0.1595,0.1599,0.1602,0.1605,0.1608,0.1611,0.1619,0.1628,0.1637,0.1646,0.1655,0.1665,0.1674,0.1683,0.1692,0.1701,0.1710,0.1730,0.1750,0.1771,0.1791,0.1811,0.1831,0.1852;0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000", 0, {})
landscape.add_op_item(op_item) # Add optical properties
op_item = OpticalItem("fagus_leaf", "0.0761,0.0795,0.0832,0.0871,0.0914,0.0958,0.0999,0.1043,0.1089,0.1136,0.1185,0.1238,0.1294,0.1352,0.1412,0.1472,0.1532,0.1594,0.1654,0.1716,0.1781,0.1848,0.1914,0.1979,0.2042,0.2106,0.2169,0.2229,0.2290,0.2354,0.2419,0.2486,0.2553,0.2619,0.2684,0.2748,0.2811,0.2871,0.2933,0.2993,0.3052,0.3107,0.3161,0.3218,0.3275,0.3332,0.3390,0.3453,0.3513,0.3572,0.3628,0.3682,0.3733,0.3786,0.3840,0.3892,0.3942,0.3992,0.4046,0.4092,0.4137,0.4177,0.4215,0.4250,0.4281,0.4303,0.4330,0.4352,0.4381,0.4411,0.4436,0.4461,0.4482,0.4507,0.4528,0.4544,0.4562,0.4577,0.4591,0.4607,0.4628,0.4643,0.4661,0.4678,0.4699,0.4720,0.4744,0.4769,0.4797,0.4827,0.4857,0.4889,0.4922,0.4956,0.4991,0.5027,0.5063,0.5101,0.5139,0.5177,0.5216,0.5255,0.5294,0.5332,0.5371,0.5409,0.5448,0.5485,0.5523,0.5559,0.5595,0.5630,0.5665,0.5698,0.5731,0.5762,0.5792,0.5820,0.5847,0.5872,0.5895,0.5916,0.5936,0.5954,0.5971,0.5985,0.5998,0.6010,0.6020,0.6028,0.6035,0.6041,0.6046,0.6049,0.6052,0.6054,0.6056,0.6056,0.6056,0.6056,0.6055,0.6055,0.6053,0.6052,0.6051,0.6050,0.6049,0.6048,0.6048,0.6046,0.6045,0.6044,0.6042,0.6040,0.6038,0.6035,0.6031,0.6028,0.6023,0.6018,0.6013,0.6008,0.6001,0.5994,0.5987,0.5979,0.5970,0.5960,0.5950,0.5940,0.5929,0.5918,0.5906,0.5895,0.5884,0.5873,0.5862,0.5852,0.5842,0.5833,0.5823,0.5814,0.5805,0.5797,0.5789,0.5781,0.5774,0.5766,0.5760,0.5753,0.5748,0.5742,0.5737,0.5733,0.5728,0.5724,0.5720,0.5716,0.5712,0.5708,0.5704,0.5700,0.5695,0.5690,0.5684,0.5677,0.5671,0.5663,0.5655,0.5646,0.5637,0.5628,0.5618,0.5608,0.5598,0.5588,0.5579,0.5569,0.5560,0.5552,0.5544,0.5537,0.5531,0.5526,0.5521,0.5517,0.5514,0.5512,0.5509,0.5507,0.5505,0.5503,0.5499,0.5495,0.5489,0.5482,0.5473,0.5462,0.5450,0.5436,0.5420,0.5403,0.5385,0.5365,0.5345,0.5324,0.5304,0.5284,0.5265,0.5247,0.5231,0.5217,0.5203,0.5190,0.5176,0.5160,0.5143,0.5122,0.5099,0.5072,0.5042,0.5007,0.4971,0.4932,0.4893,0.4852,0.4811,0.4774,0.4738,0.4706,0.4676,0.4652,0.4630,0.4614,0.4599,0.4590,0.4583,0.4584,0.4587,0.4604,0.4626,0.4668,0.4715,0.4780,0.4850,0.4931,0.5015,0.5101,0.5187,0.5274,0.5358,0.5438,0.5515,0.5587,0.5655,0.5717,0.5774,0.5826,0.5874,0.5916,0.5955;0.0761,0.0795,0.0832,0.0871,0.0914,0.0958,0.0999,0.1043,0.1089,0.1136,0.1185,0.1238,0.1294,0.1352,0.1412,0.1472,0.1532,0.1594,0.1654,0.1716,0.1781,0.1848,0.1914,0.1979,0.2042,0.2106,0.2169,0.2229,0.2290,0.2354,0.2419,0.2486,0.2553,0.2619,0.2684,0.2748,0.2811,0.2871,0.2933,0.2993,0.3052,0.3107,0.3161,0.3218,0.3275,0.3332,0.3390,0.3453,0.3513,0.3572,0.3628,0.3682,0.3733,0.3786,0.3840,0.3892,0.3942,0.3992,0.4046,0.4092,0.4137,0.4177,0.4215,0.4250,0.4281,0.4303,0.4330,0.4352,0.4381,0.4411,0.4436,0.4461,0.4482,0.4507,0.4528,0.4544,0.4562,0.4577,0.4591,0.4607,0.4628,0.4643,0.4661,0.4678,0.4699,0.4720,0.4744,0.4769,0.4797,0.4827,0.4857,0.4889,0.4922,0.4956,0.4991,0.5027,0.5063,0.5101,0.5139,0.5177,0.5216,0.5255,0.5294,0.5332,0.5371,0.5409,0.5448,0.5485,0.5523,0.5559,0.5595,0.5630,0.5665,0.5698,0.5731,0.5762,0.5792,0.5820,0.5847,0.5872,0.5895,0.5916,0.5936,0.5954,0.5971,0.5985,0.5998,0.6010,0.6020,0.6028,0.6035,0.6041,0.6046,0.6049,0.6052,0.6054,0.6056,0.6056,0.6056,0.6056,0.6055,0.6055,0.6053,0.6052,0.6051,0.6050,0.6049,0.6048,0.6048,0.6046,0.6045,0.6044,0.6042,0.6040,0.6038,0.6035,0.6031,0.6028,0.6023,0.6018,0.6013,0.6008,0.6001,0.5994,0.5987,0.5979,0.5970,0.5960,0.5950,0.5940,0.5929,0.5918,0.5906,0.5895,0.5884,0.5873,0.5862,0.5852,0.5842,0.5833,0.5823,0.5814,0.5805,0.5797,0.5789,0.5781,0.5774,0.5766,0.5760,0.5753,0.5748,0.5742,0.5737,0.5733,0.5728,0.5724,0.5720,0.5716,0.5712,0.5708,0.5704,0.5700,0.5695,0.5690,0.5684,0.5677,0.5671,0.5663,0.5655,0.5646,0.5637,0.5628,0.5618,0.5608,0.5598,0.5588,0.5579,0.5569,0.5560,0.5552,0.5544,0.5537,0.5531,0.5526,0.5521,0.5517,0.5514,0.5512,0.5509,0.5507,0.5505,0.5503,0.5499,0.5495,0.5489,0.5482,0.5473,0.5462,0.5450,0.5436,0.5420,0.5403,0.5385,0.5365,0.5345,0.5324,0.5304,0.5284,0.5265,0.5247,0.5231,0.5217,0.5203,0.5190,0.5176,0.5160,0.5143,0.5122,0.5099,0.5072,0.5042,0.5007,0.4971,0.4932,0.4893,0.4852,0.4811,0.4774,0.4738,0.4706,0.4676,0.4652,0.4630,0.4614,0.4599,0.4590,0.4583,0.4584,0.4587,0.4604,0.4626,0.4668,0.4715,0.4780,0.4850,0.4931,0.5015,0.5101,0.5187,0.5274,0.5358,0.5438,0.5515,0.5587,0.5655,0.5717,0.5774,0.5826,0.5874,0.5916,0.5955;0.0000,0.0001,0.0001,0.0001,0.0001,0.0002,0.0002,0.0003,0.0003,0.0004,0.0005,0.0005,0.0007,0.0008,0.0009,0.0011,0.0013,0.0015,0.0017,0.0020,0.0023,0.0026,0.0029,0.0033,0.0037,0.0041,0.0046,0.0050,0.0055,0.0061,0.0067,0.0074,0.0081,0.0088,0.0096,0.0103,0.0112,0.0120,0.0129,0.0138,0.0147,0.0156,0.0165,0.0175,0.0185,0.0196,0.0207,0.0220,0.0233,0.0245,0.0258,0.0270,0.0283,0.0296,0.0309,0.0322,0.0336,0.0349,0.0364,0.0377,0.0390,0.0402,0.0414,0.0425,0.0434,0.0441,0.0450,0.0457,0.0466,0.0476,0.0484,0.0493,0.0500,0.0509,0.0516,0.0522,0.0528,0.0533,0.0538,0.0544,0.0552,0.0557,0.0564,0.0571,0.0578,0.0586,0.0595,0.0605,0.0615,0.0627,0.0639,0.0651,0.0664,0.0678,0.0692,0.0707,0.0722,0.0738,0.0754,0.0770,0.0787,0.0805,0.0822,0.0839,0.0857,0.0875,0.0892,0.0910,0.0928,0.0946,0.0963,0.0980,0.0998,0.1014,0.1031,0.1047,0.1063,0.1077,0.1091,0.1105,0.1117,0.1129,0.1140,0.1150,0.1159,0.1168,0.1176,0.1182,0.1188,0.1194,0.1198,0.1202,0.1206,0.1209,0.1211,0.1213,0.1215,0.1216,0.1217,0.1218,0.1219,0.1219,0.1220,0.1220,0.1221,0.1221,0.1222,0.1222,0.1223,0.1223,0.1224,0.1224,0.1225,0.1225,0.1224,0.1224,0.1223,0.1223,0.1221,0.1220,0.1219,0.1217,0.1215,0.1212,0.1209,0.1206,0.1203,0.1199,0.1195,0.1190,0.1186,0.1181,0.1177,0.1172,0.1167,0.1162,0.1158,0.1154,0.1150,0.1146,0.1143,0.1139,0.1136,0.1132,0.1129,0.1126,0.1124,0.1121,0.1119,0.1117,0.1115,0.1113,0.1111,0.1110,0.1108,0.1107,0.1106,0.1105,0.1104,0.1103,0.1101,0.1100,0.1098,0.1096,0.1094,0.1092,0.1089,0.1086,0.1083,0.1079,0.1075,0.1071,0.1067,0.1063,0.1059,0.1055,0.1050,0.1046,0.1043,0.1039,0.1036,0.1033,0.1031,0.1029,0.1027,0.1026,0.1025,0.1024,0.1023,0.1023,0.1022,0.1021,0.1020,0.1018,0.1016,0.1013,0.1009,0.1004,0.0998,0.0992,0.0984,0.0976,0.0968,0.0959,0.0949,0.0940,0.0931,0.0921,0.0913,0.0905,0.0898,0.0891,0.0885,0.0879,0.0873,0.0866,0.0858,0.0849,0.0839,0.0827,0.0814,0.0799,0.0783,0.0767,0.0750,0.0733,0.0717,0.0701,0.0687,0.0675,0.0663,0.0654,0.0645,0.0639,0.0634,0.0630,0.0628,0.0628,0.0630,0.0636,0.0645,0.0661,0.0680,0.0706,0.0735,0.0770,0.0806,0.0844,0.0883,0.0923,0.0963,0.1002,0.1039,0.1076,0.1110,0.1142,0.1172,0.1200,0.1225,0.1248,0.1270", 0, {})
landscape.add_op_item(op_item) # Add optical properties

Objects

#If yo do not intend to change scene structures, you should comment out this section to avoid importing objs for each simulation,
#and you should also comment out landscape.clear_landscape_elements()

#ashape folder
ashape_folder = r"J:/Rheinland Pfalz Projekt/K_RP/03_ashapes_allTrees"
#dynmic handling of plot name in patter
plot_name = "SB_1"
#Define the pattern to search for
pattern = f"{plot_name}treeashape.obj"
#pattern = "VB_9_tree
_ashape.obj"
matching_files = glob.glob(os.path.join(ashape_folder, pattern))

print(f"Searching for pattern: {os.path.join(ashape_folder, pattern)}")
print(f"Found files: {matching_files}")

#Normalize paths to use forward slashes
normalized_files = [os.path.normpath(file) for file in matching_files]

#Regular expression to extract the tree number (adjusted to match dynamic plot_name)
regex = re.compile(rf"^{plot_name.split('')[0]}.tree(\d+)_.*.obj$")

#Dictionary to store files by tree number
tree_files = {}
#Find all objects for the designated plot and categorize by tree number
for file in normalized_files:
file_name = os.path.basename(file) # Get the file name without the path
match = regex.match(file_name)
#print matching for file
#print(f"matching file: {file_name}")
if match:
tree_number = int(match.group(1)) # Extract the tree number
tree_files[tree_number] = file # Store the file with its tree number
#print tree number and file
#print(f"tree number extraction: {tree_number}, file: {file}")
sorted_tree_numbers = sorted(tree_files.keys())

#setting a small number of test trees
subset = sorted_tree_numbers[1:10]
#print subset
#print(f"subset: {subset}")

#add alphashapes and polygons by looping through file tree names
#Loop through tree numbers and create SceneObjects
for tree_number in subset:
tree_name = f"{plot_name}Tree{tree_number:02d}"
#print tree name processed
print(f"Processing tree (SceneObject creation): {tree_name}")

obj = SceneObject(tree_name)  # Define an object

#Add components based on the files
obj.add_component_from_file(
    rf"J:/Rheinland Pfalz Projekt/K_RP/03_ashapes_allTrees/{plot_name}_tree_{tree_number}_ashape.obj", 
    "fagus_leaf", temperature="-", color="0x006400ff", is_turbid=True, leaf_density=8,
    lad="Spherical", hotspot_factor=-999
)

obj.add_component_from_file(
    rf"J:/Rheinland Pfalz Projekt/K_RP/03_polygons_stems_allTrees/{plot_name}_tree_{tree_number}_bark.obj", 
    "fagus_bark", color="0x483D8BFF"
)

#Add the object to the landscape
landscape.add_object(obj)

#Instances
#If you do not intend to change scene structures, you should comment out this section,
#and you should also comment out landscape.clear_landscape_elements()
#You can read the positions from a file and using a loop to place objects, [X Y Z Rotation]
common_position = [0.0, 78.7345, 0.0, 0.0] #z -4.25

#place each tree in the landscape at the same position
for tree_number in subset:
tree_name = f"{plot_name}Tree{tree_number:02d}"
landscape.place_object(tree_name, x=common_position[0], y=common_position[1], z=common_position[2], rotate=common_position[3])

Terrain

#If you use default optical ,e.g., dark_soil_mollisol, and if you change the number of spectral
#bands, please define your own optical properties, otherwise, there will be band number issues.
#The three default optical properties have two bands only in the PyLessSDK.
terrain = landscape.get_terrain()
terrain.set_extent_width(115)
terrain.set_extent_height(115)
terrain.set_terrain_type(TERRAIN_TYPE.MESH)
terrain.set_terrain_file(r"C:\Users\K\Documents\LESS\sim_ashapes_SB\Parameters\DTM_transformed_shifted.obj")
terrain.set_terr_brdf_type(TERRAIN_BRDF_TYPE.SPATIALLY_UNIFORM)
terrain.set_optical(r"dark_soil_mollisol")
#If you want to open the simulation with GUI, please uncomment this following line
#sim.prepare_for_ui()

Sensor

#!Note that scene.set_sensor(sensor) should be executed after sensor setup is complete!
sensor = SensorPhotonTracing()
sensor.set_spectral_bands("400.00:1,401.00:1,402.00:1,403.00:1,404.00:1,405.00:1,406.00:1,407.00:1,408.00:1,409.00:1,410.00:1,411.00:1,412.00:1,413.00:1,414.00:1,415.00:1,416.00:1,417.00:1,418.00:1,419.00:1,420.00:1,421.00:1,422.00:1,423.00:1,424.00:1,425.00:1,426.00:1,427.00:1,428.00:1,429.00:1,430.00:1,431.00:1,432.00:1,433.00:1,434.00:1,435.00:1,436.00:1,437.00:1,438.00:1,439.00:1,440.00:1,441.00:1,442.00:1,443.00:1,444.00:1,445.00:1,446.00:1,447.00:1,448.00:1,449.00:1,450.00:1,451.00:1,452.00:1,453.00:1,454.00:1,455.00:1,456.00:1,457.00:1,458.00:1,459.00:1,460.00:1,461.00:1,462.00:1,463.00:1,464.00:1,465.00:1,466.00:1,467.00:1,468.00:1,469.00:1,470.00:1,471.00:1,472.00:1,473.00:1,474.00:1,475.00:1,476.00:1,477.00:1,478.00:1,479.00:1,480.00:1,481.00:1,482.00:1,483.00:1,484.00:1,485.00:1,486.00:1,487.00:1,488.00:1,489.00:1,490.00:1,491.00:1,492.00:1,493.00:1,494.00:1,495.00:1,496.00:1,497.00:1,498.00:1,499.00:1,500.00:1,501.00:1,502.00:1,503.00:1,504.00:1,505.00:1,506.00:1,507.00:1,508.00:1,509.00:1,510.00:1,511.00:1,512.00:1,513.00:1,514.00:1,515.00:1,516.00:1,517.00:1,518.00:1,519.00:1,520.00:1,521.00:1,522.00:1,523.00:1,524.00:1,525.00:1,526.00:1,527.00:1,528.00:1,529.00:1,530.00:1,531.00:1,532.00:1,533.00:1,534.00:1,535.00:1,536.00:1,537.00:1,538.00:1,539.00:1,540.00:1,541.00:1,542.00:1,543.00:1,544.00:1,545.00:1,546.00:1,547.00:1,548.00:1,549.00:1,550.00:1,551.00:1,552.00:1,553.00:1,554.00:1,555.00:1,556.00:1,557.00:1,558.00:1,559.00:1,560.00:1,561.00:1,562.00:1,563.00:1,564.00:1,565.00:1,566.00:1,567.00:1,568.00:1,569.00:1,570.00:1,571.00:1,572.00:1,573.00:1,574.00:1,575.00:1,576.00:1,577.00:1,578.00:1,579.00:1,580.00:1,581.00:1,582.00:1,583.00:1,584.00:1,585.00:1,586.00:1,587.00:1,588.00:1,589.00:1,590.00:1,591.00:1,592.00:1,593.00:1,594.00:1,595.00:1,596.00:1,597.00:1,598.00:1,599.00:1,600.00:1,601.00:1,602.00:1,603.00:1,604.00:1,605.00:1,606.00:1,607.00:1,608.00:1,609.00:1,610.00:1,611.00:1,612.00:1,613.00:1,614.00:1,615.00:1,616.00:1,617.00:1,618.00:1,619.00:1,620.00:1,621.00:1,622.00:1,623.00:1,624.00:1,625.00:1,626.00:1,627.00:1,628.00:1,629.00:1,630.00:1,631.00:1,632.00:1,633.00:1,634.00:1,635.00:1,636.00:1,637.00:1,638.00:1,639.00:1,640.00:1,641.00:1,642.00:1,643.00:1,644.00:1,645.00:1,646.00:1,647.00:1,648.00:1,649.00:1,650.00:1,651.00:1,652.00:1,653.00:1,654.00:1,655.00:1,656.00:1,657.00:1,658.00:1,659.00:1,660.00:1,661.00:1,662.00:1,663.00:1,664.00:1,665.00:1,666.00:1,667.00:1,668.00:1,669.00:1,670.00:1,671.00:1,672.00:1,673.00:1,674.00:1,675.00:1,676.00:1,677.00:1,678.00:1,679.00:1,680.00:1,681.00:1,682.00:1,683.00:1,684.00:1,685.00:1,686.00:1,687.00:1,688.00:1,689.00:1,690.00:1,691.00:1,692.00:1,693.00:1,694.00:1,695.00:1,696.00:1,697.00:1,698.00:1,699.00:1,700.00:1")
sensor.enable_brf_product(True)
sensor.enable_Fluor_product(0)
sensor.set_sun_ray_resolution(0.02)
sensor.set_virtual_directions("")
sensor.enable_fpar_product(True)
sensor.set_fpar_layer("0:5:60")

scene.set_sensor(sensor)
obs = ObservationPhotonTracing()
scene.set_observation(obs)

enable batch processing (when outcommented, the code works)

sim.enable_runtime_modification_of_properties(True)
sim.reload_runtime_structural_properties()
#sim.save_sim_project()
#sim.prepare_for_ui()

Iterate over sun angles for 2 test times (batch processing)

zenith_list = [83.25, 73.35]
azimuth_list = [75.18, 86]

month_list = [4, 4]
day_list = [30, 30]

rang = 2

for k in range(rang):
try:

#set output filename for each iteration
print(f"Running simulation for iteration {k} with month={month_list[k]}, day={day_list[k]}, zenith={zenith_list[k]}, azimuth={azimuth_list[k]}")
sim.set_dist_file(os.path.join(sim.get_sim_dir(), "Results", "output_photontracing_"+str(+k)))

# Illumination
illu = Illumination()

if zenith_list[k] > 85:
  print(f"Warning: Zenith angle at iteration {k} is over 85°, resetting to 85°")
  illu.set_sun_zenith(85)
else:
  illu.set_sun_zenith(zenith_list[k])

#illu.set_sun_zenith(zenith_list[k])
illu.set_sun_azimuth(azimuth_list[k])
#The type can be SKY_TO_TOTAL or ATMOSPHERE
illu.set_ats_type("ATMOSPHERE")
illu.set_ats_model("6S")
model_6s = Atmosphere6S()
model_6s.ats_profile="MidlatitudeSummer" 
model_6s.aot_550=0.375
model_6s.target_altitude=0
model_6s.aero_profile="Continental" 
model_6s.month=month_list[k]
model_6s.day=day_list[k]
scene.set_illumination(illu)


# Advanced Parameter
scene.get_advanced_params().set_number_of_cores(16)  # How many CPU cores used to do simulation

# Simulation
#You can use sim.set_dist_file to customize the final file name
#You can use PostProcessing.radiance2brf to convert radiance image to BRF image

sim.save_sim_project()
sim.start()

except Exception as e:
print(f"Error occurred during iteration {k}: {e}")

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions