def update_streaming_distribution(StreamingDistributionConfig=None, Id=None,
    IfMatch=None):
    """
    Update a streaming distribution.
    See also: AWS API Documentation

    :example: response = client.update_streaming_distribution(
        StreamingDistributionConfig={
            'CallerReference': 'string',
            'S3Origin': {
                'DomainName': 'string',
                'OriginAccessIdentity': 'string'
            },
            'Aliases': {
                'Quantity': 123,
                'Items': [
                    'string',
                ]
            },
            'Comment': 'string',
            'Logging': {
                'Enabled': True|False,
                'Bucket': 'string',
                'Prefix': 'string'
            },
            'TrustedSigners': {
                'Enabled': True|False,
                'Quantity': 123,
                'Items': [
                    'string',
                ]
            },
            'PriceClass': 'PriceClass_100'|'PriceClass_200'|'PriceClass_All',
            'Enabled': True|False
        },
        Id='string',
        IfMatch='string'
    )

    :type StreamingDistributionConfig: dict
    :param StreamingDistributionConfig: [REQUIRED]
            The streaming distribution's configuration information.
            CallerReference (string) -- [REQUIRED]A unique number that ensures that the request can't be replayed. If the CallerReference is new (no matter the content of the StreamingDistributionConfig object), a new streaming distribution is created. If the CallerReference is a value that you already sent in a previous request to create a streaming distribution, and the content of the StreamingDistributionConfig is identical to the original request (ignoring white space), the response includes the same information returned to the original request. If the CallerReference is a value that you already sent in a previous request to create a streaming distribution but the content of the StreamingDistributionConfig is different from the original request, CloudFront returns a DistributionAlreadyExists error.
            S3Origin (dict) -- [REQUIRED]A complex type that contains information about the Amazon S3 bucket from which you want CloudFront to get your media files for distribution.
            DomainName (string) -- [REQUIRED]The DNS name of the Amazon S3 origin.
            OriginAccessIdentity (string) -- [REQUIRED]The CloudFront origin access identity to associate with the RTMP distribution. Use an origin access identity to configure the distribution so that end users can only access objects in an Amazon S3 bucket through CloudFront.
            If you want end users to be able to access objects using either the CloudFront URL or the Amazon S3 URL, specify an empty OriginAccessIdentity element.
            To delete the origin access identity from an existing distribution, update the distribution configuration and include an empty OriginAccessIdentity element.
            To replace the origin access identity, update the distribution configuration and specify the new origin access identity.
            For more information, see Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content in the Amazon Amazon CloudFront Developer Guide .
            Aliases (dict) --A complex type that contains information about CNAMEs (alternate domain names), if any, for this streaming distribution.
            Quantity (integer) -- [REQUIRED]The number of CNAME aliases, if any, that you want to associate with this distribution.
            Items (list) --A complex type that contains the CNAME aliases, if any, that you want to associate with this distribution.
            (string) --

            Comment (string) -- [REQUIRED]Any comments you want to include about the streaming distribution.
            Logging (dict) --A complex type that controls whether access logs are written for the streaming distribution.
            Enabled (boolean) -- [REQUIRED]Specifies whether you want CloudFront to save access logs to an Amazon S3 bucket. If you do not want to enable logging when you create a streaming distribution or if you want to disable logging for an existing streaming distribution, specify false for Enabled , and specify empty Bucket and Prefix elements. If you specify false for Enabled but you specify values for Bucket and Prefix , the values are automatically deleted.
            Bucket (string) -- [REQUIRED]The Amazon S3 bucket to store the access logs in, for example, myawslogbucket.s3.amazonaws.com .
            Prefix (string) -- [REQUIRED]An optional string that you want CloudFront to prefix to the access log filenames for this streaming distribution, for example, myprefix/ . If you want to enable logging, but you do not want to specify a prefix, you still must include an empty Prefix element in the Logging element.
            TrustedSigners (dict) -- [REQUIRED]A complex type that specifies any AWS accounts that you want to permit to create signed URLs for private content. If you want the distribution to use signed URLs, include this element; if you want the distribution to use public URLs, remove this element. For more information, see Serving Private Content through CloudFront in the Amazon CloudFront Developer Guide .
            Enabled (boolean) -- [REQUIRED]Specifies whether you want to require viewers to use signed URLs to access the files specified by PathPattern and TargetOriginId .
            Quantity (integer) -- [REQUIRED]The number of trusted signers for this cache behavior.
            Items (list) --
            Optional : A complex type that contains trusted signers for this cache behavior. If Quantity is 0 , you can omit Items .
            (string) --

            PriceClass (string) --A complex type that contains information about price class for this streaming distribution.
            Enabled (boolean) -- [REQUIRED]Whether the streaming distribution is enabled to accept user requests for content.

    :type Id: string
    :param Id: [REQUIRED]
            The streaming distribution's id.

    :type IfMatch: string
    :param IfMatch: The value of the ETag header that you received when retrieving the streaming distribution's configuration. For example: E2QWRUHAPOMQZL .

    :rtype: dict
    :return: {
        'StreamingDistribution': {
            'Id': 'string',
            'ARN': 'string',
            'Status': 'string',
            'LastModifiedTime': datetime(2015, 1, 1),
            'DomainName': 'string',
            'ActiveTrustedSigners': {
                'Enabled': True|False,
                'Quantity': 123,
                'Items': [
                    {
                        'AwsAccountNumber': 'string',
                        'KeyPairIds': {
                            'Quantity': 123,
                            'Items': [
                                'string',
                            ]
                        }
                    },
                ]
            },
            'StreamingDistributionConfig': {
                'CallerReference': 'string',
                'S3Origin': {
                    'DomainName': 'string',
                    'OriginAccessIdentity': 'string'
                },
                'Aliases': {
                    'Quantity': 123,
                    'Items': [
                        'string',
                    ]
                },
                'Comment': 'string',
                'Logging': {
                    'Enabled': True|False,
                    'Bucket': 'string',
                    'Prefix': 'string'
                },
                'TrustedSigners': {
                    'Enabled': True|False,
                    'Quantity': 123,
                    'Items': [
                        'string',
                    ]
                },
                'PriceClass': 'PriceClass_100'|'PriceClass_200'|'PriceClass_All',
                'Enabled': True|False
            }
        },
        'ETag': 'string'
    }

    :returns:
    self , which is the AWS account used to create the distribution.
    An AWS account number.

    """
    pass


@staticmethod
def get_meta_attributes():
    """
        Sequences do not support meta attributes.

        Returns:
            list:
                Empty List
        """
    return []


@classmethod
def getSystemMessages(cls):
    """Gets the SystemMessages for this application. SystemMessages are
        used to notify the user of various critical situations that can occur,
        such as session expiration, client/server out of sync, and internal
        server error.

        You can customize the messages by "overriding" this method and
        returning L{CustomizedSystemMessages}. To "override" this method,
        re-implement this method in your application (the class that extends
        L{Application}). Even though overriding class methods is not
        possible in Python, Muntjac selects to call the static method from the
        subclass instead of the original L{getSystemMessages} if such a
        method exists.

        @return: the SystemMessages for this application
        """
    return cls._DEFAULT_SYSTEM_MESSAGES


@staticmethod
def _recSortKey(r):
    """
        Sort order for Features, by genomic coordinate,
        disambiguated by feature type (alphabetically).
        """
    return r.seqname, r.start, -r.end, r.type


def qn(namespace, tag_name):
    """Return the qualified name for a given namespace and tag name
    This is the ElementTree representation of a qualified name
    """
    return '{%s}%s' % (namespace, tag_name)


@staticmethod
def sci_formatter(value):
    """
		Convert a value to a scientific notation string as applicable.
		"""
    if value != 0 and (abs(value) < 0.001 or abs(value) > 1000.0):
        parts = '{0:e}'.format(value).split('e')
        result = parts[0].rstrip('0').rstrip('.') + 'e' + parts[1]
    else:
        result = '{0:f}'.format(value).rstrip('0').rstrip('.')
    return result


def std_array(comment, valueType, ndim, **kwargs):
    """Description for standard array column with variable shape (used for smaller arrays)."""
    return dict(comment=comment, valueType=valueType, ndim=ndim,
        dataManagerType='StandardStMan', dataManagerGroup='StandardStMan',
        _c_order=True, option=0, maxlen=0, **kwargs)


@classmethod
def get_time_intervals(cls, city_ref, datetime):
    """
        Method for fetching info about time intervals (for ordering "time intervals" service).

        :example:
        ``Common.get_time_intervals(city_ref='udb5c896a-391c-11dd-90d9-001a92567626', datetime='2.10.2015')``
        :param city_ref:
            ID of the recipient's city
        :param datetime:
            date for getting info about time intervals ('dd.mm.yyyy' date format)
        :return:
            dictionary with info about time intervals
        :rtype:
            dict
        """
    req = cls.send(method='getTimeIntervals', method_props={
        'RecipientCityRef': city_ref, 'DateTime': datetime})
    return req


def delete_stack(StackId=None):
    """
    Deletes a specified stack. You must first delete all instances, layers, and apps or deregister registered instances. For more information, see Shut Down a Stack .
    See also: AWS API Documentation

    :example: response = client.delete_stack(
        StackId='string'
    )

    :type StackId: string
    :param StackId: [REQUIRED]
            The stack ID.

    """
    pass


def set(object, value):
    """Set the value of the field for the object

        Raises a type error if the field is a read-only field.
        """


def get_plural_string(word: str, amount: int) ->str:
    """Returns singular or plural of the word depending on the amount.
	Example:
		word = 'piece', amount = 0 -> '0 pieces'
		word = 'piece', amount = 1 -> '1 piece'
		word = 'piece', amount = 5 -> '5 pieces'"""
    if amount == 1:
        return f'1 {word}'
    else:
        return f'{amount} {word}s'


def inv_imag_sign(zs):
    """Invert sign of imaginary parts of imp. tensor(s)."""
    return zs.real + zs.imag * -1 * 1.0j


def typed_subpart_iterator(msg, maintype='text', subtype=None):
    """Iterate over the subparts with a given MIME type.

    Use `maintype' as the main MIME type to match against; this defaults to
    "text".  Optional `subtype' is the MIME subtype to match against; if
    omitted, only the main type is matched.
    """
    for subpart in msg.walk():
        if subpart.get_content_maintype() == maintype:
            if subtype is None or subpart.get_content_subtype() == subtype:
                yield subpart


def GetInterface(setting):
    """Get the class, subclass, and protocol for the given USB setting."""
    return setting.getClass(), setting.getSubClass(), setting.getProtocol()


def not_empty_list(l):
    """Check if given value is a non-empty list.

    :param l: value
    :return: True on non-empty list, False otherwise
    :rtype: bool

    :Example:
        >>> not_empty_list([1, 2, 3])
        True
        >>> not_empty_list(None)
        False
    """
    return isinstance(l, list) and len(l) > 0


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 shoulder_r2_released(controller):
    """
    Callback function that is triggered, when the shoulder button R2 was released

    :param controller:              the controller that triggered the action
    :type controller:               steuer.Controller
    """
    print('ACTION:' + str(controller.number) + ':' + controller.name +
        ':Shoulder R2 released')


