code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def from_url(url, db=None, **kwargs):
from redis.client import Redis
return Redis.from_url(url, db, **kwargs) | Returns an active Redis client generated from the given database URL.
Will attempt to extract the database id from the path url fragment, if
none is provided. |
def addParts(parentPart, childPath, count, index):
if index == None:
index = 0
if index == len(childPath):
return
c = childPath[index]
parentPart.count = coalesce(parentPart.count, 0) + count
if parentPart.partitions == None:
parentPart.partitions = FlatList()
for i, part... | BUILD A hierarchy BY REPEATEDLY CALLING self METHOD WITH VARIOUS childPaths
count IS THE NUMBER FOUND FOR self PATH |
def SADWindowSize(self, value):
if value >= 1 and value <= 11 and value % 2:
self._sad_window_size = value
else:
raise InvalidSADWindowSizeError("SADWindowSize must be odd and "
"between 1 and 11.")
self._replace_bm() | Set private ``_sad_window_size`` and reset ``_block_matcher``. |
def target_to_source(target_adjacency, embedding):
source_adjacency = {v: set() for v in embedding}
reverse_embedding = {}
for v, chain in iteritems(embedding):
for u in chain:
if u in reverse_embedding:
raise ValueError("target node {} assigned to more than one source no... | Derive the source adjacency from an embedding and target adjacency.
Args:
target_adjacency (dict/:class:`networkx.Graph`):
A dict of the form {v: Nv, ...} where v is a node in the target graph and Nv is the
neighbors of v as an iterable. This can also be a networkx graph.
e... |
def setup(self, ds):
self._find_coord_vars(ds)
self._find_aux_coord_vars(ds)
self._find_ancillary_vars(ds)
self._find_clim_vars(ds)
self._find_boundary_vars(ds)
self._find_metadata_vars(ds)
self._find_cf_standard_name_table(ds)
self._find_geophysical_vars(... | Initialize various special variable types within the class.
Mutates a number of instance variables.
:param netCDF4.Dataset ds: An open netCDF dataset |
def as_hyperbola(self, rotated=False):
idx = N.diag_indices(3)
_ = 1/self.covariance_matrix[idx]
d = list(_)
d[-1] *= -1
arr = N.identity(4)*-1
arr[idx] = d
hyp = conic(arr)
if rotated:
R = augment(self.axes)
hyp = hyp.transform(R)
... | Hyperbolic error area |
def attribute_read(self, sender, name):
"Handles the creation of ExpectationBuilder when an attribute is read."
return ExpectationBuilder(self.sender, self.delegate, self.add_invocation, self.add_expectations, name) | Handles the creation of ExpectationBuilder when an attribute is read. |
def destroy(self, force=False):
if force:
super(UnmanagedLXC, self).destroy()
else:
raise UnmanagedLXCError('Destroying an unmanaged LXC might not '
'work. To continue please call this method with force=True') | UnmanagedLXC Destructor.
It requires force to be true in order to work. Otherwise it throws an
error. |
def worker_workerfinished(self, node):
self.config.hook.pytest_testnodedown(node=node, error=None)
if node.workeroutput["exitstatus"] == 2:
self.shouldstop = "%s received keyboard-interrupt" % (node,)
self.worker_errordown(node, "keyboard-interrupt")
return
if... | Emitted when node executes its pytest_sessionfinish hook.
Removes the node from the scheduler.
The node might not be in the scheduler if it had not emitted
workerready before shutdown was triggered. |
def inherit_dict(base, namespace, attr_name,
inherit=lambda k, v: True):
items = []
base_dict = getattr(base, attr_name, {})
new_dict = namespace.setdefault(attr_name, {})
for key, value in base_dict.items():
if key in new_dict or (inherit and not inherit... | Perform inheritance of dictionaries. Returns a list of key
and value pairs for values that were inherited, for
post-processing.
:param base: The base class being considered; see
``iter_bases()``.
:param namespace: The dictionary of the new class being built.
... |
def write_str(self, s):
self.write(s)
self.room -= len(s) | Add string s to the accumulated body. |
def lambda_not_found_response(*args):
response_data = jsonify(ServiceErrorResponses._NO_LAMBDA_INTEGRATION)
return make_response(response_data, ServiceErrorResponses.HTTP_STATUS_CODE_502) | Constructs a Flask Response for when a Lambda function is not found for an endpoint
:return: a Flask Response |
def process_data(name=None):
ct = current_process()
if not hasattr(ct, '_pulsar_local'):
ct._pulsar_local = {}
loc = ct._pulsar_local
return loc.get(name) if name else loc | Fetch the current process local data dictionary.
If ``name`` is not ``None`` it returns the value at``name``,
otherwise it return the process data dictionary |
def hijack_require_http_methods(fn):
required_methods = ['POST']
if hijack_settings.HIJACK_ALLOW_GET_REQUESTS:
required_methods.append('GET')
return require_http_methods(required_methods)(fn) | Wrapper for "require_http_methods" decorator. POST required by default, GET can optionally be allowed |
def do_minus(self, parser, group):
grouper = group.__class__()
next_not = None
for node in group:
if isinstance(node, self.Minus):
if next_not is not None:
continue
next_not = whoosh.qparser.syntax.NotGroup()
grouper... | This filter sorts nodes in a flat group into "required", "default",
and "banned" subgroups based on the presence of plus and minus nodes. |
def to_kaf(self):
if self.type == 'NAF':
for node in self.__get_opinion_nodes():
node.set('oid',node.get('id'))
del node.attrib['id'] | Converts the opinion layer to KAF |
def get_cell(self, row, column):
url = self.build_url(self._endpoints.get('get_cell').format(row=row, column=column))
response = self.session.get(url)
if not response:
return None
return self.range_constructor(parent=self, **{self._cloud_data_key: response.json()}) | Gets the range object containing the single cell based on row and column numbers. |
def set_float_param(params, name, value, min=None, max=None):
if value is None:
return
try:
value = float(str(value))
except:
raise ValueError(
"Parameter '%s' must be numeric (or a numeric string) or None,"
" got %r." % (name, value))
if min is not None a... | Set a float parameter if applicable.
:param dict params: A dict containing API call parameters.
:param str name: The name of the parameter to set.
:param float value:
The value of the parameter. If ``None``, the field will not be set. If
an instance of a numeric type or a string that can ... |
def add_plot(self, *args, extension='pdf', **kwargs):
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 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... |
def update_offer(self, offer_id, offer_dict):
return self._create_put_request(resource=OFFERS, billomat_id=offer_id, send_data=offer_dict) | Updates an offer
:param offer_id: the offer id
:param offer_dict: dict
:return: dict |
def rvon_mises(mu, kappa, size=None):
return (np.random.mtrand.vonmises(
mu, kappa, size) + np.pi) % (2. * np.pi) - np.pi | Random von Mises variates. |
def get_all_reminders(self, params=None):
if not params:
params = {}
return self._iterate_through_pages(self.get_reminders_per_page, resource=REMINDERS, **{'params': params}) | Get all reminders
This will iterate over all pages until it gets all elements.
So if the rate limit exceeded it will throw an Exception and you will get nothing
:param params: search params
:return: list |
def memory():
memory_oper = ['read', 'write']
memory_scope = ['local', 'global']
test_command = 'sysbench --num-threads=64 --test=memory '
test_command += '--memory-oper={0} --memory-scope={1} '
test_command += '--memory-block-size=1K --memory-total-size=32G run '
result = None
ret_val = {}
... | This tests the memory for read and write operations.
CLI Examples:
.. code-block:: bash
salt '*' sysbench.memory |
def eth_getBlockByNumber(self, number):
block_hash = self.reader._get_block_hash(number)
block_number = _format_block_number(number)
body_key = body_prefix + block_number + block_hash
block_data = self.db.get(body_key)
body = rlp.decode(block_data, sedes=Block)
return bod... | Get block body by block number.
:param number:
:return: |
def memory_usage(self, index=True, deep=False):
result = Series([c.memory_usage(index=False, deep=deep)
for col, c in self.iteritems()], index=self.columns)
if index:
result = Series(self.index.memory_usage(deep=deep),
index=['Index']).app... | Return the memory usage of each column in bytes.
The memory usage can optionally include the contribution of
the index and elements of `object` dtype.
This value is displayed in `DataFrame.info` by default. This can be
suppressed by setting ``pandas.options.display.memory_usage`` to Fa... |
def _check_user_parameters(self, user_parameters):
if not user_parameters:
return
for key in user_parameters:
if key not in submission_defaults:
raise ValueError("Unknown parameter {0}".format(key)) | Verifies that the parameter dict given by the user only contains
known keys. This ensures that the user detects typos faster. |
def create_saml_provider(name, saml_metadata_document, region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.create_saml_provider(saml_metadata_document, name)
log.info('Successfully created %s SAML provider.', name)
... | Create SAML provider
CLI Example:
.. code-block:: bash
salt myminion boto_iam.create_saml_provider my_saml_provider_name saml_metadata_document |
def get_metadata(self):
try:
metadata = get_build_json()["metadata"]
self.build_id = metadata["name"]
except KeyError:
self.log.error("No build metadata")
raise
for image in self.workflow.tag_conf.unique_images:
self.pullspec_image = im... | Build the metadata needed for importing the build
:return: tuple, the metadata and the list of Output instances |
def tags(self, tags=None):
if tags is None or not tags:
return self
nodes = []
for node in self.nodes:
if any(tag in node.extra['tags'] for tag in tags):
nodes.append(node)
self.nodes = nodes
return self | Filter by tags.
:param tags: Tags to filter.
:type tags: ``list``
:return: A list of Node objects.
:rtype: ``list`` of :class:`Node` |
def _init_imu(self):
if not self._imu_init:
self._imu_init = self._imu.IMUInit()
if self._imu_init:
self._imu_poll_interval = self._imu.IMUGetPollInterval() * 0.001
self.set_imu_config(True, True, True)
else:
raise OSError('IMU ... | Internal. Initialises the IMU sensor via RTIMU |
def ipv4(value, allow_empty = False):
if not value and allow_empty is False:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
try:
components = value.split('.')
except AttributeError:
raise errors.InvalidIPAddressError('value (%s) i... | Validate that ``value`` is a valid IP version 4 address.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if ``value`` i... |
def setorigin(self):
try:
origin = self.repo.remotes.origin
if origin.url != self.origin_url:
log.debug('[%s] Changing origin url. Old: %s New: %s',
self.name, origin.url, self.origin_url)
origin.config_writer.set('url', self.orig... | Set the 'origin' remote to the upstream url that we trust. |
def length_prepend(byte_string):
length = tx.VarInt(len(byte_string))
return length.to_bytes() + byte_string | bytes -> bytes |
def delayed_assattr(self, node):
try:
frame = node.frame()
for inferred in node.expr.infer():
if inferred is util.Uninferable:
continue
try:
if inferred.__class__ is bases.Instance:
inferred =... | Visit a AssAttr node
This adds name to locals and handle members definition. |
def show(self, visible=True, run=False):
self._backend._vispy_set_visible(visible)
if run:
self.app.run() | Show or hide the canvas
Parameters
----------
visible : bool
Make the canvas visible.
run : bool
Run the backend event loop. |
def replace_meta(self, name, content=None, meta_key=None):
children = self.meta._children
if not content:
children = tuple(children)
meta_key = meta_key or 'name'
for child in children:
if child.attr(meta_key) == name:
if content:
... | Replace the ``content`` attribute of meta tag ``name``
If the meta with ``name`` is not available, it is added, otherwise
its content is replaced. If ``content`` is not given or it is empty
the meta tag with ``name`` is removed. |
def add_bookmark(self, name, time, chan=''):
try:
bookmarks = self.rater.find('bookmarks')
except AttributeError:
raise IndexError('You need to have at least one rater')
new_bookmark = SubElement(bookmarks, 'bookmark')
bookmark_name = SubElement(new_bookmark, 'boo... | Add a new bookmark
Parameters
----------
name : str
name of the bookmark
time : (float, float)
float with start and end time in s
Raises
------
IndexError
When there is no selected rater |
def requestAvatarId(self, credentials):
username, domain = credentials.username.split("@")
key = self.users.key(domain, username)
if key is None:
return defer.fail(UnauthorizedLogin())
def _cbPasswordChecked(passwordIsCorrect):
if passwordIsCorrect:
... | Return the ID associated with these credentials.
@param credentials: something which implements one of the interfaces in
self.credentialInterfaces.
@return: a Deferred which will fire a string which identifies an
avatar, an empty tuple to specify an authenticated anonymous user
... |
def save(self, fname=''):
if fname != '':
with open(fname, 'w') as f:
for i in self.lstPrograms:
f.write(self.get_file_info_line(i, ','))
filemap = mod_filemap.FileMap([], [])
object_fileList = filemap.get_full_filename(filemap.find_type('OBJECT'),... | Save the list of items to AIKIF core and optionally to local file fname |
def compile_with_symbol(self, func, theano_args=None, owner=None):
if theano_args is None:
theano_args = []
upc = UpdateCollector()
theano_ret = func(*theano_args) if owner is None \
else func(owner, *theano_args)
out = copy.copy(self.default_options)
out[... | Compile the function with theano symbols |
def _serialize(self, value, attr, obj):
try:
return super(DateString, self)._serialize(
arrow.get(value).date(), attr, obj)
except ParserError:
return missing | Serialize an ISO8601-formatted date. |
def get_authorizations_on_date(self, from_, to):
authorization_list = []
for authorization in self.get_authorizations():
if overlap(from_, to, authorization.start_date, authorization.end_date):
authorization_list.append(authorization)
return objects.AuthorizationList(... | Gets an ``AuthorizationList`` effective during the entire given date range inclusive but not confined to the date range.
arg: from (osid.calendaring.DateTime): starting date
arg: to (osid.calendaring.DateTime): ending date
return: (osid.authorization.AuthorizationList) - the returned
... |
def read_message_type(file):
message_byte = file.read(1)
if message_byte == b'':
return ConnectionClosed
message_number = message_byte[0]
return _message_types.get(message_number, UnknownMessage) | Read the message type from a file. |
def ccifrm(frclss, clssid, lenout=_default_len_out):
frclss = ctypes.c_int(frclss)
clssid = ctypes.c_int(clssid)
lenout = ctypes.c_int(lenout)
frcode = ctypes.c_int()
frname = stypes.stringToCharP(lenout)
center = ctypes.c_int()
found = ctypes.c_int()
libspice.ccifrm_c(frclss, clssid, le... | Return the frame name, frame ID, and center associated with
a given frame class and class ID.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ccifrm_c.html
:param frclss: Class of frame.
:type frclss: int
:param clssid: Class ID of frame.
:type clssid: int
:param lenout: Maximum le... |
def get_fields(config):
for data in config['scraping']['data']:
if data['field'] != '':
yield data['field']
if 'next' in config['scraping']:
for n in config['scraping']['next']:
for f in get_fields(n):
yield f | Recursive generator that yields the field names in the config file
:param config: The configuration file that contains the specification of the extractor
:return: The field names in the config file, through a generator |
def cluster_del_slots(self, slot, *slots):
slots = (slot,) + slots
if not all(isinstance(s, int) for s in slots):
raise TypeError("All parameters must be of type int")
fut = self.execute(b'CLUSTER', b'DELSLOTS', *slots)
return wait_ok(fut) | Set hash slots as unbound in receiving node. |
def _set_value(self, entity, value):
if entity._projection:
raise ReadonlyPropertyError(
'You cannot set property values of a projection entity')
if self._repeated:
if not isinstance(value, (list, tuple, set, frozenset)):
raise datastore_errors.BadValueError('Expected list or tuple... | Internal helper to set a value in an entity for a Property.
This performs validation first. For a repeated Property the value
should be a list. |
def closed_by(self, **kwargs):
path = '%s/%s/closed_by' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs) | List merge requests that will close the issue when merged.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetErrot: If the merge requests could not be retrieved
Retur... |
def get_zone_variable(self, zone_id, variable):
try:
return self._retrieve_cached_zone_variable(zone_id, variable)
except UncachedVariable:
return (yield from self._send_cmd("GET %s.%s" % (
zone_id.device_str(), variable))) | Retrieve the current value of a zone variable. If the variable is
not found in the local cache then the value is requested from the
controller. |
def socket_recv(self):
try:
data = self.sock.recv(2048)
except socket.error, ex:
print ("?? socket.recv() error '%d:%s' from %s" %
(ex[0], ex[1], self.addrport()))
raise BogConnectionLost()
size = len(data)
if size == 0:
rai... | Called by TelnetServer when recv data is ready. |
def _load_themes(self):
with utils.temporary_chdir(utils.get_file_directory()):
self._append_theme_dir("themes")
self.tk.eval("source themes/pkgIndex.tcl")
theme_dir = "gif" if not self.png_support else "png"
self._append_theme_dir(theme_dir)
self.tk.e... | Load the themes into the Tkinter interpreter |
def createBamHeader(self, baseHeader):
header = dict(baseHeader)
newSequences = []
for index, referenceInfo in enumerate(header['SQ']):
if index < self.numChromosomes:
referenceName = referenceInfo['SN']
assert referenceName == self.chromosomes[index]
... | Creates a new bam header based on the specified header from the
parent BAM file. |
def ceil_nearest(x, dx=1):
precision = get_sig_digits(dx)
return round(math.ceil(float(x) / dx) * dx, precision) | ceil a number to within a given rounding accuracy |
def set_title(self, msg):
self.s.move(0, 0)
self.overwrite_line(msg, curses.A_REVERSE) | Set first header line text |
def readfmt(stream, fmt):
size = struct.calcsize(fmt)
blob = stream.read(size)
return struct.unpack(fmt, blob) | Read and unpack an object from stream, using a struct format string. |
def lock_up_period(self, lock_up_period):
try:
if isinstance(lock_up_period, (str, int)):
self._lock_up_period = int(lock_up_period)
except Exception:
raise ValueError('invalid input of lock up period %s, cannot be converted to an int' %
... | This lockup period is in months. This might change to a relative delta. |
def set_timezone(rollback=False):
if not rollback:
if contains(filename='/etc/timezone', text=env.TIME_ZONE, use_sudo=True):
return False
if env.verbosity:
print env.host, "CHANGING TIMEZONE /etc/timezone to "+env.TIME_ZONE
_backup_file('/etc/timezone')
sudo('... | Set the time zone on the server using Django settings.TIME_ZONE |
def EncryptPrivateKey(self, decrypted):
aes = AES.new(self._master_key, AES.MODE_CBC, self._iv)
return aes.encrypt(decrypted) | Encrypt the provided plaintext with the initialized private key.
Args:
decrypted (byte string): the plaintext to be encrypted.
Returns:
bytes: the ciphertext. |
def save_srm(self, filename):
with open(filename, 'wb') as fp:
raw_data = bread.write(self._song_data, spec.song)
fp.write(raw_data) | Save a project in .srm format to the target file.
:param filename: the name of the file to which to save |
def reload(self):
text = self._read(self.location)
cursor_position = min(self.buffer.cursor_position, len(text))
self.buffer.document = Document(text, cursor_position)
self._file_content = text | Reload file again from storage. |
def create_customer(self, *, full_name, email):
payload = {
"fullName": full_name,
"email": email
}
return self.client._post(self.url + 'customers', json=payload, headers=self.get_headers()) | Creation of a customer in the system.
Args:
full_name: Customer's complete name.
Alphanumeric. Max: 255.
email: Customer's email address.
Alphanumeric. Max: 255.
Returns: |
def execute_process_async(func, *args, **kwargs):
global _GIPC_EXECUTOR
if _GIPC_EXECUTOR is None:
_GIPC_EXECUTOR = GIPCExecutor(
num_procs=settings.node.gipc_pool_size,
num_greenlets=settings.node.greenlet_pool_size)
return _GIPC_EXECUTOR.submit(func, *args, **kwargs) | Executes `func` in a separate process. Memory and other resources are not
available. This gives true concurrency at the cost of losing access to
these resources. `args` and `kwargs` are |
def get_tunnels(self):
method = 'GET'
endpoint = '/rest/v1/{}/tunnels'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | Retrieves all running tunnels for a specific user. |
def move_right(self):
self.at(ardrone.at.pcmd, True, self.speed, 0, 0, 0) | Make the drone move right. |
def salt_ssh():
import salt.cli.ssh
if '' in sys.path:
sys.path.remove('')
try:
client = salt.cli.ssh.SaltSSH()
_install_signal_handlers(client)
client.run()
except SaltClientError as err:
trace = traceback.format_exc()
try:
hardcrash = client.... | Execute the salt-ssh system |
def get_xpub(xpub, filter=None, limit=None, offset=None, api_code=None):
resource = 'multiaddr?active=' + xpub
if filter is not None:
if isinstance(filter, FilterType):
resource += '&filter=' + str(filter.value)
else:
raise ValueError('Filter must be of FilterType enum')
... | Get data for a single xpub including balance and list of relevant transactions.
:param str xpub: address(xpub) to look up
:param FilterType filter: the filter for transactions selection (optional)
:param int limit: limit number of transactions to fetch (optional)
:param int offset: number of transactio... |
def on_btn_delete_fit(self, event):
self.delete_fit(self.current_fit, specimen=self.s) | removes the current interpretation
Parameters
----------
event : the wx.ButtonEvent that triggered this function |
def edit(self, request, id):
with pushd(tempfile.gettempdir()):
try:
self.clone(id)
with pushd(id):
files = [f for f in os.listdir('.') if os.path.isfile(f)]
quoted = ['"{}"'.format(f) for f in files]
os.syst... | Edit a gist
The files in the gist a cloned to a temporary directory and passed to
the default editor (defined by the EDITOR environmental variable). When
the user exits the editor, they will be provided with a prompt to
commit the changes, which will then be pushed to the remote.
... |
def _show_input_processor_key_buffer(self, cli, new_screen):
key_buffer = cli.input_processor.key_buffer
if key_buffer and _in_insert_mode(cli) and not cli.is_done:
data = key_buffer[-1].data
if get_cwidth(data) == 1:
cpos = new_screen.cursor_position
... | When the user is typing a key binding that consists of several keys,
display the last pressed key if the user is in insert mode and the key
is meaningful to be displayed.
E.g. Some people want to bind 'jj' to escape in Vi insert mode. But the
first 'j' needs to be displayed in order... |
def get_restricted_sites(self, request):
try:
return request.user.get_sites()
except AttributeError:
return Site.objects.none() | The sites on which the user has permission on.
To return the permissions, the method check for the ``get_sites``
method on the user instance (e.g.: ``return request.user.get_sites()``)
which must return the queryset of enabled sites.
If the attribute does not exists, the user is conside... |
async def async_connect(self):
kwargs = {
'username': self._username if self._username else None,
'client_keys': [self._ssh_key] if self._ssh_key else None,
'port': self._port,
'password': self._password if self._password else None,
'known_hosts': None... | Fetches the client or creates a new one. |
def _explore_storage(self):
path = ''
dirs = [path]
while dirs:
path = dirs.pop()
subdirs, files = self.media_storage.listdir(path)
for media_filename in files:
yield os.path.join(path, media_filename)
dirs.extend([os.path.join(path... | Generator of all files contained in media storage. |
def load_config(self, custom_config):
self.config = configparser.ConfigParser()
if custom_config:
self.config.read(custom_config)
return f'Loading config from file {custom_config}.'
home = os.path.expanduser('~{}'.format(getpass.getuser()))
home_conf_file = os.pat... | Attempt to load config from file.
If the command specified a --config parameter, then load that config file.
Otherwise, the user's home directory takes precedence over a system wide config.
Config file in the user's dir should be named ".cronyrc".
System wide config should be located at... |
def crop_box(endpoint=None, filename=None):
crop_size = current_app.config['AVATARS_CROP_BASE_WIDTH']
if endpoint is None or filename is None:
url = url_for('avatars.static', filename='default/default_l.jpg')
else:
url = url_for(endpoint, filename=filename)
return... | Create a crop box.
:param endpoint: The endpoint of view function that serve avatar image file.
:param filename: The filename of the image that need to be crop. |
def _config_params(base_config, assoc_files, region, out_file, items):
params = []
dbsnp = assoc_files.get("dbsnp")
if dbsnp:
params += ["--dbsnp", dbsnp]
cosmic = assoc_files.get("cosmic")
if cosmic:
params += ["--cosmic", cosmic]
variant_regions = bedutils.population_variant_re... | Add parameters based on configuration variables, associated files and genomic regions. |
def find_resistance(record):
for feature in record.features:
labels = set(feature.qualifiers.get("label", []))
cassettes = labels.intersection(_ANTIBIOTICS)
if len(cassettes) > 1:
raise RuntimeError("multiple resistance cassettes detected")
elif len(cassettes) == 1:
... | Infer the antibiotics resistance of the given record.
Arguments:
record (`~Bio.SeqRecord.SeqRecord`): an annotated sequence.
Raises:
RuntimeError: when there's not exactly one resistance cassette. |
def validate(self):
errors = []
app = errors.append
if not self.hint_cores >= self.mpi_procs * self.omp_threads >= self.min_cores:
app("self.hint_cores >= mpi_procs * omp_threads >= self.min_cores not satisfied")
if self.omp_threads > self.hw.cores_per_node:
app("... | Validate the parameters of the run. Raises self.Error if invalid parameters. |
def range_initialization(X, num_weights):
X_ = X.reshape(-1, X.shape[-1])
min_val, max_val = X_.min(0), X_.max(0)
data_range = max_val - min_val
return data_range * np.random.rand(num_weights,
X.shape[-1]) + min_val | Initialize the weights by calculating the range of the data.
The data range is calculated by reshaping the input matrix to a
2D matrix, and then taking the min and max values over the columns.
Parameters
----------
X : numpy array
The input data. The data range is calculated over the last ... |
def set_alpha_for_selection(self, alpha):
selection = self.treeview_layers.get_selection()
list_store, selected_iter = selection.get_selected()
if selected_iter is None:
return
else:
surface_name, original_alpha = list_store[selected_iter]
self.set_alp... | Set alpha for selected layer. |
def populate(self, **values):
values = values.copy()
fields = list(self.iterate_with_name())
for _, structure_name, field in fields:
if structure_name in values:
field.__set__(self, values.pop(structure_name))
for name, _, field in fields:
if name ... | Populate values to fields. Skip non-existing. |
def fit_cosine_function(wind):
wind_daily = wind.groupby(wind.index.date).mean()
wind_daily_hourly = pd.Series(index=wind.index, data=wind_daily.loc[wind.index.date].values)
df = pd.DataFrame(data=dict(daily=wind_daily_hourly, hourly=wind)).dropna(how='any')
x = np.array([df.daily, df.index.hour])
p... | fits a cosine function to observed hourly windspeed data
Args:
wind: observed hourly windspeed data
Returns:
parameters needed to generate diurnal features of windspeed using a cosine function |
def init(opts):
if CONFIG_BASE_URL in opts['proxy']:
CONFIG[CONFIG_BASE_URL] = opts['proxy'][CONFIG_BASE_URL]
else:
log.error('missing proxy property %s', CONFIG_BASE_URL)
log.debug('CONFIG: %s', CONFIG) | Perform any needed setup. |
async def start(self):
self._loop.add_task(self._periodic_loop, name="periodic task for %s" % self._adapter.__class__.__name__,
parent=self._task)
self._adapter.add_callback('on_scan', functools.partial(_on_scan, self._loop, self))
self._adapter.add_callback('on_repor... | Start the device adapter.
See :meth:`AbstractDeviceAdapter.start`. |
def group(self):
for group in self._server.groups:
if self.identifier in group.clients:
return group | Get group. |
def groupByNode(requestContext, seriesList, nodeNum, callback):
return groupByNodes(requestContext, seriesList, callback, nodeNum) | Takes a serieslist and maps a callback to subgroups within as defined by a
common node.
Example::
&target=groupByNode(ganglia.by-function.*.*.cpu.load5,2,"sumSeries")
Would return multiple series which are each the result of applying the
"sumSeries" function to groups joined on the second nod... |
def remove_sbi_id(self, sbi_id):
sbi_ids = self.sbi_ids
sbi_ids.remove(sbi_id)
DB.set_hash_value(self._key, 'sbi_ids', sbi_ids) | Remove an SBI Identifier. |
def cleanup(self):
keys = self.client.smembers(self.keys_container)
for key in keys:
entry = self.client.get(key)
if entry:
entry = pickle.loads(entry)
if self._is_expired(entry, self.timeout):
self.delete_entry(key) | Cleanup all the expired keys |
def print_verbose(self):
print "Nodes: "
for a in (self.nodes(failed="all")):
print a
print "\nVectors: "
for v in (self.vectors(failed="all")):
print v
print "\nInfos: "
for i in (self.infos(failed="all")):
print i
print "\nTra... | Print a verbose representation of a network. |
def union(self, another_moc, *args):
interval_set = self._interval_set.union(another_moc._interval_set)
for moc in args:
interval_set = interval_set.union(moc._interval_set)
return self.__class__(interval_set) | Union between the MOC instance and other MOCs.
Parameters
----------
another_moc : `~mocpy.moc.MOC`
The MOC used for performing the union with self.
args : `~mocpy.moc.MOC`
Other additional MOCs to perform the union with.
Returns
-------
... |
def tell(self):
self._check_open_file()
if self._flushes_after_tell():
self.flush()
if not self._append:
return self._io.tell()
if self._read_whence:
write_seek = self._io.tell()
self._io.seek(self._read_seek, self._read_whence)
... | Return the file's current position.
Returns:
int, file's current position in bytes. |
def has_bom(self, f):
content = f.read(4)
encoding = None
m = RE_UTF_BOM.match(content)
if m is not None:
if m.group(1):
encoding = 'utf-8-sig'
elif m.group(2):
encoding = 'utf-32'
elif m.group(3):
encodi... | Check for UTF8, UTF16, and UTF32 BOMs. |
def full_photos(self):
if self._photos is None:
if self.total_photo_count > 0:
self.assert_bind_client()
self._photos = self.bind_client.get_activity_photos(self.id, only_instagram=False)
else:
self._photos = []
return self._photos | Gets a list of photos using default options.
:class:`list` of :class:`stravalib.model.ActivityPhoto` objects for this activity. |
def _register_user_models(user_models, admin=None, schema=None):
if any([issubclass(cls, AutomapModel) for cls in user_models]):
AutomapModel.prepare(
db.engine, reflect=True, schema=schema)
for user_model in user_models:
register_model(user_model, admin) | Register any user-defined models with the API Service.
:param list user_models: A list of user-defined models to include in the
API service |
def pdf(self, mu):
if self.transform is not None:
mu = self.transform(mu)
return self.pdf_internal(mu, df=self.df0, loc=self.loc0, scale=self.scale0, gamma=self.gamma0) | PDF for Skew t prior
Parameters
----------
mu : float
Latent variable for which the prior is being formed over
Returns
----------
- p(mu) |
def get_entity(self,entity_id):
entity_node = self.map_entity_id_to_node.get(entity_id)
if entity_node is not None:
return Centity(node=entity_node,type=self.type)
else:
for entity_node in self.__get_entity_nodes():
if self.type == 'NAF':
... | Returns the entity object for the given entity identifier
@type entity_id: string
@param entity_id: the token identifier
@rtype: L{Centity}
@return: the entity object |
def software_language(instance):
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'software' and
'languages' in obj):
for lang in obj['languages']:
if lang not in enums.SOFTWARE_LANG_CODES:
yield JSONError("The ... | Ensure the 'language' property of software objects is a valid ISO 639-2
language code. |
def glyph_extents(self, glyphs):
glyphs = ffi.new('cairo_glyph_t[]', glyphs)
extents = ffi.new('cairo_text_extents_t *')
cairo.cairo_glyph_extents(
self._pointer, glyphs, len(glyphs), extents)
self._check_status()
return (
extents.x_bearing, extents.y_bear... | Returns the extents for a list of glyphs.
The extents describe a user-space rectangle
that encloses the "inked" portion of the glyphs,
(as it would be drawn by :meth:`show_glyphs`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` values
indicate the amount by which the c... |
def add_point_feature(self, resnum, feat_type=None, feat_id=None, qualifiers=None):
if self.feature_file:
raise ValueError('Feature file associated with sequence, please remove file association to append '
'additional features.')
if not feat_type:
fea... | Add a feature to the features list describing a single residue.
Args:
resnum (int): Protein sequence residue number
feat_type (str, optional): Optional description of the feature type (ie. 'catalytic residue')
feat_id (str, optional): Optional ID of the feature type (ie. 'TM... |
def get_all_items_of_credit_note(self, credit_note_id):
return self._iterate_through_pages(
get_function=self.get_items_of_credit_note_per_page,
resource=CREDIT_NOTE_ITEMS,
**{'credit_note_id': credit_note_id}
) | Get all items of credit note
This will iterate over all pages until it gets all elements.
So if the rate limit exceeded it will throw an Exception and you will get nothing
:param credit_note_id: the credit note id
:return: list |
def _generateInitialModel(self, output_model_type):
logger().info("Generating initial model for BHMM using MLHMM...")
from bhmm.estimators.maximum_likelihood import MaximumLikelihoodEstimator
mlhmm = MaximumLikelihoodEstimator(self.observations, self.nstates, reversible=self.reversible,
... | Initialize using an MLHMM. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.