def get_variables(self, include_submodules=False, include_nontrainable=False):

        if include_nontrainable:
            model_variables = [self.all_variables[key] for key in sorted(self.all_variables)]

            states_preprocessing_variables = [
                variable for name in sorted(self.states_preprocessing)
                for variable in self.states_preprocessing[name].get_variables()
            ]
            model_variables += states_preprocessing_variables

            actions_exploration_variables = [
                variable for name in sorted(self.actions_exploration)
                for variable in self.actions_exploration[name].get_variables()
            ]
            model_variables += actions_exploration_variables

            if self.reward_preprocessing is not None:
                reward_preprocessing_variables = self.reward_preprocessing.get_variables()
                model_variables += reward_preprocessing_variables

        else:
            model_variables = [self.variables[key] for key in sorted(self.variables)]

        return model_variables

Returns the TensorFlow variables used by the model.

Args:
        include_submodules: Includes variables of submodules (e.g. baseline, target network)
            if true.
        include_nontrainable: Includes non-trainable variables if true.

Returns:
        List of variables.


def from_hyperplane(basis, origin, point, internal = True):

        basis = np.array(basis)
        assert basis.shape[0] + 1 == basis.shape[1]

        big_basis = np.zeros((basis.shape[1], basis.shape[1]))
        big_basis[:basis.shape[0],:basis.shape[1]] = basis

        u, s, vh = np.linalg.svd(big_basis)
        null_mask = (s <= 1e-8)
        normal = np.compress(null_mask, vh, axis=0)[0]

        if np.inner(np.array(point)-np.array(origin), normal) > 0:
            if internal:
                normal *= -1
        else:
            if not internal:
                normal *= -1
        offset = -np.dot(origin, normal)
        return Halfspace(normal, offset)

Returns a Halfspace defined by a list of vectors parallel to the
    bounding hyperplane.

Args:
        basis: basis for the hyperplane (array with vector rows)
        origin: point on the hyperplane
        point: point not on the hyperplane
        internal: whether point is inside the halfspace


def get_chromosomes(self, sv=False):

        if sv:
            res = self.db.structural_variant.distinct('chrom')
        else:
            res = self.db.variant.distinct('chrom')

        return res

Return a list of all chromosomes found in database

Args:
        sv(bool): if sv variants should be choosen

Returns:
        res(iterable(str)): An iterable with all chromosomes in the database


def gt(self, other, axis="columns", level=None):

        return self._binary_op("gt", other, axis=axis, level=level)

Checks element-wise that this is greater than other.

Args:
        other: A DataFrame or Series or scalar to compare to.
        axis: The axis to perform the gt over.
        level: The Multilevel index level to apply gt over.

Returns:
        A new DataFrame filled with Booleans.


def listdir(*paths, glob=None):

    path = genpath(*paths)

    names = os.listdir(path)
    if glob is not None:
        names = fnmatch.filter(names, glob)

    retn = [os.path.join(path, name) for name in names]
    return retn

List the (optionally glob filtered) full paths from a dir.

Args:
        *paths ([str,...]): A list of path elements
        glob (str): An optional fnmatch glob str


def ApplyPluginToTypedCollection(plugin, type_names, fetch_fn):

  for chunk in plugin.Start():
    yield chunk

  def GetValues(tn):
    for v in fetch_fn(tn):
      yield v

  for type_name in sorted(type_names):
    stored_cls = rdfvalue.RDFValue.classes[type_name]

    for chunk in plugin.ProcessValues(stored_cls,
                                      functools.partial(GetValues, type_name)):
      yield chunk

  for chunk in plugin.Finish():
    yield chunk

Applies instant output plugin to a collection of results.

Args:
        plugin: InstantOutputPlugin instance.
        type_names: List of type names (strings) to be processed.
        fetch_fn: Function that takes a type name as an argument and returns
        available items (FlowResult) corresponding to this type. Items are
        returned as a generator

Yields:
        Bytes chunks, as generated by the plugin.


def tag(self, main_type, sub_type, unique_id, tag, action='GET', owner=None, params=None):

        params = params or {}

        if owner:
            params['owner'] = owner

        action = action.upper()
        if sub_type:
            url = '/v2/{}/{}/{}/tags/{}'.format(main_type, sub_type, unique_id, quote(tag))
        else:
            url = '/v2/{}/{}/tags/{}'.format(main_type, unique_id, quote(tag))
        response = None
        if action == 'ADD':
            response = self.tcex.session.post(url, params=params)
        elif action == 'DELETE':
            response = self.tcex.session.delete(url, params=params)
        elif action == 'GET':
            response = self.tcex.session.get(url, params=params)
        else:
            self.tcex.log.error('_tags error')
        return response

Args:
    owner:
    main_type:
    sub_type:
    unique_id:
    tag:
    action:
    params:

    Return:


def referrer_uri(self, value):

        if value == self._defaults['referrerUri'] and 'referrerUri' in self._values:
            del self._values['referrerUri']
        else:
            self._values['referrerUri'] = value

The referrer_uri property.

Args:
        value (string). the property value.


def run_dumper(self, dumper):

        logging.debug("start dumper::")
        dumper(
            experiments=self.experiments,
            farms=self.farms,
            barn=self.barn,
            engine=self.current_engine,
        )
        logging.debug("::dumper ended")

run dumber (once pr. engine)

Args:
        dumper: dumper to run (function or method).

    The dumper takes the attributes experiments, farms, and barn as input.
    It does not return anything. But can, if the dumper designer feels in
    a bad and nasty mood, modify the input objects
    (for example experiments).


def _layer_stack(mp,
                 inputs,
                 self_attention_bias,
                 layers,
                 hparams,
                 encoder_output=None,
                 encoder_decoder_attention_bias=None):

  layers = layers.strip(",").split(",")

  # scaled_dot_product_attention_with_projections uses a 3d attention bias
  # (no heads), where multihead_attention uses 4d attention bias.
  self_attention_bias_3d = mp(tf.squeeze, self_attention_bias, 1)
  if encoder_decoder_attention_bias is not None:
    encoder_decoder_attention_bias_3d = mp(
        tf.squeeze, encoder_decoder_attention_bias, 1)
  relu_dropout_broadcast_dims = (
      common_layers.comma_separated_string_to_integer_list(
          getattr(hparams, "relu_dropout_broadcast_dims", "")))
  mix_size = int(hparams.mix_fraction * hparams.hidden_size)
  accumulator = inputs
  x = inputs
  for layer_num, layer_type in enumerate(layers):
    with tf.variable_scope("%s_%d" % (layer_type, layer_num)):
      tf.logging.info("%s_%d" % (layer_type, layer_num))
      if layer_type == "a":
        # accumulate
        accumulator = mp(tf.add, x, accumulator)
        x = accumulator
      elif layer_type == "n":
        # normalize
        x = mp(common_layers.apply_norm,
               x, hparams.norm_type, hparams.hidden_size, hparams.norm_epsilon)
      elif layer_type == "d":
        # dropout
        x = mp(tf.nn.dropout, x, 1.0 - hparams.layer_prepostprocess_dropout)
      elif layer_type == "m":
        if mix_size > 0:
          # mix across shards
          def _split(t):
            return tuple(tf.split(
                t, [mix_size, hparams.hidden_size - mix_size], 2))
          to_mix, to_keep = mp(_split, x)
          mixed = expert_utils.all_reduce_ring(to_mix, mp)
          mixed = mp(tf.multiply, mixed, mp.n ** -0.5)
          x = mp(lambda a, b: tf.concat([a, b], 2), mixed, to_keep)
      elif layer_type == "att":
        # single-head attention
        q = mp(tf.layers.dense, x, hparams.hidden_size, use_bias=False,
               name="q_transform")
        x = mp(
            common_attention.scaled_dot_product_attention_simple,
            q, x, x, self_attention_bias_3d)
        x = mp(tf.layers.dense, x, hparams.hidden_size, use_bias=False,
               name="o_transform")
      elif layer_type == "enc-att":
        # single-head attention over encoder
        q = mp(tf.layers.dense, x, hparams.hidden_size, use_bias=False,
               name="q_transform")
        assert encoder_output is not None
        x = mp(
            common_attention.scaled_dot_product_attention_simple,
            q, encoder_output, encoder_output,
            encoder_decoder_attention_bias_3d)
        x = mp(tf.layers.dense, x, hparams.hidden_size, use_bias=False,
               name="o_transform")
      elif layer_type == "multihead-att":
        # multi-head attention
        x = mp(
            common_attention.multihead_attention,
            x,
            None,
            self_attention_bias,  # bias
            hparams.multihead_attention_key_channels or hparams.hidden_size,
            hparams.multihead_attention_value_channels or hparams.hidden_size,
            hparams.hidden_size,
            hparams.multihead_attention_num_heads,
            hparams.attention_dropout)
      elif layer_type == "enc-multihead-att":
        # multi-head attention
        x = mp(
            common_attention.multihead_attention,
            x,
            encoder_output,
            encoder_decoder_attention_bias,  # bias
            hparams.multihead_attention_key_channels or hparams.hidden_size,
            hparams.multihead_attention_value_channels or hparams.hidden_size,
            hparams.hidden_size,
            hparams.multihead_attention_num_heads,
            hparams.attention_dropout)
      elif layer_type == "ffn":
        x = mp(
            common_layers.dense_relu_dense, x,
            hparams.filter_size, hparams.hidden_size,
            dropout=hparams.relu_dropout,
            dropout_broadcast_dims=[relu_dropout_broadcast_dims] * mp.n)
      else:
        assert False, "unknown sublayer %s" % layer_type
  return x

A stack of layers.

Args:
        mp: a Parallelism object
        inputs: a list of Tensors
        self_attention_bias: list of bias Tensor for self-attention
        (see common_attention.attention_bias())
        layers: a string
        hparams: hyperparameters for model
        encoder_output: optional list of tensors
        encoder_decoder_attention_bias: optional list of tensors

Returns:
        y: a list of Tensors


def _LogForwardedIpChanges(
      self, configured, desired, to_add, to_remove, interface):

    if not to_add and not to_remove:
      return
    self.logger.info(
        'Changing %s IPs from %s to %s by adding %s and removing %s.',
        interface, configured or None, desired or None, to_add or None,
        to_remove or None)

Log the planned IP address changes.

Args:
        configured: list, the IP address strings already configured.
        desired: list, the IP address strings that will be configured.
        to_add: list, the forwarded IP address strings to configure.
        to_remove: list, the forwarded IP address strings to delete.
        interface: string, the output device to modify.