@classmethod
def set_dark_background(cls):
    """Choose dark colors for all 'auto'-prefixed codes for readability on light backgrounds."""
    cls.LIGHT_BACKGROUND = False


def __before_delete(collection, _sa_initiator=None):
    """Special method to run 'commit existing value' methods"""
    executor = collection._sa_adapter
    if executor:
        executor.fire_pre_remove_event(_sa_initiator)


def get_comm_name(name, i):
    """Get the name of the ith comm in the series.

    Args:
        name (str): Name of the fork comm.
        i (int): Index of comm in fork bundle.

    Returns:
        str: Name of ith comm in fork bundle.

    """
    return '%s_%d' % (name, i)


def path_open(filepath: str=''):
    """Open a path in a file browser

    :param filepath: filepath
    :type filepath: str
    """
    pass


@staticmethod
def encode(obj):
    """
        Defines the underlying format used during traces or services encoding.
        This method must be implemented and should only be used by the internal functions.
        """
    raise NotImplementedError


def nick(raw_nick):
    """
    Split nick into constituent parts.

    Nicks with an ident are in the following format:

        nick!ident@hostname

    When they don't have an ident, they have a leading tilde instead:

        ~nick@hostname
    """
    if '!' in raw_nick:
        nick, _rest = raw_nick.split('!')
        ident, host = _rest.split('@')
    else:
        nick, host = raw_nick.split('@')
        nick = nick.lstrip('~')
        ident = None
    return {'nick': nick, 'ident': ident, 'host': host}


def post_content(botName=None, botAlias=None, userId=None,
    sessionAttributes=None, contentType=None, accept=None, inputStream=None):
    """
    Sends user input (text or speech) to Amazon Lex. Clients use this API to send requests to Amazon Lex at runtime. Amazon Lex interprets the user input using the machine learning model that it built for the bot.
    In response, Amazon Lex returns the next message to convey to the user. Consider the following example messages:
    Not all Amazon Lex messages require a response from the user. For example, conclusion statements do not require a response. Some messages require only a yes or no response. In addition to the message , Amazon Lex provides additional context about the message in the response that you can use to enhance client behavior, such as displaying the appropriate client user interface. Consider the following examples:
    In addition, Amazon Lex also returns your application-specific sessionAttributes . For more information, see Managing Conversation Context .
    See also: AWS API Documentation

    :example: response = client.post_content(
        botName='string',
        botAlias='string',
        userId='string',
        sessionAttributes={...}|[...]|123|123.4|'string'|True|None,
        contentType='string',
        accept='string',
        inputStream=b'bytes'|file
    )

    :type botName: string
    :param botName: [REQUIRED]
            Name of the Amazon Lex bot.

    :type botAlias: string
    :param botAlias: [REQUIRED]
            Alias of the Amazon Lex bot.

    :type userId: string
    :param userId: [REQUIRED]
            ID of the client application user. Typically, each of your application users should have a unique ID. The application developer decides the user IDs. At runtime, each request must include the user ID. Note the following considerations:
            If you want a user to start conversation on one device and continue the conversation on another device, you might choose a user-specific identifier, such as the user's login, or Amazon Cognito user ID (assuming your application is using Amazon Cognito).
            If you want the same user to be able to have two independent conversations on two different devices, you might choose device-specific identifier, such as device ID, or some globally unique identifier.

    :type sessionAttributes: JSON serializable
    :param sessionAttributes: You pass this value in the x-amz-lex-session-attributes HTTP header. The value must be map (keys and values must be strings) that is JSON serialized and then base64 encoded.
            A session represents dialog between a user and Amazon Lex. At runtime, a client application can pass contextual information, in the request to Amazon Lex. For example,
            You might use session attributes to track the requestID of user requests.
            In Getting Started Exercise 1, the example bot uses the price session attribute to maintain the price of flowers ordered (for example, 'price':25). The code hook (Lambda function) sets this attribute based on the type of flowers ordered. For more information, see Review the Details of Information Flow .
            In the BookTrip bot exercise, the bot uses the currentReservation session attribute to maintains the slot data during the in-progress conversation to book a hotel or book a car. For more information, see Details of Information Flow .
            Amazon Lex passes these session attributes to the Lambda functions configured for the intent In the your Lambda function, you can use the session attributes for initialization and customization (prompts). Some examples are:
            Initialization - In a pizza ordering bot, if you pass user location (for example, 'Location : 111 Maple Street' ), then your Lambda function might use this information to determine the closest pizzeria to place the order (and perhaps set the storeAddress slot value as well). Personalized prompts - For example, you can configure prompts to refer to the user by name (for example, 'Hey [firstName], what toppings would you like?'). You can pass the user's name as a session attribute ('firstName': 'Joe') so that Amazon Lex can substitute the placeholder to provide a personalized prompt to the user ('Hey Joe, what toppings would you like?').
            Note
            Amazon Lex does not persist session attributes.
            If you configured a code hook for the intent, Amazon Lex passes the incoming session attributes to the Lambda function. The Lambda function must return these session attributes if you want Amazon Lex to return them to the client.
            If there is no code hook configured for the intent Amazon Lex simply returns the session attributes to the client application.

    :type contentType: string
    :param contentType: [REQUIRED]
            You pass this values as the Content-Type HTTP header.
            Indicates the audio format or text. The header value must start with one of the following prefixes:
            PCM format
            audio/l16; rate=16000; channels=1
            audio/x-l16; sample-rate=16000; channel-count=1
            Opus format
            audio/x-cbr-opus-with-preamble; preamble-size=0; bit-rate=1; frame-size-milliseconds=1.1
            Text format
            text/plain; charset=utf-8

    :type accept: string
    :param accept: You pass this value as the Accept HTTP header.
            The message Amazon Lex returns in the response can be either text or speech based on the Accept HTTP header value in the request.
            If the value is text/plain; charset=utf-8 , Amazon Lex returns text in the response.
            If the value begins with audio/ , Amazon Lex returns speech in the response. Amazon Lex uses Amazon Polly to generate the speech (using the configuration you specified in the Accept header). For example, if you specify audio/mpeg as the value, Amazon Lex returns speech in the MPEG format. The following are the accepted values:
            audio/mpeg
            audio/ogg
            audio/pcm
            text/plain; charset=utf-8
            audio/* (defaults to mpeg)

    :type inputStream: bytes or seekable file-like object
    :param inputStream: [REQUIRED]
            User input in PCM or Opus audio format or text format as described in the Content-Type HTTP header.

    :rtype: dict
    :return: {
        'contentType': 'string',
        'intentName': 'string',
        'slots': {...}|[...]|123|123.4|'string'|True|None,
        'sessionAttributes': {...}|[...]|123|123.4|'string'|True|None,
        'message': 'string',
        'dialogState': 'ElicitIntent'|'ConfirmIntent'|'ElicitSlot'|'Fulfilled'|'ReadyForFulfillment'|'Failed',
        'slotToElicit': 'string',
        'inputTranscript': 'string',
        'audioStream': StreamingBody()
    }

    :returns:
    If the message is to elicit slot data, Amazon Lex returns the following context information:
    x-amz-lex-dialog-state header set to ElicitSlot
    x-amz-lex-intent-name header set to the intent name in the current context
    x-amz-lex-slot-to-elicit header set to the slot name for which the message is eliciting information
    x-amz-lex-slots header set to a map of slots configured for the intent with their current values

    If the message is a confirmation prompt, the x-amz-lex-dialog-state header is set to Confirmation and the x-amz-lex-slot-to-elicit header is omitted.
    If the message is a clarification prompt configured for the intent, indicating that the user intent is not understood, the x-amz-dialog-state header is set to ElicitIntent and the x-amz-slot-to-elicit header is omitted.

    """
    pass


def hasChildren():
    """Returns True if this mmeber has children False otherwise."""


@staticmethod
def fit_category_nans(df):
    """ONLY FIT: Convert np.NaNs to a category 'NaN'"""
    for column in df.select_dtypes(include=['category']).columns:
        if df[column].isnull().any():
            df[column].cat.add_categories('NaN', inplace=True)
            df[column].fillna('NaN', inplace=True)


def filter_data(df, filter_name, verbose=False):
    """Filter certain entries with given name."""
    df = df[df.stop_name.apply(lambda cell: filter_name.encode('utf-8') in
        cell)]
    if verbose:
        msg = '- Filtered down to %d entries containing "%s".'
        print(msg % (len(df), filter_name))
    return df


def rmod(denom, result, num_range):
    """
    Calculates the inverse of a mod operation.

    The *denom* parameter specifies the denominator of the original mod (%)
    operation. In this implementation, *denom* must be greater than 0. The
    *result* parameter specifies the result of the mod operation. For obvious
    reasons this value must be in the range ``[0, denom)`` (greater than or
    equal to zero and less than the denominator).

    Finally, *num_range* specifies the range that the numerator of the original
    mode operation can lie in. This must be an iterable sorted in ascending
    order with unique values (e.g. most typically a :func:`range`).

    The function returns the set of potential numerators (guaranteed to be a
    subset of *num_range*).
    """
    if denom <= 0:
        raise ValueError('invalid denominator')
    if not 0 <= result < denom:
        return set()
    if len(num_range) == 0:
        return set()
    assert num_range[-1] >= num_range[0]
    start = num_range[0] + (result - num_range[0] % denom) % denom
    stop = num_range.stop
    return range(start, stop, denom)


def _combine_localized_attributes(pvsystem=None, location=None, **kwargs):
    """
    Get and combine attributes from the pvsystem and/or location
    with the rest of the kwargs.
    """
    if pvsystem is not None:
        pv_dict = pvsystem.__dict__
    else:
        pv_dict = {}
    if location is not None:
        loc_dict = location.__dict__
    else:
        loc_dict = {}
    new_kwargs = dict(list(pv_dict.items()) + list(loc_dict.items()) + list
        (kwargs.items()))
    return new_kwargs


def parse_elasticsearch(config):
    """Parse configuration values and get values of the elasticsearch section"""
    cfg = {}
    section = 'elasticsearch'
    cfgoption = 'index'
    if config.has_section(section):
        if config.has_option(section, cfgoption):
            cfgvalue = config.get(section, cfgoption)
        cfg[cfgoption] = cfgvalue
    return cfg


def suppress_context(exc):
    """
    This is used to mask an exception with another one.

    For instance, below, the divide by zero error is masked by the CustomException.
        try:
            1/0
        except ZeroDivisionError:
            raise suppress_context(CustomException())

    Note: In python 3, the last line would simply be raise CustomException() from None
    :param exc: new Exception that will be raised
    :return: Exception to be raised
    """
    exc.__cause__ = None
    return exc


