content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_outdir_simupara(fp, line):
"""
get output directory and simulation parameters (in format: time steps)
:param fp: opened file
:param line: current line
:return: output directory and simulation parameters
Note: output directory is '' if not specified and
list of simulation parameters... | 22da06da0466657a5905ba3333b270787cf98a58 | 17,854 |
import re
def ShortenDsn(connect_str_clear):
"""
This must be very fast because used in loops.
It abbreviates the DSN especially if this is a connection string.
"""
mtch_dsn = re.match(".*DSN=([^;]+).*", connect_str_clear, re.IGNORECASE)
if mtch_dsn:
return mtch_dsn.group(1)
mtch_d... | 1041a7e3e731d24593268150e074624ef92d0b86 | 17,855 |
def grid_coordinates(bbox: tuple, gridsize: int) -> list:
"""
Returns a matrix of gridsize with the real world coordinates of each cell's center
:param bbox:
:param gridsize
:return:
"""
x_min = bbox[0]
y_min = bbox[1]
x_max = bbox[2]
y_max = bbox[3]
cell_width = (x_max-x_mi... | 9c522d9a24307e34d564f2fc8d1a135168e8f8ff | 17,856 |
def get_indexing(string):
"""
Parse numpy-like fancy indexing from a string.
Args:
string (str): string represent the indices to take
a subset of from array. Indices for each dimension
are separated by `,`; indices for different dimensions
are separated by `;`.
... | 327054d0387f4bda1f3345d2886541a20e96e962 | 17,857 |
import pytz
def timezonize(timezone):
"""Convert a string representation of a timezone to its pytz object, or do nothing if the argument is already a pytz timezone."""
# Check if timezone is a valid pytz object is hard as it seems that they are spread arount the pytz package.
# Option 1): Try to conv... | 1145bb17bf9c50985d88770e8fa0437bfb3e9a18 | 17,859 |
import numpy
def multivariate_gaussian(x_array, mean_mu, corr_sigma):
"""
Computes the probability density function of the multivariate gaussian distribution.
Parameters
----------
x_array : array_like
The dataset of shape (m x n). Where there are m examples of n-dimensions.
mean_mu ... | 7c2c08642531e2790289db1179924cff440fd23a | 17,860 |
import inspect
from typing import get_type_hints
import sys
def _class_get_type_hints(obj, globalns=None, localns=None): # noqa: MAN001,MAN002
"""
Return type hints for an object.
For classes, unlike :func:`typing.get_type_hints` this will attempt to
use the global namespace of the modules where the class and i... | c04d6d391c7b06980fa33407e6bca809ff86c07e | 17,861 |
import time
def convert_to_timestamp(seconds):
"""
Converts an integer into a string 'HH:MM:SS'.
We differ a bit from python's standard time library
in that if a number is negative, instead of reversing
back into the 24hr mark, we return 00:00:00.
"""
if seconds < 0:
return '0:00'
... | 45428766c440c15366030b07cac95c304cefee89 | 17,862 |
def unpack_string(byte_stream):
"""Return decoded ASCII string from bytestring.
Decode a bytes object via UTF-8 into a string
Args:
byte_stream (bytes): arbitrary length
Returns:
string: UTF-8 decoded string
"""
out_string = byte_stream.decode("utf-8", "replace")
return ou... | 5caaf20a41a05fb0026cb9131dd4825f036ec837 | 17,863 |
from sys import getsizeof
from typing import Mapping
from typing import Iterable
def get_size(obj, seen=None):
"""Return size of any Python object."""
if seen is None:
seen = set()
size = getsizeof(obj)
if id(obj) in seen:
return 0
seen.add(id(obj))
if hasattr(obj, "__dict__"):... | 8bb39d45f1a5a44199e81a65bedc7005d22eaeba | 17,864 |
import os
def _make_concatenated_data_dirs(suite_locs, area):
"""Create dirs to hold cubeList files."""
suites_locations = {}
supermeans_locations = {}
for suite_dir in suite_locs:
suite_data = os.path.join(suite_locs[suite_dir], area)
if not os.path.exists(suite_data):
os.... | 0977fc4cec9f0b5bd1baadf5b7b24a76fccb19f8 | 17,865 |
import importlib
def import_from_module_name(module_name):
"""Imports a module and returns it and its name."""
module = importlib.import_module(module_name)
return module, module_name | 87d38536dc23c3ef86bcc1d0b5b0ec937ba397d6 | 17,866 |
def get_external_results_priorities(results):
"""
Return additional, external results priorities.
Results priorities from external plugins (e.g. DonPedro) are coming
together with results.
"""
priorities = {}
for plugin_name, plugin_results in results.iteritems():
if 'results_prior... | f18927a19929b52229aa10ea17ddb5d5e16bc832 | 17,869 |
def get_range_around(range_value, current_item, padding):
"""
Returns a range of numbers around the given number.
This is useful for pagination, where you might want to show something
like this::
<< < ... 4 5 (6) 7 8 .. > >>
In this example `6` would be the current page and we show 2 item... | 28a18ff5e998ed6b5eb7ec7a0aaf540037ac1946 | 17,870 |
import math
def _scale_gaussian_param(snr, data):
"""
A helper function to convert given gaussian parameters in SNR dB
according to standard deviation, and scale to correct values
according to given data set features.
"""
return math.sqrt(data.std() ** 2 / math.pow(10, snr / 10.0)) | e08c8fe67ef37cfe98c9bae35be86818cea541ff | 17,872 |
def purify(dirty_word):
"""
Очищає від пробільних символів та конвертурє в lowercase
"""
purify = dirty_word.strip().lower()
for i in ",.[]_()'":
purify = purify.replace(i, '')
if not purify:
raise ValueError("Не може бути пустий рядок")
return purify | 2d1ad098d971d5473cadea4463893d26f1fa50d0 | 17,874 |
import logging
def create_tair10_featureset(
genes, config, dfu, gsu
): # pylint: disable=too-many-locals
"""Create an Arabidopsis thaliana featureset from a list of genes."""
params = config.get("params")
workspace_id = params["workspace_id"]
genome_ref = "Phytozome_Genomes/Athaliana_TAIR10"
... | c42a01cdc1ceef25806cd8055d6e6cf30a93fd40 | 17,875 |
import requests
def get_ticket(tgt: str) -> str:
""" Get ticket """
params = {'service': 'http://umlsks.nlm.nih.gov'}
headers = {
'Content-type': 'application/x-www-form-urlencoded',
'Accept': 'text/plain',
'User-Agent': 'python'
}
req = requests.post(tgt, data=params, hea... | 52adcb7d87c97f3d0706260e972cc25caadc362e | 17,876 |
def get_solved (sol_dict):
"""Returns the solved variables of a solution dictionary"""
return filter(lambda k: sol_dict[k] is not None, sol_dict) | a712caa09be029f0ad7054248cce7762644a6644 | 17,877 |
def generate_legend_marker_colour_orders(plot_order, method_legend_colour_marker_dict):
""" Generates a list of legends, colours, and markers based off the dictionary. """
plot_legends = [method_legend_colour_marker_dict[meth]['legend'] for meth in plot_order]
plot_colours = [method_legend_colour_marker_dic... | 60d957517f97a7ba5c78aa31ea4f222d37ad7195 | 17,879 |
import os
def create_dir(*args) -> str:
"""Creates directory if it does not exist yet. Recursive.
Input:
- unknown number of string parameters
Output:
- names: full path name
"""
names = os.path.join(*args)
if not os.path.exists(names):
os.makedirs(names, exist_ok=Tru... | 209c292192751f69b19e097908b64f91420ff8b4 | 17,880 |
def strip_stac_item(item: dict) -> dict:
"""
Strips a stac item, removing not stored fields
:param item dict: input stac item
:rtype: dict
:return: stripped stac item
"""
strip = item
s3_key = None
for link in item["links"]:
if link["rel"] == "self":
s3_key = li... | 1909b44f316875f0cd0d65fff8bd62329cd229e5 | 17,881 |
import numpy
def sort_visibility(vis, order=None):
""" Sort a visibility on a given column
:param vis:
:param order: Array of string of column to be used for sortin
:return:
"""
if order is None:
order = ['index']
vis.data = numpy.sort(vis.data, order=order)
return vis | c5f7f835c2cff1bb4d0daac5fda85af77ab09e74 | 17,882 |
def no_zipped():
"""
No-zipped strings
"""
return [
('', []),
('123', [123]),
('123,456', [123, 456])
] | 9aa18599d98f9d22e5597cc6078489617fb1e3aa | 17,883 |
import subprocess
def execute_cmdline(lst, output):
"""execute_cmdline(lst: list of str)-> int Builds a command line
enquoting the arguments properly and executes it using popen4. It
returns the output on output. popen4 doesn't return a code, so it
will always return 0
"""
proc = subprocess.P... | 769d5aab23b416894933fcd59dbba7559fdbe2d6 | 17,886 |
def mul(a, b):
"""
>>> mul(2, 3)
6
>>> mul('a', 2)
'aa'
"""
return a * b | 990465cb677ea9b0f848b0a9bfc6bfdc5d8b373f | 17,887 |
import numpy
def gsim_imt_dt(sorted_gsims, sorted_imts):
"""
Build a numpy dtype as a nested record with keys 'idx' and nested
(gsim, imt).
:param sorted_gsims: a list of GSIM instances, sorted lexicographically
:param sorted_imts: a list of intensity measure type strings
"""
dtlist = [(i... | e5a885efc5f404ef19f931ebe194141c88980c46 | 17,888 |
def prepare(raw_input):
"""
Input is organized in three chunks: (1) rules, (2) my ticket, (3) tickets nearby.
Must be prepared following different rules.
(1) label ':' lower 'or' upper ',' lower 'or' upper
(2) header line "your ticket:" followed by one line of comma separated integers
... | a784da2ad5ef864d3114187766acd8af2b69b868 | 17,889 |
import codecs
def rot_13(char):
"""Special case of shift alphabet by half."""
return codecs.encode(char, "rot_13") | 7a08262ece3c2151cfdf7ac66361802aa93c6ee1 | 17,890 |
import os
def list_files(camera, path="/"):
"""List all files in a camera directory."""
result = []
# get files
for name, value in camera.folder_list_files(path):
result.append(os.path.join(path, name))
# read folders
folders = []
for name, value in camera.folder_list_folders(path)... | 42060038d3645badb5bc9a7121331024deb813e0 | 17,892 |
import os
def __get_files(root_dir, file_types, filters):
"""__get_files.
file_types = ['.css', '.js', '.htm']
filters = ['', '.min.', 'sweet-alert']
"""
def is_vaild_file(filename, file_types):
if not file_types:
return False
for x in file_types:
if filen... | 95b7c8c4057b724d46e15d4a73b7a213c5f9dd40 | 17,894 |
def string_empty(string: str) -> bool:
"""Return True if the input string is None or whitespace."""
return not (bool(string) or isinstance(string, str) and bool(string.strip())) | cca19df1eda7039f7299c49fcb9832ce11847524 | 17,895 |
import sys
def src_mul_edge(src, edge, out):
"""Builtin message function that computes message by performing
binary operation mul between src feature and edge feature.
Notes
-----
This function is deprecated. Please use :func:`~dgl.function.u_mul_e` instead.
Parameters
----------
src... | 4a703a09b0ebce8fb9cdf24739d8449873bf91b6 | 17,896 |
def get_attr_flows(results, key='variable_costs'):
"""
Return all flows of an EnergySystem for a given attribute,
which is not zero.
Parameters
----------
results : dict
Results dicionary of the oemof.solph optimisation including the
Parameters with key 'param'.
key : str
... | 756ec66cdf7b01cdbc6b872b4f30cf27e4ff524f | 17,897 |
from typing import Callable
import hmac
import hashlib
def generate_hash_key(chain_url: str, privkey: bytes, strategy: Callable):
"""Generate a hash key to use as `client_id`, using the :mod:`hmac` library.
The message is the concatenation of `chain_url` plus the `__name__` attribute of the
`strategy`.
... | 1bb6b69f06c6ecb245b8ea8b4c772ede872c460c | 17,898 |
import hashlib
def hash(filepath):
"""
function responsible for generating a hash of a given file in SHA256.
param filepath: directory where the file is located.
return: SHA256 requested file hash
"""
with open(filepath, 'rb') as stream:
hash = hashlib.sha256(stream.read())
retu... | 320bcb258a5eb13e29c1f53c0caa4d3ed0b33a5e | 17,899 |
def _rename_artifact(ctx, tpl_string, src_file, packaging_type):
"""Rename the artifact to match maven naming conventions."""
artifact = ctx.new_file(ctx.bin_dir, tpl_string % (ctx.attr.artifact_id, ctx.attr.version, packaging_type))
ctx.action(
inputs = [src_file],
outputs = [artifact],
... | 6c5bf6928e79bfaf20f222bea9815643aaff3dc5 | 17,901 |
def get_config_data(config_data):
"""
Parameters
----------
config_data : list containing config parameters
Returns
-------
[config parameters] : various parameters and values from the config file
"""
exp_type = config_data['RobotSettings']['commandFile']
reward_dur = config_da... | b6f8199547d8177660336c8c0aab09deddf96118 | 17,902 |
import socket
import struct
import random
def randip():
"""Return random IP address
Returns:
str -- IP address
"""
return socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff))) | e1baec43b7616a7f7345d5bf83c79f868bf95c80 | 17,903 |
def dumb_portfolio_evaluate(assets, weights):
"""
Takes weighted sum of asset reward and risk.
:param assets: Cassandra ORM model for asset stat table.
:param weights: Vector of weights for each asset (should sum to 1)
:return: Dictionary containing portfolio reward, risk and weight vector.
"""
... | 6945974d40247d585a5595a5eb7b0e5ff4625e41 | 17,904 |
import six
def is_list_of_strings(vals):
"""Returns True if val is a list (or enumerable) of strings. False otherwise"""
try:
# check if everything is a string
for val in vals:
if not isinstance(val, six.string_types):
return False
except:
# vals is not... | 61c48b7b43acc1ab8f86c47273606a830ccb0bab | 17,905 |
def clean_url(raw_url):
"""
Returns a clean URL from garbage
"""
return 'https' + raw_url.split(' https')[1].split('#')[0] | f34581e230182c026ff26d2f8e8da91137417930 | 17,907 |
def removeSearchIndice(doc):
""" Remove search indices for isotopes Uranium and Thorium """
if (doc.has_key("sort_indices")):
del doc["sort_indices"]
return doc | cd0239b9e96d3eed70fbf41b5d0aec9bd7589c35 | 17,908 |
def getPruning(table, index):
"""Extract pruning value"""
if ((index & 1) == 0):
res = table[index // 2] & 0x0f
else:
res = (table[index // 2] & 0xf0) >> 4
return res
# return table[index] & 0xf | 45e9e81bef153edfa7003f5256a3e9b169a6a2c0 | 17,909 |
import torch
def append_homog(tensor: torch.Tensor, homog_value: float = 1.) -> torch.Tensor:
"""Appends a homogeneous coordinate to the last dimension of a Tensor.
Args:
tensor: A Tensor.
homog_value: Value to append as homogeneous coordinate to the last dimension
of `tensor`. (Default: 1.0... | d07361ded84608d0aa2d4587b5418be0a6f5c395 | 17,910 |
def get_fitness(solution):
"""Return the fitness value of the passed solution"""
if not solution:
return 0
# the fitness of a valid solution coincides with its value
return solution.value | bd3abcb2600ee074ce33b543c7a19b58924e3415 | 17,911 |
def sortByHeight(a):
"""
>>> sortByHeight([-1, 150, 190, 170, -1, -1, 160, 180])
[-1, 150, 160, 170, -1, -1, 180, 190]
"""
tree_positions = sorted([index for index, value in enumerate(a) if value == -1])
a = sorted(a)[len(tree_positions) :]
for tree_pos in tree_positions:
a.insert(tr... | a98de199fc5a9580986b91548693fe05f60f2340 | 17,912 |
def white_spaces(x):
"""
Blank Spaces
"""
x -= 2
espac = ' ' * x
return espac | a9a7af435add1400429116b04884cac3241d9c8b | 17,913 |
def pretty_size(size, unit=1024):
"""
This function returns a pretty representation of a size value
:param int|long|float size: the number to to prettify
:param int unit: 1000 or 1024 (the default)
:rtype: str
"""
suffixes = ["B"] + [i + {1000: "B", 1024: "iB"}[unit] for i in "KMGTPEZY"]
... | abeafa97d45212c0170b981e9448e63acc1a54d2 | 17,914 |
import copy
def json_row_to_dict(row):
"""Convert a sqlalchemy row object into a plain python dictionary.
Assumes that row object contains the following columns:
- id (int(64))
- version (int(64))
- data (JSON) Contains the rest of the fields as a single JSON column in postgres
Args:
... | 902d45a9beb717e56ad8d8468eb0815b9171013c | 17,915 |
import logging
import requests
def request_image(image_url):
"""Attempts to download the file at the URL specified and, if available,
returns it as a raw response object."""
if image_url is None:
logging.error("Image URL is None")
return None
logging.info(f"Downloading roll image {ima... | c5d0847859b9e036ebf0121f1c8a71492d0923f6 | 17,916 |
import binascii
import os
import requests
import base64
def test_kvstore(put_host_addr, get_host_addr):
"""Executes a simple test against the key/value store running on the given
Tendermint node."""
url = "http://%s" % put_host_addr
# generate a random hex value to send through to the kv store
te... | 5386e80439490f3180cbf6dcbee673b2ba2d6ba8 | 17,917 |
def phrase_feature(sentences, phrase_list):
""" List of values from 0 to 1 rating the number of phrases that appear in the sentence from a list """
total_number_words = 0
phrase_frequency = []
# Calculate the number of words of the text
# Number of phrase that appear in that sentence
for sent... | 36d21a6dfd0c7beefa1739e522783d2ecc6241cb | 17,918 |
def set_title(title=None, property_name=None, channel=None):
"""Set title for map.
Parameters:
title (str):
If ``None``, try to set automatically from property (and channel)
name(s). For no title, set to ''. Default is ``None``.
property_str (str):
Map proper... | 6483c8df9fafaa7e46ef667801a24a921ae871da | 17,919 |
from pathlib import Path
def ready_for_postinstall(chroot):
"""True if the chroot path exists and nothing mounted inside, False otherwise"""
path = Path(chroot)
return path.exists() and not any(path.iterdir()) | c684cf9f4940f4f6e102752a2456737b5de56cff | 17,920 |
import sys
def modules(modulePath):
"""Load a module and retrieve a reference to that module."""
__import__(modulePath)
return sys.modules[modulePath] | f25fe4f7ce16086949583e69bc7d60537b2cdaab | 17,921 |
def null_action(env, ob):
""" Do nothing. """
if hasattr(env.action_space, 'n'): # Is descrete
return 0
if hasattr(env.action_space, 'low') and hasattr(env.action_space, 'high'): # Is box
return (env.action_space.low + env.action_space.high) / 2.0 # Return the most average action
rais... | 1ed066f6719af853a539ee077a47320d84bf8bfd | 17,922 |
def transition_model(corpus, page, damping_factor):
"""
Return a probability distribution over which page to visit next,
given a current page.
With probability `damping_factor`, choose a link at random
linked to by `page`. With probability `1 - damping_factor`, choose
a link at random chosen fr... | c7ea20809acce0f9290f3b5890122c7d34acd416 | 17,923 |
import uuid
def new_uuid():
"""Return a string UUID."""
return uuid.uuid4().hex | cdbe6cb239d719b0a6a31be60bcb8585971a6e1c | 17,924 |
import torch
def generate_spixel(logits, img_in):
"""
generate superpixels (Not used)
Args:
logits: torch.Tensor
A Tensor of shape (b, nSpixel, h, w)
that could be regarded as a soft assignment matrix
img_in: torch.Tensor
A Tensor of shape (b, c, h*w)
... | 6f8c24dde059203bb52028747191161fa90b0d9f | 17,925 |
def is_developer_certificate_getter(self):
"""Return whether this certificate is a developer certificate or not.
:param self: Instance of the entity for which this is a custom method.
:type self: mbed_cloud.foundation.TrustedCertificate
:return: True if a developer certificate, False otherwise.
:r... | cebb9ba74150c0a9ae5d3fb2b99e504977525b1f | 17,927 |
from typing import OrderedDict
def dismantle_dict_values_to_deep_list(dict_):
""" returns a list of dict values even if the values of the dict are dicts again. """
dict_ = OrderedDict(sorted(dict_.items()))
return [val if not isinstance(val, dict) else dismantle_dict_values_to_deep_list(
val) ... | 045268625aa63266ef988fb56ae9eaeb329ac412 | 17,928 |
import os
def get_whence_string(whence):
"""Retrieves a human readable string representation of the whence."""
if whence == os.SEEK_CUR:
whence_string = "SEEK_CUR"
elif whence == os.SEEK_END:
whence_string = "SEEK_END"
elif whence == os.SEEK_SET:
whence_string = "SEEK_SET"
else:
whence_strin... | b02cc04ddfb7b028d626f750ea3da612e908b542 | 17,929 |
def average_speed(s1 : float, s0 : float, t1 : float, t0 : float) -> float:
"""
[FUNC] average_speed:
Returns the average speed.
Where:
Delta Space = (space1[s1] - space0[s0])
Delta Time = (time1[t1] - time0[t0])
"""
return ((s1-s0)/(t1-t0)); | 8125fb0454433288b506ffd277fa6b1bd21b06c9 | 17,930 |
from typing import Coroutine
from typing import Any
import asyncio
def await_async(task: Coroutine[Any, Any, Any]) -> Any:
"""Await async task in sync function.
Parameters
----------
task : Coroutine
task to be awaited, eg f() where f is async function.
Returns
-------
Any
... | 9dc6c3301dcc91036e05059b695b3edba9de61a1 | 17,931 |
def multiply2by2Matricies(A, B):
"""This performs matrix multiplication in only 7 multiplies."""
##Thank you the internet and Strassen...
M_1 = (A[0][0]+A[1][1])*(B[0][0]+B[1][1])
M_2 = (A[1][0]+A[1][1])*B[0][0]
M_3 = A[0][0]*(B[0][1]-B[1][1])
M_4 = A[1][1]*(B[1][0]-B[0][0])
M_5 = (A[0][0]+A... | cfdf29632265c1161ea7808aa9241c04c0cb47ed | 17,932 |
from argparse import ArgumentParser
from pathlib import Path
def parse_args_berry(args):
"""Argument parser for `berry` subcommand."""
parser = ArgumentParser(prog='pwproc berry')
parser.add_argument('in_file', nargs='+', type=Path)
parser.add_argument('--phase', type=Path)
parser.add_argument('-... | de7ca37b6882154c2da49820ef8c8f373775d11e | 17,933 |
import json
def wrap_error_data(mes):
"""包装错误消息"""
return json.dumps({
'mes': mes
}).encode() | dfc1274d38859fc15d06474b34336f9af132a694 | 17,936 |
def create_arrays_from_input(dir_arr):
"""
This function gets:
:param dir_arr: an array of 24 strings: matchsticks' directions: up('U')/down('D')/left('L')/right('R')
:return: 3 arrays of 24 integers:
Each index represents a matchstick
The values represent rows, columns and diagonals: matchstick... | d16f1bd28d53d92dff675defff2e91a1bedf5f55 | 17,937 |
def multiline_rstrip(s: str) -> str:
"""
Takes a multiline string and returns a copy with trailing spaces from all lines
removed.
"""
return "\n".join((l.rstrip() for l in s.splitlines())) | 51ee39528918e1a5a35f840d1524a17941a7a170 | 17,938 |
import sys
def strip_indent(s):
"""
Given a multiline string C{s}, find the minimum indentation for
all non-blank lines, and return a new string formed by stripping
that amount of indentation from all lines in C{s}.
"""
# Strip indentation from the template.
minindent = sys.maxsize
lin... | ca128a349bb9f0a1538e9fc8e3638b7f64806538 | 17,939 |
import socket
import struct
def send_packet(mac_str):
"""Send magic packet to given mac address
:param mac_str: mac address string separated by :
:return:
"""
def broadcast(magic):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADC... | cd6a8fe49d43b1970995068302f611839b454187 | 17,940 |
import argparse
def parse_args(args):
"""
Parse and return command-line arguments.
"""
parser = argparse.ArgumentParser(
description="Execute clang-format on your working copy changes."
)
parser.add_argument(
"-d",
"--diff",
action="store_true",
default=... | a5663ab8c1df586b334d5a608a7ccc8c46d83a31 | 17,941 |
def gaussian2D_from_shape(shape = (100,100), amplitude = 3000, position = (100,100), sigma = (5,5), dtype = 'uint16'):
"""
return 2D gaussian function in a given 'position' on the provided image. The input image can be made of all zeros.
"""
from numpy import sqrt,exp,copy,zeros
r_mu = position[0]
... | 9557b6df7ae575740be97e21cca8065561051ed8 | 17,942 |
import hashlib
def hash_file(file_content):
"""Create an md5 of file contents"""
the_hash = hashlib.md5(file_content.encode('utf-8'))
return the_hash.hexdigest() | ba3b84edb78ccb70e4fb37b8cc6c8eb73c0d108b | 17,944 |
def visit(event, *args):
""" This decorator is used to indicate which nodes the function should
examine. The function should accept (self, node) and return the relevant
node or None. """
def _decorate(fn):
fn._visit_event = event
fn._visit_nodes = args
return fn
return _decor... | a2ee19945446d100e3282f5cb5bc080ff4e568c2 | 17,945 |
from datetime import datetime
def unrets_date(rets_date):
"""
Converts a RETS date (ISO 8601 format) into a Python datetime
:param rets_date: a RETS/ISO 8601 date
:type rets_date: str
:rtype: datetime.datetime
:return: rets_date as a Python datetime
"""
# For datetimes with microsecon... | 9f8cae6880ac4d2f285eff856db09da0a39ec4ee | 17,946 |
def compute_mae(y_pred, y, center_to_border_dict=None):
"""
Returns the absolute distance of predicted value to ground truth.
Args center_to_border_dict is for compatibility issues in quanfification error analysis.
"""
return abs(y_pred - y) | a28f638779aa11dafdfb8d430eb0ad1a5515aefa | 17,947 |
def add_nones(word):
"""Change word into a list and add None at its beginning, end, and between every other pair of elements. Works whether the word is a str or a list.
"""
def yield_it(word_string):
yield None
it = iter(word_string)
yield next(it)
... | 63c8437361f2f0cc200665d7cdf6a41aab7eaf67 | 17,948 |
import sys
def is_py3():
"""
Function for checking if we are in python3. This is used in other
part of Bip for compatibility between python2 and python3.
"""
return sys.version_info[0] == 3 | 5264206d68c4a77aa9243ce97f95819941146555 | 17,949 |
import six
def make_key(*args, **kwargs):
"""
Given any number of lists and strings will join them in order as one
string separated by the sep kwarg. sep defaults to u"_".
Add exclude_last_string=True as a kwarg to exclude the last item in a
given string after being split by sep. Note if you on... | b5c48386304ab248518a7330605fbcfb37ecad23 | 17,950 |
def has_restart_file(job):
"""Check if the job has a restart file."""
return job.isfile("fort.77") | d6d5bd748722ab5bdc83461728d5a02e539d25ed | 17,951 |
from typing import List
def fixture_sample_tag_names(vcf_tag_name: str, sample_tag_name: str) -> List[str]:
"""Return a list of the sample tag names"""
return [vcf_tag_name, sample_tag_name] | 40f38b1c5e17254b1a0c9974216b98bdc8d27c43 | 17,952 |
import hashlib
def compute_file_checksum(path):
""" Compute a SHA1 checksum for a file. """
with open(path, 'rb') as f:
checksum = hashlib.sha1(f.read()).hexdigest()
return checksum | d253d98039a916be19ee3ad1c3d050b2dd251c1e | 17,955 |
def get_default_titles(combine, plot_data, nfunc_list, **kwargs):
"""Get some default titles for the plots."""
adfam = kwargs.pop('adfam', False)
adfam_nn = kwargs.pop('adfam_nn', False)
true_signal = kwargs.pop('true_signal', True)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.forma... | 236b29386f2ea4c38e803240a2a7fa167336c952 | 17,957 |
def FillAbstractObject(service, objectType, valueDict):
"""This method is useful for creating the "cartItems" and "payments" fields of
the CheckoutShoppingCart method. It takes in the array currently being built,
the name in the WSDL of the element to be added (e.g. DebitAccountInfo for payments
... | d2a8d7625c05a70cad7e0e9a359e1326973ea3ff | 17,958 |
import subprocess
def get_file_contents(branch, path):
"""Get the contents of a file on a particular branch."""
result = subprocess.run(
['git', 'show', f'{branch}:{path}'],
check=True,
capture_output=True,
)
return result.stdout.decode('utf-8') | 9e92f041cef6e82ec48f66aadf22d296321a4c8d | 17,959 |
import win32api, win32process
from typing import Optional
def _set_win_process_priority() -> Optional[bool]:
"""
Sets the process priority class to an elevated value.
Microbenchmarks are typically very short in duration and therefore are prone
to noise from other code running on the same machine. Set... | c69e2ffcf1de40507f77113ea9d4a15730ed3f1a | 17,960 |
import random
def find_junk(a, nodes, edge_list, cur_cci_junk):
"""
"""
c = random.choice(nodes)
while [a, c] in nodes or [a, c] in cur_cci_junk:
c = random.choice(nodes)
return a, c | 258cea57cbff782a4d26863f46c31483e0263e6a | 17,962 |
def linear_interp(x, in_min, in_max, out_min, out_max):
""" linear interpolation function
maps `x` between `in_min` -> `in_max`
into `out_min` -> `out_max`
"""
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min | eff41353ee48e1c2b1372030fa5480ce8e3bb817 | 17,963 |
def get47Dfeatures():
"""
Returns list containing the names of the 47 features found in the data accessible through
`ttbarzp.import47Ddata()`
"""
return [
'pT b1', 'pT b2', 'pT b3', 'pT b4',
'sdEta b1 b2', 'sdEta b1 b3', 'sdEta b1 b4', 'sdEta b2 b3', 'sdEta b2 b4', 'sdEta b3 b4',
... | de433bf6e326978bf78205b7ed513a191a424c3b | 17,964 |
def lrange(*args):
"""For compatibility with range() in python 2"""
return list(range(*args)) | 5b70d400cd9725284f9ba7b6d512386988f00b2e | 17,965 |
def migrate_autoload_details(autoload_details, shell_name, shell_type):
""" Migrate autoload details. Add namespace for attributes
:param autoload_details:
:param shell_name:
:param shell_type:
:return:
"""
mapping = {}
for resource in autoload_details.resources:
resource.model... | f316a0a63520a9b245d3000d23181c2fff3b2292 | 17,966 |
def new_list(a):
"""
Converts lists into number format with minimal decimal places
:param a: list
:return: new list with floats
"""
b = []
for i in a:
b.append(float(format(i, ".2f")))
return b | f1f80ea44f58f0780f02e8df698dbeb81d7ac934 | 17,967 |
def z2g(r_geoid, g0, z):
"""Calculate gravitational acceleration at elevation
Derived from atmlabs equivalent function
https://www.sat.ltu.se/trac/rt/browser/atmlab/trunk/geophysics/pt2z.m
:param r: surface radius at point [m]
:param g0: surface gravitational acceleration at point [m/s^2]
:par... | c04080156670e137f56ba4dfc872530bbada4d27 | 17,969 |
import re
def a_bytes_copied(plugin_ctx, fsm_ctx):
"""Capture number of bytes copied."""
m = re.search(r"\d+ bytes copied in .* secs", fsm_ctx.ctrl.before)
if m:
plugin_ctx.info('{}'.format(m.group(0)))
else:
plugin_ctx.info('{}'.format(fsm_ctx.ctrl.before))
return True | 5b5f9135660a0ab7e634b2b0630f8af47ae02dd5 | 17,970 |
def get_crawled_date(df):
""" Extract crawled date from the 'scrape_id' field. """
df['crawled_date'] = df['scrape_id'].astype(str)
df['crawled_date'] = df['crawled_date'].apply(lambda x: x[:8])
return df | af5242fa98de713eaa0bbd8684f797b5db563033 | 17,971 |
import random
import math
def box_optimizer(f, starting_point, gs=[], x_range=[-1000, 1000], alpha=1.3, epsilon=1e-6, limit_iter=-1):
"""Finds minimum for function for given restrictions
Args:
f (TargetFunction): [function for which minimum needs to be found]
starting_point ([list]): [starti... | 9ff50db7711d2d94025bd956278749d6c59547c6 | 17,972 |
async def add_future_callback(fut, success_callback, fail_callback=None, need_fut_as_success_cb_args=True):
"""
adding a callback after future completed
:param fut:
:param callback:
:param args:
:return:
"""
try:
result = await fut
if need_fut_as_success_cb_args:
... | a42c8e2cc31d91da7333842710ed8677cabb1baa | 17,973 |
from typing import Union
from typing import Callable
from typing import List
from typing import Tuple
def make_cmd(
to_fn_call: Union[str, Callable[[List[str]], str]], arity: int
) -> Tuple[str, int]:
"""
Returns a tuple with the transpiled command and its arity.
:param to_fn_call
If Callable, ... | bf71c9cb40aee40df3cee1ee08e156bca62091ff | 17,974 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.