thouska / spotpy

A Statistical Parameter Optimization Tool
https://spotpy.readthedocs.io/en/latest/
MIT License
254 stars 152 forks source link

`list index out of range` error in `def __call__(self,jobs)` of `sequential.py` #262

Closed DavidChoi76 closed 3 years ago

DavidChoi76 commented 3 years ago

I'm studying spotpy to apply to the SUMMA model. I'm a beginner at uncertainty analysis. I created spotpy_setup class and apply this class to spotpy and SUMMA. But there was no problem until 56 times simulations. But I got an error after that. Do you know what the problem is or how to fix it?

54 of 100, min objf=0.157309, max objf=0.223511, time remaining: 00:04:49 ['/home/jovyan/work/SUMMA3_Manual/SummaModel_ReynoldsAspenStand_BasicPlot/output/vegImpactsTranspire_Jarvis_0.5694176471187008_timestep.nc'] 55 of 100, min objf=0.157309, max objf=0.223511, time remaining: 00:04:43 ['/home/jovyan/work/SUMMA3_Manual/SummaModel_ReynoldsAspenStand_BasicPlot/output/vegImpactsTranspire_Jarvis_0.6860752758665234_timestep.nc'] 56 of 100, min objf=0.157309, max objf=0.223511, time remaining: 00:04:36 []


IndexError Traceback (most recent call last)

in 2 #sampler = spotpy.algorithms.sceua(spotpy_setup(),dbname='SCEUA_CMF',dbformat='csv') 3 results=[] ----> 4 sampler.sample(100) 5 results.append(sampler.getdata()) /opt/conda/envs/pysumma/lib/python3.8/site-packages/spotpy/algorithms/mc.py in sample(self, repetitions) 67 param_generator = ((rep, self.parameter()['random']) 68 for rep in range(int(repetitions))) ---> 69 for rep, randompar, simulations in self.repeat(param_generator): 70 # A function that calculates the fitness of the run and the manages the database 71 self.postprocessing(rep, randompar, simulations) /opt/conda/envs/pysumma/lib/python3.8/site-packages/spotpy/parallel/sequential.py in __call__(self, jobs) 25 def __call__(self,jobs): 26 for job in jobs: ---> 27 data = self.process(job) 28 yield data 29 /opt/conda/envs/pysumma/lib/python3.8/site-packages/spotpy/algorithms/_algorithm.py in simulate(self, id_params_tuple) 465 466 else: --> 467 model_result = self.setup.simulation(self.partype(*all_params)) 468 469 return id, params, model_result in simulation(self, vector) 46 results_simpleResistance_ncfile = S.get_output_files() 47 print(results_simpleResistance_ncfile) ---> 48 results_simpleResistance = xr.open_dataset(results_simpleResistance_ncfile[0]) 49 simResis_hour = self.calc_total_et(results_simpleResistance) 50 IndexError: list index out of range
thouska commented 3 years ago

Hi @DavidChoi76,

thank you for your message. From looking at the error message it looks to me like the model did not produce all the results you expected it to produce. This is commonly happening with models, e.g. if a parameter combination is not optimal and results in numerical errors. There are two ways to fix this: Option 1: Try to figure out why the model fails with the given paramter set and fix this. Option 2: Ignore the model failure and help spotpy to move on. This means that whatever is happening inside of the def simulation function should not result in any errors. This can be handled with try/except statements. Just make sure that if the model brakes you return the number of simulation results you would have expected. A example for such an approach can be found here and there Lines 59 and 87-89.

DavidChoi76 commented 3 years ago

Thank you so much. I will try it.

thouska commented 3 years ago

I assume this issue is solved, if not feel free to re-open.