@classmethod
def from_db(cls, db, field_names, values):
    """Override model save methods """
    orion_object = super().from_db(db, field_names, values)
    orion_object.update_from_orion()
    return orion_object


def back(branch):
    """
        handle return from branch chain

        @param branch: branch chain
        """


def logout(request):
    """Possibly logout.

        If a logout was performed, return True, otherwise return False.
        """


def order_preserving_single_index_shift(arr, index, new_index):
    """Moves a list element to a new index while preserving order.

    Parameters
    ---------
    arr : list
        The list in which to shift an element.
    index : int
        The index of the element to shift.
    new_index : int
        The index to which to shift the element.

    Returns
    -------
    list
        The list with the element shifted.

    Example
    -------
    >>> arr = ['a', 'b', 'c', 'd']
    >>> order_preserving_single_index_shift(arr, 2, 0)
    ['c', 'a', 'b', 'd']
    >>> order_preserving_single_index_shift(arr, 2, 3)
    ['a', 'b', 'd', 'c']
    """
    if new_index == 0:
        return [arr[index]] + arr[0:index] + arr[index + 1:]
    if new_index == len(arr) - 1:
        return arr[0:index] + arr[index + 1:] + [arr[index]]
    if index < new_index:
        return arr[0:index] + arr[index + 1:new_index + 1] + [arr[index]
            ] + arr[new_index + 1:]
    if new_index <= index:
        return arr[0:new_index] + [arr[index]] + arr[new_index:index] + arr[
            index + 1:]


def eval_el(el, model):
    """
        el で示された値を model の中から取り出す。見つからない場合は ValueError 例外となる
    """
    context = model
    path = ''
    for part in el.split('.'):
        path = path + '.' + part
        if isinstance(context, list):
            if not part.isdigit():
                raise ValueError('%s: %s should be array but %s' % (el,
                    part, context))
            index = int(part)
            if index < 0 or index >= len(context):
                raise ValueError(
                    '%s: index %d is out of range for model: %s' % (el,
                    index, context))
            context = context[index]
            continue
        if isinstance(context, dict):
            if not part in context:
                raise ValueError('%s: %s key not found in model: %s' % (el,
                    part, context))
            context = context[part]
            continue
        ValueError("model doesn't match %s" % path)
        break
    return context


@classmethod
def scan(cls, query=None, limit=1000, myindex=None, scroll='5m'):
    """Scan scroll for big pagination when you need to loop throw data bigger than max_result_window (defined in the top template).

    query: dict
    limit: int
    myindex: str or list
    scroll: string

    return {cls.get_index_name(): data(list), total: scroll_size(int), sid: sid(int)}
    """
    from elasticsearch import helpers
    conn = cls.get_connection()
    if not myindex:
        myindex = cls.get_index_name()
    elif isinstance(myindex, (list, tuple)):
        myindex = ','.join(myindex)
    return helpers.scan(conn, query=query, index=myindex, size=limit,
        scroll=scroll)


def GridInterpolator(grid_obj):
    """
      Interpolates the energy grid based on scipy's RegularGridInterpolator with default settings.

      :type grid_obj: instance of the grid3D class
      :param grid_obj: contains all the information regarding the energy grid used in isotherm prediction

      :raises: ValueError

      :rtype: An interpolator function of the type RegularGridInterpolator from scipy.interpolate
      """
    from scipy.interpolate import RegularGridInterpolator
    pot_interp = RegularGridInterpolator((grid_obj.X, grid_obj.Y, grid_obj.
        Z), grid_obj.pot_repeat)
    return pot_interp


def render_pep440_pre(pieces):
    """TAG[.post.devDISTANCE] -- No -dirty.

    Exceptions:
    1: no tags. 0.post.devDISTANCE
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance']:
            rendered += '.post.dev%d' % pieces['distance']
    else:
        rendered = '0.post.dev%d' % pieces['distance']
    return rendered


def spark_step_properties(jar, submitOptions, arguments=None):
    """
    Create spark step properties

    :param jar: the path of .jar file
    :type jar: string

    :param main_class: the package path for main class
    :type main_class: string

    :param arguments: arguments for the step
    :type arguments: string

    :return:
    :rtype map
    """
    spark_step = {'jar': jar, 'submitOptions': submitOptions}
    if arguments is not None:
        spark_step['arguments'] = arguments
    return spark_step


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

        :param PrimaryTeamRequestReminderDetails val:
        :rtype: TeamMergeRequestReminderExtraDetails
        """
    return cls('primary_team', val)


def maxCtxContextualRule(maxCtx, st, chain):
    """Calculate usMaxContext based on a contextual feature rule."""
    if not chain:
        return max(maxCtx, st.GlyphCount)
    elif chain == 'Reverse':
        return max(maxCtx, st.GlyphCount + st.LookAheadGlyphCount)
    return max(maxCtx, st.InputGlyphCount + st.LookAheadGlyphCount)


def outlier_removal_mode_numeric(dataframe, colname, low_cut, high_cut):
    """Replace outliers with the modal numeric value on dataframe[colname]"""
    col = dataframe[colname]
    col_numerics = col.loc[col.apply(lambda x: isinstance(x, (int, float)) and
        (x >= low_cut and x <= high_cut))]
    dataframe.loc[col.apply(lambda x: isinstance(x, (int, float)) and (x <
        low_cut or x > high_cut)), colname] = col_numerics.mode().get(0, None)
    return dataframe


def log2floor(n):
    """ log of n in base 2 rounded down """
    k = -1
    assert n >= 0
    while n:
        k += 1
        n >>= 1
    return k


def no_tqdm(it, total=1, **kwargs):
    """ Do-nothing iterable wrapper to subsitute for tqdm when verbose==False """
    return it


@classmethod
def create(cls, specgrid, zcorn, coord, actnum, mapaxes=None):
    """
        Create a new grid instance from existing keywords.

        This is a class method which can be used to create an EclGrid
        instance based on the EclKW instances @specgrid, @zcorn,
        @coord and @actnum. An ECLIPSE EGRID file contains the
        SPECGRID, ZCORN, COORD and ACTNUM keywords, so a somewhat
        involved way to create a EclGrid instance could be:

          file = ecl.EclFile("ECLIPSE.EGRID")
          specgrid_kw = file.iget_named_kw("SPECGRID", 0)
          zcorn_kw = file.iget_named_kw("ZCORN", 0)
          coord_kw = file.iget_named_kw("COORD", 0)
          actnum_kw = file.iget_named_kw("ACTNUM", 0)

          grid = EclGrid.create(specgrid_kw, zcorn_kw, coord_kw, actnum_kw)

        If you are so inclined ...
        """
    return cls._grdecl_create(specgrid[0], specgrid[1], specgrid[2], zcorn,
        coord, actnum, mapaxes)


def filter_not_in(values, vmin=None, vmax=None):
    """
    Handles 'not in' filters

    op: ['in', 'not in']
    values: iterable of values
    vmin, vmax: the range to compare within

    Returns
    -------
    True or False
    """
    if len(values) == 0:
        return False
    if vmax is not None and vmax in values:
        return True
    elif vmin is not None and vmin in values:
        return True
    else:
        return False


def announce(zelf, *args, **kwargs):
    """
            Announce a text on all channels of all bots.

            args[0] = "text to announce"

            >>> import medz.bots
            >>> bot = medz.bots.Bot()
            >>> bot.announce("hello")
            hello

        """
    from medz.kernel import fleet
    thrs = []
    for bot in fleet:
        thrs.append(zelf.put(bot.announce, *args, **kwargs))
    if thrs:
        zelf.collect(thrs)
    return thrs


def dot_join(*args):
    """Join the args together."""
    return '.'.join(args)


def compress_pubkey(pubkey: bytes) ->bytes:
    """Take a an uncompressed pubkey, return the compressed representation"""
    pub = pubkey[1:] if len(pubkey) == 65 else pubkey
    parity = (pub[-1] & 1) + 2
    compressed = bytes([parity]) + pub[:32]
    return compressed


def invert_colors(colors):
    """
    Generates inverted colours for each colour in the given colour list, using a simple inversion of each colour
    to the opposite corner on the r,g,b cube.

    :return: inverted_colors - A list of inverted (r,g,b) (r,g,b) values are floats between 0 and 1.
    """
    inverted_colors = []
    for color in colors:
        r = 0 if color[0] > 0.5 else 1
        g = 0 if color[1] > 0.5 else 1
        b = 0 if color[2] > 0.5 else 1
        inverted_colors.append((r, g, b))
    return inverted_colors


def insert(key, value):
    """Insert a key and value into the collection.

        If the key was already in the collection, then there is no
        change and 0 is returned.

        If the key was not already in the collection, then the item is
        added and 1 is returned.

        This method is here to allow one to generate random keys and
        to insert and test whether the key was there in one operation.

        A standard idiom for generating new keys will be::

          key = generate_key()
          while not t.insert(key, value):
              key=generate_key()
        """


def expand_repeat(string, size):
    """Expands a motif to highest motif size, used for checking duplicates"""
    return_string = ''
    i = 0
    while len(return_string) < size:
        return_string += string[i]
        i += 1
        if i >= len(string):
            i = 0
    return return_string


def letter_to_number(letter_grade, scale):
    """Convert a letter grade to a number using a given scale.
       Returns float('Nan') for grades not in the scale."""
    for grade, val, mx, mn in scale:
        if letter_grade == grade:
            return val
    else:
        return float('Nan')


def wavelet_frequency_inverse(*args, **kwargs):
    """Procedural interface for WaveletFrequencyInverse"""
    import itk
    instance = itk.WaveletFrequencyInverse.New(*args, **kwargs)
    return instance.__internal_call__()


def inpoly(xv, yv, xt, yt):
    """
    Originally in C by Bob Stein and Craig Yap
    http://www.visibone.com/inpoly/
    Converted to python by Bryan Miller
    2013.04.18
    Inputs:
      xv - x vertices of polygon (does not have to be 'closed', ie. last = first)
      yv - y vertices of polygon
      xt - x of test point(s)
      yt - y of test point(s)

    # 2016.06.25 - generalize to handle input arrays
    """
    nvert = len(xv)
    if nvert != len(yv) or nvert < 3:
        return -1
    l_xt = xt
    l_yt = yt
    try:
        npoints = len(l_xt)
    except Exception:
        l_xt = [l_xt]
        npoints = len(l_xt)
    try:
        npointsy = len(l_yt)
    except Exception:
        l_yt = [l_yt]
        npointsy = len(l_yt)
    if npoints != npointsy:
        return -1
    inside = [(False) for ii in range(npoints)]
    for jj in range(npoints):
        xold = xv[nvert - 1]
        yold = yv[nvert - 1]
        for i in range(nvert):
            xnew = xv[i]
            ynew = yv[i]
            if xnew > xold:
                x1 = xold
                x2 = xnew
                y1 = yold
                y2 = ynew
            else:
                x1 = xnew
                x2 = xold
                y1 = ynew
                y2 = yold
            if (xnew < l_xt[jj]) == (l_xt[jj] <= xold) and (l_yt[jj] - y1) * (
                x2 - x1) < (y2 - y1) * (l_xt[jj] - x1):
                inside[jj] = not inside[jj]
            xold = xnew
            yold = ynew
    if npoints == 1:
        inside = inside[0]
    return inside


