rainc = wrf.getvar(
ncfile, "RAINC"
) # Cumulative convective (grid-scale) precipitation
rainnc = wrf.getvar(
ncfile, "RAINNC"
) # Cumulative non-convective (resolved-scale) precipitation
rainsh = wrf.getvar(ncfile, "RAINSH") # Cumulative shallow precipitation
total_rain = (rainc + rainnc + rainsh) * 0.0393701 # mm to inch
# Add the total rain for the current hour to the recent rains list
recent_rains.append(total_rain)
# If we have more than 3 hours of data, remove the oldest hour's data
if len(recent_rains) > 3:
recent_rains.pop(0)
# Calculate the 3-hour accumulated rain
three_hour_rain = recent_rains[-1] - recent_rains[0] if len(recent_rains) == 3 else np.zeros_like(total_rain)
# Update the previous total rain and datetime for the next iteration
prev_total_rain = total_rain.copy()
prev_datetime = file_datetime