code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def _send_cli_conf_string(self, nexus_host, cli_str):
starttime = time.time()
path_snip = snipp.PATH_USER_CMDS
body_snip = snipp.BODY_USER_CONF_CMDS % ('1', cli_str)
LOG.debug("NexusDriver CLI config for host %s: path: %s body: %s",
nexus_host, path_snip, body_snip)
... | Sends CLI Config commands to Nexus switch using NXAPI. |
def add(self, component: Union[Component, Sequence[Component]]) -> None:
try:
self[Span(*self._available_cell())] = component
except NoUnusedCellsError:
span = list(self._spans.keys())[-1]
self._spans[span] += component | Add a widget to the grid in the next available cell.
Searches over columns then rows for available cells.
Parameters
----------
components : bowtie._Component
A Bowtie widget instance. |
def appdata_roaming_dir():
install = arcpy.GetInstallInfo('desktop')
app_data = arcpy.GetSystemEnvironment("APPDATA")
product_dir = ''.join((install['ProductName'], major_version()))
return os.path.join(app_data, 'ESRI', product_dir) | Returns the roaming AppData directory for the installed ArcGIS Desktop. |
def backtrack(self, source):
key = self.get_tok(source)
s = self[key]()
meta = s.metadata['original_source']
cls = meta['cls']
args = meta['args']
kwargs = meta['kwargs']
cls = import_name(cls)
sout = cls(*args, **kwargs)
sout.metadata = s.metadata... | Given a unique key in the store, recreate original source |
def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
warnings.warn("use _get_price_id_for_upgrade_option() instead",
DeprecationWarning)
option_category = {
'memory': 'ram',
'cpus': 'guest_core',
'nic_speed': 'port_spee... | Find the price id for the option and value to upgrade.
Deprecated in favor of _get_price_id_for_upgrade_option()
:param list package_items: Contains all the items related to an VS
:param string option: Describes type of parameter to be upgraded
:param int value: The value of the parame... |
def catch_mon_errors(conn, logger, hostname, cfg, args):
monmap = mon_status_check(conn, logger, hostname, args).get('monmap', {})
mon_initial_members = get_mon_initial_members(args, _cfg=cfg)
public_addr = cfg.safe_get('global', 'public_addr')
public_network = cfg.safe_get('global', 'public_network')
... | Make sure we are able to catch up common mishaps with monitors
and use that state of a monitor to determine what is missing
and warn apropriately about it. |
def get_instance(self, payload):
return RoleInstance(self._version, payload, service_sid=self._solution['service_sid'], ) | Build an instance of RoleInstance
:param dict payload: Payload response from the API
:returns: twilio.rest.chat.v2.service.role.RoleInstance
:rtype: twilio.rest.chat.v2.service.role.RoleInstance |
def raw_escape(pattern, unix=False):
pattern = util.norm_pattern(pattern, False, True)
return escape(pattern, unix) | Apply raw character transform before applying escape. |
def _init_credentials(self, oauth_token, oauth_token_secret):
"Depending on the state passed in, get self._oauth up and running"
if oauth_token and oauth_token_secret:
if self.verified:
self._init_oauth(oauth_token, oauth_token_secret)
else:
self.o... | Depending on the state passed in, get self._oauth up and running |
def _find_keys(self, identity='image'):
prefix = add_prefix('', identity)
raw_keys = self._find_keys_raw(prefix) or []
for raw_key in raw_keys:
yield del_prefix(raw_key) | Finds and returns all keys for identity, |
def read_table(filename, sheetname, index_col=None):
if sheetname is None or \
(hasattr(sheetname, '__iter__') \
and not isinstance(sheetname, six.string_types)):
raise TypeError("sheetname should specify a single sheet")
if packaging.version.parse(pd.__version__) \
... | Return the contents of an Excel table as a pandas DataFrame.
Parameters
----------
filename : str
Name of the Excel file to read.
sheetname : str or int
Name or index of the sheet inside the Excel file to read.
index_col : str, optional
Column name or index to be used as row... |
def map(self, data, layout):
msg = "{} should implement this method."
raise NotImplementedError(
msg.format(self.__class.__name__)) | Assign a data points to panels
Parameters
----------
data : DataFrame
Data for a layer
layout : DataFrame
As returned by self.compute_layout
Returns
-------
data : DataFrame
Data with all points mapped to the panels
... |
def collect_cases(data_dir):
cases = {}
for root, dirs, files in os.walk(data_dir):
if not dirs:
split_case = os.path.relpath(root, data_dir).split(os.path.sep)
if split_case[0] not in cases:
cases[split_case[0]] = []
cases[split_case[0]].append("-".jo... | Find all cases and subcases of a particular run type |
def embedManifestDllCheck(target, source, env):
if env.get('WINDOWS_EMBED_MANIFEST', 0):
manifestSrc = target[0].get_abspath() + '.manifest'
if os.path.exists(manifestSrc):
ret = (embedManifestDllAction) ([target[0]],None,env)
if ret:
raise SCons.Error... | Function run by embedManifestDllCheckAction to check for existence of manifest
and other conditions, and embed the manifest by calling embedManifestDllAction if so. |
def args(parsed_args, name=None):
strings = parsed_args.arg_strings(name)
files = [s for s in strings if os.path.isfile(s)]
if files:
streams = [open(f) for f in files]
else:
streams = []
if getattr(parsed_args, 'paste', not files):
streams.append(clipboard_stream())
if g... | Interpret parsed args to streams |
def make_server(host, port, app=None, threaded=False, processes=1,
request_handler=None, passthrough_errors=False,
ssl_context=None):
if threaded and processes > 1:
raise ValueError("cannot have a multithreaded and "
"multi process server.")
elif ... | Create a new server instance that is either threaded, or forks
or just processes one request after another. |
def _feature_most_population(self, results):
try:
populations = [i['population'] for i in results['hits']['hits']]
most_pop = results['hits']['hits'][np.array(populations).astype("int").argmax()]
return most_pop['country_code3']
except Exception as e:
retu... | Find the placename with the largest population and return its country.
More population is a rough measure of importance.
Paramaters
----------
results: dict
output of `query_geonames`
Returns
-------
most_pop: str
ISO code of country of p... |
def get_previous_tag(cls, el):
sibling = el.previous_sibling
while not cls.is_tag(sibling) and sibling is not None:
sibling = sibling.previous_sibling
return sibling | Get previous sibling tag. |
def events(self, event_id):
json = self.request('/events/%s' % event_id, method='GET')
status = json.get('status')
if status == 'OK':
event_json = json.get('event')
event = Event.from_json(event_json)
return event
else:
message = json.get('... | This method is primarily used to report on the progress of an event
by providing the percentage of completion.
Required parameters
event_id:
Numeric, this is the id of the event you would like more
information about |
def env(mounts):
f_mounts = [m.strip("/") for m in mounts]
root = local.path("/")
ld_libs = [root / m / "lib" for m in f_mounts]
ld_libs.extend([root / m / "lib64" for m in f_mounts])
paths = [root / m / "bin" for m in f_mounts]
paths.extend([root / m / "sbin" for m in f_mounts])
paths.exten... | Compute the environment of the change root for the user.
Args:
mounts: The mountpoints of the current user.
Return:
paths
ld_libs |
def dinfContributingArea(self,
contributing_area_grid,
flow_dir_grid,
outlet_shapefile=None,
weight_grid=None,
edge_contamination=False,
):
... | Calculates contributing area with Dinf method. |
def update(self, other=(), **kwargs):
_kwargs = dict(kwargs)
_kwargs.update(other)
for key, value in _kwargs.items():
self[key] = value | Just like `dict.update` |
def song(self):
if self._song is None:
self._song = Song(self._song_data)
return self._song | the song associated with the project |
def get_monomers(self, ligands=True, pseudo_group=False):
base_filters = dict(ligands=ligands, pseudo_group=pseudo_group)
restricted_mol_types = [x[0] for x in base_filters.items() if not x[1]]
in_groups = [x for x in self.filter_mol_types(restricted_mol_types)]
monomers = itertools.chai... | Retrieves all the `Monomers` from the `Assembly` object.
Parameters
----------
ligands : bool, optional
If `true`, will include ligand `Monomers`.
pseudo_group : bool, optional
If `True`, will include pseudo atoms. |
def is_text_type(text):
if isinstance(text, six.text_type) or isinstance(text, six.string_types):
return True
return False | Check if given parameter is a string or not
Parameters
----------
text : *
Parameter to be checked for text type
Returns
-------
bool
Whether parameter is a string or not |
def initialize(self, params, repetition):
super(TinyCIFARExperiment, self).initialize(params, repetition)
self.network_type = params.get("network_type", "sparse") | Initialize experiment parameters and default values from configuration file.
Called at the beginning of each experiment and each repetition. |
def safe_request(
url,
method=None,
params=None,
data=None,
json=None,
headers=None,
allow_redirects=False,
timeout=30,
verify_ssl=True,
):
session = requests.Session()
kwargs = {}
if json:
kwargs['json'] = json
if not headers:
headers = {}
... | A slightly safer version of `request`. |
def load(self, path):
config = _Config.load(os.path.join(path, 'config.pkl'))
config.save_dir = path
self._vocab = vocab = ParserVocabulary.load(config.save_vocab_path)
with mx.Context(mxnet_prefer_gpu()):
self._parser = BiaffineParser(vocab, config.word_dims, config.tag_dims... | Load from disk
Parameters
----------
path : str
path to the directory which typically contains a config.pkl file and a model.bin file
Returns
-------
DepParser
parser itself |
def stop_listener_thread(self):
self.should_listen = False
if self.sync_thread:
self.sync_thread.kill()
self.sync_thread.get()
if self._handle_thread is not None:
self._handle_thread.get()
self.sync_thread = None
self._handle_thread = None | Kills sync_thread greenlet before joining it |
def _dumpNdarrayToFile(filelike, ndarray):
bytedata = ndarray.tobytes('C')
start = filelike.tell()
end = start + len(bytedata)
metadata = {'start': start, 'end': end, 'size': ndarray.size,
'dtype': ndarray.dtype.name, 'shape': ndarray.shape
}
filelike.write(bytedata)
... | Serializes an N-dimensional ``numpy.array`` to bytes, writes the bytes to
the filelike object and returns a dictionary with metadata, necessary to
restore the ``numpy.array`` from the file.
:param filelike: can be a file or a file-like object that provides the
methods ``.write()`` and ``.tell()``.
... |
def clone_with_git(repo_uri, dest_path):
log.info('Cloning git repo %s to %s', repo_uri, dest_path)
git.Repo.clone_from(repo_uri, dest_path, depth=1) | Create a clone by cloning a git repository.
Args:
repo_uri: The URI of the git repository to clone.
dest_path: The location to clone to. |
def delete_network_postcommit(self, context):
segments = context.network_segments
network_name = context.current['name']
for segment in segments:
if not self.check_segment(segment):
return
vlan_id = segment.get(api.SEGMENTATION_ID)
if not vlan_... | Delete all configuration added to UCS Manager for the vlan_id. |
def make_full_qualified_url(self, path: str) -> str:
return self.application_uri.rstrip('/') + '/' + path.lstrip('/') | append application url to path |
def aws(product, tile, folder, redownload, info, entire, bands, l2a):
band_list = None if bands is None else bands.split(',')
data_source = DataSource.SENTINEL2_L2A if l2a else DataSource.SENTINEL2_L1C
if info:
if product is None:
click.echo(get_safe_format(tile=tile, entire_product=enti... | Download Sentinel-2 data from Sentinel-2 on AWS to ESA SAFE format. Download uses multiple threads.
\b
Examples with Sentinel-2 L1C data:
sentinelhub.aws --product S2A_MSIL1C_20170414T003551_N0204_R016_T54HVH_20170414T003551
sentinelhub.aws --product S2A_MSIL1C_20170414T003551_N0204_R016_T54HVH_201... |
def _pot_month_counts(self, pot_dataset):
periods = pot_dataset.continuous_periods()
result = [set() for x in range(12)]
for period in periods:
year = period.start_date.year
month = period.start_date.month
while True:
result[month - 1].add(year... | Return a list of 12 sets. Each sets contains the years included in the POT record period.
:param pot_dataset: POT dataset (records and meta data)
:type pot_dataset: :class:`floodestimation.entities.PotDataset` |
def check_attr_dimension(attr_id, **kwargs):
attr_i = _get_attr(attr_id)
datasets = db.DBSession.query(Dataset).filter(Dataset.id == ResourceScenario.dataset_id,
ResourceScenario.resource_attr_id == ResourceAttr.id,
ResourceAttr.attr_id == attr_id).all()
bad_d... | Check that the dimension of the resource attribute data is consistent
with the definition of the attribute.
If the attribute says 'volume', make sure every dataset connected
with this attribute via a resource attribute also has a dimension
of 'volume'. |
def get_columns(self, index, columns=None, as_dict=False):
i = sorted_index(self._index, index) if self._sort else self._index.index(index)
return self.get_location(i, columns, as_dict) | For a single index and list of column names return a DataFrame of the values in that index as either a dict
or a DataFrame
:param index: single index value
:param columns: list of column names
:param as_dict: if True then return the result as a dictionary
:return: DataFrame or d... |
def validate(self):
if self.status_code == 200 and self.data.get("ok", False):
self._logger.debug("Received the following response: %s", self.data)
return self
msg = "The request to the Slack API failed."
raise e.SlackApiError(message=msg, response=self.data) | Check if the response from Slack was successful.
Returns:
(SlackResponse)
This method returns it's own object. e.g. 'self'
Raises:
SlackApiError: The request to the Slack API failed. |
def _validate_format(req):
for key in SLOJSONRPC._min_keys:
if not key in req:
logging.debug('JSONRPC: Fmt Error: Need key "%s"' % key)
raise SLOJSONRPCError(-32600)
for key in req.keys():
if not key in SLOJSONRPC._allowed_keys:
log... | Validate jsonrpc compliance of a jsonrpc-dict.
req - the request as a jsonrpc-dict
raises SLOJSONRPCError on validation error |
def pre_run_hook(self, func, prefix=None):
cf = self.capture(func, prefix=prefix)
self.pre_run_hooks.append(cf)
return cf | Decorator to add a pre-run hook to this ingredient.
Pre-run hooks are captured functions that are run, just before the
main function is executed. |
def to_execution_plan(self,
domain,
default_screen,
start_date,
end_date):
if self._domain is not GENERIC and self._domain is not domain:
raise AssertionError(
"Attempted to compil... | Compile into an ExecutionPlan.
Parameters
----------
domain : zipline.pipeline.domain.Domain
Domain on which the pipeline will be executed.
default_screen : zipline.pipeline.term.Term
Term to use as a screen if self.screen is None.
all_dates : pd.Datetime... |
def update_leads_list(self, leads_list_id, name, team_id=None):
params = self.base_params
payload = {'name': name}
if team_id:
payload['team_id'] = team_id
endpoint = self.base_endpoint.format('leads_lists/' + str(leads_list_id))
return self._query_hunter(endpoint, pa... | Update a leads list.
:param name: Name of the list to update. Must be defined.
:param team_id: The id of the list to share this list with.
:return: 204 Response. |
def list_images(self):
r = self.get(self.registry_url + '/v2/_catalog', auth=self.auth)
return r.json()['repositories'] | List images stored in the registry.
Returns:
list[str]: List of image names. |
def upgradeBatch(self, n):
store = self.store
def _doBatch(itemType):
upgradedAnything = False
for theItem in store.query(itemType, limit=n):
upgradedAnything = True
try:
self.upgradeItem(theItem)
except:
... | Upgrade the entire store in batches, yielding after each batch.
@param n: Number of upgrades to perform per transaction
@type n: C{int}
@raise axiom.errors.ItemUpgradeError: if an item upgrade failed
@return: A generator that yields after each batch upgrade. This needs
to ... |
def _warmup(self, num_updates):
assert self.base_lr is not None
if not self.warmup:
return self.base_lr
fraction = (num_updates + 1) * self.base_lr / (self.warmup + 1)
if num_updates > self.last_warmup_log and num_updates % self.log_warmup_every_t == 0:
self.last_... | Returns linearly increasing fraction of base_lr. |
def list_subnetpools(self, retrieve_all=True, **_params):
return self.list('subnetpools', self.subnetpools_path, retrieve_all,
**_params) | Fetches a list of all subnetpools for a project. |
def require_foreign(namespace, symbol=None):
try:
if symbol is None:
get_foreign_module(namespace)
else:
get_foreign_struct(namespace, symbol)
except ForeignError as e:
raise ImportError(e) | Raises ImportError if the specified foreign module isn't supported or
the needed dependencies aren't installed.
e.g.: check_foreign('cairo', 'Context') |
def downloadSessionImages(server, filename=None, height=150, width=150,
opacity=100, saturation=100):
info = {}
for media in server.sessions():
url = None
for part in media.iterParts():
if media.thumb:
url = media.thumb
if part.in... | Helper to download a bif image or thumb.url from plex.server.sessions.
Parameters:
filename (str): default to None,
height (int): Height of the image.
width (int): width of the image.
opacity (int): Opacity of the resulting image (possibly deprecated).
satu... |
async def set_as_default_gateway(self):
interface = self._data['interface']
await interface._handler.set_default_gateway(
system_id=interface.node.system_id, id=interface.id,
link_id=self.id) | Set this link as the default gateway for the node. |
def _flush_ndb_puts(self, items, options):
assert ndb is not None
ndb.put_multi(items, config=self._create_config(options)) | Flush all NDB puts to datastore. |
def prefetch_translations(instances, **kwargs):
from .mixins import ModelMixin
if not isinstance(instances, collections.Iterable):
instances = [instances]
populate_missing = kwargs.get("populate_missing", True)
grouped_translations = utils.get_grouped_translations(instances, **kwargs)
if not... | Prefetches translations for the given instances.
Can be useful for a list of instances. |
def retry(self):
logger.info('Job {0} retrying all failed tasks'.format(self.name))
self.initialize_snapshot()
failed_task_names = []
for task_name, log in self.run_log['tasks'].items():
if log.get('success', True) == False:
failed_task_names.append(task_name)... | Restarts failed tasks of a job. |
def register_entry_points(self):
for entrypoint in entrypoints.get_group_all("papermill.engine"):
self.register(entrypoint.name, entrypoint.load()) | Register entrypoints for an engine
Load handlers provided by other packages |
def _promote_solitary_xvowel(self):
char_type = self.active_char_type
if char_type == VOWEL or char_type == CV or self.active_xvowel is None:
return
self._set_char(self.active_xvowel, XVOWEL)
self.active_xvowel = None
self.active_xvowel_info = None | "Promotes" the current xvowel to a regular vowel, in case
it is not otherwise connected to a character.
Used to print small vowels that would otherwise get lost;
normally small vowels always form a pair, but in case one is
by itself it should basically act like a regular vowel. |
def rule(ctxt, name):
if name in ctxt.rule_cache:
ctxt.stack.append(ctxt.rule_cache[name])
return
try:
rule = ctxt.policy[name]
except KeyError:
log = logging.getLogger('policies')
log.warn("Request to evaluate non-existant rule %r "
"while evaluating... | Allows evaluation of another rule while evaluating a rule.
:param ctxt: The evaluation context for the rule.
:param name: The name of the rule to evaluate. |
def catalog(self, table='', column=''):
lookup_table = self.lookup_table
if lookup_table is not None:
if table:
if column:
column = column.upper()
return lookup_table[table][column]
return lookup_table[table]
... | Lookup the values available for querying. |
def _check_pattern_list(patterns, key, default=None):
if not patterns:
return default
if isinstance(patterns, basestring):
return [patterns]
if isinstance(patterns, list):
if all(isinstance(p, basestring) for p in patterns):
return patterns
raise ValueError("Invalid f... | Validates file search patterns from user configuration.
Acceptable input is a string (which will be converted to a singleton list),
a list of strings, or anything falsy (such as None or an empty dictionary).
Empty or unset input will be converted to a default.
Args:
patterns: input from user c... |
def _sanitize_resources(cls, resources):
try:
for resource in cls._loop_raw(resources):
cls._sanitize_resource(resource)
except (KeyError, TypeError):
_LOGGER.debug("no shade data available")
return None | Loops over incoming data looking for base64 encoded data and
converts them to a readable format. |
def make_wcs_data_from_hpx_data(self, hpx_data, wcs, normalize=True):
wcs_data = np.zeros(wcs.npix)
self.fill_wcs_map_from_hpx_data(hpx_data, wcs_data, normalize)
return wcs_data | Creates and fills a wcs map from the hpx data using the pre-calculated
mappings
hpx_data : the input HEALPix data
wcs : the WCS object
normalize : True -> perserve integral by splitting HEALPix values between bins |
def rouge_1(hypotheses, references):
rouge_1 = [
rouge_n([hyp], [ref], 1) for hyp, ref in zip(hypotheses, references)
]
rouge_1_f, _, _ = map(np.mean, zip(*rouge_1))
return rouge_1_f | Calculate ROUGE-1 F1, precision, recall scores |
def aggregate_data(self, start, end, aggregation, keys=[], tags=[],
attrs={}, rollup=None, period=None, interpolationf=None,
interpolation_period=None, tz=None, limit=1000):
url = 'segment'
vstart = check_time_param(start)
vend = check_time_param(end... | Read data from multiple series according to a filter and apply a
function across all the returned series to put the datapoints together
into one aggregrate series.
See the :meth:`list_series` method for a description of how the filter
criteria are applied, and the :meth:`read_data` meth... |
def jd_to_datetime(jd):
year, month, day = jd_to_date(jd)
frac_days,day = math.modf(day)
day = int(day)
hour,min,sec,micro = days_to_hmsm(frac_days)
return datetime(year,month,day,hour,min,sec,micro) | Convert a Julian Day to an `jdutil.datetime` object.
Parameters
----------
jd : float
Julian day.
Returns
-------
dt : `jdutil.datetime` object
`jdutil.datetime` equivalent of Julian day.
Examples
--------
>>> jd_to_datetime(2446113.75)
datetime(1985, 2, 17, 6,... |
def generate_new_bracket(self):
logger.debug(
'start to create a new SuccessiveHalving iteration, self.curr_s=%d', self.curr_s)
if self.curr_s < 0:
logger.info("s < 0, Finish this round of Hyperband in BOHB. Generate new round")
self.curr_s = self.s_max
self.b... | generate a new bracket |
def started(name):
ret = {'name': name,
'changes': {},
'comment': '',
'result': False}
volinfo = __salt__['glusterfs.info']()
if name not in volinfo:
ret['result'] = False
ret['comment'] = 'Volume {0} does not exist'.format(name)
return ret
if int... | Check if volume has been started
name
name of the volume
.. code-block:: yaml
mycluster:
glusterfs.started: [] |
def get_project(self, project_id):
try:
result = self._request('/getproject/',
{'projectid': project_id})
return TildaProject(**result)
except NetworkError:
return [] | Get project info |
def sumlogs(x, axis=None, out=None):
maxx = x.max(axis=axis, keepdims=True)
xnorm = x - maxx
np.exp(xnorm, out=xnorm)
out = np.sum(xnorm, axis=axis, out=out)
if isinstance(out, np.ndarray):
np.log(out, out=out)
else:
out = np.log(out)
out += np.squeeze(maxx)
return out | Sum of vector where numbers are represented by their logarithms.
Calculates ``np.log(np.sum(np.exp(x), axis=axis))`` in such a fashion that
it works even when elements have large magnitude. |
def _keep_this(self, name):
for keep_name in self.keep:
if name == keep_name:
return True
return False | Return True if there are to be no modifications to name. |
def _find_output_dependencies(self, outputs):
dependencies = []
for address in outputs:
dependencies.extend(
self._predecessor_tree.find_write_predecessors(address))
return dependencies | Use the predecessor tree to find dependencies based on outputs.
Returns: A list of transaction ids. |
def enable(self):
if not CrashReporter.active:
CrashReporter.active = True
self._excepthook = sys.excepthook
sys.excepthook = self.exception_handler
self.logger.info('CrashReporter: Enabled')
if self.report_dir:
if os.path.exists(self.r... | Enable the crash reporter. CrashReporter is defaulted to be enabled on creation. |
def get_state(self, key=None, drop_defaults=False):
if key is None:
keys = self.keys
elif isinstance(key, string_types):
keys = [key]
elif isinstance(key, collections.Iterable):
keys = key
else:
raise ValueError("key must be a string, an it... | Gets the widget state, or a piece of it.
Parameters
----------
key : unicode or iterable (optional)
A single property's name or iterable of property names to get.
Returns
-------
state : dict of states
metadata : dict
metadata for each fi... |
def get_nt_filename (path):
unc, rest = os.path.splitunc(path)
head, tail = os.path.split(rest)
if not tail:
return path
for fname in os.listdir(unc+head):
if fname.lower() == tail.lower():
return os.path.join(get_nt_filename(unc+head), fname)
log.error(LOG_CHECK, "could ... | Return case sensitive filename for NT path. |
def concat(self, axis, other, **kwargs):
return self._append_list_of_managers(other, axis, **kwargs) | Concatenates two objects together.
Args:
axis: The axis index object to join (0 for columns, 1 for index).
other: The other_index to concat with.
Returns:
Concatenated objects. |
def get_request(self):
request, client_addr = super(BoundedThreadingMixIn, self).get_request()
overload = False
with self._thread_guard:
if self._threads is not None and len(self._threads) + 1 > MAX_RPC_THREADS:
overload = True
if overload:
res = s... | Accept a request, up to the given number of allowed threads.
Defer to self.overloaded if there are already too many pending requests. |
def new_media_status(self, media_status):
casts = self._casts
group_members = self._mz.members
for member_uuid in group_members:
if member_uuid not in casts:
continue
for listener in list(casts[member_uuid]['listeners']):
listener.multizone... | Handle reception of a new MediaStatus. |
def _generate_energy_edges_single(ene):
midene = np.sqrt((ene[1:] * ene[:-1]))
elo, ehi = np.zeros(len(ene)) * ene.unit, np.zeros(len(ene)) * ene.unit
elo[1:] = ene[1:] - midene
ehi[:-1] = midene - ene[:-1]
elo[0] = ene[0] * (1 - ene[0] / (ene[0] + ehi[0]))
ehi[-1] = elo[-1]
return u.Quantit... | Generate energy edges for single group |
def on_close(self):
if self.id in self.funcserver.websocks:
self.funcserver.websocks[self.id] = None
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.add_callback(lambda: self.funcserver.websocks.pop(self.id, None))
psession = self.funcserver.pysessions.get(self.pyses... | Called when client closes this connection. Cleanup
is done here. |
def _clone(self, *args, **kwargs):
clone = super(VersionedQuerySet, self)._clone(**kwargs)
clone.querytime = self.querytime
return clone | Overrides the QuerySet._clone method by adding the cloning of the
VersionedQuerySet's query_time parameter
:param kwargs: Same as the original QuerySet._clone params
:return: Just as QuerySet._clone, this method returns a clone of the
original object |
def _init_structures(self, data, subjects):
x = []
mu = []
rho2 = np.zeros(subjects)
trace_xtx = np.zeros(subjects)
for subject in range(subjects):
mu.append(np.mean(data[subject], 1))
rho2[subject] = 1
trace_xtx[subject] = np.sum(data[subject]... | Initializes data structures for SRM and preprocess the data.
Parameters
----------
data : list of 2D arrays, element i has shape=[voxels_i, samples]
Each element in the list contains the fMRI data of one subject.
subjects : int
The total number of subjects in `... |
def crossvalidate_model(cls, clusterer, data, num_folds, rnd):
return javabridge.static_call(
"Lweka/clusterers/ClusterEvaluation;", "crossValidateModel",
"(Lweka/clusterers/DensityBasedClusterer;Lweka/core/Instances;ILjava/util/Random;)D",
clusterer.jobject, data.jobject, nu... | Cross-validates the clusterer and returns the loglikelihood.
:param clusterer: the clusterer instance to evaluate
:type clusterer: Clusterer
:param data: the data to evaluate on
:type data: Instances
:param num_folds: the number of folds
:type num_folds: int
:par... |
def _clone_block_and_wires(block_in):
block_in.sanity_check()
block_out = block_in.__class__()
temp_wv_map = {}
with set_working_block(block_out, no_sanity_check=True):
for wirevector in block_in.wirevector_subset():
new_wv = clone_wire(wirevector)
temp_wv_map[wirevector]... | This is a generic function to copy the WireVectors for another round of
synthesis This does not split a WireVector with multiple wires.
:param block_in: The block to change
:param synth_name: a name to prepend to all new copies of a wire
:return: the resulting block and a WireVector map |
def route(
self,
uri,
methods=frozenset({"GET"}),
host=None,
strict_slashes=None,
stream=False,
version=None,
name=None,
):
if strict_slashes is None:
strict_slashes = self.strict_slashes
def decorator(handler):
... | Create a blueprint route from a decorated function.
:param uri: endpoint at which the route will be accessible.
:param methods: list of acceptable HTTP methods.
:param host: IP Address of FQDN for the sanic server to use.
:param strict_slashes: Enforce the API urls are requested with a
... |
def parallel_scan(self, scan_id, target):
try:
ret = self.exec_scan(scan_id, target)
if ret == 0:
self.add_scan_host_detail(scan_id, name='host_status',
host=target, value='0')
elif ret == 1:
self.add_s... | Starts the scan with scan_id. |
def _get_access_type(self, mode):
access_type = None
for char in mode:
if char in 'bt':
if access_type is not None:
raise IOError('File mode "%s" contains contradictory flags' % mode)
access_type = char
elif char not in 'rbt':
... | Make sure mode is appropriate; return 'b' for binary access and 't' for text |
def merge(filehandle_1, filehandle_2, output_filehandle):
line2 = filehandle_2.readline()
for line1 in filehandle_1.readlines():
while line2 != '' and line2 <= line1:
output_filehandle.write(line2)
line2 = filehandle_2.readline()
output_filehandle.write(line1)
while l... | Merges together two files maintaining sorted order. |
def network(n):
tpm(n.tpm)
connectivity_matrix(n.cm)
if n.cm.shape[0] != n.size:
raise ValueError("Connectivity matrix must be NxN, where N is the "
"number of nodes in the network.")
return True | Validate a |Network|.
Checks the TPM and connectivity matrix. |
def _connect_hive(self, hive):
try:
handle = self._remote_hives[hive]
except KeyError:
handle = win32.RegConnectRegistry(self._machine, hive)
self._remote_hives[hive] = handle
return handle | Connect to the specified hive of a remote Registry.
@note: The connection will be cached, to close all connections and
erase this cache call the L{close} method.
@type hive: int
@param hive: Hive to connect to.
@rtype: L{win32.RegistryKeyHandle}
@return: Open han... |
def reference(self, tkn: str):
return self.grammarelts[tkn] if tkn in self.grammarelts else UndefinedElement(tkn) | Return the element that tkn represents |
def _create_connection(self):
transport = SSL if self.ssl else TCP
return transport(self.server, self.port) | Creates a transport channel.
:return: transport channel instance
:rtype: :class:`fatbotslim.irc.tcp.TCP` or :class:`fatbotslim.irc.tcp.SSL` |
def complete_pool_name(arg):
search_string = '^'
if arg is not None:
search_string += arg
res = Pool.search({
'operator': 'regex_match',
'val1': 'name',
'val2': search_string
})
ret = []
for p in res['result']:
ret.append(p.name)
return ret | Returns list of matching pool names |
def validate(mcs, bases, attributes):
if bases[0] is object:
return None
mcs.check_model_cls(attributes)
mcs.check_include_exclude(attributes)
mcs.check_properties(attributes) | Check attributes. |
def array_bytes(array):
return np.product(array.shape)*np.dtype(array.dtype).itemsize | Estimates the memory of the supplied array in bytes |
def search(self, term):
r = requests.get(self.apiurl + "/users", params={"filter[name]": term}, headers=self.header)
if r.status_code != 200:
raise ServerError
jsd = r.json()
if jsd['meta']['count']:
return SearchWrapper(jsd['data'], jsd['links']['next'] if 'next'... | Search for a user by name.
:param str term: What to search for.
:return: The results as a SearchWrapper iterator or None if no results.
:rtype: SearchWrapper or None |
def _save_json(self, filename):
with open(filename, 'w') as file_handle:
json.dump(self._sensors, file_handle, cls=MySensorsJSONEncoder,
indent=4)
file_handle.flush()
os.fsync(file_handle.fileno()) | Save sensors to json file. |
def _link(self, base_dir: str, artifact_map: dict, conf: Config):
num_linked = 0
for dst, src in artifact_map.items():
abs_src = join(conf.project_root, src)
abs_dest = join(conf.project_root, base_dir, dst)
link_node(abs_src, abs_dest)
num_linked += 1
... | Link all artifacts in `artifact_map` under `base_dir` and return
the number of artifacts linked. |
def get_delimited_message_bytes(byte_stream, nr=4):
(length, pos) = decoder._DecodeVarint32(byte_stream.read(nr), 0)
if log.getEffectiveLevel() == logging.DEBUG:
log.debug("Delimited message length (pos %d): %d" % (pos, length))
delimiter_bytes = nr - pos
byte_stream.rewind(delimiter_bytes)
... | Parse a delimited protobuf message. This is done by first getting a protobuf varint from
the stream that represents the length of the message, then reading that amount of
from the message and then parse it.
Since the int can be represented as max 4 bytes, first get 4 bytes and try to decode.
The decoder... |
def to_dict(self):
as_dict = dict(self.payload or ())
as_dict['message'] = self.message
return as_dict | Return a dictionary representation of the exception. |
def EmitProto(cls):
result = "message %s {\n" % cls.__name__
for _, desc in sorted(iteritems(cls.type_infos_by_field_number)):
result += desc.Definition()
result += "}\n"
return result | Emits .proto file definitions. |
def tofile(self, f):
f.write(pack(self.FILE_FMT, self.scale, self.ratio,
self.initial_capacity, self.error_rate))
f.write(pack(b'<l', len(self.filters)))
if len(self.filters) > 0:
headerpos = f.tell()
headerfmt = b'<' + b'Q'*(len(self.filters))
... | Serialize this ScalableBloomFilter into the file-object
`f'. |
def mb_filter(fastq, cores):
filter_mb = partial(umi_filter)
p = multiprocessing.Pool(cores)
chunks = tz.partition_all(10000, read_fastq(fastq))
bigchunks = tz.partition_all(cores, chunks)
for bigchunk in bigchunks:
for chunk in p.map(filter_mb, list(bigchunk)):
for read in chunk... | Filters umis with non-ACGT bases
Expects formatted fastq files. |
def ID_colored_tube(color):
tubing_data_path = os.path.join(os.path.dirname(__file__), "data",
"3_stop_tubing.txt")
df = pd.read_csv(tubing_data_path, delimiter='\t')
idx = df["Color"] == color
return df[idx]['Diameter (mm)'].values[0] * u.mm | Look up the inner diameter of Ismatec 3-stop tubing given its color code.
:param color: Color of the 3-stop tubing
:type color: string
:returns: Inner diameter of the 3-stop tubing (mm)
:rtype: float
:Examples:
>>> from aguaclara.research.peristaltic_pump import ID_colored_tube
>>> from ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.