def convert_selection_range2scaling_from_to(start_point, end_point, size):
    """ 選択範囲を座標から画面全体のパーセントにスケーリングし、順序も直す """
    from_ = min([start_point, end_point]) / size
    to_ = max([start_point, end_point]) / size
    return from_, to_


def build_option_parser(parser):
    """Hook to add global options"""
    return parser


@staticmethod
def converter(fn):
    """Tag the method as the collection converter.

        This optional method will be called when a collection is being
        replaced entirely, as in::

            myobj.acollection = [newvalue1, newvalue2]

        The converter method will receive the object being assigned and should
        return an iterable of values suitable for use by the ``appender``
        method.  A converter must not assign values or mutate the collection,
        its sole job is to adapt the value the user provides into an iterable
        of values for the ORM's use.

        The default converter implementation will use duck-typing to do the
        conversion.  A dict-like collection will be convert into an iterable
        of dictionary values, and other types will simply be iterated::

            @collection.converter
            def convert(self, other): ...

        If the duck-typing of the object does not match the type of this
        collection, a TypeError is raised.

        Supply an implementation of this method if you want to expand the
        range of possible types that can be assigned in bulk or perform
        validation on the values about to be assigned.

        """
    fn._sa_instrument_role = 'converter'
    return fn


def instantiate(o):
    """Instantiate `o` if it's a class"""
    return o() if isinstance(o, type) else o


def s2n(s):
    """
    String to number.
    """
    if not len(s):
        return 0
    return int(s.encode('hex'), 16)


def is_item_iterable(item):
    """Determine if an item is iterable.

    Parameters
    ----------
    item : object
        The item to test.

    Returns
    -------
    bool
        True if the item is iterable.
        False otherwise.

    Examples
    --------
    >>> is_item_iterable(1.0)
    False
    >>> is_item_iterable('abc')
    True
    """
    try:
        _ = [_ for _ in item]
    except TypeError:
        return False
    return True


def dgl_adjacency(data=None, out=None, name=None, **kwargs):
    """This operator converts a CSR matrix whose values are edge Ids
    to an adjacency matrix whose values are ones. The output CSR matrix always has
    the data value of float32.

    Example:

       .. code:: python

      x = [[ 1, 0, 0 ],
           [ 0, 2, 0 ],
           [ 0, 0, 3 ]]
      dgl_adjacency(x) =
          [[ 1, 0, 0 ],
           [ 0, 1, 0 ],
           [ 0, 0, 1 ]]

    Defined in src/operator/contrib/dgl_graph.cc:L1393

    Parameters
    ----------
    data : NDArray
        Input ndarray

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

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


def check_metadata(metadata1, metadata2):
    """
    Check that to MetaData class are compatible with each other

    Parameters
    ----------
    metadata1: `lstchain.io.MetaData`
    metadata2: `lstchain.io.MetaData`
    """
    assert metadata1.keys() == metadata2.keys()
    keys = ['LSTCHAIN_VERSION']
    for k in keys:
        assert metadata1[k] == metadata2[k]


def delete_proxy():
    """Delete movie clip proxy files from the hard drive

    """
    pass


def transform_aabb(transform, aabb):
    """ Apply a transformation to an axis aligned bounding box.

    The result is a new AABB in the same coordinate system as the original AABB.
    The new AABB contains all corner points of the original AABB after applying the given transformation.

    Args
        transform: The transformation to apply.
        x1:        The minimum x value of the AABB.
        y1:        The minimum y value of the AABB.
        x2:        The maximum x value of the AABB.
        y2:        The maximum y value of the AABB.
    Returns
        The new AABB as tuple (x1, y1, x2, y2)
    """
    x1, y1, x2, y2 = aabb
    points = transform.dot([[x1, x2, x1, x2], [y1, y2, y2, y1], [1, 1, 1, 1]])
    min_corner = points.min(axis=1)
    max_corner = points.max(axis=1)
    return [min_corner[0], min_corner[1], max_corner[0], max_corner[1]]


@classmethod
def xml_item(cls, item):
    """ Represents a single resource (member of a collection) as XML.

        :param data: the data stream to be rendered as xml.

        .. versionadded:: 0.0.3
        """
    xml = cls.xml_root_open(item)
    xml += cls.xml_add_links(item)
    xml += cls.xml_dict(item)
    xml += cls.xml_root_close()
    return xml


@classmethod
def getName(class_, code, lowerize=False):
    """Gets the language name (in this language) from a 2-chars language
           p_code."""
    r = class_.getIsoLanguages().get(code)[2]
    if not lowerize:
        return r
    return r.lower()


@staticmethod
def _get_primary_keys(formatted_columns):
    """Get columns that are primary key"""
    primary_keys = list()
    for column in formatted_columns:
        column_is_primary_key = column[3]
        if column_is_primary_key:
            column_name = column[0]
            primary_keys.append(column_name)
    return primary_keys


def denoise_animation(input_filepath: str='', output_filepath: str=''):
    """Denoise rendered animation sequence using current scene and view layer settings. Requires denoising data passes and output to OpenEXR multilayer files

    :param input_filepath: Input Filepath, File path for image to denoise. If not specified, uses the render file path and frame range from the scene
    :type input_filepath: str
    :param output_filepath: Output Filepath, If not specified, renders will be denoised in-place
    :type output_filepath: str
    """
    pass


def to_uuid(uuid):
    """Return the UUID from the string representation.

        :param uuid: A UUID, or the string representation of the UUID.
        :type uuid: UUID or str
        :return: The UUID, converted if needed as appropriate for the
            API version.  In 3.0, the string representation is
            interpreted as an integer, while in 3.1 it is the hex
            string.
        :rtype: UUID
        """


@staticmethod
def _deny_overrides(policies):
    """
            Deny overrides evaluation algorithm

            :param policies: list of policies to evaluate
            :return: True if request is authorized else False
        """
    if not policies:
        return False
    for policy in policies:
        if not policy.is_allowed:
            return False
    return True


def _KeyValueToDict(pair):
    """Converts an iterable object of key=value pairs to dictionary."""
    d = dict()
    for kv in pair:
        k, v = kv.split('=', 1)
        d[k] = v
    return d


def set_starting_position(poly, ggr=None):
    """Check and set starting position."""
    if not ggr:
        starting_position = 'upperleftcorner'
    else:
        starting_position = ggr.Starting_Vertex_Position.lower()
    poly = poly.order_points(starting_position)
    return poly


def tilt_clear():
    """Clear the tilt of selected control points

    """
    pass


def testXMLAttribute(element, attribute):
    """

    Test that the XML element and attribute exist, return attribute's value, else return None

    Parameters
    ----------

    - element: the element containing the attribute
    - attribute: the attribute name

    """
    if element is not None:
        return element.get(attribute)
    return None


def def_get(target, key, default=None):
    """Special get function. Return default if the value is None."""
    value = target.get(key, default)
    if value is None:
        return default
    return value


def destos_to_binfmt(key):
    """
	Returns the binary format based on the unversioned platform name,
	and defaults to ``elf`` if nothing is found.

	:param key: platform name
	:type  key: string
	:return: string representing the binary format
	"""
    if key == 'darwin':
        return 'mac-o'
    elif key in ('win32', 'cygwin', 'uwin', 'msys'):
        return 'pe'
    return 'elf'


def plus_or_dot(pieces):
    """Return a + if we don't already have one, else return a ."""
    if '+' in pieces.get('closest-tag', ''):
        return '.'
    return '+'


def printMenu(menu, showExit=True, prefix=''):
    """Prints the menu for the user to see

    :param menu: an array of menu entries, each menu entry is a dictionary
    :param showExit: boolean for whether or not to show the EXIT entry
    :param prefix: string to print in from of the menu entry (e.g for formatting)

    :returns: n/a

    The 'menu' parameter is an array of dictionary values. Each entry in the array
    translates to a single menu item that looks like the following dictionary:
        {
            'type': '<type>',
            'index': #<index>#,
            'text': '<text>'
        }

    The dictionary may contain other entries. The 'type' and 'text' fields are both
    string values. The 'type' value only has one special value ('EXIT') used to denote
    the Exit menu entry; it may otherwise be any arbitrary string. The 'index' field
    is typically an integer used to provide the value input for the user to select
    the menu item with.

    There are two easy ways to create the menu dictionary:

        menu = [
            {'type': 'entry', 'index': 0, 'text': 'First Entry'},
            {'type': 'entry', 'index': 1, 'text': 'Second Entry'},
            {'type': 'entry', 'index': 2, 'text': 'Third Entry'},
        ]

    or

        menu = []
        for x in range(3):
            menu.append({
                'type': 'entry',
                'index': len(menu),
                'text': 'Entry #{0}'.format(x)
            })
    """
    for entry in menu:
        if entry['type'] == 'EXIT' and showExit is True or entry['type'
            ] != 'EXIT':
            print('{0:}{1:02d}) {2:}'.format(prefix, entry['index'], entry[
                'text']))


def handle_year_stradling(date_time):
    """
    Deals with the scenario of the water year starting in
    10/1/N  and ending in 10/1/N+1, assumes that the water year is asssociated
    to the bulk of time at the year which is N+1

    Depending on the time, will return the appropiate year for the starting
    point
    """
    if date_time.month < 10:
        year = date_time.year - 1
    else:
        year = date_time.year
    return year


def get_project_milestone(gl, project_id, milestone_id):
    """ Get Project's Milestone
    :param gl: GitLab Object Instance
    :param project_id: Project Identifier (int)
    :param milestone_id: Milestone Identifier (int)
    :return: Milestone (Object)
    """
    return False


def _add_doc(func, doc):
    """Add documentation to a function."""
    func.__doc__ = doc


@classmethod
def active_setup(klass):
    """
        This class method must be called after the child class definition
        in order to setup the dataset active state
        """
    klass.set_global_prop('display', active=klass._active_prop)
    klass.enable.set_prop('display', active=True, hide=klass._ro_prop,
        store=klass._active_prop)


def delete_zero_amount_exchanges(data, drop_types=None):
    """Drop all zero value exchanges from a list of datasets.

    ``drop_types`` is an optional list of strings, giving the type of exchanges to drop; default is to drop all types.

    Returns the modified data."""
    if drop_types:
        dont_delete = lambda x: x['type'] not in drop_types or x['amount']
    else:
        dont_delete = lambda x: x['amount']
    for ds in data:
        ds['exchanges'] = list(filter(dont_delete, ds['exchanges']))
    return data


