def psi_K_Na_OH_HMW84(T, P):
    """c-c'-a: potassium sodium hydroxide [HMW84]."""
    psi = 0
    valid = T == 298.15
    return psi, valid


def clearcollapsemsg(repo):
    """Remove collapse message file"""
    repo.vfs.unlinkpath(b'last-message.txt', ignoremissing=True)


def hasdir(dir):
    """Returns a bool indicating if a directory is in this manifest."""


def get_image_xml_meta(root):
    """gets all Image XML information from ETree root object. Returns list"""
    img_el = root.findall(
        '{http://www.openmicroscopy.org/Schemas/OME/2016-06}Image')
    return img_el


def ping():
    """Attempt to contact the worker and see if it is still alive. This
        returns a Deferred which fires with either True (the worker is still
        alive) or False (the worker did not respond). As a side effect, adds an
        event to this builder's column in the waterfall display containing the
        results of the ping. Note that this may not fail for a long time, it is
        implemented in terms of the timeout on the underlying TCP connection."""


@classmethod
def _get_snapshots_by_name(cls, snapshots, name):
    """
        Filter the snapshots by name
        :param snapshots: The list of the snapshots
        :param name: The name

        :return: The list of snapshots filtered
        """
    found_snapshots = []
    for snapshot in snapshots:
        if name == snapshot.name:
            found_snapshots.append(snapshot)
        found_snapshots = found_snapshots + cls._get_snapshots_by_name(snapshot
            .childSnapshotList, name)
    return found_snapshots


def identifyKeyValue(string):
    """
    identify key-end and value-start position
    from data start immediately with the key.

    the data should not have leading whitespace
    since whitespace will be read as seperator,
    then the key will be empty.

    @example
    identifyKeyValue('key=value') -> 3, 4
    identifyKeyValue('key = value') -> 3, 6
    """
    limit = len(string)
    keyEnd = 0
    valueStart = limit
    hasSep = False
    precedingBackslash = False
    while keyEnd < limit:
        c = string[keyEnd]
        if (c == '=' or c == ':') and not precedingBackslash:
            valueStart = keyEnd + 1
            hasSep = True
            break
        elif (c == ' ' or c == '\t' or c == '\x0c') and not precedingBackslash:
            valueStart = keyEnd + 1
            break
        if c == '\\':
            precedingBackslash = not precedingBackslash
        else:
            precedingBackslash = False
        keyEnd += 1
    while valueStart < limit:
        c = string[valueStart]
        if c != ' ' and c != '\t' and c != '\x0c':
            if not hasSep and (c == '=' or c == ':'):
                hasSep = True
            else:
                break
        valueStart += 1
    return keyEnd, valueStart


@staticmethod
def _check_key_list(key_list):
    """Check if key_list is valid"""
    if len(key_list) == 0:
        raise KeyError('key_list cannot be empty')


def momentcondquant(distfn, params, mom2, quantile=None, shape=None):
    """moment conditions for estimating distribution parameters by matching
    quantiles, defines as many moment conditions as quantiles.

    Returns
    -------
    difference : ndarray
        difference between theoretical and empirical quantiles

    Notes
    -----
    This can be used for method of moments or for generalized method of
    moments.

    """
    if len(params) == 2:
        loc, scale = params
    elif len(params) == 3:
        shape, loc, scale = params
    else:
        pass
    pq, xq = quantile
    cdfdiff = distfn.cdf(xq, *params) - pq
    return cdfdiff


def decode(text):
    """
    Декодирование текста полученного с фискального регистратора.
    """
    return text.decode('cp1251')


@staticmethod
def setup_command_line(parser):
    """Setup command line options for getting graphs"""
    raise NotImplementedError('Graph Input helper must be subclassed')


def get_discovery_summary():
    """
    Retrieves a short summary of discovered assets.
    See also: AWS API Documentation

    :example: response = client.get_discovery_summary()

    :rtype: dict
    :return: {
        'servers': 123,
        'applications': 123,
        'serversMappedToApplications': 123,
        'serversMappedtoTags': 123,
        'agentSummary': {
            'activeAgents': 123,
            'healthyAgents': 123,
            'blackListedAgents': 123,
            'shutdownAgents': 123,
            'unhealthyAgents': 123,
            'totalAgents': 123,
            'unknownAgents': 123
        },
        'connectorSummary': {
            'activeConnectors': 123,
            'healthyConnectors': 123,
            'blackListedConnectors': 123,
            'shutdownConnectors': 123,
            'unhealthyConnectors': 123,
            'totalConnectors': 123,
            'unknownConnectors': 123
        }
    }

    """
    pass


def setCss(css):
    """
    Function generating a script to set a given CSS style sheet.

    @param css style sheet
    @type str
    @return script to set the style sheet
    @rtype str
    """
    source = """
(function() {{
    var css = document.createElement('style');
    css.setAttribute('type', 'text/css');
    css.appendChild(document.createTextNode('{0}'));
    document.getElementsByTagName('head')[0].appendChild(css);
    }})()"""
    style = css.replace("'", "\\'").replace('\n', '\\n')
    return source.format(style)


def hasVersion(state):
    """Return true if a version exists in state.
        """


