sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
def _find_parameter(self, name_list, create_missing=False, quiet=False): """ Tries to find and return the parameter of the specified name. The name should be of the form ['branch1','branch2', 'parametername'] Setting create_missing=True means if it doesn't find a branch it ...
Tries to find and return the parameter of the specified name. The name should be of the form ['branch1','branch2', 'parametername'] Setting create_missing=True means if it doesn't find a branch it will create one. Setting quiet=True will suppress error messages (for checking)
entailment
def _clean_up_name(self, name): """ Cleans up the name according to the rules specified in this exact function. Uses self.naughty, a list of naughty characters. """ for n in self.naughty: name = name.replace(n, '_') return name
Cleans up the name according to the rules specified in this exact function. Uses self.naughty, a list of naughty characters.
entailment
def add_button(self, name, checkable=False, checked=False): """ Adds (and returns) a button at the specified location. """ # first clean up the name name = self._clean_up_name(name) # split into (presumably existing) branches and parameter s = name.split('/') ...
Adds (and returns) a button at the specified location.
entailment
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...
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 indicated. value=42.0 Value of the leaf. Com...
entailment
def _get_parameter_dictionary(self, base_name, dictionary, sorted_keys, parameter): """ Recursively loops over the parameter's children, adding keys (starting with base_name) and values to the supplied dictionary (provided they do not have a value of None). """ # assembl...
Recursively loops over the parameter's children, adding keys (starting with base_name) and values to the supplied dictionary (provided they do not have a value of None).
entailment
def send_to_databox_header(self, destination_databox): """ Sends all the information currently in the tree to the supplied databox's header, in alphabetical order. If the entries already exists, just updates them. """ k, d = self.get_dictionary() destination_datab...
Sends all the information currently in the tree to the supplied databox's header, in alphabetical order. If the entries already exists, just updates them.
entailment
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 ...
Returns the list of parameters and a dictionary of values (good for writing to a databox header!) Return format is sorted_keys, dictionary
entailment
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. ...
Returns the value of the parameter with the specified name.
entailment
def get_list_values(self, name): """ Returns the values for a list item of the specified 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 co...
Returns the values for a list item of the specified name.
entailment
def set_value(self, name, value, ignore_error=False, block_user_signals=False): """ Sets the variable of the supplied name to the supplied value. Setting block_user_signals=True will temporarily block the widget from sending any signals when setting the value. """ # firs...
Sets the variable of the supplied name to the supplied value. Setting block_user_signals=True will temporarily block the widget from sending any signals when setting the value.
entailment
def save(self, path=None): """ Saves all the parameters to a text file using the databox functionality. If path=None, saves to self._autosettings_path. If self._autosettings_path=None, does not save. """ if path==None: if self._autosettings_path ...
Saves all the parameters to a text file using the databox functionality. If path=None, saves to self._autosettings_path. If self._autosettings_path=None, does not save.
entailment
def load(self, path=None, ignore_errors=True, block_user_signals=False): """ Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path (provided this is not None). Parameters ---------- path=None Path to load ...
Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path (provided this is not None). Parameters ---------- path=None Path to load the settings from. If None, will load from the specified autosettings_path. ...
entailment
def update(self, d, ignore_errors=True, block_user_signals=False): """ Supply a dictionary or databox with a header of the same format and see what happens! (Hint: it updates the existing values.) This will store non-existent key-value pairs in the dictionary self._lazy...
Supply a dictionary or databox with a header of the same format and see what happens! (Hint: it updates the existing values.) This will store non-existent key-value pairs in the dictionary self._lazy_load. When you add settings in the future, these will be checked for the defau...
entailment
def _set_value_safe(self, k, v, ignore_errors=False, block_user_signals=False): """ Actually sets the value, first by trying it directly, then by """ # for safety: by default assume it's a repr() with python code try: self.set_value(k, v, ignore_error = ignore_...
Actually sets the value, first by trying it directly, then by
entailment
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...
Called whenever the button is clicked.
entailment
def save_file(self, path=None, force_overwrite=False, just_settings=False, **kwargs): """ Saves the data in the databox to a file. Parameters ---------- path=None Path for output. If set to None, use a save dialog. force_overwrite=False Do not que...
Saves the data in the databox to a file. Parameters ---------- path=None Path for output. If set to None, use a save dialog. force_overwrite=False Do not question the overwrite if the file already exists. just_settings=False Set to True to sa...
entailment
def load_file(self, path=None, just_settings=False): """ Loads a data file. After the file is loaded, calls self.after_load_file(self), which you can overwrite if you like! just_settings=True will only load the configuration of the controls, and will not plot anything or run aft...
Loads a data file. After the file is loaded, calls self.after_load_file(self), which you can overwrite if you like! just_settings=True will only load the configuration of the controls, and will not plot anything or run after_load_file
entailment
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)...
Automatically generates a python script for plotting.
entailment
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: ...
Sets the internal databox to the supplied value and plots it. If databox=None, this will plot the internal databox.
entailment
def autosave(self): """ Autosaves the currently stored data, but only if autosave is checked! """ # 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.num...
Autosaves the currently stored data, but only if autosave is checked!
entailment
def autozoom(self, n=None): """ Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone. """ if n==None: for p in self.plot_widgets: p.autoRange() else: self.plot_widgets[n].autoRange() return self
Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone.
entailment
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()...
Updates the gui based on button configs.
entailment
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...
Adjusts number of plots & curves to the desired value the gui.
entailment
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...
Loops over the axes and links / unlinks them.
entailment
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...
Finds and links the ConstSpec with the given name.
entailment
def resolve_type_spec(self, name, lineno): """Finds and links the TypeSpec with the given name.""" 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.includ...
Finds and links the TypeSpec with the given name.
entailment
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...
Finds and links the ServiceSpec with the given name.
entailment
def add_include(self, name, included_scope, module): """Register an imported module into this scope. Raises ``ThriftCompilerError`` if the name has already been used. """ # The compiler already ensures this. If we still get here with a # conflict, that's a bug. assert na...
Register an imported module into this scope. Raises ``ThriftCompilerError`` if the name has already been used.
entailment
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...
Registers the given ``ServiceSpec`` into the scope. Raises ``ThriftCompilerError`` if the name has already been used.
entailment
def add_const_spec(self, const_spec): """Adds a ConstSpec to the compliation scope. If the ConstSpec's ``save`` attribute is True, the constant will be added to the module at the top-level. """ if const_spec.name in self.const_specs: raise ThriftCompilerError( ...
Adds a ConstSpec to the compliation scope. If the ConstSpec's ``save`` attribute is True, the constant will be added to the module at the top-level.
entailment
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 ) ...
Adds a top-level attribute with the given name to the module.
entailment
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 ...
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 ``link`` stage. :param lineno: ...
entailment
def coarsen_array(a, level=2, method='mean'): """ Returns a coarsened (binned) version of the data. Currently supports any of the numpy array operations, e.g. min, max, mean, std, ... level=2 means every two data points will be binned. level=0 or 1 just returns a copy of the array """ i...
Returns a coarsened (binned) version of the data. Currently supports any of the numpy array operations, e.g. min, max, mean, std, ... level=2 means every two data points will be binned. level=0 or 1 just returns a copy of the array
entailment
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...
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 arrays). These are coarsened by taking an average. ey=None, ex=None ...
entailment
def coarsen_matrix(Z, xlevel=0, ylevel=0, method='average'): """ This returns a coarsened numpy matrix. method can be 'average', 'maximum', or 'minimum' """ # coarsen x if not ylevel: Z_coarsened = Z else: temp = [] for z in Z: temp.append(coarsen_array(z, ylevel, m...
This returns a coarsened numpy matrix. method can be 'average', 'maximum', or 'minimum'
entailment
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: ...
Returns a numpy array over the specified range taking geometric steps. See also numpy.logspace()
entailment
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 ...
This takes an object and determines whether it's a number or a string representing a number.
entailment
def array_shift(a, n, fill="average"): """ This will return an array with all the elements shifted forward in index by n. a is the array n is the amount by which to shift (can be positive or negative) fill="average" fill the new empty elements with the average of the array fill="wrap" ...
This will return an array with all the elements shifted forward in index by n. a is the array n is the amount by which to shift (can be positive or negative) fill="average" fill the new empty elements with the average of the array fill="wrap" fill the new empty elements with the lopped-of...
entailment
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...
This takes an error vector and a correlation matrix and assembles the covariance
entailment
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
returns the combined dictionary. a's values preferentially chosen
entailment
def decompose_covariance(c): """ This decomposes a covariance matrix into an error vector and a correlation matrix """ # 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 ...
This decomposes a covariance matrix into an error vector and a correlation matrix
entailment
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[...
performs d(ydata)/d(xdata) with nearest-neighbor slopes must be well-ordered, returns new arrays [xdata, dydx_data] neighbors:
entailment
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...
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 include.
entailment
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]. ...
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]. new_xmin, new_xmax is the possible range of the distorted x-variable fo...
entailment
def distort_matrix_Y(Z, Y, f, new_ymin, new_ymax, subsample=3): """ Applies a distortion (remapping) to the matrix Z (and y-values Y) using function f. returns new_Z, new_Y f is a function old_y(new_y) Z is a matrix. Y is an array where Y[n] is the y-value associated with the array Z[:,n]. ne...
Applies a distortion (remapping) to the matrix Z (and y-values Y) using function f. returns new_Z, new_Y f is a function old_y(new_y) Z is a matrix. Y is an array where Y[n] is the y-value associated with the array Z[:,n]. new_ymin, new_ymax is the range of the distorted x-variable for generating Z ...
entailment
def dumbguy_minimize(f, xmin, xmax, xstep): """ This just steps x and looks for a peak returns x, f(x) """ 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 just steps x and looks for a peak returns x, f(x)
entailment
def elements_are_numbers(array): """ Tests whether the elements of the supplied array are numbers. """ # 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 ...
Tests whether the elements of the supplied array are numbers.
entailment
def equalize_list_lengths(a,b): """ Modifies the length of list a to match b. Returns a. a can also not be a list (will convert it to one). a will not be modified. """ 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...
Modifies the length of list a to match b. Returns a. a can also not be a list (will convert it to one). a will not be modified.
entailment
def find_N_peaks(array, N=4, max_iterations=100, rec_max_iterations=3, recursion=1): """ This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found. """ if recursion<0: return None # get an initial guess as to the baseline ymin = min(array) ymax = max(ar...
This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found.
entailment
def find_peaks(array, baseline=0.1, return_subarrays=False): """ This will try to identify the indices of the peaks in array, returning a list of indices in ascending order. Runs along the data set until it jumps above baseline. Then it considers all the subsequent data above the baseline as part of th...
This will try to identify the indices of the peaks in array, returning a list of indices in ascending order. Runs along the data set until it jumps above baseline. Then it considers all the subsequent data above the baseline as part of the peak, and records the maximum of this data as one peak value.
entailment
def find_zero_bisect(f, xmin, xmax, xprecision): """ This will bisect the range and zero in on zero. """ if f(xmax)*f(xmin) > 0: print("find_zero_bisect(): no zero on the range",xmin,"to",xmax) return None temp = min(xmin,xmax) xmax = max(xmin,xmax) xmin = temp xmid = (...
This will bisect the range and zero in on zero.
entailment
def fit_linear(xdata, ydata): """ Returns slope and intercept of line of best fit: y = a*x + b through the supplied data. Parameters ---------- xdata, ydata: Arrays of x data and y data (having matching lengths). """ x = _n.array(xdata) y = _n.arra...
Returns slope and intercept of line of best fit: y = a*x + b through the supplied data. Parameters ---------- xdata, ydata: Arrays of x data and y data (having matching lengths).
entailment
def frange(start, end, inc=1.0): """ A range function, that accepts float increments and reversed direction. See also numpy.linspace() """ 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 incremen...
A range function, that accepts float increments and reversed direction. See also numpy.linspace()
entailment
def generate_fake_data(f='2*x-5', x=_n.linspace(-5,5,11), ey=1, ex=0, include_errors=False, **kwargs): """ Generates a set of fake data from the underlying "reality" (or mean behavior) function f. Parameters ---------- f: Underlying "reality" function or mean behavior. This can be a...
Generates a set of fake data from the underlying "reality" (or mean behavior) function f. Parameters ---------- f: Underlying "reality" function or mean behavior. This can be any python-evaluable string, and will have access to all the numpy functions (e.g., cos), scipy's sp...
entailment
def get_shell_history(): """ This only works with some shells. """ # 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.jo...
This only works with some shells.
entailment
def index(value, array): """ Array search that behaves like I want it to. Totally dumb, I know. """ i = array.searchsorted(value) if i == len(array): return -1 else: return i
Array search that behaves like I want it to. Totally dumb, I know.
entailment
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)
expects a _n.array returns the global minimum of (value-array)^2
entailment
def index_next_crossing(value, array, starting_index=0, direction=1): """ starts at starting_index, and walks through the array until it finds a crossing point with value set direction=-1 for down crossing """ for n in range(starting_index, len(array)-1): if (value-array[n] )*directi...
starts at starting_index, and walks through the array until it finds a crossing point with value set direction=-1 for down crossing
entailment
def insert_ordered(value, array): """ This will insert the value into the array, keeping it sorted, and returning the index where it was inserted """ index = 0 # search for the last array item that value is larger than for n in range(0,len(array)): if value >= array[n]: index = n+1...
This will insert the value into the array, keeping it sorted, and returning the index where it was inserted
entailment
def integrate_data(xdata, ydata, xmin=None, xmax=None, autozero=0): """ Numerically integrates up the ydata using the trapezoid approximation. estimate the bin width (scaled by the specified amount). Returns (xdata, integrated ydata). autozero is the number of data points to use as an estimate of t...
Numerically integrates up the ydata using the trapezoid approximation. estimate the bin width (scaled by the specified amount). Returns (xdata, integrated ydata). autozero is the number of data points to use as an estimate of the background (then subtracted before integrating).
entailment
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) ...
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.
entailment
def fft(t, y, pow2=False, window=None, rescale=False): """ FFT of y, assuming complex or real-valued inputs. This goes through the numpy fourier transform process, assembling and returning (frequencies, complex fft) given time and signal data y. Parameters ---------- t,y Time (t) ...
FFT of y, assuming complex or real-valued inputs. This goes through the numpy fourier transform process, assembling and returning (frequencies, complex fft) given time and signal data y. Parameters ---------- t,y Time (t) and signal (y) arrays with which to perform the fft. Note the t ...
entailment
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...
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)*df, where df is the frequency spacing, is the variance of the or...
entailment
def replace_in_files(search, replace, depth=0, paths=None, confirm=True): """ Does a line-by-line search and replace, but only up to the "depth" line. """ # have the user select some files if paths==None: paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return fo...
Does a line-by-line search and replace, but only up to the "depth" line.
entailment
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 ...
Finds lines containing the search string and replaces the whole line with the specified replacement string.
entailment
def reverse(array): """ returns a reversed numpy array """ l = list(array) l.reverse() return _n.array(l)
returns a reversed numpy array
entailment
def round_sigfigs(x, n=2): """ Rounds the number to the specified significant figures. x can also be a list or array of numbers (in these cases, a numpy array is returned). """ iterable = is_iterable(x) if not iterable: x = [x] # make a copy to be safe x = _n.array(x) # loop o...
Rounds the number to the specified significant figures. x can also be a list or array of numbers (in these cases, a numpy array is returned).
entailment
def shift_feature_to_x0(xdata, ydata, x0=0, feature=imax): """ Finds a feature in the the ydata and shifts xdata so the feature is centered at x0. Returns shifted xdata, ydata. Try me with plot.tweaks.manipulate_shown_data()! xdata,ydata data set x0=0 where to shift the peak feat...
Finds a feature in the the ydata and shifts xdata so the feature is centered at x0. Returns shifted xdata, ydata. Try me with plot.tweaks.manipulate_shown_data()! xdata,ydata data set x0=0 where to shift the peak feature=imax function taking an array/list and returning the index of sa...
entailment
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: ...
Returns smoothed [xdata, ydata, yerror]. Does not destroy the input arrays.
entailment
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()]
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.
entailment
def submatrix(matrix,i1,i2,j1,j2): """ returns the submatrix defined by the index bounds i1-i2 and j1-j2 Endpoints included! """ new = [] for i in range(i1,i2+1): new.append(matrix[i][j1:j2+1]) return _n.array(new)
returns the submatrix defined by the index bounds i1-i2 and j1-j2 Endpoints included!
entailment
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'...
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
entailment
def trim_data_uber(arrays, conditions): """ Non-destructively selects data from the supplied list of arrays based on the supplied list of conditions. Importantly, if any of the conditions are not met for the n'th data point, the n'th data point is rejected for all supplied arrays. Example ...
Non-destructively selects data from the supplied list of arrays based on the supplied list of conditions. Importantly, if any of the conditions are not met for the n'th data point, the n'th data point is rejected for all supplied arrays. Example ------- x = numpy.linspace(0,10,20) y = num...
entailment
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...
Fetch a response from the Geocoding API.
entailment
def coordinates(self, x, y, **kwargs): '''Geocode a (lon, lat) coordinate.''' kwargs['returntype'] = 'geographies' fields = { 'x': x, 'y': y } return self._fetch('coordinates', fields, **kwargs)
Geocode a (lon, lat) coordinate.
entailment
def address(self, street, city=None, state=None, zipcode=None, **kwargs): '''Geocode an address.''' fields = { 'street': street, 'city': city, 'state': state, 'zip': zipcode, } return self._fetch('address', fields, **kwargs)
Geocode an address.
entailment
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', fields, **kwargs)
Geocode an an address passed as one string. e.g. "4600 Silver Hill Rd, Suitland, MD 20746"
entailment
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...
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 list of dicts with the above fields (although ID is optiona...
entailment
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...
Loads a colormap of the supplied name. None means used the internal name. (See self.get_name())
entailment
def save_colormap(self, name=None): """ Saves the colormap with the specified name. None means use internal name. (See get_name()) """ if name == None: name = self.get_name() if name == "" or not type(name)==str: return "Error: invalid name." # get the colormaps ...
Saves the colormap with the specified name. None means use internal name. (See get_name())
entailment
def delete_colormap(self, name=None): """ Deletes the colormap with the specified name. None means use the internal name (see get_name()) """ if name == None: name = self.get_name() if name == "" or not type(name)==str: return "Error: invalid name." # assemble th...
Deletes the colormap with the specified name. None means use the internal name (see get_name())
entailment
def set_name(self, name="My Colormap"): """ Sets the name. Make sure the name is something your OS could name a file. """ if not type(name)==str: print("set_name(): Name must be a string.") return self._name = name return self
Sets the name. Make sure the name is something your OS could name a file.
entailment
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()
Set which pylab image to tweak.
entailment
def update_image(self): """ Set's the image's cmap. """ if self._image: self._image.set_cmap(self.get_cmap()) _pylab.draw()
Set's the image's cmap.
entailment
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...
Removes and returns the specified colorpoint. Will always leave two behind.
entailment
def insert_colorpoint(self, position=0.5, color1=[1.0,1.0,0.0], color2=[1.0,1.0,0.0]): """ Inserts the specified color into the list. """ L = self._colorpoint_list # if position = 0 or 1, push the end points inward if position <= 0.0: L.insert(0,[0.0,color1...
Inserts the specified color into the list.
entailment
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 ...
Changes the values of an existing colorpoint, then updates the colormap.
entailment
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...
Generates a pylab cmap object from the colorpoint data.
entailment
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 = [...
Removes all existing sliders and rebuilds them based on the colormap.
entailment
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...
Load the selected cmap.
entailment
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()
Save the selected cmap.
entailment
def _button_delete_clicked(self): """ Save the selected cmap. """ name = str(self._combobox_cmaps.currentText()) self.delete_colormap(name) self._combobox_cmaps.setEditText("") self._load_cmap_list()
Save the selected cmap.
entailment
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], [...
Updates the color of the slider.
entailment
def _button_plus_clicked(self, n): """ Create a new colorpoint. """ self._button_save.setEnabled(True) self.insert_colorpoint(self._colorpoint_list[n][0], self._colorpoint_list[n][1], self._colorpoint_list[n][2]) ...
Create a new colorpoint.
entailment
def _button_minus_clicked(self, n): """ Remove a new colorpoint. """ self._button_save.setEnabled(True) self.pop_colorpoint(n) self._build_gui()
Remove a new colorpoint.
entailment
def _slider_changed(self, n): """ updates the colormap / plot """ self._button_save.setEnabled(True) self.modify_colorpoint(n, self._sliders[n].value()*0.001, self._colorpoint_list[n][1], self._colorpoint_list[n][2])
updates the colormap / plot
entailment
def _color_button_clicked(self, n,top): """ Opens the dialog. """ self._button_save.setEnabled(True) if top: self._color_dialogs_top[n].open() else: self._color_dialogs_bottom[n].open()
Opens the dialog.
entailment
def _load_cmap_list(self): """ Searches the colormaps directory for all files, populates the list. """ # store the current name name = self.get_name() # clear the list self._combobox_cmaps.blockSignals(True) self._combobox_cmaps.clear() # list th...
Searches the colormaps directory for all files, populates the list.
entailment
def save(filters='*.*', text='Save THIS, facehead!', default_directory='default_directory', force_extension=None): """ Pops up a save dialog and returns the string path of the selected file. Parameters ---------- filters='*.*' Which file types should appear in the dialog. text='Save...
Pops up a save dialog and returns the string path of the selected file. Parameters ---------- filters='*.*' Which file types should appear in the dialog. text='Save THIS, facehead!' Title text for the dialog. default_directory='default_directory' Key for the spinmob.sett...
entailment
def load(filters="*.*", text='Select a file, FACEFACE!', default_directory='default_directory'): """ Pops up a dialog for opening a single file. Returns a string path or None. """ # make sure the filters contains "*.*" as an option! if not '*' in filters.split(';'): filters = filters + ";;All files ...
Pops up a dialog for opening a single file. Returns a string path or None.
entailment