def calc_R_Zh_relationship(self): ''' calc_R_Zh_relationship calculates the power law fit for Zh based upon scattered radar parameters. It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. ''' popt, pcov = expfit(np.power(10, 0.1 * self.Zh[self.rain_rate > 0]), self.rain_rate[self.rain_rate > 0]) return popt, pcov
def calc_R_kdp_relationship(self): ''' calc_R_kdp_relationship calculates a power fit for the rainfall-kdp relationship based upon the calculated radar parameters(which should have already been run). It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. ''' popt, pcov = expfit(self.Kdp[self.rain_rate > 0], self.rain_rate[self.rain_rate > 0]) return popt, pcov
def calculate_R_Zh_relationship(self): ''' calculate_R_Zh_relationship calculates the power law fit for Zh based upon scattered radar parameters. It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. Returns: -------- popt: tuple a,b,c fits for relationship. pcov: array Covariance matrix of fits. ''' popt, pcov = expfit(np.power(10, 0.1 * self.fields['Zh']['data'][self.rain_rate['data'] > 0]), self.fields['rain_rate']['data'][self.fields['rain_rate']['data'] > 0]) return popt, pcov
def calculate_R_Kdp_relationship(self): ''' calculate_R_kdp_relationship calculates a power fit for the rainfall-kdp relationship based upon the calculated radar parameters(which should have already been run). It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. ''' if 'rain_rate' in self.fields.keys(): filt = np.logical_and(self.fields['Kdp']['data'] > 0, self.fields['rain_rate']['data'] > 0) popt, pcov = expfit(self.fields['Kdp']['data'][filt], self.fields['rain_rate']['data'][filt]) return popt, pcov else: print("Please run calculate_RR() function first.") return None
def ajuste(fn, x, y): """ Calcula os coeficientes de um ajuste usando o método dos mínimos quadrados. Entradas: fn: uma string indicando a forma da função a ser ajustada. x: o vetor contendo as abscissas. y: o vetor contendo as ordenadas. Saída: a função ajustada e uma legenda para ela. A legenda poderá ser usada em um gráfico do matplotlib. """ if fn == 'n': # Ajusta os coeficientes de um polinômio de grau 1 coefs = np.polyfit(x, y, 1) f = np.poly1d(coefs) legenda = legenda_poli(coefs) elif fn == 'n^2': # Ajusta os coeficientes de um polinômio de grau 2 coefs = np.polyfit(x, y, 2) f = np.poly1d(coefs) legenda = legenda_poli(coefs) elif fn == 'nln(n)': # Ajusta os coeficientes a e b da função f(n)= a*n*ln(n) + b coefs = nlognfit(x, y) a, b = coefs f = lambda n: a * n * np.log(n) + b legenda = legenda_nln(a, b) elif fn == 'ln(n)': # Ajusta os coeficientes a e b da função f(n)= a*ln(n) + b coefs = logfit(x, y) a, b = coefs f = lambda n: a * np.log(n) + b legenda = legenda_ln(a, b) elif fn == 'e(n)': # Ajusta os coeficientes a e b da função f(n)= ae^(bx) coefs = expfit(x, y) a, b = coefs f = lambda n: a * np.exp(b * n) legenda = legenda_en(a, b) else: print("A função 'ajuste' nao esta preparada para ajustar " + fn) raise return (f, '$' + legenda + '$')
def calculate_R_Kdp_relationship(self): ''' calculate_R_kdp_relationship calculates a power fit for the rainfall-kdp relationship based upon the calculated radar parameters(which should have already been run). It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. ''' if 'rain_rate' in self.fields.keys(): filt = np.logical_and( self.fields['Kdp']['data'] > 0, self.fields['rain_rate']['data'] > 0) popt, pcov = expfit(self.fields['Kdp']['data'][filt], self.fields['rain_rate']['data'][filt]) return popt, pcov else: print("Please run calculate_RR() function first.") return None
def calculate_R_Zh_relationship(self): ''' calculate_R_Zh_relationship calculates the power law fit for Zh based upon scattered radar parameters. It returns the scale and exponential parameter a and b in the first tuple, and the second returned argument gives the covariance matrix of the fit. Returns: -------- popt: tuple a,b,c fits for relationship. pcov: array Covariance matrix of fits. ''' popt, pcov = expfit( np.power( 10, 0.1 * self.fields['Zh']['data'][self.rain_rate['data'] > 0]), self.fields['rain_rate']['data'][ self.fields['rain_rate']['data'] > 0]) return popt, pcov
RHS1 = [ r + 1/p for p in ps_] print r - rr # rl = [laplace_mechanism(compute_sum_ti_p(p, data) , len(ps)*1.0/EPSILON) for p in ps] # rl = [laplace_mechanism(compute_sum_ti_p(p, data) , len(ps)*1.0/EPSILON) for p in ps] # rl1 = [laplace_mechanism(compute_sum_ti_p_log(p, data), bb*len(ps)*1.0/EPSILON) for p in ps] rl_ = [compute_sum_ti_p(p, data) for p in ps_] rl1_ = [compute_sum_ti_p_log(p, data) for p in ps_] etm = [ laplace_mechanism(compute_sum_ti_p_log(ps[i], data) , bb*1.0/(0.8*EPSILON/2.0*2.0*(i+1)/len(ps)/(len(ps)+1.0) ) ) / laplace_mechanism(compute_sum_ti_p(ps[i], data) , 1.0/( 0.8*EPSILON/2.0*2.0*(i+1)/len(ps)/(len(ps)+1.0))) for i in range(len(ps)) ] fit = expfit(ps, 10, 1) a0 = np.ones(2) alp,bet,lam,aopt = fit.getOptCoeffs(etm,a0) y = fit.getCurrentState() # fit = expfit(ps, 30, 1) # a0 = np.ones(2) # alp,bet,lam,aopt = fit.getOptCoeffs(rl,a0) # y = fit.getCurrentState() # # fit = expfit(ps, 30, 1) # a0 = np.ones(2) # alp,bet,lam,aopt = fit.getOptCoeffs(rl1,a0) # y1 = fit.getCurrentState() # z = np.polyfit(ps, rl, 2)