output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
def set_value(self, column=0, row=0, value='', block_events=False): """ Sets the value at column, row. This will create elements dynamically, and in a totally stupid while-looping way. Setting block_events=True will temporarily block the widget from sending any signals when sett...
Write a Python 3 script for setting the value at column row.
You are a Python code analyst, evaluating scripts for potential improvements.
def set_column_width(self, n=0, width=120): """ Sets the n'th column width in pixels. """ self._widget.setColumnWidth(n, width) return self
Can you create a Python 3 function that sets then'th column width in pixels.
As a Python code analyst, you investigate and solve complex coding mysteries
Sets whether we can see the column and row headers.
Explain what the following Python 3 code does def set_header_visibility(self, column=False, row=False): if row: self._widget.verticalHeader().show() else: self._widget.verticalHeader().hide() if column: self._widget.horizontalHeader().show() else: self._widget.horizontalHea...
You are a Python code generator, capable of creating scripts from specifications.
def set_row_height(self, n=0, height=18): """ Sets the n'th row height in pixels. """ self._widget.setRowHeight(n, height) return self
Implement a function in Python 3 to set then'th row height in pixels.
As a Python code composer, you craft elegant and concise scripts.
Clean up the key string with no naughty characters.
Explain what the following Python 3 code does def _clean_up_key(self, key): for n in self.naughty: key = key.replace(n, '_') return key
You are a Python code generator, capable of creating scripts from specifications.
def _cell_changed(self, *a): """ Called whenever a cell is changed. Updates the dictionary. """ # block all signals during the update (to avoid re-calling this) self.block_events() # loop over the rows for n in range(self.get_row_count()): # get the...
Can you implement a function in Python 3 that calls when a cell is changed. Updates the dictionary.
You are a Python code analyst, evaluating scripts for potential improvements.
Returns the value associated with the key.
Make a summary of the following Python 3 code def get_item(self, key): keys = list(self.keys()) # make sure it exists if not key in keys: self.print_message("ERROR: '"+str(key)+"' not found.") return None try: x = eval(self.get_value(1,keys.index(key...
You are a Python code analyst, evaluating scripts for potential improvements.
Returns a sorted list of keys
Here you have a function in Python 3, explain what it does def keys(self): keys = list() for n in range(len(self)): # only append the valid keys key = self.get_value() if not key in ['', None]: keys.append(key) return keys
As a python code expert, you are capable of creating scripts from specifications.
Sets the item by key and refills the table sorted.
How would you explain what the following Python 3 function does def set_item(self, key, value): keys = list(self.keys()) # if it exists, update if key in keys: self.set_value(1,keys.index(key),str(value)) # otherwise we have to add an element else: self....
As a Python code translator, you convert algorithms and pseudocode into Python.
def update(self, dictionary=None, **kwargs): """ Adds/overwrites all the keys and values from the dictionary. """ if not dictionary == None: kwargs.update(dictionary) for k in list(kwargs.keys()): self[k] = kwargs[k]
Write a Python 3 function that can update the dictionary with the values from kwargs.
As a python code expert, you are capable of creating scripts from specifications.
Returns the current text.
How would you explain what the following Python 3 function does def get_text(self): if self._multiline: return str(self._widget.toPlainText()) else: return str(self._widget.text())
You are a Python code generator, capable of creating scripts from specifications.
Sets the text of the text box.
Here you have a function in Python 3, explain what it does def set_text(self, text="YEAH."): # Make sure the text is actually different, so as not to # trigger a value changed signal s = str(text) if not s == self.get_text(): self._widget.setText(str(text)) return self
You are a Python code analyst, evaluating scripts for potential improvements.
def set_colors(self, text='black', background='white'): """ Sets the colors of the text area. """ if self._multiline: self._widget.setStyleSheet("QTextEdit {background-color: "+str(background)+"; color: "+str(text)+"}") else: self._widget.setStyleSheet("QLineEdit {b...
Create a Python 3 function to set the colors of the text area.
You are a Python code analyst, evaluating scripts for potential improvements.
Block all tree elements and parameters in the tree.
Here you have a function in Python 3, explain what it does def block_events(self): # block events in the usual way BaseObject.block_events(self) # loop over all top level parameters for i in range(self._widget.topLevelItemCount()): self._widget.topLevelItem(i).param....
As a Python code composer, you craft elegant and concise scripts.
def unblock_events(self): """ Special version of unblock_events that loops over all tree elements as well. """ # unblock events in the usual way BaseObject.unblock_events(self) # loop over all top level parameters for i in range(self._widget.topLevelItemC...
Write a Python 3 function that can unblock all events in the tree.
As a Python code translator, you convert algorithms and pseudocode into Python.
Connects the anything changed signal to all of the tree items.
Can you generate the documentation for the following Python 3 function def connect_any_signal_changed(self, function): # loop over all top level parameters for i in range(self._widget.topLevelItemCount()): # make sure there is only one connection! try: s...
You are a Python code generator, capable of creating scripts from specifications.
def connect_signal_changed(self, name, function): """ Connects a changed signal from the parameters of the specified name to the supplied function. """ x = self._find_parameter(name.split("/")) # if it pooped. if x==None: return None # connect it ...
Can you create a Python 3 function that connects a changed signal from the parameters of the specified name to the supplied function.
You are a Python code architect, reviewing and designing scalable and efficient code
Disconnects all user - defined signals for the specified parameter name.
Make a summary of the following Python 3 code def block_user_signals(self, name, ignore_error=False): x = self._find_parameter(name.split("/"), quiet=ignore_error) # if it pooped. if x==None: return None # disconnect it from all its functions if name in self._connec...
As a Python code analyst, you investigate and solve complex coding mysteries
Unblock the user - defined signals for the specified parameter name.
Here you have a function in Python 3, explain what it does def unblock_user_signals(self, name, ignore_error=False): x = self._find_parameter(name.split("/"), quiet=ignore_error) # if it pooped. if x==None: return None # reconnect it to all its functions if name in ...
You are a Python code generator, capable of creating scripts from specifications.
Tries to find and return the parameter of the specified name.
Here you have a function in Python 3, explain what it does def _find_parameter(self, name_list, create_missing=False, quiet=False): # make a copy so this isn't destructive to the supplied list s = list(name_list) # if the length is zero, return the root widget if len(s)==0: return self....
As a Python code composer, you craft elegant and concise scripts.
Cleans up the name according to the rules specified in this exact function.
Can you generate the documentation for the following Python 3 function def _clean_up_name(self, name): for n in self.naughty: name = name.replace(n, '_') return name
You are a Python code analyst, evaluating scripts for potential improvements.
Adds a button at the specified location.
How would you explain what the following Python 3 function does def add_button(self, name, checkable=False, checked=False): # first clean up the name name = self._clean_up_name(name) # split into (presumably existing) branches and parameter s = name.split('/') # make sure it d...
As a Python code translator, you convert algorithms and pseudocode into Python.
def add_parameter(self, name='test', value=42.0, **kwargs): """ Adds a parameter "leaf" to the tree. Parameters ---------- name='test' The name of the leaf. It should be a string of the form "branch1/branch2/parametername" and will be nested as i...
How would you implement a function in Python 3 that adds a parameter to the tree.
As a Python code composer, you craft elegant and concise scripts.
Recursively loops over the parameter s children adding the base_name and values to the supplied dictionary.
Can you tell what is the following Python 3 function doing def _get_parameter_dictionary(self, base_name, dictionary, sorted_keys, parameter): # assemble the key for this parameter k = base_name + "/" + parameter.name() # first add this parameter (if it has a value) if not parameter.va...
As a Python code analyst, you investigate and solve complex coding mysteries
Sends all the information currently in the tree to the supplied databox s header in alphabetical order.
Here you have a function in Python 3, explain what it does def send_to_databox_header(self, destination_databox): k, d = self.get_dictionary() destination_databox.update_headers(d,k)
You are a Python code generator, capable of creating scripts from specifications.
def get_dictionary(self): """ Returns the list of parameters and a dictionary of values (good for writing to a databox header!) Return format is sorted_keys, dictionary """ # output k = list() d = dict() # loop over the root items for i ...
Write a Python 3 script for returning the list of parameters and a dictionary of values
You are a Python code analyst, evaluating scripts for potential improvements.
def get_value(self, name): """ Returns the value of the parameter with the specified name. """ # first clean up the name name = self._clean_up_name(name) # now get the parameter object x = self._find_parameter(name.split('/')) # quit if it pooped. ...
Can you create a Python 3 function that returns the value of the parameter with the specified name.
As a Python code composer, you craft elegant and concise scripts.
Returns the list values for a list item of the specified name.
Explain what the following Python 3 code does def get_list_values(self, name): # Make sure it's a list if not self.get_type(name) in ['list']: self.print_message('ERROR: "'+name+'" is not a list.') return # Return a copy of the list values return list(se...
As a python code expert, you are capable of creating scripts from specifications.
Sets the value of the supplied parameter name to the supplied value.
Given the following Python 3 function, write the documentation def set_value(self, name, value, ignore_error=False, block_user_signals=False): # first clean up the name name = self._clean_up_name(name) # If we're supposed to, block the user signals for this parameter if block_user_signa...
You are a Python code architect, reviewing and designing scalable and efficient code
Saves all the parameters to a text file using the databox functionality.
Can you generate the documentation for the following Python 3 function def save(self, path=None): if path==None: if self._autosettings_path == None: return self # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') ...
You are a Python code generator, capable of creating scripts from specifications.
Set the value of a key to a value.
Given the following Python 3 function, write the documentation def _set_value_safe(self, k, v, ignore_errors=False, block_user_signals=False): # for safety: by default assume it's a repr() with python code try: self.set_value(k, v, ignore_error = ignore_errors, ...
As a python code expert, you are capable of creating scripts from specifications.
def _button_autosave_clicked(self, checked): """ Called whenever the button is clicked. """ if checked: # get the path from the user path = _spinmob.dialogs.save(filters=self.file_type) # abort if necessary if not path: sel...
Implement a function in Python 3 to call when the button is clicked.
You are a Python code architect, reviewing and designing scalable and efficient code
Save the data in the databox to a file.
Here you have a function in Python 3, explain what it does def save_file(self, path=None, force_overwrite=False, just_settings=False, **kwargs): # Update the binary mode if not 'binary' in kwargs: kwargs['binary'] = self.combo_binary.get_text() # if it's just the settings file, make a n...
As a python code expert, you are capable of creating scripts from specifications.
Loads a data file and updates the internal data and the GUI.
Given the following Python 3 function, write the documentation def load_file(self, path=None, just_settings=False): # if it's just the settings file, make a new databox if just_settings: d = _d.databox() header_only = True # otherwise use the internal databox els...
You are a Python code generator, capable of creating scripts from specifications.
def _autoscript(self): """ Automatically generates a python script for plotting. """ # This should never happen unless I screwed up. if self.combo_autoscript.get_index() == 0: return "ERROR: Ask Jack." # if there is no data, leave it blank if len(self)...
Write a Python 3 function for generating a python script for plotting the current object.
As a python code expert, you are capable of creating scripts from specifications.
def plot(self): """ Sets the internal databox to the supplied value and plots it. If databox=None, this will plot the internal databox. """ # if we're disabled or have no data columns, clear everything! if not self.button_enabled.is_checked() or len(self) == 0: ...
Can you write a function in Python 3 where it plots the internal databox.
As a Python code composer, you craft elegant and concise scripts.
Autosaves the currently stored data but only if autosave is checked!
Can you generate a brief explanation for the following Python 3 code def autosave(self): # make sure we're suppoed to if self.button_autosave.is_checked(): # save the file self.save_file(_os.path.join(self._autosave_directory, "%04d " % (self.number_file.get_value()) + self._lab...
You are a Python code analyst, evaluating scripts for potential improvements.
def _synchronize_controls(self): """ Updates the gui based on button configs. """ # whether the script is visible self.grid_script._widget.setVisible(self.button_script.get_value()) # whether we should be able to edit it. if not self.combo_autoscript.get_index()...
Write a Python 3 script to synchronize the control based on button configs.
As a Python code composer, you craft elegant and concise scripts.
def _set_number_of_plots(self, n): """ Adjusts number of plots & curves to the desired value the gui. """ # multi plot, right number of plots and curves = great! if self.button_multi.is_checked() \ and len(self._curves) == len(self.plot_widgets) \ a...
Can you implement a function in Python 3 that adjusts the number of plots and curves to the desired value the gui.
As a python code expert, you are capable of creating scripts from specifications.
def _update_linked_axes(self): """ Loops over the axes and links / unlinks them. """ # no axes to link! if len(self.plot_widgets) <= 1: return # get the first plotItem a = self.plot_widgets[0].plotItem.getViewBox() # now loop through all the axes...
Implement a function in Python 3 to update the linked axes of the current plot item.
You are a Python code architect, reviewing and designing scalable and efficient code
def resolve_const_spec(self, name, lineno): """Finds and links the ConstSpec with the given name.""" if name in self.const_specs: return self.const_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.in...
Implement a function in Python 3 to find and links the ConstSpec with the given name.
As a Python code composer, you craft elegant and concise scripts.
Finds and links the TypeSpec with the given name.
Can you tell what is the following Python 3 function doing def resolve_type_spec(self, name, lineno): if name in self.type_specs: return self.type_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.included_sc...
You are a Python code generator, capable of creating scripts from specifications.
def resolve_service_spec(self, name, lineno): """Finds and links the ServiceSpec with the given name.""" if name in self.service_specs: return self.service_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 2) if include_name in...
Can you implement a function in Python 3 that finds and links the ServiceSpec with the given name.
You are a Python code generator, capable of creating scripts from specifications.
Register an imported module into this scope.
Can you generate the documentation for the following Python 3 function def add_include(self, name, included_scope, module): # The compiler already ensures this. If we still get here with a # conflict, that's a bug. assert name not in self.included_scopes self.included_scopes[name] = inc...
You are a Python code analyst, evaluating scripts for potential improvements.
def add_service_spec(self, service_spec): """Registers the given ``ServiceSpec`` into the scope. Raises ``ThriftCompilerError`` if the name has already been used. """ assert service_spec is not None if service_spec.name in self.service_specs: raise ThriftCompilerErr...
Write a Python 3 function that can add the given ServiceSpec into the scope.
As a Python code composer, you craft elegant and concise scripts.
Adds a ConstSpec to the compliation scope.
Explain what the following Python 3 code does def add_const_spec(self, const_spec): if const_spec.name in self.const_specs: raise ThriftCompilerError( 'Cannot define constant "%s". That name is already taken.' % const_spec.name ) self.const_specs[c...
You are a Python code analyst, evaluating scripts for potential improvements.
def add_surface(self, name, surface): """Adds a top-level attribute with the given name to the module.""" assert surface is not None if hasattr(self.module, name): raise ThriftCompilerError( 'Cannot define "%s". The name has already been used.' % name ) ...
Write a Python 3 script to add a top - level attribute with the given name to the module.
As a Python code translator, you convert algorithms and pseudocode into Python.
def add_type_spec(self, name, spec, lineno): """Adds the given type to the scope. :param str name: Name of the new type :param spec: ``TypeSpec`` object containing information on the type, or a ``TypeReference`` if this is meant to be resolved during the ...
Can you create a Python 3 function that adds the given type to the scope.
As a Python code analyst, you investigate and solve complex coding mysteries
Coarsen an array of data.
Here you have a function in Python 3, explain what it does def coarsen_array(a, level=2, method='mean'): if a is None: return None # make sure it's a numpy array a = _n.array(a) # quickest option if level in [0,1,False]: return a # otherwise assemble the python code to execute ...
As a Python code analyst, you investigate and solve complex coding mysteries
def coarsen_data(x, y, ey=None, ex=None, level=2, exponential=False): """ Coarsens the supplied data set. Returns coarsened arrays of x, y, along with quadrature-coarsened arrays of ey and ex if specified. Parameters ---------- x, y Data arrays. Can be lists (will convert to numpy a...
Can you implement a function in Python 3 that coarsens the supplied data set and returns a list of arrays along with the specified quadrature - coarsened arrays of x y uncertainties and ex uncertainties.
As a python code expert, you are capable of creating scripts from specifications.
This returns a numpy matrix that coarsenes the columns and rows of the tree Z.
Make a summary of the following Python 3 code def coarsen_matrix(Z, xlevel=0, ylevel=0, method='average'): # coarsen x if not ylevel: Z_coarsened = Z else: temp = [] for z in Z: temp.append(coarsen_array(z, ylevel, method)) Z_coarsened = _n.array(temp) # coarsen y i...
You are a Python code analyst, evaluating scripts for potential improvements.
def erange(start, end, steps): """ Returns a numpy array over the specified range taking geometric steps. See also numpy.logspace() """ if start == 0: print("Nothing you multiply zero by gives you anything but zero. Try picking something small.") return None if end == 0: ...
Write a Python 3 function that can return a numpy array over the specified range taking geometric steps.
You are a Python code generator, capable of creating scripts from specifications.
def is_a_number(s): """ This takes an object and determines whether it's a number or a string representing a number. """ if _s.fun.is_iterable(s) and not type(s) == str: return False try: float(s) return 1 except: try: complex(s) return 2 ...
Create a Python 3 function for returning True if the object s value is a number False otherwise.
You are a Python code analyst, evaluating scripts for potential improvements.
def assemble_covariance(error, correlation): """ This takes an error vector and a correlation matrix and assembles the covariance """ covariance = [] for n in range(0, len(error)): covariance.append([]) for m in range(0, len(error)): covariance[n].append(correlation[n][m...
Create a Python 3 function for assembling the covariance matrix from an error vector and a correlation matrix.
As a Python code analyst, you investigate and solve complex coding mysteries
def combine_dictionaries(a, b): """ returns the combined dictionary. a's values preferentially chosen """ c = {} for key in list(b.keys()): c[key]=b[key] for key in list(a.keys()): c[key]=a[key] return c
Implement a Python 3 function for returning the combined dictionary a and b.
You are a Python code architect, reviewing and designing scalable and efficient code
This decomposes a covariance matrix into an error vector and a correlation matrix.
Make a summary of the following Python 3 code def decompose_covariance(c): # make it a kickass copy of the original c = _n.array(c) # first get the error vector e = [] for n in range(0, len(c[0])): e.append(_n.sqrt(c[n][n])) # now cycle through the matrix, dividing by e[1]*e[2] for n in r...
You are a Python code architect, reviewing and designing scalable and efficient code
def derivative(xdata, ydata): """ performs d(ydata)/d(xdata) with nearest-neighbor slopes must be well-ordered, returns new arrays [xdata, dydx_data] neighbors: """ D_ydata = [] D_xdata = [] for n in range(1, len(xdata)-1): D_xdata.append(xdata[n]) D_ydata.append((ydata[...
How would you code a function in Python 3 to return the derivative of the data with nearest - neighbor slopes.
You are a Python code analyst, evaluating scripts for potential improvements.
def derivative_fit(xdata, ydata, neighbors=1): """ loops over the data points, performing a least-squares linear fit of the nearest neighbors at each point. Returns an array of x-values and slopes. xdata should probably be well-ordered. neighbors How many data point on the left and right to incl...
Write a Python 3 function for performing a least - squares linear fit of the data points at each point. Returns an array of x - values and slopes.
You are a Python code architect, reviewing and designing scalable and efficient code
def distort_matrix_X(Z, X, f, new_xmin, new_xmax, subsample=3): """ Applies a distortion (remapping) to the matrix Z (and x-values X) using function f. returns new_Z, new_X f is an INVERSE function old_x(new_x) Z is a matrix. X is an array where X[n] is the x-value associated with the array Z[n]. ...
Implement a Python 3 function for applying a distortion (remapping) to the matrix Z (and x-values X) using function f. returns new_Z, new_X f is an INVERSE function old_x(new_x) Z is a matrix. X is an array where X[n] is the x-value associated with the array Z[n]. new_xmin, new_xmax is the possible range of the distort...
As a Python code translator, you convert algorithms and pseudocode into Python.
Applies a distortion to the matrix Z and y - values Y using function f.
Here you have a function in Python 3, explain what it does def distort_matrix_Y(Z, Y, f, new_ymin, new_ymax, subsample=3): # just use the same methodology as before by transposing, distorting X, then # transposing back new_Z, new_Y = distort_matrix_X(Z.transpose(), Y, f, new_ymin, new_ymax, subsample) ...
As a python code expert, you are capable of creating scripts from specifications.
This just steps x and looks for a peak returns x and f
Can you generate the documentation for the following Python 3 function def dumbguy_minimize(f, xmin, xmax, xstep): prev = f(xmin) this = f(xmin+xstep) for x in frange(xmin+xstep,xmax,xstep): next = f(x+xstep) # see if we're on top if this < prev and this < next: return x, this ...
You are a Python code architect, reviewing and designing scalable and efficient code
Tests whether the elements of the supplied array are numbers.
How would you explain what the following Python 3 function does def elements_are_numbers(array): # empty case if len(array) == 0: return 0 output_value = 1 for x in array: # test it and die if it's not a number test = is_a_number(x) if not test: return False # mention...
You are a Python code generator, capable of creating scripts from specifications.
Modifies the length of list a to match b. Returns a.
Given the following Python 3 function, write the documentation def equalize_list_lengths(a,b): if not _s.fun.is_iterable(a): a = [a] a = list(a) while len(a)>len(b): a.pop(-1) while len(a)<len(b): a.append(a[-1]) return a
As a Python code translator, you convert algorithms and pseudocode into Python.
Linear fit of the best fit.
Can you generate a brief explanation for the following Python 3 code def fit_linear(xdata, ydata): x = _n.array(xdata) y = _n.array(ydata) ax = _n.average(x) ay = _n.average(y) axx = _n.average(x*x) ayx = _n.average(y*x) slope = (ayx - ay*ax) / (axx - ax*ax) intercept = ay - slop...
As a python code expert, you are capable of creating scripts from specifications.
A range function that accepts float increments and reversed direction.
Make a summary of the following Python 3 code def frange(start, end, inc=1.0): start = 1.0*start end = 1.0*end inc = 1.0*inc # if we got a dumb increment if not inc: return _n.array([start,end]) # if the increment is going the wrong direction if 1.0*(end-start)/inc < 0.0: inc ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Generate a set of fake data from the underlying reality function or mean behavior.
Make a summary of the following Python 3 code def generate_fake_data(f='2*x-5', x=_n.linspace(-5,5,11), ey=1, ex=0, include_errors=False, **kwargs): # Make a fitter object, which handily interprets string functions # The "+0*x" is a trick to ensure the function takes x as an argument # (makes it a lit...
You are a Python code analyst, evaluating scripts for potential improvements.
Returns a list of history items for the current shell.
Explain what the following Python 3 code does def get_shell_history(): # try for ipython if 'get_ipython' in globals(): a = list(get_ipython().history_manager.input_hist_raw) a.reverse() return a elif 'SPYDER_SHELL_ID' in _os.environ: try: p = _os.path.join(_sett...
As a python code expert, you are capable of creating scripts from specifications.
Returns the index of the value in the array.
Can you generate the documentation for the following Python 3 function def index(value, array): i = array.searchsorted(value) if i == len(array): return -1 else: return i
As a python code expert, you are capable of creating scripts from specifications.
def index_nearest(value, array): """ expects a _n.array returns the global minimum of (value-array)^2 """ a = (array-value)**2 return index(a.min(), a)
Create a Python 3 function to return the index of the nearest value in an array
As a python code expert, you are capable of creating scripts from specifications.
Returns the index of the next crossing point with value in the array.
Can you generate a brief explanation for the following Python 3 code def index_next_crossing(value, array, starting_index=0, direction=1): for n in range(starting_index, len(array)-1): if (value-array[n] )*direction >= 0 \ and (value-array[n+1])*direction < 0: return n # no crossing...
You are a Python code architect, reviewing and designing scalable and efficient code
def invert_increasing_function(f, f0, xmin, xmax, tolerance, max_iterations=100): """ This will try try to qickly find a point on the f(x) curve between xmin and xmax that is equal to f0 within tolerance. """ for n in range(max_iterations): # start at the middle x = 0.5*(xmin+xmax) ...
Write a Python 3 function that can invert the increasing function f by f0.
You are a Python code architect, reviewing and designing scalable and efficient code
def psd(t, y, pow2=False, window=None, rescale=False): """ Single-sided power spectral density, assuming real valued inputs. This goes through the numpy fourier transform process, assembling and returning (frequencies, psd) given time and signal data y. Note it is defined such that sum(psd)*d...
How would you code a function in Python 3 to return a single - sided power spectral density of the signal at time t and signal y.
As a Python code composer, you craft elegant and concise scripts.
Replaces the search string in the specified list of files.
Make a summary of the following Python 3 code def replace_in_files(search, replace, depth=0, paths=None, confirm=True): # have the user select some files if paths==None: paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return for path in paths: lines = read_lines(pat...
As a Python code translator, you convert algorithms and pseudocode into Python.
def replace_lines_in_files(search_string, replacement_line): """ Finds lines containing the search string and replaces the whole line with the specified replacement string. """ # have the user select some files paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return ...
Write a Python 3 function that can find lines containing the search string and replaces the whole line with replacement_line.
As a Python code composer, you craft elegant and concise scripts.
returns a reversed numpy array
Here you have a function in Python 3, explain what it does def reverse(array): l = list(array) l.reverse() return _n.array(l)
You are a Python code generator, capable of creating scripts from specifications.
Rounds the number to the specified significant figures.
Can you tell what is the following Python 3 function doing def round_sigfigs(x, n=2): iterable = is_iterable(x) if not iterable: x = [x] # make a copy to be safe x = _n.array(x) # loop over the elements for i in range(len(x)): # Handle the weird cases if not x[i] i...
You are a Python code architect, reviewing and designing scalable and efficient code
Shifts xdata ydata by x0
Explain what the following Python 3 code does def shift_feature_to_x0(xdata, ydata, x0=0, feature=imax): i = feature(ydata) return xdata-xdata[i]+x0, ydata
As a Python code composer, you craft elegant and concise scripts.
def smooth_data(xdata, ydata, yerror, amount=1): """ Returns smoothed [xdata, ydata, yerror]. Does not destroy the input arrays. """ new_xdata = smooth_array(_n.array(xdata), amount) new_ydata = smooth_array(_n.array(ydata), amount) if yerror is None: new_yerror = None else: ...
How would you code a function in Python 3 to return smoothed [xdata, ydata, yerror]. Does not destroy the input arrays.
As a Python code translator, you convert algorithms and pseudocode into Python.
def sort_matrix(a,n=0): """ This will rearrange the array a[n] from lowest to highest, and rearrange the rest of a[i]'s in the same way. It is dumb and slow. Returns a numpy array. """ a = _n.array(a) return a[:,a[n,:].argsort()]
Create a Python 3 function for sorting a matrix by n elements.
You are a Python code architect, reviewing and designing scalable and efficient code
Returns the submatrix of the given matrix.
How would you explain what the following Python 3 function does def submatrix(matrix,i1,i2,j1,j2): new = [] for i in range(i1,i2+1): new.append(matrix[i][j1:j2+1]) return _n.array(new)
You are a Python code architect, reviewing and designing scalable and efficient code
def trim_data(xmin, xmax, xdata, *args): """ Removes all the data except that in which xdata is between xmin and xmax. This does not mutilate the input arrays, and additional arrays can be supplied via args (provided they match xdata in shape) xmin and xmax can be None """ # make sure it'...
Can you implement a function in Python 3 that removes all the data except that xdata is between xmin and xmax.
As a Python code composer, you craft elegant and concise scripts.
def _fetch(self, searchtype, fields, **kwargs): '''Fetch a response from the Geocoding API.''' fields['vintage'] = self.vintage fields['benchmark'] = self.benchmark fields['format'] = 'json' if 'layers' in kwargs: fields['layers'] = kwargs['layers'] returnty...
Can you implement a function in Python 3 that fetches a response from the Geocoding API.
As a Python code translator, you convert algorithms and pseudocode into Python.
Geocode a ( lon lat ) coordinate.
How would you explain what the following Python 3 function does def coordinates(self, x, y, **kwargs): '''Geocode a (lon, lat) coordinate.''' kwargs['returntype'] = 'geographies' fields = { 'x': x, 'y': y } return self._fetch('coordinates', fields, **kwar...
As a python code expert, you are capable of creating scripts from specifications.
Geocode an address passed as one string.
Explain what the following Python 3 code does def onelineaddress(self, address, **kwargs): '''Geocode an an address passed as one string. e.g. "4600 Silver Hill Rd, Suitland, MD 20746" ''' fields = { 'address': address, } return self._fetch('onelineaddress', ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def addressbatch(self, data, **kwargs): ''' Send either a CSV file or data to the addressbatch API. According to the Census, "there is currently an upper limit of 1000 records per batch file." If a file, must have no header and fields id,street,city,state,zip If data, should be a...
Can you implement a function in Python 3 that sends either a CSV file or a list of dicts with the above fields.
You are a Python code analyst, evaluating scripts for potential improvements.
def load_colormap(self, name=None): """ Loads a colormap of the supplied name. None means used the internal name. (See self.get_name()) """ if name == None: name = self.get_name() if name == "" or not type(name)==str: return "Error: Bad name." # assemble the pat...
Can you create a Python 3 function that loads a colormap from the supplied name.
You are a Python code architect, reviewing and designing scalable and efficient code
Saves the colormap with the specified name.
Here you have a function in Python 3, explain what it does def save_colormap(self, name=None): if name == None: name = self.get_name() if name == "" or not type(name)==str: return "Error: invalid name." # get the colormaps directory colormaps = _os.path.join(_settings.path_home, 'colorm...
As a python code expert, you are capable of creating scripts from specifications.
Deletes the colormap with the specified name.
Make a summary of the following Python 3 code def delete_colormap(self, name=None): if name == None: name = self.get_name() if name == "" or not type(name)==str: return "Error: invalid name." # assemble the path to the colormap path = _os.path.join(_settings.path_home, 'colormaps', name...
As a Python code translator, you convert algorithms and pseudocode into Python.
Sets the name of the object.
Explain what the following Python 3 code does def set_name(self, name="My Colormap"): if not type(name)==str: print("set_name(): Name must be a string.") return self._name = name return self
As a python code expert, you are capable of creating scripts from specifications.
def set_image(self, image='auto'): """ Set which pylab image to tweak. """ if image=="auto": image = _pylab.gca().images[0] self._image=image self.update_image()
Can you implement a function in Python 3 that sets which pylab image to tweak.
As a Python code composer, you craft elegant and concise scripts.
Update the image s cmap.
Can you generate the documentation for the following Python 3 function def update_image(self): if self._image: self._image.set_cmap(self.get_cmap()) _pylab.draw()
As a Python code translator, you convert algorithms and pseudocode into Python.
def pop_colorpoint(self, n=0): """ Removes and returns the specified colorpoint. Will always leave two behind. """ # make sure we have more than 2; otherwise don't pop it, just return it if len(self._colorpoint_list) > 2: # do the popping x = self._color...
Write a Python 3 script to remove and returns the specified colorpoint. Will always leave two behind.
You are a Python code generator, capable of creating scripts from specifications.
Insert a colorpoint into the list of colorpoints.
Can you generate a brief explanation for the following Python 3 code def insert_colorpoint(self, position=0.5, color1=[1.0,1.0,0.0], color2=[1.0,1.0,0.0]): L = self._colorpoint_list # if position = 0 or 1, push the end points inward if position <= 0.0: L.insert(0,[0.0,color1,color...
You are a Python code analyst, evaluating scripts for potential improvements.
def modify_colorpoint(self, n, position=0.5, color1=[1.0,1.0,1.0], color2=[1.0,1.0,1.0]): """ Changes the values of an existing colorpoint, then updates the colormap. """ if n==0.0 : position = 0.0 elif n==len(self._colorpoint_list)-1: position = 1.0 ...
How would you code a function in Python 3 to modify the colorpoint n in the image.
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_cmap(self): """ Generates a pylab cmap object from the colorpoint data. """ # now generate the colormap from the ordered list r = [] g = [] b = [] for p in self._colorpoint_list: r.append((p[0], p[1][0]*1.0, p[2][0]*1.0)) g...
Write a Python 3 function that can generate a pylab colormap object from the colorpoint data.
As a Python code analyst, you investigate and solve complex coding mysteries
def _build_gui(self): """ Removes all existing sliders and rebuilds them based on the colormap. """ # remove all widgets (should destroy all children too) self._central_widget.deleteLater() # remove all references to other controls self._sliders = [...
Create a Python 3 function for building the gui for the current locale.
As a python code expert, you are capable of creating scripts from specifications.
def _signal_load(self): """ Load the selected cmap. """ # set our name self.set_name(str(self._combobox_cmaps.currentText())) # load the colormap self.load_colormap() # rebuild the interface self._build_gui() self._button_save.setEnable...
How would you code a function in Python 3 to load the selected cmap.
As a Python code analyst, you investigate and solve complex coding mysteries
def _button_save_clicked(self): """ Save the selected cmap. """ self.set_name(str(self._combobox_cmaps.currentText())) self.save_colormap() self._button_save.setEnabled(False) self._load_cmap_list()
Write a Python 3 function that can save the selected cmap.
You are a Python code analyst, evaluating scripts for potential improvements.
Delete the selected cmap.
Explain what the following Python 3 code does def _button_delete_clicked(self): name = str(self._combobox_cmaps.currentText()) self.delete_colormap(name) self._combobox_cmaps.setEditText("") self._load_cmap_list()
As a Python code composer, you craft elegant and concise scripts.
def _color_dialog_changed(self, n, top, c): """ Updates the color of the slider. """ self._button_save.setEnabled(True) cp = self._colorpoint_list[n] # if they're linked, set both if self._checkboxes[n].isChecked(): self.modify_colorpoint(n, cp[0], [...
Write a Python 3 function that can update the color of the slider.
You are a Python code architect, reviewing and designing scalable and efficient code