def __init__(self, channel):

        self.ListSinks = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/ListSinks",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListSinksRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListSinksResponse.FromString,
        )
        self.GetSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/GetSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.GetSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.CreateSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/CreateSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.CreateSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.UpdateSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/UpdateSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.UpdateSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.DeleteSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/DeleteSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.DeleteSinkRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.ListExclusions = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/ListExclusions",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListExclusionsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListExclusionsResponse.FromString,
        )
        self.GetExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/GetExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.GetExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.CreateExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/CreateExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.CreateExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.UpdateExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/UpdateExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.UpdateExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.DeleteExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/DeleteExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.DeleteExclusionRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
        channel: A grpc.Channel.


def get(self, name):

        return self.prepare_model(self.client.api.inspect_plugin(name))

Gets a plugin.

Args:
        name (str): The name of the plugin.

Returns:
        (:py:class:`Plugin`): The plugin.

Raises:
        :py:class:`docker.errors.NotFound` If the plugin does not
        exist.
        :py:class:`docker.errors.APIError`
            If the server returns an error.


def set_membership(self, room_id, user_id, membership, reason="", profile=None,
                       timestamp=None):

        if profile is None:
            profile = {}
        body = {
            "membership": membership,
            "reason": reason
        }
        if 'displayname' in profile:
            body["displayname"] = profile["displayname"]
        if 'avatar_url' in profile:
            body["avatar_url"] = profile["avatar_url"]

        return self.send_state_event(room_id, "m.room.member", body, state_key=user_id,
                                     timestamp=timestamp)

Perform PUT /rooms/$room_id/state/m.room.member/$user_id

Args:
        room_id (str): The room ID
        user_id (str): The user ID
        membership (str): New membership value
        reason (str): The reason
        timestamp (int): Set origin_server_ts (For application services only)


def unpack(self, buff=None, offset=0):

        instruction_type = UBInt16(enum_ref=InstructionType)
        instruction_type.unpack(buff, offset)
        self.__class__ = InstructionType(instruction_type.value).find_class()

        length = UBInt16()
        length.unpack(buff, offset=offset+2)

        super().unpack(buff[:offset+length.value], offset)

Unpack *buff* into this object.

    This method will convert a binary data into a readable value according
    to the attribute format.

Args:
        buff (bytes): Binary buffer.
        offset (int): Where to begin unpacking.

Raises:
        :exc:`~.exceptions.UnpackException`: If unpack fails.


def find(format):

    try:
        serializer = SERIALIZERS[format]
    except KeyError:
        raise UnknownSerializer('No serializer found for %s' % format.acronym)

    return serializer

Find and return a serializer for the given format.

Args:
    format -- A Format instance.


def _CopyDateFromString(self, date_string):

    date_string_length = len(date_string)

    # The date string should at least contain 'YYYY-MM-DD'.
    if date_string_length < 10:
      raise ValueError('Date string too short.')

    if date_string[4] != '-' or date_string[7] != '-':
      raise ValueError('Invalid date string.')

    try:
      year = int(date_string[0:4], 10)
    except ValueError:
      raise ValueError('Unable to parse year.')

    try:
      month = int(date_string[5:7], 10)
    except ValueError:
      raise ValueError('Unable to parse month.')

    try:
      day_of_month = int(date_string[8:10], 10)
    except ValueError:
      raise ValueError('Unable to parse day of month.')

    days_per_month = self._GetDaysPerMonth(year, month)
    if day_of_month < 1 or day_of_month > days_per_month:
      raise ValueError('Day of month value out of bounds.')

    return year, month, day_of_month

Copies a date from a string.

Args:
        date_string (str): date value formatted as: YYYY-MM-DD

Returns:
        tuple[int, int, int]: year, month, day of month.

Raises:
        ValueError: if the date string is invalid or not supported.


def dedent(self, node, dirty=True):

        if node.id not in self._subitems:
            return

        del self._subitems[node.id]
        node.super_list_item_id = None
        node.parent_item = None
        if dirty:
            node.touch(True)

Dedent an item. Does nothing if the target is not indented under this item.

Args:
        node (gkeepapi.node.ListItem): Item to dedent.
        dirty (bool): Whether this node should be marked dirty.


def conv_to_float(indata, inf_str=''):

    if indata.strip() == inf_str:
        outdata = float('Inf')
    else:
        try:
            outdata = float(indata)
        except:
            raise ValueError('Unable to convert {} to float'.format(indata))

    return outdata

Try to convert an arbitrary string to a float. Specify what will be replaced with "Inf".

Args:
        indata (str): String which contains a float
        inf_str (str): If string contains something other than a float, and you want to replace it with float("Inf"),
            specify that string here.

Returns:
        float: Converted string representation


def external_ids(self, **kwargs):

        path = self._get_id_path('external_ids')

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

Get the external ids for a specific movie id.

Args:
        language: (optional) ISO 639-1 code.
        append_to_response: (optional) Comma separated, any movie method.

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


def import_users(self, connection_id, file_obj, upsert=False):

        return self.client.file_post(self._url('users-imports'),
                                     data={'connection_id': connection_id, 'upsert': str(upsert).lower()},
                                     files={'users': file_obj})

Imports users to a connection from a file.

Args:
        connection_id (str): The connection id of the connection to which
            users will be inserted.

        file_obj (file): A file-like object to upload. The format for
            this file is explained in: https://auth0.com/docs/bulk-import

    See: https://auth0.com/docs/api/management/v2#!/Jobs/post_users_imports


def __init__(self,env_id,visualize=False):

		envs = [Arm2DEnv,L2RunEnv,ProstheticsEnv]
		self.env = envs[env_id](visualize=visualize)

		self.state_shape = len(self.env.reset())
		self.num_actions = len(self.env.action_space.sample())

Initialize OpenSimulator environment.

Args:
    visualize: render enviroment
    env: environment id to use ([0:Arm2DEnv, 1:L2RunEnv, 2:ProstheticsEnv])


def jpeg_compression(x, severity=1):

  c = [25, 18, 15, 10, 7][severity - 1]
  x = tfds.core.lazy_imports.PIL_Image.fromarray(x.astype(np.uint8))
  output = io.BytesIO()
  x.save(output, 'JPEG', quality=c)
  output.seek(0)
  x = tfds.core.lazy_imports.PIL_Image.open(output)
  return np.asarray(x)

Conduct jpeg compression to images.

Args:
        x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
        severity: integer, severity of corruption.

Returns:
        numpy array, image with uint8 pixels in [0,255]. Applied jpeg compression.


