I have been trying endlessly to figure out why the variable c in the program below is not been returned. Rather, I was getting an error that says NameError: name 'c' is not defined. I have searched for solutions online, including here, but no answer offered a desirable solution yet. How can I print the content of *c *? Any assistance from you will be much appreciated. Thanks.
# obs=observation, p=model data, s=projected data
def bias_correction(obs, p, s, method='delta', nbins=10, extrapolate=None):
if (method == 'eqm') and (nbins > 1):
binmid = np.arange((1./nbins)*0.5, 1., 1./nbins)
qo = mquantiles(obs[np.isfinite(obs)], prob=binmid)
qp = mquantiles(p[np.isfinite(p)], prob=binmid)
p2o = interp1d(qp, qo, kind='linear', bounds_error=False)
c = p2o(s)
if extrapolate is None:
c[s > np.max(qp)] = qo[-1]
c[s < np.min(qp)] = qo[0]
elif extrapolate == 'constant':
c[s > np.max(qp)] = s[s > np.max(qp)] + qo[-1] - qp[-1]
c[s < np.min(qp)] = s[s < np.min(qp)] + qo[0] - qp[0]
elif method == 'delta':
c = obs + (np.nanmean(s) - np.nanmean(p))
elif method == 'scaling_add':
c = s - np.nanmean(p) + np.nanmean(obs)
elif method == 'scaling_multi':
c = (s/np.nanmean(p)) * np.nanmean(obs)
else:
raise ValueError("incorrect method, choose from 'delta', 'scaling_add', 'scaling_multi' or 'eqm'")
return c # c is the bias-corrected series for s