def ScenarioSetClk(Sig, Period_ns):
    """
	Return a string of clock generator command for TBGen.
	"""
    return '\nGPIO SET_CLK {Name} {HalfPeriod_ps} {HalfPeriod_ps} 0'.format(
        Name=Sig.Name, HalfPeriod_ps=int(Period_ns / 2 * 1000))


def get_initial_contact(request):
    """Fill in initial contact form fields from request."""
    initial = {}
    if request.user.is_authenticated:
        initial['name'] = request.user.full_name
        initial['email'] = request.user.email
    return initial


def format_number(number, number_of_digits):
    """
    The function format_number() return a string-representation of a number
    with a number of digits after the decimal separator.
    If the number has more digits, it is rounded.
    If the number has less digits, zeros are added.

    @param number: the number to format
    @param digits: the number of digits
    """
    if number is None:
        return ''
    return '%.{0}f'.format(number_of_digits) % number


@classmethod
def getInstance(cls) ->'CameraServer':
    """Get the CameraServer instance."""
    try:
        return cls._server
    except AttributeError:
        cls._server = cls()
        return cls._server


def all_dependencies(object=True):
    """ Returns a list of all the dependencies (including dependencies
            of dependencies) of a ticket
        """


def p_simple_list_terminator(p):
    """simple_list_terminator : NEWLINE
                              | EOF"""
    pass


@staticmethod
def __is_iterable(i):
    """ boolean test to see if the argument is iterable """
    output = False
    try:
        iter(i)
        output = True
    except:
        pass
    return output


def robot_command(api, command, exp_id, nodes_list=()):
    """ Launch commands ('status',) on nodes_list

    :param api: API Rest api object
    :param command: command that should be run
    :param exp_id: Target experiment id
    :param nodes_list: List of nodes where to run command.
                       Empty list runs on all nodes
    """
    assert command in ('status',)
    result = api.robot_command(command, exp_id, nodes_list)
    return result


def fixMono(SpGrp):
    """fixes b-unique monoclinics in e.g. P 1 2/1c 1 --> P 21/c """
    Flds = SpGrp.split()
    if len(Flds) == 4:
        if Flds[2] != '1':
            return '%s %s' % (Flds[0], Flds[2])
        else:
            return None
    else:
        return SpGrp


def _get_labeled_order(state):
    """Get the order in which papers were labeled."""
    label_order = []
    n_initial = 0
    n_queries = state.n_queries()
    for query_i in range(n_queries):
        try:
            label_methods = state.get('label_methods', query_i)
        except KeyError:
            continue
        label_idx = state.get('label_idx', query_i)
        for i in range(len(label_idx)):
            if label_methods[i] == 'initial':
                n_initial += 1
        label_order.extend(label_idx)
    return label_order, n_initial


def ENVP(df, pct=0.01, price='Close'):
    """
    Envelope Percent
    Returns: dict of lists of floats = jhta.ENVP(df, pct=.01, price='Close')
    Source: https://www.fmlabs.com/reference/default.htm?url=EnvelopePct.htm
    """
    envp_dict = {'hi': [], 'lo': []}
    for i in range(len(df[price])):
        hi = df[price][i] + df[price][i] * pct
        lo = df[price][i] - df[price][i] * pct
        envp_dict['hi'].append(hi)
        envp_dict['lo'].append(lo)
    return envp_dict


@staticmethod
def _bool_translate(thing):
    """Translate the thing into a boolean."""
    return False if str(thing).lower() == 'false' else bool(thing)


def other():
    """
    Note to contributors:
        Please, check /DESIGN.md and adhere to our coding style
        for other range masking operations.
    """


def __call__(context):
    """
        Invoke the behavior-specific factory if the context can be adapted
        """


def print_upper_triangular_matrix(matrix):
    """Prints a CVRP data dict matrix

    Arguments
    ---------
    matrix : dict
        Description

    Note
    -----
    It is assummed that the first row of matrix contains all needed headers.
    """
    first = sorted(matrix.keys())[0]
    print('\t', end=' ')
    for i in matrix[first]:
        print('{}\t'.format(i), end=' ')
    print()
    indent_count = 0
    for i in matrix:
        print('{}\t'.format(i), end=' ')
        if indent_count:
            print('\t' * indent_count, end=' ')
        for j in sorted(matrix[i]):
            print('{}\t'.format(matrix[i][j]), end=' ')
        print()
        indent_count = indent_count + 1


def get_default_app_name(site, user):
    """get the default app for the currrent user"""
    if user.is_authenticated:
        default_app = site.home_app_name
    else:
        default_app = site.index_app_name
    return default_app


def pytest_xdist_setupnodes(config, specs):
    """ called before any remote node is set up. """


def match(path):
    """
        If the ``path`` passed to this function can be matched by the
        ``pattern`` of this route, return a dictionary (the
        'matchdict'), which will contain keys representing the dynamic
        segment markers in the pattern mapped to values extracted from
        the provided ``path``.

        If the ``path`` passed to this function cannot be matched by
        the ``pattern`` of this route, return ``None``.
        """


def translate(value, left_min, left_max, right_min, right_max):
    """This code maps values from the left range and interpolates to the
    corresponding range on the right. This is used to translate the amino acid
    substition matrix scores to a scale between 0 and 1 for making alphamaps.

    I don't know if this works if the directionality of the ranges are swapped.
      IE [5, -10] mapped to [0, 1]

    args:
      <value> - the value in [<left_min>:<left_max>] to scale between
                 [<right_min>:<right_max>]
      <left_min> - the 'min' of the left (source) range
      <left_max> - the 'max' of the left (source) range
      <right_min> - the 'min' of the right (target) range
      <right_max>   the 'max' of the right (target) range

    output:
      the <value>(float) scaled between <right_min> and <right_max>
    """
    left_span = left_max - left_min
    right_span = right_max - right_min
    value_scaled = float(value - left_min) / float(left_span)
    return right_min + value_scaled * right_span


def _pairwise(true, pred):
    """Return numerators and denominators for precision and recall,
    as well as size of symmetric difference, used in negative pairwise."""
    p_num = r_num = len(true & pred)
    p_den = len(pred)
    r_den = len(true)
    return p_num, p_den, r_num, r_den


def e_join(l, t='and', s=', '):
    """Join a list of strings in an intelligble way for display
    a, b, c becomes a, b and c with default params"""
    if len(l) == 0:
        return ''
    elif len(l) == 1:
        return l[0]
    else:
        return s.join(l[:-1]) + ' %s ' % t + str(l[-1])


def store(resource_id: str) ->str:
    """
        Store a copy of a resource in this adapter.

        Store assumes that the file is in the `dropbox_dir`.
        AdapterManager will always verify that this is the case.

        :param r_id - the resource to store's UUID
        """
    pass


def convert_codonlist_to_tuplelist(seq_codons, codon_to_codon_extended):
    """Convert a list of triplets into a list of tuples, using a swaptable.

    The swaptable is a dict of triplet: triplets, and determines the
    allowed swaps.
    """
    codon_extended = [None] * len(seq_codons)
    for i, codon in enumerate(seq_codons):
        codon_extended[i] = codon_to_codon_extended[codon]
    return codon_extended


def ifelse(test, if_true, if_false):
    """
    Return `if_true` is argument `test` evaluates to `True`,
    return `if_false` otherwise.

    This is just a workaround for Python 2.4 lack of the
    conditional assignment operator::

      >>> a = 1
      >>> b = ifelse(a, "yes", "no"); print(b)
      yes
      >>> b = ifelse(not a, 'yay', 'nope'); print(b)
      nope

    """
    if test:
        return if_true
    else:
        return if_false


def normalize_pep440(**kwd):
    """ Normalize the version.

        >>> normalize_pep440(**parse_pep440('1.2.3.4.rc5.post.dev'))
        '1.2.3.4rc5'
    """
    normalized = '.'.join(map(str, kwd['release']))
    if 'pre_release' in kwd:
        normalized += '%s%s' % kwd['pre_release']
    if 'post_release' in kwd:
        normalized += '.post' + str(kwd['post_release'])
    if 'dev_release' in kwd:
        normalized += '.dev' + str(kwd['dev_release'])
    if 'epoch' in kwd:
        normalized = '{}!{}'.format(kwd['epoch'], normalized)
    return normalized


@staticmethod
def _deserialize(filecontent):
    """
        Given the contents of a cache file, reconstruct the original response
        in the original format (as returned by :func:`_get_fresh_content`).
        Use this function to deserialize cache files for structured responses
        when needed.

        Unless overridden by the subclass, this function simply returns the
        file content unaltered.

        The actions of this function should be reversed by
        :func:`_serialize`.
        """
    return filecontent


def _get_template(isamAppliance):
    """
    Retrieve a URL Mapping Template
    """
    return isamAppliance.invoke_get('Retrieve a URL Mapping Template',
        '/wga_templates/dynurl_template.json')


def _register_process_with_cgrulesengd(pid):
    """Tell cgrulesengd daemon to not move the given process into other cgroups,
    if libcgroup is available.
    """
    from ctypes import cdll
    try:
        libcgroup = cdll.LoadLibrary('libcgroup.so.1')
        failure = libcgroup.cgroup_init()
        if failure:
            pass
        else:
            CGROUP_DAEMON_UNCHANGE_CHILDREN = 1
            failure = libcgroup.cgroup_register_unchanged_process(pid,
                CGROUP_DAEMON_UNCHANGE_CHILDREN)
            if failure:
                pass
    except OSError:
        pass


