def remove_config(self, id):

        url = self._url('/configs/{0}', id)
        res = self._delete(url)
        self._raise_for_status(res)
        return True

Remove a config

Args:
id (string): Full ID of the config to remove

Returns (boolean): True if successful

Raises:
:py:class:`docker.errors.NotFound`
if no config with that ID exists


def _transpose_batch_time(x):
    x_static_shape = x.get_shape()
    if x_static_shape.rank is not None and x_static_shape.rank < 2:
        return x
    x_rank = array_ops.rank(x)
    x_t = array_ops.transpose(x, array_ops.concat(([1, 0], math_ops.range(2, x_rank)), axis=0))
    x_t.set_shape(tensor_shape.TensorShape([x_static_shape.dims[1].value, x_static_shape.dims[0].value]).concatenate(x_static_shape[2:]))
    return x_t

Transposes the batch and time dimensions of a Tensor.

If the input tensor has rank < 2 it returns the original tensor. Retains as
much of the static shape information as possible.

Args:
x: A Tensor.

Returns:
x transposed along the first two dimensions.


def _forward_over_back_hessian(f, params, use_pfor, dtype=None):
    return _vectorize_parameters(functools.partial(_hvp, f, params), params, use_pfor=use_pfor, dtype=dtype)

Computes the full Hessian matrix for the scalar-valued f(*params).

Args:
f: A function taking `params` and returning a scalar.
params: A possibly nested structure of tensors.
use_pfor: If true, uses `tf.vectorized_map` calls instead of looping.
dtype: Required if `use_pfor=False`. A possibly nested structure of dtypes
(e.g. `tf.float32`) matching the structure of `f`'s returns.

Returns:
A possibly nested structure of matrix slices corresponding to `params`. Each
slice has shape [P, p_s] where `p_s` is the number of parameters (`tf.size`)
in the corresponding element of `params` and `P` is the total number of
parameters (`sum_s(p_s)`). The full matrix can be obtained by concatenating
along the second axis.


def get(self, *, search, limit=0, headers=None):

        return self.transport.forward_request(
            method='GET',
            path=self.path,
            params={'search': search, 'limit': limit},
            headers=headers
        )

Retrieves the assets that match a given text search string.

Args:
search (str): Text search string.
limit (int): Limit the number of returned documents. Defaults to
zero meaning that it returns all the matching assets.
headers (dict): Optional headers to pass to the request.

Returns:
:obj:`list` of :obj:`dict`: List of assets that match the query.


def delete_asset(self, asset_id, asset_type):

        return self.asset(asset_id, asset_type=asset_type, action='DELETE')

Delete the asset with the provided asset_id.

Args:
asset_id: The id of the asset.
asset_type: The asset type.

Returns:


def __new__(cls, name, parents, dct):

        newClass = super(CommandMeta, cls).__new__(cls, name, parents, dct)

        if name != 'Command':
            for attribute in ['name', 'description', 'help']:
                if attribute not in dct or dct[attribute] is None:
                    raise ValueError('%s cannot be None.' % attribute)
            CommandMeta.registry[name] = newClass

        return newClass

Creates a new Command class and validates it.

Args:
cls (Class): the class object being created
name (name): the name of the class being created
parents (list): list of parent classes
dct (dictionary): class attributes

Returns:
``Class``


def wrap_in_placeholder(self, arg, shape_info):
    if shape_info == 'known':
        return arg
    if isinstance(arg, ragged_tensor.RaggedTensor):
        return arg.with_flat_values(self.wrap_in_placeholder(arg.flat_values, shape_info))
    if isinstance(arg, tensor_shape.TensorShape):
        if arg.ndims is None:
            return arg
        arg = constant_op.constant(arg.as_list())
    if shape_info == 'unknown_rank':
        return array_ops.placeholder_with_default(arg, None)
    if shape_info == 'unknown_dims':
        return array_ops.placeholder_with_default(arg, [None] * arg.shape.rank)
    raise AssertionError('Unexpected shape_info %r' % shape_info)

Wraps `arg` in a placeholder to limit static shape info.

Args:
arg: The value to wrap.  A Tensor, RaggedTensor, or TensorShape.
shape_info: One of ['known', 'unknown_dims', 'unknown_rank'].

Returns:
* If shape_info is 'known': returns `arg`.
* If shape_info is 'unknown_dims': returns a placeholder wrapping `arg`
where the dimension sizes are unknown.  If `arg` is a TensorShape,
then convert it to a vector first.  If `arg` is a RaggedTensor, then
wrap the flat_values.
* If shape_info is 'unknown_rank': returns a placeholder wrapping `arg`
where the rank is unknown.  If `arg` is a TensorShape, then convert it
to a vector first.  If `arg` is a RaggedTensor, then wrap the
flat_values.


def tensor_summary(name, tensor, summary_description=None, collections=None, summary_metadata=None, family=None, display_name=None):
    if summary_metadata is None:
        summary_metadata = _SummaryMetadata()
    if summary_description is not None:
        summary_metadata.summary_description = summary_description
    if display_name is not None:
        summary_metadata.display_name = display_name
    serialized_summary_metadata = summary_metadata.SerializeToString()
    if _distribute_summary_op_util.skip_summary():
        return _constant_op.constant('')
    with _summary_op_util.summary_scope(name, family, values=[tensor]) as (tag, scope):
        val = _gen_logging_ops.tensor_summary_v2(tensor=tensor, tag=tag, name=scope, serialized_summary_metadata=serialized_summary_metadata)
        _summary_op_util.collect(val, collections, [_ops.GraphKeys.SUMMARIES])
    return val

Outputs a `Summary` protocol buffer with a serialized tensor.proto.

Args:
name: A name for the generated node. If display_name is not set, it will
also serve as the tag name in TensorBoard. (In that case, the tag
name will inherit tf name scopes.)
tensor: A tensor of any type and shape to serialize.
summary_description: A long description of the summary sequence. Markdown
is supported.
collections: Optional list of graph collections keys. The new summary op is
added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
summary_metadata: Optional SummaryMetadata proto (which describes which
plugins may use the summary value).
family: Optional; if provided, used as the prefix of the summary tag,
which controls the name used for display on TensorBoard when
display_name is not set.
display_name: A string used to name this data in TensorBoard. If this is
not set, then the node name will be used instead.

Returns:
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
buffer.


def _update_graph(self, vertex_dict=None, edge_dict=None):

    def set_attrs(ref, attrs):
        for attr_name, attr_val in attrs.items():
            ref.set(attr_name, attr_val)
    with self._lock:
        if vertex_dict:
            for vertex, vertex_attrs in vertex_dict.items():
                set_attrs(self._vertex_refs[vertex], vertex_attrs)
        if edge_dict:
            for edge, edge_attrs in edge_dict.items():
                if isinstance(edge, tuple):
                    set_attrs(self._edge_refs[edge], edge_attrs)
                else:
                    for vertex_pair in self._edge_to_vertex_pairs[edge]:
                        set_attrs(self._edge_refs[vertex_pair], edge_attrs)

Updates the pydot.Dot object with the given attribute update

Args:
vertex_dict: (Dict[str, Dict[str, str]]) maps vertex names to attributes
edge_dict: This should be
Either (Dict[str, Dict[str, str]]) which maps edge names to attributes
Or (Dict[(str, str), Dict[str, str]]) which maps vertex pairs to edge
attributes


def invite_by_email(self, email, user, organization, **kwargs):

        try:
            invitee = self.user_model.objects.get(email__iexact=email)
        except self.user_model.DoesNotExist:
            invitee = None

        user_invitation = self.invitation_model.objects.create(
            invitee=invitee,
            invitee_identifier=email.lower(),
            invited_by=user,
            organization=organization,
        )
        self.send_invitation(user_invitation)
        return user_invitation

Primary interface method by which one user invites another to join

Args:
email:
request:
**kwargs:

Returns:
an invitation instance

Raises:
MultipleObjectsReturned if multiple matching users are found


def add_presence_listener(self, callback):
    listener_uid = uuid4()
    self.presence_listeners[listener_uid] = callback
    return listener_uid

Add a presence listener that will send a callback when the client receives
a presence update.

Args:
callback (func(roomchunk)): Callback called when a presence update arrives.

Returns:
uuid.UUID: Unique id of the listener, can be used to identify the listener.


def position(msg0, msg1, t0, t1, lat_ref=None, lon_ref=None):

    tc0 = typecode(msg0)
    tc1 = typecode(msg1)

    if (5<=tc0<=8 and 5<=tc1<=8):
        if (not lat_ref) or (not lon_ref):
            raise RuntimeError("Surface position encountered, a reference \
                               position lat/lon required. Location of \
                               receiver can be used.")
        else:
            return surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref)

    elif (9<=tc0<=18 and 9<=tc1<=18):

        return airborne_position(msg0, msg1, t0, t1)

    elif (20<=tc0<=22 and 20<=tc1<=22):

        return airborne_position(msg0, msg1, t0, t1)

    else:
        raise RuntimeError("incorrect or inconsistant message types")

Decode position from a pair of even and odd position message
(works with both airborne and surface position messages)

Args:
msg0 (string): even message (28 bytes hexadecimal string)
msg1 (string): odd message (28 bytes hexadecimal string)
t0 (int): timestamps for the even message
t1 (int): timestamps for the odd message

Returns:
(float, float): (latitude, longitude) of the aircraft


def hex_to_name(hexx):
    for (n, h) in defaults.COLOURS.items():
        if ((len(n) > 1) and (h == hexx.upper())):
            return n.lower()
    return None

Convert hex to a color name, using matplotlib's colour names.

Args:
hexx (str): A hexadecimal colour, starting with '#'.

Returns:
str: The name of the colour, or None if not found.


def save_summaries(frames, keys, selected_summaries, batch_dir, batch_name):

    if not frames:
        logger.info("Could save summaries - no summaries to save!")
        logger.info("You have no frames - aborting")
        return None
    if not keys:
        logger.info("Could save summaries - no summaries to save!")
        logger.info("You have no keys - aborting")
        return None

    selected_summaries_dict = create_selected_summaries_dict(selected_summaries)
    summary_df = pd.concat(frames, keys=keys, axis=1)

    for key, value in selected_summaries_dict.items():
        _summary_file_name = os.path.join(batch_dir, "summary_%s_%s.csv" % (
        key, batch_name))
        _summary_df = summary_df.iloc[:,
                      summary_df.columns.get_level_values(1) == value]

        _header = _summary_df.columns
        _summary_df.to_csv(_summary_file_name, sep=";")
        logger.info(
            "saved summary (%s) to:\n       %s" % (key, _summary_file_name))
    logger.info("finished saving summaries")
    return summary_df

Writes the summaries to csv-files

Args:
frames: list of ``cellpy`` summary DataFrames
keys: list of indexes (typically run-names) for the different runs
selected_summaries: list defining which summary data to save
batch_dir: directory to save to
batch_name: the batch name (will be used for making the file-name(s))

Returns: a pandas DataFrame with your selected summaries.


def check_num_tasks(chain, task_count):
    errors = []
    min_decision_tasks = 1
    if (task_count['decision'] < min_decision_tasks):
        errors.append('{} decision tasks; we must have at least {}!'.format(task_count['decision'], min_decision_tasks))
    raise_on_errors(errors)

Make sure there are a specific number of specific task types.

Currently we only check decision tasks.

Args:
chain (ChainOfTrust): the chain we're operating on
task_count (dict): mapping task type to the number of links.

Raises:
CoTError: on failure.


def load_institute(adapter, internal_id, display_name, sanger_recipients=None):

    institute_obj = build_institute(
        internal_id=internal_id,
        display_name=display_name,
        sanger_recipients=sanger_recipients
    )
    log.info("Loading institute {0} with display name {1}" \
             " into database".format(internal_id, display_name))

    adapter.add_institute(institute_obj)

