_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q15400 | Snapserver.delete_client | train | def delete_client(self, identifier):
"""Delete client."""
params = {'id': identifier}
| python | {
"resource": ""
} |
q15401 | Snapserver.synchronize | train | def synchronize(self, status):
"""Synchronize snapserver."""
self._version = status.get('server').get('version')
self._groups = {}
self._clients = {}
self._streams = {}
for stream in status.get('server').get('streams'):
self._streams[stream.get('id')] = Snapstream(stream)
_LOGGER.debug('stream found: %s', self._streams[stream.get('id')])
for group in status.get('server').get('groups'):
| python | {
"resource": ""
} |
q15402 | Snapserver._request | train | def _request(self, method, identifier, key=None, value=None):
"""Perform request with identifier."""
params = {'id': identifier}
| python | {
"resource": ""
} |
q15403 | Snapserver._on_server_disconnect | train | def _on_server_disconnect(self, exception):
"""Handle server disconnection."""
self._protocol = None
if self._on_disconnect_callback_func and callable(self._on_disconnect_callback_func):
| python | {
"resource": ""
} |
q15404 | Snapserver._on_group_mute | train | def _on_group_mute(self, data):
"""Handle group mute."""
| python | {
"resource": ""
} |
q15405 | Snapserver._on_group_stream_changed | train | def _on_group_stream_changed(self, data):
"""Handle group stream change."""
| python | {
"resource": ""
} |
q15406 | Snapserver._on_client_connect | train | def _on_client_connect(self, data):
"""Handle client connect."""
client = None
if data.get('id') in self._clients:
client = self._clients[data.get('id')]
client.update_connected(True)
else:
client = Snapclient(self, data.get('client'))
| python | {
"resource": ""
} |
q15407 | Snapserver._on_client_disconnect | train | def _on_client_disconnect(self, data):
"""Handle client disconnect."""
self._clients[data.get('id')].update_connected(False) | python | {
"resource": ""
} |
q15408 | Snapserver._on_client_volume_changed | train | def _on_client_volume_changed(self, data):
"""Handle client volume change."""
| python | {
"resource": ""
} |
q15409 | Snapserver._on_client_name_changed | train | def _on_client_name_changed(self, data):
"""Handle client name changed."""
| python | {
"resource": ""
} |
q15410 | Snapserver._on_client_latency_changed | train | def _on_client_latency_changed(self, data):
"""Handle client latency changed."""
| python | {
"resource": ""
} |
q15411 | Snapserver._on_stream_update | train | def _on_stream_update(self, data):
"""Handle stream update."""
self._streams[data.get('id')].update(data.get('stream'))
_LOGGER.info('stream %s updated', self._streams[data.get('id')].friendly_name)
for | python | {
"resource": ""
} |
q15412 | mac | train | def mac():
""" Get MAC. """
from uuid import getnode as get_mac
return ':'.join(("%012x" % | python | {
"resource": ""
} |
q15413 | Client.register | train | def register(self):
""" Transact with server. """
self._queue.put(hello_packet(socket.gethostname(), mac(), __version__))
self._queue.put(request_packet(MSG_SERVER_SETTINGS))
| python | {
"resource": ""
} |
q15414 | Client.request_start | train | def request_start(self):
""" Indicate readiness to receive stream.
This is a blocking call.
"""
| python | {
"resource": ""
} |
q15415 | Client._read_socket | train | def _read_socket(self):
""" Process incoming messages from socket. """
while True:
base_bytes = self._socket.recv(BASE_SIZE)
base = basemessage.parse(base_bytes)
| python | {
"resource": ""
} |
q15416 | Client._handle_message | train | def _handle_message(self, data):
""" Handle messages. """
if data.type == MSG_SERVER_SETTINGS:
_LOGGER.info(data.payload)
elif data.type == MSG_SAMPLE_FORMAT:
_LOGGER.info(data.payload)
self._connected = True
elif data.type == MSG_TIME:
if not self._buffered:
_LOGGER.info('Buffering')
elif data.type == MSG_HEADER:
# Push to app source and start playing.
_LOGGER.info(data.payload.codec.decode('ascii'))
self._source.push(data.payload.header)
self._source.play()
| python | {
"resource": ""
} |
q15417 | Client._write_socket | train | def _write_socket(self):
""" Pass messages from queue to socket. """
while True:
now = time.time()
if self._connected and (self._last_sync + SYNC_AFTER) < now:
self._queue.put(request_packet(MSG_TIME))
| python | {
"resource": ""
} |
q15418 | Client._play | train | def _play(self):
""" Relay buffer to app source. """
while True:
if self._buffered: | python | {
"resource": ""
} |
q15419 | Snapgroup.set_stream | train | def set_stream(self, stream_id):
"""Set group stream."""
self._group['stream_id'] = stream_id
yield | python | {
"resource": ""
} |
q15420 | Snapgroup.set_muted | train | def set_muted(self, status):
"""Set group mute status."""
self._group['muted'] = status
yield | python | {
"resource": ""
} |
q15421 | Snapgroup.volume | train | def volume(self):
"""Get volume."""
volume_sum = 0
for client in self._group.get('clients'):
| python | {
"resource": ""
} |
q15422 | Snapgroup.add_client | train | def add_client(self, client_identifier):
"""Add a client."""
if client_identifier in self.clients:
_LOGGER.error('%s already in group %s', client_identifier, self.identifier)
return
| python | {
"resource": ""
} |
q15423 | Snapgroup.remove_client | train | def remove_client(self, client_identifier):
"""Remove a client."""
new_clients = self.clients
new_clients.remove(client_identifier)
yield from self._server.group_clients(self.identifier, new_clients)
| python | {
"resource": ""
} |
q15424 | Snapgroup.update_mute | train | def update_mute(self, data):
"""Update mute."""
self._group['muted'] = data['mute']
self.callback()
| python | {
"resource": ""
} |
q15425 | Snapgroup.update_stream | train | def update_stream(self, data):
"""Update stream."""
self._group['stream_id'] = data['stream_id']
self.callback()
| python | {
"resource": ""
} |
q15426 | Snapgroup.callback | train | def callback(self):
"""Run callback."""
if self._callback_func | python | {
"resource": ""
} |
q15427 | map_helper | train | def map_helper(data):
""" Build a map message. """
as_list = []
length = 2
for field, value in data.items():
as_list.append(Container(field=bytes(field, ENCODING),
value=bytes(value, ENCODING))) | python | {
"resource": ""
} |
q15428 | command_packet | train | def command_packet(cmd):
""" Build a command message. """
return message('Command',
Container(string_length=len(cmd),
| python | {
"resource": ""
} |
q15429 | Snapclient.group | train | def group(self):
"""Get group."""
for group in self._server.groups:
| python | {
"resource": ""
} |
q15430 | Snapclient.friendly_name | train | def friendly_name(self):
"""Get friendly name."""
if len(self._client.get('config').get('name')):
| python | {
"resource": ""
} |
q15431 | Snapclient.set_name | train | def set_name(self, name):
"""Set a client name."""
if not name:
name = ''
self._client['config']['name'] | python | {
"resource": ""
} |
q15432 | Snapclient.set_latency | train | def set_latency(self, latency):
"""Set client latency."""
self._client['config']['latency'] = latency
| python | {
"resource": ""
} |
q15433 | Snapclient.set_muted | train | def set_muted(self, status):
"""Set client mute status."""
new_volume = self._client['config']['volume']
new_volume['muted'] = status
self._client['config']['volume']['muted'] = status
| python | {
"resource": ""
} |
q15434 | Snapclient.set_volume | train | def set_volume(self, percent, update_group=True):
"""Set client volume percent."""
if percent not in range(0, 101):
raise ValueError('Volume percent out of range')
new_volume = self._client['config']['volume']
| python | {
"resource": ""
} |
q15435 | Snapclient.update_volume | train | def update_volume(self, data):
"""Update volume."""
self._client['config']['volume'] = data['volume']
| python | {
"resource": ""
} |
q15436 | Snapclient.update_name | train | def update_name(self, data):
"""Update name."""
self._client['config']['name'] = data['name']
| python | {
"resource": ""
} |
q15437 | Snapclient.update_latency | train | def update_latency(self, data):
"""Update latency."""
self._client['config']['latency'] = data['latency']
| python | {
"resource": ""
} |
q15438 | Snapclient.update_connected | train | def update_connected(self, status):
"""Update connected."""
self._client['connected'] = status
| python | {
"resource": ""
} |
q15439 | GstreamerAppSrc.push | train | def push(self, buf):
""" Push a buffer into the source. """
| python | {
"resource": ""
} |
q15440 | create_server | train | def create_server(loop, host, port=CONTROL_PORT, reconnect=False):
"""Server factory."""
server = Snapserver(loop, host, | python | {
"resource": ""
} |
q15441 | _get_ordering | train | def _get_ordering(son):
"""Helper function to extract formatted ordering from dict.
"""
def fmt(field, direction):
return '{0}{1}'.format({-1: '-', 1: '+'}[direction], field)
| python | {
"resource": ""
} |
q15442 | as_iterable | train | def as_iterable(iterable_or_scalar):
"""Utility for converting an object to an iterable.
Parameters
----------
iterable_or_scalar : anything
Returns
-------
l : iterable
If `obj` was None, return the empty tuple.
If `obj` was not iterable returns a 1-tuple containing `obj`.
Otherwise return `obj`
Notes
-----
Although both string types and dictionaries are iterable in Python, we are treating them as not iterable in this
method. Thus, as_iterable(dict()) returns (dict, ) and as_iterable(string) returns (string, )
Exammples
---------
>>> as_iterable(1)
(1,)
>>> as_iterable([1, 2, 3])
[1, 2, 3]
>>> as_iterable("my string")
| python | {
"resource": ""
} |
q15443 | SparkJVMHelpers.classloader | train | def classloader(self):
"""Returns the private class loader that spark uses.
This is needed since jars added with --jars are not easily resolvable by py4j's classloader
| python | {
"resource": ""
} |
q15444 | SparkJVMHelpers.get_java_container | train | def get_java_container(self, package_name=None, object_name=None, java_class_instance=None):
"""Convenience method to get the container that houses methods we wish to call a method on.
"""
if package_name is not None:
jcontainer = self.import_scala_package_object(package_name)
elif object_name is not None:
jcontainer = self.import_scala_object(object_name)
| python | {
"resource": ""
} |
q15445 | _save_documentation | train | def _save_documentation(version, base_url="https://spark.apache.org/docs"):
"""
Write the spark property documentation to a file
"""
target_dir = join(dirname(__file__), 'spylon', 'spark')
with open(join(target_dir, "spark_properties_{}.json".format(version)), 'w') as fp:
all_props = _fetch_documentation(version=version, base_url=base_url)
| python | {
"resource": ""
} |
q15446 | _pretty_time_delta | train | def _pretty_time_delta(td):
"""Creates a string representation of a time delta.
Parameters
----------
td : :class:`datetime.timedelta`
Returns
-------
pretty_formatted_datetime : str
"""
seconds = td.total_seconds()
sign_string = '-' if seconds < 0 else ''
seconds = abs(int(seconds))
days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
d = dict(sign=sign_string, days=days, hours=hours, minutes=minutes, seconds=seconds)
if days | python | {
"resource": ""
} |
q15447 | _format_stage_info | train | def _format_stage_info(bar_width, stage_info, duration, timedelta_formatter=_pretty_time_delta):
"""Formats the Spark stage progress.
Parameters
----------
bar_width : int
Width of the progressbar to print out.
stage_info : :class:`pyspark.status.StageInfo`
Information about the running stage
stage_id : int
Unique ID of the stage
duration : :class:`datetime.timedelta`
Duration of the stage so far
timedelta_formatter : callable
Converts a timedelta to a string.
Returns
-------
formatted : str
"""
dur = timedelta_formatter(duration)
percent = (stage_info.numCompletedTasks * bar_width) // stage_info.numTasks
bar = [' '] | python | {
"resource": ""
} |
q15448 | ProgressPrinter.resume | train | def resume(self):
"""Resume progress updates."""
| python | {
"resource": ""
} |
q15449 | ProgressPrinter.run | train | def run(self):
"""Run the progress printing loop."""
last_status = ''
# lambda is used to avoid http://bugs.python.org/issue30473 in py36
start_times = defaultdict(lambda: datetime.datetime.now())
max_stage_id = -1
status = self.sc.statusTracker()
while True:
with self.condition:
if self.sc._jsc is None or not self.alive:
# End the thread
self.paused = True
break
elif self.paused:
# Pause the thread
self.condition.wait()
stage_ids = status.getActiveStageIds()
progressbar_list = []
# Only show first 3
stage_counter = 0
current_max_stage = max_stage_id
for stage_id in stage_ids:
stage_info = status.getStageInfo(stage_id)
if stage_info and stage_info.numTasks > 0:
# Set state variables used for flushing later
current_max_stage = stage_id
stage_counter += 1
| python | {
"resource": ""
} |
q15450 | create_conda_env | train | def create_conda_env(sandbox_dir, env_name, dependencies, options=()):
"""
Create a conda environment inside the current sandbox for the given list of dependencies and options.
Parameters
----------
sandbox_dir : str
env_name : str
dependencies : list
List of conda specs
options
List of additional options to pass to conda. Things like ["-c", "conda-forge"]
Returns
-------
(env_dir, env_name)
"""
| python | {
"resource": ""
} |
q15451 | archive_dir | train | def archive_dir(env_dir):
"""
Compresses the directory and writes to its parent
Parameters
----------
env_dir : str
Returns
-------
str
"""
output_filename = env_dir + | python | {
"resource": ""
} |
q15452 | prepare_pyspark_yarn_interactive | train | def prepare_pyspark_yarn_interactive(env_name, env_archive, spark_conf):
"""
This ASSUMES that you have a compatible python environment running on the other side.
WARNING: Injects "PYSPARK_DRIVER_PYTHON" and "PYSPARK_PYTHON" as
environmental variables into your current environment
Parameters
----------
env_name : str
env_archive : str
spark_conf : SparkConfiguration
Examples
--------
>>> from spylon.spark import SparkConfiguration
>>> conf = SparkConfiguration()
>>> import spylon.spark.yarn_launcher as yl
>>> conf = yl.prepare_pyspark_yarn_interactive(
... env_name="yarn-pyspark-env", env_archive="hdfs:///path/to/conda_envs/yarn-pyspark-env.zip",
... spark_conf=conf
... )
... # Create our context
... sc, sqlC = conf.sql_context("conda-test")
... # Example of it working
... rdd = sc.parallelize(range(10), 10)
...
... def pandas_test(x):
... import numpy
... import pandas
... import sys
... import socket
... return [{"numpy": numpy.__version__, "pandas": pandas.__version__,
... "host": socket.getfqdn(), "python": sys.executable}]
...
... rdd.mapPartitions(pandas_test).collect()
Returns
-------
SparkConfiguration
Copy of `spark_conf` input with added | python | {
"resource": ""
} |
q15453 | run_pyspark_yarn_cluster | train | def run_pyspark_yarn_cluster(env_dir, env_name, env_archive, args):
"""
Initializes the requires spark command line options on order to start a python job with the given python environment.
Parameters
----------
env_dir : str
env_name : str
env_archive : str
args : list
Returns
-------
This call will spawn a child process and block until that is complete.
"""
env = dict(os.environ)
yarn_python = os.path.join(".", "CONDA", env_name, "bin", "python")
archives = env_archive + "#CONDA"
prepend_args = [
"--master", "yarn",
"--deploy-mode", "cluster",
"--conf", "spark.yarn.appMasterEnv.PYSPARK_PYTHON={}".format(yarn_python),
"--archives", archives,
]
env_update = {
| python | {
"resource": ""
} |
q15454 | launcher | train | def launcher(deploy_mode, args, working_dir=".", cleanup=True):
"""Initializes arguments and starts up pyspark with the correct deploy mode and environment.
Parameters
----------
deploy_mode : {"client", "cluster"}
args : list
Arguments to pass onwards to spark submit.
working_dir : str, optional
Path to working directory to use for creating conda environments. Defaults to the current working directory.
cleanup : bool, optional
Clean up extracted / generated files. This defaults to true since conda environments can be rather large.
Returns
-------
This call will spawn a child process and block until that is complete.
"""
spark_args = args.copy()
# Scan through the arguments to find --conda
# TODO: make this optional, if not specified ignore all the python stuff
# Is this double dash in front of conda env correct?
i = spark_args.index("--conda-env")
# pop off the '--conda-env' portion and just drop it on the floor
spark_args.pop(i)
# Now pop off the actual conda env var passed to the launcher
conda_env = spark_args.pop(i)
cleanup_functions = []
# What else could this possibly be other than a string here?
assert isinstance(conda_env, str)
func_kwargs = {'conda_env': conda_env,
'deploy_mode': deploy_mode,
'working_dir': working_dir,
'cleanup_functions': cleanup_functions}
if conda_env.startswith("hdfs:/"):
# "hadoop fs -ls" can return URLs with only a single "/" after the "hdfs:" scheme
env_name, env_dir, env_archive = _conda_from_hdfs(**func_kwargs)
elif conda_env.endswith(".zip"):
| python | {
"resource": ""
} |
q15455 | _extract_local_archive | train | def _extract_local_archive(working_dir, cleanup_functions, env_name, local_archive):
"""Helper internal function for extracting a zipfile and ensure that a cleanup is queued.
Parameters
----------
working_dir : str
cleanup_functions : List[() -> NoneType]
env_name : str
local_archive : str
"""
with zipfile.ZipFile(local_archive) as z:
z.extractall(working_dir)
archive_filenames = z.namelist()
root_elements = {m.split(posixpath.sep, 1)[0] for m in archive_filenames}
abs_archive_filenames = [os.path.abspath(os.path.join(working_dir, f)) for f in root_elements]
def cleanup():
for fn in abs_archive_filenames:
if os.path.isdir(fn):
| python | {
"resource": ""
} |
q15456 | keyfilter | train | def keyfilter(predicate, d, factory=dict):
""" Filter items in dictionary by key
>>> iseven = lambda x: x % 2 == 0
>>> d = {1: 2, 2: 3, 3: 4, 4: 5}
>>> keyfilter(iseven, d)
{2: 3, 4: 5}
See Also:
valfilter
| python | {
"resource": ""
} |
q15457 | _SparkConfHelper.set_if_unset | train | def set_if_unset(self, key, value):
"""Set a particular spark property by the string key name if it hasn't already been set.
This method allows chaining so that i can provide a similar feel to the standard Scala way of setting
multiple configurations
Parameters
---------- | python | {
"resource": ""
} |
q15458 | SparkConfiguration._repr_pretty_ | train | def _repr_pretty_(self, p, cycle):
"""Pretty printer for the spark cnofiguration"""
from IPython.lib.pretty import RepresentationPrinter
assert isinstance(p, RepresentationPrinter)
p.begin_group(1, "SparkConfiguration(")
def kv(k, v, do_comma=True):
p.text(k)
p.pretty(v)
if do_comma:
p.text(", ")
| python | {
"resource": ""
} |
q15459 | SparkConfiguration._set_launcher_property | train | def _set_launcher_property(self, driver_arg_key, spark_property_key):
"""Handler for a special property that exists in both the launcher arguments and the spark conf dictionary.
This will use the launcher argument if set falling back to the spark conf argument. If neither are set this is
a noop (which means that the standard spark defaults will be used).
Since `spark.driver.memory` (eg) can be set erroneously by a user on the standard spark conf, we want to be able
to use that value if present. If we do not have this fall-back behavior then these settings are IGNORED when
starting up the spark driver JVM under client mode (standalone, local, yarn-client or mesos-client).
Parameters
| python | {
"resource": ""
} |
q15460 | SparkConfiguration._set_environment_variables | train | def _set_environment_variables(self):
"""Initializes the correct environment variables for spark"""
cmd = []
# special case for driver JVM properties.
self._set_launcher_property("driver-memory", "spark.driver.memory")
self._set_launcher_property("driver-library-path", "spark.driver.extraLibraryPath")
self._set_launcher_property("driver-class-path", "spark.driver.extraClassPath")
self._set_launcher_property("driver-java-options", "spark.driver.extraJavaOptions")
self._set_launcher_property("executor-memory", "spark.executor.memory")
| python | {
"resource": ""
} |
q15461 | SparkConfiguration._init_spark | train | def _init_spark(self):
"""Initializes spark so that pyspark is importable. This also sets up the required environment variables
"""
global _SPARK_INITIALIZED
spark_home = self.spark_home
python_path = self._python_path
if use_findspark:
if _SPARK_INITIALIZED:
if spark_home == os.environ["SPARK_HOME"]:
# matches with already initialized
pass
else:
# findspark adds two path to the search path.
sys.path.pop(0)
sys.path.pop(0)
| python | {
"resource": ""
} |
q15462 | WePay.get_authorization_url | train | def get_authorization_url(self, redirect_uri, client_id, options=None,
scope=None):
"""
Returns a URL to send the user to in order to get authorization.
After getting authorization the user will return to redirect_uri.
Optionally, scope can be set to limit permissions, and the options
dict can be loaded with any combination of state, user_name
or user_email.
:param str redirect_uri: The URI to redirect to after a authorization.
| python | {
"resource": ""
} |
q15463 | Visualizer3D.figure | train | def figure(bgcolor=(1,1,1), size=(1000,1000)):
"""Create a blank figure.
Parameters
----------
bgcolor : (3,) float
Color of the background with values in [0,1].
size : (2,) int
Width and height of the figure in pixels.
| python | {
"resource": ""
} |
q15464 | Visualizer3D.show | train | def show(animate=False, axis=np.array([0.,0.,1.]), clf=True, **kwargs):
"""Display the current figure and enable interaction.
Parameters
----------
animate : bool
Whether or not to animate the scene.
axis : (3,) float or None
If present, the animation will rotate about the given axis in world coordinates.
Otherwise, the animation will rotate in azimuth.
clf : bool
If true, the Visualizer is cleared after showing the figure.
kwargs : dict
Other keyword arguments for the SceneViewer instance.
| python | {
"resource": ""
} |
q15465 | Visualizer3D.render | train | def render(n_frames=1, axis=np.array([0.,0.,1.]), clf=True, **kwargs):
"""Render frames from the viewer.
Parameters
----------
n_frames : int
Number of frames to render. If more than one, the scene will animate.
axis : (3,) float or None
If present, the animation will rotate about the given axis in world coordinates.
Otherwise, the animation will rotate in azimuth.
clf : | python | {
"resource": ""
} |
q15466 | Visualizer3D.save | train | def save(filename, n_frames=1, axis=np.array([0.,0.,1.]), clf=True, **kwargs):
"""Save frames from the viewer out to a file.
Parameters
----------
filename : str
The filename in which to save the output image. If more than one frame,
should have extension .gif.
n_frames : int
Number of frames to render. If more than one, the scene will animate.
axis : (3,) float or None
If present, the animation will rotate about the given axis in world coordinates.
Otherwise, the animation will rotate in azimuth.
clf : bool
If true, the Visualizer is cleared after rendering the figure.
kwargs : dict
Other keyword arguments for the SceneViewer instance.
"""
if n_frames >1 and os.path.splitext(filename)[1] != '.gif':
raise ValueError('Expected .gif file for multiple-frame save.')
v = SceneViewer(Visualizer3D._scene,
size=Visualizer3D._init_size,
| python | {
"resource": ""
} |
q15467 | Visualizer3D.save_loop | train | def save_loop(filename, framerate=30, time=3.0, axis=np.array([0.,0.,1.]), clf=True, **kwargs):
"""Off-screen save a GIF of one rotation about the scene.
Parameters
----------
filename : str
The filename in which to save the output image (should have extension .gif)
framerate : int
The frame rate at which to animate motion.
time : float
The number of seconds for one rotation.
axis : (3,) float or None
If present, the animation will rotate about the given axis in world coordinates.
Otherwise, the animation will rotate in azimuth.
clf : bool
| python | {
"resource": ""
} |
q15468 | Visualizer3D.clf | train | def clf():
"""Clear the current figure
"""
Visualizer3D._scene = Scene(background_color=Visualizer3D._scene.background_color) | python | {
"resource": ""
} |
q15469 | Visualizer3D.points | train | def points(points, T_points_world=None, color=np.array([0,1,0]), scale=0.01, n_cuts=20, subsample=None, random=False, name=None):
"""Scatter a point cloud in pose T_points_world.
Parameters
----------
points : autolab_core.BagOfPoints or (n,3) float
The point set to visualize.
T_points_world : autolab_core.RigidTransform
Pose of points, specified as a transformation from point frame to world frame.
color : (3,) or (n,3) float
Color of whole cloud or per-point colors
scale : float
Radius of each point.
n_cuts : int
Number of longitude/latitude lines on sphere points.
subsample : int
Parameter of subsampling to display fewer points.
name : str
A name for the object to be added.
"""
if isinstance(points, BagOfPoints):
if points.dim != 3:
raise ValueError('BagOfPoints must have dimension 3xN!')
else:
if type(points) is not np.ndarray:
raise ValueError('Points visualizer expects BagOfPoints or numpy array!')
if len(points.shape) == 1:
points = points[:,np.newaxis].T
if len(points.shape) != 2 or points.shape[1] != 3:
raise ValueError('Numpy array of points must have dimension (N,3)')
frame = 'points'
if T_points_world:
frame = T_points_world.from_frame
points = PointCloud(points.T, frame=frame)
color = np.array(color)
if subsample is not None:
num_points = points.num_points
points, inds = points.subsample(subsample, random=random)
if color.shape[0] == num_points and color.shape[1] == 3:
color = color[inds,:]
# transform into world frame
if points.frame != 'world':
if T_points_world is None:
T_points_world = RigidTransform(from_frame=points.frame, to_frame='world')
points_world = T_points_world * points
else:
points_world = points
| python | {
"resource": ""
} |
q15470 | Visualizer3D.mesh | train | def mesh(mesh, T_mesh_world=RigidTransform(from_frame='obj', to_frame='world'),
style='surface', smooth=False, color=(0.5,0.5,0.5), name=None):
"""Visualize a 3D triangular mesh.
Parameters
----------
mesh : trimesh.Trimesh
The mesh to visualize.
T_mesh_world : autolab_core.RigidTransform
The pose of the mesh, specified as a transformation from mesh frame to world frame.
style : str
Triangular mesh style, either 'surface' or 'wireframe'.
| python | {
"resource": ""
} |
q15471 | Visualizer3D.mesh_stable_pose | train | def mesh_stable_pose(mesh, T_obj_table,
T_table_world=RigidTransform(from_frame='table', to_frame='world'),
style='wireframe', smooth=False, color=(0.5,0.5,0.5),
dim=0.15, plot_table=True, plot_com=False, name=None):
"""Visualize a mesh in a stable pose.
Parameters
----------
mesh : trimesh.Trimesh
The mesh to visualize.
T_obj_table : autolab_core.RigidTransform
Pose of object relative to table.
T_table_world : autolab_core.RigidTransform
Pose of table relative to world.
style : str
Triangular mesh style, either 'surface' or 'wireframe'.
smooth : bool
If true, the mesh is smoothed before rendering.
color : 3-tuple
Color tuple.
dim : float
The side-length for the table.
plot_table : bool
If true, a table is visualized as well.
plot_com : bool
If true, a ball | python | {
"resource": ""
} |
q15472 | Visualizer3D.table | train | def table(T_table_world=RigidTransform(from_frame='table', to_frame='world'), dim=0.16, color=(0,0,0)):
"""Plot a table mesh in 3D.
Parameters
----------
T_table_world : autolab_core.RigidTransform
Pose of table relative to world.
dim : float
The side-length for the table.
color : 3-tuple
Color tuple.
"""
table_vertices = np.array([[ dim, dim, 0],
[ dim, -dim, 0],
[-dim, dim, 0],
| python | {
"resource": ""
} |
q15473 | Visualizer3D.plot3d | train | def plot3d(points, color=(0.5, 0.5, 0.5), tube_radius=0.005, n_components=30, name=None):
"""Plot a 3d curve through a set of points using tubes.
Parameters
----------
points : (n,3) float
A series of 3D points that define a curve in space.
color : (3,) float
The color of the tube.
tube_radius : float
Radius of tube representing curve.
n_components : int
The number of edges in each polygon representing the tube.
name : str
A name for the object to be added.
"""
points = np.asanyarray(points)
mp = MaterialProperties(
color = np.array(color),
k_a = 0.5,
k_d = 0.3,
k_s = 0.0,
alpha = 10.0,
smooth=True
)
# Generate circular polygon
vec = np.array([0,1]) * tube_radius
| python | {
"resource": ""
} |
q15474 | Visualizer2D.figure | train | def figure(size=(8,8), *args, **kwargs):
""" Creates a figure.
Parameters
----------
size : 2-tuple
size of the view window in inches
| python | {
"resource": ""
} |
q15475 | Visualizer2D.show | train | def show(filename=None, *args, **kwargs):
""" Show the current figure.
Parameters
----------
filename : :obj:`str`
filename to save the image to, for auto-saving
"""
| python | {
"resource": ""
} |
q15476 | Visualizer2D.box | train | def box(b, line_width=2, color='g', style='-'):
""" Draws a box on the current plot.
Parameters
----------
b : :obj:`autolab_core.Box`
box to draw
line_width : int
width of lines on side of box
color : :obj:`str`
color of box
style : :obj:`str`
style of lines to draw
"""
if not isinstance(b, Box):
raise ValueError('Input must be of type Box')
# get min pixels
min_i = b.min_pt[1]
min_j = b.min_pt[0]
| python | {
"resource": ""
} |
q15477 | Visualizer2D.contour | train | def contour(c, subsample=1, size=10, color='g'):
""" Draws a contour on the current plot by scattering points.
Parameters
----------
c : :obj:`autolab_core.Contour`
contour to draw
subsample : int
subsample rate for boundary pixels
size : int
size of scattered points
color : :obj:`str`
color of box
"""
| python | {
"resource": ""
} |
q15478 | flatten | train | def flatten(in_list):
"""given a list of values in_list, flatten returns the list obtained by
flattening the top-level elements of in_list."""
out_list = []
for val in in_list:
| python | {
"resource": ""
} |
q15479 | create_parameterized_CAG | train | def create_parameterized_CAG(input, output, filename="CAG_with_indicators_and_values.pdf"):
""" Create a CAG with mapped and parameterized indicators """
with open(input, "rb") as f:
| python | {
"resource": ""
} |
q15480 | get_concepts | train | def get_concepts(sts: List[Influence]) -> Set[str]:
""" Get a set of all unique concepts in the list of INDRA | python | {
"resource": ""
} |
q15481 | get_valid_statements_for_modeling | train | def get_valid_statements_for_modeling(sts: List[Influence]) -> List[Influence]:
""" Select INDRA statements that can be used to construct a Delphi model
from a given list of statements. """
return [
s
for | python | {
"resource": ""
} |
q15482 | is_grounded_to_name | train | def is_grounded_to_name(c: Concept, name: str, cutoff=0.7) -> bool:
""" Check if a concept is grounded to a given name. """ | python | {
"resource": ""
} |
q15483 | contains_relevant_concept | train | def contains_relevant_concept(
s: Influence, relevant_concepts: List[str], cutoff=0.7
) -> bool:
""" Returns true if a given Influence statement has a relevant concept, and
false otherwise. """
| python | {
"resource": ""
} |
q15484 | top_grounding | train | def top_grounding(c: Concept) -> str:
""" Return the top-scoring grounding from the UN ontology. """
| python | {
"resource": ""
} |
q15485 | nameTuple | train | def nameTuple(s: Influence) -> Tuple[str, str]:
""" Returns a 2-tuple consisting of the | python | {
"resource": ""
} |
q15486 | createNewICM | train | def createNewICM():
""" Create a new ICM"""
data = json.loads(request.data)
G = AnalysisGraph.from_uncharted_json_serialized_dict(data)
G.assemble_transition_model_from_gradable_adjectives()
| python | {
"resource": ""
} |
q15487 | getICMByUUID | train | def getICMByUUID(uuid: str):
""" Fetch an ICM by UUID"""
_metadata = ICMMetadata.query.filter_by(id=uuid).first().deserialize() | python | {
"resource": ""
} |
q15488 | deleteICM | train | def deleteICM(uuid: str):
""" Deletes an ICM"""
_metadata = ICMMetadata.query.filter_by(id=uuid).first()
| python | {
"resource": ""
} |
q15489 | getExperiment | train | def getExperiment(uuid: str, exp_id: str):
""" Fetch experiment results"""
experimentResult = ForwardProjectionResult.query.filter_by(
| python | {
"resource": ""
} |
q15490 | create_statement_inspection_table | train | def create_statement_inspection_table(sts: List[Influence]):
""" Display an HTML representation of a table with INDRA statements to
manually inspect for validity.
Args:
sts: A list of INDRA statements to be manually inspected for validity.
"""
columns = [
"un_groundings",
"subj_polarity",
"obj_polarity",
"Sentence",
"Source API",
]
polarity_to_str = lambda x: "+" if x == 1 else "-" if x == -1 else "None"
l = []
for s in sts:
subj_un_grounding = s.subj.db_refs["UN"][0][0].split("/")[-1]
obj_un_grounding = s.obj.db_refs["UN"][0][0].split("/")[-1]
subj_polarity = s.subj_delta["polarity"]
obj_polarity = s.obj_delta["polarity"]
subj_adjectives = s.subj_delta["adjectives"]
for e in s.evidence:
l.append(
(
(subj_un_grounding, obj_un_grounding),
subj_polarity,
obj_polarity,
| python | {
"resource": ""
} |
q15491 | get_python_shell | train | def get_python_shell():
"""Determine python shell
get_python_shell() returns
'shell' (started python on command line using "python")
'ipython' (started ipython on command line using "ipython")
'ipython-notebook' (e.g., running in Spyder or started with "ipython qtconsole")
'jupyter-notebook' (running in a Jupyter notebook)
See also https://stackoverflow.com/a/37661854
"""
env = os.environ
shell = "shell" | python | {
"resource": ""
} |
q15492 | create_precipitation_centered_CAG | train | def create_precipitation_centered_CAG(input, output):
""" Get a CAG that examines the downstream effects of changes in precipitation. """
with open(input, "rb") as f:
G = pickle.load(f)
G = G.get_subgraph_for_concept(
"UN/events/weather/precipitation", depth=2, reverse=False
)
G.prune(cutoff=2)
# Manually correcting a bad CWMS extraction
G.edges[
| python | {
"resource": ""
} |
q15493 | index_modules | train | def index_modules(root) -> Dict:
""" Counts the number of modules in the Fortran file including the program
file. Each module is written out into a separate Python file. | python | {
"resource": ""
} |
q15494 | draw_graph | train | def draw_graph(G: nx.DiGraph, filename: str):
""" Draw a networkx graph with Pygraphviz. """
A = | python | {
"resource": ""
} |
q15495 | get_input_nodes | train | def get_input_nodes(G: nx.DiGraph) -> List[str]:
""" Get all input nodes from a network. """
| python | {
"resource": ""
} |
q15496 | get_output_nodes | train | def get_output_nodes(G: nx.DiGraph) -> List[str]:
""" Get all output nodes from a network. """
| python | {
"resource": ""
} |
q15497 | nx_graph_from_dotfile | train | def nx_graph_from_dotfile(filename: str) -> nx.DiGraph:
""" Get a networkx graph from a DOT file, and reverse the edges. | python | {
"resource": ""
} |
q15498 | to_dotfile | train | def to_dotfile(G: nx.DiGraph, filename: str):
""" Output a networkx graph to a DOT file. """
| python | {
"resource": ""
} |
q15499 | get_shared_nodes | train | def get_shared_nodes(G1: nx.DiGraph, G2: nx.DiGraph) -> List[str]:
"""Get all the nodes that are common to both networks.""" | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.