def __init__(self): super().__init__("SimpleParser") # input ports self.input = StreamInput(self, "in") self.average_data = choice_input(self, "Average data", "off", ["off", "on"]) # output ports self.e = ArrayOutput(self, "e", self.read_e) self.intensity = ArrayOutput(self, "intensity", self.read_intensity) # declare self.inputs = [ self.input, self.average_data, ] self.outputs = [ self.e, self.intensity, ] self.e_data = None self.intensity_data = None
def __init__(self): super().__init__("XAS spectra") # inputs self.a_p_norm = StreamInput(self, "a_p_norm") self.a_a_norm = StreamInput(self, "a_a_norm") # parameter inputs self.fit = choice_input( self, "fit", "Do Nothing!!", [ "linear", "polynomial", "exp decay", "2 point linear", "Do Nothing!!" ], ) self.background_start = int_input(self, "p_start_xas", self.a_p_norm, 770) self.background_stop = int_input(self, "p_stop_xas", self.a_p_norm, 805) # outputs self.xas = ArrayOutput(self, "xas", self.read_xas) self.xas_bg = ArrayOutput(self, "xas_bg", self.read_xas_bg) self.xas_integral = ArrayOutput(self, "xas_integral", self.read_xas_integral)
def __init__(self): super().__init__("XMCDStreamParser") # input ports self.input = StreamInput(self, "in") self.average_data = choice_input(self, "Average data", "off", ["off", "on"]) # output ports self.t_a_all = ArrayOutput(self, "t_a_all", self.read_t_a) self.t_p_all = ArrayOutput(self, "t_p_all", self.read_t_p) self.e = ArrayOutput(self, "e", self.read_e) # declare self.inputs = [ self.input, self.average_data, ] self.outputs = [ self.t_a_all, self.t_p_all, self.e, ] self.t_a_all_data = None self.t_p_all_data = None self.e_data = None self.parent = Function
def __init__(self): super().__init__("step_subtraction") # Input Ports self.a_p_norm = StreamInput(self, "a_p_norm") self.a_a_norm = StreamInput(self, "a_a_norm") self.apply_step = choice_input(self, "Apply", "off", ["off", "on"]) self.fit_type = choice_input(self, "fit_type", "Alpha", ["Alpha", "Beta"]) self.fit_function = choice_input(self, "fit_function", "Voight", ["Voight", "Arctan"]) self.step_start = int_input(self, "step_start", self.a_p_norm, None) self.step_intermediate = int_input(self, "step_intermediate", self.a_p_norm, None) self.step_stop = int_input(self, "step_stop", self.a_p_norm, None) # output ports self.a_a_stepfunction = ArrayOutput(self, "a_a_stepfunction", self.read_a_a_stepfunction) self.a_p_stepfunction = ArrayOutput(self, "a_p_stepfunction", self.read_a_p_stepfunction) self.a_a_step_subtracted = ArrayOutput(self, "a_a_step_subtracted", self.read_a_a_step_subtracted) self.a_p_step_subtracted = ArrayOutput(self, "a_p_step_subtracted", self.read_a_p_step_subtracted)
class difference(Function): """Adds two nd arrays together""" def __init__(self): super().__init__("Addition") # inputs self.A = StreamInput(self, "a_p_norm") self.B = StreamInput(self, "a_a_norm") # outputs self.added = ArrayOutput(self, "added", self.read_added) # port declaration self.inputs = [ self.Reverse, self.A, self.B, ] self.outputs = [ self.added, ] def getpath(self, name): return_path = str(self) + "/" + name return return_path def evaluate(self): a = np.array(self.A.read()["data"][1]) b = np.array(self.B.read()["data"][1]) if a.ndim and b.ndim == 1: add = a + b elif a.ndim and b.ndim == 2: add_list = [] for i in range(a.shape[0]): add_i = a[i] + b[i] add_list.append(add_i) add = np.array(add_list) self.add_calc = np.array(add) self.lines = None def read_added(self): return { "data": [self.A.read()["data"][0], self.add_calc, self.lines], "label": self.A.read()["label"], }
def __init__(self): super().__init__("integrate") # input ports self.input = StreamInput(self, "inputarray") self.integral = ArrayOutput(self, "integral", self.read_integral)
class difference(Function): """takes the subtracts on spectra from another""" def __init__(self): super().__init__("Difference") # inputs self.A = StreamInput(self, "a_p_norm") self.B = StreamInput(self, "a_a_norm") self.Reverse = choice_input(self, "A-B", "A-B", ["A-B", "B-A"]) # outputs self.diff = ArrayOutput(self, "diff", self.read_diff) def evaluate(self): a = np.array(self.A.read()["data"][1]) b = np.array(self.B.read()["data"][1]) if a.ndim and b.ndim == 1: if self.Reverse.default == "A-B": diff = a - b else: diff = b - a elif a.ndim and b.ndim == 2: diff_list = [] for i in range(a.shape[0]): if self.Reverse.default == "A-B": diff_i = a[i] - b[i] diff_list.append(diff_i) else: diff_i = b[i] - a[i] diff_list.append(diff_i) diff = np.array(diff_list) self.diffs = diff self.lines = None def read_diff(self): return { "data": [self.A.read()["data"][0], self.diffs, self.lines], "label": self.A.read()["label"], }
def __init__(self): super().__init__("Addition") # inputs self.A = StreamInput(self, "A") self.B = StreamInput(self, "B") # outputs self.added = ArrayOutput(self, "added", self.read_added)
def __init__(self): super().__init__("Convolve") # ports self.A = StreamInput(self, "A") self.B = StreamInput(self, "B") self.convolution = ArrayOutput(self, "convolution", self.read_convolution)
class FindValue(Function): def __init__(self, name): super().__init__(name) # input ports self.inputarray = StreamInput(self, "inputarray") self.lookup = int_input(self, "lookup", self.inputarray, None) # output ports self.value = TextOutput(self, "value", self.read_value) self.graph = ArrayOutput(self, "graph", self.read_graph) def evaluate(self): x = np.array(self.inputarray.read()["data"][0]) y = np.array(self.inputarray.read()["data"][1]) if self.lookup.default: if x.ndim and y.ndim == 1: value = [y[find_array_equivalent(x, self.lookup.default)]] elif x.ndim and y.ndim == 2: value = [] for i in range(x.shape[0]): value_i = y[i][find_array_equivalent( x[i], self.lookup.default)] value.append(value_i) else: value = None self.value = value self.lines = [self.lookup.default] def read_value(self): return { "data": [self.inputarray.read()["data"][0], self.value], "label": self.inputarray.read()["label"], } # return self.value def read_graph(self): return { "data": [ self.inputarray.read()["data"][0], self.inputarray.read()["data"][1], self.lines, ], "label": self.inputarray.read()["label"], }
def __init__(self, name): super().__init__(name) # input ports self.inputarray = StreamInput(self, "inputarray") self.lookup = int_input(self, "lookup", self.inputarray, None) # output ports self.value = TextOutput(self, "value", self.read_value) self.graph = ArrayOutput(self, "graph", self.read_graph)
def __init__(self): super().__init__("Difference") # inputs self.A = StreamInput(self, "a_p_norm") self.B = StreamInput(self, "a_a_norm") self.Reverse = choice_input(self, "A-B", "A-B", ["A-B", "B-A"]) # outputs self.diff = ArrayOutput(self, "diff", self.read_diff)
def __init__(self): super().__init__("Scale") # inputs self.input = StreamInput(self, "input") # params self.scale_value = num_input(self, "scale_value", self.input, 1) # outputs self.scaled = ArrayOutput(self, "scaled", self.read_scaled)
class Integrate(Function): def __init__(self): super().__init__("integrate") # input ports self.input = StreamInput(self, "inputarray") self.integral = ArrayOutput(self, "integral", self.read_integral) def evaluate(self): x = self.input.read()["data"][0] y = self.input.read()["data"][1] if x.ndim and y.ndim == 1: intgrl = integrate.cumtrapz( y[:], x[:], initial=0, ) elif x.ndim and y.ndim == 2: int_list = [] for i in range(x.shape[0]): integral_calc_ind_i = integrate.cumtrapz( y[i][:], x[i][:], initial=0, ) int_list.append(integral_calc_ind_i) intgrl = np.array(int_list) self.integral_calc = intgrl self.lines = None def read_integral(self): return { "data": [self.input.read()["data"][0], self.integral_calc, self.lines], "label": self.input.read()["label"], }
def __init__(self): super().__init__("EXAFSStreamParser") # input ports self.input = StreamInput(self, "in") self.average_data = choice_input(self, "Average data", "off", ["off", "on"]) # output ports self.e = ArrayOutput(self, "e", self.read_e) self.intensity = ArrayOutput(self, "intensity", self.read_intensity) self.e_data = None self.intensity_data = None
def __init__(self): super().__init__("Transpose") # streamed inputs self.spectra = StreamInput(self, "spectra") # parameter inputs self.action = choice_input(self, "Action", "on", ["off", "on"]) self.x_value_for_transpose = int_input(self, "x_value_for_transpose", self.spectra, 771) # output ports self.transposed_data = ArrayOutput(self, "transposed_data", self.read_transposed_data)
def __init__(self): super().__init__("area") # input ports self.input = StreamInput(self, "inputarray") # int_input takes arguments (fn, name, input_stream) # The input_stream allows for limits to be calculated for GUI sliders. self.start = int_input(self, "start", self.input, 770) self.mid = int_input(self, "mid", self.input, 790) self.end = int_input(self, "end", self.input, 800) # self.value = TextOutput(self, "value", self.read_value) self.graph = ArrayOutput(self, "graph", self.read_graph)
class scale(Function): """takes the subtracts on spectra from another""" def __init__(self): super().__init__("Scale") # inputs self.input = StreamInput(self, "input") # params self.scale_value = num_input(self, "scale_value", self.input, 1) # outputs self.scaled = ArrayOutput(self, "scaled", self.read_scaled) def evaluate(self): a = np.array(self.input.read()["data"][1]) if a.ndim == 1: ab = a * self.scale_value.default elif a.ndim == 2: scale_list = [] for i in range(a.shape[0]): scale_i = a[i] * self.scale_value.default scale_list.append(scale_i) ab = np.array(scale_list) self.scaled_calc = np.array(ab) self.lines = None def read_scaled(self): return { "data": [self.input.read()["data"][0], self.scaled_calc, self.lines], "label": self.input.read()["label"], }
class addition(Function): """Adds two nd arrays together""" def __init__(self): super().__init__("Addition") # inputs self.A = StreamInput(self, "A") self.B = StreamInput(self, "B") # outputs self.added = ArrayOutput(self, "added", self.read_added) def evaluate(self): a = np.array(self.A.read()["data"][1]) b = np.array(self.B.read()["data"][1]) if a.ndim and b.ndim == 1: add = a + b elif a.ndim and b.ndim == 2: add_list = [] for i in range(a.shape[0]): add_i = a[i] + b[i] add_list.append(add_i) add = np.array(add_list) self.add_calc = np.array(add) self.lines = None def read_added(self): return { "data": [self.A.read()["data"][0], self.add_calc, self.lines], "label": self.A.read()["label"], }
def __init__(self): super().__init__("step_subtraction") # Input Ports self.input_array = StreamInput(self, "input_array") self.apply_step = choice_input(self, "Apply", "on", ["on", "off"]) self.fit_function = choice_input(self, "fit_function", "Voight", ["Voight", "Arctan"]) self.step_start = int_input(self, "step_start", self.input_array, None) self.step_stop = int_input(self, "step_stop", self.input_array, None) self.edge = int_input(self, "edge", self.input_array, None) # output ports self.stepfunction = ArrayOutput(self, "stepfunction", self.read_stepfunction) self.subtracted_step = ArrayOutput(self, "post_step_a", self.read_subtracted_step)
def __init__(self): super().__init__("background_subtraction") # streamed inputs # self.e = StreamInput(self, "e") self.input_data = StreamInput(self, "input_data") # input.changed += self.on_data # parameter inputs self.fit = choice_input( fn=self, name="fit", default="No fit", choices=[ "No fit", "Polynomial fit inside limits", "Polynomial fit outside limits", "exp decay (fits for all e < 'Background_start' and e > ' Background_end')", "2 point linear (straight line between 2 points)", ], ) self.apply_offset = choice_input( fn=self, name="apply_offset", default="off", choices=[ "off", "on (shifts post 'Background_end' by amount equal to e = 'Background_end' to e = 'Background_start' )", ], ) # self.apply_offset = int_input(self, "apply_offset", 1, 1, 3) self.p_start = int_input(self, "Background_start", self.input_data, None) self.p_end = int_input(self, "Background_end", self.input_data, None) self.power = free_int_input(self, "power", 1, 1, 3) # output ports self.background = ArrayOutput(self, "background", self.read_background) self.subtracted_background = ArrayOutput( self, "subtracted_background", self.read_subtracted_background)
def __init__(self): super().__init__("Addition") # inputs self.A = StreamInput(self, "a_p_norm") self.B = StreamInput(self, "a_a_norm") # outputs self.added = ArrayOutput(self, "added", self.read_added) # port declaration self.inputs = [ self.Reverse, self.A, self.B, ] self.outputs = [ self.added, ]
def __init__(self): super().__init__("Identify Peaks") # Input Ports self.input_array = StreamInput(self, "input_array") self.number_of_peaks = free_int_input(self, "number_of_peaks", 1, 2, 10) self.center_of_peaks = int_input( self, "center_of_peaks", self.input_array, 5990 ) self.sigma_of_peaks = int_input(self, "sigma_of_peaks", self.input_array, 30) self.height_of_peaks = int_input( self, "height_of_peaks", self.input_array, 0.12 ) self.type_of_peaks = choice_input( self, "GaussianModel", "GaussianModel", ["GaussianModel", "LorentzianModel"] ) # output ports self.fitted_peaks = ArrayOutput(self, "fitted_peaks", self.read_fitted_peaks)
def __init__(self): super().__init__("Normalise") # streamed inputs self.t_p_all = StreamInput(self, "t_p_all") self.t_a_all = StreamInput(self, "t_a_all") # parameter inputs self.action = choice_input( self, "Action", "Do not Apply", ["Do not Apply", "Apply"] ) self.normalise_point_1 = int_input( self, "normalise_point_1", self.t_p_all, None ) self.normalise_point_2 = int_input( self, "normalise_point_2", self.t_p_all, None ) # output ports self.a_p_norm = ArrayOutput(self, "a_p_norm", self.read_a_p_norm) self.a_a_norm = ArrayOutput(self, "a_a_norm", self.read_a_a_norm)
class single_step_subtraction(Function): """TODO: Centre the step function on the peaks energy!""" def __init__(self): super().__init__("step_subtraction") # Input Ports self.input_array = StreamInput(self, "input_array") self.apply_step = choice_input(self, "Apply", "on", ["on", "off"]) self.fit_function = choice_input(self, "fit_function", "Voight", ["Voight", "Arctan"]) self.step_start = int_input(self, "step_start", self.input_array, None) self.step_stop = int_input(self, "step_stop", self.input_array, None) self.edge = int_input(self, "edge", self.input_array, None) # output ports self.stepfunction = ArrayOutput(self, "stepfunction", self.read_stepfunction) self.subtracted_step = ArrayOutput(self, "post_step_a", self.read_subtracted_step) # evaluate method def evaluate(self): local_arguments = args_step(self) self.stepfunction_calc, self.subtracted_step_calc = single_step( energy=self.input_array.read()["data"][0], absorption=self.input_array.read()["data"][1], args=local_arguments, ) self.lines = [self.step_start.default, self.step_stop.default] def read_stepfunction(self): return { "data": [ self.input_array.read()["data"][0], self.stepfunction_calc, self.lines, ], "label": self.input_array.read()["label"], } # return self.stepfunction_a def read_subtracted_step(self): return { "data": [ self.input_array.read()["data"][0], self.subtracted_step_calc, self.lines, ], "label": self.input_array.read()["label"], }
def __init__(self): super().__init__("step_subtraction") # Input Ports self.input_array = StreamInput(self, "input_array") self.apply_step = choice_input(self, "Apply", "off", ["off", "on"]) self.fit_function = choice_input(self, "fit_function", "Voight", ["Voight", "Arctan"]) self.pre_feature_min = int_input(self, "pre_feature_min", self.input_array, None) self.pre_feature_max = int_input(self, "pre_feature_max", self.input_array, None) self.post_feature_min = int_input(self, "post_feature_min", self.input_array, None) self.post_feature_max = int_input(self, "post_feature_max", self.input_array, None) # output ports self.stepfunction = ArrayOutput(self, "stepfunction", self.read_stepfunction) self.subtracted_step = ArrayOutput(self, "subtracted_step", self.read_subtracted_step)
class convolve(Function): """ This create a sin function where the user can alter the frequency and amplitude """ def __init__(self): super().__init__("Convolve") # ports self.A = StreamInput(self, "A") self.B = StreamInput(self, "B") self.convolution = ArrayOutput(self, "convolution", self.read_convolution) def evaluate(self): self.conv_calc = self.A.read()["data"][1] + self.B.read()["data"][1] def read_convolution(self): return { "data": [self.A.read()["data"][0], self.conv_calc, None], "label": "s" }
class Transpose(Function): def __init__(self): super().__init__("Transpose") # streamed inputs self.spectra = StreamInput(self, "spectra") # parameter inputs self.action = choice_input(self, "Action", "on", ["off", "on"]) self.x_value_for_transpose = int_input(self, "x_value_for_transpose", self.spectra, 771) # output ports self.transposed_data = ArrayOutput(self, "transposed_data", self.read_transposed_data) def evaluate(self): local_arguments = args_transpose(self) self.transposed = Transpose_spectra( energy=self.spectra.read()["data"][0], absorption=self.spectra.read()["data"][1], args=local_arguments, ) self.lines = [self.x_value_for_transpose.default] def read_transposed_data(self): return { "data": [self.spectra.read()["data"][0], self.transposed, self.lines], "label": self.spectra.read()["label"], }
def __init__(self, n_inputs): super().__init__("Multiplexer") self.n_inputs = n_inputs self.inputs = [] for item in range(n_inputs): input = StreamInput(self, "in" + str(item)) self.inputs.append(input) # input.changed += self.on_data self.multiplot = ArrayOutput(self, "out", self.read_output) self.a = None
def __init__(self): super().__init__("SumRules") self.p = StreamInput(self, "p") self.q = StreamInput(self, "q") self.r = StreamInput(self, "r") self.shell_occupation = num_input(self, "shell_occupation", self.p, 7.51) self.ratio = TextOutput(self, r"ratio = \frac{2q} {9p - 6p}", self.read_ratio) self.orbitalmoment = TextOutput( self, "orbital moment \frac{4 q} {3 r} * (10 - n3d) ", self.read_orbitalmoment, ) self.spinmoment = TextOutput(self, "spin moment \frac{2q} {9p - 6p}", self.read_spinmoment)