Load a institute into the database

Args:
adapter(MongoAdapter)
internal_id(str)
display_name(str)
sanger_recipients(list(email))


def _Identity(tensor, name=None):
    tensor = ops.internal_convert_to_tensor_or_composite(tensor, as_ref=True)
    tensor = variable_utils.convert_variables_to_tensors(tensor)
    if isinstance(tensor, tensor_lib.Tensor):
        if tensor.dtype._is_ref_dtype:
            return gen_array_ops.ref_identity(tensor, name=name)
        else:
            return array_ops.identity(tensor, name=name)
    elif isinstance(tensor, composite_tensor.CompositeTensor):
        return nest.map_structure(_Identity, tensor, expand_composites=True)
    else:
        raise TypeError(f"'tensor' must be a Tensor or CompositeTensor. Received: {type(tensor)}.")

Return a tensor with the same shape and contents as the input tensor.

Args:
tensor: A Tensor.
name: A name for this operation (optional).

Returns:
A Tensor with the same type and value as the input Tensor.


def __init__(self, input_reader=None, output_writer=None):

    super(Log2TimelineTool, self).__init__(
        input_reader=input_reader, output_writer=output_writer)
    self._command_line_arguments = None
    self._enable_sigsegv_handler = False
    self._number_of_extraction_workers = 0
    self._storage_serializer_format = definitions.SERIALIZER_FORMAT_JSON
    self._source_type = None
    self._status_view = status_view.StatusView(self._output_writer, self.NAME)
    self._status_view_mode = status_view.StatusView.MODE_WINDOW
    self._stdout_output_writer = isinstance(
        self._output_writer, tools.StdoutOutputWriter)
    self._worker_memory_limit = None

    self.dependencies_check = True
    self.list_hashers = False
    self.list_parsers_and_plugins = False
    self.list_profilers = False
    self.show_info = False
    self.show_troubleshooting = False

Initializes a log2timeline CLI tool.

Args:
input_reader (Optional[InputReader]): input reader, where None indicates
that the stdin input reader should be used.
output_writer (Optional[OutputWriter]): output writer, where None
indicates that the stdout output writer should be used.


def save_attributes_to_hdf5_group(group, name, data):
    bad_attributes = [x for x in data if len(x) > HDF5_OBJECT_HEADER_LIMIT]
    if bad_attributes:
        raise RuntimeError('The following attributes cannot be saved to HDF5 file because they are larger than %d bytes: %s' % (HDF5_OBJECT_HEADER_LIMIT, ', '.join(bad_attributes)))
    data_npy = np.asarray(data)
    num_chunks = 1
    chunked_data = np.array_split(data_npy, num_chunks)
    while any((x.nbytes > HDF5_OBJECT_HEADER_LIMIT for x in chunked_data)):
        num_chunks += 1
        chunked_data = np.array_split(data_npy, num_chunks)
    if num_chunks > 1:
        for chunk_id, chunk_data in enumerate(chunked_data):
            group.attrs['%s%d' % (name, chunk_id)] = chunk_data
    else:
        group.attrs[name] = data

Saves attributes (data) of the specified name into the HDF5 group.

This method deals with an inherent problem of HDF5 file which is not
able to store data larger than HDF5_OBJECT_HEADER_LIMIT bytes.

Args:
group: A pointer to a HDF5 group.
name: A name of the attributes to save.
data: Attributes data to store.

Raises:
RuntimeError: If any single attribute is too large to be saved.


def create_from_binary(cls, load_dataruns, binary_view):
    (attr_type, attr_len, non_resident, name_len, name_offset, flags, attr_id, start_vcn, end_vcn, rl_offset, compress_usize, alloc_sstream, curr_sstream, init_sstream) = cls._REPR.unpack(binary_view[:cls._REPR.size])
    if name_len:
        name = binary_view[name_offset:(name_offset + (2 * name_len))].tobytes().decode('utf_16_le')
    else:
        name = None
    nw_obj = cls((AttrTypes(attr_type), attr_len, bool(non_resident), AttrFlags(flags), attr_id, name), (start_vcn, end_vcn, rl_offset, compress_usize, alloc_sstream, curr_sstream, init_sstream))
    if load_dataruns:
        nw_obj.data_runs = DataRuns.create_from_binary(binary_view[nw_obj.rl_offset:])
    _MOD_LOGGER.debug('NonResidentAttrHeader object created successfully')
    return nw_obj

Creates a new object NonResidentAttrHeader from a binary stream. The binary
stream can be represented by a byte string, bytearray or a memoryview of the
bytearray.

Args:
load_dataruns (bool) - Indicates if the dataruns are to be loaded
binary_view (memoryview of bytearray) - A binary stream with the
information of the attribute
non_resident_offset (int) - The offset where the non resident header
begins

Returns:
NonResidentAttrHeader: New object using hte binary stream as source


def gen_encoder_output_proposals(self, enc_output, padding_mask, spatial_shapes):
    batch_size = enc_output.shape[0]
    proposals = []
    _cur = 0
    level_ids = []
    for level, (height, width) in enumerate(spatial_shapes):
        mask_flatten_ = padding_mask[:, _cur:_cur + height * width].view(batch_size, height, width, 1)
        valid_height = torch.sum(~mask_flatten_[:, :, 0, 0], 1)
        valid_width = torch.sum(~mask_flatten_[:, 0, :, 0], 1)
        grid_y, grid_x = meshgrid(torch.linspace(0, height - 1, height, dtype=torch.float32, device=enc_output.device), torch.linspace(0, width - 1, width, dtype=torch.float32, device=enc_output.device), indexing='ij')
        grid = torch.cat([grid_x.unsqueeze(-1), grid_y.unsqueeze(-1)], -1)
        scale = torch.cat([valid_width.unsqueeze(-1), valid_height.unsqueeze(-1)], 1).view(batch_size, 1, 1, 2)
        grid = (grid.unsqueeze(0).expand(batch_size, -1, -1, -1) + 0.5) / scale
        width_height = torch.ones_like(grid) * 0.05 * 2.0 ** level
        proposal = torch.cat((grid, width_height), -1).view(batch_size, -1, 4)
        proposals.append(proposal)
        _cur += height * width
        level_ids.append(grid.new_ones(height * width, dtype=torch.long) * level)
    output_proposals = torch.cat(proposals, 1)
    output_proposals_valid = ((output_proposals > 0.01) & (output_proposals < 0.99)).all(-1, keepdim=True)
    output_proposals = torch.log(output_proposals / (1 - output_proposals))
    output_proposals = output_proposals.masked_fill(padding_mask.unsqueeze(-1), float('inf'))
    output_proposals = output_proposals.masked_fill(~output_proposals_valid, float('inf'))
    object_query = enc_output
    object_query = object_query.masked_fill(padding_mask.unsqueeze(-1), float(0))
    object_query = object_query.masked_fill(~output_proposals_valid, float(0))
    object_query = self.enc_output_norm(self.enc_output(object_query))
    level_ids = torch.cat(level_ids)
    return (object_query, output_proposals, level_ids)

Generate the encoder output proposals from encoded enc_output.

Args:
enc_output (Tensor[batch_size, sequence_length, hidden_size]): Output of the encoder.
padding_mask (Tensor[batch_size, sequence_length]): Padding mask for `enc_output`.
spatial_shapes (Tensor[num_feature_levels, 2]): Spatial shapes of the feature maps.

Returns:
`tuple(torch.FloatTensor)`: A tuple of feature map and bbox prediction.
- object_query (Tensor[batch_size, sequence_length, hidden_size]): Object query features. Later used to
directly predict a bounding box. (without the need of a decoder)
- output_proposals (Tensor[batch_size, sequence_length, 4]): Normalized proposals, after an inverse
sigmoid.


def login_with_password(self, username, password, limit=10):
    warn('login_with_password is deprecated. Use login with sync=True.', DeprecationWarning)
    return self.login(username, password, limit, sync=True)

Deprecated. Use ``login`` with ``sync=True``.

Login to the homeserver.

Args:
username (str): Account username
password (str): Account password
limit (int): Deprecated. How many messages to return when syncing.
This will be replaced by a filter API in a later release.

Returns:
str: Access token

Raises:
MatrixRequestError


def get(self, record_id):

        record_url = self.record_url(record_id)
        return self._get(record_url)

Retrieves a record by its id

>>> record = airtable.get('recwPQIfs4wKPyc9D')

Args:
record_id(``str``): Airtable record id

Returns:
record (``dict``): Record


def parse_config(self, config):
    prefix = self.argument_prefix
    self.sources = config.get_sources(prefix)
    self.smart_sources = [self._get_smart_filename(s) for s in self.sources]
    self.index = config.get_index(prefix)
    self.source_roots = OrderedSet(config.get_paths(('%s_source_roots' % prefix)))
    for (arg, dest) in list(self.paths_arguments.items()):
        val = config.get_paths(arg)
        setattr(self, dest, val)
    for (arg, dest) in list(self.path_arguments.items()):
        val = config.get_path(arg)
        setattr(self, dest, val)
    self.formatter.parse_config(config)

Override this, making sure to chain up first, if your extension adds
its own custom command line arguments, or you want to do any further
processing on the automatically added arguments.

The default implementation will set attributes on the extension:
- 'sources': a set of absolute paths to source files for this extension
- 'index': absolute path to the index for this extension

Additionally, it will set an attribute for each argument added with
`Extension.add_path_argument` or `Extension.add_paths_argument`, with
the extension's `Extension.argument_prefix` stripped, and dashes
changed to underscores.

Args:
config: a `config.Config` instance


def calculate_uncertainty(self, logits: torch.Tensor) -> torch.Tensor:
    uncertainty_scores = -torch.abs(logits)
    return uncertainty_scores

In Mask2Former paper, uncertainty is estimated as L1 distance between 0.0 and the logit prediction in 'logits'
for the foreground class in `classes`.

Args:
logits (`torch.Tensor`):
A tensor of shape (R, 1, ...) for class-specific or class-agnostic, where R is the total number of predicted masks in all images and C is:
the number of foreground classes. The values are logits.

Returns:
scores (`torch.Tensor`): A tensor of shape (R, 1, ...) that contains uncertainty scores with the most
uncertain locations having the highest uncertainty score.


def __similarity(s1, s2, ngrams_fn, n=3):
    (ngrams1, ngrams2) = (set(ngrams_fn(s1, n=n)), set(ngrams_fn(s2, n=n)))
    matches = ngrams1.intersection(ngrams2)
    return ((2 * len(matches)) / (len(ngrams1) + len(ngrams2)))

The fraction of n-grams matching between two sequences

Args:
s1: a string
s2: another string
n: an int for the n in n-gram

Returns:
float: the fraction of n-grams matching


