OmbreaPV / pySTICS

Python Implementation of a simplified version of STICS crop model
https://ombreapv.github.io/pySTICS/
MIT License
9 stars 2 forks source link

corn simulation #6

Open edericqu opened 3 months ago

edericqu commented 3 months ago

Hi,

I am trying to run pySTICS for corn simulation.

I have taken de "run_pystics_simulation_stics_example.ipynb" and changed species and variety to :

species = 'corn' variety = 'Cherif'

where 'Cherif' is a variety present in "corn_plt.xml"

the "parametrization_from_stics_example_files" function retrieves correctly the different example parameters, but the execution fails in the simulation run_pystics_simulation where i get the bellow error:

""" in senescence_stress(lev_i, ulai, vlaimax, temp_min_prev, tgeljuv10, tgeljuv90, tgelveg10, tgelveg90, tletale, tdebgel, codgeljuv, codgelveg) else: fstressgel = 1 return fstressgel """ UnboundLocalError: cannot access local variable 'fstressgel' where it is not associated with a value

If you have any insights to resolve this issue i am having. (When leaving to wheat and Talent everything works fine)

Best regards

edericqu commented 3 months ago

As a work around i modified the function bellow by adding an init value to the return value. fstressgel = 1 at the start of the function, and seems to have corrected the issue :

def senescence_stress(lev_i, ulai, vlaimax, temp_min_prev, tgeljuv10, tgeljuv90, tgelveg10, tgelveg90, tletale, tdebgel, codgeljuv, codgelveg):

    fstressgel = 1 // ADDED INIT

    if lev_i > 0:

        # Frost stress
        if (
            ulai < vlaimax
        ):  # si on est avant stade iamf --> fgeljuv
            if codgeljuv == 2:
                fstressgel = frost_stress(temp_min_prev, tgeljuv90, tgeljuv10, tletale, tdebgel)

       else:  # après stade iamf -> fgelveg
            if codgelveg == 2:
                fstressgel = frost_stress(temp_min_prev, tgelveg90, tgelveg10, tletale, tdebgel)
    else:
        fstressgel = 1

    return fstressgel
etienneperez commented 2 months ago

hey @edericqu Thanks for your warning ! I never had this issue on wheat, but I saw the same kind of problem on other modules if the output has not been initialized and when none of the condition is verified. I think your fix is fine, I will add it to the new version released in few days

pySTICS has not been tested and validated on corn yet, so take your precautions when interpreting your results. Validated species will be gradually mentioned in the readme

edericqu commented 2 months ago

OK, thanks for your warning @etienneperez , that might explain that somme paramaters had very little infleunce is my initials tests.

Are the weather and soil modules validated in a general matter, or need to be adapted to each crop ?

etienneperez commented 2 months ago

The options implemented in pySTICS seem validated in our first tests on wheat, we are currently testing other determinate growth crops and forage crops to see if specific formalisms are needed (for example, codlainet code for barley and cutting for forage crops were implemented). @edericqu