content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def air2vacMortonIAU(wl_air):
"""Take an input air wavelength in Angstroms and return the vacuum
wavelength.
Formula taken from
https://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion
"""
s = 1e4 / wl_air
n = 1 + 0.00008336624212083 + (0.02408926869968 / (130.1065924522 - s**2))\
... | 66823170493c3b7d8f63bd7d2e32364aa5efa78e | 702,513 |
def instanceType(ty):
""" Return the type of an object as a string. """
#print(type(ty).__name__)
return type(ty).__name__ | 8a259626163100ac5e85f1bf26ea5f531405e6da | 148,843 |
def on_off(tag):
"""Return an ON/OFF string for a 1/0 input. Simple utility function."""
return ['OFF','ON'][tag] | 9b21150c4ff8c1533f536d9b95ee467c11f45c89 | 455,644 |
def extract(values, label, raise_error=True, default_value=None):
"""Create a flat dictionary from a nested one. The resulting dictionary
contains the same keys as the input dictionary. The associated values are
the values from the nested dictionaries under the given label.
If a nested value does not c... | 90716781be11e8b4a2db4b23df734cbe12186fec | 283,741 |
def exists(env):
""" Check if `gtags` module has been loaded in the environment """
return env['GTAGS'] if 'GTAGS' in env else None | 8feb1b08e24cd77c8f954c113f9fa6241496318d | 646,801 |
def effort_std(df):
"""Standard deviation of the effort."""
return df["e2"].std() | 033eed35c4bb7612f99f745ffa6fa17601a79df2 | 454,399 |
from typing import Dict
def freq_dict_to_lowercase(input_dict: Dict[str, int]) -> Dict[str, int]:
"""Takes a dictionary of string to value, and returns one where the keys are all mapped to
lowercase and the values are the sums of all the values mapped in this way."""
output_dict = {}
for item in input... | 0ce5348e32104c2ff5e258798b4a22312dc6192d | 498,628 |
def force_to_energy_grad(dataset):
"""
Converts forces to energy gradients in a dataset. This conforms to
the notation that a key with `_grad` is the gradient of the
property preceding it. Modifies the database in-place.
Args:
dataset (TYPE): Description
dataset (nff.data.Da... | 584095bea241bd2a08b8b99824d5ef9aa2b1499e | 90,883 |
def format_error(string: str, is_warning: bool) -> str:
"""
Formats a given message in an error color using ANSI escape sequences
(see https://stackoverflow.com/a/287944/5299750
and https://stackoverflow.com/a/33206814/5299750)
:param string: to be printed
:param is_warning: determines the color... | b1bd11cbb24c0b511656336b4c4b8ec510671b74 | 193,657 |
import json
def handle_exception(e):
"""Return JSON instead of HTML for HTTP errors."""
# start with the correct headers and status code from the error
response = e.get_response()
# replace the body with JSON
response.data = json.dumps(
{"code": e.code, "name": e.name, "description": e.des... | 5ea827253deba3d36f4902d556511ccc99431646 | 429,602 |
def force_unicode(value, encoding='utf-8', errors='strict'):
"""
Convert bytes or any other Python instance to string.
"""
if isinstance(value, str):
return value
return value.decode(encoding, errors) | b681d5b331c5cda6192c38ebd931c5ffec591692 | 339,000 |
def _recvall(sock, size):
"""
Read exactly the specified amount of data from a socket. If a
``recv()`` call returns less than the requested amount, the
``recv()`` is retried until it either returns EOF or all the
requested data has been read.
:param sock: A socket from which bytes may be read.... | 6a456ee4925b7faa25646e9bc6e702848d047783 | 13,354 |
def unwrap_links(soup):
"""
unwrap <a> elements (remove links) if link target contains
removed directories: players/ leagues/ coaches/ teams/
returns a tuple:
(soup, n_unwrapped_links)
"""
unwrapped_links = 0
hrefs = soup.body.find_all('a')
for elem in hrefs:
if (
... | 76c20988294f984aa7fb396538b2ad58dee911c0 | 168,382 |
from typing import List
import yaml
def assemble_container_names(validated_compose_content: str) -> List[str]:
"""returns the list of container names from a validated compose_spec"""
parsed_compose_spec = yaml.safe_load(validated_compose_content)
return [
service_data["container_name"]
for... | ea213cc4dc54d4da1fb50c9a855818db2c142d98 | 383,566 |
def get_confirmation(warningtext):
"""
Prints a warning message and asks for user confirmation
Return Values:
True: User selected Yes
False: User selected No
"""
print()
print(warningtext)
while True:
try:
user_input = input("Please confirm (Y/N): ")
... | d34f66935d199b5cf230691bb197f0d9f4b78370 | 661,847 |
def is_enum_namestack(nameStack):
"""Determines if a namestack is an enum namestack"""
if not nameStack:
return False
if nameStack[0] == "enum":
return True
if len(nameStack) > 1 and nameStack[0] == "typedef" and nameStack[1] == "enum":
return True
return False | e5d909ad2380dcc5186c377d0440c34159c0b628 | 468,676 |
from typing import Union
import pathlib
def get_gecko_version_from_path_gecko_msi_filename(path_gecko_msi_filename: Union[str, pathlib.Path]) -> str:
"""
wine_gecko-2.47-x86.msi --> 2.47
>>> assert get_gecko_version_from_path_gecko_msi_filename(pathlib.Path('wine_gecko-2.47-x86.msi')) == '2.47'
"""
... | 7e0c9aa13450d4aeb9b277d01b06023ae0a6454f | 441,079 |
def get_header_tokens(headers, key):
"""
Retrieve all tokens for a header key. A number of different headers
follow a pattern where each header line can containe comma-separated
tokens, and headers can be set multiple times.
"""
if key not in headers:
return []
tokens = h... | 9a89d77543fa58d6841e7a48b3a08b2f5cb1b7e4 | 408,599 |
def _get_identifier(obj):
"""
Gets the name of the identifier defined by an object with either an 'identifier' attribute or
a 'typed_identifier' attribute.
"""
if hasattr(obj, 'identifier'):
return obj.identifier
if hasattr(obj, 'typed_identifier'):
return obj.typed_identifier
... | dee249361e96e784047df57efb07e18688abaadf | 70,700 |
def s2ms(t):
"""Convert seconds to milliseconds."""
return t * 1000 | f2cc135c59d2694a08abc4f8c4088cabcd12664b | 150,161 |
def signabs(x):
"""
Split x into its sign and absolute value.
Returns a tuple (sign(x),abs(x)). Note: sign(0) = 1, unlike
numpy.sign.
"""
if x < 0:
sgn = -1
else:
sgn = 1
return sgn,abs(x) | 9a12328734a3952bfcb18239e4700b5bffe323f1 | 193,644 |
def format_plaintext_email(message):
"""Replace \n by <br> to display as HTML"""
return message.replace('\n', '<br>') | 88a753dd33dcf9a1432547ab0c9d27edd546e9db | 376,168 |
import re
def id_validator(s):
""" A valid UID must follow the rules below:
It must contain at least 2 uppercase English alphabet characters.
It must contain at least 3 digits (0-9).
It should only contain alphanumeric characters (a-z, A-Z & 0-9).
No character should repeat.
There must be exa... | c601dd2cd2bd5a2e5f616151c03b51580be5632b | 512,574 |
import math
def transmon_perturbative(tmax, omega_q, eta, g):
"""Produce energies and cuplings of the transmon perturbatively
Uses an anharmonic approximation of the transmon to get the energies
Args:
tmax (int): maximum number of transmon levels
omega_q (float): qubit frequency, eta... | bd15dfff9e391b8455a608bb2f0397f8ecb438f1 | 307,245 |
def Strip(txt):
"""Return stripped string, can handle None"""
try:
return txt.strip()
except:
return None | 44edfab97b1cdbfec4174cf554c78077fb31cfd7 | 693,601 |
def is_a(cls, x): # noqa: F811
"""
Check if x is an instance of cls.
Equivalent to isinstance, but auto-curried and with the order or arguments
flipped.
Args:
cls:
Type or tuple of types to test for.
x:
Instance.
Examples:
>>> is_int = sk.is_a(... | 1af08973716c16d6ee673904af5cbeddff0ef386 | 138,713 |
def align_up(offset, align):
"""Align ``offset`` up to ``align`` boundary.
Args:
offset (int): value to be aligned.
align (int): alignment boundary.
Returns:
int: aligned offset.
>>> align_up(3, 2)
4
>>> align_up(3, 1)
3
"""
remain = offset % align
if ... | f74c2c3fba775d6bb15b7faf369e8706ecccc610 | 645,556 |
def flatten(tensor):
"""Returns a copy of the tensor flatten into one dimension.
Args:
tensor (ndarray): tensor to flatten
Returns:
ndarray: flattened tensor
"""
return tensor.flatten() | bc632301578df0896d98574175358f8cc8057613 | 241,532 |
def get_factory_name(factory):
""" Returns a factory name, given the factory. This ensure that something
will be displayed (id or name of the factory) even if no name has been
specified for the factory """
name = factory.name.strip()
if len(name) != 0:
return name
else:
return fa... | e3c626097c77f34dacab947072186582596bab0a | 82,973 |
import functools
def has_default_decorator(decorator_factory):
"""A meta-decorator for decorator factories.
This decorator of decorators allows a decorator factory to be used
as a normal decorator (without calling syntax).
A single non-keyword argument (with no keyword arguments) will be
conside... | 0a20270c02880445e880f395c9422ac5c6ab25d3 | 120,957 |
def get_coord_axes(path):
"""Return the number of atoms and the axes corresponding to atoms
and coordinates for a given path.
The `path` is assumed to be a :class:`numpy.ndarray` where the 0th axis
corresponds to a frame (a snapshot of coordinates). The :math:`3N`
(Cartesian) coordinates are assume... | 1d8e3239c0361e7671ada05ebc28948ec2334d5f | 401,767 |
def _transform_hostname_to_http_endpoint(hostnames):
"""Convert hostnames to status page endpoint.
Args:
hostnames: List of server names
Returns a list of urls in the format "http://<hostname>/status"
"""
return ["http://{}/status".format(server) for server in hostnames] | e0921161f25b98c62199bb7e0da33d07ee3da9c1 | 614,878 |
def filters_from_args(request_args):
"""
Helper to centralize reading filters from url params
"""
timespans_id = request_args['timespanId'] if 'timespanId' in request_args else None
snapshots_id = request_args['snapshotId'] if 'snapshotId' in request_args else None
foci_id = request_args['focusI... | 9bfee40d13c086f7114c9322ede4fb51a1226ee3 | 327,295 |
import torch
def hard_example_mining(distance_matrix, pos_idxs, neg_idxs):
"""For each anchor, find the hardest positive and negative sample.
Args:
distance_matrix: pair wise distance between samples, shape [N, M]
pos_idxs: positive index with shape [N, M]
neg_idxs: negative index wit... | 00066433a8eb1f5fff5efc3266bfc7a5e91242ca | 425,316 |
import torch
def interp(x: torch.Tensor, xp: torch.Tensor, fp: torch.Tensor) -> torch.Tensor:
"""Interpolate ``x`` tensor according to ``xp`` and ``fp`` as in ``np.interp``.
This implementation cannot reproduce numpy results identically, but reasonable.
Code referred to `here <https://github.com/pytorch/... | b18c373d8d1bfc8da736a0322d6abcc41af3cde0 | 27,279 |
import random
def partitionByState(ser, holdouts=1):
"""
Creates training and test indexes by randomly selecting
a indices for each state.
:param pd.DataFrame ser: Classes for instances
:param int holdouts: number of holdouts for test
:return list-object, list-object: test, train
"""
classes = ser.uni... | c98d7ee7d7ddeafa97285db9df339db1a01a188f | 33,872 |
def _convert_read_lat_to_system_dat(lattice):
"""This method converts the lattice_data dictionary returned by
io_utils.read_lattice to the dictionary structure of io_utils.read_enum_out.
Args:
attice (dict): The io_utils.read_lattice style dictionary with keys:
"sizes": the range of cell ... | 639fe625e309986cef5107e8e3c4bb31d61f8bff | 415,002 |
import hashlib
def create_hash(string, hash_func=hashlib.sha256):
"""
Create a 10-caracters string hash
"""
_hash = hash_func(string)
return _hash.hexdigest()[:10] | e155846f4652e250e7e06bb3a1e74e400e3e3d7c | 282,910 |
import struct
def getpeerid(sock):
""" Get peer credentials on a UNIX domain socket.
Returns a nested tuple: (uid, (gids)) """
LOCAL_PEERCRED = 0x001
NGROUPS = 16
#struct xucred {
# u_int cr_version; /* structure layout version */
# uid_t cr_uid; /*... | 71d8aee0e2495e6fb07311d596a3bbb38675f611 | 422,997 |
import re
def replace_unescaped_utf_8_chars(input_text):
"""
Unescapes characters like "ä" with their equivalents,
e.g. "ö". Only necessary to support Python 2.7+.
"""
pattern = re.compile(r"�(\w{2});�(\w{2});")
def replace(match):
byte_array = bytearray(map(lam... | c5cc78e62e01dcda4343261e840ab38aff375660 | 646,427 |
def removeprefix(string, prefix):
"""Implementation of str.removeprefix() function available for Python versions lower than 3.9."""
if string.startswith(prefix):
return string[len(prefix) :]
else:
return string | 9bb3065a332b78dd868ca2ea7002ca22248b204c | 437,048 |
def meetup_time_format(a_datetime):
"""Format a date/time for Meetup."""
return a_datetime.strftime('%Y-%m-%dT%H:%M:%S.000') | 1310423730c61f8bfb9eda3c6d8aac13ddb645be | 206,249 |
def topHat(r,A0=0.2):
"""Top-hat beam profile as used in Ref. [1].
Args:
r (numpy array, ndim=1): Equispaced 1D grid for radial coordinate.
A0 (float): Top hat width (default: 0.2).
Returns:
f (numpy array, ndim=1): Top-hat beam profile.
"""... | 5bb8a71daf3150d45b6120ce9be692e03e4f4e23 | 663,685 |
def _medgen_url(cui):
"""
URL linkout the NCBI MedGen website.
:param cui: concept unique identifier
:return: str url
"""
return 'http://www.ncbi.nlm.nih.gov/medgen/' + str(cui) | eaf99ee34eb2b7592bc184c9edbecd02c47ca864 | 296,095 |
def java_is_subclass(obj, class_name):
"""Given a deserialized JavaObject as returned by the javaobj library,
determine whether it's a subclass of the given class name.
"""
clazz = obj.get_class()
while clazz:
if clazz.name == class_name:
return True
clazz = clazz.supercl... | 27e26c1211c4ddc2f299e0af6d9c15f03dba8680 | 139,252 |
import math
def elevation_radians(lat, dec, ha):
"""Returns elevation radians."""
return math.asin(math.sin(dec) * math.sin(lat) + math.cos(dec) * math.cos(lat) * math.cos(ha)) | 5bb9b7e1121cfd1d770072bced4d4dfd36880a7b | 176,502 |
def postorder_DFT(tree, nodelist):
""" Post order traversal on binary RST tree
:type tree: SpanNode instance
:param tree: an binary RST tree
:type nodelist: list
:param nodelist: list of node in post order
"""
if tree.lnode is not None:
postorder_DFT(tree.lnode, nodelist)
if tr... | b3b65ce98ceb227ee743b3b40e0ee5f21ed1e56c | 66,050 |
def NORMALIZE_OBSERVATION(obs_b, action_b, rew_b, next_obs_b, done_b):
"""Normalize observation for Atari environments."""
return obs_b / 255, action_b, rew_b, next_obs_b / 255, done_b | f412ce3473e6f7f82b74236ed7a80f8879692125 | 178,634 |
import base64
def is_base64(s):
"""Function to check whether a string is base64 encoded or not
Parameters
----------
s
String to check
"""
try:
return base64.b64encode(base64.b64decode(s)) == s
except Exception:
return False | 677aa804f7a76b74f1624796b7eff0ae173a0bf8 | 654,738 |
import re
def _contains_single(string: str) -> bool:
"""Whether a string contains a single quote."""
match = re.search(r"[']", string)
return match is not None | 329cd8bf42412bbcc35c09b139244666866b668e | 406,263 |
import math
def amps_per_meter_to_oersted(amps_per_meter):
"""Converts \(\\frac{A}{m}\) to Oersted"""
return amps_per_meter*1e-3*4*math.pi | 3e8e30dfdd557cbed197066e86c0b2fce8209e46 | 343,232 |
import io
import json
def load_scan(json_input):
"""
Return a list of scan results loaded from a json_input, either in
ScanCode standard JSON format or the data.js html-app format.
"""
with io.open(json_input, encoding='utf-8') as jsonf:
scan = jsonf.read()
scan_results = json.loads(s... | c6209e79d8b3d026cca05059b5e90b5b15b70743 | 297,700 |
from typing import Sequence
def get_digits(n: int, base: int = 10) -> Sequence[int]:
"""Decomposes a positive integer into digit values in a given base.
Args:
n: A positive integer value.
base: The base in which ``n`` will be represented. Must be at least 2.
Returns:
An integer s... | 5346c8c8741d1d6739c7586a68cfb06ffe723746 | 274,324 |
def generate_configs(**configs):
"""
Given configs from users, we want to generate different combinations of
those configs
For example, given M = ((1, 2), N = (4, 5)) and sample_func being cross_product,
we will generate (({'M': 1}, {'N' : 4}),
({'M': 1}, {'N' : 5}),
... | 018259def2e58ea52cf8e443898add8b394a5057 | 567,954 |
import string
def remove_punctuation(txt):
"""
Use the list of punctuation given with wordcloud to remove it from the text
:params:
--------
txt list(): of string that need to have punctuation removed
:return:
--------
to_return list(): of strings with punctuation removed
... | 88464a95abe9a10eca849a4dd86e55e8947ae76d | 403,612 |
def hash_key(aMap, key):
"""Given a key this will create a number and then convert to
an index for the aMap's buckets."""
return hash(key) % len(aMap) | 179869154845e7da1ab4e50218ddc7f1f04cf7cb | 586,803 |
from typing import List
from typing import Tuple
def transform_identifiers(identifiers: List[Tuple[str, int]]) -> List[str]:
"""
Transform the original list of identifiers into the writable form.
:param identifiers: list of tuples, identifier and count.
:return: a list of identifiers in the writable f... | c280397d5174b50312d9009dd5fa3de94536ac60 | 490,941 |
def format_seconds(ms: int) -> str:
"""Formats milliseconds into min:sec:ms format"""
sec, ms = divmod(ms, 1000)
min, sec = divmod(sec, 60)
return "%01d:%02d.%03d" % (min, sec, ms) | 8ee8db40dae91aa9d6c4132825dc637209675a1a | 466,283 |
import re
def clean(name):
"""Clean name by only keeping the key-words in it.
Args:
name (str): name we are cleaning.
Returns:
relevant_sentence (str): cleaned name
"""
if str(name) != "nan":
# seperate in words
name_lowercase = name.lower()
relevant_words... | e67a0e675217f61445a6b7ccd34985f5ebdc11ce | 528,004 |
def truncate(string, length):
"""truncate a string to specified length by adding ... in the middle of the string"""
# print(len(string), string)
sep = '...'
if length < len(sep) + 2:
string = string[:length]
elif len(string) > length:
part = (length - len(sep)) // 2
remainder... | 7951180823f5c90ada5df7c9cfdf6785f4603d46 | 383,996 |
import torch
def ssm(vec):
"""
Get the skew-symmetric matrix equivalent to cross-prodict for a (batch of) 3-element vector(s).
"""
if len(vec.shape) == 1:
return ssm(vec.unsuqeeze(0)).squeeze()
out = torch.zeros(vec.shape[0], 3, 3, device=vec.device)
out[:, 0, 1] = -vec[:, 2]
... | 5a000c219e4f4d79aff9bb0400a01177738d223d | 260,357 |
import torch
def get_TFPN_dict(preds, labels, true_label=1, as_float=False):
"""
Given predictions and labels, returns a dictionary with TP, TN, FP and FN for a given class label.
"""
eval_dict = dict()
eval_dict["TP"] = torch.logical_and(preds == true_label, preds == labels)
eval_dict["TN"] =... | 5a3589e8b12877b736209049441bb3b6eb6f84d5 | 318,519 |
from typing import List
import re
def decodeBinInfoData(bin_data: List[str]) -> List[str]:
""" Decode information data from BIN_DATA """
decoded_data = []
for line in bin_data:
temp_line = ""
for bin_asc in re.findall(r'.{8}', line):
dec_asc = int(bin_asc, 2)
ch = c... | 0c3e82201c8802c3f1495a39e4e6ef9d459cfec9 | 204,284 |
from typing import Sequence
from typing import Callable
import torch
def zero(units: Sequence[int]) -> Callable[[torch.Tensor], torch.Tensor]:
"""Zero the given units.
Args:
units (Sequence[int]): The units to zero.
Returns:
Callable[[torch.Tensor], torch.Tensor]: Function that takes lay... | 6adb88bf2a27cb2bcc89f663a2950922abdde37e | 153,485 |
def yo(name):
"""Say yo to yo friend."""
return f"yo, {name}!" | f6d2bed159aaf26c600171c878ce32262df7abf3 | 307,359 |
from typing import Any
def is_number(thing: Any) -> bool:
"""
Test if an object can be converted to a number UNLESS it is a string
"""
if isinstance(thing, str):
return False
try:
float(thing)
return True
except (ValueError, TypeError):
return False | f0cc1048635fd71d5917dd2a13615697aef6afdb | 479,482 |
def is_subset(dict1, dict2):
"""Is dict1 subset of dict2."""
for key, value in dict1.items():
if key not in dict2 or value != dict2[key]:
return False
return True | 560660a1eefb4ac108868cd0936b615e5ee4fc1c | 274,817 |
def rec_to_dict(arr):
""" Turns record array *arr* into a dict """
return dict(zip(arr.dtype.names, arr)) | 21f9fd0c47b25c27c912ab441a5e1743d06f4566 | 364,859 |
def alt_case(string, lower_first=True):
"""Returns the string with alternating upper and lowercase characters.
lower_first: if True, first character is lowercase; if False, first character is uppercase"""
string = string.lower()
for i in range(len(string)):
if bool(i % 2) == lower_first:
... | 6ada67f2ee6878db6f844e58191614d51ebda932 | 367,431 |
import warnings
def deprecated(message=None):
"""A decorator for deprecated functions"""
def _decorator(func, message=message):
if message is None:
message = '%s is deprecated' % func.__name__
def newfunc(*args, **kwds):
warnings.warn(message, DeprecationWarning, stack... | 0b9f271f63334e5ad82ae61ebeb2b2e44eddf278 | 328,333 |
def find_node_name(model, name):
"""
Finds a node by its name.
:param model: onnx graph
:param name: node name
:return: node pointer
"""
if not hasattr(model, "graph"):
raise TypeError( # pragma: no cover
"Parameter model is not an ONNX model but "
"{}".forma... | 9dc3a308f5134236b12bf79bc76b0d09fc41458d | 16,817 |
from typing import Sequence
def non_decreasing(seq: Sequence):
"""
Return True if a sequence is in non-decreasing order, False otherwise.
"""
return all(x <= y for x, y in zip(seq, seq[1:])) | 554957a92a970b5c2c688c1a9babbfd5c285b3a2 | 218,024 |
def version_is_dash(request):
"""Return a boolean, whether the version they asked for is -.
"""
return request.line.uri.path.get('version') == '-' | d44fc7621dee4dfc10966456803a4fa3b3b234f4 | 504,815 |
def _perp(t: tuple) -> tuple:
"""
Obtain the point whose corresponding vector is perpendicular to t.
Parameters
----------
t : tuple
Point (x, y)
Returns
-------
tuple:
(-y, x)
"""
return -t[1], t[0] | ed49a4f326f8ef065e72d964bce3b3ce444c25f5 | 629,725 |
def trim(s):
"""Trim string to fit on terminal (assuming 80-column display)"""
return s if len(s) <= 80 else s[:77] + "..." | b3c2236b902bf20e0f2e4e7c97cfb57487ec1031 | 691,271 |
def clamp(value, min_value, max_value):
"""
Method to clamp a value between a certain range.
Args:
value(float): Value to clamp.
min_value(float): Minimum limit to clamp the value with.
max_value(float): Upper limit to clamp the value with.
Returns:
value(float): Value ... | e284dc0f1440ae6371ff961e1d992f153b3aa52d | 406,370 |
def is_pathogenic(pvs, ps_terms, pm_terms, pp_terms):
"""Check if the criterias for Pathogenic is fullfilled
The following are descriptions of Pathogenic clasification from ACMG paper:
Pathogenic
(i) 1 Very strong (PVS1) AND
(a) ≥1 Strong (PS1–PS4) OR
(b) ≥2 Moderate (PM1–PM6) OR
... | d26d6c528906e4efb6cc4df9aaca1e0e3cc4dfae | 130,400 |
import logging
def check_entries_and_report_duplicates(class_entries):
"""
Scans given dict with class entries and prints information about duplicate entries
:return 0 if there no duplicates, 1 otherwise
"""
rc = 0
for class_entry in class_entries.keys():
class_entry_jars = class_ent... | addd9ce46df0987da0aa74930329d5825373447d | 379,661 |
def triple_prod(vec1, vec2, vec3):
""" Triple cross product (vec1 x vec2) x vec3.
PARAMETERS
----------
vec{1, 2, 3}: Vec
Vectors for triple cross product. Order is important
"""
cross_vec = vec1.cross(vec2)
return cross_vec.cross(vec3) | 77a249154c37ea54a9b48c0ba77af1680a5b62d9 | 138,183 |
def _make_phase_block(phase, number=1, name="", scale_down=1.0):
"""Create a pcr phase block skelleton with placeholder strings for different
refinement options.
(for internal use)
:param phase: a crystal structucture
:type phase: cctbx.xray_structure
:param number: the number of the phase
:type number:... | 10282f321aa435e970c39b071c9eaa0ad8c94fb9 | 313,473 |
def is_visible(attr):
"""
This function checks whether an HTML element attribute is visible or hidden based on
the style of that HTML element. The purpose of this function in this package is to avoid
including data that is useless, such as inner code markers, non-sense data, etc. So this
function wi... | 0e1eb59f7c53b0329c1ad4e61e4fe100d63ee112 | 97,377 |
import math
def get_angle_between_yaw_and_point(a, p, yaw):
"""
Gets the angle between the point p and the vector starting from a's centroid with the given yaw angle.
"""
p_yaw = [math.cos(math.radians(yaw)), math.sin(math.radians(yaw))]
p_self = [p[0] - a.centroid.x, p[1] - a.centroid.y]
angl... | f6ff0d1affec482a2324209e452d7e24439466b4 | 97,457 |
import hashlib
def calculate_md5(text):
"""Calculate the MD5 hash for the give text"""
return hashlib.md5(text.encode('utf-8')).hexdigest() | bbf8b7b0ef61a14bb8a69c0de48efb2b44b61449 | 483,431 |
def delete_words(dataframe, *word_list, include_report=False):
"""
Delete rows containing at least one of the specified words.
:param dataframe: Dataframe to filter.
:param word_list: List of words to remove.
:param include_report: If True, the object returned will be a Dictionary including the fitl... | ebbd44e75fbc7891e49ce4ce205109a3dcc314ae | 180,012 |
import collections
def _sort_almost_sorted(almost_sorted_deque, key):
"""
Sort a deque like that where only the first element is potentially unsorted and should probably be last and the rest
of the deque is sorted in descending order.
:param collections.deque almost_sorted_deque: The deque of size n... | 93d282f6cc0fd4df16480b0ebbc33d132bd3cc0e | 666,140 |
def getFloatFromStr(number: str) -> float:
""" Return float representation of a given number string.
HEX number strings must start with ``0x``.
Args:
numberStr: int/float/string representation of a given number.
"""
numberStr = number.strip()
isNegative = False
if "-" in numberStr:
... | de5ee4e8193bd8127bb8d42946e184f45d1f3b23 | 661,459 |
def not_in_dict_or_none(dict, key):
"""
Check if a key exists in a map and if it's not None
:param dict: map to look for key
:param key: key to find
:return: true if key is in dict and not None
"""
if key not in dict or dict[key] is None:
return True
else:
return False | 2bc3f2194b82e978ab8edb2ffaac7a88a58e9c9e | 24,841 |
def make_options_bank_drop(values):
"""
Helper function to generate the data format the dropdown dash component wants
"""
ret = []
for value in values:
ret.append({"label": value, "value": value})
return ret | 3c89c73b6e3cdc6fe07a71080577320f0af6729f | 39,481 |
def apply_linear_transform(value):
"""
Transforms value from non-linear scale (with gamma transform) to linear
:param value: Value to be transform (between 0-1)
:return: Transformed value (between 0-1)
"""
if value > 0.04045:
return pow(((value + 0.055) / 1.055), 2.4)
else:
... | 45c63324bdbd5532da1a9e3a119c319448e6de50 | 516,663 |
def _CppName(desc):
"""Return the fully qualified C++ name of the entity in |desc|."""
return '::'+desc.fqname.replace('.', '::') | bd5985321918850bfb1f095c1587028194e9739b | 46,875 |
def generate_all_descriptions(env_params):
"""
Generates all possible descriptions from a set of environment parameters.
Parameters
----------
env_params: dict
Dict of environment parameters from get_env_params function.
Returns
-------
training_descriptions: tuple of str
... | 00b50eb085550515c4f7e57c96d7b78fdc2c8f6f | 257,862 |
def corefNode(parseinfo, mention):
"""
Returns the best node in the tree that matches the mention
"""
sentence = parseinfo.sentence(mention.sentence)
tree = sentence.parseTree()
for st in tree.subtrees():
# print st.tag(), st.token_range(), (mention.start, mention.end)==st.token_range()
... | 17dab0c6e1dd0682f43194043b29b347174faec0 | 164,880 |
def get_sessid(sessdir):
"""
get_sessid(sessdir)
Returns the session ID associated with a session.
Required args:
- sessdir (str): session directory
Returns:
- sessid (int): session ID (9 digits)
"""
sesspart = "ophys_session_"
start = sessdir.find(sesspart) + len(se... | 457c332acebeb8787a0e870cf74821e2702730d5 | 493,120 |
def CleanLine(line):
"""Converts a line from coolrunning results to a tuple of values."""
t = line.split()
if len(t) < 6:
return None
place, divtot, div, gun, net, pace = t[0:6]
if not '/' in divtot:
return None
for time in [gun, net, pace]:
if ':' not in time:
... | c59550c846e474ab5eadcc0e082feda4c04cc819 | 643,654 |
def insertion_sort(items):
"""Sort given items by taking first unsorted item, inserting it in sorted
order in front of items, and repeating until all items are in order.
Running time: O(n^2) because as items grow outter and inner loop both increases, also the function increases in a quadratic way
Memory... | 07a15b8373d9168b92f71d78748c01fddefd6a8c | 566,233 |
def resolve_object_property(obj, path: str):
"""Resolves the value of a property on an object.
Is able to resolve nested properties. For example,
a path can be specified:
'other.beer.name'
Raises:
AttributeError:
In case the property could not be resolved.
Returns:
... | ed1afb179daa719a028ddadea5bc320e1a238a40 | 160,012 |
def estimated_bigram_probability(bigram, unigram_dict, bigram_dict):
""" estimate the probability of bigram (= (syll_1,syll_2)) by:
(count (syll_1,syll_2)) / (count syll_1)
"""
# set the count to zero
count = 0
# check if bigram is actually in our dict
if bigram in bigram_dict:
# i... | adf5d3830118da86b4e9a7981bfda4210f47b7f9 | 668,849 |
def convert_locp(locp, converter):
"""
Convert the given list of card plays using the converter
:param locp: CardPlays to convert
:type locp: [CardPlay, ...]
:param converter: method to convert a CardPlay
:type converter: CardPlay -> PyJSON or None
:return: the list of PyJSON
:rtype: [Py... | 23330bec68ef8b5a658f387f421144d88c2d5a39 | 585,733 |
from typing import Dict
def _new_ax_png_name(dct: Dict[str, str]) -> str:
"""
Returns the first string of the form "axNNN.png" not present in dct, for NNN=000, 001, 002, ...
"""
idx = 0
while True:
base = f"figure{idx:03d}.png"
if base not in dct:
return base
id... | d880e277a64dd01b565d367b64c5bfd9302c1642 | 548,914 |
def _default_list(length: int) -> list:
""" Returns a list filled with None values. """
return [None for _ in range(length)] | fbdd2b5769960c87f64b9ed9769bd4f9e80ae608 | 330,757 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.