content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def calc_default_colors(p_index):
"""List of default colors, lines, and markers to use if user does not
specify them in the input yaml file.
Parameters
----------
p_index : integer
Number of pairs in analysis class
Returns
-------
list
List of dictionaries cont... | febc6ce222f57dec8192379855f404efdfb24c7e | 483,673 |
def relationship_types() -> str:
"""
Returns a statement to get all the relationship types in the database.
Returns
-------
out: str
Neo4j statement
"""
return 'CALL db.relationshipTypes()' | cebfff5f89e7673f5227ec1a5bf39105d6d2ef0d | 345,503 |
def get_tuplets(gn):
"""Return the (part of) tuplets on top of a general note.
The tuplets are expressed as a list of strings "start", "continue" and "stop.
Args:
gn (GeneralNote): the music21 general note (e.g. note, rest or chord).
Returns:
list: the list of tuplets.
"""
tup... | 21eb1a99abadac746ea3b7363d23b8e920e1b340 | 422,908 |
import math
def ToMercDegrees(y, num_tiles):
"""Calculate latitude of southern border of yth tile in degrees.
LOD is log2(num_tiles)
Args:
y: (float) Position of tile in qt grid moving from south to north.
Non-integer values give latitude within tile.
num_tiles: (integer) Number of tiles in the ... | 76b0859a9b3a60878bf64398a43fe92b70af1303 | 493,466 |
def read_analogies(filename, word2id):
"""
Reads through the analogy question file.
Returns:
questions: a [n, 4] numpy array containing the analogy question's word ids.
questions_skipped: questions skipped due to unknown words.
"""
questions = []
questions_skipped = 0
with open(... | 10ab73c672e8c7614b483a760e3385fd981621a3 | 401,101 |
def map_category_id(category_map):
""" Assign an ID to each category """
category_id = {}
id_category = {}
counter = 0
for category in category_map:
category_id[category['name']] = counter
id_category[counter] = category['name']
counter += 1
return category_id, id_categor... | 9d48427aeb0e8ae2ac53ec02768d3081f641fcb6 | 670,749 |
def compute_cell_extents_grid(bounding_rect=(0.03, 0.03, 0.97, 0.97),
num_rows=2, num_cols=6,
axis_pad=0.01):
"""
Produces array of num_rows*num_cols elements each containing
the rectangular extents of the corresponding cell the grid, whose posit... | b2560857876440164eff4d9bdb1c2e659eb850dd | 340,752 |
def from_json(json_data, key):
""" Helper method to extract values from JSON data.
Return the value of `key` from `json_data`, or None if `json_data`
does not contain `key`.
"""
if key in json_data:
return json_data[key]
return None | a573c780166530781b7fc495e3c786011f484f39 | 478,732 |
def is_msvc(conanfile):
""" Validate if current compiler in setttings is 'Visual Studio' or 'msvc'
:param conanfile: ConanFile instance
:return: True, if the host compiler is related to Visual Studio, otherwise, False.
"""
settings = conanfile.settings
return settings.get_safe("compiler") in ["V... | dfdbc4a62201c915fdc392a3d62bdd3b3c65db74 | 185,096 |
def lat(source):
"""Convert source bytes to a latitude (deg, min) pair.
Latitude: 2543.7024 = DDMM.MMMM
>>> lat(b'2543.7024')
(25, 43.7024)
"""
if len(source) == 0: return None, None
dd= int(source[:2])
mm= float(source[2:])
return int(dd), float(mm) | 631b5421c38556ca0b71bf26f38d50f02edf641a | 229,785 |
def polygon_area(polygon):
"""Calculates the area of an arbitrary polygon."""
area = 0.0
n = len(polygon)
if n > 0:
polygon -= polygon[0]
for j, p1 in enumerate(polygon):
p2 = polygon[(j+1) % n]
area += p1[0] * p2[1] - p2[0] * p1[1]
return 0.5 * area | 2c7f858d5a19edac18f9572d6b469dbd6db67ab4 | 607,437 |
def fmt_cycles(cycles):
"""
Format cycle information into a string.
"""
out_data = []
for entry in cycles:
datav = entry[0] + '-' + str(entry[1])
out_data.append(datav)
return ','.join(out_data) | b6012807f7b50f8f0ff22ae86ef1b7f631ade6bb | 351,753 |
def qs_opt_eq(qs, opt, value):
"""
Returns True if the query string option is equal to value.
"""
for opt_value in qs.get(opt, []):
if opt_value == value:
return True | 68dede185a9b1aa62e32a833db4b395ce6c4b1cd | 643,060 |
def dash_to_underscore(keyword):
"""Change dash '-' to underscore '_' in string
param keyword: string where the replacement has to
be done
return: string. Example one-two changes to one_two
"""
return keyword.replace('-', '_') | 870ffddfe0e16d44a52cc2cd6fd7a2f584239250 | 297,035 |
def kind(event):
"""
Finds the type of an event
:param event: the event
:return: the type of the event
"""
return event.type | 68f0170eac9fc06f954542769dcd0d4ef974e725 | 699,054 |
def get_conversion_rate(df, total, conversions):
"""Return the conversion rate of column.
Args:
:param df: Pandas DataFrame.
:param total: Column containing the total value.
:param conversions: Column containing the conversions value.
Returns:
Conversion rate of conversions... | 3dbfd40669e3fc751a1344e4b9d6c467f742e35b | 102,619 |
import json
def load_json(config_path):
"""Load json file content
Args:
config_path (str): Path to json file.
Returns:
dict: config dictionary.
"""
with open(config_path, "r") as fhandle:
default_config = json.load(fhandle)
return default_config | d4924cd90857ac5b8cf63e942a6914e595132d30 | 121,669 |
import typing
import ast
def genConstructAstObj(varName: str, className: str) -> typing.Tuple[ast.Name, ast.Name, ast.Assign]:
"""
Returns a tuple of 3 elements
first is `className` AST node
second is `varName` AST node
third is `varName = className()`"""
clsNameAST = ast.Name(id=className, ctx=ast.Load())
ret... | 773054faa998d597e88118004473cd4fd33b3609 | 352,836 |
import re
def sub_args(args, args_regex, sub):
"""Substitute all instances of args_regex in args.
Works if args is a str, list, tuple, or dict. All values replaced with
re.sub. If args is dict, only the values, not the keys, are replaced.
:args: str, list, tuple, or dict
:args_regex: r'' e... | 9d72de0266ac8bfe3a4e3dd5ffa17f761938ad29 | 517,306 |
def create_instance_template(properties, name_prefix):
""" Creates an instance template resource. """
name = name_prefix + '-it'
instance_template = {
'type': 'instance_template.py',
'name': name,
'properties': properties
}
self_link = '$(ref.{}.selfLink)'.format(name)
... | 28a1f6403a23565b53ff08f94ee3f13875645c9b | 276,118 |
def get_members(connection, id, include_access=False, offset=0, limit=-1, error_msg=None):
"""Get member information for a specific user group.
Args:
connection: MicroStrategy REST API connection object
id (string): ID of user group containing your required privileges
include_access (bo... | 1c87036232fafb54cf8d0a3bfe440e2c4f4b5e22 | 342,250 |
def accuracy(list1, list2):
"""
Computes the element-wise similarity between lists list1 and list2.
INPUTS:
- list1 [list]: list of arbitrary values
- list2 [list]: list of arbitrary values
RETURNS:
- n_correct [int]: total num. of elementwise matches
- n_total [int]: total num. elemen... | 319e0f9baec2e5dac3fb62df0388b6d136c1fa41 | 474,439 |
def bundle_tweets(tweets):
""" Bundles all the text in the tweets into a single string """
result = ''
for tweet in tweets:
result += tweet['text']
return result | 8256439f8f0dab2cd9429bc203785c4df8d88f5a | 193,637 |
def extract_hashtags(text, tags_to_append=[]):
"""Extracts distinct sorted hashtag collection from a string, complemented with tags_to_append items."""
return sorted(set([item.strip("#.,-\"\'&*^!") for item in text.split()
if (item.startswith("#") and len(item) < 256)] + tags_to_append)) | 560f3d77a8e424382874e626333f77681f39674d | 488,789 |
def score_programs(adata_here,program_name='bulk.guide.program',
pref=None,copy=False):
"""Get program score for each cell, by averaging program genes
"""
if copy: adata_here = adata_here.copy()
if pref is None:
pref=program_name
programs=list(set(adata_here.var... | d023b37f5ad375a6a969ad1a4e7058044c3c97f1 | 305,389 |
def get_anntypes(batch):
"""Get anntypes from annotation
"""
return [ann["anntype"] for ann in batch.annotation] | 3584c7efb06c266df54cf33963a8078f45974653 | 304,247 |
def filter_subjects_by_coverage(args):
"""Check whether the subject passes the coverage filter."""
subject, cov, SD_MEAN_CUTOFF, STRIM_5, STRIM_3 = args
# Trim the ends
if cov.shape[0] >= STRIM_5 + STRIM_3 + 10:
cov = cov[STRIM_5: -STRIM_3]
passes_filter = cov.mean() > 0 and cov.std() / c... | 450cb5cdf496a58f0a97d111997c4b57d75038f2 | 195,456 |
def definite_crop(img, bbox):
"""crop an image.
Args:
img: `ndarray`, input image
bbox: list, with crop co-ordinates and width and height
e.g.: [x, y, width, height]
Returns:
returns cropped image
"""
img = img[:, bbox[0]:bbox[2], bbox[1]:bbox[3]]
return img | bdfbaf42022aa06a79c2f2b0fa1f3c0d0ea711d8 | 141,182 |
def classify_by_composition(structures):
"""
Classify the different IStructures by composition.
:param structures: List of structures
:return: Dictionary of composition strings with a List of the corresponding
IStructures.
"""
comp_dic = {}
for structure in structures:
if comp_di... | d7df6a6d678bec641e3007328bbc7d1f9ca8f323 | 574,442 |
def get_median(numbers: list) -> int:
"""
Get the median from a list of numbers.
:param numbers: The list containing the numbers.
:return: The median.
"""
numbers.sort()
return numbers[len(numbers) // 2] | dbdf0f0257865fe400cb6f8481a2761cec2202ac | 389,384 |
def _add_thumb(s):
"""
Modifies a string (filename, URL) containing an image filename, to insert
'.thumb.jpg' at the end.
"""
return s + ".thumb.jpg" | 220bd067a7c443853ccdadc553ff6e73eaedaa32 | 391,513 |
import cmath # Can return complex numbers from square roots
def quad_roots(a=1.0, b=2.0, c=0.0):
"""Returns the roots of a quadratic equation: ax^2 + bx + c = 0.
INPUTS
=======
a: float, optional, default value is 1
Coefficient of quadratic term
b: float, optional, default value is 2
... | 665e79754a37ffca1f7c9396e4b3f0186f80022a | 110,041 |
def parse_bitcoin_conf(fd):
"""Returns dict from bitcoin.conf-like configuration file from open fd"""
conf = {}
for line in fd:
line = line.strip()
if not line.startswith('#') and '=' in line:
key, value = line.split('=', 1)
conf[key] = value
return conf | 33ac9d9561c7effeb3e499431fbb708703c1bd00 | 528,285 |
def extract_ids(objects_or_ids):
"""Return a list of ids given either objects with ids or a list of ids."""
try:
ids = [obj.id for obj in objects_or_ids]
except:
ids = objects_or_ids
return ids | 3a70f1f29cf2538d06439254daeff20f1982c85b | 481,493 |
def is_set(cards):
""" Return True if all cards all unique, False otherwise.
"""
return len(set(cards)) == len(cards) | faa2585b108d8b970cb01f2bc38b0757bdfd1079 | 568,692 |
def forecast_error(y, y_predicted):
"""Calculate the forecast error in a regression model.
Parameters
----------
y : array-like of shape = number_of_outputs
Represent the target values.
y_predicted : array-like of shape = number_of_outputs
Target values predicted by the model.
... | 4aede163ae2b1affbc533c9ef054ba789c8c53f0 | 629,643 |
import time
def retry(func, exc=Exception, tries=3, delay=1):
"""
Call ``func()`` up to ``tries`` times, exiting only if the function
returns without an exception. If the function raises an exception on
the final try that exception is raised.
If given, ``exc`` can be either an `Exception` or a t... | 5384afd77840b77b2cb278502d8fc64890af6be7 | 22,227 |
from typing import Dict
from typing import Any
def source_startswith(cell: Dict[str, Any], key: str) -> bool:
"""Return True if cell source start with the key."""
source = cell.get("source", [])
return len(source) > 0 and source[0].startswith(key) | a3dab1e72488a5075832432f36c6fc10d9808a7f | 29,455 |
import ast
from typing import List
from typing import Tuple
def get_scr119(node: ast.ClassDef) -> List[Tuple[int, int, str]]:
"""
Get a list of all classes that should be dataclasses"
ClassDef(
name='Person',
bases=[],
keywords=[],
body=[
... | eef10160a580c4b09451e69dd3054499e1d6ab91 | 656,690 |
import hashlib
def md5(string):
"""Computes and returns an md5 digest of the supplied string
Args:
string: string to digest
Returns:
digest value
"""
return hashlib.md5(string.encode('UTF-8')).hexdigest() | c8204de8c173a4277cc4ea3218f7fd9a518a7348 | 260,929 |
def shuffle_data(data_df):
"""
Performs data shuffling.
"""
return data_df.sample(frac=1).reset_index(drop=True) | 02b512b8198cb3ee4d294f4d67c64f5c57c74306 | 404,822 |
def remove_newlines(text):
# type: (str) -> str
"""
Remove newlines.
The `name` field serves as a displayable title. We remove newlines and leading and trailing
whitespace. We also collapse consecutive spaces to single spaces.
:param text: Text for newline removal
:return: Single line of t... | 06a06d2756099fc45ffc1345bf0bef44cffa9f78 | 658,426 |
def merge_list_dictionaries(*dictionaries):
"""Merges dictionary list values from given dictionaries"""
for addendum in dictionaries[1:]:
for key in addendum:
if key in dictionaries[0]:
dictionaries[0][key] += addendum[key]
else:
dictionaries[0][ke... | 91b75c69f3281b3759193949537a03617630b88d | 432,016 |
import torch
def rankdata_pt(b, tie_method='ordinal', dim=0):
"""
pytorch equivalent of scipy.stats.rankdata, GPU compatible.
:param b: torch.Tensor
The 1-D or 2-D tensor of values to be ranked. The tensor is first flattened
if tie_method is not 'ordinal'.
:param tie_method: s... | 88bd901c945d6ca9b3d2e785c6b0ea627116a03f | 689,557 |
import hashlib
def calculate_hashes_from_pre_hashes(prehash_string_list, hashalg="sha256"):
"""Hash all strings in the list with the given algorithm. Returned in the appropriate NI format.
"""
hashValueList = []
for pre_hash_string in prehash_string_list:
if hashalg == 'sha256':
ha... | 68ee3bf1ee7ccae3ce6d6f5ce4701b1136f55e8d | 314,593 |
def truncate(source, max_len: int, el: str = "...", align: str = "<") -> str:
"""Return a truncated string.
:param source: The string to truncate.
:param max_len: The total length of the string to be returned.
:param el: The ellipsis characters to append to the end of the string if it exceeds max_len.
... | fae74fa46f1e3aaf06c9b2d7cf4be6f31fce2596 | 686,015 |
def translate_tokens(tokens, d):
""" Produce set of translated tokens, returns number of tokens that
were translated. All possible translations of a token are added. """
n_translated = 0
translated = set()
for w in tokens:
if w not in d:
continue
translated.update(d[w])
... | 79fa07b82c9aa6c180c92840f8cf91bdca3422cd | 160,239 |
from math import fabs
from datetime import datetime
def pretty_date(d):
"""
Format the time delta between d and now human-friendly. E.g. 'in 2 hours', '20 seconds ago'
:param d:
:return:
"""
now = datetime.now()
diff = now - d
total_seconds = diff.seconds + diff.days * 24 * 60 * 60
... | 153bf459c55d2d69c8d9638be1f91f66adfcac47 | 357,022 |
def friends(graph, user):
"""Returns a set of the friends of the given user, in the given graph"""
return set(graph.neighbors(user)) | 125c3cc21be4cc29f9ff6f0ff0bb60b35a1074ba | 7,710 |
import hashlib
def get_hash(data):
"""
Get a checksum for the input data
"""
md5 = hashlib.md5()
md5.update(data)
return md5.hexdigest() | 9b19f26528bcec8119b9886300634719cf74f059 | 415,524 |
from typing import List
def accuracy_score(y_true: List, y_pred: List) -> float:
"""
Compute accuracy score
Parameters
----------
y_true : list
True labels
y_pred : list
Predicted labels
Returns
-------
float
Accuracy score
Examples
--------
>... | 552cc0fab91b8dd62b08e512fb2d9f232f5b3606 | 694,476 |
def to_list(*args: dict) -> dict:
"""Convert a list of dicts to a dict of lists."""
if len(args) == 0:
raise ValueError("Input can't be empty.")
keys = [set(d.keys()) for d in args]
ref = keys[0]
for test in keys[1:]:
if ref != test:
raise ValueError("All input dictionari... | fa88a8c60b7255528dea61c193556e532d00c476 | 545,081 |
import re
def _createNameReplacement(search, replace):
"""
Return a tuple containing a regex and replacement string.
Regexes replace prefixes, suffixes, or middles, as long as
the search is separated with '_' from adjacent characters.
"""
regex = re.compile('(?<![^_]){0}(?=(_|$))'.format(searc... | 7abfbf06683d887fb2f3b5d7f15bb77cfdd259ff | 225,080 |
def message_warning(msg, *a, **kwargs):
"""Ignore everything except the message."""
return str(msg) + '\n' | a39440007b6e07c4810e73a9c16edd06316962e4 | 638,035 |
def enl_seq(seq_of_seq, otherentries):
""" Returns a sequence of sequences, with each element consisting of an
element from otherentries appended to a sequence from seq_of_seq.
Note: this is used for building chords.
"""
ret = [];
for i in seq_of_seq:
for j in otherentries:
... | 9c1220c9fa91d70246c808c6574b2ac4b29f34b5 | 264,797 |
def _get_statusline(params):
"""Generate a mock statusline like py.test would output."""
info_elements = []
if 'failed' in params:
info_elements.append('{failed} failed')
if 'passed' in params:
info_elements.append('{passed} passed')
if 'error' in params:
info_elements.append... | fafc090c2da72487453ae92e19cdd26808f1b6dc | 485,025 |
def cshock_dissipation_time(shock_vel,initial_dens):
"""A simple function used to calculate the dissipation time of a C-type shock.
Use to obtain a useful timescale for your C-shock model runs. Velocity of
ions and neutrals equalizes at dissipation time and full cooling takes a few dissipation times.
A... | b97a184a60ccc1587eee40bad6325131a1348c98 | 90,432 |
def convert_to_aws_ecr_compatible_format(string):
"""Make string compatible with AWS ECR repository naming
Arguments:
string {string} -- Desired ECR repository name
Returns:
string -- Valid ECR repository name
"""
return string.replace(" ", "-").lower() | badde81dc7a6b6e53f52e60733b6623370a8f9e7 | 487,164 |
def rotate_left(a):
"""
Returns the result of rotating the matrix a 90 degrees left.
"""
return list(zip(*[reversed(r) for r in a])) | 6453b944b770cb6b18d039518bf1d10dff816b08 | 284,972 |
def cols_change_list() -> list:
""" Returns the list of columns that need to be processed."""
cols_s1_change = ['12th_grade', '11th_grade', '10th_grade',
'Indicador de Sucesso', 'pct_stud_in_need_12th_grade',
'pct_profs_on_the_board', 'average_moms', 'average_dads', '... | e797caba670db0e85ff15fafbca553aebe838bc2 | 282,463 |
def _IsSpecified(args, name):
"""Returns true if an arg is defined and specified, false otherwise."""
return hasattr(args, name) and args.IsSpecified(name) | 3730179ad3913d95d9cc4cdbfd168ee92f54aff5 | 67,800 |
import re
def format_imports(text):
"""
Takes a string of text and formats it based on rule 3 (see docs).
"""
# rule to find consective imports
regex4 = r"^import[\s\w]+?(?=from|^\s*$)"
# this subsitution will happen with a function
def subst4(match_obj):
pattern = r"import (\w+)"... | 2b66fded4660396c1b386daa99666250aa5a3f06 | 669,074 |
from typing import List
def double(items: List[str]) -> List[str]:
"""
Returns a new list that is the input list, repeated twice.
"""
return items + items | 9e4b6b9e84a80a9f5cbd512ca820274bb8cad924 | 706,540 |
def cov(df, groupby_columns:list, value_column:str):
"""
Calculates the coefficient of variation for data grouped by specific columns
Args:
df: pandas dataframe
groupby_columns: list of column names to group the data by
value_column: string name of column containing the values for wh... | 881cce82ff323e0295731901bafeaeac5e47c0bc | 81,379 |
import mimetypes
def is_pdf(file_path):
"""
Checks whether the file is a pdf.
"""
type = mimetypes.guess_type(file_path)[0]
return type and type == 'application/pdf' | 5d34f7c1a6e581a882c92d7dc664afc924de8bbe | 445,344 |
def _organize_parameter(parameter):
"""
Convert operation parameter message to its dict format.
Args:
parameter (OperationParameter): Operation parameter message.
Returns:
dict, operation parameter.
"""
parameter_result = dict()
parameter_keys = [
'mapStr',
... | 8cbd7c863bb244e71266a573ba756647d0ba13ea | 708,639 |
def parse_config_option(line, is_global, dt_keys, global_key_types):
"""Parses a single line from the configuration file.
Args:
line: String containing the key=value line from the file.
is_global: Boolean indicating if we should parse global or DT entry
specific option.
dt_k... | 016ca756bdad85524a9ab0c4a8526762db3ef4c7 | 148,258 |
def time2str(t):
"""Takes a value of time as a number of seconds and returns it in the form
"hh:mm:ss".
Parameters
----------
t : int
Time in seconds.
Returns
-------
s : str
Time in the form "hh:mm:ss". Hours omitted if there are none.
"""
hours = t //... | 58d01cc7699c957379d2a6841162664596d07811 | 163,007 |
def _eos(veos):
"""
EOS = DOY for end of seasonn
"""
return veos.time.dt.dayofyear | 1dba9aa2ec775283371e3c6e8c1d8fc1b4b85831 | 473,299 |
import string
def expand_vars(template, **variables):
"""
Expands a configuration template which uses $-style substitutions.
"""
template = string.Template(template)
return template.safe_substitute(**variables) | fd31f64994b51088eccf03fdbd4a81757c6dd6c5 | 545,728 |
def get_resource_and_action(action, pluralized=None):
"""Extract resource and action (write, read) from api operation."""
data = action.split(':', 1)[0].split('_', 1)
resource = pluralized or ("%ss" % data[-1])
return (resource, data[0] != 'get') | 3ba6b9fc8e2b6d246500bb4864e8222b00f79209 | 458,921 |
def get_p7_seq(x):
"""
Return the sequence of P7: TruSeq, Nextera, smallRNA
"""
p7 = {
'truseq': ['AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC', 6, 'ATCTCGTATGCCGTCTTCTGCTTG'],
'nextera': ['CTGTCTCTTATACACATCTCCGAGCCCACGAGAC', 8, 'ATCTCGTATGCCGTCTTCTGCTTG'],
'smallrna': [],
}
retu... | 700cad512b0019f37a66cb33665a8d994ebd63e9 | 605,843 |
import logging
def reconstruct_position(pos, deleted_pos):
"""Computes the prior position of one column in an MSA.
pos: index of current position in an MSA
deleted_positions: list with column indexes that were removed
It returns the position of a column in an MSA that has undergone
deletion of se... | 07cad43b603c83140afaa40a82caeaf75918a019 | 331,309 |
def _get_output_file_idx(build_args):
"""
Get the index of output file from build args
:param build_args: arguments of gcc
:return: index in the build args where output file is.
"""
i = 0
while i < len(build_args):
if build_args[i] == "-o":
return i + 1
i += 1... | 1d8ff0b30525c1074feb88cf2646b910fe7f7db8 | 492,507 |
def frequencies(colorings):
"""
Procedure for computing the frequency of each colour in a given coloring.
:param colorings: The given coloring.
:return: An array of colour frequencies.
"""
maxvalue = -1
frequency = [0] * (len(colorings))
for i in colorings:
maxvalue = max(maxvalu... | f9509e4c6ff253656a5e3d734e3b913c4428ec1c | 668,071 |
def get_duration(s):
"""
Calculate trip duration
"""
pickup = s['tpep_pickup_datetime']
dropoff = s['tpep_dropoff_datetime']
if not all((pickup, dropoff)):
return None
duration_seconds = (dropoff - pickup).seconds
return duration_seconds | b92e09ecf666d338f8b004cfdf8d3b80d6d19e57 | 277,946 |
def getVarTimeRange(dataArray, rangeMin, rangeMax,
timeStrt, timeEnd):
""" This function extracts the radar variable
for a desired range and time interval.
Arguments
---------
dataArray : xarray DataArray of the variable
rangeMin : minimum range in m
... | 3baa45abe77a81786c34ace3e2e8c6ad67dfd6ba | 447,054 |
import configparser
def get_aws_config(path="~/.aws/credentials"):
"""Get the AWS configuration"""
config = configparser.ConfigParser()
config.read(path)
return config | 76426db61b986b0e0c749caa39078a902e68c76a | 445,708 |
import torch
def build_mse_loss(loss_coef, correspondence_keys=None):
"""
Build the mean squared error loss function.
Args:
loss_coef (dict): dictionary containing the weight coefficients
for each property being predicted.
Example: `loss_coef = {'energy': rho, 'force': 1}`... | 003e8ad9315e3b9e8d49ee5a7fedd0229502cffd | 470,438 |
def number_to_string(n, alphabet):
"""
Given an non-negative integer ``n``, convert it to a string composed of
the given ``alphabet`` mapping, where the position of each element in
``alphabet`` is its radix value.
Examples::
>>> number_to_string(12345678, '01')
'1011110001100001010... | 6be6b4e725331dbaa10ded7bdfa6daffd7a967d1 | 315,881 |
import math
def solar_declination(doy):
"""
Calculate the solar declination for a given day of the year
(Allen et al. 1998).
Parameters
----------
doy : int
Julian day of the year (-).
Returns
-------
float
Solar declination (rad).
"""
return 0.409 * math... | db1b6bbf38c69ffbb0b5f5ba47283cdf2cd7a4dd | 627,173 |
def GetGTestOutput(args):
"""Extracts gtest_output from the args. Returns none if not present."""
for arg in args:
if '--gtest_output=' in arg:
return arg.split('=')[1]
return None | d2dfd96c30184209120d656a2c797d66e96bde1b | 481,640 |
def get_table_number_of_rows(cursor, table_name):
"""
Return the number of rows of a table
"""
sql_command = f"SELECT COUNT(*) FROM '{table_name}';"
v = cursor.execute(sql_command).fetchall()
assert len(v) == 1
assert len(v[0]) == 1
return v[0][0] | 310d64d0b25c8729a838a5c5335b80f3a0bb8e6a | 71,219 |
def to_numpy(var):
"""Tensor --> numpy
Parameters:
var (tensor): tensor
Returns:
var (ndarray): ndarray
"""
return var.data.numpy() | 6e5ae6ad239306cbd1d0f8f04e339bd08398e693 | 405,465 |
def area_triangle(b, h):
"""
Returns the area of a triangle given its base
and its height
"""
area = b * h / 2
return area | a9bdd783f1a43fe73bcd7338120ffaef4863fac6 | 627,500 |
def int_bytes_to_programmatic_units(byte_value):
"""Convert a byte count into OVF-style bytes + multiplier.
Inverse operation of :func:`programmatic_bytes_to_int`
Args:
byte_value (int): Number of bytes
Returns:
tuple: ``(base_value, programmatic_units)``
Examples:
::
... | b88bf07a3d60427ffbc964384aa2fdb38fa20694 | 289,602 |
def polyfill_integers(generator, low, high=None, size=None, dtype="int32",
endpoint=False):
"""Sample integers from a generator in different numpy versions.
Parameters
----------
generator : numpy.random.Generator or numpy.random.RandomState
The generator to sample from. I... | b4061e8ec7cb9927bbe4fcce1c847aecdc10052b | 9,544 |
def get_appropriated_part_size(file_size):
"""
Gets the appropriated part size when uploading or downloading files,
given an initial file size.
"""
if file_size <= 104857600: # 100MB
return 128
if file_size <= 786432000: # 750MB
return 256
if file_size <= 2097152000: # 200... | ac1f9aa0dbfd63984879df49abeeca1f0af6ead8 | 340,345 |
import click
def success_style(success_string: str) -> str:
"""
Styling function to emphasise bullet names.
:param success_string: The string to style
:type success_string: str
:return: Styled success string
:rtype: str
"""
return click.style(success_string, fg="green") | ce658ec661193c4381c458f84e2e6ee2f300d281 | 300,131 |
from typing import Union
from typing import List
from typing import Tuple
import torch
def get_qubit_indices(
index: Union[int, List[int], Tuple[int, ...], torch.Tensor],
state_tensor: torch.Tensor,
num_qubits: int
):
"""Convert qubit indices 0, ..., n-1 to correct PyTorch tensor indices.
... | 0f78ed23417d447450622feb370eeb399650e870 | 500,875 |
import six
def pad(data, bs=16):
"""PKCS#7 Padding. Takes a bytestring data and an optional blocksize 'bs'"""
length = bs - (len(data) % bs)
data += six.int2byte(length) * length
return data | e5a1c422f4021da2e7afc1af6483c97e99e6b6a6 | 79,219 |
from typing import Optional
def validate_discharge_efficiency(discharge_efficiency: Optional[float]) -> Optional[float]:
"""
Validates the discharge efficiency of an object.
Discharge efficiency is always optional.
:param discharge_efficiency: The discharge efficiency of the object.
:return: The ... | 689e951673954f2112112d2d6e1c358f9ef7678b | 615,852 |
def read_network_from_file(file_name, delimeter=','):
""" Read from a file and build a network
file_name: file to read from
delimeter: delimeter that separates fields
"""
cities = list()
distances = dict()
f = open(file_name, 'r')
lines = f.readlines()
for line in lines:
fie... | c2f3562c7cf314a45a4449f0e23ddab0f1bcaec9 | 183,810 |
from pathlib import Path
def get_last_file(base_dir, pattern):
"""Return the last file in a folder that match the given pattern.
Parameters
----------
base_dir: str or Path
Base directory to search for a matching file.
pattern: str
Pattern used in glob to find files.
Returns
... | a1f0f9fdea03f8271c2e0320496c9d11a976c4a2 | 253,509 |
from typing import Callable
def runge_kutta_method_o4(f: Callable[[float, float], float], y0: float, x: list[float], h: float, precission: int = 5) -> float:
"""Finds the value of y(x) for some ODE using Runge Kutta method (order 4).
Params
------
f: Callable[[float, float], float]
function r... | 5f8f19bdf6e565b63d350888bd7b08f36f7d4ee7 | 635,996 |
def get_file_names_on_anaconda_channel(username, anaconda_cli,
channel='main'):
"""Get the names of **all** the files on anaconda.org/username
Parameters
----------
username : str
anaconda_cli : return value from binstar_client.utils.get_binstar()
channel ... | 4f547249fabf7a199976a6207820df46833588dd | 612,742 |
def index_of(array, value, from_index=0):
"""Gets the index at which the first occurrence of value is found.
Args:
array (list): List to search.
value (mixed): Value to search for.
from_index (int, optional): Index to search from.
Returns:
int: Index of found item or ``-1``... | 57b7bfee4f74bd448b1fb95e3a30a1df85362345 | 217,869 |
def knot_insertion_alpha(u, knotvector, span, idx, leg):
""" Computes :math:`\\alpha` coefficient for knot insertion algorithm.
:param u: knot
:type u: float
:param knotvector: knot vector
:type knotvector: tuple
:param span: knot span
:type span: int
:param idx: index value (degree-dep... | 51e3e61eae5e562c47b67904873e4ffe327bb842 | 674,601 |
def get_forecast_metadata_variables(ds):
"""
Returns a list of variables that represent forecast reference time
metadata.
:param netCDF4.Dataset ds: An open netCDF4 Dataset.
:rtype: list
"""
forecast_metadata_standard_names = {
"forecast_period",
"forecast_reference_time",
... | 83b8fe0eb785c1a3129ec19df680ce135cd3fa82 | 7,062 |
def max_factor(num):
"""Find the maximum prime factor."""
factor = 2
while factor * factor <= num:
while num % factor == 0:
num /= factor
factor += 1
if (num > 1):
return num
return factor | 3b29d27d77454c1a52f483936b6a6bd94b98e306 | 386,640 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.