def render_git_describe(pieces):
    """TAG[-DISTANCE-gHEX][-dirty].

    Like 'git describe --tags --dirty --always'.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance']:
            rendered += '-%d-g%s' % (pieces['distance'], pieces['short'])
    else:
        rendered = pieces['short']
    if pieces['dirty']:
        rendered += '-dirty'
    return rendered


def install(createpdf, options):
    """ This function is called with an object with the createpdf
        module globals as attributes, and with the options from
        the command line parser.  This function does not have
        to exist, but must have the correct call signature if
        it does.
    """


def entry_spread_price(data, value, _idx):
    """
    The net price of the spread.

    For example, it would set a min max of $0.10 to $0.20 and find only spreads with prices
    within that range.
    """
    pass


@classmethod
def get_isolated_subnets(cls, network):
    """Returns a dict indicating whether or not a subnet is isolated"""
    raise NotImplementedError()


def add_edge(graph, s, t, attrs=None, **attr):
    """Add an edge to a graph.

    Parameters
    ----------
    graph : regraph.Graph
    s : hashable, source node id.
    t : hashable, target node id.
    attrs : dict
        Edge attributes.

    Raises
    ------
    ReGraphError
        If `attrs` is not a dictionary
    GraphError
        If either one of the nodes does not exist in the graph or
        an edge between `s` and `t` already
        exists.
    """
    graph.add_edge(s, t, attrs)


def make_payload(method, params):
    """
    Makes the JSON-RPC payload
    :param method: Name of the RPC method to invoke
    :param params: Parameters of the method
    :return: Full payload
    """
    payload = {'method': method}
    if len(params) > 0:
        payload['params'] = params
    return payload


@staticmethod
def _get_accumulators(outputs: dict):
    """
        builds and returns a dictionary containing a key for each step output.
        The outputs of each learning step is stored on this dictionary.
        :param outputs: A dictionary containing the learning step outputs.
        """
    accumulators = dict()
    for output_name in outputs.keys():
        accumulators[output_name] = list()
    return accumulators


@staticmethod
def color_message(text, color='#1433b1'):
    """
        Puts BB-Code formatting around the provided text.

        :param text: text which should be colored.
        :param color: the color which should be put on the text.
        :return: color BB-code formatted string.
        """
    return f'[color={color}]{text}[/color]'


def cast(annotations, bytestring, value):
    """
    Default “cast” function.
    """
    return value


@staticmethod
def pay_server_ip_request():
    """
        Get a Pay server IP validation :class:`paynlsdk2.api.validate.payserverip.Request` instance

        :return: Request instance
        :rtype: paynlsdk2.api.validate.payserverip.Request
        """
    from paynlsdk2.api.validate.payserverip import Request
    request = Request()
    return request


def register_constructor(cls, extension, constructor):
    """
        Register a function as a constructor.  Registered constructors
        apply to all instances of `URLParser`.

        The extension should have a leading ``.``, or the special
        extensions ``dir`` (for directories) and ``*`` (a catch-all).

        `constructor` must be a callable that takes two arguments:
        ``environ`` and ``filename``, and returns a WSGI application.
        """
    d = cls.global_constructors
    assert extension not in d, 'A constructor already exists for the extension %r (%r) when attemption to register constructor %r' % (
        extension, d[extension], constructor)
    d[extension] = constructor


def sample_object_to_dict(data, elem, skip=''):
    """Process data from self object to data dictionary to prepare for json serialization.

    Parameters
    ----------
    data : dict, required
        Stores collected data for json
    elem : dict, required
        Default data from Sample object(s)
    skip : str, optional
        Some keys in the object should be skipped, such as `outputs` or `populations`. Latter
        is skipped in case if it is already processed previously.

    """
    for key, val in elem.__dict__.items():
        if key in ['outputs', skip]:
            continue
        if key == 'meta':
            for meta_key, meta_val in elem.__dict__[key].items():
                data[meta_key] = meta_val
            continue
        data[key] = val


def saturation(value):
    """Saturation of the light. 254 is the most saturated (colored) and 0 is
    the least saturated (white)."""
    value = int(value)
    if value < 0 or value > 254:
        raise ValueError('Minimum saturation is 0, to the maximum 254')
    return value


def __get_invite_dataset(_query_uri):
    """This function identifies the appropriate invite dataset."""
    _dataset = 'invite'
    if 'invites/event' in _query_uri:
        _dataset = 'event_invite'
    return _dataset


def _expr_compute_of(op1, op2):
    """
    Get overflow flag of @op1 - @op2
    Ref: x86 of flag
    @op1: Expression
    @op2: Expression
    """
    res = op1 - op2
    of = ((op1 ^ res) & (op1 ^ op2)).msb()
    return of


def get_operation_full_job_id(op):
    """Returns the job-id or job-id.task-id for the operation."""
    job_id = op.get_field('job-id')
    task_id = op.get_field('task-id')
    if task_id:
        return '%s.%s' % (job_id, task_id)
    else:
        return job_id


@classmethod
def get_perceval_params_from_url(cls, url):
    """ Get the perceval params given a URL for the data source """
    return [url]


def extract(listvector, argname):
    """Retrieve argument argname from R listvector."""
    if argname not in listvector.names:
        raise ValueError(f'{argname} not found.')
    index = list(listvector.names).index(argname)
    return listvector[index]


def is_empty(G):
    """Returns ``True`` if ``G`` has no edges.

    Parameters
    ----------
    G : graph
        A NetworkX graph.

    Returns
    -------
    bool
        ``True`` if ``G`` has no edges, and ``False`` otherwise.

    Notes
    -----
    An empty graph can have nodes but not edges. The empty graph with zero
    nodes is known as the null graph. This is an O(n) operation where n is the
    number of nodes in the graph.

    """
    return not any(G.adj.values())


@staticmethod
def _dump_foreach_function_name(flow_name, idx):
    """Create foreach function name for a dump.

        :param flow_name: flow name
        :type flow_name: str
        :param idx: index of condition within the flow
        :type idx: int
        :return: condition function representation
        """
    assert idx >= 0
    return '_foreach_{}_{}'.format(flow_name, idx)


def get_grid_coord_from_points_coords(point_coord):
    """
    Converts coordinates to be used in the grid. Returns (row,col). This value will not change with slider.
    :param point:
    :return:
    """
    canvas_origo = 50, 670
    row = canvas_origo[1] - point_coord[1] * 10
    col = point_coord[0] * 10
    return row, col


def get_float_arg(r, name, default=None):
    """
    Retrieve argument from :attr:`flask:flask.request` and convert to float

    :param r: :attr:`flask:flask.request`
    :param name: argument name
    :type: str
    :param default: default value if parameter is non-existent, defaults to None
    :return: float argument value
    """
    val = r.args.get(name)
    if val is None or val == '':
        return default
    else:
        try:
            return float(val)
        except BaseException:
            return default


def _status_as_tuple(status):
    """Translate a status into a tuple of user, context, state"""
    creator = status.get('creator')
    if not creator:
        user = 'Unknown'
    else:
        user = creator.get('login')
    context = status.get('context')
    state = status.get('state')
    return user, context, state


def _get_sub_prop(container, keys, default=None):
    """Get a nested value from a dictionary.

    This method works like ``dict.get(key)``, but for nested values.

    Arguments:
        container (Dict):
            A dictionary which may contain other dictionaries as values.
        keys (Iterable):
            A sequence of keys to attempt to get the value for. Each item in
            the sequence represents a deeper nesting. The first key is for
            the top level. If there is a dictionary there, the second key
            attempts to get the value within that, and so on.
        default (object):
            (Optional) Value to returned if any of the keys are not found.
            Defaults to ``None``.

    Examples:
        Get a top-level value (equivalent to ``container.get('key')``).

        >>> _get_sub_prop({'key': 'value'}, ['key'])
        'value'

        Get a top-level value, providing a default (equivalent to
        ``container.get('key', default='default')``).

        >>> _get_sub_prop({'nothere': 123}, ['key'], default='not found')
        'not found'

        Get a nested value.

        >>> _get_sub_prop({'key': {'subkey': 'value'}}, ['key', 'subkey'])
        'value'

    Returns:
        object: The value if present or the default.
    """
    sub_val = container
    for key in keys:
        if key not in sub_val:
            return default
        sub_val = sub_val[key]
    return sub_val


def _add_profile(api, profile, json_out=False):
    """ Add user profile. if json, dump json dict to stdout """
    if json_out:
        return profile
    return api.add_profile(profile)


def p_update_values(p):
    """update_values : identifier '=' value
					 | update_values ',' identifier '=' value"""
    if len(p) == 4:
        p[0] = {p[1]: p[3]}
    elif isinstance(p[1], dict):
        p[1][p[3]] = p[5]
        p[0] = p[1]
    else:
        p[0] = None


def strip_regex_metachars(pattern):
    """Strip ^ and $ from pattern begining and end.

    According to http://www.w3.org/TR/xmlschema-0/#regexAppendix XMLSchema
    expression language does not contain the metacharacters ^ and $.

    :returns: stripped pattern string

    """
    start = 0
    till = len(pattern)
    if pattern.startswith('^'):
        start = 1
    if pattern.endswith('$'):
        till -= 1
    return pattern[start:till]


@staticmethod
def p_number_string_value_list(p):
    """number_string_value_list : number_string_value
                                    | number_string_value number_string_value_list"""
    try:
        p[0] = [p[1]] + p[2]
    except IndexError:
        p[0] = [p[1]]


def object_mode_pie_or_toggle():
    """Undocumented contribute <https://developer.blender.org/T51061>

    """
    pass


@classmethod
def find(cls, interface, name):
    """
        Returns a :class:`Scheme` or `None` based on interface and
        name.
        """
    try:
        return cls.where(lambda s: s.interface == interface and s.name == name
            )[0]
    except IndexError:
        return None


@classmethod
def global_config(cls, key, *args):
    """ This reads or sets the global settings stored in class.settings. """
    if args:
        cls.settings = cls.settings.copy()
        cls.settings[key] = args[0]
    else:
        return cls.settings[key]


def p_prop(p):
    """prop : PROP '(' named_values ')'"""
    p[0] = dict(p[3])


def index(item, *args):
    """Return first index of value

        `L.index(value, [start, [stop]])` -> integer"""


def plot_mts(Y, names=None, index=None):
    """
    Plot multiple time series
    """
    import matplotlib.pyplot as plt
    k = Y.shape[1]
    rows, cols = k, 1
    fig = plt.figure(figsize=(10, 10))
    for j in range(k):
        ts = Y[:, (j)]
        ax = fig.add_subplot(rows, cols, j + 1)
        if index is not None:
            ax.plot(index, ts)
        else:
            ax.plot(ts)
        if names is not None:
            ax.set_title(names[j])
    return fig


@classmethod
def get_real_child_model(cls, data):
    """Returns the real base class specified by the discriminator"""
    discriminator_value = data[cls.json_discriminator_key]
    return cls.discriminator_value_class_map.get(discriminator_value)


@classmethod
def get_json_schema(cls):
    """
        Get a json schema of this document with datatypes and required
        status
        """
    if cls.__schema__:
        return cls.__schema__


def evalCpuNeeds(totLn, algorithm=None, debug=False):
    """
    Estimates the number of needed threads (cores) based on the total lines to be processed
    For the supported algorithms an estimation is given but should be updated when possible
    NOTES: it is very experimental and based on a very few samples
    """
    import multiprocessing
    maxCores = multiprocessing.cpu_count()
    buckets = [2, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128]
    if debug:
        print('\n evalCpuNeeds START:')
        print('TOT LINES ::\t%s' % str(totLn))
        print('ALGORITHM ::\t%s' % str(algorithm))
    chunkDict = {'bwa': 720000, 'map_pct_calc': 400000, 'avg': 560000}
    if algorithm == None:
        algorithm = 'avg'
    chunkSize = chunkDict[algorithm]
    if chunkSize >= totLn:
        if debug:
            print(
                'Chunk size is bigger than the line to be porcessed, 1 core will do just fine...'
                )
        return 1
    cores = int(totLn / chunkSize)
    if debug:
        print('Selected Algorimth for Estimation:\t%s' % algorithm)
        print('CHUNK SIZE FOR %s ALGORITHM:\t%d' % (algorithm.upper(),
            chunkSize))
    if cores >= maxCores:
        return maxCores
    if algorithm != 'map_pct_calc':
        for el in buckets:
            if float(cores / el) <= 1:
                return el
    return cores


def shorten(s, N=80):
    """
    Return short representation of string s.
    """
    if len(s) <= N:
        return s[:]
    else:
        l = (N - 5) / 2
        return '{} ... {}'.format(s[:l], s[-l:])


def evalcontextfilter(f):
    """Decorator for marking eval-context dependent filters.  An eval
    context object is passed as first argument.  For more information
    about the eval context, see :ref:`eval-context`.

    .. versionadded:: 2.4
    """
    f.evalcontextfilter = True
    return f


@staticmethod
def __get_class(clazz):
    """
        Loads Python class from its name.
        """
    parts = clazz.split('.')
    module = '.'.join(parts[:-1])
    m = __import__(module)
    for comp in parts[1:]:
        m = getattr(m, comp)
    return m


def subscription_get(transport, request, queue_name, subscription_id):
    """Gets a particular subscription data

    :param transport: Transport instance to use
    :type transport: `transport.base.Transport`
    :param request: Request instance ready to be sent.
    :type request: `transport.request.Request`
    :param queue_name: Queue reference name.
    :type queue_name: `six.text_type`
    :param subscription_id: ID of subscription.
    :type subscription_id: `six.text_type`

    """
    request.operation = 'subscription_get'
    request.params['queue_name'] = queue_name
    request.params['subscription_id'] = subscription_id
    resp = transport.send(request)
    return resp.deserialized_content


def list_vaults(accountId=None, marker=None, limit=None):
    """
    This operation lists all vaults owned by the calling user's account. The list returned in the response is ASCII-sorted by vault name.
    By default, this operation returns up to 1,000 items. If there are more vaults to list, the response marker field contains the vault Amazon Resource Name (ARN) at which to continue the list with a new List Vaults request; otherwise, the marker field is null . To return a list of vaults that begins at a specific vault, set the marker request parameter to the vault ARN you obtained from a previous List Vaults request. You can also limit the number of vaults returned in the response by specifying the limit parameter in the request.
    An AWS account has full permission to perform all operations (actions). However, AWS Identity and Access Management (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific actions. For more information, see Access Control Using AWS Identity and Access Management (IAM) .
    For conceptual information and underlying REST API, see Retrieving Vault Metadata in Amazon Glacier and List Vaults in the Amazon Glacier Developer Guide .
    See also: AWS API Documentation

    Examples
    The example lists all vaults owned by the specified AWS account.
    Expected Output:

    :example: response = client.list_vaults(
        marker='string',
        limit='string'
    )

    :type accountId: string
    :param accountId: The AccountId value is the AWS account ID. This value must match the AWS account ID associated with the credentials used to sign the request. You can either specify an AWS account ID or optionally a single '- ' (hyphen), in which case Amazon Glacier uses the AWS account ID associated with the credentials used to sign the request. If you specify your account ID, do not include any hyphens ('-') in the ID.
            Note: this parameter is set to '-' bydefault if no value is not specified.

    :type marker: string
    :param marker: A string used for pagination. The marker specifies the vault ARN after which the listing of vaults should begin.

    :type limit: string
    :param limit: The maximum number of vaults to be returned. The default limit is 1000. The number of vaults returned might be fewer than the specified limit, but the number of returned vaults never exceeds the limit.

    :rtype: dict
    :return: {
        'VaultList': [
            {
                'VaultARN': 'string',
                'VaultName': 'string',
                'CreationDate': 'string',
                'LastInventoryDate': 'string',
                'NumberOfArchives': 123,
                'SizeInBytes': 123
            },
        ],
        'Marker': 'string'
    }

    """
    pass


def key_value_convert(dictin, keyfn=lambda x: x, valuefn=lambda x: x,
    dropfailedkeys=False, dropfailedvalues=False, exception=ValueError):
    """Convert keys and/or values of dictionary using functions passed in as parameters

    Args:
        dictin (DictUpperBound): Input dictionary
        keyfn (Callable[[Any], Any]): Function to convert keys. Defaults to lambda x: x
        valuefn (Callable[[Any], Any]): Function to convert values. Defaults to lambda x: x
        dropfailedkeys (bool): Whether to drop dictionary entries where key conversion fails. Defaults to False.
        dropfailedvalues (bool): Whether to drop dictionary entries where value conversion fails. Defaults to False.
        exception (ExceptionUpperBound): The exception to expect if keyfn or valuefn fail. Defaults to ValueError.

    Returns:
        Dict: Dictionary with converted keys and/or values

    """
    dictout = dict()
    for key in dictin:
        try:
            new_key = keyfn(key)
        except exception:
            if dropfailedkeys:
                continue
            new_key = key
        value = dictin[key]
        try:
            new_value = valuefn(value)
        except exception:
            if dropfailedvalues:
                continue
            new_value = value
        dictout[new_key] = new_value
    return dictout


def unique(x):
    """Convert a list in a unique list."""
    return list(set(x))


def lookupService(name, timeout=None):
    """
        Perform an SRV record lookup.

        @type name: C{str}
        @param name: DNS name to resolve.

        @type timeout: Sequence of C{int}
        @param timeout: Number of seconds after which to reissue the query.
            When the last timeout expires, the query is considered failed.

        @rtype: L{Deferred}
        @return: A L{Deferred} which fires with a three-tuple of lists of
            L{twisted.names.dns.RRHeader} instances.  The first element of the
            tuple gives answers.  The second element of the tuple gives
            authorities.  The third element of the tuple gives additional
            information.  The L{Deferred} may instead fail with one of the
            exceptions defined in L{twisted.names.error} or with
            C{NotImplementedError}.
        """


def require_minimum_pandas_version():
    """ Raise ImportError if minimum version of Pandas is not installed
    """
    minimum_pandas_version = '0.19.2'
    from distutils.version import LooseVersion
    try:
        import pandas
        have_pandas = True
    except ImportError:
        have_pandas = False
    if not have_pandas:
        raise ImportError(
            'Pandas >= %s must be installed; however, it was not found.' %
            minimum_pandas_version)
    if LooseVersion(pandas.__version__) < LooseVersion(minimum_pandas_version):
        raise ImportError(
            'Pandas >= %s must be installed; however, your version was %s.' %
            (minimum_pandas_version, pandas.__version__))


def url_path(data_type, instance_id):
    """
    Build thumbnail download path for given data type and instance ID.
    """
    data_type = data_type.replace('_', '-')
    return 'pictures/thumbnails/%s/%s.png' % (data_type, instance_id)


def print_generated_sequence(gen, num, *, sep=', ', fmt='', seed=None):
    """
    Helper function which prints a sequence of `num` items
    produced by the random generator `gen`.
    """
    if seed:
        gen.reset(seed)
    elems = [format(next(gen), fmt) for _ in range(num)]
    sep_initial = '\n\n' if '\n' in sep else ' '
    print('Generated sequence:{}{}'.format(sep_initial, sep.join(elems)))


@staticmethod
def _format_equality(value) ->str:
    """
        Formatting value in the event of equality operation
        :param value: str
        :return: str
        """
    return '{}'.format(value) if not isinstance(value, list) else value


def save_page(page, filename):
    """Writes the text of an html page to disk

    Parameters
    ----------
    page : requests page object
        The page to write
    filename
        The name of the file to create
    """
    with open(filename, 'w') as f:
        f.write(page.text)


def compute_chunksize(src, w, h, chunksize=None, max_mem=None):
    """
    Attempts to compute a chunksize for the resampling output array
    that is as close as possible to the input array chunksize, while
    also respecting the maximum memory constraint to avoid loading
    to much data into memory at the same time.

    Parameters
    ----------
    src : dask.array.Array
        The source array to resample
    w : int
        New grid width
    h : int
        New grid height
    chunksize : tuple(int, int) (optional)
        Size of the output chunks. By default the chunk size is
        inherited from the *src* array.
    max_mem : int (optional)
        The maximum number of bytes that should be loaded into memory
        during the regridding operation.

    Returns
    -------
    chunksize : tuple(int, int)
        Size of the output chunks.
    """
    start_chunksize = src.chunksize if chunksize is None else chunksize
    if max_mem is None:
        return start_chunksize
    sh, sw = src.shape
    height_fraction = float(sh) / h
    width_fraction = float(sw) / w
    ch, cw = start_chunksize
    dim = True
    nbytes = src.dtype.itemsize
    while ch * height_fraction * (cw * width_fraction) * nbytes > max_mem:
        if dim:
            cw -= 1
        else:
            ch -= 1
        dim = not dim
    if ch == 0 or cw == 0:
        min_mem = height_fraction * width_fraction * nbytes
        raise ValueError(
            'Given the memory constraints the resampling operation could not find a chunksize that avoids loading too much data into memory. Either relax the memory constraint to a minimum of %d bytes or resample to a larger grid size. Note: A future implementation could handle this condition by declaring temporary arrays.'
             % min_mem)
    return ch, cw


def rotate_video(filename, angle):
    """
    Rotates a video by an `angle` using ffmpeg.

    Parameters
    ----------
    - filename : str

        The path to the input video.
    - angle : int or float

        The angle (in degrees) specifying the amount of rotation. Positive values rotate clockwise.

    Outputs
    -------
    - `filename`_rot.avi

        The rotated video file.

    Returns
    -------
    - str

        The path to the output (rotated) video file.
    """
    import os
    import math
    of = os.path.splitext(filename)[0]
    fex = os.path.splitext(filename)[1]
    if os.path.isfile(of + '_rot.avi'):
        os.remove(of + '_rot.avi')
    cmds = ' '.join(['ffmpeg', '-i', filename, '-c:v', 'mjpeg', '-q:v', '3',
        '-vf', f'rotate={math.radians(angle)}', of + '_rot.avi'])
    os.system(cmds)
    return of + '_rot', fex


def _raw_compile(f_code):
    """
    Compile some code for injection into the locals().
    We cheat the systems by giving the f_code as the filename.
    This allows programmers to actually see the autogenerated output instead of just "<string>".

    :param f_code: the code to compile for execution
    :type f_code: str
    :return: the compiled code object
    :rtype: code
    """
    return compile(f_code, '<string>' + f_code, 'exec')


@classmethod
def kwinsert(clas, pool_or_cursor, **kwargs):
    """kwargs version of insert"""
    returning = kwargs.pop('returning', None)
    fields, vals = list(zip(*list(kwargs.items())))
    return clas.insert(pool_or_cursor, fields, vals, returning=returning)


@classmethod
def child(cls, _):
    """This method gets called for |Element| nodes that have
        children. If it is overwritten then it will not traverse
        through child nodes unless you return something other than
        ``None``.

        This method by default returns ``True`` so that the |Writer|
        can traverse through the child nodes. """
    return True


def substitute_variables(command, level, name, value, target=None, **kwargs):
    """Substitute variables in command fragments by values e.g. ${level} => 'warning'."""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {'${level}': str(level), '${target}': str(target),
        '${name}': '"' + str(name) + '"', '${value}': str(value),
        '${limit_value}': str(rule_value)}
    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)
    return result


def salmon_setting(func, key):
    """Simple way to get the salmon setting off the function, or None."""
    return func._salmon_settings.get(key)


@classmethod
def showcase_untrashed_details(cls, val):
    """
        Create an instance of this class set to the
        ``showcase_untrashed_details`` tag with value ``val``.

        :param ShowcaseUntrashedDetails val:
        :rtype: EventDetails
        """
    return cls('showcase_untrashed_details', val)


def WhollyContains(contains, contained):
    """Helper function.

    :param `contains`: the containing shape
    :param `contained`: the contained shape
    :returns: `True` if 'contains' wholly contains 'contained'

    """
    xp1, yp1 = contains.GetX(), contains.GetY()
    xp2, yp2 = contained.GetX(), contained.GetY()
    w1, h1 = contains.GetBoundingBoxMax()
    w2, h2 = contained.GetBoundingBoxMax()
    left1 = xp1 - w1 / 2.0
    top1 = yp1 - h1 / 2.0
    right1 = xp1 + w1 / 2.0
    bottom1 = yp1 + h1 / 2.0
    left2 = xp2 - w2 / 2.0
    top2 = yp2 - h2 / 2.0
    right2 = xp2 + w2 / 2.0
    bottom2 = yp2 + h2 / 2.0
    return (left1 <= left2 and top1 <= top2 and right1 >= right2 and
        bottom1 >= bottom2)


def chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in range(0, len(l), n):
        yield l[i:i + n]


def collection_objects_select():
    """Select all objects in collection

    """
    pass


def zero_region(data, x, y, w, h):
    """Fills a region with zeroes."""
    for by in range(y, y + h):
        line = data[by]
        data[by] = line[:x] + [0] * w + line[x + w:]


def query_dict(data, query_string, ret_default=None):
    """
    Drill down into a dict using dot notation, e.g. query_dict({'this': {'that': 'other'}}, 'this.that'}).
    :param dict data:
    :param str query_string:
    :param ret_default:
    """
    _data = data.copy()
    for q in query_string.split('.'):
        d = _data.get(q)
        if d is not None:
            _data = d
        else:
            return ret_default
    return _data


def choose_stable_variables(stability_scores, bootstrap_threshold=0.5):
    """Returns adjacency matrix corresponding to edges with stability scores above threshold."""
    return (stability_scores.max(axis=0) > bootstrap_threshold).astype('float')


def find_key_case_insensitive(key_name, the_dict):
    """
    Finds if a dictionary (the_dict) has a string key (key_name) in any string case

    Args:
        key_name: the key to search in the dictionary
        the_dict: the dictionary to search

    Returns:
        The found key name in its original case, if found. Otherwise, returns the searching key name

    """
    for key in the_dict:
        if key.lower() == key_name:
            return key
    return key_name


@classmethod
def legal_holds_report_a_hold_details(cls, val):
    """
        Create an instance of this class set to the
        ``legal_holds_report_a_hold_details`` tag with value ``val``.

        :param LegalHoldsReportAHoldDetails val:
        :rtype: EventDetails
        """
    return cls('legal_holds_report_a_hold_details', val)


def render_git_describe(pieces):
    """TAG[-DISTANCE-gHEX][-dirty].

    Like 'git describe --tags --dirty --always'.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance']:
            rendered += '-%d-g%s' % (pieces['distance'], pieces['short'])
    else:
        rendered = pieces['short']
    if pieces['dirty']:
        rendered += '-dirty'
    return rendered


