content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
from typing import Dict from typing import Any from typing import List def set_user_defined_functions( fha: Dict[str, Any], functions: List[str] ) -> Dict[str, Any]: """Set the user-defined functions for the user-defined calculations. .. note:: by default we set the function equal to 0.0. This prevents ...
5078168319e4360f3ac3b3c02087439e5175da07
654,195
import math def compute_colors(n, cols): """Interpolate a list of colors cols to a list of n colors.""" m = len(cols) lst = [] for i in range(n): j = math.floor (i * (m - 1.0) / (n - 1.0)) k = math.ceil (i * (m - 1.0) / (n - 1.0)) t = (i * (m - 1.0) / (n - 1.0)) - j (r0...
121f2080faa3ca9d574572a47c231fc525ee74fe
651,450
def output_dest_addr(pnr, settings): """ Output destination address in pnr header. """ return settings.dest_addr
91d6bd55bbabdc58ce1c5d7770960c40134cac7a
403,713
import torch def cos_dist_mat(x, y): """ Cos similarity :param x: [n1, d] :param y: [n2, d] :return: [n1, n2] """ n1, d1 = x.shape n2, d2 = y.shape assert d1 == d2 if n1 * n2 > 10000: D = torch.cat( [torch.cosine_similarity(x[i].view(1, 1, d1), y.view(1, n2...
148a93e3f55bdfafe99dcca49beb488ae85ca5e8
377,118
import collections def countSeqs(seqs): """ Count n-gram statistics on a collection of sequences. Parameters ---------- seqs : iterable( iterable(Hashable) ) Returns ------- bigram_counts : collections.defaultdict((Hashable, Hashable) -> int) unigram_counts : collections.defaultdict(...
6c692c25c42e9e381f792f0674a96e0107a11e30
390,062
def check_scenarios(scenes): """ Make sure all scenarios have unique case insensitive names """ assert len(scenes) == len(dict((k.lower(), v) for k, v in scenes)) return scenes
c9b437d396a4d0ca17c17a85cb99e8574cc78fe3
22,127
def perfect_weighted_distance(reference: dict) -> int: """ The nature of the algorithm causes some double counting to occur when we are recording contig lengths. Here we find out what the "length" of a completely correct assembly would be, and use that as the max length. Args: reference: T...
99748e7b321b9474b3bc7be883d981044070fa7e
175,494
from time import sleep def fatorial(num, show=False): """ -> O fatorial calcula o fatorial de um número :param num: O número a ser calculado o fatorial :param show: (opcional) Mostra ou não a conta :return: O valor do Fatorial de um número n """ fat = 1 print('-'*30) if show: ...
f0ea977f5164a25106ce7768b725962bf4ed9af1
140,716
def is_leap(year: int) -> bool: """Returns True if year is a leap year :param: year: Represents a year :returns: bool: True if year is a leap year """ # Leap years are years that are divisible by 4, and not by 100 OR are divisible by 400! CASE1: bool = year % 4 == 0 CASE2: b...
2a414ebae6a80139c1614853cbd25c1520149a88
58,699
def _dotted_path(segments): """Convert a JS object path (``['dir/', 'file/', 'class#', 'instanceMethod']``) to a dotted style that Sphinx will better index.""" segments_without_separators = [s[:-1] for s in segments[:-1]] segments_without_separators.append(segments[-1]) return '.'.join(segments_with...
58219b0ff710438401f9c2ef773db0b17a3f3d32
401,354
import math def get_distance_between_coords(point1, point2): """ Computes the distance between to GPS coordinates. :param point1: :param point2: :return: distance between two GPS coordinates in meters """ R = 6371000 lat1 = math.radians(point1[0]) lat2 = math.radians(point2[0]) ...
15d78a6f6d52aeb64ce2917befb39bdda550d950
211,068
def check_views(views): """Checks which views were selected.""" if views is None: return range(3) views = [int(vw) for vw in views] out_views = list() for vw in views: if vw < 0 or vw > 2: print('one of the selected views is out of range - skipping it.') out_vie...
edfd0234cb1c8955176f52f53d74bd0f0cfbdeb6
345,647
def get_mean_intersection_over_union(scores): """ MIOU generated by averaging IOUs of each class, unweighted :param scores: an array of ClassificationScore objects :return: 0->1 where 1 implies perfect intersection """ iou = 0 for score in scores: iou += score.get_iou() if len(sc...
55c469c2a7ddfffb93e89f9cef14d386bd455756
445,812
import socket def port_is_open(adr, timeout=1, attempts=1): """ Returns `true` if the tcp address *ip*:*port* is reachable. Parameters: * adr The network address tuple of the target. * timeout Time in seconds waited until a connection attempt is conside...
859ae0217056f83870fee49959fc15e8ca3ce10f
549,553
import hashlib from pathlib import Path def dir_hash(directory): """ Return single md5 hash of all filenames and file contents in directory, for comparison. """ hash = hashlib.md5() path = Path(directory) if not path.exists(): raise FileNotFoundError for file in sorted(path.g...
0212555485be8c6c4a7193c5699b0d7bbc1bcf76
161,624
def generate_select(data, id=''): """Generates a select box from a tuple of tuples .. code-block:: python generate_select(( ('val1', 'Value One'), ('val2', 'Value Two'), ('val3', 'Value Three') )) will return:- .. code-block:: html <select id=''...
93018131712ad662ace2c66ba66afbd14bb22364
199,589
def enough(cap: int, on: int, wait: int) -> int: """ The driver wants you to write a simple program telling him if he will be able to fit all the passengers. If there is enough space, return 0, and if there isn't, return the number of passengers he can't take. You have to write a function that...
3333d31c1de9d77871ee15ca3960dc83898371e3
268,905
def parse_word_list_file(file_name): """Creates a jumble dictionary from a file containing a list of words Args: file_name (str): Name of file containing a list of words Returns: dict[list[str]]: Jumble dictionary, keys are sorted words, values are list of original words """ jumble...
e72ec50d5cae539a76566063d1f5cde5b4797194
533,052
def _displacements_yaml_lines_type1_info(dataset): """Return lines of displacement-pair summary.""" n_single = len(dataset["first_atoms"]) n_pair = 0 n_included = 0 for d1 in dataset["first_atoms"]: n_pair += len(d1["second_atoms"]) for d2 in d1["second_atoms"]: if "inclu...
0ca1bdf92be1302b1dbbd9a08ee933c7ff626884
442,653
def split(path, blocksize): """ Split the file into blocks according to the given size. Input: `path`: video path `blocksize`: size of each block Output: list contain splitted blocks """ with open(path, 'rb') as video: byte_content = video.read() length = len(byte_con...
cb428b555cc08f31a34ccada2db6b0cb09981456
492,754
def image_transform_crop(img, new_shape=[160, 160]): """ Crops an image to new dimensions (assumes you want to keep the centre) Parameters ---------- img : np.ndarray Input image new_shape : tuple Expected new shape for image Returns ------- np.ndarray Resha...
b7e0f3ab30b813addd5ce2a556b693ee1ab38df8
122,151
def UppercaseMutator(current, value): """Uppercase the value.""" return current.upper()
ee16c6a92cd7e3f4d55859d22ab7a23c0a39af9b
624,764
def calc_gene_length(file_path): """Read in a FASTA file and calculate sequence length. Assumes a typical one line header for a FASTA file. **Parameters** file_path : str Path to FASTA file **Returns** seq_len : int length of gene """ with open(file_path) as handle: ...
f95504a4aebd8b4a81373aaa7a342a98a5579068
88,726
def make_valid_latex_string(s: str) -> str: """ Take a string and make it a valid latex math string by wrapping it with "$"" when necessary. Of course, strings are only wrapped with the "$" if they are not already present. Args: s: The input string. Returns: The properly formatted stri...
9f2355cb7a4f59efa47f40a746149804ac5f0229
79,804
def user_query(query: str = 'save?', entry: list = ['y', 'n']): """ user_query(query, choices) Args: query (str, optional): [promt the user with this]. Defaults to 'save?'. choices (list, optional): [what do they type for yay/nay]. Defaults to ['y','n']. Returns: [bool]...
f0141bd6780875d9db02c4a390a04bb1ef34a189
449,964
def filter_dictionary(dict_data, values): """ Create a subset of a dictionary given keys found in a list. The incoming dictionary should have keys that point to dictionary's. Create a subset of that dictionary by using the same outer keys but only using the inner key:val pair if that inner ...
6b5a0266cd9ff2ef484451bc73231d9e7d9a5a1b
356,601
def cli(ctx, dataset_collection_id, maxwait=12000, interval=3, proportion_complete=1.0, check=True): """Wait until all or a specified proportion of elements of a dataset collection are in a terminal state. Output: Details of the given dataset collection. """ return ctx.gi.dataset_collections.wait_for_...
1f19003c2666acbbd2d144bb641433e516a7832a
93,098
def get_ttt(jd:float): """ Get Julian centuries. Args: jd (float): Julan day number. Returns: (float): Julian centuries. """ return (jd - 2451545.0) / 36525.0
1a934050e3303f522619f2723fdfa3d5c8dc46b6
508,457
def format_includes(includes): """ Format includes for the api query (to {'include' : <foo>,<bar>,<bat>}) :param includes: str or list: can be None, related resources to include :return: dict: the formatted includes """ result = None if isinstance(includes, str): result = includes ...
9f15ac9b767b6612794bec7b14427b6f90d4a734
39,067
def lerp(a, b, t): """Linear interpolation.""" return t * b + (1.0 - t) * a
d637b00ba383c48c5e588bada9063320ba2ca5d7
176,323
def read_word_list(filename): """ This function reads the file and returns the words read. It expects a file where each word is in a line. """ # Initialize words list words = [] # Quick'n'dirty file reading with open(filename) as words_file: for line in words_file: words...
e93af9a9d169fb7f2f066c63eccc29f0bbbbf176
194,404
import hashlib def hash100(s: str): """ Hash a string into 1~100. Useful when you split a dataset into subsets. """ h = hashlib.md5(s.encode()) return int(h.hexdigest(), base=16) % 100 + 1
0686d599e42c104d487462682340f04bd3fe94b4
34,069
def int_to_bits(int_str, qubit_count): """ Convert a number (possibly in string form) to a readable bit format. For example, the result '11', which means both qubits were measured as 1, is returned by the API as "3". This converts that output to the readable version. Args: int_str: A string...
1a2d25281c2ec9ff4e885daeba0ff76448bfbf0a
287,691
def Yes_No(value, collection): """ True -> "Yes", green background ; False->"No",red, None to "-",no color """ if value: return ("Yes", "black; background-color:green;") if value == None: return ("-", "black") return ("No", "black; background-color:red;")
856b729ebc5eae2a6e0d1e8ad5a8abc1a649dab3
438,298
def AddFieldToUpdateMask(field, patch_request): """Adds name of field to update mask.""" if patch_request is None: return None update_mask = patch_request.updateMask if update_mask: if update_mask.count(field) == 0: patch_request.updateMask = update_mask + ',' + field else: patch_request.upd...
46634d00751fb05b19199caf67983d4e6275c21c
282,206
def get_predictor_cost(x, y, rho, sens, spec, cov): """ Calculate the predictor's cost on a point (x, y) based on the rho and its sensitivity, specificity and coverage """ return x * ((rho * cov * (1 - sens)) + cov - 1) + y * (((1 - rho) * cov * (1 - spec)) + cov - 1) + 1 - cov
f3e88b9cd16a26e0de8f5c54ae12fb0800b1e17d
100,651
def extend_to_blank(l): """ Transform ['','a','','b',''] into ['','a','a','b','b'] """ out, ext = [], '' for i in l: ext = i or ext out.append(ext) return out
72cb2e398df24d7360d69e1f382fd8e62915b786
358,817
def tokey(item): """ Key function for sorting filenames """ return int(item.split("_")[-1].split(".")[0])
fd53b1306081e1fc63312f2d491cd4994c5d158a
253,939
def cryostat_losses(Acr, dT=228.0): """ Calculating the cryostat losses according to doi: 10.1088/1742-6596/97/1/012318 :param Acr: the surface of the cryostat # m2 :param dT: temperature difference between the maximum outside temperature (40C) and the working temp :return: losses of the cryostat ...
be065f91f2a0ad943b80269bcb55bea4ab30f2d0
376,518
def first(iterable, or_=None): """Get the first element of an iterable. Just semantic sugar for next(it, None). """ return next(iterable, or_)
ef7f2d9834defe477830ca7dd5851644e904d2e7
64,824
def selection_sort(items): """Implementation of selection sort where a given list of items are sorted in ascending order and returned""" for current_position in range(len(items)): # assume the current position as the smallest values position smallest_item_position = current_position # ...
45d94530d5a43175da7ea60bb0ee22ce24d6bded
431,244
import struct def _read_entry(f, type): """Read a protobuf entry from a pirate log file. The pirate stores protobuf messages with the length prepended to the message as an uin32_t. This function first reads the uint32_t to determine the length of the entry and then the message itself. The message...
bbcc78fae9571cf66dd7b88be8bbc572d57bf98c
232,831
def join_string(value): """ Can be used to join strings with "-" to make id or class """ return value.lower().replace(' ', '-')
43fa0ebc7906d2f3963731cd8f74e24b82223bd2
557,856
import torch def entropic_loss(pnl) -> torch.Tensor: """ Return entropic loss function, which is a negative of the expected exponential utility: loss(pnl) = -E[u(pnl)], u(x) = -exp(-x) Parameters ---------- pnl : torch.Tensor, shape (*) Profit-loss distribution. Returns ...
7a8ea92d344fbb3e9effb2c3af9214f28773e12e
457,506
def reconstruct_path_to_destination(prev, end): """ Constructs an in-order sequence of (x,y) coordinates (list of tuples) to the end destination using the mapping from nodes to their predecessors (prev). """ path = [end] curr = end while curr in prev.keys(): curr = prev[curr] ...
7a77fae4d438ec1f2a48b371ac16be31cda0e7db
484,798
def get_high_pin_idx_pull_up(pin_input_values): """Returns the index of the first high pin value. Assumes Pull UP mode. i.e. a stronger force will pull the pin value down to 0. If no high pins were found, None is returned.""" high_pin_idx = ( pin_input_values.index(False) if False in pin_input_values el...
92cad383e5bfa7775a800629fc2650c2070177d1
316,169
import csv def open_metadata_records(fn='nandq_internet_archive.txt'): """Open and read metadata records file.""" with open(fn, 'r') as f: # We are going to load the data into a data structure known as a dictionary, or dict # Each item in the dictionary contains several elements as `key:value...
7d75b08f90f4e15636aa21030e065c8cbbe48931
233,853
def get_trial_results(trial): """Format results from a `orion.core.worker.trial.Trial` using standard structures.""" results = dict() lie = trial.lie objective = trial.objective if lie: results["objective"] = lie.value elif objective: results["objective"] = objective.value ...
1569b0b0f77e5c3c5416c6a3a4e1e181b4dadda9
247,141
import math def _raw_stat(base: int, ev: int, iv: int, level: int, nature_multiplier: float) -> int: """Converts to raw stat :param base: the base stat :param ev: Stat Effort Value (EV) :param iv: Stat Individual Values (IV) :param level: pokemon level :param nature_multiplier: stat multiplier...
0f3947ce5b73d629acc830f6f6275013e1de995f
559,850
def _target_ads_in_campaign_to_user_list( client, customer_id, campaign_id, user_list_resource_name ): """Creates a campaign criterion that targets a user list with a campaign. Args: client: an initialized GoogleAdsClient instance. customer_id: a str client customer ID used to create an cam...
28944ade1b3d2d3e94fc39bf1fffc1887d8be868
82,012
import ipaddress def cidr_stix_pattern_producer(data): """Convert a CIDR from TC to a STIX pattern.""" if isinstance(ipaddress.ip_network(data.get('summary'), strict=False), ipaddress.IPv6Network): return f"[ipv6-addr:value = '{data.get('summary')}']" return f"[ipv4-addr:value = '{data.get('summa...
56f7d94fef6d913d6c2bd3afa48d747dc5a4c549
110,115
def raman_intensity(R): """ Scattering intensity Args: R (3x3 numpy array): Susceptibility tensor Returns: float: scattering intensity according to Eq 7, Phys Rev B 73, 104304 2006 """ return ( 4 * (R[0, 0] ** 2 + R[1, 1] ** 2 + R[2, 2] ** 2) + 7 * (R[0, 1] ** 2...
82e7f4caed5fe38f15c60a585aa31bd33498d30d
602,639
def kilometer2meter(dist): """ Function that converts km to m. """ return dist * 1000
508fdf4758353d4a128e95c3933ac30f5fe23988
515,490
def get_lastkey(path, delimiter="/"): """ Return name of the rightmost fragment in path """ return path.split(delimiter)[-1]
0e2287c95974466fae70b15c75aca11d5ed02795
662,580
def find(predicate, array): """ find_.find(list, predicate, [context]) Alias: detect Looks through each value in the list, returning the first one that passes a truth test (predicate), or undefined if no value passes the test. The function returns as soon as it finds an acceptable element, and d...
33d12b252336cf32399f707b9bbfb8a82df89287
367,708
def fp_tuple(fp): """ Build a string that uniquely identifies a key """ # An SSH public key is uniquely identified by the tuple [length, hash, type]] # fp should be a list of results of the `ssh-keygen -l -f` command return ' '.join([fp[0], fp[1], fp[-1]])
b282997ab21cf3a10fb3b8b305fc855077f26081
386,600
def rc_to_xy(row, col, rows): """ Convert from (row, col) coordinates (eg: numpy array) to (x, y) coordinates (bottom left = 0,0) (x, y) convention * (0,0) in bottom left * x +ve to the right * y +ve up (row,col) convention: * (0,0) in top left * row +ve down * col +ve to the...
529f88a99ba5c3143c528df3eb844be834568c20
654,117
def _split_repo_url(url): """Split a repository URL into an org / repo combination.""" if "github.com/" in url: end = url.split("github.com/")[-1] org, repo = end.split("/")[:2] else: raise ValueError( f"Currently Binder/JupyterHub repositories must be on GitHub, got {url...
47a7a80cbf4d58b2874472ae337eca3a1d6a12ac
526,987
from typing import Iterable import six def is_iterable(arg): """ Returns True if object is an iterable and is not a string, false otherwise """ return isinstance(arg, Iterable) and not isinstance(arg, six.string_types)
07664a14d6ac3fbf754d37ae4ae1057a6bfa31c3
355,414
def calc_temp(Data_ref, Data): """ Calculates the temperature of a data set relative to a reference. The reference is assumed to be at 300K. Parameters ---------- Data_ref : DataObject Reference data set, assumed to be 300K Data : DataObject Data object to have the temperatu...
15c4f998c9581db6336648d8176a5ec33874e492
465,300
def time_mirror(clip): """ Returns a clip that plays the current clip backwards. The clip must have its ``duration`` attribute set. The same effect is applied to the clip's audio and mask if any. """ return clip.time_transform(lambda t: clip.duration - t - 1, keep_duration=True)
4f7283cf53090946ed41fc1c736a7c84f7cfba37
690,306
import posixpath def normalize_path_posix(path): """ normalize_path_posix(path) -> str Turn path into a relative POSIX path with no parent directory references. """ return posixpath.relpath(posixpath.normpath(posixpath.join('/', path)), '/')
ca816b6e4902b06c5a76c10a24fc0de64cf1ac3d
112,510
def filter_claims_by_date(claims_data, from_date, to_date): """Return claims falling in the specified date range.""" return [ claim for claim in claims_data if (from_date <= claim.clm_from_dt <= to_date) ]
d1568d0fd52382bdb3f1f02414f591d5f4da3596
7,297
import string def get_filename_from_title(title): """Generate simpler file name from title Arguments: title {string} -- Simplified title to be used as the markdown filename """ printable = set(string.ascii_letters) printable.add(' ') return ''.join(filter(lambda x : x in printable, ti...
05917929adebc45c2e7a3b3294ce607e3400ecd3
221,005
def build_fib_iterative(n): """ n: number of elements in the sequence Returns a Fibonacci sequence of n elements by iterative method """ if n == 1: return [0] elif n == 2: return [0, 1] else: fib = [0, 1] count = 2 while count < n: last_el...
edd2e95db7a7e9039f45dcd70a19521ccbe4c904
213,774
def create_log_message_payload(message: str): """Create and return "logMessage" dictionary to send to the Plugin Manager. As per Stream Deck documentation: Logs are saved to disk per plugin in the folder `~/Library/Logs/StreamDeck/` on macOS and `%appdata%\\Elgato\\StreamDeck\\logs\\` on Windows. Note ...
bf0659ea3654aca6b82d0f37e3e6cbdb523334f8
321,943
def get_object_name_by_faceid(oEditor, faceid): """ Return the object name corresponding to the given face ID. Parameters ---------- oEditor : pywin32 COMObject The HFSS editor in which the operation will be performed. faceid : int The face ID of the given face. Ret...
4803b3ca95ca054e1534ea5cc2b0bc563ee57de2
143,934
def exchange_rate_format(data): """Return a dict with the exchange rate data formatted for serialization""" return { 'provider_1': { 'name': 'dof', 'rate': data.dof_rate, 'date': data.dof_date, 'last_updated': data.dof_last_updated, }, 'pro...
47dbc58bf1c49d14372333cb38ef4fc8ea624490
57,600
def _use_static_reflect_func(opt): """ Whether a static reflect function is to be used. """ if opt.algorithm == opt.algo_table_driven: return False elif opt.reflect_out is not None and opt.algorithm == opt.algo_bit_by_bit_fast: return False else: return True
558914c91d0cec0b6a7483464abe20014c329ad1
552,161
def weak_scaling(timing_stats, scaling_var, data_points): """ Generate data for plotting weak scaling. The data points keep a constant amount of work per processor for each data point. Args: timing_stats: the result of the generate_timing_stats function scaling_var: the variable to sel...
aa0e736f505cbc41534d3d94ad97f5fe0ca3c2e7
338,929
def count_digit(k, n): """ Count the number of k's between 0 and n. k can be 0 - 9. :param k: given digit :type k: int :param n: given number :type n: int :return: number of k's between 0 and n :rtype: int """ count = 0 for i in range(n + 1): # treat number as string...
c232eb11a5fd7807ab468cea78f95ffe6d122e47
233,885
def update_parameters(parameters, gradients, learning_rate): """ Performs a gradient descent update. :param parameters: weights and bias units :param gradients: partial derivatives w.r.t. the weights and the bias units :param learning_rate: gradient descent step size :return: updated gradients ...
6b833ab6fe868bea9b3a473d4349286a0c79f1da
550,354
def quote(input_str): """Adds single quotes around a string""" return "'{}'".format(input_str)
2756faeadffa84a8ff09a8ce8ea4b0b8ba328d24
52,612
def add_linear_gather_for_mode( m, Fr, Ft, Fz, exptheta_m, Fr_grid, Ft_grid, Fz_grid, iz_lower, iz_upper, ir_lower, ir_upper, S_ll, S_lu, S_lg, S_ul, S_uu, S_ug ): """ Add the contribution of the gathered field from azimuthal mode `m` to the fields felt by one macroparticle (`Fr`, `Ft`, `Fz`), u...
8ad3a174a8bb4a93e207fea935ddf376009ada25
269,887
def checkForQuote(file): """add quotes if find spaces in file name""" f = str(file) if f.find(" ") >= 0: return "'" + f + "'" return f
0423e565cde93c4ce1d4afee6beeae8b3176b8fd
199,890
import torch def SNRPSA(s,s_hat): """Computes the SNR_PSA as proposed in [1], with no compression and a saturation value of 20 References ---------- .. [1] Erdogan, Hakan, and Takuya Yoshioka. "Investigations on Data Augmentation and Loss Functions for Deep Learning Based Speech-Background Separa...
9780ff2715fc948b48a0969445dd5b2ef80b91eb
474,822
def is_indexed_foreign_key(constraint): """ Whether or not given foreign key constraint's columns have been indexed. :param constraint: ForeignKeyConstraint object to check the indexes """ return any( set(column.name for column in index.columns) == set(constraint.columns) ...
41811f8d18fc16951dfc8d5d3306279eab59c416
253,796
def define_activation(df, targets, input_columns, test_blocks, n_samples=None, exclude=None, scale=1): """ Function to build training objects for neural networks from a DataFrame Parameters ---------- df: DataFrame targets: list of strings list of targets (values in df.targ...
d87d0379d724b7648f7c6a10442bb790fb1feb53
443,465
def getDirectChildrenWithName(parent, name): """ Fetch *direct* sub-nodes of a `parent` DOM tree. These nodes must have a name matching `name`. Return a list of DOM Nodes. """ return [ node for node in parent.childNodes if node.nodeType == node.ELEMENT_NODE and \ n...
817518b3ca595238b290e4853f49f5df6cec64a2
303,003
def shpBBoxExpand(box, x, y=None): """ Given a shapely bounding box, return new one expanded by given amount. If y is not supplied, it the same as x. """ if y is None: y = x return (box[0] - x, box[1] - y, box[2] + x, box[3] + y)
c0a308a483b1a3a39dbf853b1d4d1e484667555b
464,883
import textwrap def dedent(ind, text): """ Dedent text to the specific indentation level. :param ind: common indentation level for the resulting text (number of spaces to append to every line) :param text: text that should be transformed. :return: ``text`` with all common indentation removed, and...
271b9fd270d78c4bc952af31d3d9be0ff6bdab73
1,301
import re def split_composite_term(x, joint_re = 'with'): """Break terms that are composites padding several words without space. This has been observed in one case study but may not be prevalent. Args: x (str): the term to split if matching, e.g. 'claywithsand' to 'clay with sand' joint_re (...
73292e684b00bba496f8d92871453a90e88e1384
305,415
import re def prepare_item(item): """ Prepares the items (each one pair from the list of pairs) to be compared. Returns the two items as separate strings. """ item = re.split(r'\] {', item) item1 = item[0][2:-1] item2 = item[1][1:-2] return item1, item2
4b2b410b6647bc9c3cbf3bee3ab168ad5e7d3e0f
359,012
def format_prob(prob, n_samples): """Translates a probability into a neat string""" if prob < 1/n_samples: return "-" elif prob > (n_samples - 1)/n_samples: return "✓" elif prob < 0.001: return "<0.1%" elif prob > 0.999: return ">99.9%" else: return f"{pro...
296ac2cc177cde1ebc4954435c6a041c7e4de22a
491,762
import json def get_person_person_key(person1_id: str, person2_id: str): """ Get a unique string from the 2 person IDs in a deterministic way. :param person1_id: the ID of the first person :param person2_id: the ID of the second person :return: the derived unique key """ return json.dumps...
cc26c6b6ef632c2ac3cffa085a6aeb6960b047fc
355,160
def localize(value, locale): """ Return the value appropriate for the current locale. This is used to retrieve the appropriate localized version of a value defined within a unit's dictionary. If 'value' is a dictionary, we assume it is a mapping of locale names to values, so we sel...
641b6598aef2486b22846b8b799a344c7ae34e4f
553,316
def _dusort (seq, decorator, reverse = False) : """Returns a sorted copy of `seq`. The sorting is done over a decoration of the form `decorator (p), i, p for (i, p) in enumerate (seq)`. >>> _dusort ([1, 3, 5, 2, 4], lambda e : -e) [5, 4, 3, 2, 1] """ temp = [(decorator (p), i, p...
f4d9afab55b7bcceabf96bfe78c8b6d91c89c55c
544,025
def create_n_users(size): """Create n users and return as a list""" users = [] for i in range(size): users.append({ "first_name": "First%d" % i, "last_name": "First%d" % i, "credit_card": i, "email": "%dgmai.com" % i, "username": "username%...
5828d81ac254f5606d085dbae43ad396ecf077c4
465,555
def get_zero_vector(numBytes): """ Generates a zero vector of a given size :param numBytes: :return: """ return bytearray([0] * numBytes).decode('ascii')
b53c021240b060f4eed38bef570b2615a1bc925a
254,990
def fillna(df, cols=None, fill_val='__missing__'): """ A wrapper for pandas fillna function Args: df - a pandas DataFrame cols - None or list of column names if None, fillna is called on the entire DataFrame if a list of columns, fillna is called only on th...
b3e6ddc9de19203aff14008e7a577faf101d0d9d
288,161
def harmonize_name(name, name_lookup): """Looks up harmonized school name Parameters ---------- name : str The school name to harmonize. name_lookup : iterable of two-value array-likes School names where the first value of each item is harmonized name and second value is li...
cd9d1437850ad7852136dbf8f5713cbeec3217ac
537,436
def calculate_total_votes(poll): """Calculate the total number of votes of a poll.""" total = 0 for vote in poll.votes: total += vote.vote_count return total
4a6314a0a4ffb1a80c8e5a927631ceb5fa646a4b
679,652
def annot(xcrd, ycrd, zcrd, txt, xancr='left'): """ Annotation structure function for plotly :param xcrd: x position :param ycrd: y position :param zcrd: z position :param txt: annotation name :param xancr: anchor position :return: annotation as dict """ annotation = dict(showarr...
4f514af6287cccc028ccd2a2ef98f5881d745c06
97,236
def merge_json(data1, data2): """merge lists in two json data together Args: data1 (json or None): first json data data2 (json): 2nd json data Returns: TYPE: merged data """ if not data1: return data2 else: for i in data2['list']: data1['list...
613b931a6d83ef65be9fada1a99d34984892bdd0
38,937
def find_empty(board): """Function to find empty cells in game board. Args: board (list): the current game board. Returns: (i, j) (tuple): empty position (row, column) if found, otherwise None. """ for i in range(len(board)): for j in range(len(board[0])): if bo...
7ac6d976fea3af469dc94107f4441e00d015f46e
585,418
def get_dictionary(key, resources): """Return a new dictionary using the given key and resources (key value). Keyword arguments: key -- the key to use in the dictionary resources -- the resources to use as the key value """ return { key: resources, }
5f7839834be10d2463c7dd085b76686eee0ebeea
126,167
from functools import reduce import operator def bitor(*args): """ BITOR num1 num2 (BITOR num1 num2 num3 ...) outputs the bitwise OR of its inputs, which must be integers. """ return reduce(operator.or_, args)
f8d3ca6861e2af4d92765efa964ad4d3fedfc94d
637,949
from pathlib import Path def dbt_run_results_file(dbt_artifacts_directory: Path) -> Path: """ Get the path to the dbt run results. Parameters ---------- dbt_artifacts_directory : Path The dbt artifacts directory. Returns ------- out : Path The dbt run results file. ...
b163c2d5afeb627df2ba5a61eace496736c04dbc
314,793
import re def find_meta(meta, meta_file): """Extract __*meta*__ from `meta_file`.""" meta_match = re.search(r"^__{meta}__\s+=\s+['\"]([^'\"]*)['\"]".format(meta=meta), meta_file, re.M) if meta_match: return meta_match.group(1) raise RuntimeError("Unable to find __{meta}__ string.".format(meta=...
e58372db8500e129bd4d7550fac015413ac7c42c
622,654
def learning_rate_scheduler(epoch, values=(0.1, 0.01, 0.001), breakpoints=(100, 150)): """Piecewise constant schedule for learning rate.""" idx = sum(1 if epoch > b else 0 for b in breakpoints) return values[idx]
a30a3270cfd171d3b1948600b7b9edd98f6997f5
378,540