def render_pep440_pre(pieces):
    """TAG[.post.devDISTANCE] -- No -dirty.

    Exceptions:
    1: no tags. 0.post.devDISTANCE
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance']:
            rendered += '.post.dev%d' % pieces['distance']
    else:
        rendered = '0.post.dev%d' % pieces['distance']
    return rendered


def parse_number(x):
    """
    Parse argument as int or float.
    """
    try:
        return int(x)
    except ValueError:
        return float(x)


@classmethod
def general(cls):
    """A factory method that creates a :class:`Permissions` with all
        "General" permissions from the official Discord UI set to ``True``."""
    return cls(2080899263)


def _character_check(items, argument_name, function_name):
    """Make sure all elements of `items` are single-character ASCII strings.

  Args:
    items: an iterable of things that should be single-character ASCII strings.
    argument_name: if raising a `TypeError` due to finding an illegal value in
        `items`, a name to give `items` in the exception string.
    function_name: if raising a `TypeError` due to finding an illegal value in
        `items`, a name to give the entity that objects to that value.

  Raises:
    TypeError: if anything that's not a single-character ASCII strings turns up
        in `items`; the exception string will say that `function_name` objects
        to finding such things in `argument_name`.
  """
    for item in items:
        try:
            _ = ord(item)
        except TypeError:
            raise TypeError(
                '{} requires all elements in its {} argument to be single-character ASCII strings, but {} was found inside {}.'
                .format(function_name, argument_name, repr(item),
                argument_name))


@staticmethod
def is_number(s):
    """
        Test if value is numeric
        """
    try:
        s = float(s)
        return True
    except ValueError:
        return False


def isHiddenName(astr):
    """ Return True if this string name denotes a hidden par or section """
    if astr is not None and len(astr) > 2 and astr.startswith('_'
        ) and astr.endswith('_'):
        return True
    else:
        return False


def multires_subdivide(modifier: str=''):
    """Add a new level of subdivision

    :param modifier: Modifier, Name of the modifier to edit
    :type modifier: str
    """
    pass


def _get_best_indexes(logits, n_best_size):
    """Get the n-best logits from a list."""
    index_and_score = sorted(enumerate(logits), key=lambda x: x[1], reverse
        =True)
    best_indexes = []
    for i in range(len(index_and_score)):
        if i >= n_best_size:
            break
        best_indexes.append(index_and_score[i][0])
    return best_indexes


def code_point_reverse_order(cp):
    """Reverse ordering function for code points."""
    return cp if isinstance(cp, int) else cp[1] - 1


def wavelength_ang(voltage_kV):
    """
    Calculates the relativistic electron wavelength
    in angstroms based on the microscope accelerating
    voltage

    Parameters
    ----------
    voltage_kV: float
                microscope operating voltage in kilo
                electronVolts

    Returns
    -------
    wavelength: float
                relativistic electron wavelength in
                angstroms

    :Authors:
    Debangshu Mukherjee <mukherjeed@ornl.gov>
    """
    m = 9.109383 * 10 ** -31
    e = 1.602177 * 10 ** -19
    c = 299792458
    h = 6.62607 * 10 ** -34
    voltage = voltage_kV * 1000
    numerator = h ** 2 * c ** 2
    denominator = e * voltage * (2 * m * c ** 2 + e * voltage)
    wavelength = 10 ** 10 * (numerator / denominator) ** 0.5
    return wavelength


def net_profit_margin(net_income, revenue):
    """Computes net profit margin.

    @params
    -------
    net_income: net income
    revenue: revenue (or sales)

    returns
    -------
    Net profit margin, int or float

    explanation
    -----------

    """
    return net_income / revenue


def mask_dict(d, *names):
    """Mask certain values in a dict."""
    m = {}
    for k, v in d.items():
        m[k] = '****' if k in names else v
    return m


def describe_type(x):
    """ Returns a friendly description of the type of x. """
    if hasattr(x, '__class__'):
        c = x.__class__
        if hasattr(x, '__name__'):
            class_name = '%s' % c.__name__
        else:
            class_name = str(c)
    else:
        class_name = str(type(x))
    return class_name


def apply_addons(widget, *addon_types, **named_addon_types):
    """Apply some addons to a widget.

    :param widget: The widget to apply addons to.
    :param addon_types: A list of addon types, which will be instantiated
                         and applied to the widget with the default name of
                         the addon.
    :param named_addon_types: A named list of addons, the keywords will be
                               the name of the addon when loaded and will
                               override the default addon name. This can
                               allow loading the same addon multpily for the
                               same widget under different names.

    Plugins should conform to the GObjectPlugin interface or be a subclass of
    it. Once loaded, addons will be available as widget.addons.<addon_name>
    withe standard attribute access.
    """
    for addon_type in addon_types:
        addon_type(widget)
    for name, addon_type in named_addon_types.items():
        addon_type(widget, addon_name=name)


def cursor(cursor_type='ARROW'):
    """Set the cursor to the specified type.

    :param cursor_type: The cursor type to be used (defaults to
        'ARROW'). Should be one of: {'ARROW','CROSS','HAND', 'MOVE',
        'TEXT', 'WAIT'}
    :type cursor_type: str

    """
    raise NotImplementedError


def format_display_data(obj, include=None, exclude=None):
    """Return a format data dict for an object.

    By default all format types will be computed.

    Parameters
    ----------
    obj : object
        The Python object whose format data will be computed.

    Returns
    -------
    format_dict : dict
        A dictionary of key/value pairs, one or each format that was
        generated for the object. The keys are the format types, which
        will usually be MIME type strings and the values and JSON'able
        data structure containing the raw data for the representation in
        that format.
    include : list or tuple, optional
        A list of format type strings (MIME types) to include in the
        format data dict. If this is set *only* the format types included
        in this list will be computed.
    exclude : list or tuple, optional
        A list of format type string (MIME types) to exclude in the format
        data dict. If this is set all format types will be computed,
        except for those included in this argument.
    """
    from .interactiveshell import InteractiveShell
    return InteractiveShell.instance().display_formatter.format(obj,
        include, exclude)


def _tbl_shift(opt):
    """
    Return the table shift value
    """
    if opt.algorithm == opt.algo_table_driven and (opt.width is None or opt
        .width < 8):
        if opt.width is None:
            return None
        else:
            return 8 - opt.width
    else:
        return 0


@classmethod
def from_config(cls, xknx, name, config):
    """Initialize object from configuration structure."""
    group_address_speed = config.get('group_address_speed')
    group_address_speed_state = config.get('group_address_speed_state')
    return cls(xknx, name, group_address_speed=group_address_speed,
        group_address_speed_state=group_address_speed_state)


def pad_line(line):
    """Helper function to pad line to 80 characters in case it is shorter"""
    size_of_line = len(line)
    if size_of_line < 80:
        padding = 80 - size_of_line + 1
        line = line.strip('\n') + ' ' * padding + '\n'
    return line[:81]


def simple_filter(data=None, attr=None, value=None, property_field=None):
    """Filter a list of dicts

    :param list data:
        The list to be filtered.  The list is modified in-place and will
        be changed if any filtering occurs.
    :param string attr:
        The name of the attribute to filter.  If attr does not exist no
        match will succeed and no rows will be returned.  If attr is
        None no filtering will be performed and all rows will be returned.
    :param sring value:
        The value to filter.  None is considered to be a 'no filter' value.
        '' matches against a Python empty string.
    :param string property_field:
        The name of the data field containing a property dict to filter.
        If property_field is None, attr is a field name. If property_field
        is not None, attr is a property key name inside the named property
        field.

    :returns:
        Returns the filtered list
    :rtype list:

    This simple filter (one attribute, one exact-match value) searches a
    list of dicts to select items.  It first searches the item dict for a
    matching ``attr`` then does an exact-match on the ``value``.  If
    ``property_field`` is given, it will look inside that field (if it
    exists and is a dict) for a matching ``value``.
    """
    if not data or not attr or value is None:
        return data
    for d in reversed(data):
        if attr in d:
            search_value = d[attr]
        elif property_field and property_field in d and isinstance(d[
            property_field], dict):
            if attr in d[property_field]:
                search_value = d[property_field][attr]
            else:
                search_value = None
        else:
            search_value = None
        if not search_value or search_value != value:
            try:
                data.remove(d)
            except ValueError:
                pass
    return data


def get_average(numbers):
    """
    Returns the average value of the given numbers list
    :param numbers: list<float>, list of the floats to get average from
    :return: float, average of the floats in numbers list
    """
    total = 0.0
    for num in numbers:
        total += num
    return total / len(numbers)


def render_layer_remove():
    """Remove the selected render layer

    """
    pass


def get_project_request_changes(gl, project_id, request_id):
    """ Get Merge Request's Changes
    :param gl: GitLab Object Instance
    :param project_id: Project Identifier (int)
    :param request_id: Merge Request Identifier (int)
    :return: Changes (List)
    """
    return False


def left(rect):
    """Returns the left most X value of the rectangle.

    This caters for rectangles with a negative width.

    :rtype: float
    :return: The smallest X value.
    """
    return min(rect[0][0], rect[0][0] + rect[1][0])


def calc_pct_of_absolute(values, epsilon=1000000.0):
    """calculates value / sum of abs values, adds epsilon if sum of abs values is zero"""
    denominator = values.abs().sum()
    if denominator == 0:
        denominator = epsilon
    return values / denominator


@classmethod
def isValidLabel(cls, labelString):
    """Checks if string is a valid label or
		label reference (without colons).
		"""
    return bool(cls.labelRe.match(labelString))


def rendersize():
    """Set render size and aspect from active sequence

    """
    pass


def _moduleof(obj, dflt=''):
    """Return the object's module name.
    """
    return getattr(obj, '__module__', dflt)


def zero_width_joiner():
    """Return the unicode character for the zero-width joiner.

    This is useful for making compound emoji. For example,
    :waving_black_flag: + zwj + :skull_and_crossbones: = pirate flag.
    """
    return '\u200d'


@staticmethod
def get_citations(obj):
    """Get a list of citations from an object."""
    citations = 'None'
    for attr in ('cite_as', '_cite_as'):
        try:
            citations = getattr(obj, attr)
        except AttributeError:
            pass
        else:
            break
    if isinstance(citations, str):
        citations = [citations]
    return citations


def __ConvertOSBGToLocal(easting, northing, Eo, No, one_over_CSF):
    """
    Convert OSBG36 Easting-Northing to local grid coordinates

    :param easting: easting in OSBG36
    :param northing: northing in OSBG36
    :param Eo: delta easting of local grid
    :param No: delta northing of local grid
    :param one_over_CSF: reciprocal CSF (combinated scale factor, = 1/CSF)

    :returns: todo
    """
    x_local = (easting - Eo) * one_over_CSF
    y_local = (northing - No) * one_over_CSF
    return x_local, y_local


def get_gnf():
    """Nonfiscal Operation General Counter

        @returns: gnf
        @rtype: integer
        """


def release():
    """
        Like close, but intended to be called on child objects
        created for MVCC using a ``new_instance`` method.
        """


def ica(pArray, iComponents=1):
    """
	Input: N x D matrix
	Output: D x N matrix

	"""
    from sklearn.decomposition import FastICA
    try:
        iRow, iCol = pArray.shape
        pICA = FastICA(n_components=iComponents)
        return pICA.fit_transform(pArray.T).T
    except ValueError:
        iRow = pArray.shape
        iCol = None
        return pArray


def _bootstrap_repo(ctx):
    """Bootstrap repo with standard github configuration."""
    remote_url = 'git@github.com:{}/{}.git'.format(ctx.repo.user_name, ctx.
        repo.name)
    ctx.run('git init')
    ctx.run('git add .')
    ctx.run('git commit -m "new project from {}"'.format(ctx.cc_name))
    ctx.run('git remote add origin {}'.format(remote_url))
    ctx.run('git tag -a "v_0.0.0" -m "cookiecutter ref"')


@classmethod
def visible_for_object(cls, obj, request=None):
    """
        Returns whether this sections must be visible for the provided object (e.g. `order`)
        :type model object: e.g. shuup.core.models.Order
        :type request: HttpRequest
        :return whether this section must be shown in order section list, defaults to false
        :rtype: bool
        """
    return False


def run_doctest():
    """Runs doctests for this module."""
    import doctest
    return doctest.testmod()


def get_ave_weight(state):
    """Return the average weight parameter for a state"""
    import metatab as mt
    doc = mt.open_package(
        'http://s3.amazonaws.com/library.metatab.org/census.gov-varrep_tables_support-2011e2015-1.csv'
        )
    r = doc.resource('ave_weights')
    d = {}
    for row in r.iterdict:
        try:
            if int(row['fips_state_code']) == int(state):
                return int(row['average_weight'])
        except TypeError:
            continue


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

        :param TeamMergeFromDetails val:
        :rtype: EventDetails
        """
    return cls('team_merge_from_details', val)


