This is the typical Crop Growth Curve
The general equation/function for the sigmoid curve are, as in the function below 1 2
def sigmoid(x):
y = (1 / (1 + np.exp(-x)))
return (y)
I want that during any crop period starting from day 1, to nth number of day till the cropping season ends, this sigmoid curve should retain this shape, whatever the crop duration is.
- (n/crop_end_day - is variable here, which may be 90, 100, 120, 150, etc depending upon the crop type)
crop_start_day = 1
crop_end_day = 120
time_increment = 1
crop_duration = np.arange(crop_start_day,crop_end_day,time_increment)
print(crop_duration)
crop_growth = sigmoid(crop_duration)
print(crop_growth)
plt.plot(crop_duration, crop_growth)
plt.title("Crop Growth Curve")
plt.xlabel("Days")
plt.ylabel("Relative Growth (Dry Matter/Root Growth etc..)")
plt.grid()
plt.show()
The objective is that if the relative growth (0 to 1) is known on any specific day based on this curve,
then the absolute value can be obtained by considering this relative growth as weight i.e. multiplying this relative growth with the maximum possible value of any parameter like root length, dry weight, etc on that specific day...
With the current inputs
crop_start_day = 1
crop_end_day = 120
time_increment = 1
the output is not as desired .
as I change the inputs as
crop_start_day = 1
crop_end_day = 10
time_increment = 1
the output is like this, but the relative growth does not start from zero,
and with these inputs, the curve somewhat resembles but crop start day can not be negative
crop_start_day = -10
crop_end_day = 10
time_increment = 1
The sigmoid curve is not obtained in any of the figures, in spite, the function used is same as in the references,
Is there any way to retain the sigmoid curve while changing the number of crop growth days/duration (this is the only variable part)?
Note:
The time increment should be one (1) day.
No intercept is required as crop growth will start from zero on day 1.
Tried different solutions given for Sigmoid Curve, as in Fit sigmoid function ("S" shape curve) to data using Python, but did not got the results.
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
def sigmoidx(x, L ,x0, k, b):
y = L / (1 + np.exp(-k*(x-x0)))+b
return (y)
crop_start_day = 0
crop_end_day = 120
time_increment = 1
curve_max_value = 600 # L
sigmoid_midpoint_x0 = 60 # x0
logistic_growth_rate = 5 # k (taken linear 5 units per day)
intercept = 0 # b
crop_duration = np.arange(crop_start_day,crop_end_day,time_increment)
crop_growth = sigmoidx(crop_duration, curve_max_value, sigmoid_midpoint_x0, logistic_growth_rate, intercept)
p0 = [max(crop_growth), np.median(crop_duration), 1, min(crop_growth)] # initial guess
popt, pcov = curve_fit(sigmoidx, crop_duration, crop_growth, p0, method='dogbox')
plt.plot(crop_duration, crop_growth, 'b-', label='data')