content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def remove_element(list, remove): """[summary] Args: list ([list]): [List of objects] remove ([]): [What element to remove] Returns: [list]: [A new list where the element has been removed] """ for object in list: if object._id == remove[0]: list.remove(o...
65a9fe296a6d8369127003c33f58022ededfdcba
705,350
from typing import Union from typing import Mapping from typing import Iterable from typing import Tuple from typing import Any def update_and_return_dict( dict_to_update: dict, update_values: Union[Mapping, Iterable[Tuple[Any, Any]]] ) -> dict: """Update a dictionary and return the ref to the dictionary that...
8622f96a9d183c8ce5c7f260e97a4cb4420aecc7
705,351
def get_unity_snapshotschedule_parameters(): """This method provide parameters required for the ansible snapshot schedule module on Unity""" return dict( name=dict(type='str'), id=dict(type='str'), type=dict(type='str', choices=['every_n_hours', 'every_day', ...
a25cb6c62a0a69f2586135677802309e033d86bc
705,352
import sys def keyboard_interrupt(func): """Decorator to be used on a method to check if there was a keyboard interrupt error that was raised.""" def wrap(self, *args, **kwargs): try: return func(self, *args, **kwargs) except KeyboardInterrupt: self.close() # this will...
1914924986c278bb919274b746ce13fb718268e8
705,353
def cutoff_depth(d: int): """A cutoff function that searches to depth d.""" return lambda game, state, depth: depth > d
af7396a92f1cd234263e8448a6d1d22b56f4a12c
705,354
def rgb_to_hex(red, green, blue): """Return color as #rrggbb for the given RGB color values.""" return '#%02x%02x%02x' % (int(red), int(green), int(blue))
7523bcb4b7a033655c9f5059fcf8d0ed656502c8
705,356
def _is_swiftmodule(path): """Predicate to identify Swift modules/interfaces.""" return path.endswith((".swiftmodule", ".swiftinterface"))
085fa4f8735ce371927f606239d51c44bcca5acb
705,357
def get_desc_dist(descriptors1, descriptors2): """ Given two lists of descriptors compute the descriptor distance between each pair of feature. """ #desc_dists = 2 - 2 * (descriptors1 @ descriptors2.transpose()) desc_sims = - descriptors1 @ descriptors2.transpose() # desc_sims = d...
2baea3bfa01b77765ec3ce95fd9a6be742783420
705,359
import os def get_mem_usage(): """returns percentage and vsz mem usage of this script""" pid = os.getpid() psout = os.popen( "ps -p %s u"%pid ).read() parsed_psout = psout.split("\n")[1].split() return float(parsed_psout[3]), int( parsed_psout[4] )
9d0060f435a1fb0d77a31ce946d7e46ffb7b4762
705,360
import os import requests def download_file(url, local_folder=None): """Downloads file pointed to by `url`. If `local_folder` is not supplied, downloads to the current folder. """ filename = os.path.basename(url) if local_folder: filename = os.path.join(local_folder, filename) # Downl...
2229239b4c54c9ef7858b3013cb78d00e0ea2ae0
705,361
import csv def simple_file_scan(reader, bucket_name, region_name, file_name): """ Does an initial scan of the file, figuring out the file row count and which rows are too long/short Args: reader: the csv reader bucket_name: the bucket to pull from region_name: the regi...
ccd1aad870124a9b48f05bbe0d7fe510ae36bc33
705,363
import os import sqlite3 def get_users_name(path): """ 登録されているユーザ情報の回収 Parameters ---------- path : str homeディレクトリまでのパス Returns ------- name_dict : dict 登録ユーザ情報の辞書 """ path_db = os.path.join(path, 'data', 'list.db') name_list = [] with sqlite3.connect(...
4a71b52a4dfa1e40eab62134795944b43a774a73
705,364
def get_rest_parameter_state(parameter_parsing_states): """ Gets the rest parameter from the given content if there is any. Parameters ---------- parameter_parsing_states `list` of ``ParameterParsingStateBase`` The created parameter parser state instances. Returns ------- p...
e90d1ee848af7666a72d9d0d4fb74e3fedf496fa
705,365
import io def read_all_files(filenames): """Read all files into a StringIO buffer.""" return io.StringIO('\n'.join(open(f).read() for f in filenames))
efb2e3e8f35b2def5f1861ecf06d6e4135797ccf
705,366
def path_inside_dir(path, directory): """ Returns True if the specified @path is inside @directory, performing component-wide comparison. Otherwise returns False. """ return ((directory == "" and path != "") or path.rstrip("/").startswith(directory.rstrip("/") + "/"))
30ad431f9115addd2041e4b6c9c1c8c563b93fe9
705,367
def butterworth_type_filter(frequency, highcut_frequency, order=2): """ Butterworth low pass filter Parameters ---------- highcut_frequency: float high-cut frequency for the low pass filter fs: float sampling rate, 1./ dt, (default = 1MHz) period: period of the sign...
f8ff570d209560d65b4ccc9fdfd2d26ec8a12d35
705,368
def coro1(): """定义一个简单的基于生成器的协程作为子生成器""" word = yield 'hello' yield word return word # 注意这里协程可以返回值了,返回的值会被塞到 StopIteration value 属性 作为 yield from 表达式的返回值
1bfcfb150748c002638d2c6536299025864ac1f6
705,369
def add_to_master_list(single_list, master_list): """This function appends items in a list to the master list. :param single_list: List of dictionaries from the paginated query :type single_list: list :param master_list: Master list of dictionaries containing group information :type master_list: li...
4b4e122e334624626c7db4f09278b44b8b141504
705,370
import os import re def get_sdkconfig_value(sdkconfig_file, key): """ Return the value of given key from sdkconfig_file. If sdkconfig_file does not exist or the option is not present, returns None. """ assert key.startswith('CONFIG_') if not os.path.exists(sdkconfig_file): return None ...
d8f11dec3406d5fc166883d99bc3f42ca4eb6483
705,372
def unmatched(match): """Return unmatched part of re.Match object.""" start, end = match.span(0) return match.string[:start] + match.string[end:]
6d34396c2d3c957d55dbef16c2673bb7f571205c
705,373
def cubicgw(ipparams, width, etc = []): """ This function fits the variation in Gaussian-measured PRF half-widths using a 2D cubic. Parameters ---------- x1: linear coefficient in x x2: quadratic coefficient in x x3: cubic coefficient in x y1: linear coefficient in y y2: quadratic coeffici...
334be9d8dc8baaddf122243e4f19d681efc707cf
705,374
def get_columns_by_type(df, req_type): """ get columns by type of data frame Parameters: df : data frame req_type : type of column like categorical, integer, Returns: df: Pandas data frame """ g = df.columns.to_series().groupby(df.dtypes).groups type_dict = {k.name: v for k, v ...
aeedea92fbfb720ca6e7a9cd9920827a6ad8c6b0
705,376
def get_total(lines): """ This function takes in a list of lines and returns a single float value that is the total of a particular variable for a given year and tech. Parameters: ----------- lines : list This is a list of datalines that we want to total. Returns: -------- ...
284f8061f3659999ae7e4df104c86d0077b384da
705,377
def box(t, t_start, t_stop): """Box-shape (Theta-function) The shape is 0 before `t_start` and after `t_stop` and 1 elsewhere. Args: t (float): Time point or time grid t_start (float): First value of `t` for which the box has value 1 t_stop (float): Last value of `t` for which the ...
8f4f0e57323f38c9cfa57b1661c597b756e8c4e7
705,378
import json import time def sfn_result(session, arn, wait=10): """Get the results of a StepFunction execution Args: session (Session): Boto3 session arn (string): ARN of the execution to get the results of wait (int): Seconds to wait between polling Returns: dict|None: Di...
ba8a80e81aa5929360d5c9f63fb7dff5ebaf91f3
705,379
def RoleAdmin(): """超级管理员""" return 1
78a4fce55fa0fb331c0274c23213ae72afe7184f
705,381
def run_program(intcodes): """run intcodes, which are stored as a dict of step: intcode pairs""" pc = 0 last = len(intcodes) - 1 while pc <= last: if intcodes[pc] == 1: # add if pc + 3 > last: raise Exception("out of opcodes") arg1 = intcodes[...
e87343483abddffd9508be6da7814abcbcd59a79
705,382
def to_numpy(tensor): """Convert 3-D torch tensor to a 3-D numpy array. Args: tensor: Tensor to be converted. """ return tensor.transpose(0, 1).transpose(1, 2).clone().numpy()
034e016caccdf18e8e33e476673884e2354e21c7
705,383
def decorator(IterativeReconAlg, name=None, docstring=None): """ Calls run_main_iter when parameters are given to it. :param IterativeReconAlg: obj, class instance of IterativeReconAlg :param name: str for name of func :param docstring: str other documentation that may need ...
0c7224ea3d58c367d8b7519f7f8ba4d68c00076e
705,384
import time def wait_for_result(polling_function, polling_config): """ wait_for_result will periodically run `polling_function` using the parameters described in `polling_config` and return the output of the polling function. Args: polling_config (PollingConfig): The p...
663f23b3134dabcf3cc3c2f72db33d09ca480555
705,386
def file_version_summary(list_of_files): """ Given the result of list_file_versions, returns a list of all file versions, with "+" for upload and "-" for hide, looking like this: ['+ photos/a.jpg', '- photos/b.jpg', '+ photos/c.jpg'] """ return [('+ ' if (f['action'] == 'upload') else '-...
8ca8e75c3395ea13c6db54149b12e62f07aefc13
705,387
def make_players(data, what_to_replace_null_data_with): """ 1. feature selection 2. replacing null values :param data: :param what_to_replace_null_data_with: accepted values: "1", "mean", "median" :return: players """ players = data[["Overall", "Potential", "Position", "Skill Moves", "C...
081e563f475e7e05caf3761954646b8a35ec8e54
705,388
def pwm_to_duty_cycle(pulsewidth_micros, pwm_params): """Converts a pwm signal (measured in microseconds) to a corresponding duty cycle on the gpio pwm pin Parameters ---------- pulsewidth_micros : float Width of the pwm signal in microseconds pwm_params : PWMParams PWMParams ob...
e627b84bf7e01f3d4dcb98ec94271cd34249fb23
705,389
def decode(codes, alphabet): """ Converts one-hot encodings to string Parameters ---------- code : torch.Tensor One-hot encodings. alphabet : Alphabet Matches one-hot encodings to letters. Returns ------- genes : list of Tensor List of proteins others : list...
79ff69034293a8fb7d005ec89c98ae5e7535e487
705,390
import re def getNormform_space(synonym): """ """ return re.sub("[^a-z0-9]", " ", synonym.lower())
5e03a89ca25cb5b4ae9a76ef9fb44c213a043cbd
705,391
import re def rename_leaves_taxids(tree): """ Rename the leaf nodes with just the NCBI taxonomy ID if we have it :param tree: the tree to rename :return: the tree with renamed leaves """ for n in tree.get_leaves(): m = re.search(r'\[(\d+)\]', n.name) if m: n.name =...
26b55177b1e9372ff58f3a79ab703c639661551c
705,392
from typing import Dict def remove_none_dict(input_dict: Dict) -> Dict: """ removes all none values from a dict :param input_dict: any dictionary in the world is OK :return: same dictionary but without None values """ return {key: value for key, value in input_dict.items() if value is not None...
3f91d653a680f0f9d842ab44cbbb9ea4142c12ab
705,393
import os def is_pro(): """Check if working in PRO""" return os.environ.get("VTASKS_ENV", "False") == "True"
e193f5d6e4c24d57a2903fcb5714d5f7a8473fcb
705,394
import os def pick_projects(directory): """ Finds all subdirectories in directory containing a .json file :param directory: string containing directory of subdirectories to search :return: list projects found under the given directory """ ext = '.json' subs = [x[0] for x in os.walk(directo...
577668e5f7729bb3fcfa39398b7fade9475fefbe
705,395
def inject_where(builder): """ helper function to append to the query the generated where clause :param builder: the current builder :return: """ query = builder.v.query if callable(query): return builder lower = query.lower() where = lower.find(' where ') before = -1 for before_q in [' group ...
78682f5c3712ffcb9e96a8c7c624d6f0177884ec
705,396
def main(): """ The main function to execute upon call. Returns ------- int returns integer 0 for safe executions. """ print("Program to find the character from an input ASCII value.") ascii_val = int(input("Enter ASCII value to find character: ")) print("\nASCII {asci} ...
45bec0eb658cc17005b97e6fa812c806f5b77440
705,397
def requires_ids_or_filenames(method): """ A decorator for spectrum library methods that require either a list of Ids or a list of filenames. :param method: A method belonging to a sub-class of SpectrumLibrary. """ def wrapper(model, *args, **kwargs): have_ids = ("ids" in kwargs) a...
df4cb705f11567e8e5a23da730aead8e7c90f378
705,398
import io import tokenize def remove_comments_and_docstrings(source): """ Returns *source* minus comments and docstrings. .. note:: Uses Python's built-in tokenize module to great effect. Example:: def noop(): # This is a comment ''' Does nothing. ''' ...
ffd185fc2517342e9eb0e596c431838009befde5
705,399
def prettify_name_tuple(tup): """ Processes the intersect tuples from the steam API. """ res = [] for name in tup: res.append(name.split("_")[0]) return ", ".join(res)
68d9e7170f02cf4a5de434806e7abcd99e5a77e7
705,400
import sys def open_file(file_name): """ Opens a comma separated CSV file Parameters ---------- file_name: string The path to the CSV file. Returns: -------- Output: the opened file """ # Checks for file not found and perrmission errors try: f = open(file_n...
21e3abe90fbfb169568ef051fa3f130cc7f1315a
705,401
def parse_data_name(line): """ Parses the name of a data item line, which will be used as an attribute name """ first = line.index("<") + 1 last = line.rindex(">") return line[first:last]
53a9c7e89f5fa5f47dad6bfc211d3de713c15c67
705,402
def api_error(api, error): """format error message for api error, if error is present""" if error is not None: return "calling: %s: got %s" % (api, error) return None
a9269a93d51e3203646886a893998ffec6488c95
705,403
def build_template(ranges, template, build_date, use_proxy=False, redir_target=""): """ Input: output of process_<provider>_ranges(), output of get_template() Output: Rendered template string ready to write to disk """ return template.render( ranges=ranges["ranges"], header_comments=...
ec10897cb6f92e2b927f4ef84511a7deab8cd37d
705,405
import textwrap def _strip_and_dedent(s): """For triple-quote strings""" return textwrap.dedent(s.lstrip('\n').rstrip())
8d392daede103cb2a871b94d415c705fa51d7cef
705,406
def returns_normally(expr): """For use inside `test[]` and its sisters. Assert that `expr` runs to completion without raising or signaling. Usage:: test[returns_normally(myfunc())] """ # The magic is, `test[]` lifts its expr into a lambda. When the test runs, # our arg gets evaluated ...
469447c704247f46a0cebf1b582c08d36f53383f
705,407
import re def finder(input, collection, fuzzy=False, accessor=lambda x: x): """ Args: input (str): A partial string which is typically entered by a user. collection (iterable): A collection of strings which will be filtered based on the `input`. fuzzy (bool): perform a fuz...
1bbe22f6b38f447f20071bd810cfee6e4e491f5f
705,408
def str2int(video_path): """ argparse returns and string althout webcam uses int (0, 1 ...) Cast to int if needed """ try: return int(video_path) except ValueError: return video_path
2d4714ec53304fb6cafabd5255a838b478780f8a
705,409
def describe_inheritance_rule(rule): """ Given a dictionary representing a koji inheritance rule (i.e., one of the elements of getInheritanceData()'s result), return a tuple of strings to be appended to a module's stdout_lines array conforming to the output of koji's taginfo CLI command, e.g.: ...
32eae010365d8fd5b253f23acf8104932773c7c1
705,410
def find_colour(rgb): """Compare given rgb triplet to predefined colours to find the closest one""" # this cannot normally happen to an image that is processed automatically, since colours # are rbg by default, but it can happen if the function is called with invalid values if rgb[0] < 0 or rgb[0] > 25...
f2c6e2b7daa7fd45411376cfc64409486c18e252
705,411
def log_sum_exp(input, dim=None, keepdim=False): """Numerically stable LogSumExp. Args: input (Tensor) dim (int): Dimension along with the sum is performed keepdim (bool): Whether to retain the last dimension on summing Returns: Equivalent of log(sum(exp(inputs), dim=dim, k...
c9c867d9d81191922a56716dab128ea71821a638
705,412
def make_screen_hicolor(screen): """returns a screen to pass to MainLoop init with 256 colors. """ screen.set_terminal_properties(256) screen.reset_default_terminal_palette() return screen
1fa4ee36825ca9672af58332001463e5b804d171
705,413
def cached_object_arg_test(x): """takes a MyTestClass instance and returns a string""" return str(x)
5880976f0c74dc588b1b4e93cee349fee06473ee
705,414
def adriatic_name(p, i, j, a): """ Return the name for given parameters of Adriatic indices""" #(j) name1 = {1:'Randic type ',\ 2:'sum ',\ 3:'inverse sum ', \ 4:'misbalance ', \ 5:'inverse misbalance ', \ 6:'min-max ', \ 7:'max-mi...
d08ed926d80aa19326ab4548288a0b9cb02737e4
705,415
def gcd(number1: int, number2: int) -> int: """Counts a greatest common divisor of two numbers. :param number1: a first number :param number2: a second number :return: greatest common divisor""" number_pair = (min(abs(number1), abs(number2)), max(abs(number1), abs(number2))) while number_pair[...
9f22c315cc23e2bbf954f06d416a2c44f95ddbb7
705,416
def get_overlapping_timestamps(timestamps: list, starttime: int, endtime: int): """ Find the timestamps in the provided list of timestamps that fall between starttime/endtime. Return these timestamps as a list. First timestamp in the list is always the nearest to the starttime without going over. Par...
0ad6836d43d670f811b436e34887e159462c9ec1
705,417
import os def get_field_h5files(sdir, prefix_dirs="ph"): """Return names of field h5 files in a directory Parameters ---------- sdir: str Path to the search directory prefix_dirs: str If no matching files are found in sdir, search subdirectories whose name starts with thi...
4940a3ea642e477481ff926a7d5638d6af6e0120
705,418
def is_sequence(arg): """Check if an object is iterable (you can loop over it) and not a string.""" return not hasattr(arg, "strip") and hasattr(arg, "__iter__")
466154b8ef9d19b53744187d44dc6cd172a70f62
705,419
def fix_stddev_function_name(self, compiler, connection): """ Fix function names to 'STDEV' or 'STDEVP' as used by mssql """ function = 'STDEV' if self.function == 'STDDEV_POP': function = 'STDEVP' return self.as_sql(compiler, connection, function=function)
b1fa48801fb397590ad5fb249d928906e7c21c8a
705,420
def process_hub_timeout(bit): """Return the HUB timeout.""" if bit == '1': return '5 Seconds' return '2 Seconds'
64f11056a341d64d670e2e8c918a796c954854a1
705,422
def d_d_theta_inv(y, alpha): """ xi'(y) = 1/theta''(xi(y)) > 0 = alpha / (1 - |y|)^2 Nikolova et al 2014, table 1, theta_2 and eq 5. """ assert -1 < y < 1 and alpha > 0 denom = 1 - abs(y) return alpha / (denom*denom)
8ed796a46021f64ca3e24972abcf70bd6f64976d
705,424
def center_crop(img, crop_height, crop_width): """ Crop the central part of an image. Args: img (ndarray): image to be cropped. crop_height (int): height of the crop. crop_width (int): width of the crop. Return: (ndarray): the cropped image. """ def get_center_crop_...
6e5fafee8c34632b61d047e9eb66e9b08b5d0203
705,425
import os def cmk_arn_value(variable_name): """Retrieve target CMK ARN from environment variable.""" arn = os.environ.get(variable_name, None) if arn is None: raise ValueError( 'Environment variable "{}" must be set to a valid KMS CMK ARN for examples to run'.format( va...
d235ad95c050bd68d8428d6c0d737ad394a5d1ea
705,426
def approximated_atmo_spectrum(energy): """Gives an approximated atmospheric neutrino spectrum. Can be used for comparing expected true energy distribution to recorded energy proxy distributions. It is normalised such that the weight for an energy of 1 is equal to 1. (It is agnostic to energy units) ...
86768b5ba0bd31ef19a89dfe27af6c793492daa7
705,427
def obj_size_avg_residual(coeffs, avg_size, class_id): """ :param coeffs: object sizes :param size_template: dictionary that saves the mean size of each category :param class_id: nyu class id. :return: size residual ground truth normalized by the average size """ size_residual = (coeffs - av...
8d44d4ebf273baf460195ec7c6ade58c8d057025
705,428
def _get_chromosome_dirs(input_directory): """Collect chromosome directories""" dirs = [] for d in input_directory.iterdir(): if not d.is_dir(): continue # Just in case user re-runs and # does not delete output files elif d.name == 'logs': continue ...
5047c0c158f11794e312643dbf7d307b381ba59f
705,429
def format_imports(import_statements): """ ----- examples: @need from fastest.constants import TestBodies @end @let import_input = TestBodies.TEST_STACK_IMPORTS_INPUT output = TestBodies.TEST_STACK_IMPORTS_OUTPUT @end 1) format_imports(import_input) -> output ----- :...
91514d19da4a4dab8c832e6fc2d3c6cbe7cca04a
705,430
import mpmath def sf(k, r, p): """ Survival function of the negative binomial distribution. Parameters ---------- r : int Number of failures until the experiment is stopped. p : float Probability of success. """ with mpmath.extradps(5): k = mpmath.mpf(k) ...
d836e2cd762c5fa2be11d83aae31ba5d8589b3f0
705,431
def _grid_in_property(field_name, docstring, read_only=False, closed_only=False): """Create a GridIn property.""" def getter(self): if closed_only and not self._closed: raise AttributeError("can only get %r on a closed file" % field_name...
891e3a828b496467c201ad14e0540abf235d7e64
705,432
def extract_signals(data, fs, segmentation_times): """ Signal that given the set of segmentation times, extract the signal from the raw trace. Args: data : Numpy The input seismic data containing both, start and end times of the seismic data. fs : float The sampling f...
81ff3d0b343dbba218eb5d2d988b8ca20d1a7209
705,433
import math def cos_d(x:int)->float: """ This function takes in input in radians and returns the computed derivaive of cos which is -sin. """ return -math.sin(x)
e8a0ba95d6a53d8c88bfa867dd423e23eb782911
705,434
def access(path, mode): """Use the real uid/gid to test for access to path. :type path: bytes | unicode :type mode: int :rtype: bool """ return False
c0baab44d63bf354e4da9e5d0048d8b05c1f8040
705,435
def follow_card(card, deck_size, shuffles, shuffler): """Follow position of the card in deck of deck_size during shuffles.""" position = card for shuffle, parameter in shuffles: shuffling = shuffler(shuffle) position = shuffling(deck_size, position, parameter) return position
10774bd899afde0d64cbf800bc3dad1d86543022
705,437
import tempfile def get_secure_directory(): """get a temporary secure sub directory""" temp_dir = tempfile.mkdtemp(suffix='',prefix='') return temp_dir
08fb9587a2d17778e9a733312b08b504d6aff7bd
705,438
def area(shape): """Multimethod dispatch key""" return shape.get('type')
0561d97ad21afdda160bd3063948e884a5c02945
705,439
import torch def besseli(X, order=0, Nk=64): """ Approximates the modified Bessel function of the first kind, of either order zero or one. OBS: Inputing float32 can lead to numerical issues. Args: X (torch.tensor): Input (N, 1). order (int, optional): 0 or 1, defaults to 0. ...
5233398b240244f13af595088077b8e43d2a4b2f
705,440
import random def print_mimic(mimic_dict, word): """Given mimic dict and start word, prints 200 random words.""" line, text = '', '' # Iterating 200 time to pick up random keys and values for count in range(0, 200): key = random.choice(list(mimic_dict.keys())) val = mimic_dict.get(key...
61dea92175feff7cb3e3744460ccf692cfc18ca7
705,441
def check_grid_side(ctx, param, value: int) -> int: """ check the size of the grid :type value: int """ if value < 5: raise ValueError("all sides of grid must be at least 5") return value
9e1403ca90c8f0716e10248b418ca59fe501c0c4
705,442
def min_rank(series, ascending=True): """ Equivalent to `series.rank(method='min', ascending=ascending)`. Args: series: column to rank. Kwargs: ascending (bool): whether to rank in ascending order (default is `True`). """ ranks = series.rank(method="min", ascending=ascending) ...
a772618570517a324a202d4803983240cb54396b
705,443
def algorithms(): """Get a list of the names of the available stemming algorithms. The only algorithm currently supported is the "english", or porter2, algorithm. """ return ['english']
d09bef4090fbca1729a25784d7befdb8a436bfa6
705,444
import yaml def load_yaml(filepath): """Import YAML config file.""" with open(filepath, "r") as stream: try: return yaml.safe_load(stream) except yaml.YAMLError as exc: print(exc)
e1ec81bf36d293788303e4b3379e45ecdfb38dc0
705,445
import json import logging def parse_json(json_path): """ parser JSON Args: json_path: input json file path Returns: json_dict: parser json dict result """ try: with open(json_path) as json_file: json_dict = json.load(json_file) except Exception: l...
4bb9b14d3a751451dd2a75da9b60a355934ffa65
705,446
def _get_ex_msg(obj): """ Get exception message """ return obj.value.message if hasattr(obj, 'value') else obj.message
be7be0657afab2fe1daba174c441d18f12e78355
705,447
def _validate_isofactor(isofactor, signed): """ [Docstring] """ if isofactor[0] == 0.0: return (False, "Error: 'isovalue' cannot be zero") if isofactor[1] <= 1.0: return (False, "Error: 'factor' must be greater than one") if not signed and isofactor[0] < 0: return (False,...
7b4a4faf3671fdee364cdae41e178f8e6a0453b8
705,448
def count_possibilities(dic): """ Counts how many unique names can be created from the combinations of each lists contained in the passed dictionary. """ total = 1 for key, value in dic.items(): total *= len(value) return total
856eee9bac0ddf3dbc7b714bb26fe6d4f003ef95
705,449
def get_dgs(align_dg_dict): """ Function that creates inverse dictionary of align_dg_dict align_dg_dict: dict. Dictionary of alignments and clustering DG assignments Returns dg_align_dict: dict, k=dg_id, v=[alignids] align_dg_dict comes from get_spectral(graph) or get_cliques(graph) """ dgs_...
85bca47657c83d2b308d38f05d1c88d9a78fa448
705,451
from typing import Optional def parse_options(dict_in: Optional[dict], defaults: Optional[dict] = None): """ Utility function to be used for e.g. kwargs 1) creates a copy of dict_in, such that it is safe to change its entries 2) converts None to an empty dictionary (this is useful, since empty diction...
d679539ba29f4acab11f5db59c324473a2e24cc6
705,452
def GetMaxHarmonic( efit ): """Determine highest-order of harmonic amplitudes in an ellipse-fit object""" # We assume that columns named "ai3_err", "ai4_err", "ai5_err", etc. # exist, up to "aiM_err", where M is the maximum harmonic number momentNums = [int(cname.rstrip("_err")[2:]) for cname in efit.colNames ...
e11645efa40ce3995788a05c8955d0d5a8804955
705,453
def no_op(loss_tensors): """no op on input""" return loss_tensors
317474aa2ed41668781042a22fb43834dc672bf2
705,455
import torch def generic_fftshift(x,axis=[-2,-1],inverse=False): """ Fourier shift to center the low frequency components Parameters ---------- x : torch Tensor Input array inverse : bool whether the shift is for fft or ifft Returns ------- shifted array """ ...
8b5f84f0ed2931a3c1afac7c5632e2b1955b1cd5
705,457
def make_new_images(dataset, imgs_train, imgs_val): """ Split the annotations in dataset into two files train and val according to the img ids in imgs_train, imgs_val. """ table_imgs = {x['id']:x for x in dataset['images']} table_anns = {x['image_id']:x for x in dataset['annotations']} keys...
d5851974ad63caaadd390f91bdf395a4a6f1514d
705,458
import tkinter as tk from tkinter import filedialog def select_file(title: str) -> str: """Opens a file select window and return the path to selected file""" root = tk.Tk() root.withdraw() file_path = filedialog.askopenfilename(title=title) return file_path
59fdb7945389c2ba75d27e1fe20b596c4497bac1
705,459
def _loop_over(var): """ Checks if a variable is in the form of an iterable (list/tuple) and if not, returns it as a list. Useful for allowing argument inputs to be either lists (e.g. [1, 3, 4]) or single-valued (e.g. 3). Parameters ---------- var : int or float or list Variable to che...
254143646416af441d3858140b951b7854a0241c
705,461
from typing import Any from typing import List from typing import Dict def transform_database_account_resources( account_id: Any, name: Any, resource_group: Any, resources: List[Dict], ) -> List[Dict]: """ Transform the SQL Database/Cassandra Keyspace/MongoDB Database/Table Resource response for neo4j...
dac566a1e09e1e395ff6fb78d6f8931a2bca58cb
705,462
def find_max_1(array: list) -> int: """ O(n^2) :param array: list of integers :return: integer """ overallmax = array[0] for i in array: is_greatest = True for j in array: if j > i: is_greatest = False if is_greatest: overallm...
9bab28c3d72062af75ac5c2e19c1e9d87e6fc468
705,463
def file_size(value, fmt="{value:.1f} {suffix}", si=False): """ Takes a raw number of bytes and returns a humanized filesize. """ if si: base = 1000 suffixes = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") else: base = 1024 suffixes = ("B", "KiB", "MiB", "GiB"...
272250966c0d301a86a136a7e84af6049e9fe47f
705,464