def find_all_template(im_source, im_search, threshold=0.5, maxcnt=0, rgb=False, bgremove=False):

    method = cv2.TM_CCOEFF_NORMED

    if rgb:
        s_bgr = cv2.split(im_search)
        i_bgr = cv2.split(im_source)
        weight = (0.3, 0.3, 0.4)
        resbgr = [0, 0, 0]
        for i in range(3):
            resbgr[i] = cv2.matchTemplate(i_bgr[i], s_bgr[i], method)
        res = resbgr[0]*weight[0] + resbgr[1]*weight[1] + resbgr[2]*weight[2]
    else:
        s_gray = cv2.cvtColor(im_search, cv2.COLOR_BGR2GRAY)
        i_gray = cv2.cvtColor(im_source, cv2.COLOR_BGR2GRAY)

        if bgremove:
            s_gray = cv2.Canny(s_gray, 100, 200)
            i_gray = cv2.Canny(i_gray, 100, 200)

        res = cv2.matchTemplate(i_gray, s_gray, method)
    w, h = im_search.shape[1], im_search.shape[0]

    result = []
    while True:
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
        if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
            top_left = min_loc
        else:
            top_left = max_loc
        if DEBUG:
            print('templmatch_value(thresh:%.1f) = %.3f' %(threshold, max_val))
        if max_val < threshold:
            break

        middle_point = (top_left[0]+w/2, top_left[1]+h/2)
        result.append(dict(
            result=middle_point,
            rectangle=(top_left, (top_left[0], top_left[1] + h), (top_left[0] + w, top_left[1]), (top_left[0] + w, top_left[1] + h)),
            confidence=max_val
        ))
        if maxcnt and len(result) >= maxcnt:
            break

        cv2.floodFill(res, None, max_loc, (-1000,), max_val-threshold+0.1, 1, flags=cv2.FLOODFILL_FIXED_RANGE)
    return result

Locate image position with cv2.templateFind

Use pixel match to find pictures.

Args:
im_source(string): 图像、素材
im_search(string): 需要查找的图片
threshold: 阈值，当相识度小于该阈值的时候，就忽略掉

Returns:
A tuple of found [(point, score), ...]

Raises:
IOError: when file read error


def get_membership(self, uuid=None):
    group_id = self.get_group_id(uuid=uuid)
    uri = 'group/{group_id}/member'
    mbr_data = self.get(uri.format(group_id=group_id), params=None)
    return mbr_data

Get membership data based on uuid.

Args:
uuid (str): optional uuid. defaults to self.cuuid

Raises:
PyLmodUnexpectedData: No data was returned.
requests.RequestException: Exception connection error

Returns:
dict: membership json


def mktemp(self, container: Container) -> str:
    logger.debug('creating a temporary file inside container %s', container.uid)
    response = self.command(container, 'mktemp')
    if (response.code != 0):
        msg = 'failed to create temporary file for container {}: [{}] {}'
        msg = msg.format(uid, response.code, response.output)
        logger.error(msg)
        raise Exception(msg)
    assert (response.code == 0), 'failed to create temporary file'
    fn = response.output.strip()
    logger.debug('created temporary file inside container %s: %s', container.uid, fn)
    return fn

Creates a named temporary file within a given container.

Returns:
the absolute path to the created temporary file.


def masks_to_boxes(masks: np.ndarray) -> np.ndarray:
    if masks.size == 0:
        return np.zeros((0, 4))
    h, w = masks.shape[-2:]
    y = np.arange(0, h, dtype=np.float32)
    x = np.arange(0, w, dtype=np.float32)
    y, x = np.meshgrid(y, x, indexing='ij')
    x_mask = masks * np.expand_dims(x, axis=0)
    x_max = x_mask.reshape(x_mask.shape[0], -1).max(-1)
    x = np.ma.array(x_mask, mask=~np.array(masks, dtype=bool))
    x_min = x.filled(fill_value=100000000.0)
    x_min = x_min.reshape(x_min.shape[0], -1).min(-1)
    y_mask = masks * np.expand_dims(y, axis=0)
    y_max = y_mask.reshape(x_mask.shape[0], -1).max(-1)
    y = np.ma.array(y_mask, mask=~np.array(masks, dtype=bool))
    y_min = y.filled(fill_value=100000000.0)
    y_min = y_min.reshape(y_min.shape[0], -1).min(-1)
    return np.stack([x_min, y_min, x_max, y_max], 1)

Compute the bounding boxes around the provided panoptic segmentation masks.

Args:
masks: masks in format `[number_masks, height, width]` where N is the number of masks

Returns:
boxes: bounding boxes in format `[number_masks, 4]` in xyxy format


def session_new(self, **kwargs):

        path = self._get_path('session_new')

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

Generate a session id for user based authentication.

A session id is required in order to use any of the write methods.

Args:
request_token: The token you generated for the user to approve.
The token needs to be approved before being
used here.

Returns:
A dict respresentation of the JSON returned from the API.


def DeregisterPlugin(cls, plugin_class):

    name = getattr(
        plugin_class, 'ARTIFACT_DEFINITION_NAME', plugin_class.__name__)
    name = name.lower()
    if name not in cls._plugins:
      raise KeyError(
          'Artifact plugin class not set for name: {0:s}.'.format(name))

    del cls._plugins[name]

    if name in cls._file_system_plugins:
      del cls._file_system_plugins[name]

    if name in cls._knowledge_base_plugins:
      del cls._knowledge_base_plugins[name]

    if name in cls._windows_registry_plugins:
      del cls._windows_registry_plugins[name]

Deregisters an preprocess plugin class.

Args:
plugin_class (type): preprocess plugin class.

Raises:
KeyError: if plugin class is not set for the corresponding name.
TypeError: if the source type of the plugin class is not supported.


def smartupgrade(self, restart=True, dependencies=False, prerelease=False):

        if not self.check():
            if self.verbose:
                print("Package {} already up-to-date!".format(self.pkg))
            return
        if self.verbose:
            print("Upgrading {} ...".format(self.pkg))
        self.upgrade(dependencies, prerelease, force=False)
        if restart:
            self.restart()

Upgrade the package if there is a later version available.
Args:
restart: restart app if True
dependencies: update package dependencies if True (see pip --no-deps)
prerelease: update to pre-release and development versions


def save_config(config, logdir=None):

  if logdir:
    with config.unlocked:
      config.logdir = logdir
    message = 'Start a new run and write summaries and checkpoints to {}.'
    tf.logging.info(message.format(config.logdir))
    tf.gfile.MakeDirs(config.logdir)
    config_path = os.path.join(config.logdir, 'config.yaml')
    with tf.gfile.FastGFile(config_path, 'w') as file_:
      yaml.dump(config, file_, default_flow_style=False)
  else:
    message = (
        'Start a new run without storing summaries and checkpoints since no '
        'logging directory was specified.')
    tf.logging.info(message)
  return config

Save a new configuration by name.

If a logging directory is specified, is will be created and the configuration
will be stored there. Otherwise, a log message will be printed.

Args:
config: Configuration object.
logdir: Location for writing summaries and checkpoints if specified.

Returns:
Configuration object.


def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    milk_quality_data = pandas.read_csv(known_args.pipeline_input_data)
    start = time.mktime(time.strptime('2023/06/29 10:00:00', '%Y/%m/%d %H:%M:%S'))
    test_stream = TestStream()
    test_stream.advance_watermark_to(start)
    samples = [milk_quality_data.iloc[i:i + 1] for i in range(len(milk_quality_data))]
    for watermark_offset, sample in enumerate(samples, 1):
        test_stream.advance_watermark_to(start + watermark_offset)
        test_stream.add_elements([sample])
    test_stream.advance_watermark_to_infinity()
    model_handler = XGBoostModelHandlerPandas(model_class=xgboost.XGBClassifier, model_state=known_args.model_state)
    with beam.Pipeline() as p:
        _ = p | test_stream | 'window' >> beam.WindowInto(window.SlidingWindows(30, 5)) | 'RunInference' >> RunInference(model_handler) | 'Count number of elements in window' >> beam.CombineGlobally(AggregateMilkQualityResults()).without_defaults() | 'Print' >> beam.Map(print)

Args:
argv: Command line arguments defined for this example.
save_main_session: Used for internal testing.
test_pipeline: Used for internal testing.


def easeInElastic(n, amplitude=1, period=0.3):
    _checkRange(n)
    return (1 - easeOutElastic((1 - n), amplitude=amplitude, period=period))

An elastic tween function that begins with an increasing wobble and then snaps into the destination.

Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def text(self, tag, textdata, step=None):
    if (step is None):
        step = self._step
    else:
        self._step = step
    smd = SummaryMetadata(plugin_data=SummaryMetadata.PluginData(plugin_name='text'))
    if isinstance(textdata, (str, bytes)):
        tensor = tf.make_tensor_proto(values=[textdata.encode(encoding='utf_8')], shape=(1,))
    else:
        textdata = onp.array(textdata)
        datashape = onp.shape(textdata)
        if (len(datashape) == 1):
            tensor = tf.make_tensor_proto(values=[td.encode(encoding='utf_8') for td in textdata], shape=(datashape[0],))
        elif (len(datashape) == 2):
            tensor = tf.make_tensor_proto(values=[td.encode(encoding='utf_8') for td in onp.reshape(textdata, (- 1))], shape=(datashape[0], datashape[1]))
    summary = Summary(value=[Summary.Value(tag=tag, metadata=smd, tensor=tensor)])
    self.add_summary(summary, step)

Saves a text summary.

Args:
tag: str: label for this data
textdata: string, or 1D/2D list/numpy array of strings
step: int: training step
Note: markdown formatting is rendered by tensorboard.


def _get_tf2_flags(parser):
    input_file_group = parser.add_mutually_exclusive_group()
    input_file_group.add_argument('--saved_model_dir', type=str, help='Full path of the directory containing the SavedModel.')
    input_file_group.add_argument('--keras_model_file', type=str, help='Full filepath of HDF5 file containing tf.Keras model.')
    parser.add_argument('--saved_model_tag_set', type=str, help='Comma-separated set of tags identifying the MetaGraphDef within the SavedModel to analyze. All tags must be present. In order to pass in an empty tag set, pass in "". (default "serve")')
    parser.add_argument('--saved_model_signature_key', type=str, help='Key identifying the SignatureDef containing inputs and outputs. (default DEFAULT_SERVING_SIGNATURE_DEF_KEY)')
    parser.add_argument('--enable_v1_converter', action='store_true', help='Enables the TensorFlow V1 converter in 2.0')

Returns ArgumentParser for tflite_convert for TensorFlow 2.0.

Args:
parser: ArgumentParser


def _write_input(self, input_dir="."):

        with open(os.path.join(input_dir, self.input_file), 'wt', encoding="utf-8") as inp:
            for k, v in self.control_params.items():
                inp.write('{} {}\n'.format(k, self._format_param_val(v)))

            for idx, mol in enumerate(self.mols):
                filename = os.path.join(
                    input_dir, '{}.{}'.format(
                        idx, self.control_params["filetype"])).encode("ascii")

                if self.control_params["filetype"] == "pdb":
                    self.write_pdb(mol, filename, num=idx+1)

                else:
                    a = BabelMolAdaptor(mol)
                    pm = pb.Molecule(a.openbabel_mol)
                    pm.write(self.control_params["filetype"], filename=filename,
                             overwrite=True)

                inp.write("\n")
                inp.write(
                    "structure {}.{}\n".format(
                        os.path.join(input_dir, str(idx)),
                        self.control_params["filetype"]))
                for k, v in self.param_list[idx].items():
                    inp.write('  {} {}\n'.format(k, self._format_param_val(v)))
                inp.write('end structure\n')

Write the packmol input file to the input directory.

Args:
input_dir (string): path to the input directory


def get_samples_live_last(self, sensor_id):

    url = "https:

    headers = self.__gen_headers()
    headers["Content-Type"] = "application/json"

    params = { "sensorId": sensor_id }
    url = self.__append_url_params(url, params)

    r = requests.get(url, headers=headers)
    return r.json()

Get the last sample recorded by the sensor.

Args:
sensor_id (string): hexadecimal id of the sensor to query, e.g.
``0x0013A20040B65FAD``

Returns:
list: dictionary objects containing sample data


def recode(self, table: pd.DataFrame, validate=False) -> pd.DataFrame:

        return self._recode_output(self._recode_input(table, validate=validate), validate=validate)

Pass the appropriate columns through each recoder function sequentially and return the final result.

