code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def _check_environ(variable, value):
if is_not_none(value):
return value
else:
value = os.environ.get(variable)
if is_none(value):
stop(''.join([variable,
]))
else:
return value | check if a variable is present in the environmental variables |
def reset(self):
if self.state is not TimerState.stopped:
if self.on_reset and self.state is TimerState.overflow:
if callable(self.on_reset):
self.on_reset()
else:
execute(self.on_reset)
self.state = TimerState.stopp... | Stop timer and execute ``on_reset`` if overflow occured. |
def set_snapshots(self,snapshots):
self.snapshots = pd.Index(snapshots)
self.snapshot_weightings = self.snapshot_weightings.reindex(self.snapshots,fill_value=1.)
if isinstance(snapshots, pd.DatetimeIndex) and _pd_version < '0.18.0':
snapshots = pd.Index(snapshots.values)
for ... | Set the snapshots and reindex all time-dependent data.
This will reindex all pandas.Panels of time-dependent data; NaNs are filled
with the default value for that quantity.
Parameters
----------
snapshots : list or pandas.Index
All time steps.
Returns
... |
def to_description_dict(self):
return {
'certificateArn': self.arn,
'certificateId': self.certificate_id,
'status': self.status,
'certificatePem': self.certificate_pem,
'ownedBy': self.owner,
'creationDate': self.creation_date,
... | You might need keys below in some situation
- caCertificateId
- previousOwnedBy |
def runlist_list(**kwargs):
ctx = Context(**kwargs)
ctx.execute_action('runlist:list', **{
'storage': ctx.repo.create_secure_service('storage'),
}) | Show uploaded runlists. |
def stop_instance(self, instance):
params = {'state': 'stopped'}
url = '/instances/{}'.format(instance)
self.patch_proto(url, params=params) | Stops a single instance.
:param str instance: A Yamcs instance name. |
def copy_scubadir_file(self, name, source):
dest = os.path.join(self.__scubadir_hostpath, name)
assert not os.path.exists(dest)
shutil.copy2(source, dest)
return os.path.join(self.__scubadir_contpath, name) | Copies source into the scubadir
Returns the container-path of the copied file |
def setWindowSize(self, winsz):
self.tracePlot.setWindowSize(winsz)
self.stimPlot.setWindowSize(winsz) | Sets the size of scroll window |
def sort_url_qsl(cls, raw_url, **kwargs):
parsed_url = urlparse(raw_url)
qsl = parse_qsl(parsed_url.query)
return cls._join_url(parsed_url, sorted(qsl, **kwargs)) | Do nothing but sort the params of url.
raw_url: the raw url to be sorted;
kwargs: (optional) same kwargs for ``sorted``. |
def query_all_collisions(collision_object):
global collidable_objects
colliding = []
for obj in collidable_objects:
if obj is not collision_object:
if collision_object.is_colliding(obj):
colliding.append(obj)
return colliding | Check for and return the full list of objects colliding with collision_object |
def _attach_to_instance(self, instance):
self._instance = instance
self.lockable = self.lockable and instance.lockable | Attach the current field to an instance of a model. Can be overriden to
do something when an instance is set |
def do_sqlite_connect(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close() | Ensure SQLite checks foreign key constraints.
For further details see "Foreign key support" sections on
https://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#foreign-key-support |
def get_tag_value(self, i):
found = False
for t in i.get('Tags', ()):
if t['Key'].lower() == self.tag_key:
found = t['Value']
break
if found is False:
return False
value = found.lower().encode('utf8').decode('utf8')
value = ... | Get the resource's tag value specifying its schedule. |
def on_pause(self):
self.engine.commit()
self.strings.save()
self.funcs.save()
self.config.write() | Sync the database with the current state of the game. |
def _get_encoding(encoding_or_label):
if hasattr(encoding_or_label, 'codec_info'):
return encoding_or_label
encoding = lookup(encoding_or_label)
if encoding is None:
raise LookupError('Unknown encoding label: %r' % encoding_or_label)
return encoding | Accept either an encoding object or label.
:param encoding: An :class:`Encoding` object or a label string.
:returns: An :class:`Encoding` object.
:raises: :exc:`~exceptions.LookupError` for an unknown label. |
def get_random(self, n, l=None):
random_f = Fasta()
if l:
ids = self.ids[:]
random.shuffle(ids)
i = 0
while (i < n) and (len(ids) > 0):
seq_id = ids.pop()
if (len(self[seq_id]) >= l):
start = random.randi... | Return n random sequences from this Fasta object |
def delete_metadata(self, container, prefix=None):
if prefix is None:
prefix = CONTAINER_META_PREFIX
new_meta = {}
curr_meta = self.get_metadata(container, prefix=prefix)
for ckey in curr_meta:
new_meta[ckey] = ""
uri = "/%s" % utils.get_name(container)
... | Removes all of the container's metadata.
By default, all metadata beginning with the standard container metadata
prefix ('X-Container-Meta-') is removed. If you wish to remove all
metadata beginning with a different prefix, you must specify that
prefix. |
def shrink(self, fraction=0.85):
poly = self.polydata(True)
shrink = vtk.vtkShrinkPolyData()
shrink.SetInputData(poly)
shrink.SetShrinkFactor(fraction)
shrink.Update()
return self.updateMesh(shrink.GetOutput()) | Shrink the triangle polydata in the representation of the input mesh.
Example:
.. code-block:: python
from vtkplotter import *
pot = load(datadir + 'shapes/teapot.vtk').shrink(0.75)
s = Sphere(r=0.2).pos(0,0,-0.5)
show(pot, s)
... |
def plot_bbox(sf,bbox,inside_only=True):
index,shape_records = bbox_match(sf,bbox,inside_only)
A,B,C,D = bbox
plot(shape_records,xlims=[bbox[0],bbox[2]],ylims=[bbox[1],bbox[3]]) | Plot the geometry of a shapefile within a bbox
:param sf: shapefile
:type sf: shapefile object
:param bbox: bounding box
:type bbox: list of floats [x_min,y_min,x_max,y_max]
:inside_only: True if the objects returned are those that lie within the bbox and False if the objects returned are any that ... |
def Set(self, value, fields=None):
self._metric_values[_FieldsToKey(fields)] = self._value_type(value) | Sets the metric's current value. |
def get_profane_words(self):
profane_words = []
if self._custom_censor_list:
profane_words = [w for w in self._custom_censor_list]
else:
profane_words = [w for w in self._censor_list]
profane_words.extend(self._extra_censor_list)
profane_words.extend([infl... | Returns all profane words currently in use. |
def _parallel_predict(estimators, estimators_features, X, n_classes, combination, estimators_weight):
n_samples = X.shape[0]
pred = np.zeros((n_samples, n_classes))
n_estimators = len(estimators)
for estimator, features, weight in zip(estimators, estimators_features, estimators_weight):
predicti... | Private function used to compute predictions within a job. |
def view_graph(graph_str, parent=None, prune_to=None):
from rezgui.dialogs.ImageViewerDialog import ImageViewerDialog
from rez.config import config
h = hash((graph_str, prune_to))
filepath = graph_file_lookup.get(h)
if filepath and not os.path.exists(filepath):
filepath = None
if filepat... | View a graph. |
def num_model_per_iteration(self):
model_per_iter = ctypes.c_int(0)
_safe_call(_LIB.LGBM_BoosterNumModelPerIteration(
self.handle,
ctypes.byref(model_per_iter)))
return model_per_iter.value | Get number of models per iteration.
Returns
-------
model_per_iter : int
The number of models per iteration. |
def is_valid_device_id(device_id):
valid = valid_device_id.match(device_id)
if not valid:
logging.error("A valid device identifier contains "
"only ascii word characters or dashes. "
"Device '%s' not added.", device_id)
return valid | Check if device identifier is valid.
A valid device identifier contains only ascii word characters or dashes.
:param device_id: Device identifier
:returns: Valid or not. |
def _tighten_triplet(self, max_iterations, later_iter, max_triplets, prolong):
triangles = self.find_triangles()
triplet_scores = self._get_triplet_scores(triangles)
sorted_scores = sorted(triplet_scores, key=triplet_scores.get)
for niter in range(max_iterations):
if self._is... | This method finds all the triplets that are eligible and adds them iteratively in the bunch of max_triplets
Parameters
----------
max_iterations: integer
Maximum number of times we tighten the relaxation
later_iter: integer
Number of maximum ... |
def weighted_accuracy(comparisons, weights):
N = len(comparisons)
if weights.shape[0] != N:
raise ValueError('weights and comparisons should be of the same'
' length. len(weights) = {} but len(comparisons)'
' = {}'.format(weights.shape[0], N))
if (we... | Compute the weighted accuracy of a list of chord comparisons.
Examples
--------
>>> (ref_intervals,
... ref_labels) = mir_eval.io.load_labeled_intervals('ref.lab')
>>> (est_intervals,
... est_labels) = mir_eval.io.load_labeled_intervals('est.lab')
>>> est_intervals, est_labels = mir_eval.... |
def _value_validate(self, value, rnge, identifier="Given"):
if value is not None and (value < rnge[0] or value > rnge[1]):
raise ValueError('%s value must be between %d and %d.'
% (identifier, rnge[0], rnge[1])) | Make sure a value is within a given range |
def run(self):
self.otherThread._Thread__stderr = self._stderr
if hasattr(self.otherThread, '_Thread__stop'):
self.otherThread._Thread__stop()
while self.otherThread.isAlive():
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.otherThread.ident), ctypes.py_obj... | run - The thread main. Will attempt to stop and join the attached thread. |
def first_name_capture(records):
logging.info('Applying _first_name_capture generator: '
'making sure ID only contains the first whitespace-delimited '
'word.')
whitespace = re.compile(r'\s+')
for record in records:
if whitespace.search(record.description):
... | Take only the first whitespace-delimited word as the name of the sequence.
Essentially removes any extra text from the sequence's description. |
def visit_loop(self, node, cond=None):
for stmt in node.body:
self.visit(stmt)
old_range = self.result.copy()
for stmt in node.body:
self.visit(stmt)
for expr, range_ in old_range.items():
self.result[expr] = self.result[expr].widen(range_)
con... | Handle incremented variables in loop body.
>>> import gast as ast
>>> from pythran import passmanager, backend
>>> node = ast.parse('''
... def foo():
... a = b = c = 2
... while a > 0:
... a -= 1
... b += 1''')
>>> pm = pa... |
def disable(self):
self._enabled = False
for child in self.children:
if isinstance(child, (Container, Widget)):
child.disable() | Disable all the widgets in this container |
def _significant_pathways_dataframe(pvalue_information,
side_information,
alpha):
significant_pathways = pd.concat(
[pvalue_information, side_information], axis=1)
below_alpha, qvalues, _, _ = multipletests(
significant_path... | Create the significant pathways pandas.DataFrame.
Given the p-values corresponding to each pathway in a feature,
apply the FDR correction for multiple testing and remove those that
do not have a q-value of less than `alpha`. |
def start_logging(self, region, name):
ct = self.session.client('cloudtrail', region_name=region)
ct.start_logging(Name=name)
auditlog(
event='cloudtrail.start_logging',
actor=self.ns,
data={
'account': self.account.account_name,
... | Turn on logging for a CloudTrail Trail
Args:
region (`str`): Name of the AWS region
name (`str`): Name of the CloudTrail Trail
Returns:
`None` |
def init_ui(self):
board_width = self.ms_game.board_width
board_height = self.ms_game.board_height
self.create_grid(board_width, board_height)
self.time = 0
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.timing_game)
self.timer.start(1000) | Init game interface. |
def dump_in_memory_result(self, result, output_path):
file_count = 0
logger.debug("Dumping in-memory processing results to output folder: %s", output_path)
for k, v in iteritems(result):
cur_output_path = os.path.join(output_path, k)
if isinstance(v, dict):
... | Recursively dumps the result of our processing into files within the
given output path.
Args:
result: The in-memory result of our processing.
output_path: Full path to the folder into which to dump the files.
Returns:
The number of files generated (integer). |
def get_nodes_by_tag(self, graph, tag_name):
for node, real_node in self.parsed_nodes(graph):
if tag_name in real_node.tags:
yield node | yields nodes from graph that have the specified tag |
def get_next_environment(env):
config = _config_file()
juicer.utils.Log.log_debug("Finding next environment...")
if env not in config.sections():
raise JuicerConfigError("%s is not a server configured in juicer.conf", env)
section = dict(config.items(env))
if 'promotes_to' not in section.key... | Given an environment, return the next environment in the
promotion hierarchy |
def current_timestamp(self) -> datetime:
timestamp = DB.get_hash_value(self._key, 'current_timestamp')
return datetime_from_isoformat(timestamp) | Get the current state timestamp. |
def feed_fetch_force(request, id, redirect_to):
feed = Feed.objects.get(id=id)
feed.fetch(force=True)
msg = _("Fetched tweets for %s" % feed.name)
messages.success(request, msg, fail_silently=True)
return HttpResponseRedirect(redirect_to) | Forcibly fetch tweets for the feed |
def load_werkzeug(path):
sys.path[0] = path
wz.__dict__.clear()
for key in sys.modules.keys():
if key.startswith("werkzeug.") or key == "werkzeug":
sys.modules.pop(key, None)
import werkzeug
for key in werkzeug.__all__:
setattr(wz, key, getattr(werkzeug, key))
hg_tag ... | Load werkzeug. |
def warp_object(self, tileMapObj):
print "Collision"
if tileMapObj.can_warp:
if self.map_association != self.exitWarp.map_association:
TileMapManager.load(exitWarp.map_association)
tileMapObj.parent.coords = self.exitWarp.coords | Warp the tile map object from one warp to another. |
def writeline(self, data):
try:
if self.ch_mode:
data += "\n"
parts = split_by_n(data, self.ch_mode_chunk_size)
for split_str in parts:
self.port.write(split_str.encode())
time.sleep(self.ch_mode_ch_delay)
... | Writes data to serial port.
:param data: Data to write
:return: Nothing
:raises: IOError if SerialException occurs. |
def delete(self, option):
if self.config is not None:
if option in self.config:
del self.config[option] | Deletes an option if exists |
def user_can_delete_attachments(self):
context = self.context
user = api.get_current_user()
if not self.is_ar_editable():
return False
return (self.user_can_add_attachments() and
not user.allowed(context, ["Client"])) or \
self.user_can_update_atta... | Checks if the current logged in user is allowed to delete attachments |
def _collect_cpu_info(run_info):
cpu_info = {}
cpu_info["num_cores"] = multiprocessing.cpu_count()
import cpuinfo
info = cpuinfo.get_cpu_info()
cpu_info["cpu_info"] = info["brand"]
cpu_info["mhz_per_cpu"] = info["hz_advertised_raw"][0] / 1.0e6
run_info["machine_config"]["cpu_info"] = cpu_info | Collect the CPU information for the local environment. |
def legend(self, values):
if not isinstance(values, list):
raise TypeError("legend must be a list of labels")
self.options["legend"] = values | Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels. |
def store_meta_data(self, copy_path=None):
if copy_path:
meta_file_path_json = os.path.join(copy_path, self.state.get_storage_path(), storage.FILE_NAME_META_DATA)
else:
if self.state.file_system_path is None:
logger.error("Meta data of {0} can be stored temporary ... | Save meta data of state model to the file system
This method generates a dictionary of the meta data of the state together with the meta data of all state
elements (data ports, outcomes, etc.) and stores it on the filesystem.
Secure that the store meta data method is called after storing the co... |
def reset_status(self):
for row in range(self.table.rowCount()):
status_item = self.table.item(row, 1)
status_item.setText(self.tr('')) | Set all scenarios' status to empty in the table. |
def _asdict(self):
with self._cond:
if self._prompt is None:
return
return {'id': self._prompt.id,
'message': self._prompt.message,
'text-input': self._prompt.text_input} | Return a dictionary representation of the current prompt. |
def parse(self, debug=False):
if self._parsed is None:
try:
if self._mode == "html":
self._parsed = self.html(self._content, self._show_everything, self._translation)
else:
self._parsed = self.rst(self._content, self._show_every... | Returns parsed text |
def start_stream(self):
tracking_terms = self.term_checker.tracking_terms()
if len(tracking_terms) > 0 or self.unfiltered:
self.stream = tweepy.Stream(self.auth, self.listener,
stall_warnings=True,
timeout=90,
... | Starts a stream with teh current tracking terms |
def _remove_duplicate_files(xs):
seen = set([])
out = []
for x in xs:
if x["path"] not in seen:
out.append(x)
seen.add(x["path"])
return out | Remove files specified multiple times in a list. |
def equals(self,junc):
if self.left.equals(junc.left): return False
if self.right.equals(junc.right): return False
return True | test equality with another junction |
def l2_regularizer(weight=1.0, scope=None):
def regularizer(tensor):
with tf.name_scope(scope, 'L2Regularizer', [tensor]):
l2_weight = tf.convert_to_tensor(weight,
dtype=tensor.dtype.base_dtype,
name='weight')
return tf.mult... | Define a L2 regularizer.
Args:
weight: scale the loss by this factor.
scope: Optional scope for name_scope.
Returns:
a regularizer function. |
def _set_directories(self):
if self._dirs['initial'] == None:
self._dirs['base'] = discover_base_dir(self._dirs['run'])
else:
self._dirs['base'] = discover_base_dir(self._dirs['initial'])
self._update_dirs_on_base()
self._tree_ready = verify_dir_structure(self... | Initialize variables based on evidence about the directories. |
def download(self, filename=None):
if filename is None:
filename = self.name
with self.remote_open() as infile:
with open(filename, 'wb') as outfile:
outfile.write(infile.read()) | Download the dataset to a local file.
Parameters
----------
filename : str, optional
The full path to which the dataset will be saved |
def containment_angle_bin(self, egy_bins, fraction=0.68, scale_fn=None):
vals = self.interp_bin(egy_bins, self.dtheta, scale_fn=scale_fn)
dtheta = np.radians(self.dtheta[:, np.newaxis] * np.ones(vals.shape))
return self._calc_containment(dtheta, vals, fraction) | Evaluate the PSF containment angle averaged over energy bins. |
def smove(self, src, dst, value):
src_set = self._get_set(src, 'SMOVE')
dst_set = self._get_set(dst, 'SMOVE')
value = self._encode(value)
if value not in src_set:
return False
src_set.discard(value)
dst_set.add(value)
self.redis[self._encode(src)], sel... | Emulate smove. |
def get_nodes(self, request):
nodes = []
nodes.append(NavigationNode(_('Tags'), reverse('zinnia:tag_list'),
'tags'))
for tag in tags_published():
nodes.append(NavigationNode(tag.name,
reverse('zinnia:tag_deta... | Return menu's node for tags |
def deactivate_mfa_device(self, user_name, serial_number):
user = self.get_user(user_name)
if serial_number not in user.mfa_devices:
raise IAMNotFoundException(
"Device {0} not found".format(serial_number)
)
user.deactivate_mfa_device(serial_number) | Deactivate and detach MFA Device from user if device exists. |
def _HandleHelp(self, request):
help_path = request.path.split("/", 2)[-1]
if not help_path:
raise werkzeug_exceptions.Forbidden("Error: Invalid help path.")
return self._RedirectToRemoteHelp(help_path) | Handles help requests. |
def install_monitor(self, monitor_pattern: str, monitor_stat_func_name: str):
self._monitor = mx.monitor.Monitor(interval=C.MEASURE_SPEED_EVERY,
stat_func=C.MONITOR_STAT_FUNCS.get(monitor_stat_func_name),
pattern=monitor_patte... | Installs an MXNet monitor onto the underlying module.
:param monitor_pattern: Pattern string.
:param monitor_stat_func_name: Name of monitor statistics function. |
def setup_ui(self, ):
self.main_vbox = QtGui.QVBoxLayout(self)
self.import_all_references_cb = QtGui.QCheckBox("Import references")
self.main_vbox.addWidget(self.import_all_references_cb) | Create all ui elements and layouts
:returns: None
:rtype: None
:raises: None |
def save_coeffs(coeffs, out_dir=''):
for platform in coeffs.keys():
fname = os.path.join(out_dir, "%s_calibration_data.h5" % platform)
fid = h5py.File(fname, 'w')
for chan in coeffs[platform].keys():
fid.create_group(chan)
fid[chan]['datetime'] = coeffs[platform][chan... | Save calibration coefficients to HDF5 files. |
def ad_hoc_magic_from_file(filename, **kwargs):
with open(filename, 'rb') as stream:
head = stream.read(16)
if head[:4] == b'\x7fELF':
return b'application/x-executable'
elif head[:2] == b'MZ':
return b'application/x-dosexec'
else:
raise NotImpleme... | Ad-hoc emulation of magic.from_file from python-magic. |
def get_data_files(dname, ignore=None, parent=None):
parent = parent or "."
ignore = ignore or []
result = []
for directory, subdirectories, filenames in os.walk(dname):
resultfiles = []
for exname in EXCLUDE_NAMES:
if exname in subdirectories:
subdirectories.... | Get all the data files that should be included in this distutils Project.
'dname' should be the path to the package that you're distributing.
'ignore' is a list of sub-packages to ignore. This facilitates
disparate package hierarchies. That's a fancy way of saying that
the 'twisted' package doesn't ... |
def get_fieldsets(self, request, obj=None):
fieldsets = list(super(CreateUpdateAdmin, self).get_fieldsets(
request=request, obj=obj))
fields = set()
to_add = set()
for fs in fieldsets:
fields = fields.union(fs[1]['fields'])
for k, v in self.ownership_info[... | Add ownership info fields in fieldset with proper separation.
Author: Himanshu Shankar (https://himanshus.com) |
def auth(self, transport, account_name, password):
auth_token = AuthToken()
auth_token.account_name = account_name
attrs = {sconstant.A_BY: sconstant.V_NAME}
account = SOAPpy.Types.stringType(data=account_name, attrs=attrs)
params = {sconstant.E_ACCOUNT: account,
... | Authenticates using username and password. |
def collect_info(self):
try:
info = {}
res = self._send_request('GET', "/")
info['server'] = {}
info['server']['name'] = res['name']
info['server']['version'] = res['version']
info['allinfo'] = res
info['status'] = self.cluster.... | Collect info about the connection and fill the info dictionary. |
def update_DOM(self):
response = self.fetch()
self._DOM = html.fromstring(response.text)
return self | Makes a request and updates `self._DOM`.
Worth using only if you manually change `self.base_url` or `self.path`.
:return: self
:rtype: Url |
def reset():
if hasattr(ray.worker.global_worker, "signal_counters"):
ray.worker.global_worker.signal_counters = defaultdict(lambda: b"0") | Reset the worker state associated with any signals that this worker
has received so far.
If the worker calls receive() on a source next, it will get all the
signals generated by that source starting with index = 1. |
def onex(self):
xCols=[i for i in range(self.nCols) if self.colTypes[i]==3]
if len(xCols)>1:
for colI in xCols[1:][::-1]:
self.colDelete(colI) | delete all X columns except the first one. |
def set_next_page_params(self):
if self.items:
index = self.get_last_item_index()
self.params[self.mode] = self.get_next_page_param(self.items[index]) | Set the params so that the next page is fetched. |
def runlist_add_app(name, app, profile, force, **kwargs):
ctx = Context(**kwargs)
ctx.execute_action('runlist:add-app', **{
'storage': ctx.repo.create_secure_service('storage'),
'name': name,
'app': app,
'profile': profile,
'force': force
}) | Add specified application with profile to the specified runlist.
Existence of application or profile is not checked. |
def in_coord_list_pbc(fcoord_list, fcoord, atol=1e-8):
return len(find_in_coord_list_pbc(fcoord_list, fcoord, atol=atol)) > 0 | Tests if a particular fractional coord is within a fractional coord_list.
Args:
fcoord_list: List of fractional coords to test
fcoord: A specific fractional coord to test.
atol: Absolute tolerance. Defaults to 1e-8.
Returns:
True if coord is in the coord list. |
def update_state_active(self):
self.update_state(self.links[REF_UPDATE_STATE_ACTIVE], {'type' : RUN_ACTIVE})
return self.refresh() | Update the state of the model run to active.
Raises an exception if update fails or resource is unknown.
Returns
-------
ModelRunHandle
Refreshed run handle. |
def is_this_year(self):
return is_current_year(datetime.datetime.combine(self.date, datetime.time())) | Return whether the block occurs after September 1st of this school year. |
def detect_pattern_format(pattern_filename, encoding, on_word_boundaries):
tsv = True
boundaries = on_word_boundaries
with open_file(pattern_filename) as input_file:
for line in input_file:
line = line.decode(encoding)
if line.count('\t') != 1:
tsv = False
... | Automatically detects the pattern file format, and determines
whether the Aho-Corasick string matching should pay attention to
word boundaries or not.
Arguments:
- `pattern_filename`:
- `encoding`:
- `on_word_boundaries`: |
def serialize(material_description):
material_description_bytes = bytearray(_MATERIAL_DESCRIPTION_VERSION)
for name, value in sorted(material_description.items(), key=lambda x: x[0]):
try:
material_description_bytes.extend(encode_value(to_bytes(name)))
material_description_bytes.... | Serialize a material description dictionary into a DynamodDB attribute.
:param dict material_description: Material description dictionary
:returns: Serialized material description as a DynamoDB binary attribute value
:rtype: dict
:raises InvalidMaterialDescriptionError: if invalid name or value found i... |
def parse_name(name):
inverted, op = False, OP_EQ
if name is not None:
for op_ in (OP_NIN, OP_IN, OP_NOT, OP_LIKE):
if name.endswith(op_):
op = op_
name = name[:len(name) - len(op)]
break
if name.startswith('!'):
inverted = ... | Split a query name into field name, operator and whether it is
inverted. |
def Gamma(cls,
shape: 'TensorFluent',
scale: 'TensorFluent',
batch_size: Optional[int] = None) -> Tuple[Distribution, 'TensorFluent']:
if shape.scope != scale.scope:
raise ValueError('Gamma distribution: parameters must have same scope!')
concentration = s... | Returns a TensorFluent for the Gamma sampling op with given shape and scale parameters.
Args:
shape: The shape parameter of the Gamma distribution.
scale: The scale parameter of the Gamma distribution.
batch_size: The size of the batch (optional).
Returns:
... |
def fitness_vs(self):
"Median Fitness in the validation set"
l = [x.fitness_vs for x in self.models]
return np.median(l) | Median Fitness in the validation set |
def cache(self, refreshing=None, next_action=None, data_blob=None, json_last_refresh=None, rollback_point=False):
LOGGER.debug("InjectorComponentSkeleton.cache")
if json_last_refresh is None:
json_last_refresh = datetime.datetime.now()
if rollback_point:
self.rollback_poi... | push this component into the cache
:param refreshing: the new refreshing value
:param next_action: the new next action value
:param data_blob: the new data blob value
:param json_last_refresh: the new json last refresh value - if None the date of this call
:param rollback_point:... |
def to_params(self):
params = {}
for name in self.PROPERTIES:
attr = '_{0}'.format(name)
value = getattr(self, attr, None) or getattr(self, name, None)
if value is None:
continue
if isinstance(value, datetime):
params[name] ... | Generates a Hash of property values for the current object. This helper
handles all necessary type coercions as it generates its output. |
def ListGrrUsers(self):
args = user_management_pb2.ApiListGrrUsersArgs()
items = self._context.SendIteratorRequest("ListGrrUsers", args)
return utils.MapItemsIterator(
lambda data: GrrUser(data=data, context=self._context), items) | Lists all registered GRR users. |
def stage_subset(self, *files_to_add: str):
LOGGER.info('staging files: %s', files_to_add)
self.repo.git.add(*files_to_add, A=True) | Stages a subset of files
:param files_to_add: files to stage
:type files_to_add: str |
def setCurrentIndex(self, index):
if self._currentIndex == index:
return
self._currentIndex = index
self.currentIndexChanged.emit(index)
for i, item in enumerate(self.items()):
item.setMenuEnabled(i == index)
self.repaint() | Sets the current item to the item at the inputed index.
:param index | <int> |
def import_package(rel_path_to_package, package_name):
try:
curr_dir = os.path.dirname(os.path.realpath(__file__))
except NameError:
curr_dir = os.path.dirname(os.path.realpath(os.getcwd()))
package_path = os.path.join(curr_dir, rel_path_to_package)
if package_path not in sys.path:
... | Imports a python package into the current namespace.
Parameters
----------
rel_path_to_package : str
Path to the package containing director relative from this script's
directory.
package_name : str
The name of the package to be imported.
Returns
---------
package :... |
def profiles(self):
raw_profiles = self.account.service.management().profiles().list(
accountId=self.account.id,
webPropertyId=self.id).execute()['items']
profiles = [Profile(raw, self) for raw in raw_profiles]
return addressable.List(profiles, indices=['id', 'name'], ins... | A list of all profiles on this web property. You may
select a specific profile using its name, its id
or an index.
```python
property.profiles[0]
property.profiles['9234823']
property.profiles['marketing profile']
``` |
def get_max_events_in_both_arrays(events_one, events_two):
events_one = np.ascontiguousarray(events_one)
events_two = np.ascontiguousarray(events_two)
event_result = np.empty(shape=(events_one.shape[0] + events_two.shape[0], ), dtype=events_one.dtype)
count = analysis_functions.get_max_events_in_both_ar... | Calculates the maximum count of events that exist in both arrays. |
def merge_all_cells(cells):
current = 0
while len(cells) > 1:
count = 0
while count < len(cells):
cell1 = cells[current]
cell2 = cells[count]
merge_direction = get_merge_direction(cell1, cell2)
if not merge_direction == "NONE":
merg... | Loop through list of cells and piece them together one by one
Parameters
----------
cells : list of dashtable.data2rst.Cell
Returns
-------
grid_table : str
The final grid table |
def Disks(self):
if not self.disks: self.disks = clc.v2.Disks(server=self,disks_lst=self.data['details']['disks'],session=self.session)
return(self.disks) | Return disks object associated with server.
>>> clc.v2.Server("WA1BTDIX01").Disks()
<clc.APIv2.disk.Disks object at 0x10feea190> |
def handle_initialize(self, data):
logger.info('start to handle_initialize')
self.handle_update_search_space(data)
if self.search_space:
self.cg = CG_BOHB(configspace=self.search_space,
min_points_in_model=self.min_points_in_model,
... | Initialize Tuner, including creating Bayesian optimization-based parametric models
and search space formations
Parameters
----------
data: search space
search space of this experiment
Raises
------
ValueError
Error: Search space is None |
def publish_proto_in_ipfs(self):
ipfs_hash_base58 = utils_ipfs.publish_proto_in_ipfs(self._get_ipfs_client(), self.args.protodir)
self._printout(ipfs_hash_base58) | Publish proto files in ipfs and print hash |
def trt_pmf(matrices):
ntrts, nmags, ndists, nlons, nlats, neps = matrices.shape
pmf = numpy.zeros(ntrts)
for t in range(ntrts):
pmf[t] = 1. - numpy.prod(
[1. - matrices[t, i, j, k, l, m]
for i in range(nmags)
for j in range(ndists)
for k in range(n... | Fold full disaggregation matrix to tectonic region type PMF.
:param matrices:
a matrix with T submatrices
:returns:
an array of T probabilities one per each tectonic region type |
def from_json(cls, json):
obj = cls(key_range.KeyRange.from_json(json["key_range"]),
model.QuerySpec.from_json(json["query_spec"]))
cursor = json["cursor"]
if cursor and json["cursor_object"]:
obj._cursor = datastore_query.Cursor.from_websafe_string(cursor)
else:
obj._cursor = ... | Reverse of to_json. |
def allReadGroups(self):
for dataset in self.getDatasets():
for readGroupSet in dataset.getReadGroupSets():
for readGroup in readGroupSet.getReadGroups():
yield readGroup | Return an iterator over all read groups in the data repo |
def summary_pairwise_indices(self):
summary_pairwise_indices = np.empty(
self.values[0].t_stats.shape[1], dtype=object
)
summary_pairwise_indices[:] = [
sig.summary_pairwise_indices for sig in self.values
]
return summary_pairwise_indices | ndarray containing tuples of pairwise indices for the column summary. |
def check_gcdt_update():
try:
inst_version, latest_version = get_package_versions('gcdt')
if inst_version < latest_version:
log.warn('Please consider an update to gcdt version: %s' %
latest_version)
except GracefulExit:
raise
except Except... | Check whether a newer gcdt is available and output a warning. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.