@classmethod
def from_milli_seconds(cls, millis):
    """ Create a duration with the given amount of milli-seconds. """
    return cls.from_seconds(millis * 0.001)


def is_acceptable(word, remove_total):
    """
        Determine if the word is acceptable for stemming.
    """
    word_is_acceptable = False
    if word[0] in 'aeiouy':
        if len(word) - remove_total >= 2:
            word_is_acceptable = True
    elif len(word) - remove_total >= 3:
        if word[1] in 'aeiouy':
            word_is_acceptable = True
        elif word[2] in 'aeiouy':
            word_is_acceptable = True
    return word_is_acceptable


def is_string(val):
    """Determines whether the passed value is a string."""
    return isinstance(val, str)


def view_selected(use_all_regions: bool=False):
    """Move the view to the selection center

    :param use_all_regions: All Regions, View selected for all regions
    :type use_all_regions: bool
    """
    pass


def output2widget(output):
    """Return notebook widget based on output mime-type.
    """
    pass


@staticmethod
def getNodeClass(node_type, platform=None):
    """
        Returns the class corresponding to node type.
        Must be overloaded.

        :param node_type: name of the node
        :param platform: platform (for Dynamips only)

        :returns: class or None
        """
    raise NotImplementedError()


def remove_apostrophe(text):
    """Remove apostrophes from text"""
    return text.replace("'", ' ')