def fit_size_models(self, model_names,
                        model_objs,
                        input_columns,
                        output_column="Hail_Size",
                        output_start=5,
                        output_step=5,
                        output_stop=100):

        print("Fitting size models")
        groups = self.data["train"]["member"][self.group_col].unique()
        output_start = int(output_start)
        output_step = int(output_step)
        output_stop = int(output_stop)
        for group in groups:
            group_data = self.data["train"]["combo"].loc[self.data["train"]["combo"][self.group_col] == group]
            group_data.dropna(inplace=True)
            group_data = group_data[group_data[output_column] >= output_start]
            output_data = group_data[output_column].values.astype(int)
            output_data[output_data > output_stop] = output_stop
            discrete_data = ((output_data - output_start) // output_step) * output_step + output_start
            self.size_models[group] = {}
            self.size_models[group]["outputvalues"] = np.arange(output_start, output_stop + output_step, output_step,
                                                                dtype=int)
            for m, model_name in enumerate(model_names):
                print("{0} {1}".format(group, model_name))
                self.size_models[group][model_name] = deepcopy(model_objs[m])
                self.size_models[group][model_name].fit(group_data[input_columns], discrete_data)

Fit size models to produce discrete pdfs of forecast hail sizes.

Args:
        model_names: List of model names
        model_objs: List of model objects
        input_columns: List of input variables
        output_column: Output variable name
        output_start: Hail size bin start
        output_step: hail size bin step
        output_stop: hail size bin stop


def append_with_data(url, data):

        if data is None:
            return url

        url_parts = list(urlparse(url))

        query = OrderedDict(parse_qsl(url_parts[4], keep_blank_values=True))
        query.update(data)

        url_parts[4] = URLHelper.query_dict_to_string(query)

        return urlunparse(url_parts)

Append the given URL with the given data OrderedDict.

Args:
        url (str): The URL to append.
        data (obj): The key value OrderedDict to append to the URL.

Returns:
        str: The new URL.


def _SetAllFieldTypes(self, package, desc_proto, scope):

    package = _PrefixWithDot(package)

    main_desc = self._GetTypeFromScope(package, desc_proto.name, scope)

    if package == '.':
      nested_package = _PrefixWithDot(desc_proto.name)
    else:
      nested_package = '.'.join([package, desc_proto.name])

    for field_proto, field_desc in zip(desc_proto.field, main_desc.fields):
      self._SetFieldType(field_proto, field_desc, nested_package, scope)

    for extension_proto, extension_desc in (
        zip(desc_proto.extension, main_desc.extensions)):
      extension_desc.containing_type = self._GetTypeFromScope(
          nested_package, extension_proto.extendee, scope)
      self._SetFieldType(extension_proto, extension_desc, nested_package, scope)

    for nested_type in desc_proto.nested_type:
      self._SetAllFieldTypes(nested_package, nested_type, scope)

Sets all the descriptor's fields's types.

    This method also sets the containing types on any extensions.

Args:
        package: The current package of desc_proto.
        desc_proto: The message descriptor to update.
        scope: Enclosing scope of available types.


def mapIdentity(self, primarySubject, secondarySubject, vendorSpecific=None):

        response = self.mapIdentityResponse(
            primarySubject, secondarySubject, vendorSpecific
        )
        return self._read_boolean_response(response)

See Also: mapIdentityResponse()

Args:
        primarySubject:
        secondarySubject:
        vendorSpecific:

    Returns:


def __call__(self, utterances_batch: list, history_batch: list) -> list:

        return [[True] * len(utterances_batch)] * self.size

Returns skills-utterances application matrix.

    Generates skills-utterances application matrix with all True
    elements.

Args:
        utterances_batch: A batch of utterances of any type.
        history_batch: Not used.

Returns:
        response: Skills-utterances application matrix with all True
            elements.


def add_meta_line(self, key, value):

        meta_line = '##{0}={1}'.format(
            key, value
        )
        logger.info("Adding meta line to vcf: {0}".format(meta_line))
        self.parse_meta_data(meta_line)
        return

Adds an arbitrary metadata line to the header.

    This must be a key value pair

Args:
        key (str): The key of the metadata line
        value (str): The value of the metadata line


def __new__(cls, *args, **kwargs):

        instance = super(_AutoFinalizedObjectBase, cls).__new__(cls)
        instance._finalize_called = False
        return instance

Creates a new object instance and adds the private finalizer
    attributes to it.

    Returns: new object instance

Args:
    * *args, **kwargs -- ignored


def get_timestamp(self, cycle=None, dataset_number=None,
                      in_minutes=False, full=True):

        dataset_number = self._validate_dataset_number(dataset_number)
        if dataset_number is None:
            self._report_empty_dataset()
            return
        cycle_index_header = self.headers_normal.cycle_index_txt
        timestamp_header = self.headers_normal.test_time_txt

        v = pd.Series()
        test = self.datasets[dataset_number].dfdata
        if cycle:
            c = test[(test[cycle_index_header] == cycle)]
            if not self.is_empty(c):
                v = c[timestamp_header]

        else:
            if not full:
                self.logger.debug("getting timestapm for all cycles")
                v = []
                no_cycles = np.amax(test[cycle_index_header])
                for j in range(1, no_cycles + 1):
                    txt = "Cycle  %i:  " % j
                    self.logger.debug(txt)
                    c = test[(test[cycle_index_header] == j)]
                    v.append(c[timestamp_header])
            else:
                self.logger.debug("returning full timestamp col")
                v = test[timestamp_header]
                if in_minutes and v is not None:
                    v /= 60.0
        if in_minutes and v is not None:
            v /= 60.0
        return v

Returns timestamps (in sec or minutes (if in_minutes==True)).

Args:
        cycle: cycle number (all if None)
        dataset_number: first dataset if None
        in_minutes: return values in minutes instead of seconds if True
        full: valid only for cycle=None (i.e. all cycles), returns the full
        pandas.Series if True, else a list of pandas.Series

Returns:
        pandas.Series (or list of pandas.Series if cycle=None og full=False)


def load_from_dict(self, conf_dict=None):

        self.set_to_default()
        self._update_dict(self._config, conf_dict)
        self._update_python_paths()

Load the configuration from a dictionary.

Args:
        conf_dict (dict): Dictionary with the configuration.


def parameterized_codec(raw, b64):

    if isinstance(raw, bytes):
        raw = raw.decode('utf-8')

    result = _parameterize_string(raw)

    # Note, since we want a raw JSON object (not a string) output in the
    # template, we wrap the result in GenericHelperFn (not needed if we're
    # using Base64)
    return Base64(result.data) if b64 else result

Parameterize a string, possibly encoding it as Base64 afterwards

Args:
        raw (`str` | `bytes`): String to be processed. Byte strings will be
            interpreted as UTF-8.
        b64 (`bool`): Whether to wrap the output in a Base64 CloudFormation
            call

Returns:
        :class:`troposphere.AWSHelperFn`: output to be included in a
        CloudFormation template.


def get_variant_dict(variant_line, header_line=None):

    if not header_line:
        logger.debug("No header line, use only first 8 mandatory fields")
        header_line = ['CHROM','POS','ID','REF','ALT','QUAL','FILTER','INFO']

    logger.debug("Building variant dict from variant line {0} and header"\
    " line {1}".format(variant_line, '\t'.join(header_line)))

    splitted_line = variant_line.rstrip().split('\t')
    if len(splitted_line) < len(header_line):
        logger.info('\t'.join(header_line))
        logger.info('\t'.join(splitted_line))
        raise SyntaxError("Length of variant line differs from length of"\
                            " header line")

    return dict(zip(header_line, splitted_line))

Parse a variant line

    Split a variant line and map the fields on the header columns

Args:
        variant_line (str): A vcf variant line
        header_line (list): A list with the header columns

Returns:
        variant_dict (dict): A variant dictionary


def get_revision_sha(self, dest, rev):

        # Pass rev to pre-filter the list.
        output = self.run_command(['show-ref', rev], cwd=dest,
                                  show_stdout=False, on_returncode='ignore')
        refs = {}
        for line in output.strip().splitlines():
            try:
                sha, ref = line.split()
            except ValueError:
                # Include the offending line to simplify troubleshooting if
                # this error ever occurs.
                raise ValueError('unexpected show-ref line: {!r}'.format(line))

            refs[ref] = sha

        branch_ref = 'refs/remotes/origin/{}'.format(rev)
        tag_ref = 'refs/tags/{}'.format(rev)

        sha = refs.get(branch_ref)
        if sha is not None:
            return (sha, True)

        sha = refs.get(tag_ref)

        return (sha, False)

Return (sha_or_none, is_branch), where sha_or_none is a commit hash
    if the revision names a remote branch or tag, otherwise None.

Args:
        dest: the repository directory.
        rev: the revision name.


def __init__(self, baselines, scope='aggregated-baseline', summary_labels=()):

        self.baselines = dict()
        for name in sorted(baselines):
            self.baselines[name] = Baseline.from_spec(
                spec=baselines[name],
                kwargs=dict(summary_labels=summary_labels))

        self.linear = Linear(size=1, bias=0.0, scope='prediction', summary_labels=summary_labels)

        super(AggregatedBaseline, self).__init__(scope, summary_labels)

Aggregated baseline.

Args:
        baselines: Dict of per-state baseline specification dicts


def __init__(self, namespace=None):

        assert namespace != DEFAULT_REQUEST_CACHE_NAMESPACE,\
            'Optional namespace can not be {}.'.format(DEFAULT_REQUEST_CACHE_NAMESPACE)
        self.namespace = namespace or DEFAULT_REQUEST_CACHE_NAMESPACE

Creates a request cache with the provided namespace.

Args:
        namespace (string): (optional) uses 'default' if not provided.


def __init__(self, graph: IGraph):

        super(IGraphWrapper, self).__init__(self._create_memory_database_interface())

        if not isinstance(graph, IGraph):
            raise ValueError("Invalid graph instance provided to IGraphWrapper")

        self._wrapped_graph: IGraph = graph

Initialization.

Args:
        graph (IGraph): The igraph `Graph` object to wrap.


def onTagAdd(self, name, func):

        # TODO allow name wild cards
        if '*' in name:
            self.ontagaddglobs.add(name, func)
        else:
            self.ontagadds[name].append(func)

Register a callback for tag addition.

Args:
        name (str): The name of the tag or tag glob.
        func (function): The callback func(node, tagname, tagval).


def clear(self, size=-1, *, offset=0, chunk=None) -> None:

        self.mglo.clear(size, offset, chunk)

Clear the content.

Args:
        size (int): The size. Value ``-1`` means all.

    Keyword Args:
        offset (int): The offset.
        chunk (bytes): The chunk to use repeatedly.


def fail_deployment(self, id):

        fail_json = {"DeploymentID": id}
        return self.request("fail", id, json=fail_json, method="post").json()

This endpoint is used to mark a deployment as failed. This should be done to force the scheduler to stop
    creating allocations as part of the deployment or to cause a rollback to a previous job version.

    https://www.nomadproject.io/docs/http/deployments.html

Args:
        - id
    returns: dict

Raises:
        - nomad.api.exceptions.BaseNomadException
        - nomad.api.exceptions.URLNotFoundNomadException


def get_padding_bias(x):

  with tf.name_scope("attention_bias"):
    padding = get_padding(x)
    attention_bias = padding * _NEG_INF
    attention_bias = tf.expand_dims(
        tf.expand_dims(attention_bias, axis=1), axis=1)
  return attention_bias

Calculate bias tensor from padding values in tensor.

    Bias tensor that is added to the pre-softmax multi-headed attention logits,
    which has shape [batch_size, num_heads, length, length]. The tensor is zero at
    non-padding locations, and -1e9 (negative infinity) at padding locations.

Args:
        x: int tensor with shape [batch_size, length]

Returns:
        Attention bias tensor of shape [batch_size, 1, 1, length].


def put(self, key, value):

    if value is None:
      self.delete(key)
    else:
      self._collection(key)[key] = value

Stores the object `value` named by `key`.

    Stores the object in the collection corresponding to ``key.path``.

Args:
        key: Key naming `value`
        value: the object to store.


def __init__(self, structure, element):

        self.structure = structure
        self.element = element

        # Find equivalent site list
        sga = SpacegroupAnalyzer(self.structure)
        self.symm_structure = sga.get_symmetrized_structure()

        self.equiv_sub = []
        for equiv_site_set in list(self.symm_structure.equivalent_sites):
            vac_site = equiv_site_set[0]
            if isinstance(element, str):  # make sure you compare with specie symbol or Element type
                vac_specie = vac_site.specie.symbol
            else:
                vac_specie = vac_site.specie
            if element != vac_specie:
                defect_site = PeriodicSite(element, vac_site.coords, structure.lattice, coords_are_cartesian=True)
                sub = Substitution(structure, defect_site)
                self.equiv_sub.append(sub)

Initializes a Substitution Generator
    note: an Antisite is considered a type of substitution

Args:
        structure(Structure): pymatgen structure object
        element (str or Element or Specie): element for the substitution


def process_result_value(self, value, dialect):

        masks = list()
        if value:
            for e in enums.CryptographicUsageMask:
                if e.value & value:
                    masks.append(e)
        return masks

Returns a new list of enums.CryptographicUsageMask Enums. This converts
    the integer value into the list of enums.

Args:
        value(int): The integer value stored in the database that is used
            to create the list of enums.CryptographicUsageMask Enums.
        dialect(string): SQL dialect


def mash_dist_trusted(fasta_path):

    args = [MASH_BIN,
            'dist',
            MASH_SKETCH_FILE,
            fasta_path]
    p = Popen(args, stderr=PIPE, stdout=PIPE)
    (stdout, stderr) = p.communicate()
    retcode = p.returncode
    if retcode != 0:
        raise Exception('Could not run Mash dist {}'.format(stderr))

    return stdout

Compute Mash distances of sketch file of genome fasta to RefSeq sketch DB.

Args:
        mash_bin (str): Mash binary path

Returns:
        (str): Mash STDOUT string


def normalize(code):

    if len(code) == 3:
        return code

    normalized = translate(code)

    if normalized:
        return normalized

    country = countries.get(code, None)

    if country:
        return country.alpha3.lower()

    return code

Normalize language codes to ISO 639-2. If all conversions fails, return the
    `code` as it was given.

Args:
        code (str): Language / country code.

Returns:
        str: ISO 639-2 country code.


def overwrite_workspace_config(namespace, workspace, cnamespace, configname, body):

    headers = _fiss_agent_header({"Content-type": "application/json"})
    uri = "workspaces/{0}/{1}/method_configs/{2}/{3}".format(namespace,
                                        workspace, cnamespace, configname)
    return __put(uri, headers=headers, json=body)

Add or overwrite method configuration in workspace.

Args:
        namespace  (str): project to which workspace belongs
        workspace  (str): Workspace name
        cnamespace (str): Configuration namespace
        configname (str): Configuration name
        body      (json): new body (definition) of the method config

    Swagger:
        https://api.firecloud.org/#!/Method_Configurations/overwriteWorkspaceMethodConfig


def get_supervisor(func: types.AnyFunction) -> types.Supervisor:

    if not callable(func):
        raise TypeError("func is not callable")
    if asyncio.iscoroutinefunction(func):
        supervisor = _async_supervisor
    else:
        supervisor = _sync_supervisor
    return functools.partial(supervisor, func)

Get the appropriate supervisor to use and pre-apply the function.

Args:
        func: A function.


def Readdir(self, path, fh=None):

    if self.DataRefreshRequired(path):
      self._RunAndWaitForVFSFileUpdate(path)

    return super(GRRFuse, self).Readdir(path, fh=None)

Updates the directory listing from the client.

Args:
        path: The path to the directory to update. Client is inferred from this.
        fh: A file handler. Not used.

Returns:
        A list of filenames.


def _scalar_to_vector(self, m):

        if not isinstance(m.y0, numbers.Number):
            return m
        else:
            m = copy.deepcopy(m)
            t0 = 0.0
            if isinstance(m.y0, numbers.Integral):
                numtype = np.float64
            else:
                numtype = type(m.y0)
            y0_orig = m.y0
            m.y0 = np.array([m.y0], dtype=numtype)
            def make_vector_fn(fn):
                def newfn(y, t):
                    return np.array([fn(y[0], t)], dtype=numtype)
                newfn.__name__ = fn.__name__
                return newfn
            def make_matrix_fn(fn):
                def newfn(y, t):
                    return np.array([[fn(y[0], t)]], dtype=numtype)
                newfn.__name__ = fn.__name__
                return newfn
            def make_coupling_fn(fn):
                def newfn(source_y, target_y, weight):
                    return np.array([fn(source_y[0], target_y[0], weight)])
                newfn.__name__ = fn.__name__
                return newfn
            if isinstance(m.f(y0_orig, t0), numbers.Number):
                m.f = make_vector_fn(m.f)
            if hasattr(m, 'G') and isinstance(m.G(y0_orig,t0), numbers.Number):
                m.G = make_matrix_fn(m.G)
            if (hasattr(m, 'coupling') and
                    isinstance(m.coupling(y0_orig, y0_orig, 0.5),
                               numbers.Number)):
                m.coupling = make_coupling_fn(m.coupling)
            return m

Allow submodels with scalar equations. Convert to 1D vector systems.

Args:
        m (Model)


def port(self, value):

        self._port = value
        # If port is None we remove the element and don't write it to XML
        if value is None:
            try:
                del self._connectionXML.attrib['port']
            except KeyError:
                pass
        else:
            self._connectionXML.set('port', value)

Set the connection's port property.

Args:
        value:  New port value. String.

Returns:
        Nothing.


def pyrdf2(value, class_type=None, datatype=None, lang=None, **kwargs):

    try:

        if isinstance(value, dict):
            # test to see if the type is a literal, a literal will have a another
            # dictionary key call datatype. Feed the datatype to the lookup to
            # return the value else convert it to a XsdString
            if value.get('type') == "literal":
                if not value.get("datatype"):
                    return XsdString(value['value'])
                else:
                    try:
                        if value.get("lang"):
                            # The lang keyword only applies to XsdString types
                            return DT_LOOKUP[value['datatype']](value['value'],
                                    lang=value.get("lang"))
                        else:
                            return DT_LOOKUP[value['datatype']](value['value'])
                    except:
                        rtn_val = BaseRdfDataType(value['value'])
                        rtn_val.datatype = Uri(value['datatype'])
                        return rtn_val
            else:
                return DT_LOOKUP[value['type']](value['value'])
        elif isinstance(value, BaseRdfDataType):
            return value
        else:
            return DT_LOOKUP[type(value)](value)
    except:
        pdb.set_trace()
        pass

Coverts an input to one of the rdfdatatypes classes

Args:
        value: any rdfdatatype, json dict or vlaue
        class_type: "literal", "uri" or "blanknode"
        datatype: "xsd:string", "xsd:int" , etc


def update_factor(self, name, body):

        url = self._url('factors/{}'.format(name))
        return self.client.put(url, data=body)

Update Guardian factor
    Useful to enable / disable factor

Args:
        name (str): Either push-notification or sms
        body (dict): Attributes to modify.
        See: https://auth0.com/docs/api/management/v2#!/Guardian/put_factors_by_name


def find_contacts(self, geoms_1, geoms_2):

        for contact in self.sim.data.contact[0 : self.sim.data.ncon]:
            # check contact geom in geoms
            c1_in_g1 = self.sim.model.geom_id2name(contact.geom1) in geoms_1
            c2_in_g2 = self.sim.model.geom_id2name(contact.geom2) in geoms_2
            # check contact geom in geoms (flipped)
            c2_in_g1 = self.sim.model.geom_id2name(contact.geom2) in geoms_1
            c1_in_g2 = self.sim.model.geom_id2name(contact.geom1) in geoms_2
            if (c1_in_g1 and c2_in_g2) or (c1_in_g2 and c2_in_g1):
                yield contact

Finds contact between two geom groups.

Args:
        geoms_1: a list of geom names (string)
        geoms_2: another list of geom names (string)

Returns:
        iterator of all contacts between @geoms_1 and @geoms_2


def image_path_from_index(self, index):

        assert self.image_set_index is not None, "Dataset not initialized"
        name = self.image_set_index[index]
        image_file = os.path.join(self.image_dir, 'images', name)
        assert os.path.isfile(image_file), 'Path does not exist: {}'.format(image_file)
        return image_file

given image index, find out full path

    Parameters:
    ----------
    index: int
        index of a specific image

Returns:
    ----------
    full path of this image


def product_name(self):

        buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
        self._dll.JLINKARM_EMU_GetProductName(buf, self.MAX_BUF_SIZE)
        return ctypes.string_at(buf).decode()

Returns the product name of the connected J-Link.

Args:
        self (JLink): the ``JLink`` instance

Returns:
        Product name.


def _execute(self, request):

        if self._rate_limiter:
            # Since the ratelimiter library only exposes a context manager
            # interface the code has to be duplicated to handle the case where
            # no rate limiter is defined.
            with self._rate_limiter:
                return request.execute(http=self.http,
                                       num_retries=self._num_retries)
        return request.execute(http=self.http,
                               num_retries=self._num_retries)

Run execute with retries and rate limiting.

Args:
        request (object): The HttpRequest object to execute.

Returns:
        dict: The response from the API.


def getbalance(self, user_id="", as_decimal=True):

        balance = unicode(self.rpc.call("getbalance", user_id))
        self.logger.debug("\"" + user_id + "\"", self.coin, "balance:", balance)
        if as_decimal:
            return Decimal(balance)
        else:
            return balance

Calculate the total balance in all addresses belonging to this user.

Args:
        user_id (str): this user's unique identifier
        as_decimal (bool): balance is returned as a Decimal if True (default)
                        or a string if False

Returns:
        str or Decimal: this account's total coin balance


def update_box_field(self, box_key, field):

		#does not work
		self._raise_unimplemented_error()

		uri = '/'.join([self.api_uri,
						self.boxes_suffix,
						box_key,
						self.fields_suffix
						])
		return self._update_field(uri, field)

Upates box field as specified

Args:
    box_key		key for pipeline where the fields lives
    field 				StreakField object with fresh data
    returns				(status code, updated field dict)


def __init__(
        self,
        routes,
    ):

        self.routes = type_assert_iter(
            routes,
            Route,
        )
        check_dups(routes)

desc: Contains the URIs for this service

Args:
        -   name: routes
            type: list
            subtypes: [Route]
            desc: a mapping of URIs to Route instances
            ctor: pymarshal.api_docs.routes.Route.__init__


def __init__(self, base, analysis_function, time_limit=5.0):

        self._base = base
        self._analysis_function = analysis_function
        self._tile_images = self._create_tile_images()
        self._analyze_start_time = None
        self.time_limit = time_limit
        self.summaries = None
        self._parts = self._setup_parts(self._base)

Setup the common UI elements and behavior for a PQ Game UI.

Args:
    - base: a tkinter base element in which to create parts


def __init__(self, client, base_path):

        self._client = client
        self._base_path = base_path
        self._queue_path = posixpath.join(self._base_path, 'queue', '')
        self._counter_path = posixpath.join(self._queue_path, 'counter')
        self._ensure_counter()
        self._ensure_queue()

Initialise the class.

Args:
        client (:class:`consulate.Consul`): A :class:`consulate.Consul` instance.
        base_path (str): the base path to use in Consul.


def abort_expired_batches(self, request_timeout_ms, cluster):

        expired_batches = []
        to_remove = []
        count = 0
        for tp in list(self._batches.keys()):
            assert tp in self._tp_locks, 'TopicPartition not in locks dict'

            # We only check if the batch should be expired if the partition
            # does not have a batch in flight. This is to avoid the later
            # batches get expired when an earlier batch is still in progress.
            # This protection only takes effect when user sets
            # max.in.flight.request.per.connection=1. Otherwise the expiration
            # order is not guranteed.
            if tp in self.muted:
                continue

            with self._tp_locks[tp]:
                # iterate over the batches and expire them if they have stayed
                # in accumulator for more than request_timeout_ms
                dq = self._batches[tp]
                for batch in dq:
                    is_full = bool(bool(batch != dq[-1]) or batch.records.is_full())
                    # check if the batch is expired
                    if batch.maybe_expire(request_timeout_ms,
                                          self.config['retry_backoff_ms'],
                                          self.config['linger_ms'],
                                          is_full):
                        expired_batches.append(batch)
                        to_remove.append(batch)
                        count += 1
                        self.deallocate(batch)
                    else:
                        # Stop at the first batch that has not expired.
                        break

                # Python does not allow us to mutate the dq during iteration
                # Assuming expired batches are infrequent, this is better than
                # creating a new copy of the deque for iteration on every loop
                if to_remove:
                    for batch in to_remove:
                        dq.remove(batch)
                    to_remove = []

        if expired_batches:
            log.warning("Expired %d batches in accumulator", count) # trace

        return expired_batches

Abort the batches that have been sitting in RecordAccumulator for
    more than the configured request_timeout due to metadata being
    unavailable.

Args:
        request_timeout_ms (int): milliseconds to timeout
        cluster (ClusterMetadata): current metadata for kafka cluster

Returns:
        list of ProducerBatch that were expired


def console_set_char_background(
    con: tcod.console.Console,
    x: int,
    y: int,
    col: Tuple[int, int, int],
    flag: int = BKGND_SET,
) -> None:

    lib.TCOD_console_set_char_background(_console(con), x, y, col, flag)

Change the background color of x,y to col using a blend mode.

Args:
        con (Console): Any Console instance.
        x (int): Character x position from the left.
        y (int): Character y position from the top.
        col (Union[Tuple[int, int, int], Sequence[int]]):
            An (r, g, b) sequence or Color instance.
        flag (int): Blending mode to use, defaults to BKGND_SET.


def hpo_term(self, hpo_id):

        LOG.debug("Fetching hpo term %s", hpo_id)

        return self.hpo_term_collection.find_one({'_id': hpo_id})

Fetch a hpo term

Args:
        hpo_id(str)

Returns:
        hpo_obj(dict)


def DOMDebugger_removeInstrumentationBreakpoint(self, eventName):

		assert isinstance(eventName, (str,)
		    ), "Argument 'eventName' must be of type '['str']'. Received type: '%s'" % type(
		    eventName)
		subdom_funcs = self.synchronous_command(
		    'DOMDebugger.removeInstrumentationBreakpoint', eventName=eventName)
		return subdom_funcs

Function path: DOMDebugger.removeInstrumentationBreakpoint
    Domain: DOMDebugger
    Method name: removeInstrumentationBreakpoint

    WARNING: This function is marked 'Experimental'!

    Parameters:
    Required arguments:
        'eventName' (type: string) -> Instrumentation name to stop on.
    No return value.

    Description: Removes breakpoint on particular native event.


def _ReadTable(self, tables, file_object, table_offset):

    table_header = self._ReadTableHeader(file_object, table_offset)

    for record_offset in table_header.record_offsets:
      if record_offset == 0:
        continue

      record_offset += table_offset

      if table_header.record_type == self._RECORD_TYPE_CSSM_DL_DB_SCHEMA_INFO:
        self._ReadRecordSchemaInformation(tables, file_object, record_offset)
      elif table_header.record_type == (
          self._RECORD_TYPE_CSSM_DL_DB_SCHEMA_INDEXES):
        self._ReadRecordSchemaIndexes(tables, file_object, record_offset)
      elif table_header.record_type == (
          self._RECORD_TYPE_CSSM_DL_DB_SCHEMA_ATTRIBUTES):
        self._ReadRecordSchemaAttributes(tables, file_object, record_offset)
      else:
        self._ReadRecord(
            tables, file_object, record_offset, table_header.record_type)

Reads the table.

Args:
        tables (dict[int, KeychainDatabaseTable]): tables per identifier.
        file_object (file): file-like object.
        table_offset (int): offset of the table relative to the start of
        the file.

Raises:
        ParseError: if the table cannot be read.


def __init__(self, name, data=None, package_cls=None):

        super(PackageMaker, self).__init__(data)
        self.name = name
        self.package_cls = package_cls or Package

        # set by `make_package`
        self.installed_variants = []
        self.skipped_variants = []

Create a package maker.

Args:
        name (str): Package name.


def get_forecast_errors(y_hat,
                        y_true,
                        window_size=5,
                        batch_size=30,
                        smoothing_percent=0.05,
                        smoothed=True):

    errors = [abs(y_h - y_t) for y_h, y_t in zip(y_hat, y_true)]

    if not smoothed:
        return errors

    historical_error_window = int(window_size * batch_size * smoothing_percent)
    moving_avg = []
    for i in range(len(errors)):
        left_window = i - historical_error_window
        right_window = i + historical_error_window + 1
        if left_window < 0:
            left_window = 0

        if right_window > len(errors):
            right_window = len(errors)

        moving_avg.append(np.mean(errors[left_window:right_window]))

    return moving_avg

Calculates the forecasting error for two arrays of data. If smoothed errors desired,
    runs EWMA.

Args:
    y_hat (list): forecasted values. len(y_hat)==len(y_true).
    y_true (list): true values. len(y_hat)==len(y_true).
    window_size (int):
    batch_size (int):
    smoothing_percent (float):
    smoothed (bool): whether the returned errors should be smoothed with EWMA.

Returns:
    (list): error residuals. Smoothed if specified by user.


def create_finance_metrics(metrics: list, pronacs: list):

    missing = missing_metrics(metrics, pronacs)
    print(f"There are {len(missing)} missing metrics!")

    processors = mp.cpu_count()
    print(f"Using {processors} processors to calculate metrics!")

    indicators_qs = FinancialIndicator.objects.filter(
        project_id__in=[p for p, _ in missing]
    )
    indicators = {i.project_id: i for i in indicators_qs}

    pool = mp.Pool(processors)
    results = [
        pool.apply_async(create_metric, args=(indicators, metric_name, pronac))
        for pronac, metric_name in missing
    ]

    calculated_metrics = [p.get() for p in results]
    if calculated_metrics:
        Metric.objects.bulk_create(calculated_metrics)
        print("Bulk completed")

        for indicator in indicators.values():
            indicator.fetch_weighted_complexity()

        print("Finished update indicators!")

    pool.close()
    print("Finished metrics calculation!")

Creates metrics, creating an Indicator if it doesn't already exists
    Metrics are created for projects that are in pronacs and saved in
    database.

Args:
            metrics: list of names of metrics that will be calculated
            pronacs: pronacs in dataset that is used to calculate those metrics


def cellsiter_to_dataframe(cellsiter, args, drop_allna=True):

    from modelx.core.cells import shareable_parameters

    if len(args):
        indexes = shareable_parameters(cellsiter)
    else:
        indexes = get_all_params(cellsiter.values())

    result = None

    for cells in cellsiter.values():
        df = cells_to_dataframe(cells, args)

        if drop_allna and df.isnull().all().all():
            continue  #  Ignore all NA or empty

        if df.index.names != [None]:
            if isinstance(df.index, pd.MultiIndex):
                if _pd_ver < (0, 20):
                    df = _reset_naindex(df)

            df = df.reset_index()

        missing_params = set(indexes) - set(df)

        for params in missing_params:
            df[params] = np.nan

        if result is None:
            result = df
        else:
            try:
                result = pd.merge(result, df, how="outer")
            except MergeError:
                # When no common column exists, i.e. all cells are scalars.
                result = pd.concat([result, df], axis=1)
            except ValueError:
                # When common columns are not coercible (numeric vs object),
                # Make the numeric column object type
                cols = set(result.columns) & set(df.columns)
                for col in cols:

                    # When only either of them has object dtype
                    if (
                        len(
                            [
                                str(frame[col].dtype)
                                for frame in (result, df)
                                if str(frame[col].dtype) == "object"
                            ]
                        )
                        == 1
                    ):

                        if str(result[col].dtype) == "object":
                            frame = df
                        else:
                            frame = result
                        frame[[col]] = frame[col].astype("object")

                # Try again
                result = pd.merge(result, df, how="outer")

    if result is None:
        return pd.DataFrame()
    else:
        return result.set_index(indexes) if indexes else result

Convert multiple cells to a frame.

    If args is an empty sequence, all values are included.
    If args is specified, cellsiter must have shareable parameters.

Args:
        cellsiter: A mapping from cells names to CellsImpl objects.
        args: A sequence of arguments


def create(self, project_id=None):

    if not self.exists():
      if project_id is None:
        project_id = self._api.project_id
      try:
        self._info = self._api.buckets_insert(self._name, project_id=project_id)
      except Exception as e:
        raise e
    return self

Creates the bucket.

Args:
        project_id: the project in which to create the bucket.

Returns:
        The bucket.

Raises:
        Exception if there was an error creating the bucket.


def _bot(self, k):

        if k < 2:
            raise ValueError("k smaller than 2")
        G = np.ones((self.m, self.m))
        np.fill_diagonal(G, 0)
        for i in range(self.m):
            for j in range(self.m):
                if i == j:
                    continue
                if i <= k and j <= k:
                    G[i][j] = 0
        return G

Description:
    Bottom k breaking
    Parameters:
    k: the number of alternatives to break from lowest rank


def get_built_in(self, language, level, data):

        # Language is python
        pp = pprint.PrettyPrinter(indent=level)

        lookup = {'python' : pp.pformat(data),
                  'json' : str(json.dumps(data, sort_keys=True, indent=level, separators=(',', ': ')))}

        self.data_structure = lookup[language]

Gets the return string for a language that's supported by python.
    Used in cases when python provides support for the conversion.

Args:
        language: string the langage to return for.

        level: integer, the indentation level.

        data: python data structure being converted (list of tuples)

Returns:
        None, updates self.data_structure


def upload(self, title, description="", keywords="", developer_tags=None, access_control=AccessControl.Public):

        # Raise ApiError if not authenticated
        if not self.authenticated:
            raise ApiError(_("Authentication is required"))

        # create media group
        my_media_group = gdata.media.Group(
            title=gdata.media.Title(text=title),
            description=gdata.media.Description(description_type='plain',
                                                text=description),
            keywords=gdata.media.Keywords(text=keywords),
            category=[gdata.media.Category(
                text='Autos',
                scheme='http://gdata.youtube.com/schemas/2007/categories.cat',
                label='Autos')],
            #player = None
        )

        # Access Control
        extension = self._access_control(access_control, my_media_group)

        # create video entry
        video_entry = gdata.youtube.YouTubeVideoEntry(
            media=my_media_group, extension_elements=extension)

        # add developer tags
        if developer_tags:
            video_entry.AddDeveloperTags(developer_tags)

        # upload meta data only
        response = Api.yt_service.GetFormUploadToken(video_entry)

        # parse response tuple and use the variables to build a form
        post_url = response[0]
        youtube_token = response[1]

        return {'post_url': post_url, 'youtube_token': youtube_token}

Browser based upload
    Creates the video entry and meta data to initiate a browser upload

    Authentication is needed

    Params:
        title: string
        description: string
        keywords: comma seperated string
        developer_tags: tuple

Returns:
        dict contains post_url and youtube_token. i.e { 'post_url': post_url, 'youtube_token': youtube_token }

Raises:
        ApiError: on no authentication


def raster_binarization(given_value, rasterfilename):

        origin_raster = RasterUtilClass.read_raster(rasterfilename)
        binary_raster = numpy.where(origin_raster.data == given_value, 1, 0)
        return binary_raster

Make the raster into binarization.

    The opening and closing are based on binary image. Therefore we need to
    make the raster into binarization.

Args:
        given_value: The given value's pixels will be value in 1,
        other pixels will be value in 0.
        rasterfilename: The initial rasterfilena,e.

Returns:
        binary_raster: Raster after binarization.


def prop(pode, prop):

    form = pode[0][0]
    if prop.startswith(form):
        prop = prop[len(form):]
    if prop[0] == ':':
        prop = prop[1:]
    return pode[1]['props'].get(prop)

Return the valu of a given property on the node.

Args:
        pode (tuple): A packed node.
        prop (str): Property to retrieve.

Note:
        The prop argument may be the full property name (foo:bar:baz), relative property name (:baz) , or the unadorned
        property name (baz).

    Returns:


def _check_module(folder):

        if not folder.exists():
            folder.mkdir(parents=True, exist_ok=True, mode=0o755)
            (folder / '__init__.py').touch()

Create module folder with empty __init__.py if it doesn't exist.

Args:
        folder (pathlib.Path): Module path.


def __init__(self, api, path, options):

    self._init(api, path, options)

Initialize.

Args:
        api: storage_api instance.
        path: bucket path of form '/bucket'.
        options: a dict of listbucket options. Please see listbucket doc.


def _are_scopes_sufficient(authorized_scopes, sufficient_scopes):

  for sufficient_scope_set in sufficient_scopes:
    if sufficient_scope_set.issubset(authorized_scopes):
      return True
  return False

Check if a list of authorized scopes satisfies any set of sufficient scopes.

Args:
        authorized_scopes: a list of strings, return value from oauth.get_authorized_scopes
        sufficient_scopes: a set of sets of strings, return value from _process_scopes


def splitext2(filepath):

    root, filename = os.path.split(safepath(filepath))
    filename, ext = os.path.splitext(safepath(filename))
    return root, filename, ext

Split filepath into root, filename, ext

Args:
        filepath (str, path): file path

Returns:
        str


def add(self, rule: 'functions.ReplacementRule') -> None:

        self.matcher.add(rule.pattern, rule.replacement)

Add a new rule to the replacer.

Args:
        rule:
            The rule to add.


def get(name):

    for matcher in matchers:
        if matcher.__name__ == name or getattr(matcher, 'name', None) == name:
            return matcher

Returns a matcher instance by class or alias name.

Args:
        name (str): matcher class name or alias.

Returns:
        matcher: found matcher instance, otherwise ``None``.


def _configure_tls_parameters(parameters):

    cert = config.conf["tls"]["certfile"]
    key = config.conf["tls"]["keyfile"]
    if cert and key:
        _log.info(
            "Authenticating with server using x509 (certfile: %s, keyfile: %s)",
            cert,
            key,
        )
        parameters.credentials = pika.credentials.ExternalCredentials()
    else:
        cert, key = None, None

    if SSLOptions is None:
        parameters.ssl = True
        parameters.ssl_options = {
            "keyfile": key,
            "certfile": cert,
            "ca_certs": config.conf["tls"]["ca_cert"],
            "cert_reqs": ssl.CERT_REQUIRED,
            "ssl_version": ssl.PROTOCOL_TLSv1_2,
        }
    else:
        ssl_context = ssl.create_default_context()
        if config.conf["tls"]["ca_cert"]:
            try:
                ssl_context.load_verify_locations(cafile=config.conf["tls"]["ca_cert"])
            except ssl.SSLError as e:
                raise ConfigurationException(
                    'The "ca_cert" setting in the "tls" section is invalid ({})'.format(
                        e
                    )
                )
        ssl_context.options |= ssl.OP_NO_SSLv2
        ssl_context.options |= ssl.OP_NO_SSLv3
        ssl_context.options |= ssl.OP_NO_TLSv1
        ssl_context.options |= ssl.OP_NO_TLSv1_1
        ssl_context.verify_mode = ssl.CERT_REQUIRED
        ssl_context.check_hostname = True
        if cert and key:
            try:
                ssl_context.load_cert_chain(cert, key)
            except ssl.SSLError as e:
                raise ConfigurationException(
                    'The "keyfile" setting in the "tls" section is invalid ({})'.format(
                        e
                    )
                )
        parameters.ssl_options = SSLOptions(
            ssl_context, server_hostname=parameters.host
        )

Configure the pika connection parameters for TLS based on the configuration.

    This modifies the object provided to it. This accounts for whether or not
    the new API based on the standard library's SSLContext is available for
    pika.

Args:
        parameters (pika.ConnectionParameters): The connection parameters to apply
            TLS connection settings to.


def __call__(self, fn):

        def benchmark(app, *args, **kwargs):

            # before = float('{0:.4f}'.format(time.clock()))
            before = datetime.datetime.now()
            data = fn(app, *args, **kwargs)
            # after = float('{0:.4f}'.format(time.clock()))
            after = datetime.datetime.now()
            app.tcex.log.debug(
                'function: "{}", benchmark_time: "{}"'.format(
                    self.__class__.__name__, after - before
                )
            )
            return data

        return benchmark

Implement __call__ function for decorator.

Args:
        fn (function): The decorated function.

Returns:
        function: The custom decorator function.


def create_app(config=None, config_obj=None):

    app = Flask(__name__)
    # configure application from external configs
    configure_app(app, config=config, config_obj=config_obj)
    # register different parts of the application
    register_blueprints(app)
    # setup extensions
    bind_extensions(app)
    return app

Flask app factory function.

Args:
        config (Optional[path]): path to a Python module config file
        config_obj (Optional[class]): Python config object


def rms(x):

    try:
        return (np.array(x) ** 2).mean() ** 0.5
    except:
        x = np.array(dropna(x))
        invN = 1.0 / len(x)
        return (sum(invN * (x_i ** 2) for x_i in x)) ** .5

Root Mean Square"

Args:
        x (seq of float): A sequence of numerical values

Returns:
        The square root of the average of the squares of the values

        math.sqrt(sum(x_i**2 for x_i in x) / len(x))

        or

        return (np.array(x) ** 2).mean() ** 0.5

    >>> rms([0, 2, 4, 4])
    3.0


def delete_idx_status(self, rdf_class):

        sparql_template =
        rdf_types = [rdf_class.uri] + [item.uri
                                       for item in rdf_class.subclasses]
        sparql = sparql_template.format("\n\t\t".join(rdf_types))
        log.warn("Deleting index status for %s", rdf_class.uri)
        return self.tstore_conn.update_query(sparql)

Removes all of the index status triples from the datastore

Args:
    -----
        rdf_class: The class of items to remove the status from


def exit_handler(signum, frame):

    LOGGER.debug('signal {} was caught'.format(signum))
    sys.exit(128 + signum)

Catch SIGTERM and SIGHUP and call "sys.exit" which raises
    "SystemExit" exception.
    This will trigger all the cleanup code defined in ContextManagers
    and "finally" statements.

    For more details about the arguments see "signal" documentation.

Args:
        signum(int): The signal's number
        frame(frame): The current stack frame, can be None


def parameterize(
        self,
        country: Optional[str] = "South Sudan",
        state: Optional[str] = None,
        year: Optional[int] = None,
        month: Optional[int] = None,
        unit: Optional[str] = None,
        fallback_aggaxes: List[str] = ["year", "month"],
        aggfunc: Callable = np.mean,
    ):

        valid_axes = ("country", "state", "year", "month")

        if any(map(lambda axis: axis not in valid_axes, fallback_aggaxes)):
            raise ValueError(
                "All elements of the fallback_aggaxes set must be one of the "
                f"following: {valid_axes}"
            )

        for n in self.nodes(data=True):
            for indicator in n[1]["indicators"].values():
                indicator.mean, indicator.unit = get_indicator_value(
                    indicator,
                    country,
                    state,
                    year,
                    month,
                    unit,
                    fallback_aggaxes,
                    aggfunc,
                )
                indicator.stdev = 0.1 * abs(indicator.mean)

Parameterize the analysis graph.

Args:
        country
        year
        month
        fallback_aggaxes:
            An iterable of strings denoting the axes upon which to perform
            fallback aggregation if the desired constraints cannot be met.
        aggfunc: The function that will be called to perform the
            aggregation if there are multiple matches.


def _isbn_cleanse(isbn, checksum=True):

    if not isinstance(isbn, string_types):
        raise TypeError('ISBN must be a string, received %r' % isbn)

    if PY2 and isinstance(isbn, str):  # pragma: Python 2
        isbn = unicode(isbn)
        uni_input = False
    else:  # pragma: Python 3
        uni_input = True

    for dash in DASHES:
        isbn = isbn.replace(dash, unicode())

    if checksum:
        if not isbn[:-1].isdigit():
            raise IsbnError('non-digit parts')
        if len(isbn) == 9:
            isbn = '0' + isbn
        if len(isbn) == 10:
            if not (isbn[-1].isdigit() or isbn[-1] in 'Xx'):
                raise IsbnError('non-digit or X checksum')
        elif len(isbn) == 13:
            if not isbn[-1].isdigit():
                raise IsbnError('non-digit checksum')
            if not isbn.startswith(('978', '979')):
                raise IsbnError('invalid Bookland region')
        else:
            raise IsbnError('ISBN must be either 10 or 13 characters long')
    else:
        if len(isbn) == 8:
            isbn = '0' + isbn
        elif len(isbn) == 12 and not isbn[:3].startswith(('978', '979')):
            raise IsbnError('invalid Bookland region')
        if not isbn.isdigit():
            raise IsbnError('non-digit parts')
        if not len(isbn) in (9, 12):
            raise IsbnError('ISBN must be either 9 or 12 characters long '
                            'without checksum')
    if PY2 and not uni_input:  # pragma: Python 2
        # Sadly, type ping-pong is required to maintain backwards compatibility
        # with previous pyisbn releases for Python 2 users.
        return str(isbn)
    else:  # pragma: Python 3
        return isbn

Check ISBN is a string, and passes basic sanity checks.

Args:
        isbn (str): SBN, ISBN-10 or ISBN-13
        checksum (bool): ``True`` if ``isbn`` includes checksum character

Returns:
        ``str``: ISBN with hyphenation removed, including when called with a
            SBN

Raises:
        TypeError: ``isbn`` is not a ``str`` type
        IsbnError: Incorrect length for ``isbn``
        IsbnError: Incorrect SBN or ISBN formatting


def topsSSE(symbols=None, on_data=None, token='', version=''):

    return _runSSE('tops', symbols, on_data, token, version)

TOPS provides IEX’s aggregated best quoted bid and offer position in near real time for all securities on IEX’s displayed limit order book.
    TOPS is ideal for developers needing both quote and trade data.

    https://iexcloud.io/docs/api/#tops

Args:
        symbols (string); Tickers to request
        on_data (function): Callback on data
        token (string); Access token
        version (string); API version


def is_control(input, model_file=None, model_proto=None, name=None):

  return _gen_sentencepiece_processor_op.sentencepiece_get_piece_type(
      input, model_file=model_file, model_proto=model_proto, name=name,
      piece_type=1)

Returns true if input id is control piece.

Args:
        input: An arbitrary tensor of int32.
        model_file: The sentencepiece model file path.
        model_proto: The sentencepiece model serialized proto.
                Either `model_file` or `model_proto` must be set.
        name: The name argument that is passed to the op function.

Returns:
        A tensor of bool with the same shape as input.


def __call__(self, environ, start_response):  # pylint: disable=invalid-name

    request = wrappers.Request(environ)
    parsed_url = urlparse.urlparse(request.path)
    clean_path = _clean_path(parsed_url.path, self._path_prefix)

    # pylint: disable=too-many-function-args
    if clean_path in self.data_applications:
      return self.data_applications[clean_path](environ, start_response)
    else:
      logger.warn('path %s not found, sending 404', clean_path)
      return http_util.Respond(request, 'Not found', 'text/plain', code=404)(
          environ, start_response)

Central entry point for the TensorBoard application.

    This method handles routing to sub-applications. It does simple routing
    using regular expression matching.

    This __call__ method conforms to the WSGI spec, so that instances of this
    class are WSGI applications.

Args:
        environ: See WSGI spec.
        start_response: See WSGI spec.

Returns:
        A werkzeug Response.


def export_to_tf_tensor(self, x):

    mesh_impl = self.mesh_impl(x)
    return mesh_impl.export_to_tf_tensor(
        x, self.tensors[x].to_laid_out_tensor())

Turn a Tensor into a tf.Tensor.

Args:
        x: Tensor.

Returns:
        tf.Tensor.


def __init__(self, fold_scope_location, field_type):

        super(FoldedContextField, self).__init__(fold_scope_location, field_type)
        self.fold_scope_location = fold_scope_location
        self.field_type = field_type
        self.validate()

Construct a new FoldedContextField object for this folded field.

Args:
        fold_scope_location: FoldScopeLocation specifying the location of
                            the context field being output.
        field_type: GraphQL type object, specifying the type of the field being output.
                    Since the field is folded, this must be a GraphQLList of some kind.

Returns:
        new FoldedContextField object


def _to_key_ranges_by_shard(cls, app, namespaces, shard_count, query_spec):

    key_ranges_by_ns = []
    # Split each ns into n splits. If a ns doesn't have enough scatter to
    # split into n, the last few splits are None.
    for namespace in namespaces:
      ranges = cls._split_ns_by_scatter(
          shard_count,
          namespace,
          query_spec.entity_kind,
          app)
      # The nth split of each ns will be assigned to the nth shard.
      # Shuffle so that None are not all by the end.
      random.shuffle(ranges)
      key_ranges_by_ns.append(ranges)

    # KeyRanges from different namespaces might be very different in size.
    # Use round robin to make sure each shard can have at most one split
    # or a None from a ns.
    ranges_by_shard = [[] for _ in range(shard_count)]
    for ranges in key_ranges_by_ns:
      for i, k_range in enumerate(ranges):
        if k_range:
          ranges_by_shard[i].append(k_range)

    key_ranges_by_shard = []
    for ranges in ranges_by_shard:
      if ranges:
        key_ranges_by_shard.append(key_ranges.KeyRangesFactory.create_from_list(
            ranges))
    return key_ranges_by_shard

Get a list of key_ranges.KeyRanges objects, one for each shard.

    This method uses scatter index to split each namespace into pieces
    and assign those pieces to shards.

Args:
        app: app_id in str.
        namespaces: a list of namespaces in str.
        shard_count: number of shards to split.
        query_spec: model.QuerySpec.

Returns:
        a list of key_ranges.KeyRanges objects.


def _addResults(self, results):

    # -----------------------------------------------------------------------
    # If the model potentially has temporal inferences.
    if self.__isTemporal:
      shiftedInferences = self.__inferenceShifter.shift(results).inferences
      self.__currentResult = copy.deepcopy(results)
      self.__currentResult.inferences = shiftedInferences
      self.__currentInference = shiftedInferences

    # -----------------------------------------------------------------------
    # The current model has no temporal inferences.
    else:
      self.__currentResult = copy.deepcopy(results)
      self.__currentInference = copy.deepcopy(results.inferences)

    # -----------------------------------------------------------------------
    # Save the current ground-truth results
    self.__currentGroundTruth = copy.deepcopy(results)

Stores the current model results in the manager's internal store

    Parameters:
    -----------------------------------------------------------------------
    results:  A ModelResults object that contains the current timestep's
            input/inferences


def find(self, instance_id):

        instance = AtlasServiceInstance.Instance(instance_id, self.backend)
        self.backend.storage.populate(instance)
        return instance

find an instance

    Create a new instance and populate it with data stored if it exists.

Args:
        instance_id (str): UUID of the instance

Returns:
        AtlasServiceInstance.Instance: An instance


def _get_flags(osm_obj):

    flags = []
    if osm_obj.visible:
        flags.append('visible')
    if osm_obj.user:
        flags.append('user: %s' % osm_obj.user)
    if osm_obj.timestamp:
        flags.append('timestamp: %s' % osm_obj.timestamp.isoformat())
    if osm_obj.tags:
        flags.append(', '.join('%s: %s' % (k, v)
                               for k, v in sorted(osm_obj.tags.items())))
    return flags

Create element independent flags output.

Args:
        osm_obj (Node): Object with OSM-style metadata

Returns:
        list: Human readable flags output


def make_string_field_value(cls, field):

        if field.regex is not None:
            raise NotImplementedError

        string_range = cls.get_range(field)

        return cls.get_random_string(string_range)

String Field has three constraints (apart from anything
    in the super class)

Args:
        field (StringField): actual string field object from a
        model declaration

Returns:
        random string value


def task(self, task_uuid):

        request = clearly_pb2.FindTaskRequest(task_uuid=task_uuid)
        task = self._stub.find_task(request)
        if task.uuid:
            ClearlyClient._display_task(task, True, True, True)
        else:
            print(EMPTY)

Finds one specific task.

Args:
        task_uuid (str): the task id


def find_container_traits(cls_or_string):

    if utils.is_str(cls_or_string):
        if not templates.is_instantiation(cls_or_string):
            return None
        name = templates.name(cls_or_string)
        if name.startswith('std::'):
            name = name[len('std::'):]
        if name.startswith('std::tr1::'):
            name = name[len('std::tr1::'):]
        for cls_traits in all_container_traits:
            if cls_traits.name() == name:
                return cls_traits
    else:

        if isinstance(cls_or_string, class_declaration.class_types):
            # Look in the cache.
            if cls_or_string.cache.container_traits is not None:
                return cls_or_string.cache.container_traits

        # Look for a container traits
        for cls_traits in all_container_traits:
            if cls_traits.is_my_case(cls_or_string):
                # Store in the cache
                if isinstance(cls_or_string, class_declaration.class_types):
                    cls_or_string.cache.container_traits = cls_traits
                return cls_traits

Find the container traits type of a declaration.

Args:
        cls_or_string (str | declarations.declaration_t): a string

Returns:
        declarations.container_traits: a container traits


def open_audio(frequency=44100, format=AudioFormat.default, channels=2, chunksize=1024):

    check_int_err(lib.Mix_OpenAudio(frequency, format, channels, chunksize))

Open the mixer with a certain audio format.

Args:
        frequency (int): Output sampling frequency in samples per second (Hz).
        format (AudioFormat): Output sample format.
        channels (int): Number of sound channels in output. Set to 2 for stereo, 1 for mono.
        chunksize (int): Bytes used per output sample.

Raises:
        SDLError: If the audio device cannot be opened.


def __init__(self, backend, job_id):

        self._job_id = job_id
        self._backend = backend

Initializes the asynchronous job.

Args:
        backend (BaseBackend): the backend used to run the job.
        job_id (str): a unique id in the context of the backend used to run
            the job.


def from_Z(z: int):

        for sym, data in _pt_data.items():
            if data["Atomic no"] == z:
                return Element(sym)
        raise ValueError("No element with this atomic number %s" % z)

Get an element from an atomic number.

Args:
        z (int): Atomic number

Returns:
        Element with atomic number z.


def dump(ofp, *pb_objs, **kwargs):

    mode = 'wb'
    if isinstance(ofp, str):
        ostream = open(ofp, mode=mode, **kwargs)
    else:
        ostream = open(fileobj=ofp, mode=mode, **kwargs)
    with ostream:
        ostream.write(*pb_objs)

Write to a stream.

Args:
        ofp (string or file-like object): output stream.
        pb_objs (*protobuf.message.Message): list of protobuf message objects
            to be written.


def disconnect(signal, receiver):

    inputkey = __make_id(receiver)

    with __lock:
        __purge()
        receivers = __receivers.get(signal)

        for idx in six.moves.range(len(receivers)):
            connected = receivers[idx]()

            if inputkey != __make_id(connected):
                continue

            del receivers[idx]
            return True  # receiver successfully disconnected!

    return False

Disconnect the receiver `func` from the signal, identified by
    `signal_id`.

Args:
        signal: The signal identifier.
        receiver: The callable receiver to disconnect.

Returns:
        True if the receiver was successfully disconnected. False otherwise.


def multiple(layer: int, limit: int) -> Set[str]:

	return {str(x).zfill(2) for x in [2**x for x in range(limit)] if x % 2**(layer - 1) == 0}

Returns a set of strings to be used as Slots with Pabianas default Clock.

Args:
    layer: The layer in the hierarchy this Area is placed in.
        Technically, the number specifies how many of the Clocks signals are relevant to the Area.
        Between 1 and limit.
    limit: The number of layers of the hierarchy.


def QA_fetch_financial_report_adv(code, start, end=None, ltype='EN'):

    if end is None:

        return QA_DataStruct_Financial(QA_fetch_financial_report(code, start, ltype=ltype))
    else:
        series = pd.Series(
            data=month_data, index=pd.to_datetime(month_data), name='date')
        timerange = series.loc[start:end].tolist()
        return QA_DataStruct_Financial(QA_fetch_financial_report(code, timerange, ltype=ltype))

高级财务查询接口

Args:
        code {[type]} -- [description]
        start {[type]} -- [description]
    Keyword Arguments:
        end {[type]} -- [description] (default: {None})


def get_output_dict(stack):

    outputs = {}
    if 'Outputs' not in stack:
        return outputs

    for output in stack['Outputs']:
        logger.debug("    %s %s: %s", stack['StackName'], output['OutputKey'],
                     output['OutputValue'])
        outputs[output['OutputKey']] = output['OutputValue']
    return outputs

Returns a dict of key/values for the outputs for a given CF stack.

Args:
        stack (dict): The stack object to get
            outputs from.

Returns:
        dict: A dictionary with key/values for each output on the stack.


def ch_start_time(self, *channels: List[Channel]) -> int:

        intervals = list(itertools.chain(*(self._table[chan] for chan in channels
                                           if chan in self._table)))
        if intervals:
            return min((interval.begin for interval in intervals))
        return 0

Return earliest start time in this collection.

Args:
        *channels: Channels over which to obtain start_time.


def apply(
        self,
        func,
        axis=0,
        broadcast=None,
        raw=False,
        reduce=None,
        result_type=None,
        convert_dtype=True,
        args=(),
        **kwds
    ):

        axis = self._get_axis_number(axis)
        ErrorMessage.non_verified_udf()
        if isinstance(func, string_types):
            if axis == 1:
                kwds["axis"] = axis
            result = self._string_function(func, *args, **kwds)
            # Sometimes we can return a scalar here
            if isinstance(result, BasePandasDataset):
                return result._query_compiler
            return result
        elif isinstance(func, dict):
            if axis == 1:
                raise TypeError(
                    "(\"'dict' object is not callable\", "
                    "'occurred at index {0}'".format(self.index[0])
                )
            if len(self.columns) != len(set(self.columns)):
                warnings.warn(
                    "duplicate column names not supported with apply().",
                    FutureWarning,
                    stacklevel=2,
                )
        elif not callable(func) and not is_list_like(func):
            raise TypeError("{} object is not callable".format(type(func)))
        query_compiler = self._query_compiler.apply(func, axis, *args, **kwds)
        return query_compiler

Apply a function along input axis of DataFrame.

Args:
        func: The function to apply
        axis: The axis over which to apply the func.
        broadcast: Whether or not to broadcast.
        raw: Whether or not to convert to a Series.
        reduce: Whether or not to try to apply reduction procedures.

Returns:
        Series or DataFrame, depending on func.


def to_grayscale(img, num_output_channels=1):

    if not _is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

    if num_output_channels == 1:
        img = img.convert('L')
    elif num_output_channels == 3:
        img = img.convert('L')
        np_img = np.array(img, dtype=np.uint8)
        np_img = np.dstack([np_img, np_img, np_img])
        img = Image.fromarray(np_img, 'RGB')
    else:
        raise ValueError('num_output_channels should be either 1 or 3')

    return img

Convert image to grayscale version of image.

Args:
        img (PIL Image): Image to be converted to grayscale.

Returns:
        PIL Image: Grayscale version of the image.
            if num_output_channels = 1 : returned image is single channel

            if num_output_channels = 3 : returned image is 3 channel with r = g = b


def uma_rp_get_claims_gathering_url(self, ticket):

        params = {
            'oxd_id': self.oxd_id,
            'claims_redirect_uri': self.config.get('client',
                                                   'claims_redirect_uri'),
            'ticket': ticket
        }
        logger.debug("Sending command `uma_rp_get_claims_gathering_url` with "
                     "params %s", params)
        response = self.msgr.request("uma_rp_get_claims_gathering_url",
                                     **params)
        logger.debug("Received response: %s", response)

        if response['status'] == 'error':
            raise OxdServerError(response['data'])
        return response['data']['url']

UMA RP function to get the claims gathering URL.

    Parameters:
        * **ticket (str):** ticket to pass to the auth server. for 90% of the cases, this will be obtained from 'need_info' error of get_rpt

Returns:
        **string** specifying the claims gathering url


def murmur2(key):

    # Convert key to bytes or bytearray
    if isinstance(key, bytearray) or (six.PY3 and isinstance(key, bytes)):
        data = key
    else:
        data = bytearray(str(key).encode())

    length = len(data)
    seed = 0x9747b28c
    # 'm' and 'r' are mixing constants generated offline.
    # They're not really 'magic', they just happen to work well.
    m = 0x5bd1e995
    r = 24

    # Initialize the hash to a random value
    h = seed ^ length
    length4 = length // 4

    for i in range(length4):
        i4 = i * 4
        k = ((data[i4 + 0] & 0xff) +
             ((data[i4 + 1] & 0xff) << 8) +
             ((data[i4 + 2] & 0xff) << 16) +
             ((data[i4 + 3] & 0xff) << 24))
        k &= 0xffffffff
        k *= m
        k &= 0xffffffff
        k ^= (k % 0x100000000) >> r  # k ^= k >>> r
        k &= 0xffffffff
        k *= m
        k &= 0xffffffff

        h *= m
        h &= 0xffffffff
        h ^= k
        h &= 0xffffffff

    # Handle the last few bytes of the input array
    extra_bytes = length % 4
    if extra_bytes >= 3:
        h ^= (data[(length & ~3) + 2] & 0xff) << 16
        h &= 0xffffffff
    if extra_bytes >= 2:
        h ^= (data[(length & ~3) + 1] & 0xff) << 8
        h &= 0xffffffff
    if extra_bytes >= 1:
        h ^= (data[length & ~3] & 0xff)
        h &= 0xffffffff
        h *= m
        h &= 0xffffffff

    h ^= (h % 0x100000000) >> 13  # h >>> 13;
    h &= 0xffffffff
    h *= m
    h &= 0xffffffff
    h ^= (h % 0x100000000) >> 15  # h >>> 15;
    h &= 0xffffffff

    return h

Pure-python Murmur2 implementation.

    Based on java client, see org.apache.kafka.common.utils.Utils.murmur2

Args:
        key: if not a bytes type, encoded using default encoding

    Returns: MurmurHash2 of key bytearray


def get_configured_consensus_module(block_id, state_view):

        settings_view = SettingsView(state_view)

        default_consensus = \
            'genesis' if block_id == NULL_BLOCK_IDENTIFIER else 'devmode'
        consensus_module_name = settings_view.get_setting(
            'sawtooth.consensus.algorithm', default_value=default_consensus)
        return ConsensusFactory.get_consensus_module(
            consensus_module_name)

Returns the consensus_module based on the consensus module set by
    the "sawtooth_settings" transaction family.

Args:
        block_id (str): the block id associated with the current state_view
        state_view (:obj:`StateView`): the current state view to use for
            setting values

Raises:
        UnknownConsensusModuleError: Thrown when an invalid consensus
            module has been configured.


def _SetCredentials(self, **kwds):

        args = {
            'api_key': self._API_KEY,
            'client': self,
            'client_id': self._CLIENT_ID,
            'client_secret': self._CLIENT_SECRET,
            'package_name': self._PACKAGE,
            'scopes': self._SCOPES,
            'user_agent': self._USER_AGENT,
        }
        args.update(kwds)
        # credentials_lib can be expensive to import so do it only if needed.
        from apitools.base.py import credentials_lib
        # TODO(craigcitro): It's a bit dangerous to pass this
        # still-half-initialized self into this method, but we might need
        # to set attributes on it associated with our credentials.
        # Consider another way around this (maybe a callback?) and whether
        # or not it's worth it.
        self._credentials = credentials_lib.GetCredentials(**args)

Fetch credentials, and set them for this client.

    Note that we can't simply return credentials, since creating them
    may involve side-effecting self.

Args:
        **kwds: Additional keyword arguments are passed on to GetCredentials.

Returns:
        None. Sets self._credentials.


def create(self, name, domain_name):

        name = self.wrap(self.resource.create(dict(name=name,
                                                   domain_name=domain_name)))

        self.add(name)
        return name

Register a url (e.g. wallet.gem.co) for

Args:
        name (str): human-readable wallet name (e.g. wallet)
        domain_name (str): the domain name to create subdomain on (e.g. gem.co)
        this domain must already be registered with Gem

    Returns: The new round.NetkiName


def _get_password(params):

        user_name = params['user']
        service_name = params['host'] + ':' + params['driver']
        return keyring.get_password(service_name=service_name,
                                    username=user_name)

Get the password for a database connection from :mod:`keyring`

Args:
        params (dict): database configuration, as defined in :mod:`ozelot.config`

Returns:
        str: password


def destroy(self, prefix_names=None):

        if prefix_names is None:
            self.destroy(prefix_names=self.prefixes.keys())
            return

        for prefix_name in prefix_names:
            if prefix_name == 'current' and self.current in prefix_names:
                continue

            elif prefix_name == 'current':
                prefix_name = self.current

            self.get_prefix(prefix_name).destroy()
            self.prefixes.pop(prefix_name)
            if self.prefixes:
                self._update_current()

        if not self.prefixes:
            shutil.rmtree(self.path)

Destroy all the given prefixes and remove any left files if no more
    prefixes are left

Args:
        prefix_names(list of str): list of prefix names to destroy, if None
        passed (default) will destroy all of them


def __DeviceImpl__add_command(self, cmd, device_level=True):

    add_name_in_list = False      # This flag is always False, what use is it?
    try:
        config = dict(cmd.__tango_command__[1][2])
        if config and ("Display level" in config):
            disp_level = config["Display level"]
        else:
            disp_level = DispLevel.OPERATOR
        self._add_command(cmd.__name__, cmd.__tango_command__[1], disp_level,
                          device_level)
        if add_name_in_list:
            cl = self.get_device_class()
            cl.dyn_cmd_added_methods.append(cmd.__name__)
    except:
        if add_name_in_list:
            self._remove_cmd(cmd.__name__)
        raise
    return cmd

add_command(self, cmd, level=TANGO::OPERATOR) -> cmd

    Add a new command to the device command list.

    Parameters :
        - cmd          : the new command to be added to the list
        - device_level : Set this flag to true if the command must be added
                        for only this device

    Return     : Command

    Throws     : DevFailed


def as_dict(self, verbosity: int = 0) -> Dict:

        d = {
            "@module": self.__class__.__module__,
            "@class": self.__class__.__name__,
            "matrix": self._matrix.tolist(),
        }
        (a, b, c), (alpha, beta, gamma) = self.lengths_and_angles
        if verbosity > 0:
            d.update(
                {
                    "a": a,
                    "b": b,
                    "c": c,
                    "alpha": alpha,
                    "beta": beta,
                    "gamma": gamma,
                    "volume": self.volume,
                }
            )

        return d

Json-serialization dict representation of the Lattice.

Args:
        verbosity (int): Verbosity level. Default of 0 only includes the
            matrix representation. Set to 1 for more details.


def _resolve_attribute_match(self, match):

        if match.group(1) == 'cluster':
            return str(self.cluster_id)

        return self.get(match.group(1), match.group(0))

Replaces a reference to an attribute with the value of the attribute.

Args:
        match (re.match object): A match object containing a match to a reference to an attribute.