code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def warehouse_query(line, cell): "my cell magic" from IPython import get_ipython parts = line.split() w_var_name = parts.pop(0) w = get_ipython().ev(w_var_name) w.query(cell).close()
my cell magic
def umi_histogram(fastq): annotations = detect_fastq_annotations(fastq) re_string = construct_transformed_regex(annotations) parser_re = re.compile(re_string) counter = collections.Counter() for read in read_fastq(fastq): match = parser_re.search(read).groupdict() counter[match['MB']...
Counts the number of reads for each UMI Expects formatted fastq files.
def readSB(self, bits): shift = 32 - bits return int32(self.readbits(bits) << shift) >> shift
Read a signed int using the specified number of bits
def unmarshaller(self, typed=True): if typed: return UmxEncoded(self.schema()) else: return RPC.unmarshaller(self, typed)
Get the appropriate XML decoder. @return: Either the (basic|typed) unmarshaller. @rtype: L{UmxTyped}
def write_frame(self): if not hasattr(self, 'mwriter'): raise AssertionError('This plotter has not opened a movie or GIF file.') self.mwriter.append_data(self.image)
Writes a single frame to the movie file
def get_assessment_metadata(self): metadata = dict(self._mdata['assessment']) metadata.update({'existing_id_values': self._my_map['assessmentId']}) return Metadata(**metadata)
Gets the metadata for an assessment. return: (osid.Metadata) - metadata for the assessment *compliance: mandatory -- This method must be implemented.*
def upload_submit(self, upload_request): path = '/api/1.0/upload/save' return self._api_post(definition.DatasetUploadResponse, path, upload_request)
The method is submitting dataset upload
def write(self, data, show_progress=False, invalid_data_behavior='warn'): ctx = maybe_show_progress( data, show_progress=show_progress, item_show_func=lambda e: e if e is None else str(e[0]), label="Merging minute equity files:", ) write_sid = self...
Write a stream of minute data. Parameters ---------- data : iterable[(int, pd.DataFrame)] The data to write. Each element should be a tuple of sid, data where data has the following format: columns : ('open', 'high', 'low', 'close', 'volume') ...
def formfield(self, **kwargs): defaults = {'form_class': forms.TimeZoneField} defaults.update(**kwargs) return super(TimeZoneField, self).formfield(**defaults)
Returns a custom form field for the TimeZoneField.
def get_resource_bin_session(self, proxy): if not self.supports_resource_bin(): raise errors.Unimplemented() return sessions.ResourceBinSession(proxy=proxy, runtime=self._runtime)
Gets the session for retrieving resource to bin mappings. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.resource.ResourceBinSession) - a ``ResourceBinSession`` raise: NullArgument - ``proxy`` is ``null`` raise: OperationFailed - unable to complete request ...
def server_poweroff(host=None, admin_username=None, admin_password=None, module=None): return __execute_cmd('serveraction powerdown', host=host, admin_username=admin_username, admin_password=admin_password,...
Powers down the managed server. host The chassis host. admin_username The username used to access the chassis. admin_password The password used to access the chassis. module The element to power off on the chassis such as a blade. If not provided, the chassis ...
def pause(self, scaling_group): uri = "/%s/%s/pause" % (self.uri_base, utils.get_id(scaling_group)) resp, resp_body = self.api.method_post(uri) return None
Pauses all execution of the policies for the specified scaling group.
def _install_hiero(use_threaded_wrapper): import hiero import nuke if "--hiero" not in nuke.rawArgs: raise ImportError def threaded_wrapper(func, *args, **kwargs): return hiero.core.executeInMainThreadWithResult( func, args, kwargs) _common_setup("Hiero", threaded_wrapper...
Helper function to The Foundry Hiero support
def calc_point_distance(self, chi_coords): chi1_bin, chi2_bin = self.find_point_bin(chi_coords) min_dist = 1000000000 indexes = None for chi1_bin_offset, chi2_bin_offset in self.bin_loop_order: curr_chi1_bin = chi1_bin + chi1_bin_offset curr_chi2_bin = chi2_bin + ...
Calculate distance between point and the bank. Return the closest distance. Parameters ----------- chi_coords : numpy.array The position of the point in the chi coordinates. Returns -------- min_dist : float The smallest **SQUARED** metri...
def find_field_by_name(browser, field_type, name): return ElementSelector( browser, field_xpath(field_type, 'name') % string_literal(name), filter_displayed=True, )
Locate the control input with the given ``name``. :param browser: ``world.browser`` :param string field_type: a field type (i.e. `button`) :param string name: ``name`` attribute Returns: an :class:`ElementSelector`
def get_changelog_file_for_database(database=DEFAULT_DB_ALIAS): from django.conf import settings try: return settings.LIQUIMIGRATE_CHANGELOG_FILES[database] except AttributeError: if database == DEFAULT_DB_ALIAS: try: return settings.LIQUIMIGRATE_CHANGELOG_FILE ...
get changelog filename for given `database` DB alias
def _group_sql(self, quote_char=None, groupby_alias=True, **kwargs): clauses = [] selected_aliases = {s.alias for s in self._selects} for field in self._groupbys: if groupby_alias and field.alias and field.alias in selected_aliases: clauses.append("{quote}{alias}{quot...
Produces the GROUP BY part of the query. This is a list of fields. The clauses are stored in the query under self._groupbys as a list fields. If an groupby field is used in the select clause, determined by a matching alias, and the groupby_alias is set True then the GROUP BY clause wil...
def build_target_areas(entry): target_areas = [] areas = str(entry['cap:areaDesc']).split(';') for area in areas: target_areas.append(area.strip()) return target_areas
Cleanup the raw target areas description string
def minutes(self, start_date=None, end_date=None, grouping=None): data = self.__format(start_date, end_date) url = self.base_url + '/minutes' return self.get(url, data=data)
Gets a detailed Report of encoded minutes and billable minutes for a date range. **Warning**: ``start_date`` and ``end_date`` must be ``datetime.date`` objects. Example:: import datetime start = datetime.date(2012, 12, 31) end = datetime.today() ...
def _get_pattern(self, pys_style): if "bgcolor" not in pys_style: return pattern = xlwt.Pattern() pattern.pattern = xlwt.Pattern.SOLID_PATTERN bgcolor = wx.Colour() bgcolor.SetRGB(pys_style["bgcolor"]) pattern.pattern_fore_colour = self.color2idx(*bgcolor.Get(...
Returns xlwt.pattern for pyspread style
def _check_if_must_download(request_list, redownload): for request in request_list: request.will_download = (request.save_response or request.return_data) \ and (not request.is_downloaded() or redownload)
Updates request.will_download attribute of each request in request_list. **Note:** the function mutates the elements of the list! :param request_list: a list of ``DownloadRequest`` instances :type: list[DownloadRequest] :param redownload: tells whether to download the data again or not :type: bool
def replace_media(self,src_file,dst_file): with open(dst_file, 'rb') as fh: crc = self.get_file_crc(src_file) self.crc_to_new_media[crc] = fh.read()
Replace one media by another one into a docx This has been done mainly because it is not possible to add images in docx header/footer. With this function, put a dummy picture in your header/footer, then specify it with its replacement in this function Syntax: tpl.replace_media(...
def try_storage(self, identifier, req, resp, resource, uri_kwargs): if identifier is None: user = None elif self.user_storage is not None: user = self.user_storage.get_user( self, identifier, req, resp, resource, uri_kwargs ) elif self.user_sto...
Try to find user in configured user storage object. Args: identifier: User identifier. Returns: user object.
def _handle_tag_removeobject(self): obj = _make_object("RemoveObject") obj.CharacterId = unpack_ui16(self._src) obj.Depth = unpack_ui16(self._src) return obj
Handle the RemoveObject tag.
def change_exteditor(self): path, valid = QInputDialog.getText(self, _('External editor'), _('External editor executable path:'), QLineEdit.Normal, self.get_option('external_editor/path')) if valid: self.set_...
Change external editor path
def _save_token_cache(self, new_cache): 'Write out to the filesystem a cache of the OAuth2 information.' logging.debug('Looking to write to local authentication cache...') if not self._check_token_cache_type(new_cache): logging.error('Attempt to save a bad value: %s', new_cache) ...
Write out to the filesystem a cache of the OAuth2 information.
def _post_clean(self): super()._post_clean() password = self.cleaned_data.get('password1') if password: try: password_validation.validate_password(password, self.instance) except ValidationError as error: self.add_error('password1', error)
Run password validaton after clean methods When clean methods are run, the user instance does not yet exist. To properly compare model values agains the password (in the UserAttributeSimilarityValidator), we wait until we have an instance to compare against. https://code.djang...
def stop_threadsafe(self): if self.stopped: return try: self._loop.run_coroutine(self.stop()) except asyncio.TimeoutError: raise TimeoutExpiredError("Timeout stopping task {} with {} subtasks".format(self.name, len(self.subtasks)))
Stop this task from another thread and wait for it to finish. This method must not be called from within the BackgroundEventLoop but will inject self.stop() into the event loop and block until it returns. Raises: TimeoutExpiredError: If the task does not stop in the given ...
def set(self, key, val): return self.evolver().set(key, val).persistent()
Return a new PMap with key and val inserted. >>> m1 = m(a=1, b=2) >>> m2 = m1.set('a', 3) >>> m3 = m1.set('c' ,4) >>> m1 pmap({'a': 1, 'b': 2}) >>> m2 pmap({'a': 3, 'b': 2}) >>> m3 pmap({'a': 1, 'c': 4, 'b': 2})
def make_metatiles(size, tiles, date_time=None): groups = defaultdict(list) for tile in tiles: key = tile['layer'] groups[key].append(tile) metatiles = [] for group in groups.itervalues(): parent = _parent_tile(t['coord'] for t in group) metatiles.extend(make_multi_metati...
Group by layers, and make metatiles out of all the tiles which share those properties relative to the "top level" tile which is parent of them all. Provide a 6-tuple date_time to set the timestamp on each tile within the metatile, or leave it as None to use the current time.
def by_interval_lookup(self, style_key, style_value): style_attr = style_key if self.style_types[style_key] is bool else None intervals = style_value["interval"] def proc(value, result): try: value = float(value) except TypeError: return re...
Return a processor for an "interval" style value. Parameters ---------- style_key : str A style key. style_value : dict A dictionary with an "interval" key whose value consists of a sequence of tuples where each tuple should have the form `(start, ...
def get_scores(self, y_i, y_j): z_scores = self.get_zeta_i_j_given_separate_counts(y_i, y_j) return z_scores
Same function as get_zeta_i_j_given_separate_counts Parameters ---------- y_i, np.array(int) Arrays of word counts of words occurring in positive class y_j, np.array(int) Returns ------- np.array of z-scores
def strip_py(arg): for ext in PY_EXTENSIONS: if arg.endswith(ext): return arg[:-len(ext)] return None
Strip a trailing .py or .pyi suffix. Return None if no such suffix is found.
def _get_representative(self, obj): if obj not in self._parents: self._parents[obj] = obj self._weights[obj] = 1 self._prev_next[obj] = [obj, obj] self._min_values[obj] = obj return obj path = [obj] root = self._parents[obj] whi...
Finds and returns the root of the set containing `obj`.
def error_asymptotes(pca,**kwargs): ax = kwargs.pop("ax",current_axes()) lon,lat = pca.plane_errors('upper', n=1000) ax.plot(lon,lat,'-') lon,lat = pca.plane_errors('lower', n=1000) ax.plot(lon,lat,'-') ax.plane(*pca.strike_dip())
Plots asymptotic error bounds for hyperbola on a stereonet.
def _collapse_state(args: Dict[str, Any]): index = args['index'] result = args['result'] prob_one = args['prob_one'] state = _state_shard(args) normalization = np.sqrt(prob_one if result else 1 - prob_one) state *= (_one_projector(args, index) * result + (1 - _one_projector(args, i...
Projects state shards onto the appropriate post measurement state. This function makes no assumptions about the interpretation of quantum theory. Args: args: The args from shard_num_args.
def _handle_author(author): lname = author.split(' ') try: auinit = lname[0][0] final = lname[-1].upper() if final in ['JR.', 'III']: aulast = lname[-2].upper() + " " + final.strip(".") else: aulast = final except IndexError: raise ValueError("...
Yields aulast and auinit from an author's full name. Parameters ---------- author : str or unicode Author fullname, e.g. "Richard L. Nixon". Returns ------- aulast : str Author surname. auinit : str Author first-initial.
def count_sci_extensions(filename): num_sci = 0 extname = 'SCI' hdu_list = fileutil.openImage(filename, memmap=False) for extn in hdu_list: if 'extname' in extn.header and extn.header['extname'] == extname: num_sci += 1 if num_sci == 0: extname = 'PRIMARY' num_sci...
Return the number of SCI extensions and the EXTNAME from a input MEF file.
def check_power(self): packet = bytearray(16) packet[0] = 1 response = self.send_packet(0x6a, packet) err = response[0x22] | (response[0x23] << 8) if err == 0: payload = self.decrypt(bytes(response[0x38:])) if type(payload[0x4]) == int: if payload[0x4] == 1 or payload[0x4] == 3 o...
Returns the power state of the smart plug.
def OnContextMenu(self, event): self.grid.PopupMenu(self.grid.contextmenu) event.Skip()
Context menu event handler
def get_default_keystore(prefix='AG_'): path = os.environ.get('%s_KEYSTORE_PATH' % prefix, config.keystore.path) storepass = os.environ.get('%s_KEYSTORE_STOREPASS' % prefix, config.keystore.storepass) keypass = os.environ.get('%s_KEYSTORE_KEYPASS' % prefix, config.keystore.keypass) alias = os.environ.get('%s_KE...
Gets the default keystore information based on environment variables and a prefix. $PREFIX_KEYSTORE_PATH - keystore file path, default is opt/digger/debug.keystore $PREFIX_KEYSTORE_STOREPASS - keystore storepass, default is android $PREFIX_KEYSTORE_KEYPASS - keystore keypass, default is android $PREFIX_KEYSTOR...
def from_text(text): value = _by_text.get(text.upper()) if value is None: match = _unknown_class_pattern.match(text) if match == None: raise UnknownRdataclass value = int(match.group(1)) if value < 0 or value > 65535: raise ValueError("class must be betwee...
Convert text into a DNS rdata class value. @param text: the text @type text: string @rtype: int @raises dns.rdataclass.UnknownRdataClass: the class is unknown @raises ValueError: the rdata class value is not >= 0 and <= 65535
def get_precision(self): config_str = self.raw_sensor_strings[1].split()[4] bit_base = int(config_str, 16) >> 5 return bit_base + 9
Get the current precision from the sensor. :returns: sensor resolution from 9-12 bits :rtype: int
def find_slot(self, wanted, slots=None): for slot in self.find_slots(wanted, slots): return slot return None
Searches the given slots or, if not given, active hotbar slot, hotbar, inventory, open window in this order. Args: wanted: function(Slot) or Slot or itemID or (itemID, metadata) Returns: Optional[Slot]: The first slot containing the item or N...
def read_file(path): gen = textfile.read_separated_lines_generator(path, max_columns=6, ignore_lines_starting_with=[';;']) utterances = collections.defaultdict(list) for record in gen: values = record[1:len(record)] for i in range(len(values)...
Reads a ctm file. Args: path (str): Path to the file Returns: (dict): Dictionary with entries. Example:: >>> read_file('/path/to/file.txt') { 'wave-ab': [ ['1', 0.00, 0.07, 'HI', 1], ['1', 0.09, 0.08, 'AH', 1] ], ...
def iter_files(self): if callable(self.file_iter): return self.file_iter() return iter(self.file_iter)
Iterate over files.
def crossover(cross): @functools.wraps(cross) def inspyred_crossover(random, candidates, args): if len(candidates) % 2 == 1: candidates = candidates[:-1] moms = candidates[::2] dads = candidates[1::2] children = [] for i, (mom, dad) in enumerate(zip(moms, dads...
Return an inspyred crossover function based on the given function. This function generator takes a function that operates on only two parent candidates to produce an iterable sequence of offspring (typically two). The generator handles the pairing of selected parents and collecting of all offspring. ...
def struct(self): data = {} for var, fmap in self._def.items(): if hasattr(self, var): data.update(fmap.get_outputs(getattr(self, var))) return data
XML-RPC-friendly representation of the current object state
def jsonobjlen(self, name, path=Path.rootPath()): return self.execute_command('JSON.OBJLEN', name, str_path(path))
Returns the length of the dictionary JSON value under ``path`` at key ``name``
def send_mail(subject, body, email_from, emails_to): msg = MIMEText(body) msg['Subject'] = subject msg['From'] = email_from msg['To'] = ", ".join(emails_to) s = smtplib.SMTP('smtp.gmail.com', 587) s.ehlo() s.starttls() s.ehlo() s.login(SMTP_USERNAME, SMTP_PASSWORD) s.sendmail(ema...
Funxtion for sending email though gmail
def init_database(connection=None, dbname=None): connection = connection or connect() dbname = dbname or bigchaindb.config['database']['name'] create_database(connection, dbname) create_tables(connection, dbname)
Initialize the configured backend for use with BigchainDB. Creates a database with :attr:`dbname` with any required tables and supporting indexes. Args: connection (:class:`~bigchaindb.backend.connection.Connection`): an existing connection to use to initialize the database. ...
def make_noise_surface(dims=DEFAULT_DIMS, blur=10, seed=None): if seed is not None: np.random.seed(seed) return gaussian_filter(np.random.normal(size=dims), blur)
Makes a surface by generating random noise and blurring it. Args: dims (pair): the dimensions of the surface to create blur (float): the amount of Gaussian blur to apply seed (int): a random seed to use (optional) Returns: surface: A surface.
def push_state(self, new_file=''): 'Saves the current error state to parse subpackages' self.subpackages.append({'detected_type': self.detected_type, 'message_tree': self.message_tree, 'resources': self.pushable_resources, ...
Saves the current error state to parse subpackages
async def async_set_operation_mode( self, operation_mode: OperationMode, password: str = '') -> None: await self._protocol.async_execute( SetOpModeCommand(operation_mode), password=password)
Set the operation mode on the base unit. :param operation_mode: the operation mode to change to :param password: if specified, will be used instead of the password property when issuing the command
def startResponse(self, status, headers, excInfo=None): self.status = status self.headers = headers self.reactor.callInThread( responseInColor, self.request, status, headers ) return self.write
extends startResponse to call speakerBox in a thread
def __remove_activity(self, id): query = "select count(*) as count from facts where activity_id = ?" bound_facts = self.fetchone(query, (id,))['count'] if bound_facts > 0: self.execute("UPDATE activities SET deleted = 1 WHERE id = ?", (id,)) else: self.execute("de...
check if we have any facts with this activity and behave accordingly if there are facts - sets activity to deleted = True else, just remove it
def orientnii(imfile): strorient = ['L-R', 'S-I', 'A-P'] niiorient = [] niixyz = np.zeros(3,dtype=np.int8) if os.path.isfile(imfile): nim = nib.load(imfile) pct = nim.get_data() A = nim.get_sform() for i in range(3): niixyz[i] = np.argmax(abs(A[i,:-1])) ...
Get the orientation from NIfTI sform. Not fully functional yet.
def password_get(username=None): password = keyring.get_password('supernova', username) if password is None: split_username = tuple(username.split(':')) msg = ("Couldn't find a credential for {0}:{1}. You need to set one " "with: supernova-keyring -s {0} {1}").format(*split_userna...
Retrieves a password from the keychain based on the environment and configuration parameter pair. If this fails, None is returned.
def body(self): if not self._auto_decode: return self._body if 'body' in self._decode_cache: return self._decode_cache['body'] body = try_utf8_decode(self._body) self._decode_cache['body'] = body return body
Return the Message Body. If auto_decode is enabled, the body will automatically be decoded using decode('utf-8') if possible. :rtype: bytes|str|unicode
def slice_indexer(self, start=None, end=None, step=None, kind=None): start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind) if not is_scalar(start_slice): raise AssertionError("Start slice bound is non-scalar") if n...
For an ordered or unique index, compute the slice indexer for input labels and step. Parameters ---------- start : label, default None If None, defaults to the beginning end : label, default None If None, defaults to the end step : int, default No...
def add_parent(self, parent): parent.add_child(self) self.parent = parent return parent
Adds self as child of parent, then adds parent.
def get_output(self, index): pdata = ctypes.POINTER(mx_uint)() ndim = mx_uint() _check_call(_LIB.MXPredGetOutputShape( self.handle, index, ctypes.byref(pdata), ctypes.byref(ndim))) shape = tuple(pdata[:ndim.value]) data = np.empty(shape, dtype=...
Get the index-th output. Parameters ---------- index : int The index of output. Returns ------- out : numpy array. The output array.
def _quadratic_sum_cost(self, state: _STATE) -> float: cost = 0.0 total_len = float(len(self._c)) seqs, _ = state for seq in seqs: cost += (len(seq) / total_len) ** 2 return -cost
Cost function that sums squares of lengths of sequences. Args: state: Search state, not mutated. Returns: Cost which is minus the normalized quadratic sum of each linear sequence section in the state. This promotes single, long linear sequence solutions and conv...
def get_resource_url(resource): path = model_path(resource) parsed = list(urlparse.urlparse(path)) parsed[1] = "" return urlparse.urlunparse(parsed)
Returns the URL for the given resource.
def hpx_to_axes(h, npix): x = h.ebins z = np.arange(npix[-1] + 1) return x, z
Generate a sequence of bin edge vectors corresponding to the axes of a HPX object.
def remove_droppable(self, droppable_id): updated_droppables = [] for droppable in self.my_osid_object_form._my_map['droppables']: if droppable['id'] != droppable_id: updated_droppables.append(droppable) self.my_osid_object_form._my_map['droppables'] = updated_droppab...
remove a droppable, given the id
def tail(self, n=5): return MultiIndex([v.tail(n) for v in self.values], self.names)
Return MultiIndex with the last n values in each column. Parameters ---------- n : int Number of values. Returns ------- MultiIndex MultiIndex containing the last n values in each column.
def _printUUID(uuid, detail='word'): if not isinstance(detail, int): detail = detailNum[detail] if detail > detailNum['word']: return uuid if uuid is None: return None return "%s...%s" % (uuid[:4], uuid[-4:])
Return friendly abbreviated string for uuid.
def set_regressor_interface_params(spec, features, output_features): if output_features is None: output_features = [("predicted_class", datatypes.Double())] else: output_features = _fm.process_or_validate_features(output_features, 1) if len(output_features) != 1: raise ValueError("Pr...
Common utilities to set the regressor interface params.
def find_parent_id_for_component(self, component_id): response = self.get_record(component_id) if "parent" in response: return (ArchivesSpaceClient.RESOURCE_COMPONENT, response["parent"]["ref"]) elif "resource" in response: return (ArchivesSpaceClient.RESOURCE, response["...
Given the URL to a component, returns the parent component's URL. :param string component_id: The URL of the component. :return: A tuple containing: * The type of the parent record; valid values are ArchivesSpaceClient.RESOURCE and ArchivesSpaceClient.RESOURCE_COMPONENT. * The U...
def _requires_refresh_token(self): expires_on = datetime.datetime.strptime( self.login_data['token']['expiresOn'], '%Y-%m-%dT%H:%M:%SZ') refresh = datetime.datetime.utcnow() + datetime.timedelta(seconds=30) return expires_on < refresh
Check if a refresh of the token is needed
def queryWorkitems(self, query_str, projectarea_id=None, projectarea_name=None, returned_properties=None, archived=False): rp = returned_properties return self.query.queryWorkitems(query_str=query_str, projectarea_id=...
Query workitems with the query string in a certain project area At least either of `projectarea_id` and `projectarea_name` is given :param query_str: a valid query string :param projectarea_id: the :class:`rtcclient.project_area.ProjectArea` id :param projectarea_name: the ...
def delete(self, refobj): i = self.get_typ_interface(self.get_typ(refobj)) i.delete(refobj) self.delete_refobj(refobj)
Delete the given refobj and the contents of the entity :param refobj: the refobj to delete :type refobj: refobj :returns: None :rtype: None :raises: None
def restricted_to_files(self, filenames: List[str] ) -> 'Spectra': tally_passing = \ {fn: entries for (fn, entries) in self.__tally_passing.items() \ if fn in filenames} tally_failing = \ {fn: entries for (fn, e...
Returns a variant of this spectra that only contains entries for lines that appear in any of the files whose name appear in the given list.
def add_campaign(self, name, device_filter, **kwargs): device_filter = filters.legacy_filter_formatter( dict(filter=device_filter), Device._get_attributes_map() ) campaign = Campaign._create_request_map(kwargs) if 'when' in campaign: campaign['when'] =...
Add new update campaign. Add an update campaign with a name and device filtering. Example: .. code-block:: python device_api, update_api = DeviceDirectoryAPI(), UpdateAPI() # Get a filter to use for update campaign query_obj = device_api.get_query(query_id="MYID")...
def try_set_count(self, count): check_not_negative(count, "count can't be negative") return self._encode_invoke(count_down_latch_try_set_count_codec, count=count)
Sets the count to the given value if the current count is zero. If count is not zero, this method does nothing and returns ``false``. :param count: (int), the number of times count_down() must be invoked before threads can pass through await(). :return: (bool), ``true`` if the new count was set...
def get_product_url(self, force_http=False): base_url = self.base_http_url if force_http else self.base_url return '{}products/{}/{}'.format(base_url, self.date.replace('-', '/'), self.product_id)
Creates base url of product location on AWS. :param force_http: True if HTTP base URL should be used and False otherwise :type force_http: str :return: url of product location :rtype: str
def _update_hasher(hasher, data): if isinstance(data, (tuple, list, zip)): needs_iteration = True elif (util_type.HAVE_NUMPY and isinstance(data, np.ndarray) and data.dtype.kind == 'O'): needs_iteration = True else: needs_iteration = False if needs_iteration: SE...
This is the clear winner over the generate version. Used by hash_data Ignore: import utool rng = np.random.RandomState(0) # str1 = rng.rand(0).dumps() str1 = b'SEP' str2 = rng.rand(10000).dumps() for timer in utool.Timerit(100, label='twocall'): hashe...
def safe_compare_digest(val1, val2): if len(val1) != len(val2): return False result = 0 if PY3 and isinstance(val1, bytes) and isinstance(val2, bytes): for i, j in zip(val1, val2): result |= i ^ j else: for i, j in zip(val1, val2): result |= (ord(i) ^ ord(...
safe_compare_digest method. :param val1: string or bytes for compare :type val1: str | bytes :param val2: string or bytes for compare :type val2: str | bytes
def normnorm(self): n = self.norm() return V2(-self.y / n, self.x / n)
Return a vecor noraml to this one with a norm of one :return: V2
def get_default_base_name(self, viewset): queryset = getattr(viewset, 'queryset', None) if queryset is not None: get_url_name = getattr(queryset.model, 'get_url_name', None) if get_url_name is not None: return get_url_name() return super(SortedDefaultRoute...
Attempt to automatically determine base name using `get_url_name`.
def __step4(self): step = 0 done = False row = -1 col = -1 star_col = -1 while not done: (row, col) = self.__find_a_zero() if row < 0: done = True step = 6 else: self.marked[row][col] = 2 ...
Find a noncovered zero and prime it. If there is no starred zero in the row containing this primed zero, Go to Step 5. Otherwise, cover this row and uncover the column containing the starred zero. Continue in this manner until there are no uncovered zeros left. Save the smallest uncovere...
def _unregister_service(self): if self._registration is not None: try: self._registration.unregister() except BundleException as ex: logger = logging.getLogger( "-".join((self._ipopo_instance.name, "ServiceRegistration")) ...
Unregisters the provided service, if needed
def backness(self, value): if (value is not None) and (not value in DG_V_BACKNESS): raise ValueError("Unrecognized value for backness: '%s'" % value) self.__backness = value
Set the backness of the vowel. :param str value: the value to be set
def _op(self, line, op=None, offset=0): if op is None: op = self.op_count[line] return "line{}_gate{}".format(line, op + offset)
Returns the gate name for placing a gate on a line. :param int line: Line number. :param int op: Operation number or, by default, uses the current op count. :return: Gate name. :rtype: string
def get_version(): if PackageHelper.__version: return PackageHelper.__version PackageHelper.__version = "Unknown" file = os.path.realpath(__file__) folder = os.path.dirname(file) try: semver = open(folder + "/../../.semver", "r") PackageHelper....
Get the version number of this package. Returns: str: The version number (marjor.minor.patch). Note: When this package is installed, the version number will be available through the package resource details. Otherwise this method will look for a ``.semver`` file. ...
def create(self, query_name, saved_query): url = "{0}/{1}".format(self.saved_query_url, query_name) payload = saved_query if not isinstance(payload, str): payload = json.dumps(saved_query) response = self._get_json(HTTPMethods.PUT, url, self._get_master_key(), data=payload) ...
Creates the saved query via a PUT request to Keen IO Saved Query endpoint. Master key must be set.
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super().save(force_insert, force_update, using, update_fields) if self.main_language: TransLanguage.objects.exclude(pk=self.pk).update(main_language=False)
Overwrite of the save method in order that when setting the language as main we deactivate any other model selected as main before :param force_insert: :param force_update: :param using: :param update_fields: :return:
def get_outputs(self, input_value): output_value = self.convert_to_xmlrpc(input_value) output = {} for name in self.output_names: output[name] = output_value return output
Generate a set of output values for a given input.
def which(self): if self.binary is None: return None return which(self.binary, path=self.env_path)
Figure out which binary this will execute. Returns None if the binary is not found.
def get_access_control_function(): fn_path = getattr(settings, 'ROSETTA_ACCESS_CONTROL_FUNCTION', None) if fn_path is None: return is_superuser_staff_or_in_translators_group perm_module, perm_func = fn_path.rsplit('.', 1) perm_module = importlib.import_module(perm_module) return getattr(perm...
Return a predicate for determining if a user can access the Rosetta views
def tag_dssp_solvent_accessibility(self, force=False): tagged = ['dssp_acc' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: dssp_out = run_dssp(self.pdb, path=False) if dssp_out is None: return dssp_acc_list = extract_solvent_a...
Tags each `Residues` Polymer with its solvent accessibility. Notes ----- For more about DSSP's solvent accessibilty metric, see: http://swift.cmbi.ru.nl/gv/dssp/HTML/descrip.html#ACC References ---------- .. [1] Kabsch W, Sander C (1983) "Dictionary of prote...
def alloc_vpcid(nexus_ips): LOG.debug("alloc_vpc() called") vpc_id = 0 intersect = _get_free_vpcids_on_switches(nexus_ips) for intersect_tuple in intersect: try: update_vpc_entry(nexus_ips, intersect_tuple.vpc_id, False, True) vpc_id = interse...
Allocate a vpc id for the given list of switch_ips.
def temperature_data_from_csv( filepath_or_buffer, tz=None, date_col="dt", temp_col="tempF", gzipped=False, freq=None, **kwargs ): read_csv_kwargs = { "usecols": [date_col, temp_col], "dtype": {temp_col: np.float64}, "parse_dates": [date_col], "index_col":...
Load temperature data from a CSV file. Default format:: dt,tempF 2017-01-01T00:00:00+00:00,21 2017-01-01T01:00:00+00:00,22.5 2017-01-01T02:00:00+00:00,23.5 Parameters ---------- filepath_or_buffer : :any:`str` or file-handle File path or object. tz : :any:`...
def get_task_module(feature): try: importlib.import_module(feature) except ImportError: raise FeatureNotFound(feature) tasks_module = None try: tasks_module = importlib.import_module(feature + '.apetasks') except ImportError: pass try: tasks_module = impor...
Return imported task module of feature. This function first tries to import the feature and raises FeatureNotFound if that is not possible. Thereafter, it looks for a submodules called ``apetasks`` and ``tasks`` in that order. If such a submodule exists, it is imported and returned. :param feature...
def save_html(out_file, plot_html): internal_open = False if type(out_file) == str: out_file = open(out_file, "w") internal_open = True out_file.write("<html><head><script>\n") bundle_path = os.path.join(os.path.split(__file__)[0], "resources", "bundle.js") with io.open(bundle_path, ...
Save html plots to an output file.
def remove(name, rc_file='~/.odoorpcrc'): conf = ConfigParser() conf.read([os.path.expanduser(rc_file)]) if not conf.has_section(name): raise ValueError( "'%s' session does not exist in %s" % (name, rc_file)) conf.remove_section(name) with open(os.path.expanduser(rc_file), 'wb') ...
Remove the session configuration identified by `name` from the `rc_file` file. >>> import odoorpc >>> odoorpc.session.remove('foo') # doctest: +SKIP .. doctest:: :hide: >>> import odoorpc >>> session = '%s_session' % DB >>> odoorpc.session.remove(session) :rai...
def results_history(history_log, no_color): try: with open(history_log, 'r') as f: lines = f.readlines() except Exception as error: echo_style( 'Unable to process results history log: %s' % error, no_color, fg='red' ) sys.exit(1) ...
Display a list of ipa test results history.
def to_bytes(self): raw = b'' if not self._options: return raw for ipopt in self._options: raw += ipopt.to_bytes() padbytes = 4 - (len(raw) % 4) raw += b'\x00'*padbytes return raw
Takes a list of IPOption objects and returns a packed byte string of options, appropriately padded if necessary.
def changed(self, message=None, *args): if message is not None: self.logger.debug('%s: %s', self._repr(), message % args) self.logger.debug('%s: changed', self._repr()) if self.parent is not None: self.parent.changed() elif isinstance(self, Mutable): s...
Marks the object as changed. If a `parent` attribute is set, the `changed()` method on the parent will be called, propagating the change notification up the chain. The message (if provided) will be debug logged.