def dms2decimal(dms_str):
    """Convert D500X Degrees-Minuts-Seconds to Decimal Degrees"""
    d, m, s, direction = dms_str.split()
    sign = -1 if direction in ('S', 'W') else 1
    return sign * (int(d) + float(m) / 60 + float(s) / 3600)


@classmethod
def stop_daemon(cls, wait=False):
    """ Stop the watchdog observer thread.

        Args:
            wait (`bool`): whether to wait for the thread to have joined before returning
        """
    cls.observer.unschedule_all()
    if cls.observer.is_alive():
        cls.observer.stop()
    while wait and cls.observer.is_alive():
        cls.observer.join()
    cls.observer = None
    cls.monitor = None


def defaultEventHandler(bot, groupId, creatorId, user, text, dbAction,
    handledByExtension, event):
    """
  default event handler, for event not match any above
  """
    return


def plural(length, label, suffix='s'):
    """Return a label with an optional plural suffix"""
    return '%d %s%s' % (length, label, suffix if length != 1 else '')


@classmethod
def use(cls, server_url, timestamp, salt):
    """Create a Nonce instance"""
    raise NotImplementedError('Implement in subclass')


def unpackRangeBits(ur1, ur2, ur3, ur4):
    """Given the ulUnicodeRange1, ulUnicodeRange2, ulUnicodeRange3,
    ulUnicodeRange4 values from the OS/2 table, return a set of bit numbers.

        >>> unpackRangeBits(0x0, 0x0, 0x0, 0x0)
        set()
        >>> unpackRangeBits(0x1, 0x0, 0x0, 0x0)
        {0}
        >>> unpackRangeBits(0x1, 0x1, 0x1, 0x1)
        {0, 32, 64, 96}
        >>> unpackRangeBits(0xffffffff, 0x1, 0x2, 0x4)
        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 65, 98}
    """
    bitNum = 0
    bitSet = set()
    for bitField in [ur1, ur2, ur3, ur4]:
        for localBitNum in range(32):
            mask = 1 << localBitNum
            if bitField & mask:
                bitSet.add(bitNum)
            bitNum += 1
    assert bitNum == 128
    return bitSet


def to_memberid(email):
    """Translate the email address to a member id, or None"""


def log2(data=None, out=None, name=None, **kwargs):
    """Returns element-wise Base-2 logarithmic value of the input.

    ``2**log2(x) = x``

    The storage type of ``log2`` output is always dense

    Defined in src/operator/tensor/elemwise_unary_op_logexp.cc:L105

    Parameters
    ----------
    data : NDArray
        The input array.

    out : NDArray, optional
        The output NDArray to hold the result.

    Returns
    -------
    out : NDArray or list of NDArrays
        The output of this function.
    """
    return 0,


@staticmethod
def valid_band(freq, low, high):
    """Given an array of frequencies return a boolean array that is True bounded between high and low

        Parameters
        ----------
        freq: np.array like,
              array of frequency values
        low: int,
             lower bound of desired frequency range
        high: int,
              upper bound of desired frequency range

        Returns
        -------
        boolean_array of valid boundaries
        """
    return (freq >= low) & (freq <= high)


def set_onsite(onsite, tags):
    """
    Check method *set_onsite*.
    :raises TypeError: Parameter onsite must be a dictionary.
    :raises ValueError: Parameter onsite keys must be a tag.
    :raises ValueError: Parameter onsite values must be
      real and/or complex numbers.
    """
    if not isinstance(onsite, dict):
        raise TypeError('\n\nParameter onsite must be a dictionary.\n')
    for tag, val in onsite.items():
        if tag not in tags:
            raise ValueError('\n\nParameter onsite keys must be a tag.\n')
        if not isinstance(val, (int, float, complex)):
            raise ValueError(
                '\n\nParameter onsite values must be\nreal and/or complex numbers.\n'
                )


