def _eval_evalf(self, nprec): wind_dir, wind_spd, beach_orientation = symbols('wind_dir wind_spd beach_orientation') vb_func = -wind_spd * cos((wind_dir - beach_orientation) * pi / 180) result = vb_func.evalf(subs={wind_dir: symFloat(self.args[0]), wind_spd: symFloat(self.args[1]), beach_orientation: symFloat(self.args[2])}) return result
def _eval_evalf(self, nprec): obs = symbols('obs_symbol') if self.args[0] != 0: sub_val = symFloat(self.args[0]) else: sub_val = symFloat(self.args[1]) vb_func = sign(obs) * (1 / abs(obs)) result = vb_func.evalf(subs={obs: sub_val}) return result
def _eval_evalf(self, nprec): #bs_val = 0 obs_symbol,a,b,c = symbols('obs_symbol a b c') poly_func = poly(a + b * obs_symbol + c * obs_symbol**2) #if self.args[0] != 0: # obs_val = symFloat(self.args[0]) result = poly_func.evalf(subs={obs_symbol: symFloat(self.args[0]), a: symFloat(self.args[1]), b: symFloat(self.args[2]), c: symFloat(self.args[3])}) #If the obs value is 0, then no need to calc the polynomial, the value is going #to be the value of "a" since "b" and "c" are zeroed out. return result
def runTest(self, data): if self.logger: self.logger.debug("runTest start Site: %s model name: %s formula: %s" % (self.name, self.model_name, self.formula)) start_time = time.time() try: #Get the variables from the formula, then verify the passed in data has the observation and a valid value. valid_data = True sym_expr = sympify(self.formula, globals()) observation_variables = sym_expr.free_symbols mlr_symbols = {} for obs_var in observation_variables: self.data_used[obs_var.name] = None if obs_var.name in data: self.data_used[obs_var.name] = data[obs_var.name] mlr_symbols[obs_var] = symFloat(data[obs_var.name]) if data[obs_var.name] == wq_defines.NO_DATA: valid_data = False else: valid_data = False if valid_data: self.log10MLRResult = sym_expr.evalf(subs=mlr_symbols) if self.logger: self.logger.debug("Model: %s Result: %f Data Used: %s" % (self.model_name, self.log10MLRResult, self.data_used)) try: self.mlrResult = pow(10,self.log10MLRResult) self.categorize_result() except OverflowError,e: if self.logger: self.logger.exception(e) else:
def runTest(self, data): if self.logger: self.logger.debug("runTest start Site: %s model name: %s formula: %s" % (self.name, self.model_name, self.formula)) start_time = time.time() try: #Get the variables from the formula, then verify the passed in data has the observation and a valid value. valid_data = True valid_data = True sym_expr = sympify(self.formula, globals()) observation_variables = sym_expr.free_symbols mlr_symbols = {} for obs_var in observation_variables: self.data_used[obs_var.name] = None if obs_var.name in data: self.data_used[obs_var.name] = data[obs_var.name] if data[obs_var.name] != 0: mlr_symbols[obs_var] = symFloat(data[obs_var.name]) else: mlr_symbols[obs_var] = int(data[obs_var.name]) if data[obs_var.name] == wq_defines.NO_DATA: valid_data = False else: valid_data = False if valid_data: try: self.mlrResult = sym_expr.evalf(subs=mlr_symbols, n=4) self.mlrResult = int(self.mlrResult + 0.5) if self.logger: self.logger.debug("Model: %s Result: %f Data Used: %s" % (self.model_name, self.mlrResult, self.data_used)) self.categorize_result() except (TypeError, OverflowError) as e: if self.logger: self.logger.exception(e) else: if self.logger: self.logger.debug("Model: %s test not performed, one of more invalid data points: %s" % (self.model_name, self.data_used)) except Exception,e: if self.logger: self.logger.exception(e)
def _eval_evalf(self, nprec): obs = symbols('obs_symbol') vb_func = sign(obs) * (abs(obs)**.5) result = vb_func.evalf(subs={obs: symFloat(self.args[0])}) return result
def _eval_evalf(self, nprec): obs_symbol, a, b, c= symbols('obs_symbol a b c') test_func = a + b * obs_symbol + c * obs_symbol**2 result = test_func.evalf(subs={obs_symbol: symFloat(self.args[0]), a: symFloat(self.args[1]), b: symFloat(self.args[2]), c: symFloat(self.args[3])}) return result
def _eval_evalf(self, nprec): obs = symbols('obs_symbol') vb_func = log(obs, 10) result = vb_func.evalf(subs={obs: symFloat(self.args[0])}) return result