Dear All,

My friend Naveen who volunteers along with various Farmers Movements and 
organisations, has come across a road block while trying to do some 
calculations w.r.t Crop Insurance Payout. This year in state of telangana, 
the government has not implemented the PMFBY policy and due to heavy rains 
many farmers have lost a lot of crops and are in severe losses. So we are 
trying to simulate what would have been the payout the farmers would have 
received in case PMFBY was in place.

He has written the code in Python for calculating the same. 
Below is short description of the issue he needs help with: 

"I am analysing daily rainfall data to calculate Insurance payout for 
farmers in case of excess rainfall coverage. policy covers if the 
"Consecutive 3 day cumulative rainfall" is greater than 50mm between 
1st-Oct and 31st-Oct. I was able to write the code in Python to find the 
matching criteria. But when it rains continuously then the result has 
overlapping dates which is not acceptable payout. Need help in calculating 
best payout option in case of overlapping dates."
I have attached the attachments also for further understanding.

He has also summarised the issue in this stack overflow thread.

https://stackoverflow.com/questions/65815331/rainfall-based-crop-insurance-payout-calculation

Request people to share their thoughts and suggestions.

Regards
Sreeharsha

-- 
Datameet is a community of Data Science enthusiasts in India. Know more about 
us by visiting http://datameet.org
--- 
You received this message because you are subscribed to the Google Groups 
"datameet" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to datameet+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/datameet/efbce873-8c84-4c53-a339-b6ce0fe87be6n%40googlegroups.com.
for dist in data["dcode"].unique():
    d_data = data[data["dcode"] == dist]
    #print(dist)
    for block in d_data["mandal"].unique():
        prev_rain = 0
        prev_to_date = "01/12/2022"
        for each in rain_dev_input:
            #[(rain_dev_input["TERM"] == "DEFICIT RAINFALL") & 
(rain_dev_input["DIST_CODE"] == 240)]:
            #print(each)
            distcode = each["DIST_CODE"]
            #print(distcode)
            term = str(each["TERM"])
            if (distcode == dist) & (term == "EXCESS RAINFALL"):
                start_date = each["FROM_PERIOD"]
                end_date = each["TO_PERIOD"]
                s_date = datetime.datetime.strptime(start_date, "%d/%m/%y")
                e_date = datetime.datetime.strptime(end_date, "%d/%m/%y")
                #s_date = start_date.strftime(start_date, "%Y-%m-%d")
                #e_date = end_date.strftime(end_date, "%Y-%m-%d")
                #count1 = daterange(s_date, e_date)
                #print(s_date, ": ", e_date)

                m_data = d_data[d_data["mandal"] == block]
                p_data = m_data.loc[start_date:end_date]
                for singledate in daterange(s_date, e_date):
                    #print("Inside Excess Rain")
                    from_date = datetime.datetime.strftime(singledate, 
"%Y-%m-%d")
                    to_date = datetime.datetime.strftime(
                        (singledate + timedelta(2)), "%Y-%m-%d"
                    )
                    total_rain = p_data.loc[from_date:to_date]["rain"].sum()
                    #print(total_rain)
                    range1 = float(each["RANGE1"])
                    range2 = float(each["RANGE2"])

                    if (total_rain >= range1) & (total_rain < range2):
                        #print("inside write to file")
                        if (from_date <= prev_to_date <= to_date) & (prev_rain 
<= total_rain):
                            temp["Max"] = total_rain;

                        prev_rain = total_rain
                        prev_to_date = to_date
                        temp = dict()
                        temp["district"] = each["DIST_NAME"]
                        temp["mandal"] = block
                        temp[
                            "category"
                        ] = "excess rainfall for 3 consecutive days, cumulative"
                        temp["rainfall"] = total_rain
                        temp["from_date"] = from_date
                        temp["to_date"] = to_date
                        temp["phase"] = each["PHASE"]
                        #temp["insurance"] = insurance_excessrain(each, 
total_rain)
                        temp["insurance"] = (total_rain - range1)* 
each["PAYOUT"]
                        excess_rainfall.append(temp)
# %%
# output excess rainfall rain_dev_list data
excess_rain = pd.DataFrame(excess_rainfall)
excess_rain.to_csv(str(output_folder) + "/excess_rainfall_2020_h2.csv", 
index=False)

Reply via email to