def respond_decision_task_completed(taskToken=None, decisions=None,
    executionContext=None):
    """
    Used by deciders to tell the service that the  DecisionTask identified by the taskToken has successfully completed. The decisions argument specifies the list of decisions made while processing the task.
    A DecisionTaskCompleted event is added to the workflow history. The executionContext specified is attached to the event in the workflow execution history.
    Access Control
    If an IAM policy grants permission to use RespondDecisionTaskCompleted , it can express permissions for the list of decisions in the decisions parameter. Each of the decisions has one or more parameters, much like a regular API call. To allow for policies to be as readable as possible, you can express permissions on decisions as if they were actual API calls, including applying conditions to some parameters. For more information, see Using IAM to Manage Access to Amazon SWF Workflows .
    See also: AWS API Documentation

    :example: response = client.respond_decision_task_completed(
        taskToken='string',
        decisions=[
            {
                'decisionType': 'ScheduleActivityTask'|'RequestCancelActivityTask'|'CompleteWorkflowExecution'|'FailWorkflowExecution'|'CancelWorkflowExecution'|'ContinueAsNewWorkflowExecution'|'RecordMarker'|'StartTimer'|'CancelTimer'|'SignalExternalWorkflowExecution'|'RequestCancelExternalWorkflowExecution'|'StartChildWorkflowExecution'|'ScheduleLambdaFunction',
                'scheduleActivityTaskDecisionAttributes': {
                    'activityType': {
                        'name': 'string',
                        'version': 'string'
                    },
                    'activityId': 'string',
                    'control': 'string',
                    'input': 'string',
                    'scheduleToCloseTimeout': 'string',
                    'taskList': {
                        'name': 'string'
                    },
                    'taskPriority': 'string',
                    'scheduleToStartTimeout': 'string',
                    'startToCloseTimeout': 'string',
                    'heartbeatTimeout': 'string'
                },
                'requestCancelActivityTaskDecisionAttributes': {
                    'activityId': 'string'
                },
                'completeWorkflowExecutionDecisionAttributes': {
                    'result': 'string'
                },
                'failWorkflowExecutionDecisionAttributes': {
                    'reason': 'string',
                    'details': 'string'
                },
                'cancelWorkflowExecutionDecisionAttributes': {
                    'details': 'string'
                },
                'continueAsNewWorkflowExecutionDecisionAttributes': {
                    'input': 'string',
                    'executionStartToCloseTimeout': 'string',
                    'taskList': {
                        'name': 'string'
                    },
                    'taskPriority': 'string',
                    'taskStartToCloseTimeout': 'string',
                    'childPolicy': 'TERMINATE'|'REQUEST_CANCEL'|'ABANDON',
                    'tagList': [
                        'string',
                    ],
                    'workflowTypeVersion': 'string',
                    'lambdaRole': 'string'
                },
                'recordMarkerDecisionAttributes': {
                    'markerName': 'string',
                    'details': 'string'
                },
                'startTimerDecisionAttributes': {
                    'timerId': 'string',
                    'control': 'string',
                    'startToFireTimeout': 'string'
                },
                'cancelTimerDecisionAttributes': {
                    'timerId': 'string'
                },
                'signalExternalWorkflowExecutionDecisionAttributes': {
                    'workflowId': 'string',
                    'runId': 'string',
                    'signalName': 'string',
                    'input': 'string',
                    'control': 'string'
                },
                'requestCancelExternalWorkflowExecutionDecisionAttributes': {
                    'workflowId': 'string',
                    'runId': 'string',
                    'control': 'string'
                },
                'startChildWorkflowExecutionDecisionAttributes': {
                    'workflowType': {
                        'name': 'string',
                        'version': 'string'
                    },
                    'workflowId': 'string',
                    'control': 'string',
                    'input': 'string',
                    'executionStartToCloseTimeout': 'string',
                    'taskList': {
                        'name': 'string'
                    },
                    'taskPriority': 'string',
                    'taskStartToCloseTimeout': 'string',
                    'childPolicy': 'TERMINATE'|'REQUEST_CANCEL'|'ABANDON',
                    'tagList': [
                        'string',
                    ],
                    'lambdaRole': 'string'
                },
                'scheduleLambdaFunctionDecisionAttributes': {
                    'id': 'string',
                    'name': 'string',
                    'input': 'string',
                    'startToCloseTimeout': 'string'
                }
            },
        ],
        executionContext='string'
    )

    :type taskToken: string
    :param taskToken: [REQUIRED]
            The taskToken from the DecisionTask .
            Warning
            taskToken is generated by the service and should be treated as an opaque value. If the task is passed to another process, its taskToken must also be passed. This enables it to provide its progress and respond with results.

    :type decisions: list
    :param decisions: The list of decisions (possibly empty) made by the decider while processing this decision task. See the docs for the decision structure for details.
            (dict) --Specifies a decision made by the decider. A decision can be one of these types:
            CancelTimer : cancels a previously started timer and records a TimerCanceled event in the history.
            CancelWorkflowExecution : closes the workflow execution and records a WorkflowExecutionCanceled event in the history.
            CompleteWorkflowExecution : closes the workflow execution and records a WorkflowExecutionCompleted event in the history .
            ContinueAsNewWorkflowExecution : closes the workflow execution and starts a new workflow execution of the same type using the same workflow ID and a unique run ID. A WorkflowExecutionContinuedAsNew event is recorded in the history.
            FailWorkflowExecution : closes the workflow execution and records a WorkflowExecutionFailed event in the history.
            RecordMarker : records a MarkerRecorded event in the history. Markers can be used for adding custom information in the history for instance to let deciders know that they do not need to look at the history beyond the marker event.
            RequestCancelActivityTask : attempts to cancel a previously scheduled activity task. If the activity task was scheduled but has not been assigned to a worker, then it will be canceled. If the activity task was already assigned to a worker, then the worker will be informed that cancellation has been requested in the response to RecordActivityTaskHeartbeat .
            RequestCancelExternalWorkflowExecution : requests that a request be made to cancel the specified external workflow execution and records a RequestCancelExternalWorkflowExecutionInitiated event in the history.
            ScheduleActivityTask : schedules an activity task.
            ScheduleLambdaFunction : schedules a AWS Lambda function.
            SignalExternalWorkflowExecution : requests a signal to be delivered to the specified external workflow execution and records a SignalExternalWorkflowExecutionInitiated event in the history.
            StartChildWorkflowExecution : requests that a child workflow execution be started and records a StartChildWorkflowExecutionInitiated event in the history. The child workflow execution is a separate workflow execution with its own history.
            StartTimer : starts a timer for this workflow execution and records a TimerStarted event in the history. This timer will fire after the specified delay and record a TimerFired event.
            Access Control
            If you grant permission to use RespondDecisionTaskCompleted , you can use IAM policies to express permissions for the list of decisions returned by this action as if they were members of the API. Treating decisions as a pseudo API maintains a uniform conceptual model and helps keep policies readable. For details and example IAM policies, see Using IAM to Manage Access to Amazon SWF Workflows .
            Decision Failure
            Decisions can fail for several reasons
            The ordering of decisions should follow a logical flow. Some decisions might not make sense in the current context of the workflow execution and will therefore fail.
            A limit on your account was reached.
            The decision lacks sufficient permissions.
            One of the following events might be added to the history to indicate an error. The event attribute's cause parameter indicates the cause. If cause is set to OPERATION_NOT_PERMITTED, the decision failed because it lacked sufficient permissions. For details and example IAM policies, see Using IAM to Manage Access to Amazon SWF Workflows .
            ScheduleActivityTaskFailed : a ScheduleActivityTask decision failed. This could happen if the activity type specified in the decision is not registered, is in a deprecated state, or the decision is not properly configured.
            ScheduleLambdaFunctionFailed : a ScheduleLambdaFunctionFailed decision failed. This could happen if the AWS Lambda function specified in the decision does not exist, or the AWS Lambda service's limits are exceeded.
            RequestCancelActivityTaskFailed : a RequestCancelActivityTask decision failed. This could happen if there is no open activity task with the specified activityId.
            StartTimerFailed : a StartTimer decision failed. This could happen if there is another open timer with the same timerId.
            CancelTimerFailed : a CancelTimer decision failed. This could happen if there is no open timer with the specified timerId.
            StartChildWorkflowExecutionFailed : a StartChildWorkflowExecution decision failed. This could happen if the workflow type specified is not registered, is deprecated, or the decision is not properly configured.
            SignalExternalWorkflowExecutionFailed : a SignalExternalWorkflowExecution decision failed. This could happen if the workflowID specified in the decision was incorrect.
            RequestCancelExternalWorkflowExecutionFailed : a RequestCancelExternalWorkflowExecution decision failed. This could happen if the workflowID specified in the decision was incorrect.
            CancelWorkflowExecutionFailed : a CancelWorkflowExecution decision failed. This could happen if there is an unhandled decision task pending in the workflow execution.
            CompleteWorkflowExecutionFailed : a CompleteWorkflowExecution decision failed. This could happen if there is an unhandled decision task pending in the workflow execution.
            ContinueAsNewWorkflowExecutionFailed : a ContinueAsNewWorkflowExecution decision failed. This could happen if there is an unhandled decision task pending in the workflow execution or the ContinueAsNewWorkflowExecution decision was not configured correctly.
            FailWorkflowExecutionFailed : a FailWorkflowExecution decision failed. This could happen if there is an unhandled decision task pending in the workflow execution.
            The preceding error events might occur due to an error in the decider logic, which might put the workflow execution in an unstable state The cause field in the event structure for the error event indicates the cause of the error.
            Note
            A workflow execution may be closed by the decider by returning one of the following decisions when completing a decision task: CompleteWorkflowExecution , FailWorkflowExecution , CancelWorkflowExecution and ContinueAsNewWorkflowExecution . An UnhandledDecision fault will be returned if a workflow closing decision is specified and a signal or activity event had been added to the history while the decision task was being performed by the decider. Unlike the above situations which are logic issues, this fault is always possible because of race conditions in a distributed system. The right action here is to call RespondDecisionTaskCompleted without any decisions. This would result in another decision task with these new events included in the history. The decider should handle the new events and may decide to close the workflow execution.
            How to code a decision
            You code a decision by first setting the decision type field to one of the above decision values, and then set the corresponding attributes field shown below:
            ScheduleActivityTaskDecisionAttributes
            ScheduleLambdaFunctionDecisionAttributes
            RequestCancelActivityTaskDecisionAttributes
            CompleteWorkflowExecutionDecisionAttributes
            FailWorkflowExecutionDecisionAttributes
            CancelWorkflowExecutionDecisionAttributes
            ContinueAsNewWorkflowExecutionDecisionAttributes
            RecordMarkerDecisionAttributes
            StartTimerDecisionAttributes
            CancelTimerDecisionAttributes
            SignalExternalWorkflowExecutionDecisionAttributes
            RequestCancelExternalWorkflowExecutionDecisionAttributes
            StartChildWorkflowExecutionDecisionAttributes
            decisionType (string) -- [REQUIRED]Specifies the type of the decision.
            scheduleActivityTaskDecisionAttributes (dict) --Provides details of the ScheduleActivityTask decision. It is not set for other decision types.
            activityType (dict) -- [REQUIRED]Required. The type of the activity task to schedule.
            name (string) -- [REQUIRED]The name of this activity.
            Note
            The combination of activity type name and version must be unique within a domain.
            version (string) -- [REQUIRED]The version of this activity.
            Note
            The combination of activity type name and version must be unique with in a domain.

            activityId (string) -- [REQUIRED]Required. The activityId of the activity task.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            control (string) --Optional. Data attached to the event that can be used by the decider in subsequent workflow tasks. This data is not sent to the activity.
            input (string) --The input provided to the activity task.
            scheduleToCloseTimeout (string) --The maximum duration for this activity task.
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            A schedule-to-close timeout for this activity task must be specified either as a default for the activity type or through this field. If neither this field is set nor a default schedule-to-close timeout was specified at registration time then a fault will be returned.
            taskList (dict) --If set, specifies the name of the task list in which to schedule the activity task. If not specified, the defaultTaskList registered with the activity type will be used.
            Note
            A task list for this activity task must be specified either as a default for the activity type or through this field. If neither this field is set nor a default task list was specified at registration time then a fault will be returned.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            name (string) -- [REQUIRED]The name of the task list.
            taskPriority (string) --Optional. If set, specifies the priority with which the activity task is to be assigned to a worker. This overrides the defaultTaskPriority specified when registering the activity type using RegisterActivityType . Valid values are integers that range from Java's Integer.MIN_VALUE (-2147483648) to Integer.MAX_VALUE (2147483647). Higher numbers indicate higher priority.
            For more information about setting task priority, see Setting Task Priority in the Amazon Simple Workflow Developer Guide .
            scheduleToStartTimeout (string) --Optional. If set, specifies the maximum duration the activity task can wait to be assigned to a worker. This overrides the default schedule-to-start timeout specified when registering the activity type using RegisterActivityType .
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            A schedule-to-start timeout for this activity task must be specified either as a default for the activity type or through this field. If neither this field is set nor a default schedule-to-start timeout was specified at registration time then a fault will be returned.
            startToCloseTimeout (string) --If set, specifies the maximum duration a worker may take to process this activity task. This overrides the default start-to-close timeout specified when registering the activity type using RegisterActivityType .
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            A start-to-close timeout for this activity task must be specified either as a default for the activity type or through this field. If neither this field is set nor a default start-to-close timeout was specified at registration time then a fault will be returned.
            heartbeatTimeout (string) --If set, specifies the maximum time before which a worker processing a task of this type must report progress by calling RecordActivityTaskHeartbeat . If the timeout is exceeded, the activity task is automatically timed out. If the worker subsequently attempts to record a heartbeat or returns a result, it will be ignored. This overrides the default heartbeat timeout specified when registering the activity type using RegisterActivityType .
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            requestCancelActivityTaskDecisionAttributes (dict) --Provides details of the RequestCancelActivityTask decision. It is not set for other decision types.
            activityId (string) -- [REQUIRED]The activityId of the activity task to be canceled.
            completeWorkflowExecutionDecisionAttributes (dict) --Provides details of the CompleteWorkflowExecution decision. It is not set for other decision types.
            result (string) --The result of the workflow execution. The form of the result is implementation defined.
            failWorkflowExecutionDecisionAttributes (dict) --Provides details of the FailWorkflowExecution decision. It is not set for other decision types.
            reason (string) --A descriptive reason for the failure that may help in diagnostics.
            details (string) --Optional. Details of the failure.
            cancelWorkflowExecutionDecisionAttributes (dict) --Provides details of the CancelWorkflowExecution decision. It is not set for other decision types.
            details (string) --Optional. details of the cancellation.
            continueAsNewWorkflowExecutionDecisionAttributes (dict) --Provides details of the ContinueAsNewWorkflowExecution decision. It is not set for other decision types.
            input (string) --The input provided to the new workflow execution.
            executionStartToCloseTimeout (string) --If set, specifies the total duration for this workflow execution. This overrides the defaultExecutionStartToCloseTimeout specified when registering the workflow type.
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            An execution start-to-close timeout for this workflow execution must be specified either as a default for the workflow type or through this field. If neither this field is set nor a default execution start-to-close timeout was specified at registration time then a fault will be returned.
            taskList (dict) --Represents a task list.
            name (string) -- [REQUIRED]The name of the task list.
            taskPriority (string) --Optional. The task priority that, if set, specifies the priority for the decision tasks for this workflow execution. This overrides the defaultTaskPriority specified when registering the workflow type. Valid values are integers that range from Java's Integer.MIN_VALUE (-2147483648) to Integer.MAX_VALUE (2147483647). Higher numbers indicate higher priority.
            For more information about setting task priority, see Setting Task Priority in the Amazon Simple Workflow Developer Guide .
            taskStartToCloseTimeout (string) --Specifies the maximum duration of decision tasks for the new workflow execution. This parameter overrides the defaultTaskStartToCloseTimout specified when registering the workflow type using RegisterWorkflowType .
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            A task start-to-close timeout for the new workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default task start-to-close timeout was specified at registration time then a fault will be returned.
            childPolicy (string) --If set, specifies the policy to use for the child workflow executions of the new execution if it is terminated by calling the TerminateWorkflowExecution action explicitly or due to an expired timeout. This policy overrides the default child policy specified when registering the workflow type using RegisterWorkflowType .
            The supported child policies are:
            TERMINATE: the child executions will be terminated.
            REQUEST_CANCEL: a request to cancel will be attempted for each child execution by recording a WorkflowExecutionCancelRequested event in its history. It is up to the decider to take appropriate actions when it receives an execution history with this event.
            ABANDON: no action will be taken. The child executions will continue to run.
            Note
            A child policy for this workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default child policy was specified at registration time then a fault will be returned.
            tagList (list) --The list of tags to associate with the new workflow execution. A maximum of 5 tags can be specified. You can list workflow executions with a specific tag by calling ListOpenWorkflowExecutions or ListClosedWorkflowExecutions and specifying a TagFilter .
            (string) --
            workflowTypeVersion (string) --
            lambdaRole (string) --The ARN of an IAM role that authorizes Amazon SWF to invoke AWS Lambda functions.
            Note
            In order for this workflow execution to invoke AWS Lambda functions, an appropriate IAM role must be specified either as a default for the workflow type or through this field.

            recordMarkerDecisionAttributes (dict) --Provides details of the RecordMarker decision. It is not set for other decision types.
            markerName (string) -- [REQUIRED]Required. The name of the marker.
            details (string) --Optional. details of the marker.
            startTimerDecisionAttributes (dict) --Provides details of the StartTimer decision. It is not set for other decision types.
            timerId (string) -- [REQUIRED]Required. The unique ID of the timer.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            control (string) --Optional. Data attached to the event that can be used by the decider in subsequent workflow tasks.
            startToFireTimeout (string) -- [REQUIRED]Required. The duration to wait before firing the timer.
            The duration is specified in seconds; an integer greater than or equal to 0.
            cancelTimerDecisionAttributes (dict) --Provides details of the CancelTimer decision. It is not set for other decision types.
            timerId (string) -- [REQUIRED]Required. The unique ID of the timer to cancel.
            signalExternalWorkflowExecutionDecisionAttributes (dict) --Provides details of the SignalExternalWorkflowExecution decision. It is not set for other decision types.
            workflowId (string) -- [REQUIRED]Required. The workflowId of the workflow execution to be signaled.
            runId (string) --The runId of the workflow execution to be signaled.
            signalName (string) -- [REQUIRED]Required. The name of the signal.The target workflow execution will use the signal name and input to process the signal.
            input (string) --Optional. Input data to be provided with the signal. The target workflow execution will use the signal name and input data to process the signal.
            control (string) --Optional. Data attached to the event that can be used by the decider in subsequent decision tasks.
            requestCancelExternalWorkflowExecutionDecisionAttributes (dict) --Provides details of the RequestCancelExternalWorkflowExecution decision. It is not set for other decision types.
            workflowId (string) -- [REQUIRED]Required. The workflowId of the external workflow execution to cancel.
            runId (string) --The runId of the external workflow execution to cancel.
            control (string) --Optional. Data attached to the event that can be used by the decider in subsequent workflow tasks.
            startChildWorkflowExecutionDecisionAttributes (dict) --Provides details of the StartChildWorkflowExecution decision. It is not set for other decision types.
            workflowType (dict) -- [REQUIRED]Required. The type of the workflow execution to be started.
            name (string) -- [REQUIRED]Required. The name of the workflow type.
            Note
            The combination of workflow type name and version must be unique with in a domain.
            version (string) -- [REQUIRED]Required. The version of the workflow type.
            Note
            The combination of workflow type name and version must be unique with in a domain.

            workflowId (string) -- [REQUIRED]Required. The workflowId of the workflow execution.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            control (string) --Optional. Data attached to the event that can be used by the decider in subsequent workflow tasks. This data is not sent to the child workflow execution.
            input (string) --The input to be provided to the workflow execution.
            executionStartToCloseTimeout (string) --The total duration for this workflow execution. This overrides the defaultExecutionStartToCloseTimeout specified when registering the workflow type.
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            An execution start-to-close timeout for this workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default execution start-to-close timeout was specified at registration time then a fault will be returned.
            taskList (dict) --The name of the task list to be used for decision tasks of the child workflow execution.
            Note
            A task list for this workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default task list was specified at registration time then a fault will be returned.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            name (string) -- [REQUIRED]The name of the task list.
            taskPriority (string) --Optional. A task priority that, if set, specifies the priority for a decision task of this workflow execution. This overrides the defaultTaskPriority specified when registering the workflow type. Valid values are integers that range from Java's Integer.MIN_VALUE (-2147483648) to Integer.MAX_VALUE (2147483647). Higher numbers indicate higher priority.
            For more information about setting task priority, see Setting Task Priority in the Amazon Simple Workflow Developer Guide .
            taskStartToCloseTimeout (string) --Specifies the maximum duration of decision tasks for this workflow execution. This parameter overrides the defaultTaskStartToCloseTimout specified when registering the workflow type using RegisterWorkflowType .
            The duration is specified in seconds; an integer greater than or equal to 0. The value 'NONE' can be used to specify unlimited duration.
            Note
            A task start-to-close timeout for this workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default task start-to-close timeout was specified at registration time then a fault will be returned.
            childPolicy (string) --Optional. If set, specifies the policy to use for the child workflow executions if the workflow execution being started is terminated by calling the TerminateWorkflowExecution action explicitly or due to an expired timeout. This policy overrides the default child policy specified when registering the workflow type using RegisterWorkflowType .
            The supported child policies are:
            TERMINATE: the child executions will be terminated.
            REQUEST_CANCEL: a request to cancel will be attempted for each child execution by recording a WorkflowExecutionCancelRequested event in its history. It is up to the decider to take appropriate actions when it receives an execution history with this event.
            ABANDON: no action will be taken. The child executions will continue to run.
            Note
            A child policy for this workflow execution must be specified either as a default for the workflow type or through this parameter. If neither this parameter is set nor a default child policy was specified at registration time then a fault will be returned.
            tagList (list) --The list of tags to associate with the child workflow execution. A maximum of 5 tags can be specified. You can list workflow executions with a specific tag by calling ListOpenWorkflowExecutions or ListClosedWorkflowExecutions and specifying a TagFilter .
            (string) --
            lambdaRole (string) --The ARN of an IAM role that authorizes Amazon SWF to invoke AWS Lambda functions.
            Note
            In order for this workflow execution to invoke AWS Lambda functions, an appropriate IAM role must be specified either as a default for the workflow type or through this field.

            scheduleLambdaFunctionDecisionAttributes (dict) --Provides details of the ScheduleLambdaFunction decision.
            Access Control
            You can use IAM policies to control this decision's access to Amazon SWF resources as follows:
            Use a Resource element with the domain name to limit the action to only specified domains.
            Use an Action element to allow or deny permission to call this action.
            Constrain the following parameters by using a Condition element with the appropriate keys.
            activityType.name : String constraint. The key is swf:activityType.name .
            activityType.version : String constraint. The key is swf:activityType.version .
            taskList : String constraint. The key is swf:taskList.name .
            If the caller does not have sufficient permissions to invoke the action, or the parameter values fall outside the specified constraints, the action fails. The associated event attribute's cause parameter will be set to OPERATION_NOT_PERMITTED. For details and example IAM policies, see Using IAM to Manage Access to Amazon SWF Workflows .
            id (string) -- [REQUIRED]Required. The SWF id of the AWS Lambda task.
            The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (u0000-u001f | u007f - u009f). Also, it must not contain the literal string quotarnquot.
            name (string) -- [REQUIRED]Required. The name of the AWS Lambda function to invoke.
            input (string) --The input provided to the AWS Lambda function.
            startToCloseTimeout (string) --If set, specifies the maximum duration the function may take to execute.

    :type executionContext: string
    :param executionContext: User defined context to add to workflow execution.

    """
    pass


