content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
import os def get_default_number_of_electrons(calc, filename): """ Return the default electrons for each species. from https://github.com/jkitchin/vasp#vaspget_default_number_of_electrons """ if filename is None: filename = os.path.join(calc.directory, 'POTCAR') calc.write_input(calc....
c28f06d848503b05e3355722d4ab4cd0eba6a7b9
694,622
def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x
211d6aeab23734a944a606b2a744bd4ab682a166
694,623
def _encode_for_display(text): """ Encodes strings so they can display as ASCII in a Windows terminal window. This function also encodes strings for processing by xml.etree.ElementTree functions. Returns an ASCII-encoded version of the text. Unicode characters are converted to ASCII placeholde...
59fa895204b764a105f0cc73f87f252c64e62871
694,624
def d_theta_parabolic(C, k, clk): """ A downwards concave parabola of form: f(x) = -c(x)(x - a) Here: C -> x k -> c clk -> a """ return -1 * k * C * (C - clk)
ac520d33bf11ba20e1a2f72d298a2a496ec00ca7
694,625
def get_blueprints(bot, base): """Gets the blueprints associated with the given base. Also returns whether or not the command is a shortcut. If the base is not found in the commands dictionary, returns (None, None) """ try: command = bot.commands[base] is_shortcut = base in command....
48b7a5bad96f64825cfe6178711d8714514d5bad
694,626
def iterative_gcd(x: int, y: int): """while loop will continue until y = 0""" while(y): x,y = y, x%y return x
6ecaa850da3aaeffc8af46b8f5d91ac6aa0a588b
694,627
def is_good_response(res, content_type='html'): """ Returns True if the response seems to be Content type (default html), False otherwise. """ content_type = res.headers['Content-Type'].lower() return (res.status_code == 200 and content_type is not None and content_type.find(content_type) > -1)
d48ad85a7f8790be6e037d978e84756fa7091689
694,628
def replace(template, ctx): """Replace placeholders with their values and return the result. Example: >>> replace("$NAME is down", {"$NAME": "foo"}) foo is down This function explicitly ignores "variable variables". In this example, placeholder's value itself contains a placeholder: >>> repl...
a2822d611ad6c7b64bff8631b450855322b1c4a5
694,629
def can_infer(num_sensed_blocked: int, num_confirmed_blocked: int, num_sensed_unblocked: int, num_confirmed_unblocked: int): """ check whether we can infer or not from the current set of variables :param num_sensed_blocked: number of sensed blocks :param num_confirmed_blocked: number of co...
49eea4125ffb970c89f223afd21e3e7dd3c870d7
694,630
def get_contacts(filename): """ Return two lists names, emails containing names and email addresses read from a file specified by filename. """ names = [] emails = [] lineofdata = [] # print(names) # print(emails) with open(filename, mode='r', encoding='utf-8') as contacts_file:...
e3f3b862fca1e290c2b353ba440913479e1265c9
694,631
def _int32_to_bytes(i): # NOTE: This course is done on a Mac which is little-endian """Convert an integer to four bytes in little-endian format.""" # &: Bitwise 'and' # >>: Right shift return bytes((i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff, ...
61606a87d7f074117637b3a322dcded43a514cd0
694,632
from typing import Optional from typing import Dict from typing import Any def _serialize_input_metadata_field( input_metadata_dictionary: Optional[Dict[str, Any]] ) -> Optional[Dict[str, str]]: """Serialize input metadata, converting GraphQLTypes to strings.""" # It is possible to have an empty input met...
0fc7120b975622fb986664047e0a5877f5194b4a
694,633
from typing import OrderedDict import os def return_input_paths(job, work_dir, ids, *args): """ Returns the paths of files from the FileStore Input1: Toil job instance Input2: Working directory Input3: jobstore id dictionary Input4: names of files to be returned from the jobstore Returns...
2b4d0398e29e4ef207dd6c83f7b2024b1bd754ab
694,634
import math def calculateCents(referenceScale, newScale): """Takes two arrays of frequencies and calculates the cents difference. Returns 8 values in a list.""" centsList = [] for i in range(len(referenceScale)): ratio = newScale[i] / referenceScale[i] cents = round(((math.log(ratio) / mat...
94796baa067806b2a15fd536798adf84f5360901
694,635
def usage(err=''): """ Prints the Usage() statement for the program """ m = '%s\n' %err m += ' Default usage is to seach the Scan the currect directory for PE checkpoints.\n' m += ' It will look for linked CRs in a peer directory' m += ' create_pe_load \n' return m
3b9e7b34eb7b1072f02f0678dd505961bdf9aa39
694,636
import os def build_openweathermap_base_url() -> str: """ Build the base url for an openweathermap current_request. Credentials are built from environmental variables. :return: base url string that needs lat and lng params inserted """ app_id = os.environ.get('OPENWEATHERMAP_APP_ID') retu...
68494a3f2fd4b6b67ee3cee596465f39f3242891
694,637
def is_float(n: str) -> bool: """ Checks if a string is a valid float Parameters ---------- n: str The string to check. Returns ------- bool """ try: float(n) return True except ValueError: return False
dcbcdaafc857f69bcc3b9cf728a230088adf84b7
694,638
import zipfile import pathlib async def make_zip_archive( input_directory_path: str, output_file_path: str, ) -> dict: """ Creates zip file of a directory. Parameters ---------- input_directory_path : str Path to directory to be archived output_file_path : str Path where t...
a27729eeec533e6978047268e62b644d3ce9a038
694,639
def flowDiff(graph1, graph2): """ Return the difference between the flows of two graphs. Parameters ---------- graph1: netwrorkx obj graph2: networkx obj Returns ------- a dictionary with name od edge and diff in flows. graph1-graph2 """ flowDiff_ = {} for edge in gra...
65d7392607b01f935dd6fe2e282083530a3513d3
694,640
import argparse def parse_args(): """Parse command-line arguments.""" parser = argparse.ArgumentParser() parser.add_argument("source_corpus_name", type=str, help="source corpus name.") parser.add_argument("source_dir", type=str, help="source dir.") parser.add_argument("target_corpus_name", type=s...
bb3893a1ebe11554128c2a8e9f582b23273567aa
694,641
import shutil import subprocess as sp from pathlib import Path import sys def get_git_lines(fname="line-contributors.txt"): """Run git-line-summary.""" contrib_file = Path(fname) lines = [] if contrib_file.exists(): print("WARNING: Reusing existing line-contributors.txt file.", file=sys.stde...
76932ad797c0eff18879081cdb6c7038bc6cdddd
694,643
def range_factorial(num): """Solution that iterates over a range""" result = 1 i = iter(range(1, num + 1)) try: while True: result *= next(i) except StopIteration: pass return result
e828a8a8139ac176a054f416798c8a817c89f2d4
694,644
def depth_of_tree(root): """ :param root: tree root :return: height of tree """ if not root: return 0 left = depth_of_tree(root.left) right = depth_of_tree(root.right) return max(left, right) + 1
9962f322958de30f9b69056fe4a7ef1c5eb6daa1
694,645
def tryint(s): """ try casting s to an int. if exception occurs, return s unchanged """ try: return int(s) except ValueError: return s
8a4b221a2930494a631dcd23544176d47f4ef6e0
694,646
import mimetypes def guess_mimetype(resource_path): """ Guesses the mimetype of a given resource. Args: resource_path: the path to a given resource. Returns: The mimetype string. """ mime = mimetypes.guess_type(resource_path)[0] if mime is None: return "applicati...
66f2554387966028a4ab1cf1bf3715878b3dc246
694,648
def hex_8bit(value): """Converts 8bit value into bytearray. args: 8bit value returns: bytearray of size 1 """ if value > 0xff or value < 0: raise Exception('Sar file 8bit value %s out of range' % value) return value.to_bytes(1, 'little')
597ecb6c9a499c7a5959f1f8ddd7300b78b06e9a
694,649
import math def F17(x): """Griewank function """ sum = 0 prod = 1 for i in range(len(x)): sum += x[i]/4000 prod *= math.cos(x[i]/math.sqrt(i+1)) s = sum - prod + 1 return s
a5906c8b894d74739b39fc7c396edc3c9c307a0e
694,650
def lower(s): """ Returns the string `s` converted to lowercase. """ return s.lower()
e953cb79ee371128952a6ad7a0b7c91afc08c8b6
694,651
def strftime(value, arg): """ Calls an object's strftime function. """ if value: return value.strftime(arg) else: return None
eda77a7b830a8edc292937e9cdf45442f03ebad9
694,652
from unittest.mock import call def create_checkout_path(org, path): """Create a checkout path for a metacheckout""" outdir = "%s/%s" % (path, org) mk_status = call("mkdir -p %s" % outdir, shell=True) return outdir
4434701430731dc4a28c7ffc082b9c141ab995f4
694,653
def episode_title(self): """Return episode title.""" return self.media_metadata.get("subtitle")
94b5be128e44334efe5f3c141e0b9dbc1bc10c3d
694,654
def model_docstring(cls, header='', indent='', footer=''): #pragma: no cover """Return a docstring from a list of defaults. """ #width = 60 #hbar = indent + width * '=' + '\n' # horizontal bar hbar = '\n' props = cls.find_properties() s = hbar + (header) + hbar for key, val in props.i...
adc2b4e207e09ed127b5d39a566dd9266bc535eb
694,655
def update_list(V_in, V_not): """Take out vertices from list V_not""" V_out = [v for v in V_in if v not in V_not] return V_out
633c690a3c568d0c8f9a21659326ab516db0b462
694,656
def weed_out_short_notes(pairs, **kwargs): """Remove notes from pairs whose duration are smaller than the threshold""" duration_threshold = kwargs.get('duration_threshold', 0.25) return [(n, d) for (n, d) in pairs if d > duration_threshold]
de9caea78313e4f8d77c16ed17ae885d4bed9e33
694,657
def datetime_format(datetime_obj, fmtstring = '%Y-%m-%d'): """ A function to string format a datetime.datetime object. """ return datetime_obj.strftime(fmtstring)
a64ce81cb28c59489bff3d57751feebb818e04c5
694,658
import requests def _component_id_from_target(target_chembl_id): """ Use ChEMBL API: Go to `target` endpoint and extract `component_id`. """ target_url = f"https://www.ebi.ac.uk/chembl/api/data/target/{target_chembl_id}.json" response = requests.get(target_url) response.raise_for_status() ...
2552839c435224f44f7d962cec7bce86af770273
694,659
def start_ea(obj): """ Return start ea for supplied object. :param obj: Object to retrieve start ea. :return: start ea. """ if not obj: return None try: return obj.startEA except AttributeError: return obj.start_ea
fc00c290d493ec762f165c6ff657716c8218fab3
694,660
def has_tx_succeeded(tx_receipt): """ We check tx has succeeded by reading the `status` on the `tx_receipt` More info: https://docs.pantheon.pegasys.tech/en/latest/Reference/JSON-RPC-API-Objects/#transaction-receipt-object """ status = tx_receipt.get("status", None) if status == 1: retur...
3b9e54efd1b269a835b4829adeca7afe7cfe51a9
694,661
def derive_nums_from_text(comments, regex): """Given a string, derive all related case nums using given regexes""" return set(int(num) for num in regex.findall(comments) if num)
76d1a69acefaeba64a9be9763f15f2da24652bea
694,662
def dg_pulse(Y, pop_from, pop_to, pulse_weight): """ A pulse migration event Different from merger, where the two parental populations are replaced by the admixed population. Here, pulse events keep the current populations in place. """ if pop_to in Y.pop_ids: ind_from = Y.pop_ids.i...
808569ec8f7c03e652e8a56cca5c5874036f3cb2
694,663
def display_banner(): """ Returns Banner """ return (''' _ _ _ __ | | (_) |/ _| _ __ __ _ ___ _____ _____ _ __ __| | _ __ _| | |_ ___ _ __ | '_ \ / _` / __/ __\ \ /\ / / _ \| '__/ _` | | '_...
544ce29b0855401ec3130e7205be6cefeb307963
694,664
def core(fn=None, **flags): """Wrap a graph that defines a core Myia function. The following flags can be set: core: (default: True) Indicates that this is a core function (only informative at the moment). ignore_values: (default: False) Make the inferrer ignore argument ...
40c6d16da166452bb231a0885b7e45debb2c8410
694,665
def _evaluate_cubic_spline_derivative_one(x, y, r, t): """Evaluate one point on the first derivative of the cubic spline. Parameters: x : rank-1 np.array of np.float64, length 2 data x coordinates y : rank-1 np.array of np.float64, length 2 data y coordinates r :...
ef9aa1454c412f2ec66a112d367b5171d9de4e35
694,666
import pickle def get_challenges_for_user_id(database, user_id, ctf_channel_id): """ Fetch a list of all challenges a user is working on for a given CTF. Return a list of matching Challenge objects. """ ctfs = pickle.load(open(database, "rb")) ctf = ctfs[ctf_channel_id] challenges = [] ...
bd2c048ca88aad630bfe9fda7c37924cf93c611b
694,667
def make_gmm_unaries(X, fg_gmm, bg_gmm): """ Make unaries by log probability under GMM. Take X: data in N x K ndarray where N is no. samples and K is no. features fg_gmm, bg_gmm: fitted sklearn.mixture.gmm Give fg_unary, bg_unary: log probabilities under the fg and bg gmms resp. """ fg_un, _ =...
d69b942d465262736c3d209be7e2de9a4ce2cf4b
694,669
import os def resolve_resource_file(res_name): """Convert a resource into an absolute filename. Resource names are in the form: 'filename.ext' or 'path/filename.ext' The system wil look for ~/.mycroft/res_name first, and if not found will look at /opt/mycroft/res_name, then finally it will l...
40b593e9f24315ac4bb643704a50371533878481
694,670
def d(value: bytes) -> str: """ Decode a bytestring for interpolating into an error message. """ return value.decode(errors="backslashreplace")
5b37b195cc5a462c8eb665b0fd77cbe823f57e00
694,672
def impact_seq(impact_list): """String together all selected impacts in impact_list.""" impact_string = '' connector = '-' for impact in impact_list: impact_string += connector + impact.iname.strip() return impact_string
335a879c17e263690744c947b11be872c5ccf663
694,673
def new_kernel ( lines = 3, columns = 3 ): """Cria kernel a partir de lines e columns (linhas e colunas) Args: lines: número de linhas do kernel, default = 3 columns: número de colunas do kernel, default = 3 Returns: kernel (lines x columns) """ return [ [ line * 0 + 1 ...
799a9c3187aaf06553bf76881276f4593900ff26
694,675
import re def isIntStr(numstr): """ Return True if the given string contains ony digits """ if re.match("^[0-9]+$", str(numstr)): return True return False
c0f21f5fd54bda7b7d0129b18d1a814e2a701a21
694,676
def url_to_path(url: str): """ Convert URL to path """ return url.replace("://", "___").replace(".", "__").replace("/", "_")
518fa3647d53838a9f7a68e175778f191cc82896
694,677
import subprocess import re def ping_to_site(host_to_ping, host_name, latency): """ Comprueba ping a un host y verificar su tiempo de latencia :param host_to_ping: HOST a hacer ping para probar conectividad :param host_name: Nombre del HOST a hacer ping :param latency: Tiempo de latencia en ms, n...
ff15ad6cd39eb1e8c5b0e0da6eaefa4734bda0b1
694,679
import requests def verify_physionet_credentials(username, password): """Returns True if the username and password are valid for the physionet.org website.""" url = "https://physionet.org/works/MIMICIIIClinicalDatabase/files/" r = requests.get(url, auth=(username, password)) return True if r.status_co...
2821de8abf6cb1d0f9363bbb0440f9a1ae65bc99
694,680
def _find_start_entry(line, n): """Find the starting character for entry ``n`` in a space delimited ``line`` (PRIVATE). n is counted starting with 1. The n=1 field by definition begins at the first character. Returns ------- starting character : str The starting character for entry ``n...
60b609b099bae2aa6e891008a1e49c7083c6de32
694,681
import numpy def derivation(array, order=1): """ Returns a derivation of input <array>. :param array: input array :type array: numpy.ndarray :param order: order of derivation, defaults to 1 :type order: int, optional :return: derivation :rtype: numpy.ndarray """ return numpy.d...
ff2a7fa279887aa065915ed745d7c0533e4258cb
694,682
def startswith_whitespace(text): """Check if text starts with a whitespace If text is not a string return False """ if not isinstance(text, str): return False return text[:1].isspace()
4c1acdfea37fc1ffdcde13fb6c68567489d91b30
694,683
import argparse def parse(arg=None): """Define configuration of postprocess""" parser = argparse.ArgumentParser() parser.add_argument('--bin_path', type=str, default='./result_Files/') parser.add_argument('--target_path', type=str, default='./result_Files/') return parser.parse_args(arg)
2221ac32f908c8e26473da7035737874b93d0cf5
694,684
def get_df_from_excel(spark, file_path, sheet_name): """ This method is intended to create a dataframe form excel file :param spark: spark Session :param file_path: hdfs path of the file :return: dataframe """ return (spark.read.format("com.crealytics.spark.excel") ....
c3c44cb3d68312d65e622463981496f6df9af344
694,686
def finalize(mt): """Drops entry fields no longer needed for combining. Note ---- You will not be able to run :func:`.combine_gvcfs` with the output of this function. """ return mt.drop('gvcf_info')
aecdfe238449d76f6d4133abd7586039be488514
694,687
import argparse def find_engine_override(argv): """Since the bootstrap process attempts to defer all logic to the recipes-py repo, we need to be aware if the user is overriding the recipe_engine dependency. This looks for and returns the overridden recipe_engine path, if any, or None if the user didn't overri...
ff0147c8fe75c834b7dd71f1c3b9ce3ead98feb0
694,688
def triplet(n): """Find the Pythagorean triplet who's sum equals a given number.""" for c in range(n - 3, 1, -1): for b in range(c - 1, 1, -1): a = (c**2 - b**2)**.5 if a + b + c == n: return [c, b, int(a)] return False
0f4121ac169d8830a776f4fb44d9716077288cb8
694,689
import subprocess def get_nc_dump_string_by_ncdump(nc_file_name): """ (string) -> string Return: string create by running "ncdump -h" command for netcdf file. """ try: process = subprocess.Popen(['ncdump', '-h', nc_file_name], stdout=subprocess.PIPE) nc_dump_string = process.comm...
66659e9b751ac58bb6b323586e9281b6ecf2cfc8
694,690
import os import time def connected_to_internet(): """ This function will return true or false whether there is currently an internet connection or not. """ # This represents the terminal command that will ping google.com to seek # a response ping = "ping -c2 google.com" # Define the...
4fd05fc0a84c395f0d8fd86ce4a106bd1045efba
694,691
def move_wonpts(self): """ return the best move to play """ best = -1000 bm = None #print("fuck") for m in self.t: if self.t[m].n_playout == 0: continue u = self.t[m].wonpts/self.t[m].n_playout #print("played {} times, {:.2f}% winrate, {:.2f} pts/game".format(self...
746801015cf4ac8869e9b7a4e26c56a53c282788
694,692
import six def isHTML(str): """Try to determine whether str is HTML or not.""" if isinstance(str, six.binary_type): try: str = str.decode() except UnicodeDecodeError: return False s = str.lstrip().lower() if s.startswith('<!doctype html'): return True ...
c1245b023b2647e312085b68528a3b0fef7a702f
694,693
import os def is_module(directory): """A directory is a module if it contains an ``__init__.py`` file. """ return os.path.isdir(directory) and '__init__.py' in os.listdir(directory)
4945a4fd0145735a578ecbd43c523206b95dc8fd
694,694
def to_human(seconds): """Converts seconds to human readable (weeks, days, hours) form. :param int seconds: number of seconds. :return: (weeks, days, hours) equivalent to the seconds. :rtype: str """ weeks = seconds / (7 * 24 * 60 * 60) days = seconds / (24 * 60 * 60) - 7 * weeks hour...
c6e68c58a1a57771c1d438abec209ac15898c369
694,695
import os def load_chrom_sizes(reference_genome): """ Load chromosome sizes for a reference genome """ my_path = os.path.abspath(os.path.dirname(__file__)) rg_path = f'{my_path}/utils/{reference_genome}.chrom.sizes' f = open(rg_path) lengths = {} for line in f: [ch, l] = line.s...
558d9aed272256767cba559a87ef606a6590f606
694,696
def scalePixelData(pixelData, rInt, rSlope): """Scales pixel image values linearly by rescale values""" scaledPixelData = [] for pixelRow in pixelData: scaledPixelRow = [] for pixelValue in pixelRow: pixelScale = (rSlope * pixelValue) + rInt scaledPixelRow.append(pixelScale) s...
7c5220384b0eebf80e2711b838f0f7d4c1711fdf
694,697
def tlv_file_xml_mapped(tlv_data_xml_mapped, tmp_path): """Return the path to an mapped XML file containing the test tree.""" path = tmp_path / "expected_mapped.xml" path.write_bytes(tlv_data_xml_mapped) return path
314a0a55112259940b6dcbd7d72beb69da400134
694,698
from typing import List def men_from_boys(arr: List[int]) -> list: """ Sort out the men from the boys. Men are the Even numbers and Boys are the odd. Return an array/list where Even numbers come first then odds. Since, Men are stronger than Boys, then Even numbers in ascending order ...
60a0f7f7362d85674a5becc14308cd84a3fe0f12
694,699
def has_cycle(head): """" boolean function to identify a cycle in a linked list """ print('\nIn has_cycle') count = {} if head != None: while head: if head.next in count: return True else: count[head] = 1 head = head.next return False # space complexity is O(n)
6c03759b93afbd09878b6cfaf3ae4e58c9a4f555
694,700
def bissexto(ano): """Verifica se um ano é bissexto. Retorna True se ano for bissexto ou False caso contrário. Definição de ano bissexto: Um ano é bissexto se for divisível por 400 ou então se for divisível por 4 e, ao mesmo tempo, não for divisível por 100. """ return ano % 400 == 0 or ano...
388880697cdebe9c29b8815edb99b9fda80a2210
694,701
from typing import ByteString def make_buffer_mutable(data: ByteString): """ Returns a mutable version of the input data. Already mutable inputs are returned as themselves, i.e. no copy operation occurs in these cases. """ if isinstance(data, bytearray): return data if isinstance(data,...
62a80b83a8d1ce141673e3c6b91d34c0e9cfa89c
694,702
import re def find_all(item, items, regex=False, regex_flags=None): """ Finds the indexes and values for all values matching a given item. :param item: the value (or pattern) to match/find. :param items: an iterable of items to match against. :param regex: If True, item will be treated as a regex...
bf9e78ef94261c0ee88162e6a1be85a8cdb1dd54
694,703
def mark_doc(doc, wids, mark=None, pos=None): """ Given a list of words and a set of word positions, mark the words in those positions. :param list doc: a list of words (strings) :param set wids: the positions of the words to be marked :param string mark: a string that sets the mark that will be app...
481fb2d4ca8828181288d776c6f4b73e82f0443a
694,706
def unknown_char(char_name, id_ep): """Transforms character name into unknown version.""" if "#unknown#" in char_name:#trick when re-processing already processed files return char_name return f"{char_name}#unknown#{id_ep}"
061683efd275335e58129225fe4bc9dabc044c9b
694,707
def _copy_list(seq): """Recursively copy a list of lists""" def copy_items(seq): for item in seq: if isinstance(item, list): yield list(copy_items(item)) else: yield item return list(copy_items(seq))
2e179ed338bf9b5417772509ca27a84608c240d9
694,708
def make_vij(key:str,sent:str)->str: """ 第一引数に鍵、第二引数に平文を受け取りヴィジュネル暗号を返します。 """ x,y=0,0 ang="" key=key.lower() sent=sent.lower() while y<len(sent): if ord(sent[y])>=ord('a') and ord(sent[y])<=ord('z'): ang+=chr(ord('A')+(ord(sent[y])+ord(key[x])-ord('a')*2)%26) ...
03853924d15aff5187359761bd1f5f15e33eebf2
694,709
def gumbel_parameter_converter(miu, sigma): """ NAME: gumbel_parameter_converter VERSION: 0.0.1 AUTHOR: Yan Fu, Ruben V. Coline DATE: 27 Sept 2018 DESCRIPTION: This function is used in conjunction of the scipy.stats.gumbel distribution, converts mean and standard deviation (sigma) of sam...
910ae757862a9107cbf59ceda37a9825554f1859
694,711
def calculate_occlusion(ray, obj, light, objects): """ Calculate if there is an object between the light and object Args: ray: A ray starting in the hit point with direction to the light obj: The object where the hit point is light: A source of light to calculate if it's occluded ...
c15acf785f8baf72da64307380cd36d7de6b6ef8
694,713
def create_label_lists(label_path): """ creates a label to encoding dict and a reverse dict via an output label txt file generated by retraining.py :param label_path: output label file name :param json_path: path to product json file :return: label to encoding dict and a reverse of that """ ...
db0557488bb32fa7de468b4a9011e961e977622b
694,714
def get_integer(dictionary, key): """Gets value of a key in the dictionary as a integer. Args: dictionary (dict): A dictionary. key (str): A key in the dictionary. Returns: A integer, if the value can be converted to integer. Otherwise None. """ val = dictionary.get(key) try: ...
503f168ff6ecac637fde28dae3c6fc33554b5e26
694,715
from typing import Tuple def left(x: int, y: int) -> Tuple[int, int]: """Move one step to the left""" return x - 1, y
ad16a27149980c532a72970fade1b09843168a82
694,716
import re def extract_bonds_and_angle_info(force_field): """ Given a force field files, extracts the values use for equilibrium bond lengths and angles. """ info = {"bonds":{}, "angles": {}} bond_regex = r"^(.{2}-.{2})\s+\S+\w+\s+(\S+)" angle_regex = r"^(.{2}-.{2}-.{2})\s+\S+\w+\s+(\S+...
ee314b68f9e2dfecb3b94c4493594adc30668d3e
694,717
def ymd2jd(year, month, day): """ Converts a year, month, and day to a Julian Date. This function uses an algorithm from the book "Practical Astronomy with your Calculator" by Peter Duffet-Smith (Page 7) Parameters ---------- year : int A Gregorian year month : int A Gre...
7f93c1eef14d3e75764329748d4646e41ba6fea9
694,718
import os def _find_only_folder_with_metadata(path): """Looks through a bundle for a single folder that contains a metadata file and returns that folder's name if found""" files_in_path = os.listdir(path) if len(files_in_path) > 2 and 'metadata' in files_in_path: # We see more than a couple fi...
83ef9d62e9e46cd35ddd18c5ab6b71de187ec51b
694,719
import json def json_to_key_val_dict(fn, key_name, val_name): """Input json must contain a list of tuples [(a0, b0), (a1, b1), ...], return ([a0, a1, ...], [b0, b1, ...]) fn --- json file containing a list of (key, value) tuples, e.g., [(key0, val0), ...] """ tuples = json.load(open(fn, 'r')) # lo...
ffffa436886c50d7903178953066cd6a5d069285
694,720
def _get_default_var_dicts_planetos(dataset): """ Returns dictionary mapping PlanetOS variable names to OpenOA variable names for a particular dataset Args: dataset (:obj:`string`): Dataset name ("merra2" or "era5") Returns: :obj:`dict`: Dictionary mapping reanalysis variable names fro...
b93e2b5655003ea81900e013d3c24545baae690c
694,722
from typing import Union from typing import List from typing import Any from typing import Dict def convert_to_schema(schema: Union[List[Any], Dict[str, Any], Any]) -> Dict[str, Any]: """Recursively convert a json-like object to OpenAPI example response.""" if isinstance(schema, list): return { ...
dbb5010b50f81bb86d668850b70631cad34c9407
694,723
def transformedCoordinatesWithMatrice(mol,matrice): """ for a nodeset, this function returns transformed coordinates. This function will use the pickedInstance attribute if found. @type mol: MolKit node @param mol: the molecule to be transfromed @type matrice: 4x4array @param matrice: the mat...
50ea9e73cfb48e0002e7a16eeb8d141eadda3690
694,724
import socket def get_ip(): """ Get the IP by connecting to the internet and watching which interface is being used :return: Local IP address of the main network interface """ return socket.gethostbyname(socket.gethostname())
f772364375eeea2fa155a85fdf61186df26ad20c
694,725
def checkmdscale_none(md, tocheck=['ZScale'], replace=[1.0]): """Check scaling entries for None to avoid issues later on :param md: original metadata :type md: dict :param tocheck: list with entries to check for None, defaults to ['ZScale'] :type tocheck: list, optional :param replace: list wit...
88dc27b1e7bf9f9a3b34ef863c6b0943d6a9b82e
694,726
def match_any_re(regex_list, value): """Given a list of pre-compiled regular expressions, return the first match object. Return None if there's no Match""" for regex in regex_list: match = regex.fullmatch(value) if match: return match.groupdict()
fcb1ce9530ac990dd1048eb62883adcf9a06ab6a
694,730
def part2(captcha): """ >>> part2("1212") 6 >>> part2("12131415") 4 >>> part2(read_input()) 1220 """ half = len(captcha) // 2 rotated = captcha[half:] + captcha[:half] total = 0 for (a, b) in zip(captcha, rotated): if a == b: total += int(a) ret...
c56c2262216de81377fc5d2abfff20b15d6b198e
694,732
def compare_containers(cont_a, cont_b): """ compares whether two containers have the same content regardless of their type. eg, compares [1, 2, 3] and (1, 2., 3.) as True Keyword Arguments: cont_a -- one container cont_b -- other container """ if cont_a != cont_b: # pylint: disab...
6fa3aefaf40f0cf5ea0f453f7f527714ef98848c
694,733
def get_album_from_html(self, html): """Scrapes the html parameter to get the album name of the song on a Genius page""" parse = html.findAll("span") album = '' for i in range(len(parse)): if parse[i].text == 'Album': i += 1 album = parse[i].text.strip() break...
a7cf940227dfd2dd9f2c7fe44073ef02489e6db1
694,734
def identity(mask): """ This is identity function that can be used as an argument of functions :func:`set_encoder` and :func:`set_decoder`. :param mask: input mask :type mask: numpy.ndarray :return: the same mask :rtype: numpy.ndarray Example: .. code-block:: python ...
b2082ffb09501a393776e3a1b960b4b532f3e465
694,735
import json async def assert_api_post_response(cli, path: str, payload: object = None, status: int = 200, expected_body: object = None): """ Perform a POST request with the provided http cli to the provided path with the payload, asserts that the status and data received are correct. Expectation is th...
a09185ff957446ce99cb1bcd93d5699890b72b52
694,736
def diffangles(a1, a2): """ Difference between two angles in 0-360 degrees. :param a1: angle 1 :param a2: angle 2 :return: difference """ return 180 - abs(abs(a1 - a2) - 180)
8f17b4f1bdd822082b552aa14907bcdb4b185a4f
694,737