def validate(year, month, hrv): tst_hour_step = 1/24. root = nc_process_create(getfilename(year, month, hrv)) globalradiation = nc_process_var(root, 'radiacion_global') clearskyradiation = nc_process_var(root, 'radiacion_global_despejado') dt_int = nc_process_var(root, 'datetime') timestamp = np.array([date2num(getdatetimefromint(i)) for i in dt_int]) tst_hour = nc_process_var(root, 'tiempo_tst') nc_process_ready(root) stations = pgs.getmeasuresinstations(year, month) for s in stations: l,c = dp.getpos(float(s['latitude']), float(s['longitude']), hrv) globalradiationinposition = globalradiation[:,l,c] tst_datehour = gettstdatetime(timestamp,tst_hour[:,l,c]) estimated = [] measured = [] for m in s['measures']: cond = ((tst_datehour > m['timestamp'] - tst_hour_step) & (tst_datehour <= m['timestamp'])) tst_filtered = tst_datehour[cond] if tst_filtered.size >= 4 and m['ghi'] > 0: estimated.append(globalradiationinposition[cond].mean()) measured.append(m['ghi']) measured = np.array(measured) estimated = np.array(estimated) diff = estimated - measured ghi_mean = measured.mean() ghi_ratio = 100 / ghi_mean show("----------") show("Length:", measured.size) show("mean(GHI)", ghi_mean) show("mean(estimated)", estimated.mean()) show(s['Name']) bias = diff.mean() show("BIAS:", bias, "(", bias * ghi_ratio, "%)") rmse = np.sqrt((diff**2).mean()) show("RMSE:", rmse, "(", rmse * ghi_ratio, "%)") mae = np.absolute(diff).mean() show("MAE:", mae, "(", mae * ghi_ratio, "%)")
def process_validate(year, month, times, root): tst_hour_step = 1/24. globalradiation = nc.getvar(root, 'globalradiation') clearskyradiation = nc.getvar(root, 'clearskyglobalradiation') timestamp = np.array([date2num(dt) for dt in times]) tst_hour = nc.getvar(root, 'tst_hour') stations = pgs.getmeasuresinstations(year, month) for s in stations: l,c = dp.getpos(float(s['latitude']), float(s['longitude'])) globalradiationinposition = globalradiation[:,l,c] tst_datehour = gettstdatetime(timestamp,tst_hour[:,l,c]) estimated = [] measured = [] for m in s['measures']: cond = ((tst_datehour > m['timestamp'] - tst_hour_step) & (tst_datehour <= m['timestamp'])) tst_filtered = tst_datehour[cond] if tst_filtered.size >= 4 and m['ghi'] > 0: estimated.append(globalradiationinposition[cond].mean()) measured.append(m['ghi']) measured = np.array(measured) estimated = np.array(estimated) diff = estimated - measured ghi_mean = measured.mean() ghi_ratio = 100 / ghi_mean show("----------") show("Length:", measured.size) show("mean(GHI)", ghi_mean) show("mean(estimated)", estimated.mean()) show(s['Name']) bias = diff.mean() show("BIAS:", bias, "(", bias * ghi_ratio, "%)") rmse = np.sqrt((diff**2).mean()) show("RMSE:", rmse, "(", rmse * ghi_ratio, "%)") mae = np.absolute(diff).mean() show("MAE:", mae, "(", mae * ghi_ratio, "%)")