def dists_per_taxon(means_tuple_list):
    """Get mean pairwise distances for taxon in alignment.

    Given tuple list [(alignment name, {taxon : mean distance within alignment})]
    return dict of {taxon : (alignment name, mean distance within alignment)}.
    """
    taxa_dists = {}
    for aln_name, dist_dict in sorted(means_tuple_list):
        for sp, mean_dist in dist_dict.items():
            if sp not in taxa_dists.keys():
                taxa_dists[sp] = [(aln_name, mean_dist)]
            else:
                taxa_dists[sp].append((aln_name, mean_dist))
    return taxa_dists


def CONCAT(*expressions):
    """
    Concatenates strings and returns the concatenated string.
    https://docs.mongodb.com/manual/reference/operator/aggregation/concat/
    for more details
    :param expressions: The list of strings (variables or expressions)
    :return: Aggregation operator
    """
    return {'$concat': list(expressions)}


def update(collection):
    """Add the items from the given collection object to the collection.

        The input collection must be a sequence of (key, value) 2-tuples,
        or an object with an 'items' method that returns a sequence of
        (key, value) pairs.
        """


def binary_to_decimal(number):
    """
        This function calculates the decimal of the given binary number
        :param number: decimal number in string or integer format
        :return : integer of the equivalent decimal number

        Algo:
        1. Get the last digit of the binary number.
        2. Multiply the current digit with (2^power), store the result.
        3. Increment power by 1.
        4. Repeat from step 2 until all digits have been multiplied.
        5. Sum the result of step 2 to get the answer number.
    """
    decimal = []
    number = list(str(number)[::-1])
    for i in range(len(number)):
        decimal.append(int(number[i]) * 2 ** i)
    return sum(decimal)