Args:
table (pd.DataFrame): A dataframe on which to apply recoding logic.
validate (bool): If ``True``, recoded table must pass validation tests.


def read_cs_raw_symmetrized_tensors(self):
    header_pattern = '\\s+-{50,}\\s+\\s+Absolute Chemical Shift tensors\\s+\\s+-{50,}$'
    first_part_pattern = '\\s+UNSYMMETRIZED TENSORS\\s+$'
    row_pattern = '\\s+'.join((['([-]?\\d+\\.\\d+)'] * 3))
    unsym_footer_pattern = '^\\s+SYMMETRIZED TENSORS\\s+$'
    with zopen(self.filename, 'rt') as f:
        text = f.read()
    unsym_table_pattern_text = (((header_pattern + first_part_pattern) + '(?P<table_body>.+)') + unsym_footer_pattern)
    table_pattern = re.compile(unsym_table_pattern_text, (re.MULTILINE | re.DOTALL))
    rp = re.compile(row_pattern)
    m = table_pattern.search(text)
    if m:
        table_text = m.group('table_body')
        micro_header_pattern = 'ion\\s+\\d+'
        micro_table_pattern_text = (((micro_header_pattern + '\\s*^(?P<table_body>(?:\\s*') + row_pattern) + ')+)\\s+')
        micro_table_pattern = re.compile(micro_table_pattern_text, (re.MULTILINE | re.DOTALL))
        unsym_tensors = []
        for mt in micro_table_pattern.finditer(table_text):
            table_body_text = mt.group('table_body')
            tensor_matrix = []
            for line in table_body_text.rstrip().split('\n'):
                ml = rp.search(line)
                processed_line = [float(v) for v in ml.groups()]
                tensor_matrix.append(processed_line)
            unsym_tensors.append(tensor_matrix)
        self.data['unsym_cs_tensor'] = unsym_tensors
    else:
        raise ValueError('NMR UNSYMMETRIZED TENSORS is not found')

Parse the matrix form of NMR tensor before corrected to table.

Returns:
nsymmetrized tensors list in the order of atoms.


def save(self, target, format=None, encoding=None, **options):
    if (encoding is None):
        encoding = config.DEFAULT_ENCODING
    if (format is None):
        (_, format) = helpers.detect_scheme_and_format(target)
    writer_class = self.__custom_writers.get(format)
    if (writer_class is None):
        if (format not in config.WRITERS):
            message = ('Format "%s" is not supported' % format)
            raise exceptions.FormatError(message)
        writer_class = helpers.import_attribute(config.WRITERS[format])
    writer_options = helpers.extract_options(options, writer_class.options)
    if options:
        message = 'Not supported options "%s" for format "%s"'
        message = (message % (', '.join(options), format))
        raise exceptions.TabulatorException(message)
    writer = writer_class(**writer_options)
    writer.write(self.iter(), target, headers=self.headers, encoding=encoding)

Save stream to the local filesystem.

Args:
target (str): Path where to save the stream.
format (str, optional): The format the stream will be saved as. If
None, detects from the ``target`` path. Defaults to None.
encoding (str, optional): Saved file encoding. Defaults to
``config.DEFAULT_ENCODING``.
**options: Extra options passed to the writer.


def single_device(cl_device_type='GPU', platform=None, fallback_to_any_device_type=False):
    if isinstance(cl_device_type, str):
        cl_device_type = device_type_from_string(cl_device_type)
    device = None
    if (platform is None):
        platforms = cl.get_platforms()
    else:
        platforms = [platform]
    for platform in platforms:
        devices = platform.get_devices(device_type=cl_device_type)
        for dev in devices:
            if device_supports_double(dev):
                try:
                    env = CLEnvironment(platform, dev)
                    return [env]
                except cl.RuntimeError:
                    pass
    if (not device):
        if fallback_to_any_device_type:
            return cl.get_platforms()[0].get_devices()
        else:
            raise ValueError('No devices of the specified type ({}) found.'.format(cl.device_type.to_string(cl_device_type)))
    raise ValueError('No suitable OpenCL device found.')

Get a list containing a single device environment, for a device of the given type on the given platform.

This will only fetch devices that support double (possibly only double with a pragma
defined, but still, it should support double).

Args:
cl_device_type (cl.device_type.* or string): The type of the device we want,
can be a opencl device type or a string matching 'GPU', 'CPU' or 'ALL'.
platform (opencl platform): The opencl platform to select the devices from
fallback_to_any_device_type (boolean): If True, try to fallback to any possible device in the system.

Returns:
list of CLEnvironment: List with one element, the CL runtime environment requested.


def emit_region(self, timestamp: int, duration: int, pid: int, tid: int, category: str, name: str, args: Dict[str, Any]) -> None:
    event = self._create_event('X', category, name, pid, tid, timestamp)
    event['dur'] = duration
    event['args'] = args
    self._events.append(event)

Adds a region event to the trace.

Args:
timestamp:  The start timestamp of this region as a long integer.
duration:  The duration of this region as a long integer.
pid:  Identifier of the process generating this event as an integer.
tid:  Identifier of the thread generating this event as an integer.
category: The event category as a string.
name:  The event name as a string.
args:  A JSON-compatible dictionary of event arguments.


def readMonthTariffs(self, months_type):

        self.setContext("readMonthTariffs")
        try:

            req_type = binascii.hexlify(str(months_type).zfill(1))
            req_str = "01523102303031" + req_type + "282903"
            work_table = self.m_mons
            if months_type == ReadMonths.kWhReverse:
                work_table = self.m_rev_mons

            self.request(False)
            req_crc = self.calc_crc16(req_str[2:].decode("hex"))
            req_str += req_crc
            self.m_serial_port.write(req_str.decode("hex"))
            raw_ret = self.m_serial_port.getResponse(self.getContext())
            self.serialPostEnd()
            unpacked_read = self.unpackStruct(raw_ret, work_table)
            self.convertData(unpacked_read, work_table, self.m_kwh_precision)
            return_crc = self.calc_crc16(raw_ret[1:-2])
            if str(return_crc) == str(work_table["crc16"][MeterData.StringValue]):
                ekm_log("Months CRC success, type = " + str(req_type))
                self.setContext("")
                return True
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext("")
        return False

Serial call to read month tariffs block into meter object buffer.

Args:
months_type (int): A :class:`~ekmmeters.ReadMonths` value.

Returns:
bool: True on completion.


def accuracy_score(gold, pred, ignore_in_gold=[], ignore_in_pred=[]):

    gold, pred = _preprocess(gold, pred, ignore_in_gold, ignore_in_pred)

    if len(gold) and len(pred):
        acc = np.sum(gold == pred) / len(gold)
    else:
        acc = 0

    return acc

Calculate (micro) accuracy.
Args:
gold: A 1d array-like of gold labels
pred: A 1d array-like of predicted labels (assuming abstain = 0)
ignore_in_gold: A list of labels for which elements having that gold
label will be ignored.
ignore_in_pred: A list of labels for which elements having that pred
label will be ignored.

Returns:
A float, the (micro) accuracy score


def reassign_label(cls, destination_cluster, label):
    conn = Qubole.agent(version=Cluster.api_version)
    data = {'destination_cluster': destination_cluster, 'label': label}
    return conn.put((cls.rest_entity_path + '/reassign-label'), data)

Reassign a label from one cluster to another.

Args:
`destination_cluster`: id/label of the cluster to move the label to

`label`: label to be moved from the source cluster


async def runCmdLine(self, line):
    if self.echoline:
        self.outp.printf(f'{self.cmdprompt}{line}')
    ret = None
    name = line.split(None, 1)[0]
    cmdo = self.getCmdByName(name)
    if (cmdo is None):
        self.printf(('cmd not found: %s' % (name,)))
        return
    try:
        ret = (await cmdo.runCmdLine(line))
    except s_exc.CliFini:
        (await self.fini())
    except asyncio.CancelledError:
        self.printf('Cmd cancelled')
    except Exception as e:
        exctxt = traceback.format_exc()
        self.printf(exctxt)
        self.printf(('error: %s' % e))
    return ret

Run a single command line.

Args:
line (str): Line to execute.

Examples:
Execute the 'woot' command with the 'help' switch:

await cli.runCmdLine('woot --help')

Returns:
object: Arbitrary data from the cmd class.


def sub_location(self, nbr):
    assert (nbr > (- 1)), 'Sub location number must be greater or equal to 0!'
    assert (nbr < (self.nbr_of_sub_locations() - 1)), (('Sub location number must be lower than %d!' % self.nbr_of_sub_locations()) - 1)
    return self._locations_list[nbr]

Return a given sub location, 0-based.

Args:
nbr:

Returns:


def read_avg_core_poten(self):

    def pairwise(iterable):
        's -> (s0,s1), (s1,s2), (s2, s3), ...'
        a = iter(iterable)
        return zip(a, a)
    with zopen(self.filename, 'rt') as foutcar:
        line = foutcar.readline()
        aps = []
        while (line != ''):
            line = foutcar.readline()
            if ('the norm of the test charge is' in line):
                ap = []
                while (line != ''):
                    line = foutcar.readline()
                    if ('E-fermi' in line):
                        aps.append(ap)
                        break
                    data = line.split()
                    for (i, pot) in pairwise(data):
                        ap.append(float(pot))
    return aps

Read the core potential at each ionic step.

Returns:
A list for each ionic step containing a list of the average core
potentials for each atom: [[avg core pot]].

Example:
The average core potential of the 2nd atom of the structure at the
last ionic step is: [-1][1]


def disconnect(self, container, *args, **kwargs):

        if isinstance(container, Container):
            container = container.id
        return self.client.api.disconnect_container_from_network(
            container, self.id, *args, **kwargs
        )

Disconnect a container from this network.

Args:
container (str): Container to disconnect from this network, as
either an ID, name, or
:py:class:`~docker.models.containers.Container` object.
force (bool): Force the container to disconnect from a network.
Default: ``False``

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def WriteEvent(self, event):

    self.WriteEventStart()

    try:
      self.WriteEventBody(event)

    except errors.NoFormatterFound as exception:
      error_message = 'unable to retrieve formatter with error: {0!s}'.format(
          exception)
      self._ReportEventError(event, error_message)

    except errors.WrongFormatter as exception:
      error_message = 'wrong formatter with error: {0!s}'.format(exception)
      self._ReportEventError(event, error_message)

    self.WriteEventEnd()

Writes the event to the output.

Args:
event (EventObject): event.


def get_enumerations_from_bit_mask(enumeration, mask):
    return [x for x in enumeration if ((x.value & mask) == x.value)]

A utility function that creates a list of enumeration values from a bit
mask for a specific mask enumeration class.

Args:
enumeration (class): The enumeration class from which to draw
enumeration values.
mask (int): The bit mask from which to identify enumeration values.

Returns:
list: A list of enumeration values corresponding to the bit mask.


def _process_worker(call_queue, result_queue, shutdown):

    while True:
        try:
            call_item = call_queue.get(block=True, timeout=0.1)
        except queue.Empty:
            if shutdown.is_set():
                return
        else:
            try:
                r = call_item()
            except BaseException as e:
                result_queue.put(_ResultItem(call_item.work_id, exception=e))
            else:
                result_queue.put(_ResultItem(call_item.work_id, result=r))

Evaluates calls from call_queue and places the results in result_queue.

This worker is run in a seperate process.

Args:
call_queue: A multiprocessing.Queue of _CallItems that will be read and
evaluated by the worker.
result_queue: A multiprocessing.Queue of _ResultItems that will written
to by the worker.
shutdown: A multiprocessing.Event that will be set as a signal to the
worker that it should exit when call_queue is empty.


