def neg(x): '''Returns the negitive of a Measurement object ''' import qexpy.error as e x, = check_values(x) result_derivative = {} for key in x.derivative: result_derivative[key] = -x.derivative[key] result = e.Function(-x.mean, x.std) result.derivative.update(result_derivative) result._update_info('neg', x, func_flag=1) result.error_flag = True return result
def operation_wrap(operation, *args, func_flag=False): '''e.Function wrapper to convert existing, constant functions into functions which can handle measurement objects and return an error propagated by derivative, min-max, or Monte Carlo method. ''' import qexpy.error as e args = check_values(*args) if len(args) > 1: args[0].get_covariance(args[1]) if func_flag is False: args[0]._check_der(args[1]) args[1]._check_der(args[0]) df = {} for key in args[0].derivative: df[key] = diff[operation](key, *args) if check_formula(operation, *args, func_flag=func_flag) is not None: return check_formula(op_string[operation], *args, func_flag=func_flag) mean = operation(*args) std = dev(*args, der=df) result = e.Function(mean, std) result.der = [mean, std] result.MinMax = find_minmax(operation, *args) result.MC, result.MC_list = monte_carlo(operation, *args) #TODO: This is wrong: should not keep changing the mean and std # the error method should only change this on a print!!! # Derivative Method #if e.ExperimentalValue.error_method == "Derivative": # pass # By Min-Max method #elif e.ExperimentalValue.error_method == "Min Max": # (mean, std, ) = result.MinMax # Monte Carlo Method #elif e.ExperimentalValue.error_method == 'Monte Carlo': # (mean, std, ) = result.MC #else: # print('''Error method not properly set, please set to derivatie, Monte # Carlo, or Min-Max. Derivative method used by default.''') if func_flag is False and args[0].info["Data"] is not None\ and args[1].info['Data'] is not None\ and args[0].info['Data'].size == args[1].info['Data'].size: d1 = args[0].info["Data"] d2 = args[1].info["Data"] result.info['Data'] = np.ndarray(d1.size, dtype=type(d1[0])) for i in range(d1.size): result.info["Data"][i] = operation(d1[i],d2[i]) elif args[0].info["Data"] is not None and func_flag is True: result.info["Data"] = (operation(args[0].info["Data"])) result.derivative.update(df) result._update_info(operation, *args, func_flag=func_flag) for root in result.root: result.get_covariance(e.ExperimentalValue.register[root]) return result