signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def get_function_doc(function, config=default_config): | if config.exclude_function:<EOL><INDENT>for ex in config.exclude_function:<EOL><INDENT>if ex.match(function.__name__):<EOL><INDENT>return None<EOL><DEDENT><DEDENT><DEDENT>return _doc_object(function, '<STR_LIT>', config=config)<EOL> | Return doc for a function. | f8758:m1 |
def get_class_doc(klass, config=default_config): | if config.exclude_class:<EOL><INDENT>for ex in config.exclude_class:<EOL><INDENT>if ex.match(klass.__name__):<EOL><INDENT>return None<EOL><DEDENT><DEDENT><DEDENT>nested_doc = []<EOL>class_dict = klass.__dict__<EOL>for item in dir(klass):<EOL><INDENT>if item in class_dict.keys():<EOL><INDENT>appended = None<EOL>if isins... | Return doc for a class. | f8758:m2 |
def get_module_doc(module, config=default_config, already_met=None): | <EOL>if already_met is None:<EOL><INDENT>already_met = set()<EOL><DEDENT>if config.exclude_module:<EOL><INDENT>for ex in config.exclude_module:<EOL><INDENT>if ex.match(module.__name__):<EOL><INDENT>return None<EOL><DEDENT><DEDENT><DEDENT>if hasattr(module, '<STR_LIT>'):<EOL><INDENT>subm = [<EOL>modname for importer, mo... | Return doc for a module. | f8758:m3 |
def __init__(self, value, method=Method.PREFIX): | self.value = value<EOL>self.method = method<EOL> | Init method.
Args:
value (str): value to match.
method (const): Method constant, matching method. | f8758:c0:m0 |
def match(self, name): | if self.method == Ex.Method.PREFIX:<EOL><INDENT>return name.startswith(self.value)<EOL><DEDENT>elif self.method == Ex.Method.SUFFIX:<EOL><INDENT>return name.endswith(self.value)<EOL><DEDENT>elif self.method == Ex.Method.CONTAINS:<EOL><INDENT>return self.value in name<EOL><DEDENT>elif self.method == Ex.Method.EXACT:<EOL... | Check if given name matches.
Args:
name (str): name to check.
Returns:
bool: matches name. | f8758:c0:m1 |
def __init__(self,<EOL>exclude_module=None,<EOL>exclude_class=None,<EOL>exclude_function=None,<EOL>nested_class=False,<EOL>missing_doc=True): | self.exclude_module = exclude_module<EOL>self.exclude_class = exclude_class<EOL>self.exclude_function = exclude_function<EOL>self.nested_class = nested_class<EOL>self.missing_doc = missing_doc<EOL> | Init method.
Args:
exclude_module (list): list of Ex instances.
exclude_class (list): list of Ex instances.
exclude_function (list): list of Ex instances.
nested_class (bool): whether to get nested classes in classes.
missing_doc (bool): whether to get doc even when empty. | f8758:c1:m0 |
def read(*names, **kwargs): | return io.open(<EOL>join(dirname(__file__), *names),<EOL>encoding=kwargs.get('<STR_LIT>', '<STR_LIT:utf8>')<EOL>).read()<EOL> | Read a file in current directory. | f8759:m0 |
def build_toc_tree(title, input, output, content_directory): | LOGGER.info("<STR_LIT>".format(build_toc_tree.__name__,<EOL>output))<EOL>file = File(input)<EOL>file.cache()<EOL>existing_files = [foundations.strings.get_splitext_basename(item)<EOL>for item in glob.glob("<STR_LIT>".format(content_directory, FILES_EXTENSION))]<EOL>relative_directory = content_directory.replace("<STR_L... | Builds Sphinx documentation table of content tree file.
:param title: Package title.
:type title: unicode
:param input: Input file to convert.
:type input: unicode
:param output: Output file.
:type output: unicode
:param content_directory: Directory containing the content to be included in the table of content.
:type ... | f8761:m0 |
def get_command_line_arguments(): | parser = argparse.ArgumentParser(add_help=False)<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>action="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>type=unicode,<EOL>dest="<STR_LIT:title>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LI... | Retrieves command line arguments.
:return: Namespace.
:rtype: Namespace | f8761:m1 |
@foundations.decorators.system_exit<EOL>def main(): | args = get_command_line_arguments()<EOL>return build_toc_tree(args.title,<EOL>args.input,<EOL>args.output,<EOL>args.content_directory)<EOL> | Starts the Application.
:return: Definition success.
:rtype: bool | f8761:m2 |
def bleach(file): | LOGGER.info("<STR_LIT>".format(__name__, file))<EOL>source_file = File(file)<EOL>content = source_file.read()<EOL>for pattern in STATEMENT_SUBSTITUTE:<EOL><INDENT>matches = [match for match in re.finditer(pattern, content, re.DOTALL)]<EOL>offset = <NUM_LIT:0><EOL>for match in matches:<EOL><INDENT>start, end = match.sta... | Sanitizes given python module.
:param file: Python module file.
:type file: unicode
:return: Definition success.
:rtype: bool | f8762:m0 |
def readmodule(module, path=None): | res = {}<EOL>for key, value in list(_readmodule(module, path or []).items()):<EOL><INDENT>if isinstance(value, Class):<EOL><INDENT>res[key] = value<EOL><DEDENT><DEDENT>return res<EOL> | Backwards compatible interface.
Call readmodule_ex() and then only keep Class objects from the
resulting dictionary. | f8763:m0 |
def readmodule_ex(module, path=None): | return _readmodule(module, path or [])<EOL> | Read a module file and return a dictionary of classes.
Search for MODULE in PATH and sys.path, read and parse the
module and return a dictionary with one entry for each class
found in the module. | f8763:m1 |
def _readmodule(module, path, inpackage=None): | <EOL>if inpackage is not None:<EOL><INDENT>fullmodule = "<STR_LIT>" % (inpackage, module)<EOL><DEDENT>else:<EOL><INDENT>fullmodule = module<EOL><DEDENT>if fullmodule in _modules:<EOL><INDENT>return _modules[fullmodule]<EOL><DEDENT>dict = OrderedDict()<EOL>if module in sys.builtin_module_names and inpackage is None:<EOL... | Do the hard work for readmodule[_ex].
If INPACKAGE is given, it must be the dotted name of the package in
which we are searching for a submodule, and then PATH must be the
package search path; otherwise, we are searching for a top-level
module, and PATH is combined with sys.path. | f8763:m2 |
def reStructuredText_to_html(input, output, css_file): | LOGGER.info("<STR_LIT>".format(<EOL>reStructuredText_to_html.__name__, input))<EOL>os.system("<STR_LIT>".format(RST2HTML,<EOL>os.path.join(os.path.dirname(__file__), css_file),<EOL>input,<EOL>output))<EOL>LOGGER.info("<STR_LIT>".format("<STR_LIT>"))<EOL>os.system("<STR_LIT>".format(os.path.join(os.path.dirname(__file__... | Outputs a reStructuredText file to html.
:param input: Input reStructuredText file to convert.
:type input: unicode
:param output: Output html file.
:type output: unicode
:param css_file: Css file.
:type css_file: unicode
:return: Definition success.
:rtype: bool | f8765:m0 |
def get_command_line_arguments(): | parser = argparse.ArgumentParser(add_help=False)<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>action="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>type=unicode,<EOL>dest="<STR_LIT:input>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LI... | Retrieves command line arguments.
:return: Namespace.
:rtype: Namespace | f8765:m1 |
@foundations.decorators.system_exit<EOL>def main(): | args = get_command_line_arguments()<EOL>args.css_file = args.css_file if foundations.common.path_exists(args.css_file) else CSS_FILE<EOL>return reStructuredText_to_html(args.input,<EOL>args.output,<EOL>args.css_file)<EOL> | Starts the Application.
:return: Definition success.
:rtype: bool | f8765:m2 |
def import_sanitizer(sanitizer): | directory = os.path.dirname(sanitizer)<EOL>not directory in sys.path and sys.path.append(directory)<EOL>namespace = __import__(foundations.strings.get_splitext_basename(sanitizer))<EOL>if hasattr(namespace, "<STR_LIT>"):<EOL><INDENT>return namespace<EOL><DEDENT>else:<EOL><INDENT>raise foundations.exceptions.Programming... | Imports the sanitizer python module.
:param sanitizer: Sanitizer python module file.
:type sanitizer: unicode
:return: Module.
:rtype: object | f8766:m0 |
def build_api(packages, input, output, sanitizer, excluded_modules=None): | LOGGER.info("<STR_LIT>".format(build_api.__name__))<EOL>sanitizer = import_sanitizer(sanitizer)<EOL>if os.path.exists(input):<EOL><INDENT>shutil.rmtree(input)<EOL>os.makedirs(input)<EOL><DEDENT>excluded_modules = [] if excluded_modules is None else excluded_modules<EOL>packages_modules = {"<STR_LIT>": [],<EOL>"<STR_LIT... | Builds the Sphinx documentation API.
:param packages: Packages to include in the API.
:type packages: list
:param input: Input modules directory.
:type input: unicode
:param output: Output reStructuredText files directory.
:type output: unicode
:param sanitizer: Sanitizer python module.
:type sanitizer: unicode
:param... | f8766:m1 |
def get_command_line_arguments(): | parser = argparse.ArgumentParser(add_help=False)<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>action="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>dest="<STR_LIT>",<EOL>nargs="<STR_LIT:+>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_L... | Retrieves command line arguments.
:return: Namespace.
:rtype: Namespace | f8766:m2 |
@foundations.decorators.system_exit<EOL>def main(): | args = get_command_line_arguments()<EOL>args.sanitizer = args.sanitizer if foundations.common.path_exists(args.sanitizer) else SANITIZER<EOL>args.excluded_modules = args.excluded_modules if all(args.excluded_modules) else []<EOL>return build_api(args.packages,<EOL>args.input,<EOL>args.output,<EOL>args.sanitizer,<EOL>ar... | Starts the Application.
:return: Definition success.
:rtype: bool | f8766:m3 |
def slice_reStructuredText(input, output): | LOGGER.info("<STR_LIT>".format(slice_reStructuredText.__name__, input))<EOL>file = File(input)<EOL>file.cache()<EOL>slices = OrderedDict()<EOL>for i, line in enumerate(file.content):<EOL><INDENT>search = re.search(r"<STR_LIT>", line)<EOL>if search:<EOL><INDENT>slices[search.groups()[<NUM_LIT:0>]] = i + SLICE_ATTRIBUTE_... | Slices given reStructuredText file.
:param input: ReStructuredText file to slice.
:type input: unicode
:param output: Directory to output sliced reStructuredText files.
:type output: unicode
:return: Definition success.
:rtype: bool | f8767:m0 |
def get_command_line_arguments(): | parser = argparse.ArgumentParser(add_help=False)<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>action="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>type=unicode,<EOL>dest="<STR_LIT:input>",<EOL>help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>",<EOL>"<STR_LI... | Retrieves command line arguments.
:return: Namespace.
:rtype: Namespace | f8767:m1 |
@foundations.decorators.system_exit<EOL>def main(): | args = get_command_line_arguments()<EOL>return slice_reStructuredText(args.input,<EOL>args.output)<EOL> | Starts the Application.
:return: Definition success.
:rtype: bool | f8767:m2 |
def bleach(file): | LOGGER.info("<STR_LIT>".format(__name__, file))<EOL>source_file = File(file)<EOL>content = source_file.read()<EOL>for pattern in STATEMENT_SUBSTITUTE:<EOL><INDENT>matches = [match for match in re.finditer(pattern, content, re.DOTALL)]<EOL>offset = <NUM_LIT:0><EOL>for match in matches:<EOL><INDENT>start, end = match.sta... | Sanitizes given python module.
:param file: Python module file.
:type file: unicode
:return: Definition success.
:rtype: bool | f8768:m0 |
def get_long_description(): | description = []<EOL>with open("<STR_LIT>") as file:<EOL><INDENT>for line in file:<EOL><INDENT>if "<STR_LIT>" in line and len(description) >= <NUM_LIT:2>:<EOL><INDENT>blockLine = description[-<NUM_LIT:2>]<EOL>if re.search(r"<STR_LIT>", blockLine) and not re.search(r"<STR_LIT>", blockLine):<EOL><INDENT>description[-<NUM... | Returns the Package long description.
:return: Package long description.
:rtype: unicode | f8769:m0 |
def predict(self, fitted): | if fitted.shape[<NUM_LIT:0>] != len(self.modalities):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return fitted.idxmin()<EOL> | Assign the most likely modality given the fitted data
Parameters
----------
fitted : pandas.DataFrame or pandas.Series
Either a (n_modalities, features) DatFrame or (n_modalities,)
Series, either of which will return the best modality for each
feature. | f8771:c0:m2 |
def __init__(self, alphas, betas, ylabel='<STR_LIT>'): | if not isinstance(alphas, Iterable) and not isinstance(betas,<EOL>Iterable):<EOL><INDENT>alphas = [alphas]<EOL>betas = [betas]<EOL><DEDENT>self.ylabel = ylabel<EOL>self.alphas = np.array(alphas) if isinstance(alphas, Iterable)else np.ones(len(betas)) * alphas<EOL>self.betas = np.array(betas) if isinstance(betas, Iterab... | Model a family of beta distributions
Parameters
----------
alphas : float or list-like
List of values for the alpha parameter of the Beta distribution. If
this is a single value (not a list), it will be assumed that this
value is constant, and will be propaga... | f8773:c0:m0 |
def __eq__(self, other): | return np.all(self.alphas == other.alphas)and np.all(self.betas == other.betas)and np.all(self.prob_parameters == other.prob_parameters)<EOL> | Test equality with other model | f8773:c0:m1 |
def __ne__(self, other): | return not self.__eq__(other)<EOL> | Test not equality with other model | f8773:c0:m2 |
def logliks(self, x): | x = x.copy()<EOL>x[x == <NUM_LIT:0>] = VERY_SMALL_NUMBER<EOL>x[x == <NUM_LIT:1>] = <NUM_LIT:1> - VERY_SMALL_NUMBER<EOL>return np.array([np.log(prob) + rv.logpdf(x[np.isfinite(x)]).sum()<EOL>for prob, rv in<EOL>zip(self.prob_parameters, self.rvs)])<EOL> | Calculate log-likelihood of a feature x for each model
Converts all values that are exactly 1 or exactly 0 to 0.999 and 0.001
because they are out of range of the beta distribution.
Parameters
----------
x : numpy.array-like
A single vector to estimate the log-likel... | f8773:c0:m3 |
def logsumexp_logliks(self, x): | return logsumexp(self.logliks(x))<EOL> | Calculate how well this model fits these data
Parameters
----------
x : numpy.array-like
A single vector to estimate the log-likelihood of the models on
Returns
-------
logsumexp_logliks : float
Total log-likelihood of this model given this data | f8773:c0:m5 |
@staticmethod<EOL><INDENT>def nice_number_string(number, decimal_places=<NUM_LIT:2>):<DEDENT> | if number == np.round(number):<EOL><INDENT>return str(int(number))<EOL><DEDENT>elif number < <NUM_LIT:1> and number > <NUM_LIT:0>:<EOL><INDENT>inverse = <NUM_LIT:1> / number<EOL>if int(inverse) == np.round(inverse):<EOL><INDENT>return r'<STR_LIT>'.format(int(inverse))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>template = '<... | Convert floats to either integers or a nice looking fraction | f8773:c0:m6 |
def violinplot(self, n=<NUM_LIT:1000>, **kwargs): | kwargs.setdefault('<STR_LIT>', '<STR_LIT>')<EOL>dfs = []<EOL>for rv in self.rvs:<EOL><INDENT>psi = rv.rvs(n)<EOL>df = pd.Series(psi, name=self.ylabel).to_frame()<EOL>alpha, beta = rv.args<EOL>alpha = self.nice_number_string(alpha, decimal_places=<NUM_LIT:2>)<EOL>beta = self.nice_number_string(beta, decimal_places=<NUM_... | Plot violins of each distribution in the model family
Parameters
----------
n : int
Number of random variables to generate
kwargs : dict or keywords
Any keyword arguments to seaborn.violinplot
Returns
-------
ax : matplotlib.Axes object
... | f8773:c0:m7 |
def __init__(self, one_parameter_models=ONE_PARAMETER_MODELS,<EOL>two_parameter_models=TWO_PARAMETER_MODELS,<EOL>logbf_thresh=<NUM_LIT:10>): | self.logbf_thresh = logbf_thresh<EOL>self.one_param_models = {k: ModalityModel(**v)<EOL>for k, v in one_parameter_models.items()}<EOL>self.two_param_models = {k: ModalityModel(**v)<EOL>for k, v in two_parameter_models.items()}<EOL>self.models = self.one_param_models.copy()<EOL>self.models.update(self.two_param_models)<... | Initialize an object with models to estimate splicing modality
Parameters
----------
step : float
Distance between parameter values
vmax : float
Maximum parameter value
logbf_thresh : float
Minimum threshold at which the bayes factor differenc... | f8779:c0:m0 |
def _single_feature_logliks_one_step(self, feature, models): | x_non_na = feature[~feature.isnull()]<EOL>if x_non_na.empty:<EOL><INDENT>return pd.DataFrame()<EOL><DEDENT>else:<EOL><INDENT>dfs = []<EOL>for name, model in models.items():<EOL><INDENT>df = model.single_feature_logliks(feature)<EOL>df['<STR_LIT>'] = name<EOL>dfs.append(df)<EOL><DEDENT>return pd.concat(dfs, ignore_index... | Get log-likelihood of models at each parameterization for given data
Parameters
----------
feature : pandas.Series
Percent-based values of a single feature. May contain NAs, but only
non-NA values are used.
Returns
-------
logliks : pandas.DataFr... | f8779:c0:m1 |
@staticmethod<EOL><INDENT>def assert_non_negative(x):<DEDENT> | assert np.all(x[np.isfinite(x)] >= <NUM_LIT:0>)<EOL> | Ensure all values are greater than zero
Parameters
----------
x : array_like
A numpy array
Raises
------
AssertionError
If any value in ``x`` is less than 0 | f8779:c0:m2 |
@staticmethod<EOL><INDENT>def assert_less_than_or_equal_1(x):<DEDENT> | assert np.all(x[np.isfinite(x)] <= <NUM_LIT:1>)<EOL> | Ensure all values are less than 1
Parameters
----------
x : array_like
A numpy array
Raises
------
AssertionError
If any value in ``x`` are greater than 1 | f8779:c0:m3 |
def fit(self, data): | self.assert_less_than_or_equal_1(data.values.flat)<EOL>self.assert_non_negative(data.values.flat)<EOL>if isinstance(data, pd.DataFrame):<EOL><INDENT>log2_bayes_factors = data.apply(self.single_feature_fit)<EOL><DEDENT>elif isinstance(data, pd.Series):<EOL><INDENT>log2_bayes_factors = self.single_feature_fit(data)<EOL><... | Get the modality assignments of each splicing event in the data
Parameters
----------
data : pandas.DataFrame
A (n_samples, n_events) dataframe of splicing events' PSI scores.
Must be psi scores which range from 0 to 1
Returns
-------
log2_bayes_... | f8779:c0:m4 |
def predict(self, log2_bayes_factors, reset_index=False): | if reset_index:<EOL><INDENT>x = log2_bayes_factors.reset_index(level=<NUM_LIT:0>, drop=True)<EOL><DEDENT>else:<EOL><INDENT>x = log2_bayes_factors<EOL><DEDENT>if isinstance(x, pd.DataFrame):<EOL><INDENT>not_na = (x.notnull() > <NUM_LIT:0>).any()<EOL>not_na_columns = not_na[not_na].index<EOL>x.ix[NULL_MODEL, not_na_colum... | Guess the most likely modality for each event
For each event that has at least one non-NA value, if no modalilites
have logsumexp'd logliks greater than the log Bayes factor threshold,
then they are assigned the 'multimodal' modality, because we cannot
reject the null hypothesis that th... | f8779:c0:m5 |
def fit_predict(self, data): | return self.predict(self.fit(data))<EOL> | Convenience function to assign modalities directly from data | f8779:c0:m6 |
def single_feature_logliks(self, feature): | self.assert_less_than_or_equal_1(feature.values)<EOL>self.assert_non_negative(feature.values)<EOL>logliks = self._single_feature_logliks_one_step(<EOL>feature, self.one_param_models)<EOL>logsumexps = self.logliks_to_logsumexp(logliks)<EOL>if (logsumexps <= self.logbf_thresh).all():<EOL><INDENT>logliks_two_params = self... | Calculate log-likelihoods of each modality's parameterization
Used for plotting the estimates of a single feature
Parameters
----------
featre : pandas.Series
A single feature's values. All values must range from 0 to 1.
Returns
-------
logliks : pa... | f8779:c0:m7 |
def single_feature_fit(self, feature): | if np.isfinite(feature).sum() == <NUM_LIT:0>:<EOL><INDENT>series = pd.Series(index=MODALITY_ORDER)<EOL><DEDENT>else:<EOL><INDENT>logbf_one_param = pd.Series(<EOL>{k: v.logsumexp_logliks(feature) for<EOL>k, v in self.one_param_models.items()})<EOL>if (logbf_one_param <= self.logbf_thresh).all():<EOL><INDENT>logbf_two_pa... | Get the log2 bayes factor of the fit for each modality | f8779:c0:m9 |
def violinplot(self, n=<NUM_LIT:1000>, figsize=None, **kwargs): | if figsize is None:<EOL><INDENT>nrows = len(self.models)<EOL>width = max(len(m.rvs) for name, m in self.models.items())*<NUM_LIT><EOL>height = nrows*<NUM_LIT><EOL>figsize = width, height<EOL><DEDENT>fig, axes = plt.subplots(nrows=nrows, figsize=figsize)<EOL>for ax, model_name in zip(axes, MODALITY_ORDER):<EOL><INDENT>t... | r"""Visualize all modality family members with parameters
Use violinplots to visualize distributions of modality family members
Parameters
----------
n : int
Number of random variables to generate
kwargs : dict or keywords
Any keyword arguments to seabor... | f8779:c0:m11 |
def violinplot(x=None, y=None, data=None, bw=<NUM_LIT>, scale='<STR_LIT:width>',<EOL>inner=None, ax=None, **kwargs): | if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>sns.violinplot(x, y, data=data, bw=bw, scale=scale, inner=inner, ax=ax,<EOL>**kwargs)<EOL>ax.set(ylim=(<NUM_LIT:0>, <NUM_LIT:1>), yticks=(<NUM_LIT:0>, <NUM_LIT:0.5>, <NUM_LIT:1>))<EOL>return ax<EOL> | Wrapper around Seaborn's Violinplot specifically for [0, 1] ranged data
What's different:
- bw = 0.2: Sets bandwidth to be small and the same between datasets
- scale = 'width': Sets the width of all violinplots to be the same
- inner = None: Don't plot a boxplot or points inside the violinplot | f8780:m0 |
def bar(self, counts, phenotype_to_color=None, ax=None, percentages=True): | if percentages:<EOL><INDENT>counts = <NUM_LIT:100> * (counts.T / counts.T.sum()).T<EOL><DEDENT>if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>full_width = <NUM_LIT><EOL>width = full_width / counts.shape[<NUM_LIT:0>]<EOL>for i, (group, series) in enumerate(counts.iterrows()):<EOL><INDENT>left = np.arange(len(self... | Draw barplots grouped by modality of modality percentage per group
Parameters
----------
Returns
-------
Raises
------ | f8780:c1:m0 |
def event_estimation(self, event, logliks, logsumexps, renamed='<STR_LIT>'): | plotter = _ModelLoglikPlotter()<EOL>plotter.plot(event, logliks, logsumexps, self.modality_to_color,<EOL>renamed=renamed)<EOL>return plotter<EOL> | Show the values underlying bayesian modality estimations of an event
Parameters
----------
Returns
-------
Raises
------ | f8780:c1:m1 |
def plot_best_worst_fits(assignments_df, data, modality_col='<STR_LIT>',<EOL>score='<STR_LIT>'): | ncols = <NUM_LIT:2><EOL>nrows = len(assignments_df.groupby(modality_col).groups.keys())<EOL>fig, axes = plt.subplots(nrows=nrows, ncols=ncols,<EOL>figsize=(nrows*<NUM_LIT:4>, ncols*<NUM_LIT:6>))<EOL>axes_iter = axes.flat<EOL>fits = '<STR_LIT>', '<STR_LIT>'<EOL>for modality, df in assignments_df.groupby(modality_col):<E... | Violinplots of the highest and lowest scoring of each modality | f8781:m2 |
def bin_range_strings(bins, fmt='<STR_LIT>'): | return [('<STR_LIT:{>' + fmt + '<STR_LIT>' + fmt + '<STR_LIT:}>').format(i, j)<EOL>for i, j in zip(bins, bins[<NUM_LIT:1>:])]<EOL> | Given a list of bins, make a list of strings of those bin ranges
Parameters
----------
bins : list_like
List of anything, usually values of bin edges
Returns
-------
bin_ranges : list
List of bin ranges
>>> bin_range_strings((0, 0.5, 1))
['0-0.5', '0.5-1'] | f8782:m0 |
def binify(data, bins): | if bins is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(data, pd.DataFrame):<EOL><INDENT>binned = data.apply(lambda x: pd.Series(np.histogram(x, bins=bins,<EOL>range=(<NUM_LIT:0>, <NUM_LIT:1>))[<NUM_LIT:0>]))<EOL><DEDENT>elif isinstance(data, pd.Series):<EOL><INDENT>binned = pd.Series(np.hi... | Makes a histogram of each column the provided binsize
Parameters
----------
data : pandas.DataFrame
A samples x features dataframe. Each feature (column) will be binned
into the provided bins
bins : iterable
Bins you would like to use for this data. Must include the final bin
... | f8782:m2 |
def kld(p, q): | try:<EOL><INDENT>_check_prob_dist(p)<EOL>_check_prob_dist(q)<EOL><DEDENT>except ValueError:<EOL><INDENT>return np.nan<EOL><DEDENT>p = p.replace(<NUM_LIT:0>, np.nan)<EOL>q = q.replace(<NUM_LIT:0>, np.nan)<EOL>return (np.log2(p / q) * p).sum(axis=<NUM_LIT:0>)<EOL> | Kullback-Leiber divergence of two probability distributions pandas
dataframes, p and q
Parameters
----------
p : pandas.DataFrame
An nbins x features DataFrame, or (nbins,) Series
q : pandas.DataFrame
An nbins x features DataFrame, or (nbins,) Series
Returns
-------
kld... | f8782:m3 |
def jsd(p, q): | try:<EOL><INDENT>_check_prob_dist(p)<EOL>_check_prob_dist(q)<EOL><DEDENT>except ValueError:<EOL><INDENT>return np.nan<EOL><DEDENT>weight = <NUM_LIT:0.5><EOL>m = weight * (p + q)<EOL>result = weight * kld(p, m) + (<NUM_LIT:1> - weight) * kld(q, m)<EOL>return result<EOL> | Finds the per-column JSD between dataframes p and q
Jensen-Shannon divergence of two probability distrubutions pandas
dataframes, p and q. These distributions are usually created by running
binify() on the dataframe.
Parameters
----------
p : pandas.DataFrame
An nbins x features DataFr... | f8782:m4 |
def entropy(binned, base=<NUM_LIT:2>): | try:<EOL><INDENT>_check_prob_dist(binned)<EOL><DEDENT>except ValueError:<EOL><INDENT>np.nan<EOL><DEDENT>return -((np.log(binned) / np.log(base)) * binned).sum(axis=<NUM_LIT:0>)<EOL> | Find the entropy of each column of a dataframe
Parameters
----------
binned : pandas.DataFrame
A nbins x features DataFrame of probability distributions, where each
column sums to 1
base : numeric
The log-base of the entropy. Default is 2, so the resulting entropy
is in ... | f8782:m5 |
def binify_and_jsd(df1, df2, bins, pair=None): | binned1 = binify(df1, bins=bins).dropna(how='<STR_LIT:all>', axis=<NUM_LIT:1>)<EOL>binned2 = binify(df2, bins=bins).dropna(how='<STR_LIT:all>', axis=<NUM_LIT:1>)<EOL>binned1, binned2 = binned1.align(binned2, axis=<NUM_LIT:1>, join='<STR_LIT>')<EOL>series = np.sqrt(jsd(binned1, binned2))<EOL>series.name = pair<EOL>retur... | Binify and calculate jensen-shannon divergence between two dataframes
Parameters
----------
df1, df2 : pandas.DataFrames
Dataframes to calculate JSD between columns of. Must have overlapping
column names
bins : array-like
Bins to use for transforming df{1,2} into probability dis... | f8782:m6 |
def cross_phenotype_jsd(data, groupby, bins, n_iter=<NUM_LIT:100>): | grouped = data.groupby(groupby)<EOL>jsds = []<EOL>seen = set([])<EOL>for phenotype1, df1 in grouped:<EOL><INDENT>for phenotype2, df2 in grouped:<EOL><INDENT>pair = tuple(sorted([phenotype1, phenotype2]))<EOL>if pair in seen:<EOL><INDENT>continue<EOL><DEDENT>seen.add(pair)<EOL>if phenotype1 == phenotype2:<EOL><INDENT>se... | Jensen-Shannon divergence of features across phenotypes
Parameters
----------
data : pandas.DataFrame
A (n_samples, n_features) Dataframe
groupby : mappable
A samples to phenotypes mapping
n_iter : int
Number of bootstrap resampling iterations to perform for the
with... | f8782:m7 |
def jsd_df_to_2d(jsd_df): | jsd_2d = jsd_df.mean().reset_index()<EOL>jsd_2d = jsd_2d.rename(<EOL>columns={'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>', <NUM_LIT:0>: '<STR_LIT>'})<EOL>jsd_2d = jsd_2d.pivot(index='<STR_LIT>', columns='<STR_LIT>',<EOL>values='<STR_LIT>')<EOL>return jsd_2d + np.tril(jsd_2d.T, -<NUM_LIT:1>)<EOL> | Transform a tall JSD dataframe to a square matrix of mean JSDs
Parameters
----------
jsd_df : pandas.DataFrame
A (n_features, n_phenotypes^2) dataframe of the JSD between each
feature between and within phenotypes
Returns
-------
jsd_2d : pandas.DataFrame
A (n_phenotype... | f8782:m8 |
def build_parser(): | import argparse<EOL>description = "<STR_LIT>"<EOL>parser = argparse.ArgumentParser(description=description)<EOL>parser.add_argument('<STR_LIT>', metavar='<STR_LIT>', action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', action='<STR_LIT:store_true>',<EOL>de... | Returns an argparse.ArgumentParser instance to parse the command line
arguments for lk | f8785:m0 |
def get_file_contents(path, binary=False): | <EOL>f = open(path, '<STR_LIT:r>')<EOL>file_contents = f.read()<EOL>f.close()<EOL>if not binary and file_contents.find('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>return file_contents<EOL> | Return the contents of the text file at path.
If it is a binary file,raise an IOError | f8785:m1 |
def main(): | parser = build_parser()<EOL>args = parser.parse_args()<EOL>flags = re.LOCALE<EOL>if args.dot_all:<EOL><INDENT>flags |= re.DOTALL<EOL><DEDENT>if args.ignorecase:<EOL><INDENT>flags |= re.IGNORECASE<EOL><DEDENT>if args.str:<EOL><INDENT>flags |= re.UNICODE<EOL><DEDENT>if args.multiline:<EOL><INDENT>flags |= re.MULTILINE<EO... | if lk.py is run as a script, this function will run | f8785:m2 |
def enqueue_directory(self, directory): | exclude_path_regexes = self.exclude_path_regexes[:]<EOL>if not self.search_hidden:<EOL><INDENT>exclude_path_regexes.append(self.hidden_file_regex)<EOL><DEDENT>else:<EOL><INDENT>exclude_path_regexes.remove(self.hidden_file_regex)<EOL><DEDENT>self.mark = datetime.datetime.now()<EOL>def is_path_excluded(path):<EOL><INDENT... | add a search of the directory to the queue | f8785:c0:m1 |
def search_worker(self, regex, directory_path, names, binary=False,<EOL>callback=None): | try:<EOL><INDENT>result = DirectoryResult(directory_path)<EOL>def find_matches(name):<EOL><INDENT>full_path = path.join(directory_path, name)<EOL>file_contents = get_file_contents(full_path, binary)<EOL>start = <NUM_LIT:0><EOL>match = regex.search(file_contents, start)<EOL>while match:<EOL><INDENT>result.put(name, file... | build a DirectoryResult for the given regex, directory path, and file names | f8785:c0:m2 |
def print_result(self, directory_result): | for file_name, line_results_dict in directory_result.iter_line_results_items():<EOL><INDENT>full_path = path.join(directory_result.directory_path, file_name)<EOL>self.write(full_path, '<STR_LIT>')<EOL>self.write('<STR_LIT:\n>')<EOL>for line_number, line_results in sorted(line_results_dict.items()):<EOL><INDENT>self.wri... | Print out the contents of the directory result, using ANSI color codes if
supported | f8785:c1:m4 |
def get(key, default=None): | try:<EOL><INDENT>return ast.literal_eval(os.environ.get(key.upper(), default))<EOL><DEDENT>except (ValueError, SyntaxError):<EOL><INDENT>return os.environ.get(key.upper(), default)<EOL><DEDENT> | Searches os.environ. If a key is found try evaluating its type else;
return the string.
returns: k->value (type as defined by ast.literal_eval) | f8790:m0 |
def save(filepath=None, **kwargs): | if filepath is None:<EOL><INDENT>filepath = os.path.join('<STR_LIT>')<EOL><DEDENT>with open(filepath, '<STR_LIT:wb>') as file_handle:<EOL><INDENT>file_handle.writelines(<EOL>'<STR_LIT>'.format(key.upper(), val)<EOL>for key, val in kwargs.items()<EOL>)<EOL><DEDENT> | Saves a list of keyword arguments as environment variables to a file.
If no filepath given will default to the default `.env` file. | f8790:m1 |
def load(filepath=None): | if filepath and os.path.exists(filepath):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if not os.path.exists('<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>filepath = os.path.join('<STR_LIT>')<EOL><DEDENT>for key, value in _get_line_(filepath):<EOL><INDENT>os.environ.setdefault(key, str(value))<EOL><DEDENT>return... | Reads a .env file into os.environ.
For a set filepath, open the file and read contents into os.environ.
If filepath is not set then look in current dir for a .env file. | f8790:m2 |
def _get_line_(filepath): | for line in open(filepath):<EOL><INDENT>line = line.strip()<EOL>if line.startswith('<STR_LIT:#>') or '<STR_LIT:=>' not in line:<EOL><INDENT>continue<EOL><DEDENT>key, value = line.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>key = key.strip().upper()<EOL>value = value.strip()<EOL>if not (key and value):<EOL><INDENT>continue<EO... | Gets each line from the file and parse the data.
Attempt to translate the value into a python type is possible
(falls back to string). | f8790:m3 |
def get_config_path(): | dir_path = (os.getenv('<STR_LIT>') if os.name == "<STR_LIT>"<EOL>else os.path.expanduser('<STR_LIT>'))<EOL>return os.path.join(dir_path, '<STR_LIT>')<EOL> | Put together the default configuration path based on OS. | f8792:m0 |
def read_config(): | config = configparser.RawConfigParser(allow_no_value=True)<EOL>config.read(get_config_path())<EOL>if not config.has_section('<STR_LIT>'):<EOL><INDENT>config.add_section('<STR_LIT>')<EOL>config.set('<STR_LIT>', '<STR_LIT:key>', '<STR_LIT>')<EOL>config.set('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>write_config(config)<E... | Read configuration file | f8792:m1 |
def write_config(config): | with open(get_config_path(), '<STR_LIT:w>') as configfile:<EOL><INDENT>config.write(configfile)<EOL><DEDENT> | Write configuration file | f8792:m2 |
def print_table(document, *columns): | headers = []<EOL>for _, header in columns:<EOL><INDENT>headers.append(header)<EOL><DEDENT>table = []<EOL>for element in document:<EOL><INDENT>row = []<EOL>for item, _ in columns:<EOL><INDENT>if item in element:<EOL><INDENT>row.append(element[item])<EOL><DEDENT>else:<EOL><INDENT>row.append(None)<EOL><DEDENT><DEDENT>tabl... | Print json document as table | f8792:m3 |
def print_trip_table(document): | headers = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT:Name>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']<EOL>table = []<EOL>altnr = <NUM_LIT:0><EOL>for alternative in document:<EOL><INDENT>altnr += <NUM_LIT:1><EOL>first_trip_in_alt = True<EOL>if not isinstance(alternative... | Print trip table | f8792:m4 |
def main(): | config = read_config()<EOL>key = config.get('<STR_LIT>', '<STR_LIT:key>')<EOL>secret = config.get('<STR_LIT>', '<STR_LIT>')<EOL>parser = argparse.ArgumentParser(<EOL>description=u'<STR_LIT>')<EOL>parser.add_argument(<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>nargs='<STR_LIT:?>' if key else None,<EOL>default=key,<EOL>help='... | Main function | f8792:m5 |
def _get_node(response, *ancestors): | document = response<EOL>for ancestor in ancestors:<EOL><INDENT>if ancestor not in document:<EOL><INDENT>return {}<EOL><DEDENT>else:<EOL><INDENT>document = document[ancestor]<EOL><DEDENT><DEDENT>return document<EOL> | Traverse tree to node | f8793:m0 |
def update_token(self): | headers = {<EOL>'<STR_LIT:Content-Type>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>' + base64.b64encode(<EOL>(self._key + '<STR_LIT::>' + self._secret).encode()).decode()<EOL>}<EOL>data = {'<STR_LIT>': '<STR_LIT>'}<EOL>response = requests.post(TOKEN_URL, data=data, headers=headers)<EOL>obj = json.loads(response.content.... | Get token from key and secret | f8793:c1:m1 |
def location_allstops(self): | response = self._request(<EOL>'<STR_LIT>')<EOL>return _get_node(response, '<STR_LIT>', '<STR_LIT>')<EOL> | location.allstops | f8793:c1:m2 |
def location_nearbystops(self, origin_coord_lat, origin_coord_long): | response = self._request(<EOL>'<STR_LIT>',<EOL>originCoordLat=origin_coord_lat,<EOL>originCoordLong=origin_coord_long)<EOL>return _get_node(response, '<STR_LIT>', '<STR_LIT>')<EOL> | location.nearbystops | f8793:c1:m3 |
def location_nearbyaddress(self, origin_coord_lat, origin_coord_long): | response = self._request(<EOL>'<STR_LIT>',<EOL>originCoordLat=origin_coord_lat,<EOL>originCoordLong=origin_coord_long)<EOL>return _get_node(response, '<STR_LIT>', '<STR_LIT>')<EOL> | location.nearbyaddress | f8793:c1:m4 |
def location_name(self, name): | response = self._request(<EOL>'<STR_LIT>',<EOL>input=name)<EOL>return _get_node(response, '<STR_LIT>', '<STR_LIT>')<EOL> | location.name | f8793:c1:m5 |
def arrivalboard(self, stop_id, date=None, direction=None): | date = date if date else datetime.now()<EOL>request_parameters = {<EOL>'<STR_LIT:id>': stop_id,<EOL>'<STR_LIT:date>': date.strftime(DATE_FORMAT),<EOL>'<STR_LIT:time>': date.strftime(TIME_FORMAT)<EOL>}<EOL>if direction:<EOL><INDENT>request_parameters['<STR_LIT>'] = direction<EOL><DEDENT>response = self._request(<EOL>'<S... | arrivalBoard | f8793:c1:m6 |
def departureboard(self, stop_id, date=None, direction=None): | date = date if date else datetime.now()<EOL>request_parameters = {<EOL>'<STR_LIT:id>': stop_id,<EOL>'<STR_LIT:date>': date.strftime(DATE_FORMAT),<EOL>'<STR_LIT:time>': date.strftime(TIME_FORMAT)<EOL>}<EOL>if direction:<EOL><INDENT>request_parameters['<STR_LIT>'] = direction<EOL><DEDENT>response = self._request(<EOL>'<S... | departureBoard | f8793:c1:m7 |
def trip(self, origin_id, dest_id, date=None): | date = date if date else datetime.now()<EOL>response = self._request(<EOL>'<STR_LIT>',<EOL>originId=origin_id,<EOL>destId=dest_id,<EOL>date=date.strftime(DATE_FORMAT),<EOL>time=date.strftime(TIME_FORMAT))<EOL>return _get_node(response, '<STR_LIT>', '<STR_LIT>')<EOL> | trip | f8793:c1:m8 |
def _request(self, service, **parameters): | urlformat = "<STR_LIT>"<EOL>url = urlformat.format(<EOL>baseurl=API_BASE_URL,<EOL>service=service,<EOL>parameters="<STR_LIT:&>".join([<EOL>"<STR_LIT>".format(key, value) for key, value in parameters.items()<EOL>]))<EOL>if datetime.now() > self._token_expire_date:<EOL><INDENT>self.update_token()<EOL><DEDENT>headers = {'... | request builder | f8793:c1:m9 |
@click.command()<EOL>@click.option('<STR_LIT>', is_flag=True, help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', type=click.Choice(['<STR_LIT>', '<STR_LIT>']), help="<STR_LIT>")<EOL>@pass_wio<EOL>def cli(wio, get_debug, debug): | if debug:<EOL><INDENT>if debug == "<STR_LIT>":<EOL><INDENT>cmd = "<STR_LIT>"<EOL><DEDENT>elif debug == "<STR_LIT>":<EOL><INDENT>cmd = "<STR_LIT>"<EOL><DEDENT>if not cmd:<EOL><INDENT>return debug_error()<EOL><DEDENT>result = udp.send(cmd)<EOL>if not result:<EOL><INDENT>return debug_error()<EOL><DEDENT>click.echo("<STR_L... | Change setting of device.
\b
DOES:
The config command lets you change setting of device through upd.
1. Ensure your device is Configure Mode.
2. Change your computer network to Wio's AP.
\b
EXAMPLE:
wio config --debug [on|off], enable/disable wio debug
wio config --get-debug, get wio debug status | f8797:m0 |
@click.command()<EOL>@click.option('<STR_LIT>', nargs=<NUM_LIT:1>, type=unicode, help="<STR_LIT>")<EOL>@pass_wio<EOL>def cli(wio, send): | command = send<EOL>click.echo("<STR_LIT>".format(command))<EOL>result = udp.common_send(command)<EOL>if result is None:<EOL><INDENT>return debug_error()<EOL><DEDENT>else:<EOL><INDENT>click.echo(result)<EOL><DEDENT> | Sends a UDP command to the wio device.
\b
DOES:
Support "VERSION", "SCAN", "Blank?", "DEBUG", "ENDEBUG: 1", "ENDEBUG: 0"
"APCFG: AP\\tPWDs\\tTOKENs\\tSNs\\tSERVER_Domains\\tXSERVER_Domain\\t\\r\\n",
Note:
1. Ensure your device is Configure Mode.
2. Change your computer network to Wio's AP.
\b
EXAM... | f8798:m0 |
@click.command()<EOL>@pass_wio<EOL>def cli(wio): | user_token = wio.config.get("<STR_LIT>", None)<EOL>mserver_url = wio.config.get("<STR_LIT>", None)<EOL>if not mserver_url or not user_token:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style("<STR_LIT>", fg='<STR_LIT>'))<EOL>return<EOL><DEDENT>email = wio.config.get("<STR_L... | Login state.
\b
DOES:
Display login email, token, server url.
\b
USE:
wio state | f8799:m0 |
@click.command()<EOL>@pass_wio<EOL>def cli(wio): | user_token = wio.config.get("<STR_LIT>", None)<EOL>api_prefix = wio.config.get("<STR_LIT>", None)<EOL>if not api_prefix or not user_token:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style("<STR_LIT>", fg='<STR_LIT>'))<EOL>return<EOL><DEDENT>thread = termui.waiting_echo("<S... | Displays a list of your devices.
\b
DOES:
Displays a list of your devices, as well as their APIs
\b
USE:
wio list | f8800:m0 |
@click.command()<EOL>@pass_wio<EOL>def cli(wio): | mserver = wio.config.get("<STR_LIT>", None)<EOL>if mserver:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style(mserver, fg='<STR_LIT>'))<EOL>if click.confirm(click.style('<STR_LIT>', bold=True), default=False):<EOL><INDENT>choise_server(wio)<EOL><DEDENT><DEDENT>else:<EOL><IN... | Login with your Wio account.
\b
DOES:
Login and save an access token for interacting with your account on the Wio.
\b
USE:
wio login | f8801:m0 |
@click.command()<EOL>@click.argument('<STR_LIT>')<EOL>@click.argument('<STR_LIT>')<EOL>@click.argument('<STR_LIT>')<EOL>@pass_wio<EOL>def cli(wio, method, endpoint, token,): | user_token = wio.config.get("<STR_LIT>", None)<EOL>api_prefix = wio.config.get("<STR_LIT>", None)<EOL>if not api_prefix or not user_token:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style("<STR_LIT>", fg='<STR_LIT>'))<EOL>return<EOL><DEDENT>api = "<STR_LIT>" %(api_prefix, ... | Request api, return json.
\b
DOES:
Call a api on your devices.
token: device_token
method: GET or POST
endpoint: device_path, such as: /v1/node/GroveTempHumProD0/temperature
wio call <device_token> <request_method> <device_path>
\b
EXAMPLE:
wio call 98dd464bd268d4dc4cb9b37e4e779313 GET /v1/nod... | f8802:m0 |
@click.command()<EOL>@click.argument('<STR_LIT>')<EOL>@pass_wio<EOL>def cli(wio, sn): | user_token = wio.config.get("<STR_LIT>", None)<EOL>api_prefix = wio.config.get("<STR_LIT>", None)<EOL>if not api_prefix or not user_token:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style("<STR_LIT>", fg='<STR_LIT>'))<EOL>return<EOL><DEDENT>params = {"<STR_LIT>":user_token... | Delete a device.
\b
DOES:
Delete a device.
sn: device_sn
wio delete <device_sn>
\b
EXAMPLE:
wio delete 2885b2cab8abc5fb8e229e4a77bf5e4d | f8803:m0 |
def get_new(mserver_url, token, board): | thread = termui.waiting_echo("<STR_LIT>")<EOL>thread.daemon = True<EOL>thread.start()<EOL>try:<EOL><INDENT>params = {"<STR_LIT:name>":"<STR_LIT>", "<STR_LIT>":board, "<STR_LIT>":token}<EOL>r = requests.post("<STR_LIT>" %(mserver_url, nodes_create_endpoint), params=params, timeout=<NUM_LIT:10>, verify=verify)<EOL>r.rais... | get node sn and key | f8804:m0 |
@click.command()<EOL>@pass_wio<EOL>def cli(wio): | token = wio.config.get("<STR_LIT>", None)<EOL>mserver_url = wio.config.get("<STR_LIT>", None)<EOL>msvr_ip = wio.config.get("<STR_LIT>", None)<EOL>if not mserver_url or not token:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>') + "<STR_LIT>" +<EOL>click.style("<STR_LIT>", fg='<STR_LIT>'))<EOL>return<EOL>... | Add a new device with USB connect.
\b
DOES:
Guides you through setting up a new device, and getting it on your network.
\b
USE:
wio setup | f8804:m4 |
def serial_ports(): | if sys.platform.startswith('<STR_LIT>'):<EOL><INDENT>ports = ['<STR_LIT>' % (i + <NUM_LIT:1>) for i in range(<NUM_LIT>)]<EOL><DEDENT>elif sys.platform.startswith('<STR_LIT>') or sys.platform.startswith('<STR_LIT>'):<EOL><INDENT>ports = glob.glob('<STR_LIT>') <EOL><DEDENT>elif sys.platform.startswith('<STR_LIT>'):<EOL><... | Lists serial port names
:raises EnvironmentError:
On unsupported or unknown platforms
:returns:
A list of the serial ports available on the system | f8806:m0 |
@click.command(cls=ComplexCLI, context_settings=CONTEXT_SETTINGS)<EOL>@click.version_option(version)<EOL>@click.pass_context<EOL>def cli(ctx): | ctx.obj = Wio()<EOL>cur_dir = os.path.abspath(os.path.expanduser("<STR_LIT>"))<EOL>if not os.path.exists(cur_dir):<EOL><INDENT>text = {"<STR_LIT:email>":"<STR_LIT>", "<STR_LIT>":"<STR_LIT>"}<EOL>os.mkdir(cur_dir)<EOL>open("<STR_LIT>"%cur_dir,"<STR_LIT:w>").write(json.dumps(text))<EOL><DEDENT>db_file_path = '<STR_LIT>' ... | \b
Welcome to the Wio Command line utility!
https://github.com/Seeed-Studio/wio-cli
For more information Run: wio <command_name> --help | f8807:m1 |
def split(inp_str, sep_char, maxsplit=-<NUM_LIT:1>, escape_char='<STR_LIT:\\>'): | word_chars = []<EOL>word_chars_append = word_chars.append<EOL>inp_str_iter = iter(inp_str)<EOL>for c in inp_str_iter:<EOL><INDENT>word_chars_append(c)<EOL>if c == escape_char:<EOL><INDENT>try:<EOL><INDENT>next_char = next(inp_str_iter)<EOL><DEDENT>except StopIteration:<EOL><INDENT>continue<EOL><DEDENT>if next_char == s... | Separates a string on a character, taking into account escapes.
:param str inp_str: string to split.
:param str sep_char: separator character.
:param int maxsplit: maximum number of times to split from left.
:param str escape_char: escape character.
:rtype: __generator[str]
:return: sub-strings... | f8812:m0 |
def _full_sub_array(data_obj, xj_path, create_dict_path): | if isinstance(data_obj, list):<EOL><INDENT>if xj_path:<EOL><INDENT>res = []<EOL>for d in data_obj:<EOL><INDENT>val, exists = path_lookup(d, xj_path, create_dict_path)<EOL>if exists:<EOL><INDENT>res.append(val)<EOL><DEDENT><DEDENT>return tuple(res), True<EOL><DEDENT>else:<EOL><INDENT>return tuple(data_obj), True<EOL><DE... | Retrieves all array or dictionary elements for '*' JSON path marker.
:param dict|list data_obj: The current data object.
:param str xj_path: A json path.
:param bool create_dict_path create a dict path.
:return: tuple with two values: first is a result and second
a boolean flag telling if ... | f8812:m1 |
def _get_array_index(array_path): | if not array_path.startswith('<STR_LIT:@>'):<EOL><INDENT>raise XJPathError('<STR_LIT>')<EOL><DEDENT>array_path = array_path[<NUM_LIT:1>:]<EOL>if array_path == '<STR_LIT>':<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>if array_path == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if array_path.isdigit() or (arr... | Translates @first @last @1 @-1 expressions into an actual array index.
:param str array_path: Array path in XJ notation.
:rtype: int
:return: Array index. | f8812:m2 |
def _single_array_element(data_obj, xj_path, array_path, create_dict_path): | val_type, array_path = _clean_key_type(array_path)<EOL>array_idx = _get_array_index(array_path)<EOL>if data_obj and isinstance(data_obj, (list, tuple)):<EOL><INDENT>try:<EOL><INDENT>value = data_obj[array_idx]<EOL>if val_type is not None and not isinstance(value, val_type):<EOL><INDENT>raise XJPathError('<STR_LIT>'<EOL... | Retrieves a single array for a '@' JSON path marker.
:param list data_obj: The current data object.
:param str xj_path: A json path.
:param str array_path: A lookup key.
:param bool create_dict_path create a dict path. | f8812:m3 |
def _split_path(xj_path): | res = xj_path.rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL>root_key = res[<NUM_LIT:0>]<EOL>if len(res) > <NUM_LIT:1>:<EOL><INDENT>return root_key, res[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>if root_key and root_key != '<STR_LIT:.>':<EOL><INDENT>return None, root_key<EOL><DEDENT>else:<EOL><INDENT>raise XJPathError('<STR_L... | Extract the last piece of XJPath.
:param str xj_path: A XJPath expression.
:rtype: tuple[str|None, str]
:return: A tuple where first element is a root XJPath and the second is
a last piece of key. | f8812:m4 |
def validate_path(xj_path): | if not isinstance(xj_path, str):<EOL><INDENT>raise XJPathError('<STR_LIT>')<EOL><DEDENT>for path in split(xj_path, '<STR_LIT:.>'):<EOL><INDENT>if path == '<STR_LIT:*>':<EOL><INDENT>continue<EOL><DEDENT>if path.startswith('<STR_LIT:@>'):<EOL><INDENT>if path == '<STR_LIT>' or path == '<STR_LIT>':<EOL><INDENT>continue<EOL... | Validates XJ path.
:param str xj_path: XJ Path
:raise: XJPathError if validation fails. | f8812:m5 |
def _clean_key_type(key_name, escape_char=ESCAPE_SEQ): | for i in (<NUM_LIT:2>, <NUM_LIT:1>):<EOL><INDENT>if len(key_name) < i:<EOL><INDENT>return None, key_name<EOL><DEDENT>type_v = key_name[-i:]<EOL>if type_v in _KEY_SPLIT:<EOL><INDENT>if len(key_name) <= i:<EOL><INDENT>return _KEY_SPLIT[type_v], '<STR_LIT>'<EOL><DEDENT>esc_cnt = <NUM_LIT:0><EOL>for pos in range(-i - <NUM_... | Removes type specifier returning detected type and
a key name without type specifier.
:param str key_name: A key name containing type postfix.
:rtype: tuple[type|None, str]
:returns: Type definition and cleaned key name. | f8812:m7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.