content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def mk_id(identifier):
"""Make an id from a string such as 'C0326'."""
return identifier | de196c51e566a6c7eb2277952d513a50075a5997 | 569,078 |
def getEndJoints(jnt):
"""
Recurse through children and return all joints that have no joint children.
Args:
jnt (PyNode): A joint node
"""
result = []
children = jnt.listRelatives(children=True, typ='joint')
if not children:
result.append(jnt)
else:
for child in... | 7d24cdef7b9d8b4e31eda2a83ec52c022a91774e | 101,717 |
def map_diameter(c: int) -> float:
""" Compute the diameter """
return 1 / 3 * (c + 1) * (c - 1) | fb3f19478901f40b52af11c6d200f125d3716112 | 687,700 |
def sentence_error(source, target):
"""
Evaluate whether the target is identical to the source.
Args:
source (str): Source string.
target (str): Target string.
Returns:
int: 0 if the target is equal to the source, 1 otherweise.
"""
return 0 if target == source else 1 | 02cfc350763b176d0296007ef44321674ef65d27 | 53,351 |
def middle(seq):
"""Return middle item of a sequence, or the first of two middle items."""
return seq[(len(seq) - 1) // 2] | 736b6aed9a8e03f0581f2d7892c5f370f0886285 | 19,268 |
import re
def exclude_filter(excl_filter, paths):
"""
Matches a set of paths against an exclude filter, removing those that don't match
param: excl_filter: The filter to match.
param: paths: The set of paths to match against the filter.
returns: A set of paths which do not match the filter.
"... | 4332ab8c75e71592ace91a614f73ce260a3895a0 | 40,721 |
def convert_range_to_list(node_range):
"""
Convert a number range to a list.
Example input: Input can be like one of the format: "1-3", "1-2,6", "2, 8"
Example output: [1, 2, 3]
"""
return sum(
(
(list(range(*[int(j) + k for k, j in enumerate(i.split("-"))])) if "-" in i els... | 11942990fdc709d3f53c2b045feb799c9f56d5a4 | 201,396 |
def read_info_file(info_file, include_labels=False):
"""
It reads an info txt file and returns the list of image paths and, eventually, the list of label paths.
The info file has an entry in each line in the form: IMAGE_PATH LABEL_PATH.
:param info_file: the path to the info txt file .
:param includ... | 32e24530cfc3ed4a794e773e5d89054ab0accf66 | 506,897 |
import unicodedata
def strip_accents(eval_ctx, value):
"""Strip non ASCII characters and convert them to ASCII."""
return unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode("utf-8") | c3287d533d8e66adfe892f9d7f07311331257b05 | 470,435 |
import re
def load_tolerances(fname):
""" Load a dictionary with custom RMS limits.
Dict keys are file (base)names, values are RMS limits to compare.
"""
regexp = r'(?P<name>\w+\.png)\s+(?P<tol>[0-9\.]+)'
dct = {}
with open(fname, 'r') as f:
for line in f:
... | 60af52ec49cadfdb5d0f23b6fa5618e7cc64b4c2 | 27,897 |
def tensor_image_converter(tensor):
"""
Converts PyTorch Tensor to Numpy Array (Image)
"""
tensor = tensor.squeeze()
if len(tensor.shape) > 2:
tensor = tensor.permute(1, 2, 0)
img = tensor.detach().cpu().numpy()
return img | cae23789e08c2a6266c1307c3ae2c490da08b0e6 | 399,913 |
def calculate_number_of_conditions(conditions_length, max_conditions):
"""
Every condition can hold up to max_conditions, which (as of writing this) is 10.
Every time a condition is created, (max_conditions) are used and 1 new one is added to the conditions list.
This means that there is a net decrease ... | 547bbdf43256d1a0b8514bb0d3fd8cb93f29c1dd | 112,805 |
def get_integer_selection(description, min_value, max_value):
"""
Asks the user to select an integer between min_value and max_value
"""
print(description)
# Initially there is no valid selection
valid_selection = False
selection = min_value - 1 # invalid selection
# Continue to prompt ... | f0f5bbea39f72106c0d848e14dc322f5ac97957d | 557,444 |
def expand_box(box, img_shape, scale=None, padding=None):
"""Expand roi box
Parameters
----------
box : list
[x, y, w, h] order.
img_shape : list
[width, height]
scale : float, optional
Expand roi by scale, by default None
padding : int, optional
Expand roi b... | 3fd9c97b8baa70a89b898d3e9d14e8c930d0045e | 17,029 |
def factorial2(num):
"""
return factorial without recursion
:param num: the number
:return: factorial
"""
product = 1
for n in range(2, num + 1):
product *= n
return product | c4dd33751fc14c0238fefa395e804837db0588e6 | 508,454 |
def task_accuracy_metrics(reward_list):
""" Accuracy as percentage of examples that received rewards """
accuracy = sum(reward_list)*100/float(len(reward_list))
#print("Total Reward: %s, Accuracy: %s %%"%(sum(reward_list),accuracy))
return accuracy | 43b3cca9f9fa4c723117df1f2bca332790232e61 | 516,195 |
import socket
import fcntl
import struct
def get_ip_address(network_iface):
"""
Returns the ip address of a specific network interface. Returns None if
it could not be determined.
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
... | 10f4e88e158fc8e260fbf4adf21182dc0e419480 | 165,168 |
import re
def match_scene_name(scene_name):
"""
Args:
scene_name (str): FloorPlanXX-<random_seed(int) | default>
Returns a tuple of scene name and seed (or 'default') if we
can match the format."""
m = re.match("^FloorPlan[0-9]+-([0-9]+|default)$", scene_name)
if m is not None:
... | d8d2de675e102984007e735992fb9c0696d4845c | 20,023 |
def compile_vprint_function(verbose):
"""Compile a verbose print function
Args:
verbose (bool): is verbose or not
Returns:
[msg, *args]->None: a vprint function
"""
if verbose:
return lambda msg, *args: print(msg.format(*args))
return lambda *_: None | d2fe3b93b09011f63df54eb162e270303c328cb9 | 695,513 |
def find_elements(node, xpath, allow_zero=True, allow_multiple=True):
"""Attempt to find child elements in a node by xpath. Raise exceptions if conditions are violated. Return a
(possibly empty) list of elements."""
all_elements = node.findall(xpath)
if (len(all_elements) == 0 and not allow_zero) or (le... | 2255fcd63f35837c647dd6dca81ab648d59addc8 | 703,996 |
def create_parameter(model, parameter_id, value, constant=True, units="dimensionless"):
"""
Creates new parameter for libsbml.Model. It is not necessary to assign the
function to a value. The parameter is automatically added to the input model
outside of the function.
Parameters
----------
... | fa7206e53941aa8bfe81f5f1ee1cd764c3c12668 | 675,418 |
def file_line(mark):
"""Format a mark as <file>:<line> information."""
result = mark.name
if mark.line:
result += ':' + str(mark.line)
return result | d4f466c5f627df42de19df39b49bc63e82f7769f | 253,410 |
def slqs_sub(x_entr, y_entr):
"""
Computes SLQS Sub score from two entropy values.
:param x_entr: entropy value of x
:param y_entr: entropy value of y
:return: SLQS Sub score
"""
score = y_entr - x_entr
return score | 2afd4e805c0fbd295bfb63b588634244cf27deef | 462,387 |
def get_wind_direction(degree):
"""Convert wind degree to direction."""
DEGREES = [-11.25, 11.25, 33.75, 56.25,
78.75, 101.25, 123.75, 146.25,
168.75, 191.25, 213.75, 236.25,
258.75, 281.25, 303.75, 326.25, 348.75]
DIRECTIONS = ['N', 'NNE', 'NE', 'ENE',
... | 110a08df997a7895becd7db49a38ca0f3b6655e7 | 557,528 |
def first(seq):
"""Return first item from a sequence."""
if isinstance(seq, (list, tuple)):
return seq[0]
return next(seq) | 50e228586d17709c5ae35cff321fa7fb6b8efb03 | 298,806 |
import torch
def complex_mult_torch(X, Y):
""" Computes the complex multiplication in Pytorch when the tensor last dimension is 2: 0 is the real component and 1 the imaginary one"""
assert X.shape[-1] == 2 and Y.shape[-1] == 2, 'Last dimension must be 2'
return torch.stack(
(X[..., 0] * Y[..., 0] ... | 2ede27dcc061d25b15f818544ae5b6e55196dad7 | 562,661 |
from typing import Optional
import traceback
def format_exc(exc: Optional[int] = None) -> str:
"""Format a traceback."""
return traceback.format_exc(exc) | 3d3df2adaca14828f393a4cb0e6a5bfcbae158e8 | 627,310 |
import json
def fetch_records(board_file):
"""Import records from servo_ina file.
board files are json files, and have a list of tuples with
the INA data.
(name, rs, swetberry_num, net_name, channel)
Args:
board_file: board file
Returns:
list of tuples as described above.
""... | 9c3fd8a6b3016faca72de5df96fafe5f76fb9810 | 435,534 |
def gram_size(term):
"""
Convenience func for getting n-gram length.
"""
return len(term.split(' ')) | 8684294afafcb68237e268e05229235bfee00e4c | 192,079 |
def find_swift_version_copt_value(copts):
"""Returns the value of the `-swift-version` argument, if found.
Args:
copts: The list of copts to be scanned.
Returns:
The value of the `-swift-version` argument, or None if it was not found in
the copt list.
"""
# Note that the argument can occur multi... | 53d2ae0aa4f0e20373df441f1dc6c326525141f2 | 247,008 |
import uuid
def url_to_uuid5(url):
"""Generate a UUID5 for a given URL."""
return str(uuid.uuid5(uuid.NAMESPACE_URL, url.encode('utf-8'))) | 688aaac5d7ad564eabb0de2adc23cf94c820bdc9 | 464,919 |
from typing import List
import torch
def average_checkpoints(
checkpoint_paths: List[str],
):
"""
Average a list of checkpoints' state_dicts.
Parameters
----------
checkpoint_paths
A list of model checkpoint paths.
Returns
-------
The averaged state_dict.
"""
... | 06dee6e4cc1a26e09fddb781855427a94a3d5cbf | 395,261 |
def bracket(v, low=0, high=255):
"""Simply brackets a value between 0 and 255."""
return max(low, min(high, v)) | e921d8a9fc792bb4dc6eebad32993b220bdb4d51 | 364,105 |
def latexify(ticklabels):
"""Manually set LaTeX format for tick labels."""
return [r"$" + str(label) + "$" for label in ticklabels] | 83b310381b4363ac15e3802112aea2d5b6201f85 | 395,866 |
from typing import OrderedDict
def load_vocab(fin):
"""
Load vocabulary from vocab file created by word2vec with
``-save-vocab <file>`` option.
Args:
fin (File): File-like object to read from.
encoding (bytes): Encoding of the input file as defined in ``codecs``
module of ... | 864f1de89e9dfe0a6b0ec0215e1bafeb5ed3d634 | 206,109 |
def block_search(dict_or_list, block_name, default=None):
"""Find block_name in dict_or_list where block_name in the form 'keya.keyb.keyc'"""
current = dict_or_list
if block_name is None or block_name == "" or block_name == ".":
return current
for part in block_name.split("."):
if isinst... | bf0f5188ac092ad9b0850d4c67ad8103322910b6 | 463,927 |
import re
def clean_kql_query(query_string: str) -> str:
"""
Return kql query stripped of comments and newline characters.
Parameters
----------
query_string : str
Input query
Returns
-------
str
Cleaned query.
"""
remove_comments = re.sub(r"(//[^\"\'\n]+)", ... | 3be00366335e8f82d60935273ae128c76e4bded2 | 260,515 |
def compute_score_of(winner: list) -> int:
"""Compute score of winning deck."""
return sum((idx + 1) * card for idx, card in enumerate(winner[::-1])) | 36c238bf5a3aeed431adfb586b4cf089f668148a | 331,859 |
def fmt_enum_repr(fmt: str, enum_type, enum_val):
"""Append repr of a given enum type to a format string.
Arguments:
fmt - Format string
enum_type - Enum Type to construct.
enum_val - Enum value.
Returns:
formatted string
"""
return fmt.format(repr(enum_type(enum_va... | eba614c155e7609d41ac706a27594c70fb840115 | 76,910 |
def title_contains(title):
""" An expectation for checking that the title contains a case-sensitive
substring. title is the fragment of title expected
returns True when the title matches, False otherwise
"""
def _predicate(driver):
return title in driver.title
return _predicate | e1372da4bd9ce34ccc02fbd15aa6b76695cb5cd2 | 356,827 |
import math
def _brevity_penalty(candidate, references):
"""Calculate brevity penalty.
As the modified n-gram precision still has the problem from the short
length sentence, brevity penalty is used to modify the overall BLEU
score according to length.
An example from the paper. There are three r... | b56c53730b2a90581a89f8cffa51f34c5d643984 | 680,563 |
import torch
def one_hot(y, K, smooth_eps = 0): # pylint: disable=invalid-name
"""One-hot encodes a tensor with optional label smoothing.
Args:
y: A tensor containing the ground-truth labels of shape (N,), i.e. one label
for each element in the batch.
K: The number of classes.
smooth_eps: Labe... | ee47f9c778d875834c49c098ded4936edb104887 | 13,113 |
def area_from_district(district_name):
"""Strip a trailing " District" from a string."""
return district_name.strip().split(" District")[0] | 4cb6700f9592a914bb75da88e538f3bd22b9528c | 271,872 |
import typing
def find(predicate: typing.Callable,
iterable: typing.Iterable):
"""
Finds the first element in an iterable matching a predicate.
:param predicate: predicate that returns true for any match.
:param iterable: iterable to iterate over.
:return: the first match; None if there ... | 14fc2b6b9ca2af1265f12b918c43bf436282d6b2 | 266,647 |
def _make_result_path(result):
"""Create a path for the result, using the fspath and test id"""
result_path = ""
if result.get("metadata") and result["metadata"].get("fspath"):
fspath = result["metadata"]["fspath"]
if fspath.startswith("../"):
fspath = fspath[3:]
if fspat... | 825f506b4923245cf65197479e4c2f6cc8546f71 | 131,966 |
def binary_string_to_num(bvalue):
""" convert from binary string (as list of chars)to int """
return int("".join(bvalue), 2) | d560ab52896ebdf550403a15be39a5139703e48f | 523,084 |
import math
def truncate_middle(content, max_length, middle="..."):
"""
Truncates the middle part of the string if the total length if too long.
For example:
truncate_middle('testabcdecho', 8) == 'tes...ho'
:param content: The string that must be truncated.
:type: str
:param max_length: ... | 16f9ec8e6210ab2820a78328e2f21ec6d636b787 | 664,347 |
def iqr(series):
"""
Extract inter-quantile range
(25%-75%)
Input
---
series : pandas series
Returns
---
inter-quantile range
(25-75%)
"""
Q1 = series.quantile(0.25)
Q3 = series.quantile(0.75)
IQR = Q3 - Q1
return IQR | 1a5f8348dcece3a9b297a34f95f092469c2fda4f | 426,462 |
def triple_split(triple):
"""Split target triple into parts.
"""
arch, vendor, os = triple.split('-', 2)
if '-' in os:
os, env = os.split('-', 1)
else:
env = ''
return arch, vendor, os, env | bdfbe48fdd32fc7a5a52cf3750d4d83e37549d32 | 98,393 |
def gray_code(N):
""" Generate a Gray code for traversing the N qubit states. """
if N <= 0 or type(N) is not int:
raise ValueError("Input for gray code construction must be a positive integer.")
if N == 1: # Base case
return ["0", "1"]
else:
sub_code = gray_code(N-1)
ret... | 148a10bb355592b7b5913e5791c90b35e2470898 | 538,930 |
def scd_session_cm(pytestconfig) -> bool:
"""True iff SCD auth1 user is authorized for constraint management"""
return pytestconfig.getoption('scd_auth1_cm') | ca5926db377d6b9512f4e34ae296dc2d18a00903 | 529,044 |
def image_index(pathname):
"""
Helper function for submission. Takes the path to an image, e.g.
"./image_folder/15.jpg", and returns the image name, in this example
"15.jpg".
"""
return pathname[pathname.rfind("/")+1:] | ce2c047ee8367cf6457ca9316eb8487314101c28 | 576,714 |
import hashlib
def get_path_from_args(args):
""" Returns a unique hash for an argparse object. """
args_str = str(args)
path = hashlib.md5(args_str.encode()).hexdigest()
return path | e09669d5e09375083af25c03ca250776352295b5 | 456,842 |
def sum_digits(s):
"""
assumes s a string
Returns an int that is the sum of all of the digits in s.
If there are no digits in s it raises a ValueError exception.
"""
sum_of_digits = 0
count = 0
for item in s:
if item in list('0123456789'):
sum_of_digits += int(item)
... | 40fb5868eccf3d6840177273ce2084da5238d3cd | 493,503 |
def performanceCalculator(count, avg, std, maxv, countref, avgref, stdref, maxvref):
"""
===========================================================================
Performance calculator function
===========================================================================
Calculate performance bas... | 92f98baa720f19a1e6f5dbcdb610b38036c49c6c | 681,655 |
def parse_csv_data(csv_filename) -> list:
"""Reads the csv file provided and formats it into a list of strings
Arguements:
csv_filename {csv} - a file containing covid data including the following parameters:
areaCode,areaName,areaType,date,cumDailyNsoDeathsByDeathDate,
hospitalCases,newCasesBySpeci... | 8e457c9756370959db7a087fa73bac8398bb01c7 | 348,636 |
import re
def dict_from_sdkconfig(path):
"""
Parse the sdkconfig file at 'path', return name:value pairs as a dict
"""
regex = re.compile(r"^([^#=]+)=(.+)$")
result = {}
with open(path) as f:
for line in f:
m = regex.match(line)
if m:
result[m.gr... | ac52b59f2179033ee265d3ea0b8dbdaabfc7740e | 619,199 |
def compute_poi_email_ratio(poi_messages, all_messages):
""" FEATURE
given a number messages to/from POI (numerator)
and number of all messages to/from a person (denominator),
return the ratio of messages to/from that person
that are from/to a POI
"""
ratio = 0.
if type(... | 982408618f8b56bffabf0030e31fe2e9dd37c6b0 | 515,804 |
import inspect
def get_functions(mod):
"""
Get a list of functions for the given module.
:param mod: The module to inspect for functions.
:type mod: types.ModuleType
:return: The list of functions.
:rtype: list[types.FunctionType]
"""
return [o[0] for o in inspect.getmembers(mod, insp... | 78a7807760086b65aefdc45be7c7c39d95e5ba9d | 101,316 |
def get_kwargs(accident_data, field):
"""
Build kwargs from accident data for a specific field.
Default is one pair: value = field_value_as_string
"""
if field == '\xef\xbb\xbfAccident_Index':
return {'acc_index': accident_data[field]}
if field == 'Date':
return {'date': accident... | f509746c61fb5a28f297dfed410609d94f79e128 | 285,580 |
def extract_ip_from_oid(oid):
"""Given a dotted OID string, this extracts an IPv4 address from the end of it (i.e. the last four decimals)"""
return ".".join(oid.split(".")[-4:]) | e34325d518891552ca8f113c742ed4bd2d3a9f5b | 368,573 |
import re
def inject_parameters(file_contents: str, parameters: dict):
"""
Replace placeholders in a file with the provided dictionary
:param file_contents: String containing expected file contents
:param parameters: Dictionary of parameters {placeholder: value}
:return: Parsed/injecte... | 80c9023e57cdf4962cdd940a8de6c732fba637f9 | 548,157 |
import uuid
import requests
def get_dns_records(params):
"""Return dictionary of all DNS records in Dreamhost account."""
url = "https://api.dreamhost.com/" + \
"?key=" + str(params["api_key"]) + \
"&cmd=dns-list_records" + \
"&unique_id=" + str(uuid.uuid4()) + \
"&form... | 5904177877b5daecffe1c6cfe8f76bce367e59e8 | 362,135 |
def get_clipped_freq(records_l, records_r, records_s, minclip=4):
"""
Get the number of reads that are clipped over the breakpoints in a meaningful way. For the left and right
breakpoints, look for clipping in the SV. For the single breakpoint, look for clipping on either side of the read.
:param recor... | e3fe7374db78d4db2303aec2807e9e7d218cbd77 | 617,019 |
def getSyndrome(H, v):
"""
Calculates the syndrome string given a matrix and codeword
:param H:
:param v:
:return:
"""
s = (H*v) % 2
return s.reshape(1, 11) | f3f44ce537f3d740a48b9565cfa3e4fc48067236 | 97,336 |
def remove_empty_str(org_list):
"""Remove empty strings from list."""
return [i for i in org_list if i != ""] | 95fa23a32516bc6bdaa0846d54ca500aeb41a17c | 234,338 |
def escape_eid(eid):
"""Replace slashes with underscores, to avoid recognizing them
as directories.
"""
return eid.replace('/', '_') | 505ad3fd245ee9744d9b4ad05547c57373e898fd | 201,669 |
def latest(scores):
"""Return the last score of the player"""
return scores[-1] | c9a1d3e55a64e002fc637449f0a0017378b02759 | 396,178 |
def get_path_from_finish(current):
"""Traces back the path through parent-nodes"""
backwards = []
while current:
backwards.append(current.location)
current = current.parent
backwards.reverse()
return backwards | 212748572ec0cd7e8ab3df09162d95d3169c95b4 | 390,752 |
from typing import Dict
def calc_post_depths_from_thread_structure(thread_structure: Dict) \
-> Dict[str, int]:
"""Calculates the nested depth of each post in a thread.
We determine post depth from the provided `structure.json` files in the
dataset because this is easier than following the chain ... | 11687977dfa107b9b94d8c097e750825e98a479e | 83,558 |
def is_request_to_send(data):
""" Check if a packet is a request-to-send packet. """
return len(data) == 45 and ord(data[25]) == 0xb4 and ord(data[26]) == 0x00 | 93d07ecdb1919a39385acce9cd8cf09869268ec1 | 262,099 |
def get_segment_token_offsets(segment_token_list, token_map):
"""
given a list of token node IDs, returns the index of its first and last
elements. this actually calculates the int indices, as there are weird
formats like RS3, which use unordered / wrongly ordered IDs.
Parameters
----------
... | 5f0aabb5f3462b53856ec62ffd9284a7d51fa981 | 265,632 |
def _safe_wrap_in_html_tag(content, tag_name):
"""
Adds an html tag around content but handles new line characters
to prevent incorrectly nested tags later
:param content: The content to wrap in the tag
:param tag_name: The name of the tag to use e.g. 'em', 'strong'
:return: the HTML tagged stri... | 878533f011012353a2bccfdf2536d7b48bb829f9 | 149,149 |
def dump_byte_array(aaa):
""" Stringify a byte array as hex. """
out = ''
for bbb in aaa:
pair = "%02x" % bbb
out += pair
return out | dd77810c637fee08ef781442519e22b50c51d6f2 | 525,011 |
def intcode_one(parameter_one, parameter_two, parameter_three, code_list):
"""Adds element in the first parameter's index with element in second parameter's index. Places sum in third parameter's index. Returns True. """
code_list[parameter_three] = code_list[parameter_one] + code_list[parameter_two]
retur... | 195909f53e4a454fe0a93df89fb9493a3f38f0d1 | 542,551 |
def timestamp_to_bytestring(val, padding=8):
"""Convert Unix timestamp to bytes"""
result = []
while val != 0:
result.append(chr(val & 0xFF))
val = val >> 8
return ''.join(reversed(result)).rjust(padding, '\0') | a238d2dfa261d0c9e83ded4d902210b11ffc7757 | 412,724 |
import inspect
def is_valid_resource(test_item, api_name = None):
""" Filter function used to determine whether the given objects within a module represent
valid ModelResources for this API version"""
if inspect.isclass(test_item):
if test_item.api_name == api_name and "DefaultResource" not in te... | 69b996835a289877b7a96f7e84e37ca24f172ebb | 529,645 |
def check_polygon(nums: list[float]) -> bool:
"""
Takes list of possible side lengths and determines whether a
two-dimensional polygon with such side lengths can exist.
Returns a boolean value for the < comparison
of the largest side length with sum of the rest.
Wiki: https://en.wikipedia.org/w... | 114ae7120e661e19f32a7424895e37493f530ee6 | 65,415 |
import math
def A12_5_3_3(Pv, A, Fy, GammaRTv = 1.05):
"""
A.12.5.3.3 Beam shear strength check
Pv = representative shear strength
A = total cross-sectional area
GammaRTv = partial resistance factor for beam
shear strength, 1,05
"""
# Pv = representative shear strength... | cec124e0c7b71f6fafbae9512a8f489297176bdf | 279,667 |
def image_filename(im_num=0, pos_num=0, channel_num=0, z_num=0):
""" create a filename based on the image number, position, channel and z
Micro-manager format:
img_channel000_position001_time000000002_z000.tif
"""
filename = "img_channel{0:03d}_position{1:03d}_time{2:09d}_z{3:03d}.tif"
retu... | 5e8e6af29c0bed4a4c26e5741d1e3c322f48c83d | 380,681 |
def anchor_ctr_inside_region_flags(anchors, stride, region):
"""Get the flag indicate whether anchor centers are inside regions."""
x1, y1, x2, y2 = region
f_anchors = anchors / stride
x = (f_anchors[:, 0] + f_anchors[:, 2]) * 0.5
y = (f_anchors[:, 1] + f_anchors[:, 3]) * 0.5
flags = (x >= x1) &... | 5f1e3b764145a9ee8abb709cd43f7f99c8515eb7 | 691,059 |
def get_ancestor(taxid, tree, stop_nodes):
"""Walk up tree until reach a stop node, or root."""
t = taxid
while True:
if t in stop_nodes:
return t
elif not t or t == tree[t]:
return t # root
else:
t = tree[t] | f7841bc5104f96cd66122165a0646b70fc3fd33e | 700,914 |
def add_dicts(base, new):
"""Add newly dict items to a base set. New items replace existing
ones."""
if new:
base.update(new)
return base | e5e076c477705986353eb930b5a738bef00842bf | 549,752 |
def _band_power(mean_ds, f, center, bandwidth=2):
"""Sum DS values over a band of frequencies."""
low_f = center - bandwidth
high_f = center + bandwidth
f_idx = (low_f <= f) & (f <= high_f)
return mean_ds[f_idx].sum(axis=0) | 5c11b912908f677f123b99c67018b0bcaee9658a | 55,042 |
def tidy(word):
"""Filter out non-printable characters such as unicode characters."""
word = word.strip()
word = ''.join([i for i in word if i.isprintable()])
return word | 306802618ee3d0fe0dcc0358b168bc281cf395a2 | 375,839 |
import json
def get_device(token):
"""
Read the device configuration from device.json file.
:return: dict - the device configuration
"""
try:
with open("/tmp/{}/device.json".format(token), "r") as f:
return json.load(f)
except:
pass | 5675113a87ee2d4abf8ce630cd167113c25e3626 | 30,020 |
def calculateBounds(sentences):
"""Given a list of sentence strings, calculate their bounds as character offsets from 0
"""
curbound, bounds = 0, []
for s in sentences:
bounds.append((curbound, curbound + len(s)))
curbound += len(s) + 1
commabounds = [','.join((str(b) for b in bnds))... | 934e1e95538f3a846384897efe00f745639cb1b7 | 523,699 |
def difference(d1, d2):
"""Difference of two dicts.
Return elements of the first dict not existing in the second dict."""
ret = {}
for k in d1:
if k not in d2:
ret[k] = d1[k]
return ret | 3358b5d836c1551a83200c5184801193610c8bdf | 326,227 |
def amz_group_grant(uri, permission):
"""
Returns XML Grant for group with URI.
:param uri: group URI
:param permission: permission value
"""
grant = (
'<Grant>'
'<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'xsi:type="Group">'
'<URI>%s</URI>'... | 6db69daa14e2c24544e4a2639a7b9229a15135d4 | 73,156 |
def get_digits(n):
"""
Get the array of digits for n
"""
digits = []
while n > 0:
digits.append(n % 10)
n //= 10
return digits | 30f8f6b32b13190dabe723eda9cb874ec24b674b | 449,787 |
import math
def p75(lis, exception=0.0, cycles=False):
"""Calculates the average of the upper half of a list.
lis is the list that is averaged.
exception is returned if there is a divide by zero error. The
default is 0.0 because the main usage in in percentage calculations.
cycles is whether or n... | 514c952c133c4448d3be27e91bac9141910cbe10 | 496,265 |
def load_points(filename):
"""
Splits the contents of the sensors data file into a list of tuples (points)
:param filename: relative path to the datafile
:return: list of tuples of floats (coordinates)
"""
with open(filename, "r") as file:
# read the whole file (1 line) without the first... | 0b642f6981dbe36d48d35348239d3dc52e1803e1 | 354,799 |
import yaml
def read_conda_environments(env_paths: list):
"""
Read in a list of paths to yaml conda environment definitions.
Used to create package whitelists for conda-mirror
:param env_paths: A list of paths to conda environment definition yaml files
:return: a list of packages defined in the ... | 8b8ac992334d8c71446becf30c970143acd23304 | 603,175 |
def route53_to_zone_file(records):
"""Return a list of Zone File lines from a list of AWS::Route53::RecordSet"""
max_name_len = max([len(record["Name"]) for record in records], default=1)
return [
"{name:{max_name_len}}\t{ttl}\tIN\t{type:5}\t{data}".format(
name=record["Name"], max_name_... | 6f6078f9a1b42b806b5690432fce42ade9e5d94a | 527,027 |
def _find_from_file(full_doc, from_file_keyword):
"""
Finds a line in <full_doc> like
<from_file_keyword> <colon> <path>
and return path
"""
path = None
for line in full_doc.splitlines():
if from_file_keyword in line:
parts = line.strip().split(':')
if ... | 0deffb34143494dc5850ff2a217b9c0e31b48f37 | 206,081 |
from typing import List
from typing import Dict
def grid_values(puzzle:str,boxes:List[str],replace:bool=True) -> Dict[str,str]:
"""This function maps each puzzle unit to its box unit.
Args:
puzzle (str): String of puzzle
boxes (List[str]): A list of box units
replace (bool) : An option... | 649954daed0b15c294ea50d43e8199114566b4b4 | 482,754 |
from typing import List
def split_content_in_lines(file_content:str)->List[str]:
"""
Splits a block of strings into lines and keeps lines that are not starting with #
:param file_content:
:return:
"""
file_content = file_content.strip()
if len(file_content) <= 0:
return []
col... | ed58454e916a84288814b906ea14e223914320b8 | 238,699 |
from typing import MutableMapping
from contextlib import suppress
def delete_recursive_dictionary_keys(dct_to_change: MutableMapping, list_of_keys_to_remove: list) -> MutableMapping:
"""
Removes the specified keys from the specified dict.
Args:
dct_to_change: Dictionary to modify
list_of_k... | e73f19521edcbcdbb21b2ced1911aea55d5af5ca | 660,458 |
from typing import Generator
def get_rel_dict_rows(rel_dict:dict) -> Generator:
"""Converts dict of relationships into a generator of rows that can be passed to
a csv.DictWriter"""
return ({'Source':src, 'Target':tar, 'Relationship Type':val} for (src,tar),val in rel_dict.items()) | cc530e9b89f0c17050f1dde25cd9fef9e79a239f | 319,657 |
def col_to_dict(col, include_id=True):
"""Convert SchemaColumn to dict to use in AddColumn/AddTable actions."""
ret = {"type": col.type, "isFormula": col.isFormula, "formula": col.formula}
if include_id:
ret["id"] = col.colId
return ret | d7c10eb07daaf1af14c73f51192f5d1a5b7bd19b | 32,354 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.