positive
stringlengths
100
30.3k
anchor
stringlengths
1
15k
def claim(ctx, vestingid, account, amount): """ Claim funds from the vesting balance """ vesting = Vesting(vestingid) if amount: amount = Amount(float(amount), "BTS") else: amount = vesting.claimable print_tx( ctx.bitshares.vesting_balance_withdraw( vesting["id"], amount=amount, account=vesting["owner"] ) )
Claim funds from the vesting balance
def _get_bool_val(self, name): """ Return the value of the boolean child element having *name*, e.g. 'b', 'i', and 'smallCaps'. """ element = getattr(self, name) if element is None: return None return element.val
Return the value of the boolean child element having *name*, e.g. 'b', 'i', and 'smallCaps'.
def extract_cpio (archive, compression, cmd, verbosity, interactive, outdir): """Extract a CPIO archive.""" cmdlist = [util.shell_quote(cmd), '--extract', '--make-directories', '--preserve-modification-time'] if sys.platform.startswith('linux') and not cmd.endswith('bsdcpio'): cmdlist.extend(['--no-absolute-filenames', '--force-local', '--nonmatching', r'"*\.\.*"']) if verbosity > 1: cmdlist.append('-v') cmdlist.extend(['<', util.shell_quote(os.path.abspath(archive))]) return (cmdlist, {'cwd': outdir, 'shell': True})
Extract a CPIO archive.
def do_clearrep(self, line): """clearrep Set the replication policy to default. The default replication policy has no preferred or blocked member nodes, allows replication and sets the preferred number of replicas to 3. """ self._split_args(line, 0, 0) self._command_processor.get_session().get_replication_policy().clear() self._print_info_if_verbose("Cleared the replication policy")
clearrep Set the replication policy to default. The default replication policy has no preferred or blocked member nodes, allows replication and sets the preferred number of replicas to 3.
def transfer_credits(self, credits, can_use_my_credits_when_they_run_out): """Transfer credits to or from this client. :param credits: An Integer representing the number of credits to transfer. This value may be either positive if you want to allocate credits from your account to the client, or negative if you want to deduct credits from the client back into your account. :param can_use_my_credits_when_they_run_out: A Boolean value representing which, if set to true, will allow the client to continue sending using your credits or payment details once they run out of credits, and if set to false, will prevent the client from using your credits to continue sending until you allocate more credits to them. :returns: An object of the following form representing the result: { AccountCredits # Integer representing credits in your account now ClientCredits # Integer representing credits in this client's account now } """ body = { "Credits": credits, "CanUseMyCreditsWhenTheyRunOut": can_use_my_credits_when_they_run_out} response = self._post(self.uri_for('credits'), json.dumps(body)) return json_to_py(response)
Transfer credits to or from this client. :param credits: An Integer representing the number of credits to transfer. This value may be either positive if you want to allocate credits from your account to the client, or negative if you want to deduct credits from the client back into your account. :param can_use_my_credits_when_they_run_out: A Boolean value representing which, if set to true, will allow the client to continue sending using your credits or payment details once they run out of credits, and if set to false, will prevent the client from using your credits to continue sending until you allocate more credits to them. :returns: An object of the following form representing the result: { AccountCredits # Integer representing credits in your account now ClientCredits # Integer representing credits in this client's account now }
def _load_feed(path: str, view: View, config: nx.DiGraph) -> Feed: """Multi-file feed filtering""" config_ = remove_node_attributes(config, ["converters", "transformations"]) feed_ = Feed(path, view={}, config=config_) for filename, column_filters in view.items(): config_ = reroot_graph(config_, filename) view_ = {filename: column_filters} feed_ = Feed(feed_, view=view_, config=config_) return Feed(feed_, config=config)
Multi-file feed filtering
def target_doc(self): """Returns resource doc as at the target, when the posting was already created \ at the target. This property normally contains the **target_doc** data from \ the livebrigde storage item, saved in a syndication earlier. :returns: dict""" if not hasattr(self, "_target_doc") or not self._target_doc: if self._existing: self._target_doc = self._existing.get("target_doc", {}) return self._target_doc
Returns resource doc as at the target, when the posting was already created \ at the target. This property normally contains the **target_doc** data from \ the livebrigde storage item, saved in a syndication earlier. :returns: dict
def wordrelationships(relationshiplist): '''Generate a Word relationships file''' # Default list of relationships # FIXME: using string hack instead of making element #relationships = makeelement('Relationships', nsprefix='pr') relationships = etree.fromstring( '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006' '/relationships"></Relationships>') count = 0 for relationship in relationshiplist: # Relationship IDs (rId) start at 1. rel_elm = makeelement('Relationship', nsprefix=None, attributes={'Id': 'rId'+str(count+1), 'Type': relationship[0], 'Target': relationship[1]} ) relationships.append(rel_elm) count += 1 return relationships
Generate a Word relationships file
def reconcile_extend(self, high): ''' Pull the extend data and add it to the respective high data ''' errors = [] if '__extend__' not in high: return high, errors ext = high.pop('__extend__') for ext_chunk in ext: for name, body in six.iteritems(ext_chunk): if name not in high: state_type = next( x for x in body if not x.startswith('__') ) # Check for a matching 'name' override in high data ids = find_name(name, state_type, high) if len(ids) != 1: errors.append( 'Cannot extend ID \'{0}\' in \'{1}:{2}\'. It is not ' 'part of the high state.\n' 'This is likely due to a missing include statement ' 'or an incorrectly typed ID.\nEnsure that a ' 'state with an ID of \'{0}\' is available\nin ' 'environment \'{1}\' and to SLS \'{2}\''.format( name, body.get('__env__', 'base'), body.get('__sls__', 'base')) ) continue else: name = ids[0][0] for state, run in six.iteritems(body): if state.startswith('__'): continue if state not in high[name]: high[name][state] = run continue # high[name][state] is extended by run, both are lists for arg in run: update = False for hind in range(len(high[name][state])): if isinstance(arg, six.string_types) and isinstance(high[name][state][hind], six.string_types): # replacing the function, replace the index high[name][state].pop(hind) high[name][state].insert(hind, arg) update = True continue if isinstance(arg, dict) and isinstance(high[name][state][hind], dict): # It is an option, make sure the options match argfirst = next(iter(arg)) if argfirst == next(iter(high[name][state][hind])): # If argfirst is a requisite then we must merge # our requisite with that of the target state if argfirst in STATE_REQUISITE_KEYWORDS: high[name][state][hind][argfirst].extend(arg[argfirst]) # otherwise, its not a requisite and we are just extending (replacing) else: high[name][state][hind] = arg update = True if (argfirst == 'name' and next(iter(high[name][state][hind])) == 'names'): # If names are overwritten by name use the name high[name][state][hind] = arg if not update: high[name][state].append(arg) return high, errors
Pull the extend data and add it to the respective high data
def format_from_extension(fname): """ Tries to infer a protocol from the file extension.""" _base, ext = os.path.splitext(fname) if not ext: return None try: format = known_extensions[ext.replace('.', '')] except KeyError: format = None return format
Tries to infer a protocol from the file extension.
def post(method, hmc, uri, uri_parms, body, logon_required, wait_for_completion): """Operation: Add Candidate Adapter Ports to an FCP Storage Group.""" assert wait_for_completion is True # async not supported yet # The URI is a POST operation, so we need to construct the SG URI storage_group_oid = uri_parms[0] storage_group_uri = '/api/storage-groups/' + storage_group_oid try: storage_group = hmc.lookup_by_uri(storage_group_uri) except KeyError: raise InvalidResourceError(method, uri) check_required_fields(method, uri, body, ['adapter-port-uris']) # TODO: Check that storage group has type FCP # Reflect the result of adding the candidate ports candidate_adapter_port_uris = \ storage_group.properties['candidate-adapter-port-uris'] for ap_uri in body['adapter-port-uris']: if ap_uri in candidate_adapter_port_uris: raise ConflictError(method, uri, 483, "Adapter port is already in candidate " "list of storage group %s: %s" % (storage_group.name, ap_uri)) else: candidate_adapter_port_uris.append(ap_uri)
Operation: Add Candidate Adapter Ports to an FCP Storage Group.
def find_matching(cls, message, channel): """ Yield ``cls`` subclasses that match message and channel """ return ( handler for handler in cls._registry if isinstance(handler, cls) and handler.match(message, channel) )
Yield ``cls`` subclasses that match message and channel
def spelling(self): """Flag incorrectly spelled words. Returns a list of booleans, where element at each position denotes, if the word at the same position is spelled correctly. """ if not self.is_tagged(WORDS): self.tokenize_words() return [data[SPELLING] for data in vabamorf.spellcheck(self.word_texts, suggestions=False)]
Flag incorrectly spelled words. Returns a list of booleans, where element at each position denotes, if the word at the same position is spelled correctly.
def redirect(to, headers=None, status=302, content_type='text/html; charset=utf-8'): '''Abort execution and cause a 302 redirect (by default). :param to: path or fully qualified URL to redirect to :param headers: optional dict of headers to include in the new request :param status: status code (int) of the new request, defaults to 302 :param content_type: the content type (string) of the response :returns: the redirecting Response ''' headers = headers or {} # According to RFC 7231, a relative URI is now permitted. headers['Location'] = to return HTTPResponse( status=status, headers=headers, content_type=content_type)
Abort execution and cause a 302 redirect (by default). :param to: path or fully qualified URL to redirect to :param headers: optional dict of headers to include in the new request :param status: status code (int) of the new request, defaults to 302 :param content_type: the content type (string) of the response :returns: the redirecting Response
def loadModules(self, *modNames, **userCtx): """Load (optionally, compiling) pysnmp MIB modules""" # Build a list of available modules if not modNames: modNames = {} for mibSource in self._mibSources: for modName in mibSource.listdir(): modNames[modName] = None modNames = list(modNames) if not modNames: raise error.MibNotFoundError( 'No MIB module to load at %s' % (self,)) for modName in modNames: try: self.loadModule(modName, **userCtx) except error.MibNotFoundError: if not self._mibCompiler: raise debug.logger & debug.FLAG_BLD and debug.logger( 'loadModules: calling MIB compiler for %s' % modName) status = self._mibCompiler.compile(modName, genTexts=self.loadTexts) errs = '; '.join( hasattr(x, 'error') and str(x.error) or x for x in status.values() if x in ('failed', 'missing')) if errs: raise error.MibNotFoundError( '%s compilation error(s): %s' % (modName, errs)) # compilation succeeded, MIB might load now self.loadModule(modName, **userCtx) return self
Load (optionally, compiling) pysnmp MIB modules
def merge_two_dicts(x: Dict, y: Dict) -> Dict: """ Given two dicts, merge them into a new dict as a shallow copy, e.g. .. code-block:: python z = merge_two_dicts(x, y) If you can guarantee Python 3.5, then a simpler syntax is: .. code-block:: python z = {**x, **y} See http://stackoverflow.com/questions/38987. """ z = x.copy() z.update(y) return z
Given two dicts, merge them into a new dict as a shallow copy, e.g. .. code-block:: python z = merge_two_dicts(x, y) If you can guarantee Python 3.5, then a simpler syntax is: .. code-block:: python z = {**x, **y} See http://stackoverflow.com/questions/38987.
def parsecounter(table, field, parsers=(('int', int), ('float', float))): """ Count the number of `str` or `unicode` values under the given fields that can be parsed as ints, floats or via custom parser functions. Return a pair of `Counter` objects, the first mapping parser names to the number of strings successfully parsed, the second mapping parser names to the number of errors. E.g.:: >>> import petl as etl >>> table = [['foo', 'bar', 'baz'], ... ['A', 'aaa', 2], ... ['B', u'2', '3.4'], ... [u'B', u'3', u'7.8', True], ... ['D', '3.7', 9.0], ... ['E', 42]] >>> counter, errors = etl.parsecounter(table, 'bar') >>> counter Counter({'float': 3, 'int': 2}) >>> errors Counter({'int': 2, 'float': 1}) The `field` argument can be a field name or index (starting from zero). """ if isinstance(parsers, (list, tuple)): parsers = dict(parsers) counter, errors = Counter(), Counter() # need to initialise for n in parsers.keys(): counter[n] = 0 errors[n] = 0 for v in values(table, field): if isinstance(v, string_types): for name, parser in parsers.items(): try: parser(v) except: errors[name] += 1 else: counter[name] += 1 return counter, errors
Count the number of `str` or `unicode` values under the given fields that can be parsed as ints, floats or via custom parser functions. Return a pair of `Counter` objects, the first mapping parser names to the number of strings successfully parsed, the second mapping parser names to the number of errors. E.g.:: >>> import petl as etl >>> table = [['foo', 'bar', 'baz'], ... ['A', 'aaa', 2], ... ['B', u'2', '3.4'], ... [u'B', u'3', u'7.8', True], ... ['D', '3.7', 9.0], ... ['E', 42]] >>> counter, errors = etl.parsecounter(table, 'bar') >>> counter Counter({'float': 3, 'int': 2}) >>> errors Counter({'int': 2, 'float': 1}) The `field` argument can be a field name or index (starting from zero).
def register_calendar_alias(self, alias, real_name, force=False): """ Register an alias for a calendar. This is useful when multiple exchanges should share a calendar, or when there are multiple ways to refer to the same exchange. After calling ``register_alias('alias', 'real_name')``, subsequent calls to ``get_calendar('alias')`` will return the same result as ``get_calendar('real_name')``. Parameters ---------- alias : str The name to be used to refer to a calendar. real_name : str The canonical name of the registered calendar. force : bool, optional If True, old calendars will be overwritten on a name collision. If False, name collisions will raise an exception. Default is False. """ if force: self.deregister_calendar(alias) if self.has_calendar(alias): raise CalendarNameCollision(calendar_name=alias) self._aliases[alias] = real_name # Ensure that the new alias doesn't create a cycle, and back it out if # we did. try: self.resolve_alias(alias) except CyclicCalendarAlias: del self._aliases[alias] raise
Register an alias for a calendar. This is useful when multiple exchanges should share a calendar, or when there are multiple ways to refer to the same exchange. After calling ``register_alias('alias', 'real_name')``, subsequent calls to ``get_calendar('alias')`` will return the same result as ``get_calendar('real_name')``. Parameters ---------- alias : str The name to be used to refer to a calendar. real_name : str The canonical name of the registered calendar. force : bool, optional If True, old calendars will be overwritten on a name collision. If False, name collisions will raise an exception. Default is False.
def list_same(list_a, list_b): """ Return the items from list_b that are also on list_a """ result = [] for item in list_b: if item in list_a: result.append(item) return result
Return the items from list_b that are also on list_a
def do_pending_lookups(event, sender, **kwargs): """Handle any pending relations to the sending model. Sent from class_prepared.""" key = (sender._meta.app_label, sender._meta.name) for callback in pending_lookups.pop(key, []): callback(sender)
Handle any pending relations to the sending model. Sent from class_prepared.
def dwelling_type(self): """ This method returns the dwelling type. :return: """ try: if self._data_from_search: info = self._data_from_search.find( 'ul', {"class": "info"}).text s = info.split('|') return s[0].strip() else: return self._ad_page_content.find( 'div', {'id': 'smi-summary-items'} ).find('span', {'class': 'header_text'}).text except Exception as e: if self._debug: logging.error( "Error getting dwelling_type. Error message: " + e.args[0]) return
This method returns the dwelling type. :return:
def read_data(self, dstart=None, dend=None): """Read data from `file` and return it as Numpy array. Parameters ---------- dstart : int, optional Offset in bytes of the data field. By default, it is taken to be the header size as determined from reading the header. Backwards indexing with negative values is also supported. Use a value larger than the header size to extract a data subset. dend : int, optional End position in bytes until which data is read (exclusive). Backwards indexing with negative values is also supported. Use a value different from the file size to extract a data subset. Returns ------- data : `numpy.ndarray` The data read from `file`. See Also -------- read_header """ self.file.seek(0, 2) # 2 means "from the end" filesize_bytes = self.file.tell() if dstart is None: dstart_abs = int(self.header_size) elif dstart < 0: dstart_abs = filesize_bytes + int(dstart) else: dstart_abs = int(dstart) if dend is None: dend_abs = int(filesize_bytes) elif dend < 0: dend_abs = int(dend) + filesize_bytes else: dend_abs = int(dend) if dstart_abs >= dend_abs: raise ValueError('invalid `dstart` and `dend`, resulting in ' 'absolute `dstart` >= `dend` ({} >= {})' ''.format(dstart_abs, dend_abs)) if dstart_abs < self.header_size: raise ValueError('invalid `dstart`, resulting in absolute ' '`dstart` < `header_size` ({} < {})' ''.format(dstart_abs, self.header_size)) if dend_abs > filesize_bytes: raise ValueError('invalid `dend`, resulting in absolute ' '`dend` > `filesize_bytes` ({} < {})' ''.format(dend_abs, filesize_bytes)) num_elems = (dend_abs - dstart_abs) / self.data_dtype.itemsize if num_elems != int(num_elems): raise ValueError( 'trying to read {} bytes, which is not a multiple of ' 'the itemsize {} of the data type {}' ''.format(dend_abs - dstart_abs, self.data_dtype.itemsize, self.data_dtype)) self.file.seek(dstart_abs) array = np.empty(int(num_elems), dtype=self.data_dtype) self.file.readinto(array.data) return array
Read data from `file` and return it as Numpy array. Parameters ---------- dstart : int, optional Offset in bytes of the data field. By default, it is taken to be the header size as determined from reading the header. Backwards indexing with negative values is also supported. Use a value larger than the header size to extract a data subset. dend : int, optional End position in bytes until which data is read (exclusive). Backwards indexing with negative values is also supported. Use a value different from the file size to extract a data subset. Returns ------- data : `numpy.ndarray` The data read from `file`. See Also -------- read_header
def fixed_poch(a, n): """Implementation of the Pochhammer symbol :math:`(a)_n` which handles negative integer arguments properly. Need conditional statement because scipy's impelementation of the Pochhammer symbol is wrong for negative integer arguments. This function uses the definition from http://functions.wolfram.com/GammaBetaErf/Pochhammer/02/ Parameters ---------- a : float The argument. n : nonnegative int The order. """ # Old form, calls gamma function: # if a < 0.0 and a % 1 == 0 and n <= -a: # p = (-1.0)**n * scipy.misc.factorial(-a) / scipy.misc.factorial(-a - n) # else: # p = scipy.special.poch(a, n) # return p if (int(n) != n) or (n < 0): raise ValueError("Parameter n must be a nonnegative int!") n = int(n) # Direct form based on product: terms = [a + k for k in range(0, n)] return scipy.prod(terms)
Implementation of the Pochhammer symbol :math:`(a)_n` which handles negative integer arguments properly. Need conditional statement because scipy's impelementation of the Pochhammer symbol is wrong for negative integer arguments. This function uses the definition from http://functions.wolfram.com/GammaBetaErf/Pochhammer/02/ Parameters ---------- a : float The argument. n : nonnegative int The order.
def mthread_submit(nslave, worker_args, worker_envs): """ customized submit script, that submit nslave jobs, each must contain args as parameter note this can be a lambda function containing additional parameters in input Parameters nslave number of slave process to start up args arguments to launch each job this usually includes the parameters of master_uri and parameters passed into submit """ procs = {} for i in range(nslave): procs[i] = Thread(target = exec_cmd, args = (args.command + worker_args, i, worker_envs)) procs[i].daemon = True procs[i].start() for i in range(nslave): procs[i].join()
customized submit script, that submit nslave jobs, each must contain args as parameter note this can be a lambda function containing additional parameters in input Parameters nslave number of slave process to start up args arguments to launch each job this usually includes the parameters of master_uri and parameters passed into submit
def _run_cmd(self, cmd, key_accept=False, passwd_retries=3): ''' Execute a shell command via VT. This is blocking and assumes that ssh is being run ''' if not cmd: return '', 'No command or passphrase', 245 term = salt.utils.vt.Terminal( cmd, shell=True, log_stdout=True, log_stdout_level='trace', log_stderr=True, log_stderr_level='trace', stream_stdout=False, stream_stderr=False) sent_passwd = 0 send_password = True ret_stdout = '' ret_stderr = '' old_stdout = '' try: while term.has_unread_data: stdout, stderr = term.recv() if stdout: ret_stdout += stdout buff = old_stdout + stdout else: buff = stdout if stderr: ret_stderr += stderr if buff and RSTR_RE.search(buff): # We're getting results back, don't try to send passwords send_password = False if buff and SSH_PRIVATE_KEY_PASSWORD_PROMPT_RE.search(buff): if not self.priv_passwd: return '', 'Private key file need passphrase', 254 term.sendline(self.priv_passwd) continue if buff and SSH_PASSWORD_PROMPT_RE.search(buff) and send_password: if not self.passwd: return '', 'Permission denied, no authentication information', 254 if sent_passwd < passwd_retries: term.sendline(self.passwd) sent_passwd += 1 continue else: # asking for a password, and we can't seem to send it return '', 'Password authentication failed', 254 elif buff and KEY_VALID_RE.search(buff): if key_accept: term.sendline('yes') continue else: term.sendline('no') ret_stdout = ('The host key needs to be accepted, to ' 'auto accept run salt-ssh with the -i ' 'flag:\n{0}').format(stdout) return ret_stdout, '', 254 elif buff and buff.endswith('_||ext_mods||_'): mods_raw = salt.utils.json.dumps(self.mods, separators=(',', ':')) + '|_E|0|' term.sendline(mods_raw) if stdout: old_stdout = stdout time.sleep(0.01) return ret_stdout, ret_stderr, term.exitstatus finally: term.close(terminate=True, kill=True)
Execute a shell command via VT. This is blocking and assumes that ssh is being run
def render(self, template_name, __data=None, **kw): '''Given a template name and template data. Renders a template and returns as string''' return self.template.render(template_name, **self._vars(__data, **kw))
Given a template name and template data. Renders a template and returns as string
def removeComments( self, comment = None ): """ Inserts comments into the editor based on the current selection.\ If no comment string is supplied, then the comment from the language \ will be used. :param comment | <str> || None :return <bool> | success """ if ( not comment ): lang = self.language() if ( lang ): comment = lang.lineComment() if ( not comment ): return False startline, startcol, endline, endcol = self.getSelection() len_comment = len(comment) line, col = self.getCursorPosition() for lineno in range(startline, endline+1 ): self.setSelection(lineno, 0, lineno, len_comment) if ( self.selectedText() == comment ): self.removeSelectedText() self.setSelection(startline, startcol, endline, endcol) self.setCursorPosition(line, col) return True
Inserts comments into the editor based on the current selection.\ If no comment string is supplied, then the comment from the language \ will be used. :param comment | <str> || None :return <bool> | success
def find_ip6_by_network(self, id_network): """List IPv6 from network. :param id_network: Network ipv6 identifier. Integer value and greater than zero. :return: Dictionary with the following structure: :: {'ip': {'id': < id >, 'id_vlan': < id_vlan >, 'block1': <block1>, 'block2': <block2>, 'block3': <block3>, 'block4': <block4>, 'block5': <block5>, 'block6': <block6>, 'block7': <block7>, 'block8': <block8>, 'descricao': < description > 'equipamento': [ { all name equipamentos related } ], }} :raise IpNaoExisteError: Network does not have any ips. :raise InvalidParameterError: Network identifier is none or invalid. :raise DataBaseError: Networkapi failed to access the database. """ if not is_valid_int_param(id_network): raise InvalidParameterError( u'Network identifier is invalid or was not informed.') url = 'ip/id_network_ipv6/' + str(id_network) + "/" code, xml = self.submit(None, 'GET', url) key = "ips" return get_list_map(self.response(code, xml, [key]), key)
List IPv6 from network. :param id_network: Network ipv6 identifier. Integer value and greater than zero. :return: Dictionary with the following structure: :: {'ip': {'id': < id >, 'id_vlan': < id_vlan >, 'block1': <block1>, 'block2': <block2>, 'block3': <block3>, 'block4': <block4>, 'block5': <block5>, 'block6': <block6>, 'block7': <block7>, 'block8': <block8>, 'descricao': < description > 'equipamento': [ { all name equipamentos related } ], }} :raise IpNaoExisteError: Network does not have any ips. :raise InvalidParameterError: Network identifier is none or invalid. :raise DataBaseError: Networkapi failed to access the database.
def split_backward(layers): # pragma: no cover """Separate a sequence of layers' `begin_update` methods into two lists of functions: one that computes the forward values, and the other that completes the backward pass. The backward sequence is only populated after the forward functions have been applied. """ backward = [] forward = [sink_return(op.begin_update, backward.append) for op in layers] return forward, backward
Separate a sequence of layers' `begin_update` methods into two lists of functions: one that computes the forward values, and the other that completes the backward pass. The backward sequence is only populated after the forward functions have been applied.
def update(self, data): """Updates the object information based on live data, if there were any changes made. Any changes will be automatically applied to the object, but will not be automatically persisted. You must manually call `db.session.add(instance)` on the object. Args: data (:obj:): AWS API Resource object fetched from AWS API Returns: True if there were any changes to the object, else false """ # If the instance was terminated, remove it if data.state['Name'] == 'terminated': self.delete(auto_commit=False) return True updated = self.set_property('launch_date', to_utc_date(data.launch_time).isoformat()) updated |= self.set_property('state', data.state['Name']) updated |= self.set_property('instance_type', data.instance_type) updated |= self.set_property('public_ip', data.public_ip_address or None) updated |= self.set_property('public_dns', data.public_dns_name or None) tags = {x['Key']: x['Value'] for x in data.tags or {}} existing_tags = {x.key: x for x in self.tags} # Check for new tags for key, value in list(tags.items()): updated |= self.set_tag(key, value) # Check for updated or removed tags for key in list(existing_tags.keys()): if key not in tags: updated |= self.delete_tag(key) return updated
Updates the object information based on live data, if there were any changes made. Any changes will be automatically applied to the object, but will not be automatically persisted. You must manually call `db.session.add(instance)` on the object. Args: data (:obj:): AWS API Resource object fetched from AWS API Returns: True if there were any changes to the object, else false
def toDict(self): """ Return a dictionary with the DataFrame data. """ d = {} nindices = self.getNumIndices() for i in range(self.getNumRows()): row = list(self.getRowByIndex(i)) if nindices > 1: key = tuple(row[:nindices]) elif nindices == 1: key = row[0] else: key = None if len(row) - nindices == 0: d[key] = None elif len(row) - nindices == 1: d[key] = row[nindices] else: d[key] = tuple(row[nindices:]) return d
Return a dictionary with the DataFrame data.
def ednde_deriv(self, x, params=None): """Evaluate derivative of E times differential flux with respect to E.""" params = self.params if params is None else params return np.squeeze(self.eval_ednde_deriv(x, params, self.scale, self.extra_params))
Evaluate derivative of E times differential flux with respect to E.
def allocate(self, pool, tenant_id=None, **params): """Allocates a floating IP to the tenant. You must provide a pool name or id for which you would like to allocate a floating IP. :returns: FloatingIp object corresponding to an allocated floating IP """ if not tenant_id: tenant_id = self.request.user.project_id create_dict = {'floating_network_id': pool, 'tenant_id': tenant_id} if 'subnet_id' in params: create_dict['subnet_id'] = params['subnet_id'] if 'floating_ip_address' in params: create_dict['floating_ip_address'] = params['floating_ip_address'] if 'description' in params: create_dict['description'] = params['description'] if 'dns_domain' in params: create_dict['dns_domain'] = params['dns_domain'] if 'dns_name' in params: create_dict['dns_name'] = params['dns_name'] fip = self.client.create_floatingip( {'floatingip': create_dict}).get('floatingip') self._set_instance_info(fip) return FloatingIp(fip)
Allocates a floating IP to the tenant. You must provide a pool name or id for which you would like to allocate a floating IP. :returns: FloatingIp object corresponding to an allocated floating IP
def starttls(self, ssl_context=None, post_handshake_callback=None): """ Start a TLS stream on top of the socket. This is an invalid operation if the stream is not in RAW_OPEN state. If `ssl_context` is set, it overrides the `ssl_context` passed to the constructor. If `post_handshake_callback` is set, it overrides the `post_handshake_callback` passed to the constructor. .. versionchanged:: 0.4 This method is now a barrier with respect to reads and writes: before the handshake is completed (including the post handshake callback, if any), no data is received or sent. """ if self._state != _State.RAW_OPEN or self._closing: raise self._invalid_state("starttls() called") if ssl_context is not None: self._ssl_context = ssl_context self._extra.update( sslcontext=ssl_context ) else: self._ssl_context = self._ssl_context_factory(self) if post_handshake_callback is not None: self._tls_post_handshake_callback = post_handshake_callback self._waiter = asyncio.Future() self._waiter.add_done_callback(self._waiter_done) self._initiate_tls() try: yield from self._waiter finally: self._waiter = None
Start a TLS stream on top of the socket. This is an invalid operation if the stream is not in RAW_OPEN state. If `ssl_context` is set, it overrides the `ssl_context` passed to the constructor. If `post_handshake_callback` is set, it overrides the `post_handshake_callback` passed to the constructor. .. versionchanged:: 0.4 This method is now a barrier with respect to reads and writes: before the handshake is completed (including the post handshake callback, if any), no data is received or sent.
def enable_radio_button(self): """Enable radio button and custom value input area then set selected radio button to 'Do not report'. """ for button in self.default_input_button_group.buttons(): button.setEnabled(True) self.set_selected_radio_button() self.custom_value.setEnabled(True)
Enable radio button and custom value input area then set selected radio button to 'Do not report'.
def _set_advertisement_interval(self, v, load=False): """ Setter method for advertisement_interval, mapped from YANG variable /routing_system/router/router_bgp/address_family/ipv4/ipv4_unicast/af_vrf/neighbor/af_ipv4_vrf_neighbor_address_holder/af_ipv4_neighbor_addr/advertisement_interval (container) If this variable is read-only (config: false) in the source YANG file, then _set_advertisement_interval is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_advertisement_interval() directly. """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=advertisement_interval.advertisement_interval, is_container='container', presence=False, yang_name="advertisement-interval", rest_name="advertisement-interval", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'Minimum interval between sending BGP routing updates', u'cli-compact-syntax': None, u'cli-incomplete-command': None}}, namespace='urn:brocade.com:mgmt:brocade-bgp', defining_module='brocade-bgp', yang_type='container', is_config=True) except (TypeError, ValueError): raise ValueError({ 'error-string': """advertisement_interval must be of a type compatible with container""", 'defined-type': "container", 'generated-type': """YANGDynClass(base=advertisement_interval.advertisement_interval, is_container='container', presence=False, yang_name="advertisement-interval", rest_name="advertisement-interval", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'Minimum interval between sending BGP routing updates', u'cli-compact-syntax': None, u'cli-incomplete-command': None}}, namespace='urn:brocade.com:mgmt:brocade-bgp', defining_module='brocade-bgp', yang_type='container', is_config=True)""", }) self.__advertisement_interval = t if hasattr(self, '_set'): self._set()
Setter method for advertisement_interval, mapped from YANG variable /routing_system/router/router_bgp/address_family/ipv4/ipv4_unicast/af_vrf/neighbor/af_ipv4_vrf_neighbor_address_holder/af_ipv4_neighbor_addr/advertisement_interval (container) If this variable is read-only (config: false) in the source YANG file, then _set_advertisement_interval is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_advertisement_interval() directly.
def get(context, request, key=None): """Return all registry items if key is None, otherwise try to fetch the registry key """ registry_records = api.get_registry_records_by_keyword(key) # Prepare batch size = req.get_batch_size() start = req.get_batch_start() batch = api.make_batch(registry_records, size, start) return { "pagesize": batch.get_pagesize(), "next": batch.make_next_url(), "previous": batch.make_prev_url(), "page": batch.get_pagenumber(), "pages": batch.get_numpages(), "count": batch.get_sequence_length(), "items": [registry_records], "url": api.url_for("senaite.jsonapi.v1.registry", key=key), }
Return all registry items if key is None, otherwise try to fetch the registry key
def extend(self, other): """ Adds the values from the iterable *other* to the end of this collection. """ def extend_trans(pipe): values = list(other.__iter__(pipe)) if use_redis else other len_self = pipe.rpush(self.key, *(self._pickle(v) for v in values)) if self.writeback: for i, v in enumerate(values, len_self - len(values)): self.cache[i] = v if self._same_redis(other, RedisCollection): use_redis = True self._transaction(extend_trans, other.key) else: use_redis = False self._transaction(extend_trans)
Adds the values from the iterable *other* to the end of this collection.
def update_id_counter(self): """Update the `id_` counter so that it doesn't grow forever. """ if not self.__entries: self.__next_id = 1 else: self.__next_id = max(self.__entries.keys()) + 1
Update the `id_` counter so that it doesn't grow forever.
def prepare(self, f): """Accept an objective function for optimization.""" self.g = autograd.grad(f) self.h = autograd.hessian(f)
Accept an objective function for optimization.
def report_accounts(self, path, per_region=True, per_capita=False, pic_size=1000, format='rst', **kwargs): """ Generates a report to the given path for all extension This method calls .report_accounts for all extensions Notes ----- This looks prettier with the seaborn module (import seaborn before calling this method) Parameters ---------- path : string Root path for the report per_region : boolean, optional If true, reports the accounts per region per_capita : boolean, optional If true, reports the accounts per capita If per_capita and per_region are False, nothing will be done pic_size : int, optional size for the figures in px, 1000 by default format : string, optional file format of the report: 'rst'(default), 'html', 'latex', ... except for rst all depend on the module docutils (all writer_name from docutils can be used as format) ffname : string, optional root file name (without extension, per_capita or per_region will be attached) and folder names If None gets passed (default), self.name with be modified to get a valid name for the operation system without blanks **kwargs : key word arguments, optional This will be passed directly to the pd.DataFrame.plot method (through the self.plot_account method) """ for ext in self.get_extensions(data=True): ext.report_accounts(path=path, per_region=per_region, per_capita=per_capita, pic_size=pic_size, format=format, **kwargs)
Generates a report to the given path for all extension This method calls .report_accounts for all extensions Notes ----- This looks prettier with the seaborn module (import seaborn before calling this method) Parameters ---------- path : string Root path for the report per_region : boolean, optional If true, reports the accounts per region per_capita : boolean, optional If true, reports the accounts per capita If per_capita and per_region are False, nothing will be done pic_size : int, optional size for the figures in px, 1000 by default format : string, optional file format of the report: 'rst'(default), 'html', 'latex', ... except for rst all depend on the module docutils (all writer_name from docutils can be used as format) ffname : string, optional root file name (without extension, per_capita or per_region will be attached) and folder names If None gets passed (default), self.name with be modified to get a valid name for the operation system without blanks **kwargs : key word arguments, optional This will be passed directly to the pd.DataFrame.plot method (through the self.plot_account method)
def download_archive(sources): """ Downloads an archive and saves locally (taken from PySMT). """ # last element is expected to be the local archive name save_to = sources[-1] # not downloading the file again if it exists if os.path.exists(save_to): print('not downloading {0} since it exists locally'.format(save_to)) return # try all possible sources one by one for url in sources[:-1]: # make five attempts per source for i in range(5): # first attempt to get a response response = urlopen(url) # handling redirections u = urlopen(response.geturl()) meta = u.info() if meta.get('Content-Length') and len(meta.get('Content-Length')) > 0: filesz = int(meta.get('Content-Length')) if os.path.exists(save_to) and os.path.getsize(save_to) == filesz: print('not downloading {0} since it exists locally'.format(save_to)) return print('downloading: {0} ({1} bytes)...'.format(save_to, filesz), end=' ') with open(save_to, 'wb') as fp: block_sz = 8192 while True: buff = u.read(block_sz) if not buff: break fp.write(buff) print('done') break else: continue break # successfully got the file else: assert 0, 'something went wrong -- cannot download {0}'.format(save_to)
Downloads an archive and saves locally (taken from PySMT).
def user(self, login=None): """Returns a User object for the specified login name if provided. If no login name is provided, this will return a User object for the authenticated user. :param str login: (optional) :returns: :class:`User <github3.users.User>` """ if login: url = self._build_url('users', login) else: url = self._build_url('user') json = self._json(self._get(url), 200) return User(json, self._session) if json else None
Returns a User object for the specified login name if provided. If no login name is provided, this will return a User object for the authenticated user. :param str login: (optional) :returns: :class:`User <github3.users.User>`
def help_center_section_subscription_delete(self, section_id, id, **kwargs): "https://developer.zendesk.com/rest_api/docs/help_center/subscriptions#delete-section-subscription" api_path = "/api/v2/help_center/sections/{section_id}/subscriptions/{id}.json" api_path = api_path.format(section_id=section_id, id=id) return self.call(api_path, method="DELETE", **kwargs)
https://developer.zendesk.com/rest_api/docs/help_center/subscriptions#delete-section-subscription
def uni(key): '''as a crutch, we allow str-type keys, but they really should be unicode. ''' if isinstance(key, str): logger.warn('assuming utf8 on: %r', key) return unicode(key, 'utf-8') elif isinstance(key, unicode): return key else: raise NonUnicodeKeyError(key)
as a crutch, we allow str-type keys, but they really should be unicode.
def getCollapseRequestsFn(self): """Helper function to determine which collapseRequests function to use from L{_collapseRequests}, or None for no merging""" # first, seek through builder, global, and the default collapseRequests_fn = self.config.collapseRequests if collapseRequests_fn is None: collapseRequests_fn = self.master.config.collapseRequests if collapseRequests_fn is None: collapseRequests_fn = True # then translate False and True properly if collapseRequests_fn is False: collapseRequests_fn = None elif collapseRequests_fn is True: collapseRequests_fn = self._defaultCollapseRequestFn return collapseRequests_fn
Helper function to determine which collapseRequests function to use from L{_collapseRequests}, or None for no merging
async def raw(self, key, *, dc=None, watch=None, consistency=None): """Returns the specified key Parameters: key (str): Key to fetch dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. watch (Blocking): Do a blocking query consistency (Consistency): Force consistency Returns: ObjectMeta: where value is the raw value """ response = await self._read(key, dc=dc, raw=True, watch=watch, consistency=consistency) return consul(response)
Returns the specified key Parameters: key (str): Key to fetch dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. watch (Blocking): Do a blocking query consistency (Consistency): Force consistency Returns: ObjectMeta: where value is the raw value
def flatten_all(nested_iterable): """Flatten arbitrary depth of nesting. Good for unknown nesting structure iterable object. Example:: >>> list(flatten_all([[1, 2], "abc", [3, ["x", "y", "z"]], 4])) [1, 2, "abc", 3, "x", "y", "z", 4] **中文文档** 将任意维度的列表压平成一维列表。 注: 使用hasattr(i, "__iter__")方法做是否是可循环对象的判断, 性能要高于其他 任何方法, 例如: isinstance(i, collections.Iterable) """ for item in nested_iterable: if hasattr(item, "__iter__") and not isinstance(item, string_types): for i in flatten_all(item): yield i else: yield item
Flatten arbitrary depth of nesting. Good for unknown nesting structure iterable object. Example:: >>> list(flatten_all([[1, 2], "abc", [3, ["x", "y", "z"]], 4])) [1, 2, "abc", 3, "x", "y", "z", 4] **中文文档** 将任意维度的列表压平成一维列表。 注: 使用hasattr(i, "__iter__")方法做是否是可循环对象的判断, 性能要高于其他 任何方法, 例如: isinstance(i, collections.Iterable)
def short_description(description): """ Sets 'short_description' attribute (this attribute is in exports to generate header name). """ def decorator(func): if isinstance(func, property): func = func.fget func.short_description = description return func return decorator
Sets 'short_description' attribute (this attribute is in exports to generate header name).
def random_get_int_mean( rnd: Optional[tcod.random.Random], mi: int, ma: int, mean: int ) -> int: """Return a random weighted integer in the range: ``mi`` <= n <= ``ma``. The result is affacted by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (int): The lower bound of the random range, inclusive. high (int): The upper bound of the random range, inclusive. mean (int): The mean return value. Returns: int: A random weighted integer in the range ``mi`` <= n <= ``ma``. """ return int( lib.TCOD_random_get_int_mean( rnd.random_c if rnd else ffi.NULL, mi, ma, mean ) )
Return a random weighted integer in the range: ``mi`` <= n <= ``ma``. The result is affacted by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (int): The lower bound of the random range, inclusive. high (int): The upper bound of the random range, inclusive. mean (int): The mean return value. Returns: int: A random weighted integer in the range ``mi`` <= n <= ``ma``.
def do_part(self, cmdargs, nick, target, msgtype, send, c): """Leaves a channel. Prevent user from leaving the primary channel. """ channel = self.config['core']['channel'] botnick = self.config['core']['nick'] if not cmdargs: # don't leave the primary channel if target == channel: send("%s must have a home." % botnick) return else: cmdargs = target if not cmdargs.startswith(('#', '+', '@')): cmdargs = '#' + cmdargs # don't leave the primary channel if cmdargs == channel: send("%s must have a home." % botnick) return # don't leave the control channel if cmdargs == self.config['core']['ctrlchan']: send("%s must remain under control, or bad things will happen." % botnick) return self.send(cmdargs, nick, "Leaving at the request of %s" % nick, msgtype) c.part(cmdargs)
Leaves a channel. Prevent user from leaving the primary channel.
def rot_from_vectors(start_vec, end_vec): """Return the rotation matrix to rotate from one vector to another.""" dot = start_vec.dot(end_vec) # TODO: check if dot is a valid number angle = math.acos(dot) # TODO: check if angle is a valid number cross = start_vec.cross(end_vec) cross.normalize rot_matrix = Matrix44.from_axis_angle(cross, angle) # TODO: catch exception and return identity for invalid numbers return rot_matrix
Return the rotation matrix to rotate from one vector to another.
def to_dqflags(self, bits=None, minlen=1, dtype=float, round=False): """Convert this `StateVector` into a `~gwpy.segments.DataQualityDict` The `StateTimeSeries` for each bit is converted into a `~gwpy.segments.DataQualityFlag` with the bits combined into a dict. Parameters ---------- minlen : `int`, optional, default: 1 minimum number of consecutive `True` values to identify as a `Segment`. This is useful to ignore single bit flips, for example. bits : `list`, optional a list of bit indices or bit names to select, defaults to `~StateVector.bits` Returns ------- DataQualityFlag list : `list` a list of `~gwpy.segments.flag.DataQualityFlag` reprensentations for each bit in this `StateVector` See Also -------- :meth:`StateTimeSeries.to_dqflag` for details on the segment representation method for `StateVector` bits """ from ..segments import DataQualityDict out = DataQualityDict() bitseries = self.get_bit_series(bits=bits) for bit, sts in bitseries.items(): out[bit] = sts.to_dqflag(name=bit, minlen=minlen, round=round, dtype=dtype, description=self.bits.description[bit]) return out
Convert this `StateVector` into a `~gwpy.segments.DataQualityDict` The `StateTimeSeries` for each bit is converted into a `~gwpy.segments.DataQualityFlag` with the bits combined into a dict. Parameters ---------- minlen : `int`, optional, default: 1 minimum number of consecutive `True` values to identify as a `Segment`. This is useful to ignore single bit flips, for example. bits : `list`, optional a list of bit indices or bit names to select, defaults to `~StateVector.bits` Returns ------- DataQualityFlag list : `list` a list of `~gwpy.segments.flag.DataQualityFlag` reprensentations for each bit in this `StateVector` See Also -------- :meth:`StateTimeSeries.to_dqflag` for details on the segment representation method for `StateVector` bits
def on_receive_append_entries(self, data): """If we discover a Leader with the same term — step down""" if self.storage.term == data['term']: self.state.to_follower()
If we discover a Leader with the same term — step down
def get_oauth_url(self): """ Returns the URL with OAuth params """ params = OrderedDict() if "?" in self.url: url = self.url[:self.url.find("?")] for key, value in parse_qsl(urlparse(self.url).query): params[key] = value else: url = self.url params["oauth_consumer_key"] = self.consumer_key params["oauth_timestamp"] = self.timestamp params["oauth_nonce"] = self.generate_nonce() params["oauth_signature_method"] = "HMAC-SHA256" params["oauth_signature"] = self.generate_oauth_signature(params, url) query_string = urlencode(params) return "%s?%s" % (url, query_string)
Returns the URL with OAuth params
def search_regexp(self, pattern, audio_basename=None): """ First joins the words of the word_blocks of timestamps with space, per audio_basename. Then matches `pattern` and calculates the index of the word_block where the first and last word of the matched result appears in. Then presents the output like `search_all` method. Note that the leading and trailing spaces from the matched results would be removed while determining which word_block they belong to. Parameters ---------- pattern : str A regex pattern. audio_basename : str, optional Search only within the given audio_basename. Default is `False`. Returns ------- search_results : {str: {str: [(float, float)]}} A dictionary whose keys are queries and whose values are dictionaries whose keys are all the audiofiles in which the query is present and whose values are a list whose elements are 2-tuples whose first element is the starting second of the query and whose values are the ending second. e.g. {"apple": {"fruits.wav" : [(1.1, 1.12)]}} """ def indexes_in_transcript_to_start_end_second(index_tup, audio_basename): """ Calculates the word block index by having the beginning and ending index of the matched result from the transcription Parameters ---------- index_tup : (int, tup) index_tup is of the form tuple(index_start, index_end) audio_basename : str Retrun ------ [float, float] The time of the output of the matched result. Derived from two separate word blocks belonging to the beginning and the end of the index_start and index_end. """ space_indexes = [i for i, x in enumerate( transcription[audio_basename]) if x == " "] space_indexes.sort(reverse=True) index_start, index_end = index_tup # re.finditer returns the ending index by one more index_end -= 1 while transcription[audio_basename][index_start] == " ": index_start += 1 while transcription[audio_basename][index_end] == " ": index_end -= 1 block_number_start = 0 block_number_end = len(space_indexes) for block_cursor, space_index in enumerate(space_indexes): if index_start > space_index: block_number_start = (len(space_indexes) - block_cursor) break for block_cursor, space_index in enumerate(space_indexes): if index_end > space_index: block_number_end = (len(space_indexes) - block_cursor) break return (timestamps[audio_basename][block_number_start].start, timestamps[audio_basename][block_number_end].end) timestamps = self.get_timestamps() if audio_basename is not None: timestamps = {audio_basename: timestamps[audio_basename]} transcription = { audio_basename: ' '.join( [word_block.word for word_block in timestamps[audio_basename]] ) for audio_basename in timestamps} match_map = map( lambda audio_basename: tuple(( audio_basename, re.finditer(pattern, transcription[audio_basename]))), transcription.keys()) search_results = _PrettyDefaultDict(lambda: _PrettyDefaultDict(list)) for audio_basename, match_iter in match_map: for match in match_iter: search_results[match.group()][audio_basename].append( tuple(indexes_in_transcript_to_start_end_second( match.span(), audio_basename))) return search_results
First joins the words of the word_blocks of timestamps with space, per audio_basename. Then matches `pattern` and calculates the index of the word_block where the first and last word of the matched result appears in. Then presents the output like `search_all` method. Note that the leading and trailing spaces from the matched results would be removed while determining which word_block they belong to. Parameters ---------- pattern : str A regex pattern. audio_basename : str, optional Search only within the given audio_basename. Default is `False`. Returns ------- search_results : {str: {str: [(float, float)]}} A dictionary whose keys are queries and whose values are dictionaries whose keys are all the audiofiles in which the query is present and whose values are a list whose elements are 2-tuples whose first element is the starting second of the query and whose values are the ending second. e.g. {"apple": {"fruits.wav" : [(1.1, 1.12)]}}
def dump_links(self, o): """Dump links.""" links = { 'self': url_for( '.object_api', bucket_id=o.bucket_id, key=o.key, uploadId=o.upload_id, _external=True, ), 'object': url_for( '.object_api', bucket_id=o.bucket_id, key=o.key, _external=True, ), } version_id = self.context.get('object_version_id') if version_id: links.update({ 'object_version': url_for( '.object_api', bucket_id=o.bucket_id, key=o.key, versionId=version_id, _external=True, ) }) bucket = self.context.get('bucket') if bucket: links.update({ 'bucket': url_for( '.bucket_api', bucket_id=o.bucket_id, _external=True, ) }) return links
Dump links.
def to_dict(self): """ Return a dict respresentation of an MNLDiscreteChoiceModel instance. """ return { 'model_type': 'discretechoice', 'model_expression': self.model_expression, 'sample_size': self.sample_size, 'name': self.name, 'probability_mode': self.probability_mode, 'choice_mode': self.choice_mode, 'choosers_fit_filters': self.choosers_fit_filters, 'choosers_predict_filters': self.choosers_predict_filters, 'alts_fit_filters': self.alts_fit_filters, 'alts_predict_filters': self.alts_predict_filters, 'interaction_predict_filters': self.interaction_predict_filters, 'estimation_sample_size': self.estimation_sample_size, 'prediction_sample_size': self.prediction_sample_size, 'choice_column': self.choice_column, 'fitted': self.fitted, 'log_likelihoods': self.log_likelihoods, 'fit_parameters': (yamlio.frame_to_yaml_safe(self.fit_parameters) if self.fitted else None) }
Return a dict respresentation of an MNLDiscreteChoiceModel instance.
def do_loop_turn(self): """Receiver daemon main loop :return: None """ # Begin to clean modules self.check_and_del_zombie_modules() # Maybe the arbiter pushed a new configuration... if self.watch_for_new_conf(timeout=0.05): logger.info("I got a new configuration...") # Manage the new configuration self.setup_new_conf() # Maybe external modules raised 'objects' # we should get them _t0 = time.time() self.get_objects_from_from_queues() statsmgr.timer('core.get-objects-from-queues', time.time() - _t0) # Get external commands from the arbiters... _t0 = time.time() self.get_external_commands_from_arbiters() statsmgr.timer('external-commands.got.time', time.time() - _t0) statsmgr.gauge('external-commands.got.count', len(self.unprocessed_external_commands)) _t0 = time.time() self.push_external_commands_to_schedulers() statsmgr.timer('external-commands.pushed.time', time.time() - _t0) # Say to modules it's a new tick :) _t0 = time.time() self.hook_point('tick') statsmgr.timer('hook.tick', time.time() - _t0)
Receiver daemon main loop :return: None
def connect(self): """Authenticate to WOS and set the SID cookie.""" if not self._SID: self._SID = self._auth.service.authenticate() print('Authenticated (SID: %s)' % self._SID) self._search.set_options(headers={'Cookie': 'SID="%s"' % self._SID}) self._auth.options.headers.update({'Cookie': 'SID="%s"' % self._SID}) return self._SID
Authenticate to WOS and set the SID cookie.
def finish(self): """Combines coverage data and sets the list of coverage objects to report on.""" # Combine all the suffix files into the data file. self.cov.stop() self.cov.combine() self.cov.save()
Combines coverage data and sets the list of coverage objects to report on.
def get_layer(pressure, *args, **kwargs): r"""Return an atmospheric layer from upper air data with the requested bottom and depth. This function will subset an upper air dataset to contain only the specified layer. The bottom of the layer can be specified with a pressure or height above the surface pressure. The bottom defaults to the surface pressure. The depth of the layer can be specified in terms of pressure or height above the bottom of the layer. If the top and bottom of the layer are not in the data, they are interpolated by default. Parameters ---------- pressure : array-like Atmospheric pressure profile *args : array-like Atmospheric variable(s) measured at the given pressures heights: array-like, optional Atmospheric heights corresponding to the given pressures. Defaults to using heights calculated from ``p`` assuming a standard atmosphere. bottom : `pint.Quantity`, optional The bottom of the layer as a pressure or height above the surface pressure. Defaults to the highest pressure or lowest height given. depth : `pint.Quantity`, optional The thickness of the layer as a pressure or height above the bottom of the layer. Defaults to 100 hPa. interpolate : bool, optional Interpolate the top and bottom points if they are not in the given data. Defaults to True. Returns ------- `pint.Quantity, pint.Quantity` The pressure and data variables of the layer """ # Pop off keyword arguments heights = kwargs.pop('heights', None) bottom = kwargs.pop('bottom', None) depth = kwargs.pop('depth', 100 * units.hPa) interpolate = kwargs.pop('interpolate', True) # If we get the depth kwarg, but it's None, set it to the default as well if depth is None: depth = 100 * units.hPa # Make sure pressure and datavars are the same length for datavar in args: if len(pressure) != len(datavar): raise ValueError('Pressure and data variables must have the same length.') # If the bottom is not specified, make it the surface pressure if bottom is None: bottom = np.nanmax(pressure) * pressure.units bottom_pressure, bottom_height = _get_bound_pressure_height(pressure, bottom, heights=heights, interpolate=interpolate) # Calculate the top if whatever units depth is in if depth.dimensionality == {'[length]': -1.0, '[mass]': 1.0, '[time]': -2.0}: top = bottom_pressure - depth elif depth.dimensionality == {'[length]': 1}: top = bottom_height + depth else: raise ValueError('Depth must be specified in units of length or pressure') top_pressure, _ = _get_bound_pressure_height(pressure, top, heights=heights, interpolate=interpolate) ret = [] # returned data variables in layer # Ensure pressures are sorted in ascending order sort_inds = np.argsort(pressure) pressure = pressure[sort_inds] # Mask based on top and bottom pressure inds = (_less_or_close(pressure, bottom_pressure) & _greater_or_close(pressure, top_pressure)) p_interp = pressure[inds] # Interpolate pressures at bounds if necessary and sort if interpolate: # If we don't have the bottom or top requested, append them if not np.any(np.isclose(top_pressure, p_interp)): p_interp = np.sort(np.append(p_interp, top_pressure)) * pressure.units if not np.any(np.isclose(bottom_pressure, p_interp)): p_interp = np.sort(np.append(p_interp, bottom_pressure)) * pressure.units ret.append(p_interp[::-1]) for datavar in args: # Ensure that things are sorted in ascending order datavar = datavar[sort_inds] if interpolate: # Interpolate for the possibly missing bottom/top values datavar_interp = log_interpolate_1d(p_interp, pressure, datavar) datavar = datavar_interp else: datavar = datavar[inds] ret.append(datavar[::-1]) return ret
r"""Return an atmospheric layer from upper air data with the requested bottom and depth. This function will subset an upper air dataset to contain only the specified layer. The bottom of the layer can be specified with a pressure or height above the surface pressure. The bottom defaults to the surface pressure. The depth of the layer can be specified in terms of pressure or height above the bottom of the layer. If the top and bottom of the layer are not in the data, they are interpolated by default. Parameters ---------- pressure : array-like Atmospheric pressure profile *args : array-like Atmospheric variable(s) measured at the given pressures heights: array-like, optional Atmospheric heights corresponding to the given pressures. Defaults to using heights calculated from ``p`` assuming a standard atmosphere. bottom : `pint.Quantity`, optional The bottom of the layer as a pressure or height above the surface pressure. Defaults to the highest pressure or lowest height given. depth : `pint.Quantity`, optional The thickness of the layer as a pressure or height above the bottom of the layer. Defaults to 100 hPa. interpolate : bool, optional Interpolate the top and bottom points if they are not in the given data. Defaults to True. Returns ------- `pint.Quantity, pint.Quantity` The pressure and data variables of the layer
def delimiters_to_re(delimiters): """convert delimiters to corresponding regular expressions""" # caching delimiters = tuple(delimiters) if delimiters in re_delimiters: re_tag = re_delimiters[delimiters] else: open_tag, close_tag = delimiters # escape open_tag = ''.join([c if c.isalnum() else '\\' + c for c in open_tag]) close_tag = ''.join([c if c.isalnum() else '\\' + c for c in close_tag]) re_tag = re.compile(open_tag + r'([#^>&{/!=]?)\s*(.*?)\s*([}=]?)' + close_tag, re.DOTALL) re_delimiters[delimiters] = re_tag return re_tag
convert delimiters to corresponding regular expressions
def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=None, contacts=None, organization=None): """ Builds the metadata of the SP :param sp: The SP data :type sp: string :param authnsign: authnRequestsSigned attribute :type authnsign: string :param wsign: wantAssertionsSigned attribute :type wsign: string :param valid_until: Metadata's expiry date :type valid_until: string|DateTime|Timestamp :param cache_duration: Duration of the cache in seconds :type cache_duration: int|string :param contacts: Contacts info :type contacts: dict :param organization: Organization info :type organization: dict """ if valid_until is None: valid_until = int(time()) + OneLogin_Saml2_Metadata.TIME_VALID if not isinstance(valid_until, basestring): if isinstance(valid_until, datetime): valid_until_time = valid_until.timetuple() else: valid_until_time = gmtime(valid_until) valid_until_str = strftime(r'%Y-%m-%dT%H:%M:%SZ', valid_until_time) else: valid_until_str = valid_until if cache_duration is None: cache_duration = OneLogin_Saml2_Metadata.TIME_CACHED if not isinstance(cache_duration, basestring): cache_duration_str = 'PT%sS' % cache_duration # 'P'eriod of 'T'ime x 'S'econds else: cache_duration_str = cache_duration if contacts is None: contacts = {} if organization is None: organization = {} str_attribute_consuming_service = '' if 'attributeConsumingService' in sp and len(sp['attributeConsumingService']): attr_cs_desc_str = '' if "serviceDescription" in sp['attributeConsumingService']: attr_cs_desc_str = """ <md:ServiceDescription xml:lang="en">%s</md:ServiceDescription> """ % sp['attributeConsumingService']['serviceDescription'] requested_attribute_data = [] for req_attribs in sp['attributeConsumingService']['requestedAttributes']: req_attr_nameformat_str = req_attr_friendlyname_str = req_attr_isrequired_str = '' req_attr_aux_str = ' />' if 'nameFormat' in req_attribs.keys() and req_attribs['nameFormat']: req_attr_nameformat_str = " NameFormat=\"%s\"" % req_attribs['nameFormat'] if 'friendlyName' in req_attribs.keys() and req_attribs['friendlyName']: req_attr_friendlyname_str = " FriendlyName=\"%s\"" % req_attribs['friendlyName'] if 'isRequired' in req_attribs.keys() and req_attribs['isRequired']: req_attr_isrequired_str = " isRequired=\"%s\"" % 'true' if req_attribs['isRequired'] else 'false' if 'attributeValue' in req_attribs.keys() and req_attribs['attributeValue']: if isinstance(req_attribs['attributeValue'], basestring): req_attribs['attributeValue'] = [req_attribs['attributeValue']] req_attr_aux_str = ">" for attrValue in req_attribs['attributeValue']: req_attr_aux_str += """ <saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">%(attributeValue)s</saml:AttributeValue>""" % \ { 'attributeValue': attrValue } req_attr_aux_str += """ </md:RequestedAttribute>""" requested_attribute = """ <md:RequestedAttribute Name="%(req_attr_name)s"%(req_attr_nameformat_str)s%(req_attr_friendlyname_str)s%(req_attr_isrequired_str)s%(req_attr_aux_str)s""" % \ { 'req_attr_name': req_attribs['name'], 'req_attr_nameformat_str': req_attr_nameformat_str, 'req_attr_friendlyname_str': req_attr_friendlyname_str, 'req_attr_isrequired_str': req_attr_isrequired_str, 'req_attr_aux_str': req_attr_aux_str } requested_attribute_data.append(requested_attribute) str_attribute_consuming_service = """ <md:AttributeConsumingService index="1"> <md:ServiceName xml:lang="en">%(service_name)s</md:ServiceName> %(attr_cs_desc)s%(requested_attribute_str)s </md:AttributeConsumingService> """ % \ { 'service_name': sp['attributeConsumingService']['serviceName'], 'attr_cs_desc': attr_cs_desc_str, 'requested_attribute_str': '\n'.join(requested_attribute_data) } sls = '' if 'singleLogoutService' in sp and 'url' in sp['singleLogoutService']: sls = """ <md:SingleLogoutService Binding="%(binding)s" Location="%(location)s" />\n""" % \ { 'binding': sp['singleLogoutService']['binding'], 'location': sp['singleLogoutService']['url'], } str_authnsign = 'true' if authnsign else 'false' str_wsign = 'true' if wsign else 'false' str_organization = '' if len(organization) > 0: organization_names = [] organization_displaynames = [] organization_urls = [] for (lang, info) in organization.items(): organization_names.append(""" <md:OrganizationName xml:lang="%s">%s</md:OrganizationName>""" % (lang, info['name'])) organization_displaynames.append(""" <md:OrganizationDisplayName xml:lang="%s">%s</md:OrganizationDisplayName>""" % (lang, info['displayname'])) organization_urls.append(""" <md:OrganizationURL xml:lang="%s">%s</md:OrganizationURL>""" % (lang, info['url'])) org_data = '\n'.join(organization_names) + '\n' + '\n'.join(organization_displaynames) + '\n' + '\n'.join(organization_urls) str_organization = """ <md:Organization> %(org)s </md:Organization>\n""" % {'org': org_data} str_contacts = '' if len(contacts) > 0: contacts_info = [] for (ctype, info) in contacts.items(): contact = """ <md:ContactPerson contactType="%(type)s"> <md:GivenName>%(name)s</md:GivenName> <md:EmailAddress>%(email)s</md:EmailAddress> </md:ContactPerson>""" % \ { 'type': ctype, 'name': info['givenName'], 'email': info['emailAddress'], } contacts_info.append(contact) str_contacts = '\n'.join(contacts_info) + '\n' metadata = u"""<?xml version="1.0"?> <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" %(valid)s %(cache)s entityID="%(entity_id)s"> <md:SPSSODescriptor AuthnRequestsSigned="%(authnsign)s" WantAssertionsSigned="%(wsign)s" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> %(sls)s <md:NameIDFormat>%(name_id_format)s</md:NameIDFormat> <md:AssertionConsumerService Binding="%(binding)s" Location="%(location)s" index="1" /> %(attribute_consuming_service)s </md:SPSSODescriptor> %(organization)s%(contacts)s</md:EntityDescriptor>""" % \ { 'valid': ('validUntil="%s"' % valid_until_str) if valid_until_str else '', 'cache': ('cacheDuration="%s"' % cache_duration_str) if cache_duration_str else '', 'entity_id': sp['entityId'], 'authnsign': str_authnsign, 'wsign': str_wsign, 'name_id_format': sp['NameIDFormat'], 'binding': sp['assertionConsumerService']['binding'], 'location': sp['assertionConsumerService']['url'], 'sls': sls, 'organization': str_organization, 'contacts': str_contacts, 'attribute_consuming_service': str_attribute_consuming_service } return metadata
Builds the metadata of the SP :param sp: The SP data :type sp: string :param authnsign: authnRequestsSigned attribute :type authnsign: string :param wsign: wantAssertionsSigned attribute :type wsign: string :param valid_until: Metadata's expiry date :type valid_until: string|DateTime|Timestamp :param cache_duration: Duration of the cache in seconds :type cache_duration: int|string :param contacts: Contacts info :type contacts: dict :param organization: Organization info :type organization: dict
def main(relation_name=None): """ This is the main entry point for the reactive framework. It calls :func:`~bus.discover` to find and load all reactive handlers (e.g., :func:`@when <decorators.when>` decorated blocks), and then :func:`~bus.dispatch` to trigger handlers until the queue settles out. Finally, :meth:`unitdata.kv().flush <charmhelpers.core.unitdata.Storage.flush>` is called to persist the flags and other data. :param str relation_name: Optional name of the relation which is being handled. """ hook_name = hookenv.hook_name() restricted_mode = hook_name in ['meter-status-changed', 'collect-metrics'] hookenv.log('Reactive main running for hook %s' % hookenv.hook_name(), level=hookenv.INFO) if restricted_mode: hookenv.log('Restricted mode.', level=hookenv.INFO) # work-around for https://bugs.launchpad.net/juju-core/+bug/1503039 # ensure that external handlers can tell what hook they're running in if 'JUJU_HOOK_NAME' not in os.environ: os.environ['JUJU_HOOK_NAME'] = hook_name try: bus.discover() if not restricted_mode: # limit what gets run in restricted mode hookenv._run_atstart() bus.dispatch(restricted=restricted_mode) except Exception: tb = traceback.format_exc() hookenv.log('Hook error:\n{}'.format(tb), level=hookenv.ERROR) raise except SystemExit as x: if x.code not in (None, 0): raise if not restricted_mode: # limit what gets run in restricted mode hookenv._run_atexit() unitdata._KV.flush()
This is the main entry point for the reactive framework. It calls :func:`~bus.discover` to find and load all reactive handlers (e.g., :func:`@when <decorators.when>` decorated blocks), and then :func:`~bus.dispatch` to trigger handlers until the queue settles out. Finally, :meth:`unitdata.kv().flush <charmhelpers.core.unitdata.Storage.flush>` is called to persist the flags and other data. :param str relation_name: Optional name of the relation which is being handled.
def get_term_by_date(date): """ Returns a term for the datetime.date object given. """ year = date.year term = None for quarter in ('autumn', 'summer', 'spring', 'winter'): term = get_term_by_year_and_quarter(year, quarter) if date >= term.first_day_quarter: break # If we're in a year, before the start of winter quarter, we need to go # to the previous year's autumn term: if date < term.first_day_quarter: term = get_term_by_year_and_quarter(year - 1, 'autumn') # Autumn quarter should always last through the end of the year, # with winter of the next year starting in January. But this makes sure # we catch it if not. term_after = get_term_after(term) if term_after.first_day_quarter > date: return term else: return term_after pass
Returns a term for the datetime.date object given.
def get(self, path, query=None, redirects=True): """ GET request wrapper for :func:`request()` """ return self.request('GET', path, query, None, redirects)
GET request wrapper for :func:`request()`
def _tupleload(l: Loader, value, type_) -> Tuple: """ This loads into something like Tuple[int,str] """ if HAS_TUPLEARGS: args = type_.__args__ else: args = type_.__tuple_params__ if len(args) == 2 and args[1] == ...: # Tuple[something, ...] return tuple(l.load(i, args[0]) for i in value) else: # Tuple[something, something, somethingelse] if l.failonextra and len(value) > len(args): raise TypedloadValueError('Value is too long for type %s' % type_, value=value, type_=type_) elif len(value) < len(args): raise TypedloadValueError('Value is too short for type %s' % type_, value=value, type_=type_) return tuple(l.load(v, t, annotation=Annotation(AnnotationType.INDEX, i)) for i, (v, t) in enumerate(zip(value, args)))
This loads into something like Tuple[int,str]
def detect_encoding(filename): """Return file encoding.""" try: with open(filename, 'rb') as input_file: from lib2to3.pgen2 import tokenize as lib2to3_tokenize encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0] # Check for correctness of encoding. with open_with_encoding(filename, encoding) as input_file: input_file.read() return encoding except (SyntaxError, LookupError, UnicodeDecodeError): return 'latin-1'
Return file encoding.
def estimated_document_count(self, **kwargs): """Get an estimate of the number of documents in this collection using collection metadata. The :meth:`estimated_document_count` method is **not** supported in a transaction. All optional parameters should be passed as keyword arguments to this method. Valid options include: - `maxTimeMS` (int): The maximum amount of time to allow this operation to run, in milliseconds. :Parameters: - `**kwargs` (optional): See list of options above. .. versionadded:: 3.7 """ if 'session' in kwargs: raise ConfigurationError( 'estimated_document_count does not support sessions') cmd = SON([('count', self.__name)]) cmd.update(kwargs) return self._count(cmd)
Get an estimate of the number of documents in this collection using collection metadata. The :meth:`estimated_document_count` method is **not** supported in a transaction. All optional parameters should be passed as keyword arguments to this method. Valid options include: - `maxTimeMS` (int): The maximum amount of time to allow this operation to run, in milliseconds. :Parameters: - `**kwargs` (optional): See list of options above. .. versionadded:: 3.7
def broadcast(data, root): """Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- object : int the result of broadcast. """ rank = get_rank() length = ctypes.c_ulong() if root == rank: assert data is not None, 'need to pass in data when broadcasting' s = pickle.dumps(data, protocol=pickle.HIGHEST_PROTOCOL) length.value = len(s) # run first broadcast _LIB.RabitBroadcast(ctypes.byref(length), ctypes.sizeof(ctypes.c_ulong), root) if root != rank: dptr = (ctypes.c_char * length.value)() # run second _LIB.RabitBroadcast(ctypes.cast(dptr, ctypes.c_void_p), length.value, root) data = pickle.loads(dptr.raw) del dptr else: _LIB.RabitBroadcast(ctypes.cast(ctypes.c_char_p(s), ctypes.c_void_p), length.value, root) del s return data
Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- object : int the result of broadcast.
def save_configuration_to_hdf5(register, configuration_file, name=''): '''Saving configuration to HDF5 file from register object Parameters ---------- register : pybar.fei4.register object configuration_file : string, file Filename of the HDF5 configuration file or file object. name : string Additional identifier (subgroup). Useful when storing more than one configuration inside a HDF5 file. ''' def save_conf(): logging.info("Saving configuration: %s" % h5_file.filename) register.configuration_file = h5_file.filename try: configuration_group = h5_file.create_group(h5_file.root, "configuration") except tb.NodeError: configuration_group = h5_file.root.configuration if name: try: configuration_group = h5_file.create_group(configuration_group, name) except tb.NodeError: configuration_group = h5_file.root.configuration.name # calibration_parameters try: h5_file.remove_node(configuration_group, name='calibration_parameters') except tb.NodeError: pass calibration_data_table = h5_file.create_table(configuration_group, name='calibration_parameters', description=NameValue, title='calibration_parameters') calibration_data_row = calibration_data_table.row for key, value in register.calibration_parameters.iteritems(): calibration_data_row['name'] = key calibration_data_row['value'] = str(value) calibration_data_row.append() calibration_data_table.flush() # miscellaneous try: h5_file.remove_node(configuration_group, name='miscellaneous') except tb.NodeError: pass miscellaneous_data_table = h5_file.create_table(configuration_group, name='miscellaneous', description=NameValue, title='miscellaneous') miscellaneous_data_row = miscellaneous_data_table.row miscellaneous_data_row['name'] = 'Flavor' miscellaneous_data_row['value'] = register.flavor miscellaneous_data_row.append() miscellaneous_data_row['name'] = 'Chip_ID' miscellaneous_data_row['value'] = register.chip_id miscellaneous_data_row.append() for key, value in register.miscellaneous.iteritems(): miscellaneous_data_row['name'] = key miscellaneous_data_row['value'] = value miscellaneous_data_row.append() miscellaneous_data_table.flush() # global try: h5_file.remove_node(configuration_group, name='global_register') except tb.NodeError: pass global_data_table = h5_file.create_table(configuration_group, name='global_register', description=NameValue, title='global_register') global_data_table_row = global_data_table.row global_regs = register.get_global_register_objects(readonly=False) for global_reg in sorted(global_regs, key=itemgetter('name')): global_data_table_row['name'] = global_reg['name'] global_data_table_row['value'] = global_reg['value'] # TODO: some function that converts to bin, hex global_data_table_row.append() global_data_table.flush() # pixel for pixel_reg in register.pixel_registers.itervalues(): try: h5_file.remove_node(configuration_group, name=pixel_reg['name']) except tb.NodeError: pass data = pixel_reg['value'].T atom = tb.Atom.from_dtype(data.dtype) ds = h5_file.create_carray(configuration_group, name=pixel_reg['name'], atom=atom, shape=data.shape, title=pixel_reg['name']) ds[:] = data if isinstance(configuration_file, tb.file.File): h5_file = configuration_file save_conf() else: with tb.open_file(configuration_file, mode="a", title='') as h5_file: save_conf()
Saving configuration to HDF5 file from register object Parameters ---------- register : pybar.fei4.register object configuration_file : string, file Filename of the HDF5 configuration file or file object. name : string Additional identifier (subgroup). Useful when storing more than one configuration inside a HDF5 file.
def _process_plan_lines(self, final_line_count): """Process plan line rules.""" if not self._lines_seen["plan"]: self._add_error(_("Missing a plan.")) return if len(self._lines_seen["plan"]) > 1: self._add_error(_("Only one plan line is permitted per file.")) return plan, at_line = self._lines_seen["plan"][0] if not self._plan_on_valid_line(at_line, final_line_count): self._add_error( _("A plan must appear at the beginning or end of the file.") ) return if plan.expected_tests != self._lines_seen["test"]: self._add_error( _("Expected {expected_count} tests but only {seen_count} ran.").format( expected_count=plan.expected_tests, seen_count=self._lines_seen["test"], ) )
Process plan line rules.
def focus_next_sibling(self): """focus next sibling of currently focussed message in thread tree""" mid = self.get_selected_mid() newpos = self._tree.next_sibling_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
focus next sibling of currently focussed message in thread tree
def delete(self, expected_value=None, return_values=None): """ Delete the item from DynamoDB. :type expected_value: dict :param expected_value: A dictionary of name/value pairs that you expect. This dictionary should have name/value pairs where the name is the name of the attribute and the value is either the value you are expecting or False if you expect the attribute not to exist. :type return_values: str :param return_values: Controls the return of attribute name-value pairs before then were changed. Possible values are: None or 'ALL_OLD'. If 'ALL_OLD' is specified and the item is overwritten, the content of the old item is returned. """ return self.table.layer2.delete_item(self, expected_value, return_values)
Delete the item from DynamoDB. :type expected_value: dict :param expected_value: A dictionary of name/value pairs that you expect. This dictionary should have name/value pairs where the name is the name of the attribute and the value is either the value you are expecting or False if you expect the attribute not to exist. :type return_values: str :param return_values: Controls the return of attribute name-value pairs before then were changed. Possible values are: None or 'ALL_OLD'. If 'ALL_OLD' is specified and the item is overwritten, the content of the old item is returned.
def serial_ppmap(func, fixed_arg, var_arg_iter): """A serial implementation of the "partially-pickling map" function returned by the :meth:`ParallelHelper.get_ppmap` interface. Its arguments are: *func* A callable taking three arguments and returning a Pickle-able value. *fixed_arg* Any value, even one that is not pickle-able. *var_arg_iter* An iterable that generates Pickle-able values. The functionality is:: def serial_ppmap(func, fixed_arg, var_arg_iter): return [func(i, fixed_arg, x) for i, x in enumerate(var_arg_iter)] Therefore the arguments to your ``func`` function, which actually does the interesting computations, are: *index* The 0-based index number of the item being processed; often this can be ignored. *fixed_arg* The same *fixed_arg* that was passed to ``ppmap``. *var_arg* The *index*'th item in the *var_arg_iter* iterable passed to ``ppmap``. """ return [func(i, fixed_arg, x) for i, x in enumerate(var_arg_iter)]
A serial implementation of the "partially-pickling map" function returned by the :meth:`ParallelHelper.get_ppmap` interface. Its arguments are: *func* A callable taking three arguments and returning a Pickle-able value. *fixed_arg* Any value, even one that is not pickle-able. *var_arg_iter* An iterable that generates Pickle-able values. The functionality is:: def serial_ppmap(func, fixed_arg, var_arg_iter): return [func(i, fixed_arg, x) for i, x in enumerate(var_arg_iter)] Therefore the arguments to your ``func`` function, which actually does the interesting computations, are: *index* The 0-based index number of the item being processed; often this can be ignored. *fixed_arg* The same *fixed_arg* that was passed to ``ppmap``. *var_arg* The *index*'th item in the *var_arg_iter* iterable passed to ``ppmap``.
def load_and_process_igor_model(self, marginals_file_name): """Set attributes by reading a generative model from IGoR marginal file. Sets attributes PV, PdelV_given_V, PDJ, PdelJ_given_J, PdelDldelDr_given_D, PinsVD, PinsDJ, Rvd, and Rdj. Parameters ---------- marginals_file_name : str File name for a IGoR model marginals file. """ raw_model = read_igor_marginals_txt(marginals_file_name) self.PV = raw_model[0]['v_choice'] self.PinsVD = raw_model[0]['vd_ins'] self.PinsDJ = raw_model[0]['dj_ins'] self.PdelV_given_V = raw_model[0]['v_3_del'].T self.PdelJ_given_J = raw_model[0]['j_5_del'].T #While this class assumes P(V, D, J) factorizes into P(V)*P(D, J), the B cell model #infers allowing for the full correlation. Most of the correlation information is due to #chromosomal correlation of alleles (i.e. what chromosome each allele is found on). #While this information can be interesting for inference purposes, it is discarded here #as generally these models may be use for CDR3s from individuals the models weren't inferred #from (and thus the chromosomal correlations are incorrect). This also equates the T and B cell #models. To reintroduce the chromosomal correlations use V and J usage masks after inferring the #allele identities on each chromosome. if raw_model[1]['d_gene'] == ['j_choice', 'd_gene']: #Factorized P(V, D, J) = P(V)*P(D, J) --- correct for T cell models self.PDJ = np.multiply(raw_model[0]['d_gene'].T, raw_model[0]['j_choice']) elif raw_model[1]['d_gene'] == ['v_choice', 'j_choice', 'd_gene']: #Full P(V, D, J) for B cells --- need to compute the marginal P(D, J) PVJ = np.multiply(raw_model[0]['j_choice'].T, raw_model[0]['v_choice']).T PVDJ = np.zeros([raw_model[0]['d_gene'].shape[0], raw_model[0]['d_gene'].shape[2], raw_model[0]['d_gene'].shape[1]]) for v_in in range(raw_model[0]['d_gene'].shape[0]): for j_in in range(raw_model[0]['d_gene'].shape[1]): PVDJ[v_in, :, j_in] = PVJ[v_in, j_in]*raw_model[0]['d_gene'][v_in, j_in, :] self.PDJ = np.sum(PVDJ, 0) else: print 'Unrecognized model structure -- need to construct P(D, J)' return 0 self.PdelDldelDr_given_D = np.transpose(np.multiply(np.transpose(raw_model[0]['d_3_del'], (2, 0, 1)), raw_model[0]['d_5_del']), (2, 0 , 1)) Rvd_raw = raw_model[0]['vd_dinucl'].reshape((4, 4)).T self.Rvd = np.multiply(Rvd_raw, 1/np.sum(Rvd_raw, axis = 0)) Rdj_raw = raw_model[0]['dj_dinucl'].reshape((4, 4)).T self.Rdj = np.multiply(Rdj_raw, 1/np.sum(Rdj_raw, axis = 0))
Set attributes by reading a generative model from IGoR marginal file. Sets attributes PV, PdelV_given_V, PDJ, PdelJ_given_J, PdelDldelDr_given_D, PinsVD, PinsDJ, Rvd, and Rdj. Parameters ---------- marginals_file_name : str File name for a IGoR model marginals file.
def main(importer_class=None, args=None): """Entry point for import program. If the ``args`` are provided, these should be a list of strings that will be used instead of ``sys.argv[1:]``. This is mostly useful for testing. """ parser = argparse.ArgumentParser( description='Import from external model formats') parser.add_argument('--source', metavar='path', default='.', help='Source directory or file') parser.add_argument('--dest', metavar='path', default='.', help='Destination directory (default is ".")') parser.add_argument('--no-exchange', action='store_true', help=('Disable importing exchange reactions as' ' exchange compound file.')) parser.add_argument('--split-subsystem', action='store_true', help='Enable splitting reaction files by subsystem') parser.add_argument('--merge-compounds', action='store_true', help=('Merge identical compounds occuring in various' ' compartments.')) parser.add_argument('--force', action='store_true', help='Enable overwriting model files') if importer_class is None: parser.add_argument( 'format', help='Format to import ("list" to see all)') args = parser.parse_args(args) # Set up logging for the command line interface if 'PSAMM_DEBUG' in os.environ: level = getattr(logging, os.environ['PSAMM_DEBUG'].upper(), None) if level is not None: logging.basicConfig(level=level) else: logging.basicConfig( level=logging.INFO, format='%(levelname)s: %(message)s') if importer_class is None: # Discover all available model importers importers = {} for importer_entry in pkg_resources.iter_entry_points( 'psamm.importer'): canonical = importer_entry.name.lower() if canonical not in importers: importers[canonical] = importer_entry else: logger.warning('Importer {} was found more than once!'.format( importer_entry.name)) # Print list of importers if args.format in ('list', 'help'): if len(importers) == 0: logger.error('No importers found!') else: importer_classes = [] for name, entry in iteritems(importers): importer_class = entry.load() title = getattr(importer_class, 'title', None) generic = getattr(importer_class, 'generic', False) if title is not None: importer_classes.append( (title, generic, name, importer_class)) print('Generic importers:') for title, _, name, importer_class in sorted( c for c in importer_classes if c[1]): print('{:<12} {}'.format(name, title)) print() print('Model-specific importers:') for title, _, name, importer_class in sorted( c for c in importer_classes if not c[1]): print('{:<12} {}'.format(name, title)) sys.exit(0) importer_name = args.format.lower() if importer_name not in importers: logger.error('Importer {} not found!'.format(importer_name)) logger.info('Use "list" to see available importers.') sys.exit(-1) importer_class = importers[importer_name].load() importer = importer_class() try: model = importer.import_model(args.source) except ModelLoadError as e: logger.error('Failed to load model!', exc_info=True) importer.help() parser.error(text_type(e)) except ParseError as e: logger.error('Failed to parse model!', exc_info=True) logger.error(text_type(e)) sys.exit(-1) if args.merge_compounds: compounds_before = len(model.compounds) sbml.merge_equivalent_compounds(model) if len(model.compounds) < compounds_before: logger.info( 'Merged {} compound entries into {} entries by' ' removing duplicates in various compartments'.format( compounds_before, len(model.compounds))) print('Model: {}'.format(model.name)) print('- Biomass reaction: {}'.format(model.biomass_reaction)) print('- Compartments: {}'.format(len(model.compartments))) print('- Compounds: {}'.format(len(model.compounds))) print('- Reactions: {}'.format(len(model.reactions))) print('- Genes: {}'.format(count_genes(model))) # Check if dest directory is empty. If we get an error assume that the # directory does not exist. dest_is_empty = False try: dest_is_empty = len(os.listdir(args.dest)) == 0 except OSError: dest_is_empty = True if not dest_is_empty: if not args.force: logger.error('Destination directory is not empty. Use --force' ' option to proceed anyway, overwriting any existing' ' files in {}'.format(args.dest)) return 1 else: logger.warning('Destination directory is not empty, overwriting' ' existing files in {}'.format(args.dest)) # Create destination directory if not exists dest = args.dest mkdir_p(dest) convert_exchange = not args.no_exchange write_yaml_model(model, dest, convert_exchange=convert_exchange, split_subsystem=args.split_subsystem)
Entry point for import program. If the ``args`` are provided, these should be a list of strings that will be used instead of ``sys.argv[1:]``. This is mostly useful for testing.
def add_cmd_handler(self, cmd, func): """Adds a command handler for a command.""" len_args = len(inspect.getargspec(func)[0]) def add_meta(f): def decorator(*args, **kwargs): f(*args, **kwargs) decorator.bytes_needed = len_args - 1 # exclude self decorator.__name__ = f.__name__ return decorator func = add_meta(func) self._command_handlers[cmd] = func
Adds a command handler for a command.
def mapValues(self, f): """ Pass each value in the key-value pair RDD through a map function without changing the keys; this also retains the original RDD's partitioning. >>> x = sc.parallelize([("a", ["apple", "banana", "lemon"]), ("b", ["grapes"])]) >>> def f(x): return len(x) >>> x.mapValues(f).collect() [('a', 3), ('b', 1)] """ map_values_fn = lambda kv: (kv[0], f(kv[1])) return self.map(map_values_fn, preservesPartitioning=True)
Pass each value in the key-value pair RDD through a map function without changing the keys; this also retains the original RDD's partitioning. >>> x = sc.parallelize([("a", ["apple", "banana", "lemon"]), ("b", ["grapes"])]) >>> def f(x): return len(x) >>> x.mapValues(f).collect() [('a', 3), ('b', 1)]
def _make_register(self) -> BaseRegisterStore: """ Make the register storage. """ s = settings.REGISTER_STORE store_class = import_class(s['class']) return store_class(**s['params'])
Make the register storage.
def deserialize(self, value, attr=None, data=None, **kwargs): """Deserialize ``value``. :param value: The value to be deserialized. :param str attr: The attribute/key in `data` to be deserialized. :param dict data: The raw input data passed to the `Schema.load`. :param dict kwargs': Field-specific keyword arguments. :raise ValidationError: If an invalid value is passed or if a required value is missing. """ # Validate required fields, deserialize, then validate # deserialized value self._validate_missing(value) if value is missing_: _miss = self.missing return _miss() if callable(_miss) else _miss if getattr(self, 'allow_none', False) is True and value is None: return None output = self._deserialize(value, attr, data, **kwargs) self._validate(output) return output
Deserialize ``value``. :param value: The value to be deserialized. :param str attr: The attribute/key in `data` to be deserialized. :param dict data: The raw input data passed to the `Schema.load`. :param dict kwargs': Field-specific keyword arguments. :raise ValidationError: If an invalid value is passed or if a required value is missing.
def create_db_user(username, password=None, flags=None): """Create a databse user.""" flags = flags or u'-D -A -R' sudo(u'createuser %s %s' % (flags, username), user=u'postgres') if password: change_db_user_password(username, password)
Create a databse user.
def find_all(self, model_class, params={}): """Return an list of models from the API and caches the result. Args: model_class (:class:`cinder_data.model.CinderModel`): A subclass of :class:`cinder_data.model.CinderModel` of your chosen model. params (dict, optional): Description Returns: list: A list of instances of you model_class or and empty list. """ url = '{host}/{namespace}/{model}{params}'.format( host=self._host, namespace=self._namespace, model=self._translate_name(model_class.__name__), params=self._build_param_string(params) ) data = self._get_json(url)['data'] fresh_models = [] for item in data: fresh_model = model_class(item['attributes']) fresh_model.id = item['id'] fresh_model.validate() fresh_models.append(fresh_model) if self._cache is not None: self._cache.set_record(model_class.__name__, fresh_model.id, fresh_model) return fresh_models
Return an list of models from the API and caches the result. Args: model_class (:class:`cinder_data.model.CinderModel`): A subclass of :class:`cinder_data.model.CinderModel` of your chosen model. params (dict, optional): Description Returns: list: A list of instances of you model_class or and empty list.
def in_chain(cls, client, chain_id, expiration_dates=[]): """ fetch all option instruments in an options chain - expiration_dates = optionally scope """ request_url = "https://api.robinhood.com/options/instruments/" params = { "chain_id": chain_id, "expiration_dates": ",".join(expiration_dates) } data = client.get(request_url, params=params) results = data['results'] while data['next']: data = client.get(data['next']) results.extend(data['results']) return results
fetch all option instruments in an options chain - expiration_dates = optionally scope
def get_elements(html_file, tags): """ Extract all the elements we're interested in. Returns a list of tuples with the attribute as first item and the list of elements as the second item. """ with open(html_file) as f: document = BeautifulSoup(f, 'html.parser') def condition(tag, attr): # Don't include external links return lambda x: x.name == tag \ and not x.get(attr, 'http').startswith(('http', '//')) all_tags = [(attr, document.find_all(condition(tag, attr))) for tag, attr in tags] return all_tags
Extract all the elements we're interested in. Returns a list of tuples with the attribute as first item and the list of elements as the second item.
def infops(self, uuid): """ Get info per second about a kvm domain by uuid :param uuid: uuid of the kvm container (same as the used in create) :return: """ args = { 'uuid': uuid, } self._domain_action_chk.check(args) return self._client.json('kvm.infops', args)
Get info per second about a kvm domain by uuid :param uuid: uuid of the kvm container (same as the used in create) :return:
def add_plot(self, *args, extension='pdf', **kwargs): """Add the current Matplotlib plot to the figure. The plot that gets added is the one that would normally be shown when using ``plt.show()``. Args ---- args: Arguments passed to plt.savefig for displaying the plot. extension : str extension of image file indicating figure file type kwargs: Keyword arguments passed to plt.savefig for displaying the plot. In case these contain ``width`` or ``placement``, they will be used for the same purpose as in the add_image command. Namely the width and placement of the generated plot in the LaTeX document. """ add_image_kwargs = {} for key in ('width', 'placement'): if key in kwargs: add_image_kwargs[key] = kwargs.pop(key) filename = self._save_plot(*args, extension=extension, **kwargs) self.add_image(filename, **add_image_kwargs)
Add the current Matplotlib plot to the figure. The plot that gets added is the one that would normally be shown when using ``plt.show()``. Args ---- args: Arguments passed to plt.savefig for displaying the plot. extension : str extension of image file indicating figure file type kwargs: Keyword arguments passed to plt.savefig for displaying the plot. In case these contain ``width`` or ``placement``, they will be used for the same purpose as in the add_image command. Namely the width and placement of the generated plot in the LaTeX document.
def cancelMktDepth(self, contract: Contract, isSmartDepth=False): """ Unsubscribe from market depth data. Args: contract: The exact contract object that was used to subscribe with. """ ticker = self.ticker(contract) reqId = self.wrapper.endTicker(ticker, 'mktDepth') if reqId: self.client.cancelMktDepth(reqId, isSmartDepth) else: self._logger.error( f'cancelMktDepth: No reqId found for contract {contract}')
Unsubscribe from market depth data. Args: contract: The exact contract object that was used to subscribe with.
def flightmode_menu(): '''construct flightmode menu''' modes = mestate.mlog.flightmode_list() ret = [] idx = 0 for (mode,t1,t2) in modes: modestr = "%s %us" % (mode, (t2-t1)) ret.append(MPMenuCheckbox(modestr, modestr, 'mode-%u' % idx)) idx += 1 mestate.flightmode_selections.append(False) return ret
construct flightmode menu
def _convert_many_to_one(self, col_name, label, description, lst_validators, filter_rel_fields, form_props): """ Creates a WTForm field for many to one related fields, will use a Select box based on a query. Will only work with SQLAlchemy interface. """ query_func = self._get_related_query_func(col_name, filter_rel_fields) get_pk_func = self._get_related_pk_func(col_name) extra_classes = None allow_blank = True if not self.datamodel.is_nullable(col_name): lst_validators.append(validators.DataRequired()) allow_blank = False else: lst_validators.append(validators.Optional()) form_props[col_name] = \ QuerySelectField(label, description=description, query_func=query_func, get_pk_func=get_pk_func, allow_blank=allow_blank, validators=lst_validators, widget=Select2Widget(extra_classes=extra_classes)) return form_props
Creates a WTForm field for many to one related fields, will use a Select box based on a query. Will only work with SQLAlchemy interface.
def create_plan(self, posted_plan, project): """CreatePlan. Add a new plan for the team :param :class:`<CreatePlan> <azure.devops.v5_0.work.models.CreatePlan>` posted_plan: Plan definition :param str project: Project ID or project name :rtype: :class:`<Plan> <azure.devops.v5_0.work.models.Plan>` """ route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') content = self._serialize.body(posted_plan, 'CreatePlan') response = self._send(http_method='POST', location_id='0b42cb47-cd73-4810-ac90-19c9ba147453', version='5.0', route_values=route_values, content=content) return self._deserialize('Plan', response)
CreatePlan. Add a new plan for the team :param :class:`<CreatePlan> <azure.devops.v5_0.work.models.CreatePlan>` posted_plan: Plan definition :param str project: Project ID or project name :rtype: :class:`<Plan> <azure.devops.v5_0.work.models.Plan>`
def chaincode_query(self, chaincode_name, type=CHAINCODE_LANG_GO, function="query", args=["a"], id=1, secure_context=None, confidentiality_level=CHAINCODE_CONFIDENTIAL_PUB, metadata=None): """ { "jsonrpc": "2.0", "method": "query", "params": { "type": 1, "chaincodeID":{ "name":"52b0d803fc395b5e34d8d4a7cd69fb6aa00099b8fabed83504ac1c5d61a425aca5b3ad3bf96643ea4fdaac132c417c37b00f88fa800de7ece387d008a76d3586" }, "ctorMsg": { "function":"query", "args":["a"] } }, "id": 3 } :return: json obj of the chaincode instance """ return self._exec_action(method="query", type=type, chaincodeID={"name": chaincode_name}, function=function, args=args, id=id, secure_context=secure_context, confidentiality_level=confidentiality_level, metadata=metadata)
{ "jsonrpc": "2.0", "method": "query", "params": { "type": 1, "chaincodeID":{ "name":"52b0d803fc395b5e34d8d4a7cd69fb6aa00099b8fabed83504ac1c5d61a425aca5b3ad3bf96643ea4fdaac132c417c37b00f88fa800de7ece387d008a76d3586" }, "ctorMsg": { "function":"query", "args":["a"] } }, "id": 3 } :return: json obj of the chaincode instance
def hide_routemap_holder_route_map_content_set_ipv6_next_vrf_next_vrf_list_next_hop(self, **kwargs): """Auto Generated Code """ config = ET.Element("config") hide_routemap_holder = ET.SubElement(config, "hide-routemap-holder", xmlns="urn:brocade.com:mgmt:brocade-ip-policy") route_map = ET.SubElement(hide_routemap_holder, "route-map") name_key = ET.SubElement(route_map, "name") name_key.text = kwargs.pop('name') action_rm_key = ET.SubElement(route_map, "action-rm") action_rm_key.text = kwargs.pop('action_rm') instance_key = ET.SubElement(route_map, "instance") instance_key.text = kwargs.pop('instance') content = ET.SubElement(route_map, "content") set = ET.SubElement(content, "set") ipv6 = ET.SubElement(set, "ipv6") next_vrf = ET.SubElement(ipv6, "next-vrf") next_vrf_list = ET.SubElement(next_vrf, "next-vrf-list") vrf_key = ET.SubElement(next_vrf_list, "vrf") vrf_key.text = kwargs.pop('vrf') next_hop = ET.SubElement(next_vrf_list, "next-hop") next_hop.text = kwargs.pop('next_hop') callback = kwargs.pop('callback', self._callback) return callback(config)
Auto Generated Code
def supported_currencies(self, project='moneywagon', level="full"): """ Returns a list of all currencies that are supported by the passed in project. and support level. Support level can be: "block", "transaction", "address" or "full". """ ret = [] if project == 'multiexplorer-wallet': for currency, data in self.sorted_crypto_data: if not data.get("bip44_coin_type"): continue if len(data.get('services', {}).get("push_tx", [])) < 1: continue if len(data.get('services', {}).get("historical_transactions", [])) < 1: continue if len(data.get('services', {}).get("single_transaction", [])) < 1: continue if len(data.get('services', {}).get("unspent_outputs", [])) < 1: continue ret.append(currency) altcore_tx = self.supported_currencies('altcore', level="transaction") return [x for x in ret if x in altcore_tx] for symbol, data in self.sorted_crypto_data: if symbol == '': # template continue if self.is_all_supported(data, project, level): ret.append(symbol) return ret
Returns a list of all currencies that are supported by the passed in project. and support level. Support level can be: "block", "transaction", "address" or "full".
def get_referenced_user(self): """ :rtype: BunqModel """ if self._user_person is not None: return self._user_person if self._user_company is not None: return self._user_company if self._user_api_key is not None: return self._user_api_key raise BunqException(self._ERROR_ALL_FIELD_IS_NULL)
:rtype: BunqModel
def get_hash(self, length=HASH_LENGTH): """ Generate and return a hash of data that can be used as suffix of logicalId :return: Hash of data if it was present :rtype string """ data_hash = "" if not self.data_str: return data_hash encoded_data_str = self.data_str if sys.version_info.major == 2: # In Py2, only unicode needs to be encoded. if isinstance(self.data_str, unicode): encoded_data_str = self.data_str.encode('utf-8') else: # data_str should always be unicode on python 3 encoded_data_str = self.data_str.encode('utf-8') data_hash = hashlib.sha1(encoded_data_str).hexdigest() return data_hash[:length]
Generate and return a hash of data that can be used as suffix of logicalId :return: Hash of data if it was present :rtype string
def send_respawn(self): """ Respawns the player. """ nick = self.player.nick self.send_struct('<B%iH' % len(nick), 0, *map(ord, nick))
Respawns the player.
def build_sdist(sdist_directory, config_settings=None): """Builds an sdist, places it in sdist_directory""" poetry = Poetry.create(".") path = SdistBuilder(poetry, SystemEnv(Path(sys.prefix)), NullIO()).build( Path(sdist_directory) ) return unicode(path.name)
Builds an sdist, places it in sdist_directory
def meanvR(self,R,t=0.,nsigma=None,deg=False,phi=0., epsrel=1.e-02,epsabs=1.e-05, grid=None,gridpoints=101,returnGrid=False, surfacemass=None, hierarchgrid=False,nlevels=2,integrate_method='dopr54_c'): """ NAME: meanvR PURPOSE: calculate the mean vR of the velocity distribution at (R,phi) INPUT: R - radius at which to calculate the moment(/ro) (can be Quantity) phi= azimuth (rad unless deg=True; can be Quantity) t= time at which to evaluate the DF (can be a list or ndarray; if this is the case, list needs to be in descending order and equally spaced) (can be Quantity) surfacemass= if set use this pre-calculated surfacemass nsigma - number of sigma to integrate the velocities over (based on an estimate, so be generous) deg= azimuth is in degree (default=False); do not set this when giving phi as a Quantity epsrel, epsabs - scipy.integrate keywords (the integration calculates the ratio of this vmoment to that of the initial DF) grid= if set to True, build a grid and use that to evaluate integrals; if set to a grid-objects (such as returned by this procedure), use this grid gridpoints= number of points to use for the grid in 1D (default=101) returnGrid= if True, return the grid object (default=False) hierarchgrid= if True, use a hierarchical grid (default=False) nlevels= number of hierarchical levels for the hierarchical grid integrate_method= orbit.integrate method argument OUTPUT: mean vR HISTORY: 2011-03-31 - Written - Bovy (NYU) """ if isinstance(grid,evolveddiskdfGrid) or \ isinstance(grid,evolveddiskdfHierarchicalGrid): grido= grid vmomentR= self.vmomentsurfacemass(R,1,0,deg=deg,t=t,phi=phi, nsigma=nsigma, epsrel=epsrel, epsabs=epsabs,grid=grid, gridpoints=gridpoints, returnGrid=False, hierarchgrid=hierarchgrid, nlevels=nlevels, integrate_method=integrate_method) elif isinstance(grid,bool) and grid: #Precalculate the grid (vmomentR,grido)= self.vmomentsurfacemass(R,1,0,deg=deg,t=t, nsigma=nsigma,phi=phi, epsrel=epsrel, epsabs=epsabs,grid=grid, gridpoints=gridpoints, returnGrid=True, hierarchgrid=hierarchgrid, nlevels=nlevels, integrate_method=integrate_method) else: grido= False vmomentR= self.vmomentsurfacemass(R,1,0,deg=deg,t=t,phi=phi, nsigma=nsigma, epsrel=epsrel, epsabs=epsabs,grid=grid, gridpoints=gridpoints, returnGrid=False, hierarchgrid=hierarchgrid, nlevels=nlevels,integrate_method=integrate_method) if surfacemass is None: surfacemass= self.vmomentsurfacemass(R,0,0,deg=deg,t=t,phi=phi, nsigma=nsigma,epsrel=epsrel, epsabs=epsabs,grid=grido, gridpoints=gridpoints, returnGrid=False, hierarchgrid=hierarchgrid, nlevels=nlevels,integrate_method=integrate_method) out= vmomentR/surfacemass if returnGrid and ((isinstance(grid,bool) and grid) or isinstance(grid,evolveddiskdfGrid) or isinstance(grid,evolveddiskdfHierarchicalGrid)): return (out,grido) else: return out
NAME: meanvR PURPOSE: calculate the mean vR of the velocity distribution at (R,phi) INPUT: R - radius at which to calculate the moment(/ro) (can be Quantity) phi= azimuth (rad unless deg=True; can be Quantity) t= time at which to evaluate the DF (can be a list or ndarray; if this is the case, list needs to be in descending order and equally spaced) (can be Quantity) surfacemass= if set use this pre-calculated surfacemass nsigma - number of sigma to integrate the velocities over (based on an estimate, so be generous) deg= azimuth is in degree (default=False); do not set this when giving phi as a Quantity epsrel, epsabs - scipy.integrate keywords (the integration calculates the ratio of this vmoment to that of the initial DF) grid= if set to True, build a grid and use that to evaluate integrals; if set to a grid-objects (such as returned by this procedure), use this grid gridpoints= number of points to use for the grid in 1D (default=101) returnGrid= if True, return the grid object (default=False) hierarchgrid= if True, use a hierarchical grid (default=False) nlevels= number of hierarchical levels for the hierarchical grid integrate_method= orbit.integrate method argument OUTPUT: mean vR HISTORY: 2011-03-31 - Written - Bovy (NYU)