def print_seqs(seqs, id2name, name):
    """
    print fasta of introns and ORFs
    # seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, iseq, [orfs], [introns], orfs?, introns?, [orf annotations]], ...]]
    """
    orfs = open('%s.orfs.faa' % name.rsplit('.', 1)[0], 'w')
    introns = open('%s.introns.fa' % name.rsplit('.', 1)[0], 'w')
    insertions = open('%s.insertions.fa' % name.rsplit('.', 1)[0], 'w')
    for seq in seqs:
        for i, ins in enumerate(seqs[seq][2], 1):
            model_pos = ins[1]
            if ins[6] is True:
                for orf in ins[4]:
                    orf_info = orf[0].split('>')[1].split()
                    id = orf_info[0].split('_', 1)[0]
                    name = id2name[id]
                    annotation = orf_info[1]
                    strand = orf_info[7]
                    if strand == '1':
                        strand = '+'
                    else:
                        strand = '-'
                    start, stop = sorted([int(orf_info[3]), int(orf_info[5])])
                    header = (
                        '>%s insertion::seq=%s type=%s strand=%s gene-pos=%s-%s model-pos=%s'
                         % (name, i, annotation, strand, start, stop,
                        model_pos))
                    print('\n'.join([header, orf[1]]), file=orfs)
            if ins[7] is True:
                for intron in ins[5]:
                    id, type, strand, pos = intron[0].split('>', 1)[1].split()
                    name = id2name[id.split('_')[0]]
                    header = (
                        '>%s insertion::seq=%s type=%s strand=%s gene-pos=%s model-pos=%s'
                         % (name, i, type, strand, pos, model_pos))
                    print('\n'.join([header, intron[1]]), file=introns)
            insertion = ins[3]
            id, info = insertion[0].split('>')[1].split(' ', 1)
            name = id2name[id.split('_')[0]]
            header = '>%s %s' % (name, info)
            print('\n'.join([header, insertion[1]]), file=insertions)
    insertions.close()
    orfs.close()
    introns.close()


def transform_resource_name(ctx, param, value):
    """Callback to transform resource_name into title case."""
    if value is not None:
        return value.title()
    return value


def pipeline_code_wrapper(pipeline_code):
    """Generate code specific to the execution of the sklearn pipeline.

    Parameters
    ----------
    pipeline_code: str
        Code that defines the final sklearn pipeline

    Returns
    -------
    Source code for the sklearn pipeline and calls to fit and predict

    """
    return (
        """exported_pipeline = {}

exported_pipeline.fit(training_features, training_target)
results = exported_pipeline.predict(testing_features)
"""
        .format(pipeline_code))


def delete():
    """Erase selected strips from the sequencer

    """
    pass


@staticmethod
def calc_cidr_mask(mask):
    """
        Calculate the CIDR mask from the given full notation subnet mask.
        :param mask: full notation subnet mask (i.e. 255.255.255.0)
        :return: subnet mask in CIDR notation (i.e. /24)
        """
    mask_splitter = mask.split('.')
    cidr_mask = 0
    for i in range(0, len(mask_splitter)):
        mask_octet = format(int(str(bin(int(mask_splitter[i])))[2:], 2),
            '{fill}{width}b'.format(width=8, fill=0))
        cidr_mask += mask_octet.count('1')
    return cidr_mask


def rad_to_scaled(obj, θ_scale):
    """
    Convert from radians to sonic scaled angle
    """
    if obj is None:
        return None
    return obj / θ_scale


def links_detach():
    """Remove all links to selected nodes, and try to connect neighbor nodes together

    """
    pass


def __new__(cls, name, module=None):
    """Make sure there is only one instance per source (file)."""
    from .module import module as M
    module = module or M.current
    qname = module.qname(name)
    if qname not in cls._instances:
        cls._instances[qname] = object.__new__(cls)
    return cls._instances[qname]


def _sacar_coefs_interno(símismo):
    """
        Esta función genera una lista de los coeficientes propios al objeto de interés para la calibración actual.
        Se debe implementar para cada Coso (objeto) que tiene coeficientes.

        :return: Una lista de diccionarios de coeficientes, con el formato siguiente:
           [ {calib1: distribución o [lista de valores],
              calib2: ibid,
              ...},
              {coeficiente 2...},
              ...
           ]
        :rtype: list

        """
    raise NotImplementedError


def add_arguments(parser):
    """Populate the given argparse.ArgumentParser with arguments.

    This function can be used to make the definition these argparse arguments
    reusable in other modules and avoid the duplication of these definitions
    among the executable scripts.

    Parameters
    ----------
    parser : argparse.ArgumentParser
        The parser to populate.

    Returns
    -------
    argparse.ArgumentParser
        Return the populated ArgumentParser object.
    """
    return parser


@classmethod
def process(cls, config_outliers, logger=None):
    """Parse the outliers field of the config dict.

        :param config_outliers: The configuration dict for the outliers field.
        :param logger:          A logger object for logging debug info. [default: None]

        :returns: an Outliers instance
        """
    import piff
    if 'type' not in config_outliers:
        raise ValueError("config['outliers'] has no type field")
    outliers_class = getattr(piff, config_outliers['type'] + 'Outliers')
    kwargs = outliers_class.parseKwargs(config_outliers, logger)
    outliers = outliers_class(**kwargs)
    return outliers


def isfile(obj):
    """
    Check whether obj is a file-like object (file, StringIO)"
    """
    return hasattr(obj, 'flush')


def make_rhs_reminder(rhs, canon):
    """Return a reminder for a relation's right hand side
    (i.e a Comparison object).
    """
    child = rhs.children[0]
    try:
        child = canon['all_variables'][child.variable][0]
    except AttributeError:
        pass
    return rhs.operator, child


def psi_MgOH_HCO3_HSO4_HMW84(T, P):
    """c-a-a': magnesium-hydroxide bicarbonate bisulfate [HMW84]."""
    psi = 0
    valid = T == 298.15
    return psi, valid


def _setsockopt(sock, option, value):
    """
    This wraps setting socket options since python2 vs python3 handles strings differently
    and pyzmq requires a different call. See http://pyzmq.readthedocs.io/en/latest/unicode.html
    """
    try:
        sock.setsockopt(option, value)
    except TypeError:
        sock.setsockopt_string(option, value)


def invalid_node_ids_error(node_ids):
    """
    Return validation error string given when node_ids are not part of CLB

    :param ``list`` node_ids: List of int node_id
    :rtype: ``str``
    """
    nodes = ','.join(map(str, sorted(node_ids)))
    return 'Node ids {0} are not a part of your loadbalancer'.format(nodes)


@classmethod
def read_dataframe(cls, dataframe, wildtype, **kwargs):
    """Construct a GenotypePhenotypeMap from a dataframe."""
    df = dataframe
    self = cls(wildtype, df.genotypes, df.phenotypes, stdeviations=df.
        stdeviations, n_replicates=df.n_replicates, **kwargs)
    return self


def reverse_operator(op):
    """adjusted operators for reversed lhs and rhs"""
    if op == '<':
        rev = '>'
    elif op == '<=':
        rev = '>='
    elif op == '>':
        rev = '<'
    elif op == '>=':
        rev = '<='
    elif op in {'==', '!=', '&', '|', 'in'}:
        rev = op
    else:
        raise Exception(u'operator not implemented')
    return rev


def dottedQuadToNum(ip):
    """
    Convert decimal dotted quad string to long integer

    >>> int(dottedQuadToNum('1 '))
    1
    >>> int(dottedQuadToNum(' 1.2'))
    16777218
    >>> int(dottedQuadToNum(' 1.2.3 '))
    16908291
    >>> int(dottedQuadToNum('1.2.3.4'))
    16909060
    >>> dottedQuadToNum('255.255.255.255')
    4294967295
    >>> dottedQuadToNum('255.255.255.256')
    Traceback (most recent call last):
    ValueError: Not a good dotted-quad IP: 255.255.255.256
    """
    import socket, struct
    try:
        return struct.unpack('!L', socket.inet_aton(ip.strip()))[0]
    except socket.error:
        raise ValueError('Not a good dotted-quad IP: %s' % ip)
    return


def match_texture_space():
    """Match texture space to object’s bounding box

    """
    pass


def filter_accuracy(points, cutoff=30):
    """Filter out points with high reported horizontal accuracy values"""
    for p in points:
        if p['h_accuracy'] <= cutoff:
            yield p


def search_basissets(data_base, args):
    """
    Take the args object and accordingly search for a basis
    set in the database
    """
    kwargs = {'regex': True, 'ignore_case': bool(args.ignorecase)}
    if args.elements:
        kwargs['has_atnums'] = list(args.elements)
    if args.name_regexp:
        kwargs['name'] = args.name_regexp
    if args.description_regexp:
        kwargs['description'] = args.description_regexp
    if args.pattern:
        kwargs['pattern'] = args.pattern
    if args.sources:
        kwargs['sources'] = args.sources
    return data_base.search_basisset(**kwargs)


def unlist(list_of_list):
    """ transform a list of list into one list with all the elements

    Examples
    --------
    >>> unlist([[1,10],[32]])
    [1,10,32]
    >>> unlist([[10],[11],[],[45]])
    [10,11,45]
    """
    res = []
    for l in list_of_list:
        res += l
    return res