@classmethod
def factory(cls, global_config, **local_config):
    """Used for paste app factories in paste.deploy config files.

        Any local configuration (that is, values under the [app:APPNAME]
        section of the paste config) will be passed into the `__init__` method
        as kwargs.

        A hypothetical configuration would look like:

            [app:wadl]
            latest_version = 1.3
            paste.app_factory = nova.api.fancy_api:Wadl.factory

        which would result in a call to the `Wadl` class as

            import tacker.api.fancy_api
            fancy_api.Wadl(latest_version='1.3')

        You could of course re-implement the `factory` method in subclasses,
        but using the kwarg passing it shouldn't be necessary.

        """
    return cls(**local_config)


def split_remote_fileid(remote_file_id):
    """
    Splite remote_file_id to (group_name, remote_file_name)
    arguments:
    @remote_file_id: string
    @return tuple, (group_name, remote_file_name)
    """
    index = remote_file_id.find('/')
    if -1 == index:
        return None
    return remote_file_id[0:index], remote_file_id[index + 1:]


def _addfont(name, bold, italic, font, fontdict):
    """insert a font and style into the font dictionary"""
    if name not in fontdict:
        fontdict[name] = {}
    fontdict[name][bold, italic] = font


def skeleton_df_to_swc(df, export_path=None):
    """
    Convert a skeleton DataFrame into a the text of an SWC file.

    Args:
        df:
            DataFrame, as returned by :py:meth:`.Client.fetch_skeleton()`

        export_path:
            Optional. Write the SWC file to disk a the given location.

    Returns:
        string
    """
    df['node_type'] = 0
    df = df[['rowId', 'node_type', 'x', 'y', 'z', 'radius', 'link']]
    swc = '# '
    swc += df.to_csv(sep=' ', header=True, index=False)
    if export_path:
        with open(export_path, 'w') as f:
            f.write(swc)
    return swc


@classmethod
def convert(cls, value):
    """
        Converts the given value to the enum value

        Returns:
            the enum for the given value
        Raises:
            ValueError: the enum value does not exist in the enum
        """
    value = str(value)
    try:
        return cls._registered[value]
    except KeyError:
        raise ValueError('Invalid value for {}: {}'.format(cls.__name__, value)
            )


def build_url_from_settings(settings):
    """Constructs web socket urls from settings"""
    is_secure = settings.TELEGRAPHY_IS_SECURE
    proto = 'wss' if is_secure else 'ws'
    url_parts = [proto, '://', settings.TELEGRAPHY_WS_HOST or 'localhost',
        ':', str(settings.TELEGRAPHY_WS_PORT), '/', settings.
        TELEGRAPHY_WS_URI or '']
    return ''.join(url_parts)


@classmethod
def has_key(cls, key):
    """Check if the key is defined in the enum."""
    return key in cls.__members__


def p_quantifier_once_or_more(p):
    """quantifier : K_ONCE K_OR K_MORE"""
    p[0] = [('once_or_more', ())]


def _py_pytype(parameter):
    """Returns the name of the *python* type for the fortran parameter.
    """
    pytype = parameter.pytype
    if pytype is None:
        raise ValueError("Can't pre-determine type for parameter: {}".
            format(parameter.definition()))
    return pytype


@classmethod
def get_url(cls, participant_code, name_in_url, page_index):
    """need this because reverse() is too slow in create_session"""
    return '/p/{pcode}/{name_in_url}/{ClassName}/{page_index}/'.format(pcode
        =participant_code, name_in_url=name_in_url, ClassName=cls.__name__,
        page_index=page_index)


def change_path_for_metric(path):
    """
    Replace the '/' in the metric path by '_' so grafana can correctly use it.
    :param path: path of the metric (example: runs/search)
    :return: path with '_' instead of '/'
    """
    if 'mlflow/' in path:
        path = path.split('mlflow/')[-1]
    return path.replace('/', '_')


@classmethod
def _from_dict(cls, _dict):
    """Initialize a ErrorInfo object from a json dictionary."""
    args = {}
    if 'code' in _dict:
        args['code'] = _dict.get('code')
    else:
        raise ValueError(
            "Required property 'code' not present in ErrorInfo JSON")
    if 'description' in _dict:
        args['description'] = _dict.get('description')
    else:
        raise ValueError(
            "Required property 'description' not present in ErrorInfo JSON")
    if 'error_id' in _dict:
        args['error_id'] = _dict.get('error_id')
    else:
        raise ValueError(
            "Required property 'error_id' not present in ErrorInfo JSON")
    return cls(**args)


@staticmethod
def validate_properties(properties):
    """Validate properties for the resource.

        Validates to ensure nothing in value_specs overwrites any key that
        exists in the schema.

        Also ensures that shared and tenant_id is not specified
        in value_specs.
        """
    if 'value_specs' in properties:
        banned_keys = set(['shared', 'tenant_id']).union(set(properties))
        found = banned_keys.intersection(set(properties['value_specs']))
        if found:
            return '%s not allowed in value_specs' % ', '.join(found)


@classmethod
def has_feature(cls, feature: int) ->bool:
    """Test whether the flash device supports a feature.

           :param feature: the feature to test
           :return: True if the feature is supported, False otherwise
        """
    raise NotImplementedError()


def generate_presigned_url(ClientMethod=None, Params=None, ExpiresIn=None,
    HttpMethod=None):
    """
    Generate a presigned url given a client, its method, and arguments

    :type ClientMethod: string
    :param ClientMethod: The client method to presign for

    :type Params: dict
    :param Params: The parameters normally passed to
            ClientMethod.

    :type ExpiresIn: int
    :param ExpiresIn: The number of seconds the presigned url is valid
            for. By default it expires in an hour (3600 seconds)

    :type HttpMethod: string
    :param HttpMethod: The http method to use on the generated url. By
            default, the http method is whatever is used in the method's model.

    """
    pass


def binom(n, k):
    """
    Returns binomial coefficient (n choose k).
    """
    if k > n:
        return 0
    if k == 0:
        return 1
    result = 1
    for denom in range(1, k + 1):
        result *= n
        result /= denom
        n -= 1
    return result


@staticmethod
def _get_crop_offset_size(axis, points, factor):
    """Get offset and size of cropped image"""
    offset = round(points.min(axis=1)[axis] / factor)
    size = round((points.max(axis=1)[axis] - offset) / factor)
    return offset, size


def sample_approx(approx, draws=100, include_transformed=True):
    """Draw samples from variational posterior.

    Parameters
    ----------
    approx : :class:`Approximation`
        Approximation to sample from
    draws : `int`
        Number of random samples.
    include_transformed : `bool`
        If True, transformed variables are also sampled. Default is True.

    Returns
    -------
    trace : class:`pymc3.backends.base.MultiTrace`
        Samples drawn from variational posterior.
    """
    return approx.sample(draws=draws, include_transformed=include_transformed)


@staticmethod
def apply_required_default(items, default):
    """Apply default value to first element of item if it's None.

        :argument items: List of tuples
        :type items: iterable
        :argument default: Value to use if none provided
        :type default: boolean

        :returns: List of tuples, with required default value applied
        :rtype: iterable of tuple

        >>> list(
        ...   OptionalPartList.apply_required_default(
        ...     [
        ...       ('<provided>', '<1>'),
        ...       (None, '<2>')
        ...     ],
        ...     default='<default>'
        ...   )
        ... )
        [('<provided>', '<1>'), ('<default>', '<2>')]

        """
    for required, args in items:
        if required is None:
            required = default
        yield required, args


def _write_points(f, points, float_fmt):
    """
    Write points coordinates.
    """
    for i, point in enumerate(points):
        fmt = 'G\t{:8}\t' + '\t'.join(3 * ['{:' + float_fmt + '}']) + '\n'
        f.write(fmt.format(i + 1, *point))


def find_participation_daterange(trips, min_dt):
    """
    Determine the time bounds for selecting user trips to remove any trips
    with inproper timestamps from a user's incorrect system clock.
    """
    first_date, last_date = None, None
    for trip in trips:
        if trip.start_local > min_dt:
            first_date = trip.start_local.date()
            break
    last_date = trips[-1].end_local.date()
    return first_date, last_date


@classmethod
def _from_dict(cls, _dict):
    """Initialize a DialogNodeAction object from a json dictionary."""
    args = {}
    if 'name' in _dict:
        args['name'] = _dict.get('name')
    else:
        raise ValueError(
            "Required property 'name' not present in DialogNodeAction JSON")
    if 'type' in _dict or 'action_type' in _dict:
        args['action_type'] = _dict.get('type') or _dict.get('action_type')
    if 'parameters' in _dict:
        args['parameters'] = _dict.get('parameters')
    if 'result_variable' in _dict:
        args['result_variable'] = _dict.get('result_variable')
    else:
        raise ValueError(
            "Required property 'result_variable' not present in DialogNodeAction JSON"
            )
    if 'credentials' in _dict:
        args['credentials'] = _dict.get('credentials')
    return cls(**args)


def isascii(s):
    """Returns True if str s is entirely ASCII characters.

    (Compare to Python 3.7 `str.isascii()`.)
    """
    try:
        s.encode('ascii')
    except UnicodeEncodeError:
        return False
    return True


