if cos(sza)>=0: raw_uvi = 12.50*pow(cos(sza),2.42)*pow(float(ozone)/300,-1.23) else: raw_uvi=0.0
This makes it so that when the sun is beneath the horizon, the sun is not 'taking back' the energy