@staticmethod
def p_mod_par_optional_list(p):
    """mod_par_optional_list : mod_par_optional
                                 | mod_par_optional mod_par_optional_list"""
    try:
        p[0] = [p[1]] + p[2]
    except IndexError:
        p[0] = [p[1]]


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

        :param ShowcaseEditedDetails val:
        :rtype: EventDetails
        """
    return cls('showcase_edited_details', val)


def convert_to_imgur_list(regular_list):
    """Turn a python list into the list format Imgur expects."""
    if regular_list is None:
        return None
    return ','.join(str(id) for id in regular_list)


def strip_ip_port(ip_address):
    """
    Strips the port from an IPv4 or IPv6 address, returns a unicode object.
    """
    if '.' in ip_address:
        cleaned_ip = ip_address.split(':')[0]
    elif ']:' in ip_address:
        cleaned_ip = ip_address.rpartition(':')[0][1:-1]
    else:
        cleaned_ip = ip_address
    return cleaned_ip


def clipboard_paste():
    """Pastes nodes from the clipboard to the active node tree

    """
    pass


def length(s):
    """
    Null (none) safe length function.

    :param str s: the string to return length of (None allowed)

    :rtype: int
    """
    if s is not None:
        return len(s)
    return 0


def freeze(model):
    """
    Set all layers in a model to non-trainable.

    The weights for these layers will not be updated during training.

    This function modifies the given model in-place,
    but it also returns the modified model to allow easy chaining with other functions.
    """
    for layer in model.layers:
        layer.trainable = False
    return model


def snap(frame: int=0):
    """Frame where selected strips will be snapped

    :param frame: Frame, Frame where selected strips will be snapped
    :type frame: int
    """
    pass


def constraints_clear():
    """Clear all the constraints for the selected bones

    """
    pass


def year_30360(dt):
    """Helper function for thirty360"""
    return dt.year + dt.month / 12 + dt.day / 360


def grad_likelihood(*X, Y=0, W=1):
    """Gradient of the log-likelihood of NMF assuming Gaussian error model.

    Args:
        X:  tuple of (A,S) matrix factors
        Y:  target matrix
        W: (optional weight matrix MxN)

    Returns:
        grad_A f, grad_S f
    """
    A, S = X
    D = W * (A.dot(S) - Y)
    return D.dot(S.T), A.T.dot(D)


def display_name_from_filepath(name):
    """Returns the path stripped of directory and extension, ensured to be utf8 compatible.

    """
    pass


@classmethod
def get_schema_obj(cls):
    """ Returns an instantiated object for Schema associated
                with the model class
        """
    if cls._schema_obj is None:
        cls._schema_obj = cls._schema_cls()
    return cls._schema_obj


def W_from_rep(data: 'AnnData', rep: str) ->'csr_matrix':
    """
    Return affinity matrix W based on representation rep.
    """
    rep_key = 'W_' + rep
    if rep_key not in data.uns:
        raise ValueError(
            'Affinity matrix does not exist. Please run neighbors first!')
    return data.uns[rep_key]


@classmethod
def _get_values(cls, diff_dict, type='new'):
    """
        Returns a dictionaries with the 'new' values in a diff dict.

        type
            Which values to return, 'new' or 'old'
        """
    ret_dict = {}
    for p in diff_dict.keys():
        if type in diff_dict[p].keys():
            ret_dict.update({p: diff_dict[p][type]})
        else:
            ret_dict.update({p: cls._get_values(diff_dict[p], type=type)})
    return ret_dict


def retrieve_data_from_config(msg, cfg):
    """
    Update msg attrs with values from the profile configuration if the
    msg.attr=None, else leave it alone.

    Args:
        :msg: (Message class) an instance of a message class.
        :cfg: (jsonconfig.Config) config instance.
    """
    msg_type = msg.__class__.__name__.lower()
    for attr in msg:
        if getattr(msg, attr) is None and attr in cfg.data[msg.profile][
            msg_type]:
            setattr(msg, attr, cfg.data[msg.profile][msg_type][attr])


def add_application_reference_data_source(ApplicationName=None,
    CurrentApplicationVersionId=None, ReferenceDataSource=None):
    """
    Adds a reference data source to an existing application.
    Amazon Kinesis Analytics reads reference data (that is, an Amazon S3 object) and creates an in-application table within your application. In the request, you provide the source (S3 bucket name and object key name), name of the in-application table to create, and the necessary mapping information that describes how data in Amazon S3 object maps to columns in the resulting in-application table.
    For conceptual information, see Configuring Application Input . For the limits on data sources you can add to your application, see Limits .
    This operation requires permissions to perform the kinesisanalytics:AddApplicationOutput action.
    See also: AWS API Documentation

    :example: response = client.add_application_reference_data_source(
        ApplicationName='string',
        CurrentApplicationVersionId=123,
        ReferenceDataSource={
            'TableName': 'string',
            'S3ReferenceDataSource': {
                'BucketARN': 'string',
                'FileKey': 'string',
                'ReferenceRoleARN': 'string'
            },
            'ReferenceSchema': {
                'RecordFormat': {
                    'RecordFormatType': 'JSON'|'CSV',
                    'MappingParameters': {
                        'JSONMappingParameters': {
                            'RecordRowPath': 'string'
                        },
                        'CSVMappingParameters': {
                            'RecordRowDelimiter': 'string',
                            'RecordColumnDelimiter': 'string'
                        }
                    }
                },
                'RecordEncoding': 'string',
                'RecordColumns': [
                    {
                        'Name': 'string',
                        'Mapping': 'string',
                        'SqlType': 'string'
                    },
                ]
            }
        }
    )

    :type ApplicationName: string
    :param ApplicationName: [REQUIRED]
            Name of an existing application.

    :type CurrentApplicationVersionId: integer
    :param CurrentApplicationVersionId: [REQUIRED]
            Version of the application for which you are adding the reference data source. You can use the DescribeApplication operation to get the current application version. If the version specified is not the current version, the ConcurrentModificationException is returned.

    :type ReferenceDataSource: dict
    :param ReferenceDataSource: [REQUIRED]
            The reference data source can be an object in your Amazon S3 bucket. Amazon Kinesis Analytics reads the object and copies the data into the in-application table that is created. You provide an S3 bucket, object key name, and the resulting in-application table that is created. You must also provide an IAM role with the necessary permissions that Amazon Kinesis Analytics can assume to read the object from your S3 bucket on your behalf.
            TableName (string) -- [REQUIRED]Name of the in-application table to create.
            S3ReferenceDataSource (dict) --Identifies the S3 bucket and object that contains the reference data. Also identifies the IAM role Amazon Kinesis Analytics can assume to read this object on your behalf.
            An Amazon Kinesis Analytics application loads reference data only once. If the data changes, you call the UpdateApplication operation to trigger reloading of data into your application.
            BucketARN (string) -- [REQUIRED]Amazon Resource Name (ARN) of the S3 bucket.
            FileKey (string) -- [REQUIRED]Object key name containing reference data.
            ReferenceRoleARN (string) -- [REQUIRED]ARN of the IAM role that the service can assume to read data on your behalf. This role must have permission for the s3:GetObject action on the object and trust policy that allows Amazon Kinesis Analytics service principal to assume this role.
            ReferenceSchema (dict) -- [REQUIRED]Describes the format of the data in the streaming source, and how each data element maps to corresponding columns created in the in-application stream.
            RecordFormat (dict) -- [REQUIRED]Specifies the format of the records on the streaming source.
            RecordFormatType (string) -- [REQUIRED]The type of record format.
            MappingParameters (dict) --When configuring application input at the time of creating or updating an application, provides additional mapping information specific to the record format (such as JSON, CSV, or record fields delimited by some delimiter) on the streaming source.
            JSONMappingParameters (dict) --Provides additional mapping information when JSON is the record format on the streaming source.
            RecordRowPath (string) -- [REQUIRED]Path to the top-level parent that contains the records.
            For example, consider the following JSON record:
            In the RecordRowPath , '$' refers to the root and path '$.vehicle.Model' refers to the specific 'Model' key in the JSON.
            CSVMappingParameters (dict) --Provides additional mapping information when the record format uses delimiters (for example, CSV).
            RecordRowDelimiter (string) -- [REQUIRED]Row delimiter. For example, in a CSV format, 'n' is the typical row delimiter.
            RecordColumnDelimiter (string) -- [REQUIRED]Column delimiter. For example, in a CSV format, a comma (',') is the typical column delimiter.

            RecordEncoding (string) --Specifies the encoding of the records in the streaming source. For example, UTF-8.
            RecordColumns (list) -- [REQUIRED]A list of RecordColumn objects.
            (dict) --Describes the mapping of each data element in the streaming source to the corresponding column in the in-application stream.
            Also used to describe the format of the reference data source.
            Name (string) -- [REQUIRED]Name of the column created in the in-application input stream or reference table.
            Mapping (string) --Reference to the data element in the streaming input of the reference data source.
            SqlType (string) -- [REQUIRED]Type of column created in the in-application input stream or reference table.

    :rtype: dict
    :return: {}

    :returns:
    (dict) --

    """
    pass


@classmethod
def collapse(cls, holomap, ranges=None, mode='data'):
    """
        Given a map of Overlays, apply all applicable compositors.
        """
    if cls.definitions == []:
        return holomap
    clone = holomap.clone(shared_data=False)
    data = zip(ranges[1], holomap.data.values()
        ) if ranges else holomap.data.items()
    for key, overlay in data:
        clone[key] = cls.collapse_element(overlay, ranges, mode)
    return clone


def filter_colony_size(colony_df, cluster_params, colony_name):
    """Assign -1 label to too small and too large colonies."""
    colony_size = colony_df.shape[0]
    if not cluster_params['min_size'] < colony_size < cluster_params['max_size'
        ]:
        colony_df['Colony'] = -1
        colony_name = -1
    return colony_df, colony_size, colony_name


def __ne__(A, other):
    """Returns true if both objects are not equal"""
    return not A == other


def get_longest_contig_list(readers):
    """
    Get the largest list of contig names from a list of readers
    :param readers: list of vcf readers
    :return: list of contig names
    """
    sorted_readers = sorted(readers, key=lambda x: len(x.contigs))
    return sorted_readers[-1].contigs.keys()


def duplicate_move(GRAPH_OT_duplicate=None, TRANSFORM_OT_transform=None):
    """Make a copy of all selected keyframes and move them

    :param GRAPH_OT_duplicate: Duplicate Keyframes, Make a copy of all selected keyframes
    :param TRANSFORM_OT_transform: Transform, Transform selected items by mode type
    """
    pass


@staticmethod
def midpoint(start, end):
    """Returns the midpoint between two dates"""
    return start + (end - start) / 2


def render_pep440_pre(pieces):
    """TAG[.post.devDISTANCE] -- No -dirty.

    Exceptions:
    1: no tags. 0.post.devDISTANCE
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance']:
            rendered += '.post.dev%d' % pieces['distance']
    else:
        rendered = '0.post.dev%d' % pieces['distance']
    return rendered


def delSomeKeywords(hdr):
    """Delete exposure-specific keywords.

    Parameters
    ----------
    hdr: pyfits Header object
        Extension header to be modified
    """
    for key in ['shift1a', 'shift1b', 'shift1c', 'shift2a', 'shift2b',
        'shift2c', 'dpixel1a', 'dpixel1b', 'dpixel1c']:
        if key in hdr:
            del hdr[key]


def time_to_longdouble(t):
    """ Return an astropy Time value as MJD in longdouble

    The returned value is accurate to within a nanosecond, while the precision of long
    double MJDs (near the present) is roughly 0.7 ns.

    """
    if t.format.startswith('pulsar_mjd'):
        return t.pulsar_mjd_long
    else:
        return t.mjd_long


def select_interior_faces():
    """Select faces where all edges have more than 2 face users

    """
    pass


def GetMeasurementsScalar(*args, **kwargs):
    """ Stub Anduin function."""
    print('GetMeasurementsScalar', args, kwargs)


def first_letter_lower(input_string):
    """
    Returns a new string with the first letter as lowercase
    :param input_string: str
    :return: str
    """
    return input_string[:1].lower() + input_string[1:]