kthorp / pyfao56

A Python implementation of the FAO-56 dual crop coefficient approach for crop water use estimation and irrigation scheduling
Other
46 stars 25 forks source link

soil_water.py computeDr() IndexError #60

Closed tpokoski closed 1 month ago

tpokoski commented 1 month ago

I have been working on adding measured soil water content data that doesn't reach a depth that meets the rzmax. This leads to an IndexError when trying to use the computeDr() function.

Lines in question are at 405 in _soilwater.py:

        for inc in list(range(1, rzmax + 1)):
            #Find soil profile layer depth that contains inc
            sol_dpth = [dpth for (idx, dpth) in enumerate(sol_dpths)
                        if inc <= dpth * 1000][0] #10^-5 meters

From what I've been able to figure out, I need to include measurements to meet or exceed the rzmax. If my rzmax is 105000 (1.05 from par.Zrmax * 100000), and _soldpths list is [45, 75], then the loop will follow increments until inc = 75001 and then give an "IndexError: list index out of range". Once 75001 is reached, the list does not meet the if statement, and is empty, but then indexing is attempted with the [0] and it breaks. I assume this will also happen to the _swcdpth list, as it follows the same list comprehension, but the loop breaks prior to actually seeing that.

It may be possible to do a try/except block, but I'm not sure of what _soldpth should equal in order to calculate the remaining variables in the function.

isukendall commented 1 month ago

Is it possible to give an alternate equation to calculate Dr? The Clutter and DeJonge (2022) paper gives methods to estimate Dr from machine learning optimization, based only on two sensor locations.

Clutter, M., & DeJonge, K. (2022). Optimizing soil moisture sensor depth for irrigation management using universal multiple linear regression. Journal of the ASABE, 0. https://elibrary.asabe.org/abstract.asp?aid=53505https://https/elibrary.asabe.org/abstract.asp?aid=53505

Kendall DeJonge Agricultural Engineer USDA-ARS

Currently hiring a Post-Doc! ( https://www.usajobs.gov/job/805649700

From: Tyler Pokoski @.> Sent: Thursday, September 19, 2024 3:01 PM To: kthorp/pyfao56 @.> Cc: Subscribed @.***> Subject: [kthorp/pyfao56] soil_water.py computeDr() IndexError (Issue #60)

I have been working on adding measured soil water content data that doesn't reach a depth that meets the rzmax. This leads to an IndexError when trying to use the computeDr() function.

Lines in question are at 405 in soil_water.py:

    for inc in list(range(1, rzmax + 1)):

        #Find soil profile layer depth that contains inc

        sol_dpth = [dpth for (idx, dpth) in enumerate(sol_dpths)

                    if inc <= dpth * 1000][0] #10^-5 meters

From what I've been able to figure out, I need to include measurements to meet or exceed the rzmax. If my rzmax is 105000 (1.05 from par.Zrmax * 100000), and sol_dpths list is [45, 75], then the loop will follow increments until inc = 75001 and then give an "IndexError: list index out of range". Once 75001 is reached, the list does not meet the if statement, and is empty, but then indexing is attempted with the [0] and it breaks. I assume this will also happen to the swc_dpth list, as it follows the same list comprehension, but the loop breaks prior to actually seeing that.

It may be possible to do a try/except block, but I'm not sure of what sol_dpth should equal in order to calculate the remaining variables in the function.

- Reply to this email directly, view it on GitHubhttps://github.com/kthorp/pyfao56/issues/60, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACL2P2DR3FGRFGKXTBWAR2TZXM3RFAVCNFSM6AAAAABOQXNZ32VHI2DSMVQWIX3LMV43ASLTON2WKOZSGUZTOMZWGAZDAMA. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>

This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

kthorp commented 1 month ago

The model bases it's calculations on the user input of Zrmax in Parameters. Thus, if the user also specifies a layered soil profile or wants to evaluate measured soil water content, they must ensure that their layered soil profile or water content measurement depths equal or exceed their specified Zrmax. I have now included some tests in soil_water.py and model.py to raise exceptions if inputted layer data is shallower than Zrmax. It would be up to the user to either adjust Zrmax or adjust their assumptions for measurement depths to meet the requirement. I'm open to an alternative suggestion, but feel that the user should be required to adjust their inputs in this case, rather than the model making changes to what the user has inputted.

For your specific case, you would either need to 1) reduce Zrmax in Parameters or 2) assume that the measurements in the lowest profile depth extend to Zrmax and adjust the bottom soil layer depth accordingly.

tpokoski commented 1 month ago

Gotcha, thanks for the clarification, and I like the way that the raise exceptions will work.