def calculate_wheel_power(velocities, accelerations, road_loads, vehicle_mass):
    """
    Calculates the wheel power [kW].

    :param velocities:
        Velocity [km/h].
    :type velocities: numpy.array | float

    :param accelerations:
        Acceleration [m/s2].
    :type accelerations: numpy.array | float

    :param road_loads:
        Cycle road loads [N, N/(km/h), N/(km/h)^2].
    :type road_loads: list, tuple

    :param vehicle_mass:
        Vehicle mass [kg].
    :type vehicle_mass: float

    :return:
        Power at wheels [kW].
    :rtype: numpy.array | float
    """
    f0, f1, f2 = road_loads
    quadratic_term = f0 + (f1 + f2 * velocities) * velocities
    vel = velocities / 3600
    return (quadratic_term + 1.03 * vehicle_mass * accelerations) * vel


@classmethod
def load(cls, file_name):
    """ Load a file into a new Data instance storing configuration in a JSON format """
    return cls.open(file_name)


@classmethod
def load_cookie(cls, request, key='session', secret_key=None):
    """Loads a :class:`SecureCookie` from a cookie in request.  If the
        cookie is not set, a new :class:`SecureCookie` instanced is
        returned.

        :param request: a request object that has a `cookies` attribute
                        which is a dict of all cookie values.
        :param key: the name of the cookie.
        :param secret_key: the secret key used to unquote the cookie.
                           Always provide the value even though it has
                           no default!
        """
    data = request.cookies.get(key)
    if not data:
        return cls(secret_key=secret_key)
    return cls.unserialize(data, secret_key)


def get_nm(delta):
    """
    Returns size in [nm] corresponding for the provided delta in degrees
    for 1.5307 [A] wavelength (common approximate formula is lambda [nm] / delta [rad] for small angles).
    """
    return 8.77 / delta


@classmethod
def get_name(cls):
    """ Returns the name of the supplier.
		"""
    return 'numpy_dict'


def setTracebackClearing(clear=True):
    """
    Enable or disable traceback clearing.
    By default, clearing is disabled and Python will indefinitely store unhandled exception stack traces.
    This function is provided since Python's default behavior can cause unexpected retention of
    large memory-consuming objects.
    """
    global clear_tracebacks
    clear_tracebacks = clear


def split_refs(text):
    """Split text with embedded references into a sequence of text
    and references.

    Reference is returned as tuple (id, name).

    :returns: iterator over pieces of text and references.
    """
    while True:
        pos = text.find('\x01')
        if pos < 0:
            if text:
                yield text
            break
        else:
            if pos > 0:
                yield text[:pos]
            text = text[pos + 1:]
            pos = text.find('\x03')
            ref_text = text[:pos]
            text = text[pos + 1:]
            ref, _, name = ref_text.partition('\x02')
            yield ref, name


def _augment_exception(exc, version, arch=''):
    """
    Add details to the exception message to help guide the user
    as to what action will resolve it.
    """
    message = exc.args[0]
    if 'vcvarsall' in message.lower() or 'visual c' in message.lower():
        tmpl = 'Microsoft Visual C++ {version:0.1f} is required.'
        message = tmpl.format(**locals())
        msdownload = 'www.microsoft.com/download/details.aspx?id=%d'
        if version == 9.0:
            if arch.lower().find('ia64') > -1:
                message += ' Get it with "Microsoft Windows SDK 7.0": '
                message += msdownload % 3138
            else:
                message += ' Get it from http://aka.ms/vcpython27'
        elif version == 10.0:
            message += ' Get it with "Microsoft Windows SDK 7.1": '
            message += msdownload % 8279
        elif version >= 14.0:
            message += (
                ' Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools'
                )
    exc.args = message,


def _on_figure_window_close(figure, function):
    """Connects a close figure signal to a given function.

    Parameters
    ----------

    figure : mpl figure instance
    function : function

    """
    window = figure.canvas.manager.window
    if not hasattr(figure, '_on_window_close'):
        figure._on_window_close = list()
    if function not in figure._on_window_close:
        figure._on_window_close.append(function)
    window.closing.connect(function)


def multiline(lineinfo, dedent):
    """ Returns one string for each line,
        properly dedented.
    """
    linenum = lineinfo[0].line
    for tok in lineinfo:
        while linenum < tok.line:
            yield ''
            linenum += 1
        yield (tok.col - dedent) * ' ' + tok.rstrip()
        linenum += 1


def strip_suffixes(s, suffixes=suffixes):
    """
    Return the `s` string with any of the string in the `suffixes` set
    striped from the right. Normalize and strip spaces.

    For example:
    >>> s = 'RedHat Inc corp'
    >>> strip_suffixes(s, set(['corp'])) == 'RedHat Inc'
    True
    """
    s = s.split()
    while s and s[-1].lower().strip().strip('.,') in suffixes:
        s = s[:-1]
    return u' '.join(s)


def _setitem_via_pathlist(external_dict, path_list, value, **kwargs):
    """
        y = {'c': {'b': {}}}
        _setitem_via_pathlist(y,['c','b'],200)
    """
    if 's2n' in kwargs:
        s2n = kwargs['s2n']
    else:
        s2n = 0
    if 'n2s' in kwargs:
        n2s = kwargs['n2s']
    else:
        n2s = 0
    this = external_dict
    for i in range(0, path_list.__len__() - 1):
        key = path_list[i]
        if n2s == 1:
            key = str(key)
        if s2n == 1:
            try:
                int(key)
            except:
                pass
            else:
                key = int(key)
        this = this.__getitem__(key)
    this.__setitem__(path_list[-1], value)
    return external_dict


@classmethod
def get(cls, obj):
    """
        Returns the annotation in the given object (or False)

        :param obj: the object to check

        :return: the annotation in the given object (or False)
        """
    return getattr(obj, cls._AT_get_full_name(), False)


@staticmethod
def cuisine_db():
    """Database of supported cuisines"""
    return ['caribbean', 'chinese', 'french', 'greek', 'indian', 'italian',
        'mexican']


@classmethod
def _file_type(cls, path):
    """Returns the FileType enum value based only on the file suffix."""
    for ctype, ftype, suff in cls.SUFFIXES:
        if path.lower().endswith(suff):
            base = path[:-len(suff)]
            return base, ctype, ftype
    return path, cls.Types.NONE, cls.Types.NORMAL


def hex_to_dec(x: str) ->int:
    """
    Convert hex to decimal
    """
    return int(x, 16)


def _get_output_filename(dataset_dir, split_name):
    """Creates the output filename.

  Args:
    dataset_dir: The directory where the temporary files are stored.
    split_name: The name of the train/test split.

  Returns:
    An absolute file path.
  """
    return '%s/mnist_%s.tfrecord' % (dataset_dir, split_name)


def calc_cutoffind(freqs, min_tf):
    """
        Using an ordered frequency list (biggest->smallest), identifies index of
            first item to be cut off.

        freqs: ordered frequency list (biggest->smallest)
        min_tf: smallest frequency to accept.
    """
    if min_tf > freqs[0]:
        raise Exception('Cutoff {} is larger than largest frequency {}.'.
            format(min_tf, freqs[0]))
    if min_tf <= freqs[-1]:
        return len(freqs)
    i = 0
    while freqs[i] >= min_tf:
        i += 1
    return i


def convert_str_to_int(data):
    """ An example expansion.
    """
    data['employees'] = int(data['employees'])
    return data


def scan_setup_py():
    """Validate the contents of setup.py against Versioneer's expectations."""
    found = set()
    setters = False
    errors = 0
    with open('setup.py', 'r') as f:
        for line in f.readlines():
            if 'import versioneer' in line:
                found.add('import')
            if 'versioneer.get_cmdclass()' in line:
                found.add('cmdclass')
            if 'versioneer.get_version()' in line:
                found.add('get_version')
            if 'versioneer.VCS' in line:
                setters = True
            if 'versioneer.versionfile_source' in line:
                setters = True
    if len(found) != 3:
        print('')
        print('Your setup.py appears to be missing some important items')
        print('(but I might be wrong). Please make sure it has something')
        print('roughly like the following:')
        print('')
        print(' import versioneer')
        print(' setup( version=versioneer.get_version(),')
        print('        cmdclass=versioneer.get_cmdclass(),  ...)')
        print('')
        errors += 1
    if setters:
        print("You should remove lines like 'versioneer.VCS = ' and")
        print("'versioneer.versionfile_source = ' . This configuration")
        print('now lives in setup.cfg, and should be removed from setup.py')
        print('')
        errors += 1
    return errors


def cir_RsC(w, Rs, C):
    """
    Simulation Function: -Rs-C-

    Inputs
    ----------
    w = Angular frequency [1/s]
    Rs = Series resistance [Ohm]
    C = Capacitance [F]
    """
    return Rs + 1 / (C * (w * 1.0j))


@classmethod
def link_starting_with_text(cls, text):
    """Returns an XPath to find an HTML <a> containing text that starts with the contents of `text`."""
    return cls('//a[starts-with(node(), "%s")]' % text)


def perimeter_quadrilateral(a, b, c, d):
    """
    P = a + b + c + d
    """
    return a + b + c + d


@classmethod
def get_real_child_model(cls, data):
    """Returns the real base class specified by the discriminator"""
    discriminator_value = data[cls.json_discriminator_key]
    return cls.discriminator_value_class_map.get(discriminator_value)


@classmethod
def loadList(cls, config):
    """Iterates over a list of Dicts that represent SkeleYamls and loads them into a list"""
    objs = []
    if isinstance(config, list):
        for element in config:
            objs.append(cls.load(element))
    return objs


def delete_intent(name=None):
    """
    Deletes all versions of the intent, including the $LATEST version. To delete a specific version of the intent, use the operation.
    You can delete a version of an intent only if it is not referenced. To delete an intent that is referred to in one or more bots (see  how-it-works ), you must remove those references first.
    This operation requires permission for the lex:DeleteIntent action.
    See also: AWS API Documentation

    :example: response = client.delete_intent(
        name='string'
    )

    :type name: string
    :param name: [REQUIRED]
            The name of the intent. The name is case sensitive.

    """
    pass


def ensure_unicode(s):
    """ Turn string or bytes to bytes

    >>> ensure_unicode(u'123')
    '123'
    >>> ensure_unicode('123')
    '123'
    >>> ensure_unicode(b'123')
    '123'
    """
    if isinstance(s, str):
        return s
    if hasattr(s, 'decode'):
        return s.decode()
    msg = 'Object %s is neither a bytes object nor has an encode method'
    raise TypeError(msg % s)


def scale(A):
    """
    A no-op data scaling transformation
    """
    return A