From 8a7f16836cbe7106038d60d8d3987c3573e23428 Mon Sep 17 00:00:00 2001 From: Marco Matthies <71844+marcom@users.noreply.github.com> Date: Thu, 7 Nov 2024 02:53:25 +0100 Subject: [PATCH] Cosmetics: remove commented-out code and rearrange comments --- src/crop/almass.jl | 52 ++++++++++------------------------------------ 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/src/crop/almass.jl b/src/crop/almass.jl index 39a9f83..90e2c58 100644 --- a/src/crop/almass.jl +++ b/src/crop/almass.jl @@ -3,12 +3,6 @@ ### This file is responsible for managing the crop growth modules. ### -#FIXME Looking at fields.pdf in the Persefone output, crop maturity is not recognised -# properly, so most crops (except maize) are never planted. At the same time, maize never -# seems to start growing. - -#TODO write tests to compare our output to the output of the original ALMaSS algorithm - # Some functions translated from ALMaSS for use in Persefone.jl # # ALMaSS is licensed as follows: @@ -33,6 +27,13 @@ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#FIXME Looking at fields.pdf in the Persefone output, crop maturity is not recognised +# properly, so most crops (except maize) are never planted. At the same time, maize never +# seems to start growing. + +#TODO write tests to compare our output to the output of the original ALMaSS algorithm + module ALMaSS ## The two input files required by ALMaSS. Must be present in the crop directory. @@ -557,41 +558,15 @@ function find_diff(dds::Vector{Float64}, slopes::Vector{T}, ddegs::Float64, ydde # more than a single inflection point in the growth curve in a # single day... - # n = length(dds) - # oldindex = 1 - # newindex = 1 + # Note: the code is slightly different to the original ALMaSS + # code, which I think is caused by ALMaSS not storing the -1 entry + # in the dds array. if first(dds) == 99999.0 return 0.0 * oneunit(T) # zero(T) does not work when slopes has units end - # for i = 1:n-1 - # if dds[i + 1] > ddegs - # newindex = i - # break - # end - # end - # for i = 1:n-1 - # if dds[i + 1] > yddegs - # oldindex = i - # break - # end - # end - - # # Note/TODO: we skip over the first datapoint if dds[1] == -1 - # # (which means that this is not a slop but should set the - # # height/LAgreen/LAtotal). Presumably the original ALMaSS code - # # does not include these points with the slopes. - # if dds[1] == -1 - # if oldindex == 1 - # oldindex = 2 - # end - # if newindex == 1 - # newindex = 2 - # end - # end - - function get_index(array::T, threshold::eltype(T)) where {T <: DenseArray} + function get_index(array::Tarr, threshold::eltype(Tarr)) where {Tarr <: DenseArray} idx = findfirst(x -> x > threshold, array) if isnothing(idx) idx = lastindex(array) + 1 @@ -614,19 +589,14 @@ function find_diff(dds::Vector{Float64}, slopes::Vector{T}, ddegs::Float64, ydde # We have passed an inflection point between today and yesterday. # First add the increment from yesterdays day degree sum up to # the inflection point. - # dddif = dds[newindex] - yddegs - # diff = slopes[oldindex] * dddif dddif = dds_newindex - yddegs diff = slopes_oldindex * dddif # Then from the inflection point up to today. - # dddif = ddegs - dds[newindex] - # diff += slopes[newindex] * dddif dddif = ddegs - dds_newindex diff += slopes_newindex * dddif else # No inflection point passed - # diff = slopes[newindex] * (ddegs - yddegs) diff = slopes_newindex * (ddegs - yddegs) end return diff -- GitLab