content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_matrix_or_template_parameters(cli_args):
"""
cifti_conn_matrix and cifti_conn_template both have the same required
parameters, with only a few exceptions. This function returns a list of
all parameters required by both scripts.
:param cli_args: Full argparse namespace containing all CLI args... | fbda701f988ebf490bfd33fa8d78d8bcc1dd109f | 695,412 |
def TR4(rv):
"""Identify values of special angles.
a= 0 pi/6 pi/4 pi/3 pi/2
----------------------------------------------------
cos(a) 0 1/2 sqrt(2)/2 sqrt(3)/2 1
sin(a) 1 sqrt(3)/2 sqrt(2)/2 1/2 0
tan(a) 0 sqt(3)/3 1 sq... | 229b610c2898be7f01b8b7e6d3c17df71d27162a | 695,413 |
import argparse
def parse_args():
"""Process input arguments"""
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('vcf', metavar='V', help="VCF file")
parser.add_argument('--filter', ... | bb9de19f5c2f4e54c73c3ac1b003d53d0252cde7 | 695,414 |
import time
import logging
def get_set_num_ruptures(src):
"""
Extract the number of ruptures and set it
"""
if not src.num_ruptures:
t0 = time.time()
src.num_ruptures = src.count_ruptures()
dt = time.time() - t0
clsname = src.__class__.__name__
if dt > 10:
... | 1ae503627e0f971de00ce4dfbc449c2037514570 | 695,415 |
def icalevent2item(event):
"""icalendarイベントからjson用itemを取得する.
Arguments:
event {Event} -- icalendarイベント
Returns:
dict -- json用item
"""
item = dict()
summary = event.decoded('SUMMARY').decode()
last_paren = summary.rfind('(')
race_name = summary[:last_paren]
item['Na... | 453e578f8e2eac6e399bb925bfeac6dd149f6dc7 | 695,416 |
from typing import Tuple
import subprocess
def run_in_shell(cmd: str) -> Tuple[bool, str]:
"""
Run given command in the shell and return result of the command.
Usually a malformed command or error in the executed code will result in
the CalledProcessError and then that message is shown. During develo... | 81ef80fdef28714600afd163c9dc9fdae09f9d0f | 695,417 |
import os
def make_path(path: str) -> str:
"""Make directory.
Args:
path (str):
Path to be made if it doesn't exist.
Returns:
path (str)
"""
if not os.path.exists(path):
os.makedirs(path)
return path | 291476930ccab8d857b5544601982af185b6ac89 | 695,418 |
import sys
import argparse
def color(value): # type: (str) -> bool
"""Strict converter for color option."""
if value == 'yes':
return True
if value == 'no':
return False
if value == 'auto':
return sys.stdout.isatty()
raise argparse.ArgumentTypeError(f"invalid choice: '{... | 3cbf58e63b2f982274e8304c8d0938a7eb4e3a5e | 695,419 |
import os
import time
import requests
def retrieve_order(outdir: str, order_url: str):
"""
Download the order
:param outdir: Full path to the order download folder
:param order_url: Order download URL
:return:
"""
order_id = order_url.split("/")[-1]
if not os.path.exists(outdir):
... | 0707ce160dd1a2bbf2e608caf9aab8a619871b92 | 695,421 |
def _format_training_params(params):
"""Convert dict pof parameters to the CLI format
{"k": "v"} --> "--k v"
Args:
params (dict): Parameters
Returns:
str: Command line params
"""
outputs = []
for k, v in params.items():
if isinstance(v, bool):
if v:
... | bc0146afe7fb5201a78ee9cf7a0bb47a80bba4db | 695,422 |
import os
def tail(filename, nlines):
""" Read the last nlines of a text file """
with open(filename) as qfile:
qfile.seek(0, os.SEEK_END)
endf = position = qfile.tell()
linecnt = 0
while position >= 0:
qfile.seek(position)
next_char = qfile.read(1)
... | 1aca62b1ab223a6567cb8b879a8fb979d43887ba | 695,423 |
def valid_parentheses_brackets(input_string: str) -> bool:
"""
Determine whether the brackets, braces, and parentheses in a string are valid.
Works only on strings containing only brackets, braces, and parentheses.
Explanation: https://www.educative.io/edpresso/the-valid-parentheses-problem
:param... | fd531bc264fc56df699de67cae60b52cf51519c3 | 695,424 |
import os
def clear_directory(path):
"""
clear the dir of path
:param path:
:return:
"""
if not os.path.exists(path):
os.mkdir(path)
try:
cmd = 'rm %s/*' % path
print(cmd)
os.popen(cmd)
except Exception as e:
print("error: %s" % e)
return... | b03a832e8c2ae7b2b1d724c76d16be18d1b2305f | 695,425 |
def do_chars_exist_in_db(conn, mal_id: int) -> bool:
"""
Args:
conn ([type]): database connection
mal_id (int): myanimelist id
Returns:
bool: returns true if there are character records for anime id
"""
with conn:
with conn.cursor() as cursor:
query = """... | b106342207feea434c59fe4493dc09c97ef3376c | 695,426 |
def id_to_ec2_id(instance_id, template='i-%08x'):
"""Convert an instance ID (int) to an ec2 ID (i-[base 16 number])"""
return template % instance_id | 7f1f65b4a846be1c46bc3d80c207f2b9ba0033af | 695,427 |
def buildnavcell(prefix, dateString, mouseoverImg, mouseoutImg, name):
"""Build the HTML for a single navcell.
prefix -- the string to tack on to the front of the anchor name
dateString -- the date, as a string, to be used in the anchor name
mouseoverImg -- name of the image to be displayed on mouseove... | 250ebba918b850a6d87fa5146fa9865c6acc14f9 | 695,428 |
import os
import json
import pprint
def read_filter_params(file_path:str,file_name:str="filter.json",filter_str=None,metadata=False,verbose=False):
""" reads filter parameter file from json
will read only the first filter entry of the first category if filter_str is None
otherwise it will look ei... | bfa6916d1e810631e7bf81d32c3b2ee6ff5a28a9 | 695,429 |
def calc_prob_sr(pt, sl, freq, tgt_sr, rf=0.):
"""Calculate required probability wrt target SR
Paramters
---------
pt: float
Profit Take
sl: float
Stop Loss
freq: float
Frequency of trading
tgt_sr: float
Target Sharpe Ratio
rf: float, (default 0)
... | 96b017e8ec18ed5c267bfd9eb0176f961481982e | 695,430 |
import sqlite3
def get_brand_stats(db_file_name, table_name):
"""Calculate brand stats of collection"""
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute('''SELECT brand, count(brand) FROM {} GROUP BY brand'''.format(table_name))
brand_dict = {}
results = c.fetchall()
for ... | 96a422ed7579314b0ccc9e59bf0e1027ce70152b | 695,432 |
def encode(integer: int) -> bytes:
"""Encodes an integer as an uvarint.
:param integer: the integer to encode
:return: bytes containing the integer encoded as an uvarint
"""
def to_byte(integer: int) -> int:
return integer & 0b1111_1111
buffer: bytearray = bytearray()
while intege... | da3b6b320ddcc39ecf494fca564d6d3ae06faea9 | 695,434 |
import requests
def request_html(url, method='GET', headers=None, proxies=None):
"""
send request
:param url:
:param method:
:param headers:
:param proxies:
:return:
"""
resp = None
try:
r = requests.request(method, url, headers=headers, proxies=proxies)
if r.st... | b7ee1a20da1bc718cf00befa40d45eaf351f9252 | 695,435 |
from typing import Dict
from typing import Any
import json
import base64
def extract_pubsub_payload(event: dict) -> Dict[str, Any]:
"""Extracts payload from the PubSub event body.
Args:
event: PubSub event body, e.g.
{
"message": {
"data": <base64 encod... | 05dadc17078fb723a385b7d36a7b9dd005c7e931 | 695,436 |
def sort_ortholog_information(faa_defs, faa_seqs):
"""Group contig name with start and stop"""
first_species_defs = []
second_species_defs = []
first_species_seqs = []
second_species_seqs = []
for x, i in enumerate(faa_defs):
if x%2==0:
first_species_defs.append(i)
... | 82fb26046cabcb74f383bbc27966322620cc49ed | 695,437 |
def extract_column_names(file_lines):
""" Return a list of tuples containing column names and its respective index. Mutates the file lines list by extracting first element (first row of data file) """
column_names = file_lines.pop(0)
column_names = column_names.rstrip().split("\t")
column_names = list(enumerate(col... | 178b4229bf77fe84d37f3d09668f2c5851ca43db | 695,438 |
import io
def parse_aliases_file(file_path):
"""
Parses an emoji aliases text file.
Returns a list of tuples in the form ('src_name', 'dst_name').
"""
with io.open(file_path, encoding='utf-8') as fp:
lines = fp.read().splitlines()
aliases_list = []
for line in lines:
line ... | 0ab98e0921655d7582c8a6261660da84f9287395 | 695,439 |
def make_goal(func):
"""Decorator that turns a function of the form f(Substitution, ...) into
a goal-creating function.
For example:
@make_goal
def same(s, u, v):
...
is equivalent to
def same(u, v):
def goal(s):
...
return go... | d5320d46d45fa749b7f3e6cea173fd41acca29b0 | 695,440 |
def _bb_has_tight_loop(f, bb):
"""
parse tight loops, true if last instruction in basic block branches to bb start
"""
return bb.offset in f.blockrefs[bb.offset] if bb.offset in f.blockrefs else False | 05b703f487b7cf8a0a828f03fd78ab53a34d87da | 695,442 |
from platform import python_compiler
def python_version(name):
"""
Get compiler version used in Python.
Parameters
----------
name : str
Compiler name.
Returns
-------
float: version
"""
version_str = python_compiler()
if name not in version_str.lower():
... | 2353ca4d9156560e7109d83673a0c485c2b27437 | 695,443 |
def get_table_rows(soup):
"""
Get all table rows from the first tbody element found in soup parameter
"""
tbody = soup.find('tbody')
return [tr.find_all('td') for tr in tbody.find_all('tr')] | b93e2968ff289c1380ee0f0be571897d9db06437 | 695,444 |
import re
def slug_to_name(slug):
"""simple function that transforms a slug to a name
args:
string name -- the name to be converted
"""
return re.sub('-', ' ', slug) | 4603d5d4e1206ced28d8d24c13c91030970fc8c7 | 695,445 |
def topleft2corner(topleft):
""" convert (x, y, w, h) to (x1, y1, x2, y2)
Args:
center: np.array (4 * N)
Return:
np.array (4 * N)
"""
x, y, w, h = topleft[0], topleft[1], topleft[2], topleft[3]
x1 = x
y1 = y
x2 = x + w
y2 = y + h
return x1, y1, x2, y2 | 094b12c4c112e906714e717c7fce79321610f69c | 695,446 |
def crop(im, slices=(slice(100, -100), slice(250, -300))):
"""Crop an image to contain only plate interior.
Parameters
----------
im : array
The image to be cropped.
slices : tuple of slice objects, optional
The slices defining the crop. The default values are for
stitched i... | e3e7c2f737b0e589e6491cba44eb3c3aaee930d0 | 695,448 |
import importlib
def internal_load_class(data: dict):
"""
For internal use only.
"""
if not isinstance(data, dict):
raise ValueError("Given parameter not a dict object.")
if "type" in data:
try:
klass = None
if data["type"].endswith("Token"):
... | 169761bd81d590e2a51137f5f1732c72a463d75f | 695,450 |
def _get_groupings(input_df):
"""Return groupings of table data based on filled/empty columns."""
input_cols = list(input_df.columns)
# change any NAs to blank strings (this might cause TypeErrors !)
input_df = input_df.fillna("")
# Create a DF with True if a col value is blank
blank_cols = inpu... | 84d6a714b0835beead7f857bdf05a0ed21e4e721 | 695,452 |
def build_speech_response(title, ssml_output, plain_output):
"""Build a speech JSON representation of the title, output text, and end of session."""
# In this app, the session always ends after a single response.
return {
'outputSpeech': {
'type': 'SSML',
'ssml': ssml_output... | 2d38b9d0d8a261c6011eec3416227e972329de86 | 695,454 |
def bin2hex(s):
"""
bin2hex
二进制 to 十六进制: hex(int(str,2))
:param s:
:return:
"""
padding_length = (8 - len(s) % 8) % 8
# 从前往后解码,不足8个的,在后面补0
encode_str = '%s%s' % (s, '0' * padding_length)
# 解码后是 0xab1234,需要去掉前面的 0x
return hex(int(encode_str, 2))[2:].rstrip('L') | 02e9f0753aff776278eb53a9667683418b6fb425 | 695,455 |
def check_input(fit_function): # pylint: disable=no-self-argument
"""Check fit input args."""
def wrapper(obj, pk, k=None):
pk = obj.check_pk(pk)
k = obj.check_k(k)
return fit_function(obj, pk, k=k)
return wrapper | c8bf35dbea4f5db1f4764a311946f37697ef6865 | 695,456 |
import copy
def nondimensionalise_parameters(params):
"""
Nondimensionalise parameters.
Arguments
---------
rc : float
Characteristic radius (length)
qc : float
Characteristic flow
Ru : float
Upstream radius
Rd : float
Downstream radius
L : float
... | d12200d10b4ee25bf3bfdec7f461e00e431cd7e0 | 695,457 |
def qtr_offset(qtr_string, delta=-1):
"""
Takes in quarter string (2005Q1) and outputs quarter
string offset by ``delta`` quarters.
"""
old_y, old_q = map(int, qtr_string.split('Q'))
old_q -= 1
new_q = (old_q + delta) % 4 + 1
if new_q == 0:
new_q = 4
new_y = old_y + (old_q + ... | e14465ad5ab600a809592a4a3a8d2aa624035515 | 695,458 |
from zlib import decompress
from base64 import b64decode
def decompress_string(string: str) -> str:
"""
Decompress a UTF-8 string compressed by compress_string
:param string: base64-encoded string to be decompressed
:return: original string
"""
# b64 string -> b64 byte array -> compressed by... | e9c8cfd4f226e4bae5d00e32428c8c028b03797c | 695,459 |
def create_dense_state_space_columns(optim_paras):
"""Create internal column names for the dense state space."""
columns = list(optim_paras["observables"])
if optim_paras["n_types"] >= 2:
columns += ["type"]
return columns | 979a17c32dbe9a31e52b2dfb16d9771bd7a4746b | 695,460 |
def calculate_overall_score(
google_gaps_percentage: float, transcript_gaps_percentage: float,
google_confidence: float, alignment_score: float,
weight_google_gaps: float, weight_transcript_gaps: float,
weight_google_confidence: float, weight_alignment_score: float
) -> float:
""... | ea7d92c694dd477b9cd801eb8c91f969a8d757e1 | 695,461 |
def toIndex(coord, size):
""" Coordinate to index """
return coord[0] * size * size + coord[1] * size + coord[2] | 82ff848d4c728129d0ad6691d3d960dff12ef388 | 695,462 |
def scal(u, v):
"""Retourne le produit scalaire u.v """
return sum([u[i]*v[i] for i in range(len(u))]) | f35c7ab378e809db8e7f13432a62da3310ad7611 | 695,463 |
def recursive_thue_morse(n):
"""The recursive definition of the Thue-Morse sequence. The first few terms
of the Thue-Morse sequence are: 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 . . ."""
if n == 0:
return 0
if n % 2 == 0:
return recursive_thue_morse(n / 2)
if n % 2 == 1:
return 1 - r... | 8fba270d9a62bf3ea4a2b320a19876228255bd0f | 695,464 |
from typing import Dict
def add_information(statistic_dict: Dict, statistic_information: Dict):
"""
Add information to existing dict.
Arguments:
statistic_dict {Dict} -- Existing dict.
statistic_information {Dict} -- Data to add.
"""
statistic_dict["dates"].append(statistic_inform... | 3b45591d4fe96a5cd93552b322869495a007fe86 | 695,465 |
def flip_edges(adj, edges):
"""
Flip the edges in the graph (A_ij=1 becomes A_ij=0, and A_ij=0 becomes A_ij=1).
Parameters
----------
adj : sp.spmatrix, shape [n, n]
Sparse adjacency matrix.
edges : np.ndarray, shape [?, 2]
Edges to flip.
Returns
-------
adj_flipped ... | 0e163616ddb645e636424d673500f07aedabf336 | 695,466 |
import socket
def _check_ip_and_port(ip_address, port, timeout):
"""Helper function to check if a port is open.
Args:
ip_address(str): The IP address to be checked.
port(int): The port to be checked.
timeout(float): The timeout to use.
Returns:
bool: True if a connection ... | f97ceaba05c54c4bb70e8731462469e4d89e1bbf | 695,467 |
def pretty_eqdmr(eqdmr):
"""Returns an executable QDMR program in a compositional manner
Parameters
----------
eqdmr : str
string representation of the executable QDMR
Returns
-------
bool
return True
"""
tab_count = 0
pretty_represenation = ''
for i in range(len(eqdmr)):
if e... | d2d53d49a94f94e718a0aecc1af3ce320a3e95f4 | 695,468 |
def _add_thumb(s):
"""
Modifies a string (filename, URL) containing an image filename, to insert
'.thumb'
"""
parts = s.split(".")
parts.insert(-1, "thumb")
if parts[-1].lower() not in ['jpeg', 'jpg']:
parts[-1] = 'jpg'
return ".".join(parts) | 9fe7ba9d1e739828471e07091008cb8de47ea312 | 695,469 |
from typing import Any
import asyncio
import inspect
def is_coroutine(obj: Any) -> bool:
"""Check to see if an object is really an asyncio coroutine.
:param Any obj: any object.
:return: `True` or `False`.
"""
return asyncio.iscoroutinefunction(obj) or inspect.isgeneratorfunction(obj) | 595582f9bd8fae930532cea4a0aa7e3b05e010be | 695,470 |
import csv
def recuperer_donnee_csv(fichier, separateur=','):
"""
cree une liste de liste contenant les donnees de fichier
Parameters
----------
fichier : string
chemin du fichier csv a lire
ce fichier ne doit contenir que des float.
separateur : string, optional
strin... | a16ebe71654688d8963dfe0930a035b8953a6aef | 695,471 |
import os
def get_connection_file():
"""
---------------------------------------------------------------------------
Gets (and creates, if necessary) the auto-connection file.
If the environment variable 'VERTICAPY_CONNECTIONS' is set, it is assumed
to be the full path to the auto-connection file.
Otherwise, we ... | 80a5d9adeb5a9b671f57377897cd35685589375d | 695,472 |
import torch
def compute_hessian(f, params):
"""Compute hessian matrix of given function."""
h = []
for i in params:
h_i = []
for j in params:
grad = torch.autograd.grad(f, j, create_graph=True)
h_ij = torch.autograd.grad(grad,
... | 5dba4f34846f25b268e9156902abdee732c8a7b0 | 695,473 |
import os
def makedoedict(str1):
"""makedoedict"""
blocklist = str1.split('..')
blocklist = blocklist[:-1]#remove empty item after last '..'
blockdict = {}
belongsdict = {}
for num in range(0, len(blocklist)):
blocklist[num] = blocklist[num].strip()
linelist = blocklist[num].sp... | fca4884f36181072e173ed2941fbf2a2b5a48ec2 | 695,474 |
import re
def format_docstring(docstring):
"""Formats a docstring. Any leading # will be converted to #### for
formatting consistency.
# args
- docstring -str: the dosctring to be formatted.
"""
if isinstance(docstring, str):
result = re.sub(r'^#+ ?', '#### ', docstring, flags=re.MULT... | 62a6c9d470be454b4c9dc2e386cd9be81450df4e | 695,475 |
def get_id_name(module, id_to_check):
"""Return the ID name if defined, otherwise return the numbered ID."""
for name in module.symbol_name_to_id:
if module.symbol_name_to_id[name] == id_to_check:
return name
return str(id_to_check) | 5647b32d86bee44d302e551ffc0e8c290254ea10 | 695,476 |
def rect_radius(ellipsoid):
"""
Computes the Rectifying Radius of an Ellipsoid with specified Inverse Flattening
(See Ref 2 Equation 3)
:param ellipsoid: Ellipsoid Object
:return: Ellipsoid Rectifying Radius
"""
nval = (1 / float(ellipsoid.inversef)) / (2 - (1 / float(ellipsoid.inversef)))
... | 525e6428de9a34f5f1f10bdb9bc1b0943f435e70 | 695,477 |
import os
def normalizePath(path):
"""Normalize the path given.
All slashes will be made the same (and doubles removed)
The real case as stored on the file system is recovered.
Returns None on error.
"""
# normalize
path = os.path.abspath(path) # make sure it is defined from the drive up... | 633e5518f8716443770e7570c495f7ba4a541a01 | 695,478 |
def endgame_score_connectfour_faster(board, is_current_player_maximizer) :
"""Given an endgame board, returns an endgame score with abs(score) >= 1000,
returning larger absolute scores for winning sooner."""
chains_1 = board.get_all_chains(current_player=is_current_player_maximizer)
chains_2 = board.get... | 24f22b4d76edcdae5918c4327855aa432f404a68 | 695,479 |
def ip_as_int(ip_address):
"""convert dot notation to int.
"""
parts = [int(x) for x in ip_address.split(".")]
return (parts[0] << 24) + (parts[1] << 16) + (parts[2] << 8) + parts[3] | fd2c83b3b279bbdce240cbb11acf7334c8e2d553 | 695,480 |
import types
def dump_packages():
"""
Function that will return a list of packages that
have been loaded and their version numbers.
This function will ignore system packages:
sys, __builtins__, types, os
as well as modules with no version.
This is not wo... | f6f4cf9c86962f68c998f2e3b127326837c12ac0 | 695,481 |
def padding_size(length: int, block_size: int, ceil: bool = True) -> int:
"""Return minimum the multiple which is large or equal than the `length`
Args:
block_size (int): the length of bytes, no the length of bit
"""
remainder = length % block_size
if ceil:
return (block_size - rem... | 3f87de905962e70f2514617bd10472a4087ad9f3 | 695,482 |
from typing import Any
def _is_simplekv_key_value_store(obj: Any) -> bool:
"""
Check whether ``obj`` is the ``simplekv.KeyValueStore``-like class.
simplekv uses duck-typing, e.g. for decorators. Therefore,
avoid `isinstance(store, KeyValueStore)`, as it would be unreliable. Instead,
only roughly ... | 1529b4531aabc50163cd00ebbb6b4aef1f99e5bd | 695,483 |
import typing
def list_difference(list_a, list_b) -> typing.List:
""" Function that returns difference between given two lists. """
# Returning.
return [element for element in list_a if element not in list_b] | 0746a34c4f24ae2f46d5c176568e733d54ba7dea | 695,484 |
def check_ranges(cpe_item, version):
"""
According to the specification, CPE uses also ranges with the keywords
'version[Start|End][Including|Excluding]'. This way it specifies ranges of versions
which are affected by the CVE, for example versions from 4.0.0 to 4.5.0.
:param cpe_item: cpe data
... | 614148e671b7d6c526badf02f784bd7669b37ec0 | 695,486 |
def CStringIo_to_String(string_io_object):
"""Converts a StringIO.StringIO object to a string.
Inverse of String_to_CStringIo"""
return string_io_object.getvalue() | 21f2b027f1eb43063bc24df25db2c2098d894d46 | 695,488 |
def is_valid_response(resp):
"""
Validates a Discovery response
Fail if a failure response was received
"""
return resp.get("result") != "failure" | e008cc34eb43906bc67f2ad645625777241b76e2 | 695,489 |
import struct
def _pack(pv, chksum, box_data, party_data):
"""Pack Pokémon data into a PKM file.
Keyword arguments:
pv (int) -- the Pokémon's personality value
chksum (int) -- the data's checksum
data (string) -- the Pokémon data
"""
chunks = [
struct.pack('<L', pv),
'\x0... | ebae4778b791ed99abb1dbb39f1fcfd6bec9ef33 | 695,490 |
def is_valid_provider(user_input: str, static_provider: str) -> bool:
"""
Validate a user's provider input irrespectve of case
"""
try:
return user_input.lower() == static_provider.lower()
except AttributeError:
return False | 7dad54bf8b2ba3a705f54915b094e3633a72ce2f | 695,491 |
def print_diff(a1,a2):
""" Print not similar elements """
diff = []
for i in a1:
if a2.count(i) == 0:
diff.append(i)
for i in a2:
if a1.count(i) == 0:
if diff.count(i) == 0:
diff.append(i)
return diff | 519ab38a193cf53fe022e8cba1627252abe6dc81 | 695,492 |
import sys
import inspect
def fident(f):
"""
Get an identifier for a function or method
"""
joinchar = "."
if hasattr(f, "im_class"):
fparent = f.im_class.__name__
else:
joinchar = ":"
fparent = f.__module__.split(".")[-1]
# sometimes inspect.getsourcelines() segfa... | 448d5257996a6a14fb047aacd3392f194b89301b | 695,495 |
import ntpath
import os
def split_path(filepath):
"""Splits a file path into folder path, file name and extension"""
head, tail = ntpath.split(filepath)
filename, extension = os.path.splitext(tail)
return head, filename, extension | 5622cec9f3223f5d41c5e9e12c05f07169ab7db2 | 695,496 |
def rateTSCan(params: dict, states: dict) -> float:
"""
Temperature Sum [oC d]
TSCan is set from negative in the vegetative phase
and to 0oC d at the start of the generative phase
(i.e. the first fruit set).
When TSCan exceeds 0 oC d, the carbohydrate distribution to
the fruits increases li... | 7ab4c8242c26a846c719a304ead1cb7748513c0b | 695,497 |
import requests
def get_from_api(url, *, verbose=False):
""" Performs GET request to URL with the ProPublica API Key header """
vprint = lambda *a, **kwa: print(*a, **kwa) if verbose else None
with open("APIKey.txt", "r") as keyFile:
apiKey=keyFile.readline()
if apiKey[-1] == '\n':
... | b0ac6365008e145d08376087b97d20a9df0f7d65 | 695,498 |
import json
def json_querystring(query_string, sort=None):
"""Generate the JSON data for a query_string query."""
query_dict = {'query': {'query_string': query_string}}
if sort:
query_dict['sort'] = sort
return json.dumps(query_dict) | 11c8119009994644e8b1e14d8282b7e3b1b04dd7 | 695,499 |
def get_total_timings(results, env, overhead_time):
""" Sum all timings and put their totals in the env """
total_framework_time = 0
total_strategy_time = 0
total_compile_time = 0
total_verification_time = 0
total_kernel_time = 0
if results:
for result in results:
if 'fra... | b6d7fe606ca3241f3030cf306e585c806f5c5d5b | 695,500 |
import re
def _get_vfab_pprofile_index(vfab_id, pprofile, mac_address, running_config):
"""Gets the index for vfab pprofile."""
index = None
match = re.search(
r"^vfab\s+{vfab_id}\s+pprofile\s+(\d+)\s+"
r"vsiid\s+mac\s+{mac}\s+{pid}\b".format(
vfab_id=vfab_id, mac=mac_address,... | 45e8a03be840b0738f589aefefbd0ac4383f17c4 | 695,501 |
import re
def check_no_splcharacter(test):
"""Check the string ``test`` have no special character listed below.
:param test:
:return:
"""
# noinspection RegExpRedundantEscape
string_check = re.compile('[@!#$%^&*()<>?/\|}{~:]')
if string_check.search(test) is None:
return True
... | 65eb3222d3bbbcc5fc876c2aecc47dddf1a12223 | 695,502 |
def _get_nc_attr(var, attr, default=""):
"""
_get_nc_attr
This function, looks inside a netCDF 4 Dataset object for the attributes of a variable within the object.
If the attribute specified for the variable exists then the attribute is returned.
If the attribute is not associated with the variabl... | 553c44a41a4bd1abf0dea721eff2bc6c19496a73 | 695,503 |
def shift_origin_dict(dictionary1, origin_list):
"""
New version of "new_origin" used for dictionaries.
Shifts all coordinates of the elements in the model by the number given in origin_list.
Returns the model with all items shifted according to new origin.
"""
new_dict = {}
for (x_co, y_co,... | bbc145ab8c942c958b8a7b0e8312920b8ec30972 | 695,504 |
def trivial(array: list, lenght: int) -> int:
"""Get the maximum minimum using a trivial solution"""
maximum = min(array[:lenght])
for i in range(len(array) - lenght + 1):
minimum = min(array[i : lenght + i])
maximum = max(maximum, minimum)
return maximum | f3f43954e8d02db24e08f7a78b1599666882c28b | 695,505 |
import argparse
def parseargs():
""""parse the arguments"""
parser = argparse.ArgumentParser(description='Decodes the content of a pcap file', epilog="Usually used to extract the file data from the a network trace (pcap) file. Remember last option wins.")
parser.add_argument('-i', '--in', dest='input_file', requir... | d64a6e4ccfde75c9ccc37602bfee452d55e2678c | 695,507 |
def chr_or_input(m):
"""Return ascii character for the ordinal or the original string."""
i = int(m.groups()[0])
if i > 31 and i < 128:
return chr(i)
else:
return "__%d__" % i | d8cc94fe33e65a0d698f1828650406312530c813 | 695,508 |
import requests
import json
def yelp_search(api_key, params):
"""
Makes an authenticated request to the Yelp API
api_key: read text file containing API key
parameters:
term: keywords to search (tacos, etc.)
location: location keywords (Seattle, etc.)
Returns JSON
"""
search... | cc4e79c72822f805c49f9be021297985cef396c3 | 695,509 |
def get_valid_image_ranges(experiments):
"""Extract valid image ranges from experiments, returning None if no scan"""
valid_images_ranges = []
for exp in experiments:
if exp.scan:
valid_images_ranges.append(exp.scan.get_valid_image_ranges(exp.identifier))
else:
valid_... | ddfcb091fabb0c70f7a6a3fce8b43396574a797c | 695,510 |
def isc_250m_to_1km ( i_sc_250m ) :
"""
return the 1km grid index cross track of a 250m pixel
"""
return i_sc_250m / 4. | a183dbf59bad703e70ce9c7e09c2bac7a6417fc2 | 695,511 |
import re
def extract_fasta_id(seqIdString):
"""
Extract the id in the fasta description string, taking only the characters till the '|'.
"""
seqId = None
regex1 = re.compile(r'^\s*?([^|]+?)(\s|\||$)')
seqIdSearch = re.search(regex1, seqIdString)
if seqIdSearch:
seqId = seqIdSearch... | fa3cc6a57fc2ded2f1ee62a80254076eada1df63 | 695,512 |
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 |
from typing import Callable
def custom_splitter(separator: str) -> Callable:
"""Custom splitter for :py:meth:`flatten_dict.flatten_dict.unflatten()` accepting a separator."""
def _inner_custom_splitter(flat_key) -> tuple[str, ...]:
keys = tuple(flat_key.split(separator))
return keys
retu... | 88417ecc172986e4cb8423f443da470e917406d2 | 695,515 |
import pathlib
def explore_directories(path_dict: dict):
"""
Recursively explores any path binded to a key in `path_dict`
eg:
| root
|deadbeef
|file1.txt
|colosseum
| battle.rst
|face
|file2.jpg
>... | 65abfdcdcae509785097a8f15c2a775249481c8d | 695,516 |
def get_required_capacity_types_from_database(conn, scenario_id):
"""
Get the required type modules based on the database inputs
for the specified scenario_id. Required modules are the unique set of
generator capacity types in the scenario's portfolio.
:param conn: database connection
:param sc... | bdd4f101465c55b712eb3f54797bbf213ed50b80 | 695,517 |
def radius_sonic_point(planet_mass, sound_speed_0):
"""
Radius of the sonic point, i.e., where the wind speed matches the speed of
sound.
Parameters
----------
planet_mass (``float``):
Planetary mass in unit of Jupiter mass.
sound_speed (``float``):
Constant speed of sound ... | 15965142ad7bd9ef3bdab1a215c0ed906b1e9102 | 695,518 |
def sampling_points_matsubara(b, whichl):
"""Computes "optimal" sampling points in Matsubara domain for given basis"""
return b.sampling_points_matsubara(whichl) | 6bd572e0502f44f28d9143ea1c39f858a47b6785 | 695,519 |
def _process_type(type_):
"""Process the SQLAlchemy Column Type ``type_``.
Calls :meth:`sqlalchemy.sql.type_api.TypeEngine.compile` on
``type_`` to produce a string-compiled form of it. "string-compiled"
meaning as it would be used for a SQL clause.
"""
return type_.compile() | ac9cc08faf958ad226da1bf08381b4bedd400e49 | 695,520 |
import pathlib
import typing
def _get_file_format_id(path: pathlib.Path, file_format: typing.Optional[str]) -> str:
"""Determine the file format for writing based on the arguments."""
formats = {
"yaml": path.name.endswith((".yml", ".yaml")),
"toml": path.name.endswith(".toml"),
"json"... | d2fc516ba1a1fae1c7d91e6bac351ca7bead5f04 | 695,521 |
from typing import Union
from pathlib import Path
def find_path_of_common_folder(files) -> Union[None, Path]:
"""finds a common path in a list of files"""
fparts = [Path(f).resolve().parts for f in files]
maxlen = len(max(fparts, key=lambda x: len(x)))
minlen = len(min(fparts, key=lambda x: len(x)))... | 89e8cff1b14597d6e58ab7c7f0452c3b18f5c428 | 695,522 |
def async_partial(coro, *added_args, **added_kwargs):
""" Like functools.partial(), but for coroutines. """
async def wrapped(*args, **kwargs):
return await coro(*added_args, *args, **added_kwargs, **kwargs)
return wrapped | 4138d0a253e8713ecff9b96345794a90116ee7bb | 695,523 |
def read_paralogs_log(paralog_log_file):
"""Get list of paralogous gene-chains."""
f = open(paralog_log_file)
gene_chains = [x for x in f.read().split("\n") if x != ""]
f.close()
return set(gene_chains) | c863f1b680854e8130fcad9e58b0b160cd39f735 | 695,524 |
def remove_common_elements(package_list, remove_set):
"""
Remove the common elements between package_list and remove_set.
Note that this is *not* an XOR operation: packages that do not
exist in remove_set (but exists in remove_set) are not included.
Parameters
----------
package_list : lis... | 99e6fc3d7273de551d9fc8e4f8dd5b1628b93dda | 695,525 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.