def _infer_shape(self, dimensions):
    n = np.prod(dimensions)
    m = np.prod(abs(np.array(self._shape)))
    v = np.array(self._shape)
    v[(v == (- 1))] = (n
    return tuple(v)

Replaces the -1 wildcard in the output shape vector.

This function infers the correct output shape given the input dimensions.

Args:
dimensions: List of input non-batch dimensions.

Returns:
Tuple of non-batch output dimensions.


def get_servo_temperature(self):

        data = []
        data.append(0x09)
        data.append(self.servoid)
        data.append(RAM_READ_REQ)
        data.append(TEMPERATURE_RAM)
        data.append(BYTE2)
        send_data(data)
        rxdata = []
        try:
            rxdata = SERPORT.read(13)
            return ord(rxdata[9])
        except HerkulexError:
            raise HerkulexError("Could not communicate with motors")

Gets the current temperature of Herkulex

Args:
none

Returns:
int: the current temperature register of Herkulex

Raises:
SerialException: Error occured while opening serial port


def __rmod__(self, other):

        try:
            other = as_dimension(other)
        except (TypeError, ValueError):
            return NotImplemented
        return other % self

Returns `other` modulo `self`.

Args:
other: Another Dimension, or a value accepted by `as_dimension`.

Returns:
A Dimension whose value is `other` modulo `self`.


def __init__(self, datastore_client, entity_kind_batches, entity_kind_images):

    self._datastore_client = datastore_client
    self._entity_kind_batches = entity_kind_batches
    self._entity_kind_images = entity_kind_images

    self._data = {}

Initialize ImageBatchesBase.

Args:
datastore_client: instance of the CompetitionDatastoreClient
entity_kind_batches: Cloud Datastore entity kind which is used to store
batches of images.
entity_kind_images: Cloud Datastore entity kind which is used to store
individual images.


def generators_from_logdir(logdir):

  subdirs = io_wrapper.GetLogdirSubdirectories(logdir)
  generators = [
      itertools.chain(*[
          generator_from_event_file(os.path.join(subdir, f))
          for f in tf.io.gfile.listdir(subdir)
          if io_wrapper.IsTensorFlowEventsFile(os.path.join(subdir, f))
      ]) for subdir in subdirs
  ]
  return generators

Returns a list of event generators for subdirectories with event files.

The number of generators returned should equal the number of directories
within logdir that contain event files. If only logdir contains event files,
returns a list of length one.

Args:
logdir: A log directory that contains event files.

Returns:
List of event generators for each subdirectory with event files.


def segment_text(text, seg_regex=SEG_REGEX):
    for m in seg_regex.finditer(text):
        (yield m.group(0))

Return an iterator of segments in the text.

Args:
text (unicode): string of IPA Unicode text
seg_regex (_regex.Pattern): compiled regex defining a segment (base +
modifiers)

Return:
generator: segments in the input text


def send_peers(self, connection_id):

        with self._lock:

            peer_endpoints = list(self._peers.values())
            if self._endpoint:
                peer_endpoints.append(self._endpoint)
            peers_response = GetPeersResponse(peer_endpoints=peer_endpoints)
            try:

                self._network.send(
                    validator_pb2.Message.GOSSIP_GET_PEERS_RESPONSE,
                    peers_response.SerializeToString(),
                    connection_id,
                    one_way=True)
            except ValueError:
                LOGGER.debug("Connection disconnected: %s", connection_id)

Sends a message containing our peers to the
connection identified by connection_id.

Args:
connection_id (str): A unique identifier which identifies an
connection on the network server socket.


def _find_reader_dataset(self, dataset_key, **dfilter):
    too_many = False
    for (reader_name, reader_instance) in self.readers.items():
        try:
            ds_id = reader_instance.get_dataset_key(dataset_key, **dfilter)
        except TooManyResults:
            LOG.trace('Too many datasets matching key {} in reader {}'.format(dataset_key, reader_name))
            too_many = True
            continue
        except KeyError:
            LOG.trace("Can't find dataset %s in reader %s", str(dataset_key), reader_name)
            continue
        LOG.trace('Found {} in reader {} when asking for {}'.format(str(ds_id), reader_name, repr(dataset_key)))
        try:
            return self.getitem(ds_id)
        except KeyError:
            return Node(ds_id, {'reader_name': reader_name})
    if too_many:
        raise TooManyResults('Too many keys matching: {}'.format(dataset_key))

Attempt to find a `DatasetID` in the available readers.

Args:
dataset_key (str, float, DatasetID):
Dataset name, wavelength, or a combination of `DatasetID`
parameters to use in searching for the dataset from the
available readers.
**dfilter (list or str): `DatasetID` parameters besides `name`
and `wavelength` to use to filter the
available datasets. Passed directly to
`get_dataset_key` of the readers, see
that method for more information.


def NetshStaticIp(interface, ip=u'127.0.0.9', subnet=u'255.255.255.255', gw=u'127.0.0.1'):
    args = ['/c', 'netsh', 'interface', 'ip', 'set', 'address', interface, 'static', ip, subnet, gw, '1']
    res = client_utils_common.Execute('cmd', args, time_limit=(- 1), bypass_whitelist=True)
    return res

Changes interface to a staticly set IP.

Sets IP configs to local if no paramaters passed.

Args:
interface: Name of the interface.
ip: IP address.
subnet: Subnet mask.
gw: IP address of the default gateway.

Returns:
A tuple of stdout, stderr, exit_status.


def _CalculateYLines(self, dists):

    tot_dist = sum(dists)
    if tot_dist > 0:
      pixel_dist = [float(d * (self._gheight-20))/tot_dist for d in dists]
      pixel_grid = [0]+[int(pd + sum(pixel_dist[0:i])) for i,pd in
                        enumerate(pixel_dist)]
    else:
      pixel_grid = []

    return pixel_grid

Builds a list with y-coordinates for the horizontal lines in the graph.

Args:
# One integer for each pair of stations
# indicating the approximate distance
dists: [0,33,140, ... ,X]

Returns:
# One integer y-coordinate for each station normalized between
# 0 and X, where X is the height of the graph in pixels
[0, 33, 140, ... , X]


def display_arr(screen, arr, video_size, transpose):

    if transpose:
        pyg_img = pygame.surfarray.make_surface(arr.swapaxes(0, 1))
    else:
        pyg_img = arr

    pyg_img = pygame.transform.scale(pyg_img, video_size)

    screen.blit(pyg_img, (0, 0))

Display an image to the pygame screen.

Args:
screen (pygame.Surface): the pygame surface to write frames to
arr (np.ndarray): numpy array representing a single frame of gameplay
video_size (tuple): the size to render the frame as
transpose (bool): whether to transpose the frame before displaying

Returns:
None


def _get_run_debug_urls(self):
    return ['file:

Get the debug_urls value for the current run() call.

Returns:
debug_urls: (list of str) Debug URLs for the current run() call.
Currently, the list consists of only one URL that is a file:// URL.


def _deduplicate_indexed_slices(values, indices):
    unique_indices, new_index_positions = array_ops.unique(indices)
    summed_values = math_ops.unsorted_segment_sum(values, new_index_positions, array_ops.shape(unique_indices)[0])
    return (summed_values, unique_indices)

Sums `values` associated with any non-unique `indices`.

Args:
values: A `Tensor` with rank >= 1.
indices: A one-dimensional integer `Tensor`, indexing into the first
dimension of `values` (as in an IndexedSlices object).
Returns:
A tuple of (`summed_values`, `unique_indices`) where `unique_indices` is a
de-duplicated version of `indices` and `summed_values` contains the sum of
`values` slices associated with each unique index.


def gmeta_pop(gmeta, info=False):
    if (type(gmeta) is GlobusHTTPResponse):
        gmeta = json.loads(gmeta.text)
    elif (type(gmeta) is str):
        gmeta = json.loads(gmeta)
    elif (type(gmeta) is not dict):
        raise TypeError('gmeta must be dict, GlobusHTTPResponse, or JSON string')
    results = []
    for res in gmeta['gmeta']:
        for con in res['content']:
            results.append(con)
    if info:
        fyi = {'total_query_matches': gmeta.get('total')}
        return (results, fyi)
    else:
        return results

Remove GMeta wrapping from a Globus Search result.
This function can be called on the raw GlobusHTTPResponse that Search returns,
or a string or dictionary representation of it.

Arguments:
gmeta (dict, str, or GlobusHTTPResponse): The Globus Search result to unwrap.
info (bool): If ``False``, will return a list of the results
and discard the metadata. If ``True``, will return a tuple containing
the results list, and other information about the query.
**Default**: ``False``.

Returns:
list (if ``info=False``): The unwrapped results.
tuple (if ``info=True``): The unwrapped results, and a dictionary of query information.


def has_chosen(state, correct, msgs):
    if (not issubclass(type(correct), int)):
        raise InstructorError('Inside `has_chosen()`, the argument `correct` should be an integer.')
    student_process = state.student_process
    if (not isDefinedInProcess(MC_VAR_NAME, student_process)):
        raise InstructorError('Option not available in the student process')
    else:
        selected_option = getOptionFromProcess(student_process, MC_VAR_NAME)
        if (not issubclass(type(selected_option), int)):
            raise InstructorError('selected_option should be an integer')
        if ((selected_option < 1) or (correct < 1)):
            raise InstructorError('selected_option and correct should be greater than zero')
        if ((selected_option > len(msgs)) or (correct > len(msgs))):
            raise InstructorError('there are not enough feedback messages defined')
        feedback_msg = msgs[(selected_option - 1)]
        state.reporter.success_msg = msgs[(correct - 1)]
        state.do_test(EqualTest(selected_option, correct, feedback_msg))

Test multiple choice exercise.

Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages
are passed to this function.

Args:
correct (int): the index of the correct answer (should be an instruction). Starts at 1.
msgs (list(str)): a list containing all feedback messages belonging to each choice of the
student. The list should have the same length as the number of options.


def read_data_event(self, whence, complete=False, can_flush=False):
    return Transition(None, _read_data_handler(whence, self, complete, can_flush))

Creates a transition to a co-routine for retrieving data as bytes.

Args:
whence (Coroutine): The co-routine to return to after the data is satisfied.
complete (Optional[bool]): True if STREAM_END should be emitted if no bytes are read or
available; False if INCOMPLETE should be emitted in that case.
can_flush (Optional[bool]): True if NEXT may be requested after INCOMPLETE is emitted as a result of this
data request.


def plot_residuals(self, plot=None):

        if plot is None:
            import matplotlib.pyplot as plot
        x = numpy.arange(1, len(self.residuals) + 1)
        y = _gvar.mean(self.residuals)
        yerr = _gvar.sdev(self.residuals)
        plot.errorbar(x=x, y=y, yerr=yerr, fmt='o', color='b')
        plot.ylabel('normalized residuals')
        xr = [x[0], x[-1]]
        plot.plot([x[0], x[-1]], [0, 0], 'r-')
        plot.fill_between(
            x=xr, y1=[-1,-1], y2=[1,1], color='r', alpha=0.075
            )
        return plot

Plot normalized fit residuals.

The sum of the squares of the residuals equals ``self.chi2``.
Individual residuals should be distributed about one, in
a Gaussian distribution.

Args:
plot: :mod:`matplotlib` plotter. If ``None``, uses
``matplotlib.pyplot`.

Returns:
Plotter ``plot``.


def _ParseApplicationPasswordRecord(self, parser_mediator, record):
    key = record.get('_key_', None)
    if ((not key) or (not key.startswith(b'ssgp'))):
        raise errors.ParseError('Unsupported application password record key value does not start with: "ssgp".')
    event_data = KeychainApplicationRecordEventData()
    event_data.account_name = self._ParseBinaryDataAsString(parser_mediator, record['acct'])
    event_data.comments = self._ParseBinaryDataAsString(parser_mediator, record['crtr'])
    event_data.entry_name = self._ParseBinaryDataAsString(parser_mediator, record['PrintName'])
    ssgp_hash = codecs.encode(key[4:], 'hex')
    event_data.ssgp_hash = codecs.decode(ssgp_hash, 'utf-8')
    event_data.text_description = self._ParseBinaryDataAsString(parser_mediator, record['desc'])
    date_time = self._ParseDateTimeValue(parser_mediator, record['cdat'])
    if date_time:
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_CREATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)
    date_time = self._ParseDateTimeValue(parser_mediator, record['mdat'])
    if date_time:
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_MODIFICATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts the information from an application password record.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
record (dict[str, object]): database record.

Raises:
ParseError: if Internet password record cannot be parsed.


def add_physical_qubit(self, physical_qubit):
    if (not isinstance(physical_qubit, int)):
        raise CouplingError('Physical qubits should be integers.')
    if (physical_qubit in self.physical_qubits):
        raise CouplingError(('The physical qubit %s is already in the coupling graph' % physical_qubit))
    self.graph.add_node(physical_qubit)
    self._dist_matrix = None
    self._qubit_list = None

Add a physical qubit to the coupling graph as a node.

physical_qubit (int): An integer representing a physical qubit.

Raises:
CouplingError: if trying to add duplicate qubit


def get_last_next(self, date):
    (past, future) = ((None, None), (None, None))
    for (mjd, value) in reversed(self.data):
        if (mjd <= date):
            past = (mjd, value)
            break
        future = (mjd, value)
    return (past, future)

Provide the last and next leap-second events relative to a date

Args:
date (float): Date in MJD
Return:
tuple:


def get_csv(filename):
    check_if_this_file_exist(filename)
    filename = os.path.abspath(filename)
    s = command_line(['exiftool', '-G', '-csv', '-sort', filename])
    if s:
        s = s.decode('utf-8')
        return s
    else:
        return 0

Return a csv representation of the exif

get a filename and returns a unicode string with a CSV format

Arguments:
filename {string} -- your filename

Returns:
[unicode] -- unicode string


def _read_template(template):

    template = _read_content_or_path(template)
    file_obj = StringIO.StringIO(template)

    return ET.parse(file_obj)

Read XSLT template.

Args:
template (str): Filename or XML string. Don't use ``\\n`` in case of
filename.

Returns:
obj: Required XML parsed with ``lxml.etree``.


def _calibrate_ir(radiance, coefs):
    logger.debug('Calibrating to brightness temperature')
    n = coefs['n']
    bteff = ((C2 * n) / xu.log((1 + ((C1 * (n ** 3)) / radiance.where((radiance > 0))))))
    bt = xr.DataArray(((bteff * coefs['b']) + coefs['a']))
    return bt.where(xu.logical_and((bt >= coefs['btmin']), (bt <= coefs['btmax'])))

Convert IR radiance to brightness temperature

Reference: [IR]

Args:
radiance: Radiance [mW m-2 cm-1 sr-1]
coefs: Dictionary of calibration coefficients. Keys:
n: The channel's central wavenumber [cm-1]
a: Offset [K]
b: Slope [1]
btmin: Minimum brightness temperature threshold [K]
btmax: Maximum brightness temperature threshold [K]

Returns:
Brightness temperature [K]


def seed(self, seed):

        if seed is None:
            self.env.seed = round(time.time())
        else:
            self.env.seed = seed
        return self.env.seed

Sets the random seed of the environment to the given value (current time, if seed=None).
Naturally deterministic Environments (e.g. ALE or some gym Envs) don't have to implement this method.

Args:
seed (int): The seed to use for initializing the pseudo-random number generator (default=epoch time in sec).
Returns: The actual seed (int) used OR None if Environment did not override this method (no seeding supported).


def tscore(sample1, sample2):

    if len(sample1) != len(sample2):
        raise ValueError("different number of values")
    error = pooled_sample_variance(sample1, sample2) / len(sample1)
    diff = statistics.mean(sample1) - statistics.mean(sample2)
    return diff / math.sqrt(error * 2)

Calculate a t-test score for the difference between two samples.

Args:
sample1: one sample.
sample2: the other sample.

Returns:
The t-test score, as a float.


def unarchive_user(self, user_id):

        url = self.record_url + "/unarchive"
        res = requests.patch(url=url, json={"user_id": user_id}, headers=HEADERS, verify=False)
        self.write_response_html_to_file(res,"bob.html")
        res.raise_for_status()

Unarchives the user with the specified user ID.

Args:
user_id: `int`. The ID of the user to unarchive.

Returns:
`NoneType`: None.


def _preserve_bonds(self, sliced_cartesian, use_lookup=None):
    if (use_lookup is None):
        use_lookup = settings['defaults']['use_lookup']
    included_atoms_set = set(sliced_cartesian.index)
    assert included_atoms_set.issubset(set(self.index)), 'The sliced Cartesian has to be a subset of the bigger frame'
    bond_dic = self.get_bonds(use_lookup=use_lookup)
    new_atoms = set([])
    for atom in included_atoms_set:
        new_atoms = (new_atoms | bond_dic[atom])
    new_atoms = (new_atoms - included_atoms_set)
    while (not (new_atoms == set([]))):
        index_of_interest = new_atoms.pop()
        included_atoms_set = (included_atoms_set | self.get_coordination_sphere(index_of_interest, n_sphere=float('inf'), only_surface=False, exclude=included_atoms_set, give_only_index=True, use_lookup=use_lookup))
        new_atoms = (new_atoms - included_atoms_set)
    molecule = self.loc[(included_atoms_set, :)]
    return molecule

Is called after cutting geometric shapes.

If you want to change the rules how bonds are preserved, when
applying e.g. :meth:`Cartesian.cut_sphere` this is the
function you have to modify.
It is recommended to inherit from the Cartesian class to
tailor it for your project, instead of modifying the
source code of ChemCoord.

Args:
sliced_frame (Cartesian):
use_lookup (bool): Use a lookup variable for
:meth:`~chemcoord.Cartesian.get_bonds`. The default is
specified in ``settings['defaults']['use_lookup']``

Returns:
Cartesian:


def get_value(data, key):
    ref = data
    try:
        for subkey in key.split('.'):
            if isinstance(ref, dict):
                ref = ref[subkey]
            else:
                print(('CRITICAL: Cannot use subkey %s on non-dictionary element' % subkey))
                return None
        return ref
    except KeyError:
        return None

Follow the dot notation to get the proper field, then perform the action

Args:
data: the data as a dictionary (required to be a dictionary)
key: the key (as dot notation) into the data that gives the field (IP.src)

Returns:
the value of the field(subfield) if it exist, otherwise None


def add_moving_summary(*args, **kwargs):
    decay = kwargs.pop('decay', 0.95)
    coll = kwargs.pop('collection', MOVING_SUMMARY_OPS_KEY)
    summ_coll = kwargs.pop('summary_collections', None)
    assert (len(kwargs) == 0), ('Unknown arguments: ' + str(kwargs))
    ctx = get_current_tower_context()
    if ((ctx is not None) and (not ctx.is_main_training_tower)):
        return []
    graph = tf.get_default_graph()
    try:
        control_flow_ctx = graph._get_control_flow_context()
        if ((control_flow_ctx is not None) and control_flow_ctx.IsXLAContext()):
            return
    except Exception:
        pass
    if (tf.get_variable_scope().reuse is True):
        logger.warn('add_moving_summary() called under reuse=True scope, ignored.')
        return []
    for x in args:
        assert isinstance(x, (tf.Tensor, tf.Variable)), x
        assert (x.get_shape().ndims == 0), 'add_moving_summary() only accepts scalar tensor! Got one with {}'.format(x.get_shape())
    ema_ops = []
    for c in args:
        name = re.sub('tower[0-9]+/', '', c.op.name)
        with tf.name_scope(None):
            if (not c.dtype.is_floating):
                c = tf.cast(c, tf.float32)
            with _enter_vs_reuse_ns('EMA') as vs:
                ema_var = tf.get_variable(name, shape=c.shape, dtype=c.dtype, initializer=tf.constant_initializer(), trainable=False)
                ns = vs.original_name_scope
            with tf.name_scope(ns):
                ema_op = moving_averages.assign_moving_average(ema_var, c, decay, zero_debias=True, name=(name + '_EMA_apply'))
            ema_ops.append(ema_op)
        with tf.name_scope(None):
            tf.summary.scalar((name + '-summary'), ema_op, collections=summ_coll)
    if (coll is not None):
        for op in ema_ops:
            tf.add_to_collection(coll, op)
    return ema_ops

Summarize the moving average for scalar tensors.
This function is a no-op if not calling from main training tower.

Args:
args: scalar tensors to summarize
decay (float): the decay rate. Defaults to 0.95.
collection (str or None): the name of the collection to add EMA-maintaining ops.
The default will work together with the default
:class:`MovingAverageSummary` callback.
summary_collections ([str]): the names of collections to add the
summary op. Default is TF's default (`tf.GraphKeys.SUMMARIES`).

Returns:
[tf.Tensor]: list of tensors returned by assign_moving_average,
which can be used to maintain the EMA.


async def export_image(self, name: str):
    response = (await self.docker._query('images/{name}/get'.format(name=name), 'GET'))
    return response.content

Get a tarball of an image by name or id.

Args:
name: name/id of the image to be exported

Returns:
Streamreader of tarball image


def print_args(output=sys.stdout):

    def decorator(func):
        'The decorator function.\n        '

        @wraps(func)
        def _(*args, **kwargs):
            'The decorated function.\n            '
            output.write('Args: {0}, KwArgs: {1}\n'.format(str(args), str(kwargs)))
            return func(*args, **kwargs)
        return _
    return decorator

Decorate a function so that print arguments before calling it.

Args:
output: writable to print args. (Default: sys.stdout)


def _rmsprop(self, grads, cache=None, decay_rate=0.95):

        if cache is None:
            cache = np.zeros_like(grads)
        cache = decay_rate * cache + (1 - decay_rate) * grads ** 2
        step = -grads / np.sqrt(cache + K.epsilon())
        return step, cache

Uses RMSProp to compute step from gradients.

Args:
grads: numpy array of gradients.
cache: numpy array of same shape as `grads` as RMSProp cache
decay_rate: How fast to decay cache

Returns:
A tuple of
step: numpy array of the same shape as `grads` giving the step.
Note that this does not yet take the learning rate into account.
cache: Updated RMSProp cache.


def open(self, host, port=23):

        self._telnet_client.open(host, port)
        config_str = self._telnet_client.cmd("MN?")
        if config_str.startswith("MN="):
            config_str = config_str[len("MN="):]
        self.properties = dict(
            zip(['model', 'max_freq', 'max_atten'], config_str.split("-", 2)))
        self.max_atten = float(self.properties['max_atten'])

Opens a telnet connection to the desired AttenuatorDevice and
queries basic information.

Args:
host: A valid hostname (IP address or DNS-resolvable name) to an
MC-DAT attenuator instrument.
port: An optional port number (defaults to telnet default 23)


def jacobian_s(nodes, degree, dimension):
    r
    num_nodes = (degree * (degree + 1))
    result = np.empty((dimension, num_nodes), order="F")
    index = 0
    i = 0
    for num_vals in six.moves.xrange(degree, 0, -1):
        for _ in six.moves.xrange(num_vals):
            result[:, index] = nodes[:, i + 1] - nodes[:, i]

            index += 1
            i += 1

        i += 1
    return float(degree) * result

r"""Compute :math:`\frac{\partial B}{\partial s}`.

.. note::

This is a helper for :func:`_jacobian_both`, which has an
equivalent Fortran implementation.

Args:
nodes (numpy.ndarray): Array of nodes in a surface.
degree (int): The degree of the surface.
dimension (int): The dimension the surface lives in.

Returns:
numpy.ndarray: Nodes of the Jacobian surface in
B |eacute| zier form.


def set_label_list(self, label_lists):

        if isinstance(label_lists, annotations.LabelList):
            label_lists = [label_lists]

        for label_list in label_lists:
            if label_list.idx is None:
                label_list.idx = 'default'

            label_list.utterance = self
            self.label_lists[label_list.idx] = label_list

Set the given label-list for this utterance.
If the label-list-idx is not set, ``default`` is used.
If there is already a label-list with the given idx,
it will be overriden.

Args:
label_list (LabelList, list): A single or multi. label-lists to add.


def needle_statistics(infile):
    alignments = list(AlignIO.parse(infile, 'emboss'))
    alignment_properties = defaultdict(dict)
    with open(infile) as f:
        line = f.readline()
        for i in range(len(alignments)):
            while (line.rstrip() != '
                line = f.readline()
                if (not line):
                    raise StopIteration
            while (line[0] == '
                parts = line[1:].split(':', 1)
                key = parts[0].lower().strip()
                if (key == '1'):
                    a_id = parts[1].strip()
                if (key == '2'):
                    b_id = parts[1].strip()
                if (key == 'identity'):
                    ident_parse = parts[1].strip().replace('(', '').replace(')', '').replace('%', '').split()
                    ident_num = int(ident_parse[0].split('/')[0])
                    ident_percent = float(ident_parse[1])
                    alignment_properties[((a_id + '_') + b_id)]['identity'] = ident_num
                    alignment_properties[((a_id + '_') + b_id)]['percent_identity'] = ident_percent
                if (key == 'similarity'):
                    sim_parse = parts[1].strip().replace('(', '').replace(')', '').replace('%', '').split()
                    sim_num = int(sim_parse[0].split('/')[0])
                    sim_percent = float(sim_parse[1])
                    alignment_properties[((a_id + '_') + b_id)]['similarity'] = sim_num
                    alignment_properties[((a_id + '_') + b_id)]['percent_similarity'] = sim_percent
                if (key == 'gaps'):
                    gap_parse = parts[1].strip().replace('(', '').replace(')', '').replace('%', '').split()
                    gap_num = int(gap_parse[0].split('/')[0])
                    gap_percent = float(gap_parse[1])
                    alignment_properties[((a_id + '_') + b_id)]['gaps'] = gap_num
                    alignment_properties[((a_id + '_') + b_id)]['percent_gaps'] = gap_percent
                if (key == 'score'):
                    score = float(parts[1].strip())
                    alignment_properties[((a_id + '_') + b_id)]['score'] = score
                line = f.readline()
    return alignment_properties

Reads in a needle alignment file and spits out statistics of the alignment.

Args:
infile (str): Alignment file name

Returns:
dict: alignment_properties - a dictionary telling you the number of gaps, identity, etc.


def __init__(self, outer_index, inner_index):
    if outer_index.batch_dims != inner_index.batch_dims:
        raise ValueError('outer_index.batch_dims and inner_index.batch_dims must be the same.')
    super().__init__(indices=inner_index.indices + outer_index.indices * inner_index.num_segments, num_segments=inner_index.num_segments * outer_index.num_segments, batch_dims=inner_index.batch_dims)
    self.outer_index = outer_index
    self.inner_index = inner_index

Combines indices i and j into pairs (i, j). The result is an index where each segment (i, j) is the
intersection of segments i and j. For example if the inputs represent table cells indexed by respectively rows
and columns the output will be a table indexed by (row, column) pairs, i.e. by cell. The implementation
combines indices {0, .., n - 1} and {0, .., m - 1} into {0, .., nm - 1}. The output has *num_segments* equal to
*outer_index.num_segments* * *inner_index.num_segments*

Args:
outer_index (`IndexMap`):
IndexMap.
inner_index (`IndexMap`):
IndexMap, must have the same shape as *outer_index*.


def seq_int_arr(seqs):
    return np.array([[NT_TO_INT[c] for c in x.upper()] for x in seqs])

Convert list of ACGT strings to matix of 1-4 ints

Args:
seqs (list of str): nucleotide sequences with only 'ACGT' characters

Returns:
numpy.array of int: matrix of integers from 1 to 4 inclusive representing A, C, G, and T
str: nucleotide sequence string


def _handle_is_dag_stopped(self, request):
    return Response(success=True, uid=request.uid, payload={'is_stopped': (request.payload['dag_name'] in self._stop_dags)})

The handler for the dag_stopped request.

The dag_stopped request checks whether a dag is flagged to be terminated.

Args:
request (Request): Reference to a request object containing the
incoming request. The payload has to contain the
following fields:
'dag_name': the name of the dag that should be checked

Returns:
Response: A response object containing the following fields:
- is_stopped: True if the dag is flagged to be stopped.


def flags(cls):

    assert cls.__bases__ == (object,)

    d = dict(cls.__dict__)
    new_type = type(cls.__name__, (int,), d)
    new_type.__module__ = cls.__module__

    map_ = {}
    for key, value in iteritems(d):
        if key.upper() == key and isinstance(value, integer_types):
            value_instance = new_type(value)
            setattr(new_type, key, value_instance)
            map_[value] = key

    def str_(self):
        value = int(self)
        matches = []
        for k, v in map_.items():
            if value & k:
                matches.append("%s.%s" % (type(self).__name__, v))
                value &= ~k
        if value != 0 or not matches:
            matches.append(text_type(value))

        return " | ".join(matches)

    def repr_(self):
        return "<%s: %d>" % (str(self), int(self))

    setattr(new_type, "__repr__", repr_)
    setattr(new_type, "__str__", str_)

    return new_type

A decorator for creating an int flags class.

Makes the values a subclass of the type and implements repr/str.
The new class will be a subclass of int.

Args:
cls (type): The class to convert to an flags

Returns:
type: A new class

::

@flags
class Foo(object):
FOO = 1
BAR = 2


def add_graph(
        self,
        y,
        x_label=None,
        y_label="",
        title="",
        x_run=None,
        y_run=None,
        svg_size_px=None,
        key_position="bottom right",
    ):

        if x_run is None:
            x_run = self.default_x_run
        if y_run is None:
            y_run = self.default_y_run
        if svg_size_px is None:
            svg_size_px = self.default_svg_size_px

        for panel in self.panels:
            x_run = self._load_x_run(x_run)
            y_run = self._load_y_run(y_run)
            svg_size_px = self._load_svg_size_px(svg_size_px)
            panel.add_graph(
                y=y,
                x_run=x_run,
                y_run=y_run,
                svg_size_px=svg_size_px,
                y_label=y_label,
                x_label=x_label if x_label is not None else self.default_x_label,
                title=title,
                key_position=key_position,
            )

Add a new graph to the overlap report.

Args:
y (str): Value plotted on y-axis.
x_label (str): Label on x-axis.
y_label (str): Label on y-axis.
title (str): Title of the plot.
x_run ((float,float)): x-range.
y_run ((int,int)): y-rang.
svg_size_px ((int,int): Size of SVG image in pixels.
key_position (str): GnuPlot position of the legend.


def _maybe_partial_apply_variables(fn, args, kwargs):

    def is_distributed_var(x):
        flat = nest.flatten(x)
        return flat and isinstance(flat[0], values.DistributedVariable)
    var_kwargs = {}
    nonvar_kwargs = {}
    if kwargs:
        var_kwargs = {k: v for k, v in kwargs.items() if is_distributed_var(v)}
    if var_kwargs:
        nonvar_kwargs = {k: v for k, v in kwargs.items() if not is_distributed_var(v)}
    positional_args = []
    index_of_star_args = None
    for i, p in enumerate(tf_inspect.signature(fn).parameters.values()):
        if i == 0 and p.name == 'self':
            continue
        if p.kind == tf_inspect.Parameter.POSITIONAL_OR_KEYWORD:
            positional_args.append(p.name)
        elif p.kind == tf_inspect.Parameter.VAR_POSITIONAL:
            index_of_star_args = i
        elif p.kind == tf_inspect.Parameter.POSITIONAL_ONLY:
            if var_kwargs or any((is_distributed_var(a) for a in args)):
                raise ValueError(f'Mixing Variables and positional-only parameters not supported by TPUStrategy. Received {len(var_kwargs)} DistributedVariables in **kwargs and {sum((is_distributed_var(a) for a in args))} in *args, expected zero for both.')
            return (fn, args, kwargs)
    star_args = []
    have_seen_var_arg = False
    for i, a in enumerate(args):
        if is_distributed_var(a):
            if index_of_star_args is not None and i >= index_of_star_args:
                raise ValueError('TPUStrategy.run() cannot handle Variables passed to *args. Either name the function argument, or capture the Variable implicitly.')
            if len(positional_args) <= i:
                raise ValueError('Too many positional arguments passed to call to TPUStrategy.run().')
            var_kwargs[positional_args[i]] = a
            have_seen_var_arg = True
        else:
            if index_of_star_args is not None and i >= index_of_star_args:
                if have_seen_var_arg:
                    raise ValueError('TPUStrategy.run() cannot handle both Variables and a mix of positional args and *args. Either remove the *args, or capture the Variable implicitly.')
                else:
                    star_args.append(a)
                    continue
            if len(positional_args) <= i:
                raise ValueError('Too many positional arguments passed to call to TPUStrategy.run().')
            nonvar_kwargs[positional_args[i]] = a
    if var_kwargs:
        return (functools.partial(fn, **var_kwargs), star_args, nonvar_kwargs)
    return (fn, args, kwargs)

Inspects arguments to partially apply any DistributedVariable.

This avoids an automatic cast of the current variable value to tensor.

Note that a variable may be captured implicitly with Python scope instead of
passing it to run(), but supporting run() keeps behavior consistent
with MirroredStrategy.

Since positional arguments must be applied from left to right, this function
does some tricky function inspection to move variable positional arguments
into kwargs. As a result of this, we can't support passing Variables as *args,
nor as args to functions which combine both explicit positional arguments and
*args.

Args:
fn: The function to run, as passed to run().
args: Positional arguments to fn, as passed to run().
kwargs: Keyword arguments to fn, as passed to run().

Returns:
A tuple of the function (possibly wrapped), args, kwargs (both
possibly filtered, with members of args possibly moved to kwargs).
If no variables are found, this function is a noop.

Raises:
ValueError: If the function signature makes unsupported use of *args, or if
too many arguments are passed.


def __init__(self, name, description=None):

    super(ArtifactDefinition, self).__init__()
    self.conditions = []
    self.description = description
    self.name = name
    self.labels = []
    self.provides = []
    self.sources = []
    self.supported_os = []
    self.urls = []

Initializes an artifact definition.

Args:
name (str): name that uniquely identifiers the artifact definition.
description (Optional[str]): description of the artifact definition.


def intersect(self, other):
    lowest_stop = min(self.stop_hz, other.stop_hz)
    highest_start = max(self.start_hz, other.start_hz)
    return FrequencyBand(highest_start, lowest_stop)

Return the intersection between this frequency band and another.

Args:
other (FrequencyBand): the instance to intersect with

Examples::
>>> import zounds
>>> b1 = zounds.FrequencyBand(500, 1000)
>>> b2 = zounds.FrequencyBand(900, 2000)
>>> intersection = b1.intersect(b2)
>>> intersection.start_hz, intersection.stop_hz
(900, 1000)


def plot_weight_posteriors(names, qm_vals, qs_vals, fname):
    fig = figure.Figure(figsize=(6, 3))
    canvas = backend_agg.FigureCanvasAgg(fig)
    ax = fig.add_subplot(1, 2, 1)
    for (n, qm) in zip(names, qm_vals):
        sns.distplot(qm.flatten(), ax=ax, label=n)
    ax.set_title('weight means')
    ax.set_xlim([(- 1.5), 1.5])
    ax.legend()
    ax = fig.add_subplot(1, 2, 2)
    for (n, qs) in zip(names, qs_vals):
        sns.distplot(qs.flatten(), ax=ax)
    ax.set_title('weight stddevs')
    ax.set_xlim([0, 1.0])
    fig.tight_layout()
    canvas.print_figure(fname, format='png')
    print('saved {}'.format(fname))

Save a PNG plot with histograms of weight means and stddevs.

Args:
names: A Python `iterable` of `str` variable names.
qm_vals: A Python `iterable`, the same length as `names`,
whose elements are Numpy `array`s, of any shape, containing
posterior means of weight varibles.
qs_vals: A Python `iterable`, the same length as `names`,
whose elements are Numpy `array`s, of any shape, containing
posterior standard deviations of weight varibles.
fname: Python `str` filename to save the plot to.


def call(self, input_ids: tf.Tensor | None=None, attention_mask: tf.Tensor | None=None, decoder_input_ids: tf.Tensor | None=None, decoder_attention_mask: tf.Tensor | None=None, decoder_position_ids: tf.Tensor | None=None, head_mask: tf.Tensor | None=None, decoder_head_mask: tf.Tensor | None=None, cross_attn_head_mask: tf.Tensor | None=None, encoder_outputs: TFBaseModelOutput | None=None, past_key_values: Tuple[Tuple[tf.Tensor]] | None=None, inputs_embeds: tf.Tensor | None=None, decoder_inputs_embeds: tf.Tensor | None=None, use_cache: bool | None=None, output_attentions: bool | None=None, output_hidden_states: bool | None=None, return_dict: bool | None=None, labels: tf.Tensor | None=None, training: bool=False) -> Tuple[tf.Tensor] | TFSeq2SeqLMOutput:
    if labels is not None:
        labels = tf.where(labels == self.config.pad_token_id, tf.fill(shape_list(labels), tf.cast(-100, labels.dtype)), labels)
        use_cache = False
        if decoder_input_ids is None and decoder_inputs_embeds is None:
            decoder_input_ids = shift_tokens_right(labels, self.config.pad_token_id, self.config.decoder_start_token_id)
    outputs = self.model(input_ids, attention_mask=attention_mask, decoder_input_ids=decoder_input_ids, encoder_outputs=encoder_outputs, decoder_attention_mask=decoder_attention_mask, decoder_position_ids=decoder_position_ids, head_mask=head_mask, decoder_head_mask=decoder_head_mask, cross_attn_head_mask=cross_attn_head_mask, past_key_values=past_key_values, inputs_embeds=inputs_embeds, decoder_inputs_embeds=decoder_inputs_embeds, use_cache=use_cache, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, training=training)
    lm_logits = tf.matmul(outputs[0], self.model.shared.weights, transpose_b=True)
    lm_logits = self.bias_layer(lm_logits)
    masked_lm_loss = None if labels is None else self.hf_compute_loss(labels, lm_logits)
    if not return_dict:
        output = (lm_logits,) + outputs[1:]
        return (masked_lm_loss,) + output if masked_lm_loss is not None else output
    return TFSeq2SeqLMOutput(loss=masked_lm_loss, logits=lm_logits, past_key_values=outputs.past_key_values, decoder_hidden_states=outputs.decoder_hidden_states, decoder_attentions=outputs.decoder_attentions, cross_attentions=outputs.cross_attentions, encoder_last_hidden_state=outputs.encoder_last_hidden_state, encoder_hidden_states=outputs.encoder_hidden_states, encoder_attentions=outputs.encoder_attentions)

labels (`tf.tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

Returns:


def set_callback(self, property_name, callback):
    if property_name not in self._config:
        raise KeyError('%s is not a valid property name.' % property_name)
    if not callable(callback):
        raise TypeError('The callback object provided is not callable.')
    self._set_callbacks[property_name] = callback

Set a set-callback for given property.

Args:
property_name: Name of the property.
callback: The callback as a `callable` of signature:
def cbk(config):
where config is the config after it is set to the new value.
The callback is invoked each time the set() method is called with the
matching property_name.

Raises:
KeyError: If property_name does not exist.
TypeError: If `callback` is not callable.


def get_clinvar_id(self, submission_id):
    submission_obj = self.clinvar_submission_collection.find_one({'_id': ObjectId(submission_id)})
    clinvar_subm_id = submission_obj.get('clinvar_subm_id')
    return clinvar_subm_id

Returns the official Clinvar submission ID for a submission object

Args:
submission_id(str): submission_id(str) : id of the submission

Returns:
clinvar_subm_id(str): a string with a format: SUB[0-9]. It is obtained from clinvar portal when starting a new submission


def optimize(self, sess, batch_index):
    feed_dict = {self._batch_index: batch_index, self._per_device_batch_size: self._loaded_per_device_batch_size, self._max_seq_len: self._loaded_max_seq_len}
    for tower in self._towers:
        feed_dict.update(tower.loss_graph.extra_compute_grad_feed_dict())
    fetches = {'train': self._train_op}
    for tower in self._towers:
        fetches.update(tower.loss_graph.extra_compute_grad_fetches())
    return sess.run(fetches, feed_dict=feed_dict)

Run a single step of SGD.

Runs a SGD step over a slice of the preloaded batch with size given by
self._loaded_per_device_batch_size and offset given by the batch_index
argument.

Updates shared model weights based on the averaged per-device
gradients.

Args:
sess: TensorFlow session.
batch_index: Offset into the preloaded data. This value must be
between `0` and `tuples_per_device`. The amount of data to
process is at most `max_per_device_batch_size`.

Returns:
The outputs of extra_ops evaluated over the batch.


def preprocess_JPEG(self, image, **kwargs):

        save_kwargs = {
            'progressive': VERSATILEIMAGEFIELD_PROGRESSIVE_JPEG,
            'quality': QUAL
        }
        if image.mode != 'RGB':
            image = image.convert('RGB')
        return (image, save_kwargs)

Receive a PIL Image instance of a JPEG and returns 2-tuple.

Args:
* [0]: Image instance, converted to RGB
* [1]: Dict with a quality key (mapped to the value of `QUAL` as
defined by the `VERSATILEIMAGEFIELD_JPEG_RESIZE_QUALITY`
setting)


def waitForEvent(self, event_name, predicate, timeout=DEFAULT_TIMEOUT):
    deadline = (time.time() + timeout)
    while (time.time() <= deadline):
        rpc_timeout = (deadline - time.time())
        if (rpc_timeout < 0):
            break
        rpc_timeout = min(rpc_timeout, MAX_TIMEOUT)
        try:
            event = self.waitAndGet(event_name, rpc_timeout)
        except TimeoutError:
            break
        if predicate(event):
            return event
    raise TimeoutError(self._ad, ('Timed out after %ss waiting for an "%s" event that satisfies the predicate "%s".' % (timeout, event_name, predicate.__name__)))

Wait for an event of a specific name that satisfies the predicate.

This call will block until the expected event has been received or time
out.

The predicate function defines the condition the event is expected to
satisfy. It takes an event and returns True if the condition is
satisfied, False otherwise.

Note all events of the same name that are received but don't satisfy
the predicate will be discarded and not be available for further
consumption.

Args:
event_name: string, the name of the event to wait for.
predicate: function, a function that takes an event (dictionary) and
returns a bool.
timeout: float, default is 120s.

Returns:
dictionary, the event that satisfies the predicate if received.

Raises:
TimeoutError: raised if no event that satisfies the predicate is
received after timeout seconds.


def total_stored(self, wanted, slots=None):

        if slots is None:
            slots = self.window.slots
        wanted = make_slot_check(wanted)
        return sum(slot.amount for slot in slots if wanted(slot))

Calculates the total number of items of that type
in the current window or given slot range.

Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)


def convert(self, value):

        if self._type is str:
            return str(value)
        elif self._type is int:
            try:
                return int(value)
            except (UnicodeError, ValueError):
                raise WorkflowArgumentError('Cannot convert {} to int'.format(value))
        elif self._type is float:
            try:
                return float(value)
            except (UnicodeError, ValueError):
                raise WorkflowArgumentError('Cannot convert {} to float'.format(value))
        elif self._type is bool:
            if isinstance(value, bool):
                return bool(value)
            value = value.lower()
            if value in ('true', '1', 'yes', 'y'):
                return True
            elif value in ('false', '0', 'no', 'n'):
                return False
            raise WorkflowArgumentError('Cannot convert {} to bool'.format(value))
        else:
            return value

Convert the specified value to the type of the option.

Args:
value: The value that should be converted.

Returns:
The value with the type given by the option.


def ReceiveMessages(self, client_id, messages):
    if data_store.RelationalDBEnabled():
        return self.ReceiveMessagesRelationalFlows(client_id, messages)
    now = time.time()
    with queue_manager.QueueManager(token=self.token) as manager:
        for (session_id, msgs) in iteritems(collection.Group(messages, operator.attrgetter('session_id'))):
            leftover_msgs = self.HandleWellKnownFlows(msgs)
            unprocessed_msgs = []
            for msg in leftover_msgs:
                if ((msg.auth_state == msg.AuthorizationState.AUTHENTICATED) or (msg.session_id == self.unauth_allowed_session_id)):
                    unprocessed_msgs.append(msg)
            if (len(unprocessed_msgs) < len(leftover_msgs)):
                logging.info('Dropped %d unauthenticated messages for %s', (len(leftover_msgs) - len(unprocessed_msgs)), client_id)
            if (not unprocessed_msgs):
                continue
            for msg in unprocessed_msgs:
                manager.QueueResponse(msg)
            for msg in unprocessed_msgs:
                if (msg.request_id == 0):
                    manager.QueueNotification(session_id=msg.session_id)
                    break
                elif (msg.type == rdf_flows.GrrMessage.Type.STATUS):
                    if msg.HasTaskID():
                        manager.DeQueueClientRequest(msg)
                    manager.QueueNotification(session_id=msg.session_id, last_status=msg.request_id)
                    stat = rdf_flows.GrrStatus(msg.payload)
                    if (stat.status == rdf_flows.GrrStatus.ReturnedStatus.CLIENT_KILLED):
                        crash_details = rdf_client.ClientCrash(client_id=client_id, session_id=session_id, backtrace=stat.backtrace, crash_message=stat.error_message, nanny_status=stat.nanny_status, timestamp=rdfvalue.RDFDatetime.Now())
                        events.Events.PublishEvent('ClientCrash', crash_details, token=self.token)
    logging.debug('Received %s messages from %s in %s sec', len(messages), client_id, (time.time() - now))

Receives and processes the messages from the source.

For each message we update the request object, and place the
response in that request's queue. If the request is complete, we
send a message to the worker.

Args:
client_id: The client which sent the messages.
messages: A list of GrrMessage RDFValues.


def generate_host_passthrough(self, vcpu_num):

        cpu = ET.Element('cpu', mode='host-passthrough')
        cpu.append(self.generate_topology(vcpu_num))
        if vcpu_num > 1:
            cpu.append(self.generate_numa(vcpu_num))
        return cpu

Generate host-passthrough XML cpu node

Args:
vcpu_num(str): number of virtual CPUs

Returns:
lxml.etree.Element: CPU XML node