code stringlengths 59 4.4k | docstring stringlengths 5 7.69k |
|---|---|
def create_template(
self,
name,
subject,
html,
text='',
timeout=None
):
payload = {
'name': name,
'subject': subject,
'html': html,
'text': text
}
return self._api_request(
self.TEMPL... | API call to create a template |
def create_full_tear_sheet(returns,
positions=None,
transactions=None,
market_data=None,
benchmark_rets=None,
slippage=None,
live_start_date=None,
... | Generate a number of tear sheets that are useful
for analyzing a strategy's performance.
- Fetches benchmarks if needed.
- Creates tear sheets for returns, and significant events.
If possible, also creates tear sheets for position analysis,
transaction analysis, and Bayesian analysis.
... |
def _execute(self, command, data=None, unpack=True):
if not data:
data = {}
if self.session_id is not None:
data.setdefault('session_id', self.session_id)
data = self._wrap_el(data)
res = self.remote_invoker.execute(command, data)
ret = WebDriverResult.fro... | Private method to execute command.
Args:
command(Command): The defined command.
data(dict): The uri variable and body.
uppack(bool): If unpack value from result.
Returns:
The unwrapped value field in the json response. |
def unmasked_blurred_image_of_galaxies_from_psf(self, padded_grid_stack, psf):
return [padded_grid_stack.unmasked_blurred_image_from_psf_and_unmasked_image(
psf, image) if not galaxy.has_pixelization else None for galaxy, image in
zip(self.galaxies, self.image_plane_image_1d_of_galax... | This is a utility function for the function above, which performs the iteration over each plane's galaxies \
and computes each galaxy's unmasked blurred image.
Parameters
----------
padded_grid_stack
psf : ccd.PSF
The PSF of the image used for convolution. |
def get_catalog(self, catalog_id):
return self._load_data(
self.CATALOGS_ENDPOINT,
default=[],
resource_id=catalog_id
) | Return specified course catalog.
Returns:
dict: catalog details if it is available for the user. |
def _calcDistance(self, inputPattern, distanceNorm=None):
if distanceNorm is None:
distanceNorm = self.distanceNorm
if self.useSparseMemory:
if self._protoSizes is None:
self._protoSizes = self._Memory.rowSums()
overlapsWithProtos = self._Memory.rightVecSumAtNZ(inputPattern)
inpu... | Calculate the distances from inputPattern to all stored patterns. All
distances are between 0.0 and 1.0
:param inputPattern The pattern from which distances to all other patterns
are calculated
:param distanceNorm Degree of the distance norm |
def get_sources(self, component_id):
StreamId = namedtuple('StreamId', 'id, component_name')
if component_id in self.inputs:
ret = {}
for istream in self.inputs.get(component_id):
key = StreamId(id=istream.stream.id, component_name=istream.stream.component_name)
ret[key] = istream.gt... | Returns the declared inputs to specified component
:return: map <streamId namedtuple (same structure as protobuf msg) -> gtype>, or
None if not found |
def do_fullscreen(self, line):
self.bot.canvas.sink.trigger_fullscreen_action(True)
print(self.response_prompt, file=self.stdout) | Make the current window fullscreen |
def tryLoadingFrom(tryPath,moduleName='swhlab'):
if not 'site-packages' in swhlab.__file__:
print("loaded custom swhlab module from",
os.path.dirname(swhlab.__file__))
return
while len(tryPath)>5:
sp=tryPath+"/swhlab/"
if os.path.isdir(sp) and os.path.exists(sp+"/__... | if the module is in this path, load it from the local folder. |
def FindExtensionByName(self, full_name):
full_name = _NormalizeFullyQualifiedName(full_name)
message_name, _, extension_name = full_name.rpartition('.')
try:
scope = self.FindMessageTypeByName(message_name)
except KeyError:
scope = self.FindFileContainingSymbol(full_name)
return scope.e... | Loads the named extension descriptor from the pool.
Args:
full_name: The full name of the extension descriptor to load.
Returns:
A FieldDescriptor, describing the named extension. |
def is_length(self, length):
if type(length) is not int:
raise TypeError('given arg must be an int')
if length < 0:
raise ValueError('given arg must be a positive int')
if len(self.val) != length:
self._err('Expected <%s> to be of length <%d>, but was <%d>.' %... | Asserts that val is the given length. |
def make_key(*args, **kwargs):
sep = kwargs.get('sep', u"_")
exclude_last_string = kwargs.get('exclude_last_string', False)
string_array = []
for arg in args:
if isinstance(arg, list):
string_array.append(six.text_type(sep.join(arg)))
else:
if exclude_last_string:... | Given any number of lists and strings will join them in order as one
string separated by the sep kwarg. sep defaults to u"_".
Add exclude_last_string=True as a kwarg to exclude the last item in a
given string after being split by sep. Note if you only have one word
in your string you can end up getti... |
def plot_gross_leverage(returns, positions, ax=None, **kwargs):
if ax is None:
ax = plt.gca()
gl = timeseries.gross_lev(positions)
gl.plot(lw=0.5, color='limegreen', legend=False, ax=ax, **kwargs)
ax.axhline(gl.mean(), color='g', linestyle='--', lw=3)
ax.set_title('Gross leverage')
ax.se... | Plots gross leverage versus date.
Gross leverage is the sum of long and short exposure per share
divided by net asset value.
Parameters
----------
returns : pd.Series
Daily returns of the strategy, noncumulative.
- See full explanation in tears.create_full_tear_sheet.
position... |
def starts_with(self, prefix):
if prefix is None:
raise TypeError('given prefix arg must not be none')
if isinstance(self.val, str_types):
if not isinstance(prefix, str_types):
raise TypeError('given prefix arg must be a string')
if len(prefix) == 0:
... | Asserts that val is string or iterable and starts with prefix. |
def parsestr(self, argstr):
argv = shlex.split(argstr, comments=True)
if len(argv) != 1:
raise BadNumberOfArguments(1, len(argv))
arg = argv[0]
lower = arg.lower()
if lower in self.true:
return True
if lower in self.false:
return False
... | Parse arguments found in settings files.
Use the values in self.true for True in settings files, or those in
self.false for False, case insensitive. |
def create_switch(apps, schema_editor):
Switch = apps.get_model('waffle', 'Switch')
Switch.objects.get_or_create(name='SAP_USE_ENTERPRISE_ENROLLMENT_PAGE', defaults={'active': False}) | Create and activate the SAP_USE_ENTERPRISE_ENROLLMENT_PAGE switch if it does not already exist. |
def atime(self):
try:
return self._stat.st_atime
except:
self._stat = self.stat()
return self.atime | Get most recent access time in timestamp. |
def sim_euclidean(src, tar, qval=2, alphabet=None):
return Euclidean().sim(src, tar, qval, alphabet) | Return the normalized Euclidean similarity of two strings.
This is a wrapper for :py:meth:`Euclidean.sim`.
Parameters
----------
src : str
Source string (or QGrams/Counter objects) for comparison
tar : str
Target string (or QGrams/Counter objects) for comparison
qval : int
... |
def count(cls, session: Optional[Session] = None) -> int:
if session is None:
session = _make_session()
count = session.query(cls).count()
session.close()
return count | Count all actions. |
def get(self, list_id, segment_id):
return self._mc_client._get(url=self._build_path(list_id, 'segments', segment_id)) | returns the specified list segment. |
def execute(helper, config, args):
if not helper.application_exists():
helper.create_application(get(config, 'app.description'))
else:
out("Application "+get(config, 'app.app_name')+" exists")
environment_names = []
environments_to_wait_for_green = []
for env_name, env_config in list... | The init command |
def sys_fsync(self, fd):
ret = 0
try:
self.files[fd].sync()
except IndexError:
ret = -errno.EBADF
except FdError:
ret = -errno.EINVAL
return ret | Synchronize a file's in-core state with that on disk. |
def mask_circular_annular_from_shape_pixel_scale_and_radii(shape, pixel_scale, inner_radius_arcsec, outer_radius_arcsec,
centre=(0.0, 0.0)):
mask = np.full(shape, True)
centres_arcsec = mask_centres_from_shape_pixel_scale_and_centre(shape=mask.shape, pi... | Compute an annular masks from an input inner and outer masks radius and regular shape. |
def read_bytes(self, where, size, force=False):
result = []
for i in range(size):
result.append(Operators.CHR(self.read_int(where + i, 8, force)))
return result | Read from memory.
:param int where: address to read data from
:param int size: number of bytes
:param force: whether to ignore memory permissions
:return: data
:rtype: list[int or Expression] |
def acquire(self, blocking=1):
me = _get_ident()
if self.__owner == me:
self.__count = self.__count + 1
if __debug__:
self._note("%s.acquire(%s): recursive success", self, blocking)
return 1
rc = self.__block.acquire(blocking)
if rc:
... | Acquire a lock, blocking or non-blocking.
When invoked without arguments: if this thread already owns the lock,
increment the recursion level by one, and return immediately. Otherwise,
if another thread owns the lock, block until the lock is unlocked. Once
the lock is unlocked (not owne... |
def events(self, **kwargs):
return self.__api.events(query=EqualsOperator("report", self.hash_),
**kwargs) | Get all events for this report. Additional arguments may also be
specified that will be passed to the query function. |
def from_spec(spec, kwargs=None):
optimizer = util.get_object(
obj=spec,
predefined_objects=tensorforce.core.optimizers.optimizers,
kwargs=kwargs
)
assert isinstance(optimizer, Optimizer)
return optimizer | Creates an optimizer from a specification dict. |
def distances(self):
distances = []
for label in self.labels:
joint = self.joints.get(label)
distances.append([np.nan, np.nan, np.nan] if joint is None else
np.array(joint.getAnchor()) - joint.getAnchor2())
return np.array(distances) | Get a list of the distances between markers and their attachments.
Returns
-------
distances : ndarray of shape (num-markers, 3)
Array of distances for each marker joint in our attachment setup. If
a marker does not currently have an associated joint (e.g. because
... |
def plot_monthly_returns_timeseries(returns, ax=None, **kwargs):
def cumulate_returns(x):
return ep.cum_returns(x)[-1]
if ax is None:
ax = plt.gca()
monthly_rets = returns.resample('M').apply(lambda x: cumulate_returns(x))
monthly_rets = monthly_rets.to_period()
sns.barplot(x=monthly... | Plots monthly returns as a timeseries.
Parameters
----------
returns : pd.Series
Daily returns of the strategy, noncumulative.
- See full explanation in tears.create_full_tear_sheet.
ax : matplotlib.Axes, optional
Axes upon which to plot.
**kwargs, optional
Passed t... |
def crop_multi(x, wrg, hrg, is_random=False, row_index=0, col_index=1):
h, w = x[0].shape[row_index], x[0].shape[col_index]
if (h < hrg) or (w < wrg):
raise AssertionError("The size of cropping should smaller than or equal to the original image")
if is_random:
h_offset = int(np.random.unifor... | Randomly or centrally crop multiple images.
Parameters
----------
x : list of numpy.array
List of images with dimension of [n_images, row, col, channel] (default).
others : args
See ``tl.prepro.crop``.
Returns
-------
numpy.array
A list of processed images. |
def convert_adaptive_max_pool2d(params, w_name, scope_name, inputs, layers, weights, names):
print('Converting adaptive_avg_pool2d...')
if names == 'short':
tf_name = 'APOL' + random_string(4)
elif names == 'keep':
tf_name = w_name
else:
tf_name = w_name + str(random.random())
... | Convert convert_adaptive_max_pool2d layer.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use... |
def get_catalog_options(self):
if hasattr(self.instance, 'site'):
catalog_api = CourseCatalogApiClient(self.user, self.instance.site)
else:
catalog_api = CourseCatalogApiClient(self.user)
catalogs = catalog_api.get_all_catalogs()
catalogs = sorted(catalogs, key=la... | Retrieve a list of catalog ID and name pairs.
Once retrieved, these name pairs can be used directly as a value
for the `choices` argument to a ChoiceField. |
def update_desc_lsib_path(desc):
if(desc['sib_seq']>0):
lsib_path = copy.deepcopy(desc['path'])
lsib_path[-1] = desc['sib_seq']-1
desc['lsib_path'] = lsib_path
else:
pass
return(desc) | leftSibling
previousSibling
leftSib
prevSib
lsib
psib
have the same parent,and on the left |
def marketNewsDF(count=10, token='', version=''):
df = pd.DataFrame(marketNews(count, token, version))
_toDatetime(df)
_reindex(df, 'datetime')
return df | News about market
https://iexcloud.io/docs/api/#news
Continuous
Args:
count (int): limit number of results
token (string); Access token
version (string); API version
Returns:
DataFrame: result |
def order(cls, query, field, s):
if s == 'asc':
query = query.order_by(asc(field))
elif s == 'desc':
query = query.order_by(desc(field))
return query | Modify query as so to order the results.
:param query: Query object.
:param str s: Orderinig: ``asc`` or ``desc``.
:returs: Query object. |
def save_model(self, request, obj, form, change):
obj.author = request.user
obj.save() | Set currently authenticated user as the author of the gallery. |
def tsne_embedding(embeddings, reverse_dictionary, plot_only=500, second=5, saveable=False, name='tsne', fig_idx=9862):
import matplotlib.pyplot as plt
def plot_with_labels(low_dim_embs, labels, figsize=(18, 18), second=5, saveable=True, name='tsne', fig_idx=9862):
if low_dim_embs.shape[0] < len(labels)... | Visualize the embeddings by using t-SNE.
Parameters
----------
embeddings : numpy.array
The embedding matrix.
reverse_dictionary : dictionary
id_to_word, mapping id to unique word.
plot_only : int
The number of examples to plot, choice the most common words.
second : int... |
def PushPopItem(obj, key, value):
if key in obj:
old_value = obj[key]
obj[key] = value
yield value
obj[key] = old_value
else:
obj[key] = value
yield value
del obj[key] | A context manager to replace and restore a value using a getter and setter.
:param object obj: The object to replace/restore.
:param object key: The key to replace/restore in the object.
:param object value: The value to replace.
Example::
with PushPop2(sys.modules, 'alpha', None):
pyte... |
def setup_mpi_gpus():
if 'CUDA_VISIBLE_DEVICES' not in os.environ:
if sys.platform == 'darwin':
ids = []
else:
lrank, _lsize = get_local_rank_size(MPI.COMM_WORLD)
ids = [lrank]
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, ids)) | Set CUDA_VISIBLE_DEVICES to MPI rank if not already set |
def enumerate_device_serials(vid=FT232H_VID, pid=FT232H_PID):
try:
ctx = None
ctx = ftdi.new()
device_list = None
count, device_list = ftdi.usb_find_all(ctx, vid, pid)
if count < 0:
raise RuntimeError('ftdi_usb_find_all returned error {0}: {1}'.format(count, ftdi.... | Return a list of all FT232H device serial numbers connected to the
machine. You can use these serial numbers to open a specific FT232H device
by passing it to the FT232H initializer's serial parameter. |
def get_newest_possible_languagetool_version():
java_path = find_executable('java')
if not java_path:
return JAVA_6_COMPATIBLE_VERSION
output = subprocess.check_output([java_path, '-version'],
stderr=subprocess.STDOUT,
univers... | Return newest compatible version.
>>> version = get_newest_possible_languagetool_version()
>>> version in [JAVA_6_COMPATIBLE_VERSION,
... JAVA_7_COMPATIBLE_VERSION,
... LATEST_VERSION]
True |
def decode(in_file, out_file=None, mode=None, quiet=0):
opened_files = []
if in_file == '-':
in_file = sys.stdin
elif isinstance(in_file, basestring):
in_file = open(in_file)
opened_files.append(in_file)
try:
while True:
hdr = in_file.readline()
if... | Decode uuencoded file |
def deserialize_assign(self, workflow, start_node):
name = start_node.getAttribute('name')
attrib = start_node.getAttribute('field')
value = start_node.getAttribute('value')
kwargs = {}
if name == '':
_exc('name attribute required')
if attrib != '' and value !... | Reads the "pre-assign" or "post-assign" tag from the given node.
start_node -- the xml node (xml.dom.minidom.Node) |
def _decrypt(self, value, encrypted_value):
if sys.platform == 'win32':
return self._decrypt_windows_chrome(value, encrypted_value)
if value or (encrypted_value[:3] != b'v10'):
return value
encrypted_value = encrypted_value[3:]
encrypted_value_half_len = int(len(e... | Decrypt encoded cookies |
def _disconnect_user_post_save_for_migrations(self, sender, **kwargs):
from django.db.models.signals import post_save
post_save.disconnect(sender=self.auth_user_model, dispatch_uid=USER_POST_SAVE_DISPATCH_UID) | Handle pre_migrate signal - disconnect User post_save handler. |
def predict(self, data, graph=None, nruns=6, njobs=None, gpus=0, verbose=None,
plot=False, plot_generated_pair=False, return_list_results=False):
verbose, njobs = SETTINGS.get_default(('verbose', verbose), ('nb_jobs', njobs))
if njobs != 1:
list_out = Parallel(n_jobs=njobs)(d... | Execute SAM on a dataset given a skeleton or not.
Args:
data (pandas.DataFrame): Observational data for estimation of causal relationships by SAM
skeleton (numpy.ndarray): A priori knowledge about the causal relationships as an adjacency matrix.
Can be fed either d... |
def ac2poly(data):
a, e, _c = LEVINSON(data)
a = numpy.insert(a, 0, 1)
return a, e | Convert autocorrelation sequence to prediction polynomial
:param array data: input data (list or numpy.array)
:return:
* AR parameters
* noise variance
This is an alias to::
a, e, c = LEVINSON(data)
:Example:
.. doctest::
>>> from spectrum import ac2poly
... |
def plot_daily_turnover_hist(transactions, positions,
ax=None, **kwargs):
if ax is None:
ax = plt.gca()
turnover = txn.get_turnover(positions, transactions)
sns.distplot(turnover, ax=ax, **kwargs)
ax.set_title('Distribution of daily turnover rates')
ax.set_xlabel... | Plots a histogram of daily turnover rates.
Parameters
----------
transactions : pd.DataFrame
Prices and amounts of executed trades. One row per trade.
- See full explanation in tears.create_full_tear_sheet.
positions : pd.DataFrame
Daily net position values.
- See full... |
def _add_tc_script(self):
context = dict(tc_options=self.config.get('tc_options', []))
contents = self._render_template('tc_script.sh', context)
self.config.setdefault('files', [])
self._add_unique_file({
"path": "/tc_script.sh",
"contents": contents,
... | generates tc_script.sh and adds it to included files |
def print_file_info():
tpl = TableLogger(columns='file,created,modified,size')
for f in os.listdir('.'):
size = os.stat(f).st_size
date_created = datetime.fromtimestamp(os.path.getctime(f))
date_modified = datetime.fromtimestamp(os.path.getmtime(f))
tpl(f, date_created, date_modi... | Prints file details in the current directory |
def get_dict(self):
return dict(
current_page=self.current_page,
total_page_count=self.total_page_count,
items=self.items,
total_item_count=self.total_item_count,
page_size=self.page_size
) | Convert Paginator instance to dict
:return: Paging data
:rtype: dict |
def py_hash(key, num_buckets):
b, j = -1, 0
if num_buckets < 1:
raise ValueError('num_buckets must be a positive number')
while j < num_buckets:
b = int(j)
key = ((key * long(2862933555777941757)) + 1) & 0xffffffffffffffff
j = float(b + 1) * (float(1 << 31) / float((key >> 33... | Generate a number in the range [0, num_buckets).
Args:
key (int): The key to hash.
num_buckets (int): Number of buckets to use.
Returns:
The bucket number `key` computes to.
Raises:
ValueError: If `num_buckets` is not a positive number. |
def read(self, path):
with open(path, "rb") as fout:
memmove(self.m_buf, fout.read(self.m_size), self.m_size) | Read file to buffer |
def replace(self, year=None, month=None, day=None):
if year is None:
year = self._year
if month is None:
month = self._month
if day is None:
day = self._day
return date.__new__(type(self), year, month, day) | Return a new date with new values for the specified fields. |
def reset_creation_info(self):
self.created_date_set = False
self.creation_comment_set = False
self.lics_list_ver_set = False | Resets builder state to allow building new creation info. |
def get_unweighted_sources(graph: BELGraph, key: Optional[str] = None) -> Iterable[BaseEntity]:
if key is None:
key = WEIGHT
for node in graph:
if is_unweighted_source(graph, node, key):
yield node | Get nodes on the periphery of the sub-graph that do not have a annotation for the given key.
:param graph: A BEL graph
:param key: The key in the node data dictionary representing the experimental data
:return: An iterator over BEL nodes that are unannotated and on the periphery of this subgraph |
def getMetricDetails(self, metricLabel):
try:
metricIndex = self.__metricLabels.index(metricLabel)
except IndexError:
return None
return self.__metrics[metricIndex].getMetric() | Gets detailed info about a given metric, in addition to its value. This
may including any statistics or auxilary data that are computed for a given
metric.
:param metricLabel: (string) label of the given metric (see
:class:`~nupic.frameworks.opf.metrics.MetricSpec`)
:returns: (dict) of met... |
def cmd_events(opts):
config = load_config(opts.config)
b = get_blockade(config, opts)
if opts.json:
outf = None
_write = puts
if opts.output is not None:
outf = open(opts.output, "w")
_write = outf.write
try:
delim = ""
logs = ... | Get the event log for a given blockade |
def keys(self):
return self.options.keys() + [p.name for p in self.positional_args] | List names of options and positional arguments. |
def group(*args):
if args and isinstance(args[0], dataframe.DataFrame):
return args[0].group(*args[1:])
elif not args:
raise ValueError("No arguments provided")
else:
return pipeable.Pipeable(pipeable.PipingMethod.GROUP, *args) | Pipeable grouping method.
Takes either
- a dataframe and a tuple of strings for grouping,
- a tuple of strings if a dataframe has already been piped into.
:Example:
group(dataframe, "column")
:Example:
dataframe >> group("column")
:param args: tuple of a... |
def saveToExternal(self, redisCon):
if type(redisCon) == dict:
conn = redis.Redis(**redisCon)
elif hasattr(conn, '__class__') and issubclass(conn.__class__, redis.Redis):
conn = redisCon
else:
raise ValueError('saveToExternal "redisCon" param must either be a dictionary of connection parameters, or redis... | saveToExternal - Saves this object to a different Redis than that specified by REDIS_CONNECTION_PARAMS on this model.
@param redisCon <dict/redis.Redis> - Either a dict of connection params, a la REDIS_CONNECTION_PARAMS, or an existing Redis connection.
If you are doing a lot of bulk copies, it is recommended t... |
def connect_to(self, joint, other_body, offset=(0, 0, 0), other_offset=(0, 0, 0),
**kwargs):
anchor = self.world.move_next_to(self, other_body, offset, other_offset)
self.world.join(joint, self, other_body, anchor=anchor, **kwargs) | Move another body next to this one and join them together.
This method will move the ``other_body`` so that the anchor points for
the joint coincide. It then creates a joint to fasten the two bodies
together. See :func:`World.move_next_to` and :func:`World.join`.
Parameters
---... |
def print_table(table,
name=None,
float_format=None,
formatters=None,
header_rows=None):
if isinstance(table, pd.Series):
table = pd.DataFrame(table)
if name is not None:
table.columns.name = name
html = table.to_html(float_form... | Pretty print a pandas DataFrame.
Uses HTML output if running inside Jupyter Notebook, otherwise
formatted text output.
Parameters
----------
table : pandas.Series or pandas.DataFrame
Table to pretty-print.
name : str, optional
Table name to display in upper left corner.
flo... |
def env_to_dict(env, pathsep=os.pathsep):
out_dict = {}
for k, v in env.iteritems():
if pathsep in v:
out_dict[k] = v.split(pathsep)
else:
out_dict[k] = v
return out_dict | Convert a dict containing environment variables into a standard dict.
Variables containing multiple values will be split into a list based on
the argument passed to pathsep.
:param env: Environment dict like os.environ.data
:param pathsep: Path separator used to split variables |
def package_for_editor_signavio(self, spec, filename):
signavio_file = filename[:-len('.bpmn20.xml')] + '.signavio.xml'
if os.path.exists(signavio_file):
self.write_file_to_package_zip(
"src/" + self._get_zip_path(signavio_file), signavio_file)
f = open(signavio_f... | Adds the SVG files to the archive for this BPMN file. |
def paste(tid=None, review=False):
submit(pastebin=True, tid=tid, review=False) | Sends the selected exercise to the TMC pastebin. |
def loadtxt2(fname, dtype=None, delimiter=' ', newline='\n', comment_character='
skiplines=0):
dtypert = [None, None, None]
def preparedtype(dtype):
dtypert[0] = dtype
flatten = flatten_dtype(dtype)
dtypert[1] = flatten
dtypert[2] = numpy.dtype([('a', (numpy.int8,
... | Known issues delimiter and newline is not respected.
string quotation with space is broken. |
def receive_one(self):
if not self.isopen:
logger = logging.getLogger(__name__)
logger.warning('the drop box is not open')
return
return self.dropbox.receive_one() | return a pair of an ID and a result of a task.
This method waits for a task to finish.
Returns
-------
An ID and a result of a task. `None` if no task is running. |
def icon_from_typename(name, icon_type):
ICONS = {
'CLASS': ICON_CLASS,
'IMPORT': ICON_NAMESPACE,
'STATEMENT': ICON_VAR,
'FORFLOW': ICON_VAR,
'FORSTMT': ICON_VAR,
'WITHSTMT': ICON_VAR,
'GLOBALSTMT': ICON_VAR,
'MODULE': ICON_NAMESPACE,
'KEYWORD'... | Returns the icon resource filename that corresponds to the given typename.
:param name: name of the completion. Use to make the distinction between
public and private completions (using the count of starting '_')
:pram typename: the typename reported by jedi
:returns: The associate icon resource f... |
def _store(self, offset, value, size=1):
self.memory.write_BE(offset, value, size)
for i in range(size):
self._publish('did_evm_write_memory', offset + i, Operators.EXTRACT(value, (size - i - 1) * 8, 8)) | Stores value in memory as a big endian |
def calc_J(self):
r0 = self.state.residuals.copy().ravel()
dl = np.zeros(self.param_vals.size)
p0 = self.param_vals.copy()
J = []
for a in range(self.param_vals.size):
dl *= 0
dl[a] += self.dl
self.update_function(p0 + dl)
r1 = self... | Calculates J along the direction. |
def get_enterprise_sso_uid(self, obj):
enterprise_learner = EnterpriseCustomerUser.objects.filter(user_id=obj.id).first()
return enterprise_learner and enterprise_learner.get_remote_id() | Get enterprise SSO UID.
Arguments:
obj (User): Django User object
Returns:
(str): string containing UUID for enterprise customer's Identity Provider. |
def batch_process(
self, zoom=None, tile=None, multi=cpu_count(), max_chunksize=1
):
list(self.batch_processor(zoom, tile, multi, max_chunksize)) | Process a large batch of tiles.
Parameters
----------
process : MapcheteProcess
process to be run
zoom : list or int
either single zoom level or list of minimum and maximum zoom level;
None processes all (default: None)
tile : tuple
... |
def _get_log(self, limit=None):
self.ui.pushbuffer()
commands.log(self.ui, self.repo, limit=limit, date=None, rev=None, user=None)
res = self.ui.popbuffer().strip()
logList = []
for logentry in res.split("\n\n"):
log = {}
logList.append(log)
fo... | Read log entries into a list of dictionaries. |
def chain(*args):
def chain_block(*args, **kwargs):
v = args[0](*args, **kwargs)
for p in args[1:]:
v = p(v)
return v
return chain_block | Runs a series of parsers in sequence passing the result of each parser to the next.
The result of the last parser is returned. |
def attach(self, frame_no):
assert not self.joints
for label, j in self.channels.items():
target = self.targets.get(label)
if target is None:
continue
if self.visibility[frame_no, j] < 0:
continue
if np.linalg.norm(self.velo... | Attach marker bodies to the corresponding skeleton bodies.
Attachments are only made for markers that are not in a dropout state in
the given frame.
Parameters
----------
frame_no : int
The frame of data we will use for attaching marker bodies. |
def normalize_magseries(times,
mags,
mingap=4.0,
normto='globalmedian',
magsarefluxes=False,
debugmode=False):
ngroups, timegroups = find_lc_timegroups(times,
... | This normalizes the magnitude time-series to a specified value.
This is used to normalize time series measurements that may have large time
gaps and vertical offsets in mag/flux measurement between these
'timegroups', either due to instrument changes or different filters.
NOTE: this works in-place! Th... |
def import_demo_experience(self, states, internals, actions, terminal, reward):
fetches = self.import_demo_experience_output
feed_dict = self.get_feed_dict(
states=states,
internals=internals,
actions=actions,
terminal=terminal,
reward=reward
... | Stores demonstrations in the demo memory. |
def handle_err(self):
with self.lock:
if self._state == 'connecting' and self._dst_addrs:
self._hup = False
self._set_state("connect")
return
self._socket.close()
self._socket = None
self._set_state("aborted")
... | Handle an error reported. |
def event_choices(events):
if events is None:
msg = "Please add some events in settings.WEBHOOK_EVENTS."
raise ImproperlyConfigured(msg)
try:
choices = [(x, x) for x in events]
except TypeError:
msg = "settings.WEBHOOK_EVENTS must be an iterable object."
raise Imprope... | Get the possible events from settings |
def decorate(msg="", waitmsg="Please wait"):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
spin = Spinner(msg=msg, waitmsg=waitmsg)
spin.start()
a = None
try:
a = func(*args, *... | Decorated methods progress will be displayed to the user as a spinner.
Mostly for slower functions that do some network IO. |
def set_default_viewport(self):
expected_height = int(self.buffer_width / self.aspect_ratio)
blank_space = self.buffer_height - expected_height
self.fbo.viewport = (0, blank_space // 2, self.buffer_width, expected_height) | Calculates the viewport based on the configured aspect ratio in settings.
Will add black borders if the window do not match the viewport. |
def _create_bound(model, reaction, bound_type, f_replace, units=None,
flux_udef=None):
value = getattr(reaction, bound_type)
if value == config.lower_bound:
return LOWER_BOUND_ID
elif value == 0:
return ZERO_BOUND_ID
elif value == config.upper_bound:
return UPPE... | Creates bound in model for given reaction.
Adds the parameters for the bounds to the SBML model.
Parameters
----------
model : libsbml.Model
SBML model instance
reaction : cobra.core.Reaction
Cobra reaction instance from which the bounds are read.
bound_type : {LOWER_BOUND, UPP... |
def parse(self, native):
if not hasattr(self, 'parser') or not self.parser:
raise NotImplementedError('Parser class not specified')
parser = self.parser(native)
self.intermediate_data = parser.intermediate_data
del parser
self.to_netjson() | Parses a native configuration and converts
it to a NetJSON configuration dictionary |
def look_at(self, vec=None, pos=None):
if pos is None:
vec = Vector3(pos)
if vec is None:
raise ValueError("vector or pos must be set")
return self._gl_look_at(self.position, vec, self._up) | Look at a specific point
:param vec: Vector3 position
:param pos: python list [x, y, x]
:return: Camera matrix |
def contours(
self, elevation, interval=100, field='elev', base=0
):
return commons_contours.extract_contours(
elevation, self.tile, interval=interval, field=field, base=base) | Extract contour lines from elevation data.
Parameters
----------
elevation : array
input elevation data
interval : integer
elevation value interval when drawing contour lines
field : string
output field name containing elevation value
... |
def grid_stack_from_deflection_stack(grid_stack, deflection_stack):
if deflection_stack is not None:
def minus(grid, deflections):
return grid - deflections
return grid_stack.map_function(minus, deflection_stack) | For a deflection stack, comput a new grid stack but subtracting the deflections |
def convert(self, samplerate=None, n_channels=None, bitdepth=None):
bitdepths = [8, 16, 24, 32, 64]
if bitdepth is not None:
if bitdepth not in bitdepths:
raise ValueError(
"bitdepth must be one of {}.".format(str(bitdepths))
)
... | Converts output audio to the specified format.
Parameters
----------
samplerate : float, default=None
Desired samplerate. If None, defaults to the same as input.
n_channels : int, default=None
Desired number of channels. If None, defaults to the same as input.
... |
def debug(self, msg, *args, **kwargs):
self._baseLogger.debug(self, self.getExtendedMsg(msg), *args, **kwargs) | Log 'msg % args' with severity 'DEBUG'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.debug("Houston, we have a %s", "thorny problem", exc_info=1) |
def add_listener(self, event, listener):
self.emit('new_listener', event, listener)
self._listeners[event].append(listener)
self._check_limit(event)
return self | Bind a listener to a particular event.
Args:
event (str): The name of the event to listen for. This may be any
string value.
listener (def or async def): The callback to execute when the event
fires. This may be a sync or async function. |
def create_transformation(self, rotation=None, translation=None):
mat = None
if rotation is not None:
mat = Matrix44.from_eulers(Vector3(rotation))
if translation is not None:
trans = matrix44.create_from_translation(Vector3(translation))
if mat is None:
... | Creates a transformation matrix woth rotations and translation.
Args:
rotation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`
translation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`
Returns:
A 4x4 matrix as a :py:class:`numpy... |
def gen_length_feats(self, e_set):
text = e_set._text
lengths = [len(e) for e in text]
word_counts = [max(len(t),1) for t in e_set._tokens]
comma_count = [e.count(",") for e in text]
ap_count = [e.count("'") for e in text]
punc_count = [e.count(".") + e.count("?") + e.cou... | Generates length based features from an essay set
Generally an internal function called by gen_feats
Returns an array of length features
e_set - EssaySet object |
def flip_y(self, center=None):
if center is None:
self.poly.flop()
else:
self.poly.flop(center[1])
return self | Flip the shape in the y direction, in-place.
Parameters
----------
center : array-like, optional
Point about which to flip.
If not passed, the center of the shape will be used. |
def mods_genre(self):
type2genre = {
'conference': 'conference publication',
'book chapter': 'bibliography',
'unpublished': 'article'
}
tp = str(self.type).lower()
return type2genre.get(tp, tp) | Guesses an appropriate MODS XML genre type. |
def readattr(path, name):
try:
f = open(USB_SYS_PREFIX + path + "/" + name)
return f.readline().rstrip("\n")
except IOError:
return None | Read attribute from sysfs and return as string |
def send_discovery_packet(self):
if self.port is None:
return
self.transport.sendto(
QRTDiscoveryP1.pack(
QRTDiscoveryPacketSize, QRTPacketType.PacketDiscover.value
)
+ QRTDiscoveryP2.pack(self.port),
("<broadcast>", 22226),
... | Send discovery packet for QTM to respond to |
def action(inner_rule, loc=None):
def decorator(mapper):
@llrule(loc, inner_rule.expected)
def outer_rule(parser):
result = inner_rule(parser)
if result is unmatched:
return result
if isinstance(result, tuple):
return mapper(parser,... | A decorator returning a function that first runs ``inner_rule`` and then, if its
return value is not None, maps that value using ``mapper``.
If the value being mapped is a tuple, it is expanded into multiple arguments.
Similar to attaching semantic actions to rules in traditional parser generators. |
def constraint_matrices(model, array_type='dense', include_vars=False,
zero_tol=1e-6):
if array_type not in ('DataFrame', 'dense') and not dok_matrix:
raise ValueError('Sparse matrices require scipy')
array_builder = {
'dense': np.array, 'dok': dok_matrix, 'lil': lil_matr... | Create a matrix representation of the problem.
This is used for alternative solution approaches that do not use optlang.
The function will construct the equality matrix, inequality matrix and
bounds for the complete problem.
Notes
-----
To accomodate non-zero equalities the problem will add th... |
def get_pending_users_queryset(self, search_keyword, customer_uuid):
queryset = PendingEnterpriseCustomerUser.objects.filter(
enterprise_customer__uuid=customer_uuid
)
if search_keyword is not None:
queryset = queryset.filter(user_email__icontains=search_keyword)
... | Get the list of PendingEnterpriseCustomerUsers we want to render.
Args:
search_keyword (str): The keyword to search for in pending users' email addresses.
customer_uuid (str): A unique identifier to filter down to only pending users
linked to a particular EnterpriseCustomer. |
def remapCategories(self, mapping):
categoryArray = numpy.array(self._categoryList)
newCategoryArray = numpy.zeros(categoryArray.shape[0])
newCategoryArray.fill(-1)
for i in xrange(len(mapping)):
newCategoryArray[categoryArray==i] = mapping[i]
self._categoryList = list(newCategoryArray) | Change the category indices.
Used by the Network Builder to keep the category indices in sync with the
ImageSensor categoryInfo when the user renames or removes categories.
:param mapping: List of new category indices. For example, mapping=[2,0,1]
would change all vectors of category 0 to be categ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.