def addToFragments(fragments, qname, chromosome, rstart, rend, cell_barcode,
    is_reverse, max_dist):
    """Add new fragment information to dictionary

    Parameters
    ----------

    fragments : dict
        A dictionary containing all the fragment information
    qname : str
        Read name
    chromosome : str
        Chromosome name
    rstart : int
        Alignment start position
    rend : int
        Alignment end position
    cell_barcode : str
        Cell barcode sequence
    is_reverse : bool
        Read is aligned to reverse strand
    max_dist : int
        Maximum allowed fragment size
    """
    if qname in fragments.keys():
        if is_reverse:
            current_coord = fragments[qname][1]
            if current_coord is None:
                del fragments[qname]
            elif rend - current_coord > max_dist or rend - current_coord < 0:
                del fragments[qname]
            elif cell_barcode is None and fragments[qname][3] is None:
                del fragments[qname]
            else:
                if fragments[qname][3] is None:
                    fragments[qname][3] = cell_barcode
                fragments[qname][2] = rend
                fragments[qname][4] = True
        else:
            current_coord = fragments[qname][2]
            if current_coord is None:
                del fragments[qname]
            elif current_coord - rstart > max_dist or current_coord - rstart < 0:
                del fragments[qname]
            elif cell_barcode is None and fragments[qname][3] is None:
                del fragments[qname]
            else:
                if fragments[qname][3] is None:
                    fragments[qname][3] = cell_barcode
                fragments[qname][1] = rstart
                fragments[qname][4] = True
    else:
        fragments[qname] = [chromosome, None, None, cell_barcode, False]
        if is_reverse:
            fragments[qname][2] = rend
        else:
            fragments[qname][1] = rstart
    return fragments


def fuzzyMatch(string1, string2):
    """Compare the English character content of two strings."""
    replacements = {'1': 'one', '2': 'two', '3': 'three', '4': 'four', '5':
        'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine',
        'gonna': 'going to'}
    whiteout = '.,"\'!?/$()'
    string1 = string1.strip().lower()
    string2 = string2.strip().lower()
    for num, word in replacements.items():
        string1 = string1.replace(num, word)
        string2 = string2.replace(num, word)
    for char in whiteout:
        string1 = string1.replace(char, '')
        string2 = string2.replace(char, '')
    return string1 == string2


@staticmethod
def setExcludeEntries(exclude, entries):
    """
        Set the Exclude object from the array of ExcludeEntry.

        :param Exclude exclude: The Exclude object to update.
        :param Array<ExcludeEntry> entries: The array of ExcludeEntry.
        """
    exclude.clear()
    for i in range(len(entries)):
        entry = entries[i]
        if i == 0 and entry._component.getValue().size(
            ) == 0 and entry._anyFollowsComponent:
            exclude.appendAny()
        else:
            exclude.appendComponent(entry._component)
            if entry._anyFollowsComponent:
                exclude.appendAny()


def cosh(data=None, name=None, attr=None, out=None, **kwargs):
    """Returns the hyperbolic cosine  of the input array, computed element-wise.

    .. math::
       cosh(x) = 0.5\\times(exp(x) + exp(-x))

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

    Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L351

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

    name : string, optional.
        Name of the resulting symbol.

    Returns
    -------
    Symbol
        The result symbol.
    """
    return 0,


def yesno(prompt, default=None):
    """
    Prompt the user for a yes or no.

    Can optionally specify a default value, which will only be
    used if they enter a blank line.

    Unrecognised input (anything other than "y", "n", "yes",
    "no" or "") will return None.
    """
    answer = input(prompt).strip().lower()
    if answer == 'y' or answer == 'yes':
        return True
    elif answer == 'n' or answer == 'no':
        return False
    elif answer == '':
        return default
    else:
        return None


def age(asof, dob):
    """
    get age as of a date based on birth date

    :param asof: datetime object, get age asof date based on dob birth date
    :param dob: datetime object, get age asof date based on dob birth date
    """
    return asof.year - dob.year - int((asof.month, asof.day) < (dob.month,
        dob.day))


def search_index_file():
    """Return the default local index file, from the download cache"""
    from metapack import Downloader
    from os import environ
    return environ.get('METAPACK_SEARCH_INDEX', Downloader.get_instance().
        cache.getsyspath('index.json'))


@staticmethod
def positional_to_model(value):
    """Converts a positional argument to a model value"""
    return value


def escape_env_var(varname):
    """
    Convert a string to a form suitable for use as an environment variable.

    The result will be all uppercase, and will have all invalid characters
    replaced by an underscore.

    The result will match the following regex: [a-zA-Z_][a-zA-Z0-9_]*

    Example:
        "my.private.registry/cat/image" will become
        "MY_PRIVATE_REGISTRY_CAT_IMAGE"
    """
    varname = list(varname.upper())
    if not varname[0].isalpha():
        varname[0] = '_'
    for i, c in enumerate(varname):
        if not c.isalnum() and c != '_':
            varname[i] = '_'
    return ''.join(varname)


@classmethod
def fromkeys(cls, iterable, value=None):
    """OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
        and values equal to v (which defaults to None).

        """
    d = cls()
    for key in iterable:
        d[key] = value
    return d


def setattrdefault(obj, attribute, default=None):
    """Setdefault for attribute.

    Returns 'attribute' value if defined or set it to default and return it.
    """
    try:
        return getattr(obj, attribute)
    except AttributeError:
        setattr(obj, attribute, default)
        return default


def DFaddCatToSubcat(df):
    """this is for final assy schedule
    first column is main category
    second column is subcategory
    if first column is blank but 2nd isn't
    then copy string from previous col to current"""
    from pandas import DataFrame, isnull
    ind = df.index.values
    for i in range(1, len(ind)):
        if isnull(df.iat[i, 0]) and not isnull(df.iat[i, 1]):
            df.iat[i, 0] = df.iat[i - 1, 0]
    return df


def varint_max_size(max_value):
    """Returns the maximum number of bytes a varint can take when encoded."""
    if max_value < 0:
        max_value = 2 ** 64 - max_value
    for i in range(1, 11):
        if max_value >> i * 7 == 0:
            return i
    raise ValueError('Value too large for varint: ' + str(max_value))


def ext_mid(data):
    """
    Extract the middle of the spectrum.

    Parameters
    ----------
    data : ndarray
        Array of NMR data.

    Returns
    -------
    ndata : ndarray
        Middle half of spectrum.

    """
    return data[(...), int(data.shape[-1] * 1.0 / 4.0):int(data.shape[-1] *
        3.0 / 4.0)]


def indent(s: str, n: int) ->str:
    """Indent all the lines in s (separated by newlines) by n spaces."""
    s = ' ' * n + s
    s = s.replace('\n', '\n' + ' ' * n)
    return s


@staticmethod
def _get_image(image_builder, runtime, layers):
    """
        Returns the name of Docker Image for the given runtime

        Parameters
        ----------
        image_builder samcli.local.docker.lambda_image.LambdaImage
            LambdaImage that can be used to build the image needed for starting the container
        runtime str
            Name of the Lambda runtime
        layers list(str)
            List of layers

        Returns
        -------
        str
            Name of Docker Image for the given runtime
        """
    return image_builder.build(runtime, layers)


def get_hl(A):
    """ Return the half-left of the given array.
    """
    nx, _ = A.shape
    li = int(nx / 2)
    return A[:, :li]


@classmethod
def create_dry_run(cls, params):
    """Create a new contact."""
    return cls.call('contact.create', dict(params), empty_key=True, dry_run
        =True, return_dry_run=True)


def atse_fieldMoveRight(schema_id, schema_template, name, RESPONSE=None):
    """ move a field of a schemata to the right"""


def _percent_former(curr, leng):
    """Formats a more-consistent of percent and fraction list. Shows like :
    100.0% Completed [1/1]"""
    percent = '{:{fill}{width}.1%} Completed'.format(curr / leng, fill=0,
        width=len(str(leng)) + 3)
    content = '[{:{fill}{width}}/{length}]'.format(curr, fill=0, width=len(
        str(leng)), length=leng)
    return percent + ' ' + content + ' :'


@classmethod
def shorten_id(cls, internal_id):
    """
        Returns the shortcode for a numeric media PK

        :param internal_id: numeric ID value
        :return:
        """
    return cls._encode(internal_id)


def nag_function_is_constant(name):
    """
    Check wether a NAG function name is of type constant
    """
    if name[0:1] == 'c':
        return True
    else:
        return False


def walk_pkg_gen(pathObject):
    """
      Description: Yields pathobject that has only file extension of pks or pkb
    """
    glob_spec_or_body = '*.pk[sb]'
    for f in pathObject.rglob(glob_spec_or_body):
        yield f


@classmethod
def from_dict(cls, connection, data):
    """
        Returns a Space object from a dictionary item,
        which is usually from Appoptics's API
        """
    obj = cls(connection, data['name'], id=data['id'], chart_dicts=data.get
        ('charts'), tags=data.get('tags'))
    return obj


def _breadth_first_iter(loc):
    """
    Given a loctation node (from a zipper) walk it's children in breadth first
    order.
    """
    tocheck = [loc]
    while tocheck:
        l = tocheck.pop(0)
        yield l
        child = l.down()
        while child:
            tocheck.append(child)
            child = child.right()


@classmethod
def unit_attname(cls, unit_str):
    """
        Retrieves the unit attribute name for the given unit string.
        For example, if the given unit string is 'metre', 'm' would be returned.
        An exception is raised if an attribute cannot be found.
        """
    lower = unit_str.lower()
    if unit_str in cls.UNITS:
        return unit_str
    elif lower in cls.UNITS:
        return lower
    elif lower in cls.LALIAS:
        return cls.LALIAS[lower]
    else:
        raise Exception(
            'Could not find a unit keyword associated with "%s"' % unit_str)


def _generate_func_api():
    """Auto detect all available interfaces and generate a function-based
       API from them
    """
    from importlib import import_module
    from .interface.base import update_docstring_with_parameters
    from .interface.base import get_interface_groups
    from .interface.base import get_api_name
    from .interface.base import alter_interface_docs_for_api
    for grp_name, grp_descr, interfaces in get_interface_groups():
        for intfspec in interfaces:
            mod = import_module(intfspec[0], package='niceman')
            intf = getattr(mod, intfspec[1])
            spec = getattr(intf, '_params_', dict())
            update_docstring_with_parameters(intf.__call__, spec, prefix=
                alter_interface_docs_for_api(intf.__doc__), suffix=
                alter_interface_docs_for_api(intf.__call__.__doc__))
            globals()[get_api_name(intfspec)] = intf.__call__


def doc_arg(name, brief):
    """argument of doc_string"""
    return '    :param {0}: {1}'.format(name, brief)


def extrude_repeat(offset: float=2.0, steps: int=10):
    """Extrude selected vertices, edges or faces repeatedly

    :param offset: Offset
    :type offset: float
    :param steps: Steps
    :type steps: int
    """
    pass


def is_receiver(metric):
    """Is interface ``metric`` a receiver?

    :param dict metric: The metric.
    :rtype: :py:class:`bool`

    """
    return metric.get('name', '').endswith('rx')


def find_tensors(sources, predicate):
    """
    find all the tensors that are used for computing grads and has been
    computed during forward
    :param grads:
    :param forward_ops:
    :return:
    """
    from collections import deque
    import tensorflow as tf
    queue = deque([])
    for source in sources:
        queue.append(source)
    results = set()
    visited = set()
    while len(queue) > 0:
        node = queue.popleft()
        if node is None:
            continue
        else:
            visited.add(node.name)
            if predicate(node):
                results.add(node)
            if isinstance(node, tf.Tensor):
                inputs = list(node.op.inputs) + list(node.op.control_inputs)
            elif isinstance(node, tf.Operation):
                inputs = list(node.inputs) + list(node.control_inputs)
            else:
                raise ValueError('Unrecognized Node: {}'.format(node))
            for input_tensor in inputs:
                if input_tensor.name not in visited:
                    queue.append(input_tensor)
    return list(results)


def p_pool_decl(p):
    """ pool_decl : POOL BRACE_OPEN pool_content BRACE_CLOSE """
    p[0] = {p[1]: p[3]}


def assert_query_has_qmark(query: str, context: str='') ->None:
    """Throws Exception if the query does not contain any question marks."""
    if '?' in query:
        return
    message = ''
    if context:
        message = ' ' + context
    message = (message +
        "Query commands must contain question-marks. Sent query: '{0}'".
        format(query.strip('\n')))
    raise Exception(message)


def string_join(*ss):
    """
    String joins with arbitrary lengthy parameters

    :param ss: strings to be joined
    :return: strings joined
    """
    return ''.join(ss)


def check_first_arg_false(first, *args):
    """
    Check first arg is false.

    :param first:
        First arg.
    :type first: T

    :return:
        If first arg is false.
    :rtype: bool
    """
    return not bool(first)


def cMultiplyVecInplace():
    """
    Return the kernel source of cMultiplyVecInplace.
    """
    R = """
        KERNEL void cMultiplyVecInplace(
                const unsigned int batch,
                GLOBAL_MEM const float2 *a,
                GLOBAL_MEM float2 *outb)
        {
        const unsigned int gid = get_global_id(0);
        // const unsigned int voxel_id = gid / batch;
        const unsigned int voxel_id = (float)gid / (float)batch;

        float2 mul = a[voxel_id];
        float2 orig = outb[gid];
        float2 tmp;
        tmp.x=orig.x*mul.x-orig.y*mul.y;
        tmp.y=orig.x*mul.y+orig.y*mul.x;
        outb[gid]=tmp;
        };
        """
    return R


def FWHMgeom2FWHMeff(FWHMgeom):
    """
    Convert FWHMgeom to FWHMeff.
    This conversion was calculated by Bo Xin and Zeljko Ivezic (and will be in an update on the LSE-40 and overview papers).
    @param [in] FWHMgeom (the geometric FWHM value, as measured from a typical PSF profile) in arcseconds
    @param [out] FWHMeff (the single-gaussian equivalent FWHM value, appropriate for calcNeff) in arcseconds
    """
    FWHMeff = (FWHMgeom - 0.052) / 0.822
    return FWHMeff


def make_stopwords(punctuation=True):
    """Makes and returns a stopwords_list for enlgish combined with punctuation(default)."""
    import nltk
    from nltk.corpus import stopwords
    try:
        stopwords.words('english')
    except LookupError:
        nltk.download('stopwords', quiet=True)
    import string
    stopwords_list = []
    stopwords_list = stopwords.words('english') + list(string.punctuation)
    stopwords_list += ["''", '""', '...', '``']
    return stopwords_list


def empty_pola(pola):
    """
    Check if *pola* not empty.

    :raises RuntimeError: Run method get_eig(eigenvec=True) first.
    """
    if pola.size == 0:
        raise RuntimeError('\n\nRun method get_eig(eigenvec=True) first\n')


@staticmethod
def filter_out_option(option):
    """ Filter out non-processor configurations """
    options_to_filter = ['cpu', 'cuda', 'dev_conll_gold', 'epochs', 'lang',
        'mode', 'save_name', 'shorthand']
    if option.endswith('_file') or option.endswith('_dir'):
        return True
    elif option in options_to_filter:
        return True
    else:
        return False


def assert_bytes(*args):
    """
    porting helper, assert args type
    """
    try:
        for x in args:
            assert isinstance(x, (bytes, bytearray))
    except:
        print('assert bytes failed', list(map(type, args)))
        raise


def get_x_intersection(y, polygon):
    """
    For a given 2D polygon, return a list of x-coordinates which crosses a given y.
    The 2D polygon is assumed closed, but the last point should not be repeated.

    :param float y: a given y coordinate
    :param polygon: a list of points, in the form [[x0,y0], [x1,y1], ...  [xn,yn]]

    :returns: a list of x coordinates.
    """
    intersections = []
    x1 = polygon[0][0]
    y1 = polygon[0][1]
    n = len(polygon)
    for i in range(n + 1):
        x2 = polygon[i % n][0]
        y2 = polygon[i % n][1]
        if y > min(y1, y2):
            if y <= max(y1, y2):
                x = (x2 - x1) / (y2 - y1) * (y - y1) + x1
                intersections.append(x)
        x1 = x2
        y1 = y2
    return intersections


def parse_orgs(org_file):
    """Parse csv table for organisms selection
    input: csv file with organisms
    return: set of organisms to exclude, set of organisms
    for which we want to select paralogs"""
    to_exlude = set()
    paralogs = set()
    with open(org_file) as lines:
        header = next(lines)
        if header.count(',') == 10:
            sgt_idx = 9
        else:
            sgt_idx = 6
        for line in lines:
            org = line.split(',')[0]
            sgt = line.split(',')[sgt_idx].strip()
            if sgt.lower() != 'yes':
                to_exlude.add(org)
            if header.count(',') == 10:
                if line.split(',')[sgt_idx + 1].strip().lower() == 'yes':
                    if org not in to_exlude:
                        paralogs.add(org)
    return to_exlude, paralogs


def itertuples_raw(df, discrete, weighted=False):
    """`df.itertuples` in a raw form left and right bound."""
    kargs = {}
    if not discrete:
        kargs['bounds'] = True
    if weighted:
        kargs['weights'] = True
    return df.itertuples(**kargs)


@staticmethod
def _write_container_output(output_itr, stdout=None, stderr=None):
    """
        Based on the data returned from the Container output, via the iterator, write it to the appropriate streams

        Parameters
        ----------
        output_itr: Iterator
            Iterator returned by the Docker Attach command
        stdout: samcli.lib.utils.stream_writer.StreamWriter, optional
            Stream writer to write stdout data from Container into
        stderr: samcli.lib.utils.stream_writer.StreamWriter, optional
            Stream writer to write stderr data from the Container into
        """
    for stdout_data, stderr_data in output_itr:
        if stdout_data and stdout:
            stdout.write(stdout_data)
        if stderr_data and stderr:
            stderr.write(stderr_data)


def removeNodeChildren(node):
    """Removes all child nodes from the specified node.
    """
    for ch in reversed(node.childNodes):
        node.removeChild(ch)
        ch.unlink()


def raiseLater(_self, _obj, *args, **kw):
    """
    This is similar to callLater(), but provides an easy way to raise a
    revent event from outide the co-operative context.
    Rather than foo.raiseEvent(BarEvent, baz, spam), you just do
    core.raiseLater(foo, BarEvent, baz, spam).
    """
    _self.scheduler.callLater(_obj.raiseEvent, *args, **kw)


@staticmethod
def _envvar_to_ini(key):
    """Transforms an env var formatted key to ini formatting."""
    if key.startswith('CKAN___'):
        key = key[7:]
    key = key.lower()
    key = key.replace('__', '.')
    return key


def _justify_pair(pair, width=80, padding_with='.'):
    """align first element along the left margin, second along the right, padding spaces"""
    n = width - len(pair[0])
    return '{key}{value:{c}>{n}}'.format(key=pair[0], value=pair[1], c=
        padding_with, n=n)


def option_wrong_value_msg(name, value, value_range):
    """ The provided value is not among the range of values that it should
    be
    """
    return (
        "'%s' is not a valid 'options.%s' value.\nPossible values are %s" %
        (value, name, value_range))


def categorical_excess_cardinality_flagger_and_reducer(df, useful_cols,
    cardinality_fraction_threshold=0.1,
    cardinality_max_categories_threshold=50, **kwargs):
    """
    Function inspects categorical features in the input dataframe where there is excess cardinality (too many unique     values), and returns a list of features which exceed these thresholds, as well as Series detailing the cardinality     (in absolute terms as well as as a fraction of the total number of samples).

    Parameters
    ----------
    df : pandas.DataFrame
        The input dataframe
    useful_cols : pandas.DataFrame
        Look-up dataframe, which contains information about the dtypes of desired features, and how to deal with
        missing values for each feature
    cardinality_fraction_threshold : int or None
        Cardinality fraction is the ratio of unique values for a given feature to the total number of samples in the dataset
        - If None, no threshold applied
        - If int, this is the threshold beyond which a feature is deemed to have excessive cardinality
    cardinality_max_categories_threshold : int or None
        Cardinality max categories is the absolute number of unique values for a given feature
        - If None, no threshold applied
        - If int, this is the threshold beyond which a feature is deemed to have excessive cardinality

    Returns
    -------
    df_cardinality : pandas.Series
        Cardinality (number of unique elements) of the categorical features in the input dataset
    df_cardinality_fraction : pandas.Series
        Cardinality fractions of the categorical features in the input dataset
    excess_cardinality : list
        List of features which exceed one or more of the thresholds

    """
    categorical_features = list(useful_cols.loc[useful_cols.dtype ==
        'nominal', 'feature'])
    categorical_data = df[categorical_features]
    m_samples = categorical_data.shape[0]
    df_cardinality = categorical_data.nunique()
    df_cardinality_fraction = df_cardinality / m_samples
    excess_cardinality_fraction = set(df_cardinality_fraction[
        df_cardinality_fraction > cardinality_fraction_threshold].index)
    print(
        f'Following features exceed cardiality fraction threshold of {cardinality_fraction_threshold}: {excess_cardinality_fraction}'
        )
    excess_cardinality_absolute = set(df_cardinality[df_cardinality >
        cardinality_max_categories_threshold].index)
    print(
        f'Following features exceed cardiality absolute number threshold of {cardinality_max_categories_threshold}: {excess_cardinality_absolute}'
        )
    excess_cardinality = list(set.union(excess_cardinality_fraction,
        excess_cardinality_absolute))
    if kwargs['reducer'] == True:
        n_max_categories = kwargs['reducer_max_categories']
        for feature in excess_cardinality:
            value_counts = df[feature].value_counts()
            small_categories = list(value_counts[n_max_categories:].index)
            df.loc[df[feature].isin(small_categories), feature
                ] = 'SMALL_CATEGORY'
        print(
            f'Features {excess_cardinality} exceeded thresholds and have each been reduced down to a maximum {n_max_categories} categories per feature'
            )
    return df_cardinality, df_cardinality_fraction, excess_cardinality


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 all_(f, iterable):
    """
    all :: Foldable t => (a -> Bool) -> t a -> Bool
    Determines whether all elements of the structure satisfy the predicate.
    """
    for x in iterable:
        if not f(x):
            return False
    return True


def __contains__(name):
    """ Does the container contains an object named by name?

        ``name`` must be a Unicode object or a bytestring object.

        If ``name`` is a bytestring object, it must be decodable using the
        system default encoding or the UTF-8 encoding.
        """


@classmethod
def _iterate(cls, container):
    """Iterate over the contents of the container. Each element returned
        should be a tuple including an index and a value.

        Args:
            container (obj): Object to be iterated over.

        Returns:
            iterator: Iterator over elements in the container.

        """
    for k, v in container.items():
        yield k, v


def history_entry():
    """ Creates a new entry in the history
        """


def predicative(adjective):
    """ Returns the predicative adjective (lowercase).
        In German, the attributive form preceding a noun is always used:
        "ein kleiner Junge" => strong, masculine, nominative,
        "eine schöne Frau" => mixed, feminine, nominative,
        "der kleine Prinz" => weak, masculine, nominative, etc.
        The predicative is useful for lemmatization.
    """
    w = adjective.lower()
    if len(w) > 3:
        for suffix in ('em', 'en', 'er', 'es', 'e'):
            if w.endswith(suffix):
                b = w[:max(-len(suffix), -(len(w) - 3))]
                if b.endswith('bl'):
                    b = b[:-1] + 'el'
                if b.endswith('pr'):
                    b = b[:-1] + 'er'
                return b
    return w


@staticmethod
def int_to_hex(intval):
    """A convenience function, use format to convert int to hex"""
    if type(intval) == 'string':
        intval = int(intval)
    return '{:02}'.format(intval, 'x')


def parse_errata_checksum(data):
    """ Parse the errata checksum and return the bz2 checksum
    """
    for line in data.splitlines():
        if line.endswith('errata.latest.xml.bz2'):
            return line.split()[0]


def _get_attribute_tensors(onnx_model_proto):
    """Create an iterator of tensors from node attributes of an ONNX model."""
    for node in onnx_model_proto.graph.node:
        for attribute in node.attribute:
            if attribute.HasField('t'):
                yield attribute.t
            for tensor in attribute.tensors:
                yield tensor


@staticmethod
def build_query(query, model, form_args):
    """
        *Hook method*. Modify given query according to the given arguments.
        """
    return query


def join(expr, lh_arg, rh_arg):
    """Helper function to combine arguments.
    """
    if lh_arg is None or rh_arg is None:
        return None
    else:
        return expr.copy([lh_arg, rh_arg])


def _get_ps_strategy(job_name, ps_specs):
    """ Returns the param server strategy to use """
    if job_name != 'worker' or len(ps_specs) <= 1:
        return None
    from diplomacy_research.utils.tensorflow import GreedyLoadBalancingStrategy, byte_size_load_fn
    return GreedyLoadBalancingStrategy(num_tasks=len(ps_specs), load_fn=
        byte_size_load_fn)


@classmethod
def _name(cls):
    """Helper to get the class name once it's been created"""
    return cls.__name__


def download_result_from_gs(bucket_name, blob_name, to_filename=None):
    """Download a file from Google Cloud Storage.

    This function assumes that the local environment is configured to access the
    target bucket. This would typically be done through the gcloud command line
    utility. More information can be found here:
    https://cloud.google.com/sdk/gcloud/

    The credentials can also be overriden with Service Account credentials
    directly through the `GOOGLE_APPLICATION_CREDENTIALS` environment variable:
    https://cloud.google.com/docs/authentication/getting-started
    """
    try:
        from google.cloud import storage
    except ImportError:
        raise Exception(
            'The google-cloud-storage package is required to download results from Google Cloud Storage buckets. For details, see: https://pypi.org/project/google-cloud-storage/'
            )
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    if blob_name[0] == '/':
        blob_name = blob_name[1:]
    blob = bucket.blob(blob_name)
    if to_filename:
        blob.download_to_filename(to_filename)
        return to_filename
    else:
        return blob.download_as_string()


def active_frame_delete():
    """Delete the active frame for the active Grease Pencil Layer

    """
    pass


def asbool(value):
    """Convert the given String to a boolean object.

    Accepted values are `True` and `1`.
    """
    if value is None:
        return False
    if isinstance(value, bool):
        return value
    return value.lower() in ('true', '1')


def filter_tracks(track_threshold: float=5.0):
    """Filter tracks which has weirdly looking spikes in motion curves

    :param track_threshold: Track Threshold, Filter Threshold to select problematic tracks
    :type track_threshold: float
    """
    pass


@classmethod
def db_type(cls, dtype):
    """Given a numpy dtype, Returns a generic database type"""
    return cls.type_map.get(dtype.char)


def p_arreglo(p):
    """arreglo : '[' arregloD ']'
               | arregloD
    """
    if len(p) > 2:
        p[0] = p[2]
    else:
        p[0] = p[1]


def connect(mask):
    """ Find if a mask is singly or multiply connected """
    import scipy.ndimage as nd
    connectivity = nd.generate_binary_structure(2, 2)
    labels, count = nd.label(mask, connectivity)
    if count > 1:
        connected = 'multiple'
    else:
        connected = 'single'
    return connected, count


def _getDict(j9Page):
    """Parses a Journal Title Abbreviations page

    Note the pages are not well formatted html as the
 tags are not closes so html parses (Beautiful Soup) do not work. This is a simple parser that only works on the webpages and may fail if they are changed

    For Backend
    """
    slines = j9Page.read().decode('utf-8').split('\n')
    while slines.pop(0) != '
':
        pass
    currentName = slines.pop(0).split('">
')[1]
    currentTag = slines.pop(0).split('
\t')[1]
    j9Dict = {}
    while True:
        try:
            j9Dict[currentTag].append(currentName)
        except KeyError:
            j9Dict[currentTag] = [currentName]
        try:
            currentName = slines.pop(0).split('
')[1]
            currentTag = slines.pop(0).split('
\t')[1]
        except IndexError:
            break
    return j9Dict


@staticmethod
def storeDB(conn, ipv4addrs):
    """Overwrite the addresses in the table with the specified addresses (string) in the database."""
    connection = conn.cursor()
    vals = []
    for ipv4addr in ipv4addrs:
        vals.append((ipv4addr,))
    connection.execute('delete from ipv4addr')
    connection.executemany('insert into ipv4addr(addr) values (?)', iter(vals))
    connection.close()


def call_post_parsing(ruleset):
    """Run all post processing hooks."""
    ruleset.ctxt.hook_parsing_end(ruleset)
    ruleset.ctxt.log.info('%s rules loaded', len(ruleset.checked))
    ruleset.call_postparsing()


def _apply_properties(widget, properties={}):
    """Applies the specified properties to the widget.

    `properties` is a dictionary with key value pairs corresponding
    to the properties to be applied to the widget.
    """
    with widget.hold_sync():
        for key, value in properties.items():
            setattr(widget, key, value)


def delete_client_certificate(clientCertificateId=None):
    """
    Deletes the  ClientCertificate resource.
    See also: AWS API Documentation

    :example: response = client.delete_client_certificate(
        clientCertificateId='string'
    )

    :type clientCertificateId: string
    :param clientCertificateId: [REQUIRED]
            The identifier of the ClientCertificate resource to be deleted.

    """
    pass


def convert_channel_id_to_short_channel_id(channel_id):
    """
    Converts a channel id to blockheight, transaction, output
    """
    return channel_id >> 40, channel_id >> 16 & 16777215, channel_id & 65535


@classmethod
def RegisterAdditionalConversionType(cls, class_, func):
    """
        This function may be used to register conversions for additional classes, not originally
        treated (e.g.: IGridFunction)

        :param type class_:
            This is the class that should be treated. So, when a conversion is requested,
            if a class is an instance of the class passed, it'll be used to do the conversions.

        :param callable func:
            The function that should do the conversion. It'll be called as
            func(unit_database, quantity_type, from_unit_info, to_unit_info, value)
        """
    if class_ not in cls._additional_conversions:
        cls._additional_conversions[class_] = func
    else:
        assert cls._additional_conversions[class_
            ] == func, 'The class %s already has a convertion function registered' % str(
            class_)


def _unfold_geometry(outer, inner_i, middle):
    """Return an list of unfolded, stacking sequence given converted geo_string tokens.

    Parameters
    ----------
    outer : tuple
        The outer token of a parsed geometry string, split by '-'.  May contain
        a string representation of an int, float or duple.
    inner_i : list
        The inner_i token of a parsed geometry string, split by '-'.  May contain
        string representations of an ints, floats and/or duples.
    middle: float or int
        The middle token of a parsed geometry string, split by '-'.  Must contain
        a string representation of an float.  Use _get_middle().

    Notes
    -----
    Unlike the Stack() parsing functions that decode Geometry objects, this function
    decodes geometry strings. This approach may have performance benefits.

    The workflow for creating an ordered stack sequence is manual, contained in a list:
       outer1 + inner_i + middle + inner_i(reversed) + outer2

    The outer is checked for a duple.  If one is found, the tensile entry is parsed.
    The inner_i is forward iterated, parsing only tensile inners if duples found.
    Next the middle is added to the list, pre-processed, stripped of symmetry flag.
    The inner_i is iterated over a reversed list.
    The final outer is checked for a duple.  If one is found, compressive entry is parsed.

    See Also
    --------
    - constructs.Stack.decode_geometry(): similar methodology applied to Geometry objects.
    - _get_outer(), _get_inner_i(), _get_middle(): helper functions for preparing tokens.

    """
    stack_seq = []
    if isinstance(outer, tuple):
        stack_seq.append(outer[0])
    else:
        stack_seq.append(outer)
    for inner in inner_i:
        if isinstance(inner, tuple):
            stack_seq.append(inner[0])
        else:
            stack_seq.append(inner)
    stack_seq.append(middle)
    for inner in inner_i[::-1]:
        if isinstance(inner, tuple):
            stack_seq.append(inner[1])
        else:
            stack_seq.append(inner)
    if isinstance(outer, tuple):
        stack_seq.append(outer[1])
    else:
        stack_seq.append(outer)
    return stack_seq


def echo(msg):
    """ Pring a plain message on the console. """
    print(msg)


def satellite():
    """
    Download satellite data.

    Warning
    -------
    Not yet implemented.
    """
    raise NotImplementedError


def initialize_event_source(source, node_pool_size, monitor_params):
    """
    Initializes the Karabo event source at XFEL.

    This function must be called on the master node before the :func:`event_generator`
    function is called on the worker nodes. There is no need to initialize the Karabo
    event source, so this function actually does nothing.

    Arguments:

        source (str): the hostname (or IP address) and the port where the Karabo Bridge
            is running, separated by a colon.

        node_pool_size (int): the total number of nodes in the OnDA pool, including all
            the worker nodes and the master node.

        monitor_params (:class:`~onda.utils.parameters.MonitorParams`): an object
            storing the OnDA monitor parameters from the configuration file.
    """
    del source
    del node_pool_size
    del monitor_params


def mock_data_dictionary(data, formset_key='mock', formset_desc='Mocktest'):
    """ Given a dictionary of key values this function returns a dictionary
    with the same structure as additional_data_dictionary, without the use
    of interfaces.

    This function exists for testing purposes.
    """
    records = list()
    formset = dict()
    formset['desc'] = formset_desc
    formset['interface'] = 'mockinterface'
    formset['values'] = records
    for i, item in enumerate(data.items()):
        records.append(dict(key=item[0], sortkey=i, value=item[1], desc=
            item[0]))
    return {formset_key: formset}


def r1001(node, *, fun, calls, entropy):
    """Check: Function has too many responsibilities.

    """
    print('{}:{}@R1001:{}:{}:{}'.format(node.lineno, node.col_offset, fun,
        calls, entropy))


@classmethod
def wrap_get_user(cls, response):
    """Wrap the response from getting a user into an instance
        and return it

        :param response: The response from getting a user
        :type response: :class:`requests.Response`
        :returns: the new user instance
        :rtype: :class:`list` of :class:`User`
        :raises: None
        """
    json = response.json()
    u = cls.wrap_json(json)
    return u


def is_parameters(obj: object) ->bool:
    """
    ``True`` only if the passed object is an instance of the BETSE-specific
    `Parameters` class.
    """
    from betse.science.parameters import Parameters
    return isinstance(obj, Parameters)


def strategy(entry_list):
    """Get the latest entry. """
    timestamp = 0
    best_entry = None
    for entry in entry_list:
        if entry['timestamp'] > timestamp:
            best_entry = entry
            timestamp = entry['timestamp']
    return best_entry


def accel_asc(n: int):
    """Efficient algorithm to generate all partitions of a positive integer

    Parameters
    ----------
    n : int
        a positive integer

    Yields
    ------
    list
        a partition of `n`
    """
    a = [(0) for i in range(n + 1)]
    k = 1
    y = n - 1
    while k != 0:
        x = a[k - 1] + 1
        k -= 1
        while 2 * x <= y:
            a[k] = x
            y -= x
            k += 1
        l = k + 1
        while x <= y:
            a[k] = x
            a[l] = y
            yield a[:k + 2]
            x += 1
            y -= 1
        a[k] = x + y
        y = x + y - 1
        yield a[:k + 1]


def KK_RC15(w, Rs, R_values, t_values):
    """
    Kramers-Kronig Function: -RC-

    Kristian B. Knudsen (kknu@berkeley.edu / kristianbknudsen@gmail.com)
    """
    return Rs + R_values[0] / (1 + w * 1.0j * t_values[0]) + R_values[1] / (
        1 + w * 1.0j * t_values[1]) + R_values[2] / (1 + w * 1.0j * t_values[2]
        ) + R_values[3] / (1 + w * 1.0j * t_values[3]) + R_values[4] / (1 +
        w * 1.0j * t_values[4]) + R_values[5] / (1 + w * 1.0j * t_values[5]
        ) + R_values[6] / (1 + w * 1.0j * t_values[6]) + R_values[7] / (1 +
        w * 1.0j * t_values[7]) + R_values[8] / (1 + w * 1.0j * t_values[8]
        ) + R_values[9] / (1 + w * 1.0j * t_values[9]) + R_values[10] / (1 +
        w * 1.0j * t_values[10]) + R_values[11] / (1 + w * 1.0j * t_values[11]
        ) + R_values[12] / (1 + w * 1.0j * t_values[12]) + R_values[13] / (
        1 + w * 1.0j * t_values[13]) + R_values[14] / (1 + w * 1.0j *
        t_values[14])


@staticmethod
def AddAccessArrays(*args):
    """

        For adding access array to a singluar array.

        Parameters:
            *args (list): Lists containing the the name and access array in the
            following format:
                [name, accessArray]

        Returns:
            addedArray (list): The array containing all the added access times.

        """
    addedArray = []
    if len(args) == 1:
        for accessArray in args[1]:
            for line in accessArray[1]:
                outputLine = [line[0], line[1], accessArray[0]]
                addedArray.append(outputLine)
        return addedArray
    else:
        for accessArray in args:
            for line in accessArray[1]:
                outputLine = [line[0], line[1], accessArray[0]]
                addedArray.append(outputLine)
        return addedArray


def key_exists(search_key, inputed_dict):
    """
    Given a search key which is dot notated
    return wether or not that key exists in a dictionary
    """
    num_levels = search_key.split('.')
    if len(num_levels) == 0:
        return False
    current_pointer = inputed_dict
    for updated_key in num_levels:
        if current_pointer is None:
            return False
        if updated_key == num_levels[-1]:
            return updated_key in current_pointer
        if updated_key in current_pointer:
            current_pointer = current_pointer[updated_key]
        else:
            return False


def provider_parser(subparser):
    """Generate a subparser for Glesys"""
    subparser.add_argument('--auth-username', help='specify username (CL12345)'
        )
    subparser.add_argument('--auth-token', help='specify API key')


def func_name(fn):
    """works only with picklable objects"""
    import inspect
    module = inspect.getmodule(fn)
    return module.__name__ + '.' + fn.__name__


def pole_from_endpoints(coord1, coord2):
    """Compute the pole from a great circle that connects the two specified
    coordinates.

    This assumes a right-handed rule from coord1 to coord2: the pole is the
    north pole under that assumption.

    Parameters
    ----------
    coord1 : `~astropy.coordinates.SkyCoord`
        Coordinate of one point on a great circle.
    coord2 : `~astropy.coordinates.SkyCoord`
        Coordinate of the other point on a great circle.

    Returns
    -------
    pole : `~astropy.coordinates.SkyCoord`
        The coordinates of the pole.
    """
    c1 = coord1.cartesian / coord1.cartesian.norm()
    coord2 = coord2.transform_to(coord1.frame)
    c2 = coord2.cartesian / coord2.cartesian.norm()
    pole = c1.cross(c2)
    pole = pole / pole.norm()
    return coord1.frame.realize_frame(pole)


def _arg_slen1(dvi, delta):
    """Signed, length *delta*+1

    Read *delta*+1 bytes, returning the bytes interpreted as signed."""
    return dvi._arg(delta + 1, True)


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 i2lsba(value, width):
    """ int to array (LSB first) """
    a = [0] * width
    for i in range(width):
        a[i] = value >> i * 8 & 255
    return a


def check(name, type, country, geometry, **args):
    """Should return True if this area is NEW, False if we should match against
    an ONS code, or an Area to be used as an override instead."""
    return False


def get_cloud(session, cloud_name, return_type=None, **kwargs):
    """
    Retrieves details for a given cloud name

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type cloud_name: str
    :param cloud_name: Cloud Name: i.e: zadaraqa9

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    path = '/api/clouds/{0}.json'.format(cloud_name)
    return session.get_api(path=path, return_type=return_type, **kwargs)


def _quadmin(a, fa, fpa, b, fb):
    """
    Finds the minimizer for a quadratic polynomial that goes through
    the points (a,fa), (b,fb) with derivative at a of fpa,

    """
    D = fa
    C = fpa
    db = b - a * 1.0
    if db == 0:
        return None
    B = (fb - D - C * db) / (db * db)
    if B <= 0:
        return None
    xmin = a - C / (2.0 * B)
    return xmin


def _name_from_element(element):
    """
    Fetches the name from the ``name`` element child of the provided element.
    If no element exists, returns ``None``.

    :param element: The element to find the name for.

    :return: The name string or ``None``
    """
    name_elem = element.find('./name')
    if name_elem is not None:
        return name_elem.text
    return None


@staticmethod
def append_slice_suffix_to_name(name, slice):
    """Append a vectored io (stripe) slice suffix to a given name
        :param str name: entity name
        :param int slice: slice num
        :rtype: str
        :return: name with appended suffix
        """
    return '{}.bxslice-{}'.format(name, slice)


@staticmethod
def _clean_name(name):
    """
        Delete extension and path

        :param name: the name to clean
        :return:
        """
    if name.endswith('.tar.gz'):
        name = name[:-7]
    elif name.endswith('.tgz'):
        name = name[:-4]
    _, _, name = name.rpartition('/')
    return name


def vertex_group_copy_to_linked():
    """Replace vertex groups of all users of the same geometry data by vertex groups of active object

    """
    pass


def weighted_avg(data, numeric_cols, weight):
    """
    Computes weighted average for specificied columns
    """
    sumprod = data[numeric_cols].multiply(data[weight], axis=0).sum()
    return sumprod / data[weight].sum()


def click_element_by_xpath(driver, xpath):
    """
    Click an element based on xpath
    @param driver: driver with element to click
    @param xpath: xpath of element to click
    """
    driver.find_element_by_xpath(xpath).click()


def guess_shape_and_submatrix_shape(dic):
    """
    Guess the data shape and the shape of the processed data submatrix.
    """
    if 'procs' not in dic:
        return None, None
    procs = dic['procs']
    if 'SI' not in procs or 'XDIM' not in procs:
        return None, None
    si_0 = procs['SI']
    xdim_0 = procs['XDIM']
    if 'proc2s' not in dic:
        return (si_0,), (xdim_0,)
    proc2s = dic['proc2s']
    if 'SI' not in proc2s or 'XDIM' not in proc2s:
        return None, None
    si_1 = proc2s['SI']
    xdim_1 = proc2s['XDIM']
    if 'proc3s' not in dic:
        return (si_1, si_0), (xdim_1, xdim_0)
    proc3s = dic['proc3s']
    if 'SI' not in proc3s or 'XDIM' not in proc3s:
        return None, None
    si_2 = proc3s['SI']
    xdim_2 = proc3s['XDIM']
    if 'proc4s' not in dic:
        return (si_2, si_1, si_0), (xdim_2, xdim_1, xdim_0)
    proc4s = dic['proc4s']
    if 'SI' not in proc4s or 'XDIM' not in proc4s:
        return None, None
    si_3 = proc4s['SI']
    xdim_3 = proc4s['XDIM']
    return (si_3, si_2, si_1, si_0), (xdim_3, xdim_2, xdim_1, xdim_0)


def csv_list(l):
    """Format list to a string with comma-separated values.
    """
    if len(l) == 0:
        return ''
    return ', '.join(map(str, l))


@staticmethod
def warn_ignore(exc, nav, repl_pairs, local_opt, node):
    """
        Failure_callback for NavigatorOptimizer: ignore all errors.

        """
    pass


def complete_code(code):
    """
    Append stock code number with code type.
    :param code: code in digits as string
    :return: code in complete form
    """
    if len(code) < 6:
        return False
    elif code[0] == '6':
        return code + '.XSHG'
    elif code[0] in ['0', '3']:
        return code + '.XSHE'
    else:
        return False


def extend_parser(optparser_parse):
    """
    You can add or remove options from the parser here.
    """


def add_remote_parser(sub_parser):
    """
    Adds a sub-parser for the "remote" sub-command to the parser provided.

    :param sub_parser: the parser to add to
    :type sub_parser: <class 'argparse.ArgumentParser'>
    :return: the parser added
    :rtype: <class 'argparse.ArgumentParser'>
    """
    remote_parser = sub_parser.add_parser('remote', help=
        'Initialise a new remote')
    remote_parser.add_argument('-n', '--name', help='Name of the remote')
    remote_parser.add_argument('-u', '--url', help='Url of the remote')
    remote_parser.add_argument('-a', '--add', help='Used to add a remote',
        action='store_true')
    remote_parser.add_argument('-v', '--verbose', help='verbose remote',
        action='store_true')
    remote_parser.add_argument('--global', help=
        'Used to specify a global remote', action='store_true', dest='glob')
    return remote_parser


def time_to_text(time):
    """Get a representative text of a time (in s)."""
    if time < 0.001:
        return str(round(time * 1000000)) + ' µs'
    elif time < 1:
        return str(round(time * 1000)) + ' ms'
    elif time < 60:
        return str(round(time, 1)) + ' s'
    else:
        return str(round(time / 60, 1)) + ' min'


def replace_methodname(format_string, methodname):
    """
    Partially format a format_string, swapping out any
    '{methodname}' or '{methodnamehyphen}' components.
    """
    methodnamehyphen = methodname.replace('_', '-')
    ret = format_string
    ret = ret.replace('{methodname}', methodname)
    ret = ret.replace('{methodnamehyphen}', methodnamehyphen)
    if 'nested_lookup' in format_string:
        ret = ret.replace('{nested_lookup}', '(?P<nested_pk>[^/.]+)')
    return ret


@staticmethod
def _show_previous_blank_lines(block):
    """
        Show the block previous blank lines
        """
    pblock = block.previous()
    while pblock.text().strip() == '' and pblock.blockNumber() >= 0:
        pblock.setVisible(True)
        pblock = pblock.previous()


def validate_format(*_arg):
    """
    This method can be overridden with format validation logic.
    """
    return True


def send_sync_update(socketio, new_job_id: int, last_job_id: str, method:
    str, resource_url: str):
    """Sends synchronization update to all connected clients.
    :param socketio: socketio connection.
    :param new_job_id: Job id of the new modification(update).
    :param last_job_id: Job id of the last(most recent) modification until this new one.
    :param method: Method type of the operation.
    :param resource_url: URL of resource which needs to be synchronized.
    """
    data = {'job_id': new_job_id, 'last_job_id': last_job_id, 'method':
        method, 'resource_url': resource_url}
    socketio.emit('update', data, namespace='/sync')


def assert_string_data(value: str) ->None:
    """Asserts value is string type."""
    assert isinstance(value, str
        ), f'Input value type must be string. Actual type: {type(value)}, value: {value}'


def hms2deg(x):
    """Transform *hours:minutes:seconds* strings to degrees.

    Parameters
    ----------
    x : str
        The input angle, written in the form, hours:minutes:seconds

    Returns
    -------
    out : float
        The angle as a number of degrees.

    """
    from astropy.coordinates import Angle
    ac = Angle(x, unit='hour')
    deg = float(ac.to_string(unit='degree', decimal=True))
    return deg


def default_use_basic_start_stop_model(is_hybrid):
    """
    Returns a flag that defines if basic or complex start stop model is applied.

    ..note:: The basic start stop model is function of velocity and
      acceleration. While, the complex model is function of velocity,
      acceleration, temperature, and battery state of charge.

    :param is_hybrid:
        Is the vehicle hybrid?
    :type is_hybrid: bool

    :return:
        If True the basic start stop model is applied, otherwise complex one.
    :rtype: bool
    """
    return not is_hybrid


def p_macro_call_arg_list_empty(p):
    """macro_arg_list : empty"""
    p[0] = []


def sorted_by_ufl_id(seq):
    """Sort a sequence by the item.ufl_id()."""
    return sorted(seq, key=lambda x: x.ufl_id())


def delta_encode(in_array):
    """A function to delta decode an int array.

    :param in_array: the inut array to be delta encoded
    :return the encoded integer array"""
    if len(in_array) == 0:
        return []
    curr_ans = in_array[0]
    out_array = [curr_ans]
    for in_int in in_array[1:]:
        out_array.append(in_int - curr_ans)
        curr_ans = in_int
    return out_array


@staticmethod
def from_jwk(jwk):
    """
        Deserializes a given RSA key from JWK back into a PublicKey or PrivateKey object
        """
    raise NotImplementedError


def copy_attributes(fields, order_item):
    """
    Copy valid attributes from order item.
    """
    payload = dict()
    for field in fields:
        if field in order_item.attributes:
            payload[field] = order_item.attributes.get(field)
    return payload


def path_shift(script_name, path_info, shift=1):
    """ Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa.

        :return: The modified paths.
        :param script_name: The SCRIPT_NAME path.
        :param script_name: The PATH_INFO path.
        :param shift: The number of path fragments to shift. May be negative to
          change the shift direction. (default: 1)
    """
    if shift == 0:
        return script_name, path_info
    pathlist = path_info.strip('/').split('/')
    scriptlist = script_name.strip('/').split('/')
    if pathlist and pathlist[0] == '':
        pathlist = []
    if scriptlist and scriptlist[0] == '':
        scriptlist = []
    if shift > 0 and shift <= len(pathlist):
        moved = pathlist[:shift]
        scriptlist = scriptlist + moved
        pathlist = pathlist[shift:]
    elif shift < 0 and shift >= -len(scriptlist):
        moved = scriptlist[shift:]
        pathlist = moved + pathlist
        scriptlist = scriptlist[:shift]
    else:
        empty = 'SCRIPT_NAME' if shift < 0 else 'PATH_INFO'
        raise AssertionError('Cannot shift. Nothing left from %s' % empty)
    new_script_name = '/' + '/'.join(scriptlist)
    new_path_info = '/' + '/'.join(pathlist)
    if path_info.endswith('/') and pathlist:
        new_path_info += '/'
    return new_script_name, new_path_info


def convert_deps_to_pip(deps, project=None, r=True, include_index=True):
    """"Converts a Pipfile-formatted dependency to a pip-formatted one."""
    from .vendor.requirementslib.models.requirements import Requirement
    dependencies = []
    for dep_name, dep in deps.items():
        if project:
            project.clear_pipfile_cache()
        indexes = getattr(project, 'pipfile_sources', []
            ) if project is not None else []
        new_dep = Requirement.from_pipfile(dep_name, dep)
        if new_dep.index:
            include_index = True
        req = new_dep.as_line(sources=indexes if include_index else None
            ).strip()
        dependencies.append(req)
    if not r:
        return dependencies
    from .vendor.vistir.path import create_tracked_tempfile
    f = create_tracked_tempfile(suffix='-requirements.txt', delete=False)
    f.write('\n'.join(dependencies).encode('utf-8'))
    f.close()
    return f.name


def primitive_uv_sphere_add(segments: int=32, ring_count: int=16, size:
    float=1.0, calc_uvs: bool=False, view_align: bool=False, enter_editmode:
    bool=False, location: float=(0.0, 0.0, 0.0), rotation: float=(0.0, 0.0,
    0.0), layers: bool=(False, False, False, False, False, False, False,
    False, False, False, False, False, False, False, False, False, False,
    False, False, False)):
    """Construct a UV sphere mesh

    :param segments: Segments
    :type segments: int
    :param ring_count: Rings
    :type ring_count: int
    :param size: Size
    :type size: float
    :param calc_uvs: Generate UVs, Generate a default UV map
    :type calc_uvs: bool
    :param view_align: Align to View, Align the new object to the view
    :type view_align: bool
    :param enter_editmode: Enter Editmode, Enter editmode when adding this object
    :type enter_editmode: bool
    :param location: Location, Location for the newly added object
    :type location: float
    :param rotation: Rotation, Rotation for the newly added object
    :type rotation: float
    :param layers: Layer
    :type layers: bool
    """
    pass


@staticmethod
def swbbName_to_IFid(swbbName):
    """Converts values found in the VCI baseBand.swbbName property to
        matching values as used in the OBS sslo.IFid property.

        swbbNames are like AC_8BIT, A1C1_3BIT, etc.
        IFids are like AC, AC1, etc."""
    conversions = {'A1C1': 'AC1', 'A2C2': 'AC2', 'B1D1': 'BD1', 'B2D2': 'BD2'}
    bbname, bits = swbbName.split('_')
    if bbname in conversions:
        return conversions[bbname]
    return bbname


def type_(type_):
    """Returns a string repr of the 'real type_'."""
    try:
        type_ = float(type_)
        if type_.is_integer():
            return int
        if not type_.is_integer():
            return float
    except ValueError:
        return str


def abstractmethod(funcobj):
    """A decorator indicating abstract methods.

    Requires that the metaclass is ABCMeta or derived from it.  A
    class that has a metaclass derived from ABCMeta cannot be
    instantiated unless all of its abstract methods are overridden.
    The abstract methods can be called using any of the normal
    'super' call mechanisms.

    Usage:

        class C(metaclass=ABCMeta):
            @abstractmethod
            def my_abstract_method(self, ...):
                ...
    """
    funcobj.__isabstractmethod__ = True
    return funcobj


def parse_boolean(value):
    """
    Parses strings into booleans using the following mapping (case-sensitive):

    'true'   => True
    'false'  => False
    '1'      => True
    '0'      => False
    """
    if value in ['true', '1']:
        return True
    elif value in ['false', '0']:
        return False
    else:
        raise ValueError("expected 'true' or 'false', got '%s'" % value)


def get_keywords():
    """Get the keywords needed to look up the version information."""
    git_refnames = '$Format:%d$'
    git_full = '$Format:%H$'
    git_date = '$Format:%ci$'
    keywords = {'refnames': git_refnames, 'full': git_full, 'date': git_date}
    return keywords


def _transpose_list_array(x):
    """Transposes a list matrix
    """
    n_dims = len(x)
    assert n_dims > 0
    n_samples = len(x[0])
    rows = [None] * n_samples
    for i in range(n_samples):
        r = [None] * n_dims
        for j in range(n_dims):
            r[j] = x[j][i]
        rows[i] = r
    return rows


def _convert_matmul(builder, node, graph, err):
    """
    convert to CoreML BatchedMatMul Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L3473
    """
    weight_name = node.inputs[1]
    W = None
    weight_as_layer_parameter = False
    if weight_name in node.input_tensors:
        W = node.input_tensors[weight_name]
    if W is not None:
        if len(W.shape) != 2:
            builder.add_load_constant_nd(node.name + '_const_weight_input',
                weight_name, constant_value=W, shape=W.shape)
        else:
            weight_as_layer_parameter = True
    if weight_as_layer_parameter:
        builder.add_batched_mat_mul(name=node.name, input_names=[node.
            inputs[0]], output_name=node.outputs[0], weight_matrix_rows=W.
            shape[0], weight_matrix_columns=W.shape[1], W=W)
    else:
        builder.add_batched_mat_mul(name=node.name, input_names=[node.
            inputs[0], weight_name], output_name=node.outputs[0])


def get_data(url, maxwidth=None, maxheight=None, format='json'):
    """Return the data provided by the endpoint."""


def is_indexable_but_not_string(obj):
    """Return True if ``obj`` is indexable but isn't a string."""
    return not hasattr(obj, 'strip') and hasattr(obj, '__getitem__')


@classmethod
def create(cls, endpoint, api, payload=None):
    """
        Process POST REST operations
        """
    if payload is not None:
        return api.post(endpoint, payload)


def getNextValue():
    """Consume and return next number in sequence"""


def false():
    """
    Returns the logical value FALSE
    """
    return False


def xieta2colrow(xi, eta, detsize, fill, npixx, npixy):
    """
    Convert detector xi and eta values to image column and row.

    :param xi: One coordinate of the unprojected detector position.

    :type xi: numpy.ndarray

    :param eta: Second coordinate of the unprojected detector position.

    :type eta: numpy.ndarray

    :param fill: Ration of the detector extent to the image extent.

    :type fill: float

    :param npixx: Number of pixels in the x dimension of an image.

    :type npixx: int

    :param nipxy: Number of pixels in the y dimension of an image.

    :type npixy: int

    :returns: tuple -- A tuple containing the image column and row values.
    """
    col = (xi / 36000.0 / (detsize / 2.0) * fill + 1.0) / 2.0 * npixx
    row = (eta / 36000.0 / (detsize / 2.0) * fill + 1.0) / 2.0 * npixy
    return col, row


def convert_h1(element, text):
    """
    Add '=' to the bottom of text
    """
    if text:
        text = text + '\n' + '=' * len(text)
    return text


@classmethod
def from_serializable(cls, object_dict):
    """ core class method to create visible objects from a dictionary """
    key_class = cls._from_visible(cls.STARTS_WITH + 'class' + cls.ENDS_WITH)
    key_module = cls._from_visible(cls.STARTS_WITH + 'module' + cls.ENDS_WITH)
    obj_class = object_dict.pop(key_class)
    obj_module = object_dict.pop(key_module
        ) if key_module in object_dict else None
    obj = cls._from_class(obj_class, obj_module)
    obj.modify_object(object_dict)
    return obj


@classmethod
def has(cls, blok):
    """ Return True if the blok is loaded

        :param blok: blok name
        :rtype: bool
        """
    return blok and blok in cls.ordered_bloks or False


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

        The iterator method is called with no arguments.  It is expected to
        return an iterator over all collection members::

            @collection.iterator
            def __iter__(self): ...

        """
    fn._sa_instrument_role = 'iterator'
    return fn


def mid_point(p1, p2):
    """ return the point inbetween the start and finish of the line """
    return [(p1[0] + p2[0]) / 2.0, (p1[1] + p2[1]) / 2.0, (p1[2] + p2[2]) / 2.0
        ]


def helpline(obj):
    """
    Yield an object's first docstring line, or an empty string.

    .. versionadded:: 1.0
    """
    docstring = obj.__doc__
    if not docstring or docstring == type(obj).__doc__:
        return None
    return docstring.lstrip().splitlines()[0]


def unduplicate_field_names(field_names):
    """Append a number to duplicate field names to make them unique. """
    res = []
    for k in field_names:
        if k in res:
            i = 1
            while k + '_' + str(i) in res:
                i += 1
            k += '_' + str(i)
        res.append(k)
    return res


@classmethod
def class_method(cls, f):
    """Decorator which dynamically binds class methods to the model for later use."""
    setattr(cls, f.__name__, classmethod(f))
    return f


@classmethod
def fromkeys(cls, iterable, value=None, callback=lambda : None):
    """ dict.fromkeys(S[,v]) -> New csvdict with keys from S and values
        equal to v. v defaults to None. """
    new_csvd = cls(callback)
    for key in iterable:
        new_csvd[key] = value
    return new_csvd


def norm_min(x):
    """min-norm: min(|x_i|); this is not a true norm"""
    return min(abs(x))


def render_pep440_old(pieces):
    """TAG[.postDISTANCE[.dev0]] .

    The ".dev0" means dirty.

    Eexceptions:
    1: no tags. 0.postDISTANCE[.dev0]
    """
    if pieces['closest-tag']:
        rendered = pieces['closest-tag']
        if pieces['distance'] or pieces['dirty']:
            rendered += '.post%d' % pieces['distance']
            if pieces['dirty']:
                rendered += '.dev0'
    else:
        rendered = '0.post%d' % pieces['distance']
        if pieces['dirty']:
            rendered += '.dev0'
    return rendered


def perms(event):
    """ show permission of user. """
    from . import users
    u = users.fetch(event.origin)
    if u:
        event.reply('permissions are %s' % ','.join(u.perms))


def quadraticEval(a, b, c, x):
    """given all params return the result of quadratic equation a*x^2 + b*x + c"""
    return a * x ** 2 + b * x + c


def _translate_attachment_summary_view(volume_id, instance_uuid, mountpoint):
    """Maps keys for attachment summary view."""
    d = {}
    d['id'] = volume_id
    d['volumeId'] = volume_id
    d['serverId'] = instance_uuid
    if mountpoint:
        d['device'] = mountpoint
    return d


def onDisconnect(game, username):
    """
    Event Hook: onDisconnect
    Print a little message in the server console
    """
    print('Client player "' + username + '" has disconnected')
    player = game.getPlayer(username)
    if player and player.ridingEntity:
        vehicle = game.getVehicle(player.ridingEntity)
        if vehicle:
            vehicle.unmountRider(player)
        player.ridingEntity = None
    props = game.getModInstance('ServerMod').tradeStateProperty.copy()
    player.setProperty('tradeState', props)
    game.packetPipeline.closeConnection(username)
    game.getModInstance('ServerMod').packetPipeline.closeConnection(username)


def get_tab_id(base_soup, tab_name):
    """
    학부전공별, 교양필수, 교양선택등 이 있는 탭의 id를 얻는다
    :param base_soup:
    SoupParser.soup_jar['base']
    :param tab_name:
    '학부전공별', '교양필수', '교양선택', ...
    :return:
    """
    tab_span = base_soup.find('span', text=tab_name)
    return tab_span.parent.parent.get('id')


@classmethod
def from_json(cls, _json, client_api, is_fetched=True):
    """
        Build a Project entity object from a json

        :param is_fetched: is Entity fetched from Platform
        :param _json: _json response from host
        :param client_api: client_api
        :return: Project object
        """
    inst = cls(feature_constraints=_json.get('featureConstraints', None),
        contributors=_json.get('contributors', None), createdAt=_json.get(
        'createdAt', None), updatedAt=_json.get('updatedAt', None), creator
        =_json.get('creator', None), account=_json.get('account', None),
        name=_json.get('name', None), role=_json.get('role', None), org=
        _json.get('org', None), id=_json.get('id', None), client_api=client_api
        )
    inst.is_fetched = is_fetched
    return inst


def setupWindowObject():
    """
    Function generating a script to setup window.object add-ons.

    @return generated script
    @rtype str
    """
    source = """
(function() {
    var external = {};
    external.AddSearchProvider = function(url) {
        window.location = 'eric:AddSearchProvider?url=' + url;
    };
    external.IsSearchProviderInstalled = function(url) {
        console.warn('NOT IMPLEMENTED: IsSearchProviderInstalled()');
        return false;
    };
    window.external = external;
    window.print = function() {
        window.location = 'eric:PrintPage';
    };
})()"""
    return source


def FormatClassToJava(i):
    """
    Transform a java class name into the typed variant found in DEX files.

    example::

        >>> FormatClassToJava('java.lang.Object')
        'Ljava/lang/Object;'

    :param i: the input class name
    :rtype: str
    """
    return 'L' + i.replace('.', '/') + ';'


@staticmethod
def blueprint_name_to_url(name):
    """ remove the last . in the string it it ends with a .
            for the url structure must follow the flask routing format
            it should be /model/method instead of /model/method/
        """
    if name[-1:] == '.':
        name = name[:-1]
    if name[-1:] is not '/':
        name = '/' + name
    name = str(name).replace('.', '/')
    return name


def crud_url_name(model, action, prefix=None):
    """
    Returns url name for given model and action.
    """
    if prefix is None:
        prefix = ''
    app_label = model._meta.app_label
    model_lower = model.__name__.lower()
    return '%s%s_%s_%s' % (prefix, app_label, model_lower, action)


def decode_edges(edges):
    """
    Decodes the specified integer representing edges in Cortex graph. Returns
    a tuple (forward, reverse) which contain the list of nucleotides that we
    append to a kmer and its reverse complement to obtain other kmers in the
    Cortex graph.
    """
    bases = ['A', 'C', 'G', 'T']
    fwd = []
    for j in range(4):
        if 1 << j & edges != 0:
            fwd.append(bases[j])
    rev = []
    bases.reverse()
    for j in range(4):
        if 1 << j + 4 & edges != 0:
            rev.append(bases[j])
    return fwd, rev


@classmethod
def darkcyan(cls, s):
    """Wrap text in darkcyan."""
    return cls._wrap_colour(s, cls.DARKCYAN)


def config_from_prefix(prefix):
    """Get config from zmq prefix"""
    settings = {}
    if prefix.lower() in ('default', 'auto', ''):
        settings['zmq_prefix'] = ''
        settings['libzmq_extension'] = False
        settings['no_libzmq_extension'] = False
    elif prefix.lower() in ('bundled', 'extension'):
        settings['zmq_prefix'] = ''
        settings['libzmq_extension'] = True
        settings['no_libzmq_extension'] = False
    else:
        settings['zmq_prefix'] = prefix
        settings['libzmq_extension'] = False
        settings['no_libzmq_extension'] = True
        settings['allow_legacy_libzmq'] = True
    return settings


def _get_job_tree_text(job_tree, property):
    """Get some parameter of an ElementTree representing a job """
    try:
        return job_tree.find(property).text
    except AttributeError:
        return ''


def kernel_density_geo(X_data, Y_data, bin_size_x=10, bin_size_y=10):
    """
    more information about the `Kernel density estimation <http://en.wikipedia.org/wiki/Kernel_density_estimation>`_
    """
    import scipy.stats as stats
    import numpy as N
    X_data = N.transpose([X_data.ravel()])
    Y_data = N.transpose([Y_data.ravel()])
    pos = N.append(X_data, Y_data, axis=1)
    kde = stats.kde.gaussian_kde(pos.T)
    X_flat = N.linspace(pos[:, (0)].min(), pos[:, (0)].max(), bin_size_x)
    Y_flat = N.linspace(pos[:, (1)].min(), pos[:, (1)].max(), bin_size_y)
    X, Y = N.meshgrid(X_flat, Y_flat)
    grid_coords = N.append(X.reshape(-1, 1), Y.reshape(-1, 1), axis=1)
    Z = kde(grid_coords.T)
    Z = Z.reshape(bin_size_x, bin_size_y)
    return grid_coords, Z


def flat(l):
    """
Returns the flattened version of a '2D' list.  List-correlate to the a.flat()
method of NumPy arrays.

Usage:    flat(l)
"""
    newl = []
    for i in range(len(l)):
        for j in range(len(l[i])):
            newl.append(l[i][j])
    return newl


def get_listOfProducts(reaction):
    """Get list of porducts of a reaction

    Args:
        reaction (xml.etree.ElementTree.Element): reaction

    Returns:
        xml.etree.ElementTree.Element: list of products
    """
    listOfProducts = None
    for e in reaction:
        if e.tag[0] == '{':
            uri, tag = e.tag[1:].split('}')
        else:
            tag = e.tag
        if tag == 'listOfProducts':
            listOfProducts = e
            break
    return listOfProducts


@classmethod
def is_applicable(cls, clients):
    """Check that implementation can be used in cloud."""
    if cls._meta_is_inited(raise_exc=False):
        impl = cls._meta_get('impl', cls)
        client = getattr(clients, impl._meta_get('client_name'))
        return client.choose_version() == impl._meta_get('version')
    return False


def revision(node, raw=False):
    """"Obtain fulltext data for a node.

        By default, any storage transformations are applied before the data
        is returned. If ``raw`` is True, non-raw storage transformations
        are not applied.

        The fulltext data may contain a header containing metadata. Most
        consumers should use ``read()`` to obtain the actual file data.
        """


def get_position_parameter(message_type, msg_tow, msg_position, tow,
    numofmsg, msgout):
    """
    Finds the position of the bounds related to the trigger

    Parameters
    ----------
    message_type : list
      names of message type
    msg_tow : list
      TOW values of the corresponding messages
    numofmsg : integer
      Count of the number of messages in the list
    msgout : string
      Name of the message the user wants to analyze
    tow : int
      TOW value of the bound message
    msg_position : list
      List of the message value that will get extracted
    """
    itt = 0
    value = 0
    while itt < numofmsg:
        if msg_tow[itt] == tow and message_type[itt] == msgout:
            value = msg_position[itt]
        itt += 1
    return value


def telco_churn(quantile=0.5):
    """Returns dataset in format x, [y1, y2]. This dataset
    is useful for demonstrating multi-output model or for
    experimenting with reduction strategy creation.

    The data is from hyperparameter optimization experiment with
    Kaggle telco churn dataset.

    x: features
    y1: val_loss
    y2: val_f1score

    quantile is for transforming the otherwise continuous y variables into
    labels so that higher value is stronger. If set to 0 then original
    continuous will be returned."""
    import wrangle
    import pandas as pd
    df = pd.read_csv(
        'https://raw.githubusercontent.com/autonomio/examples/master/telco_churn/telco_churn_for_sensitivity.csv'
        )
    df = df.drop(['val_acc', 'loss', 'f1score', 'acc', 'round_epochs'], 1)
    for col in df.iloc[:, 2:].columns:
        df = wrangle.col_to_multilabel(df, col)
    df = wrangle.df_rename_cols(df)
    if quantile > 0:
        y1 = (df.C0 < df.C0.quantile(quantile)).astype(int).values
        y2 = (df.C1 > df.C1.quantile(quantile)).astype(int).values
    else:
        y1 = df.C0.values
        y2 = df.C1.values
    x = df.drop(['C0', 'C1'], 1).values
    return x, [y1, y2]


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

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

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


@classmethod
def load(cls, fname):
    """Loads the posterior from an input file.

        Parameters
        ----------
        fname : :obj:`str`
            input filename

        Returns
        -------
        posterior : :obj:`posterior`
            loaded posterior object

        """
    import h5py as h5
    import numpy as np
    from ctypes import c_double
    from pyselfi.utils import PrintMessage
    PrintMessage(3, "Reading posterior in data file '{}'...".format(fname))
    with h5.File(fname, 'r') as hf:
        theta_0 = np.array(hf.get('/posterior/theta_0'), dtype=c_double)
        prior_covariance = np.array(hf.get('/posterior/prior_covariance'),
            dtype=c_double)
        inv_prior_covariance = np.array(hf.get(
            '/posterior/inv_prior_covariance'), dtype=c_double)
        f_0 = np.array(hf.get('/posterior/f_0'), dtype=c_double)
        C_0 = np.array(hf.get('/posterior/C_0'), dtype=c_double)
        inv_C_0 = np.array(hf.get('/posterior/inv_C_0'), dtype=c_double)
        grad_f = np.array(hf.get('/posterior/grad_f'), dtype=c_double)
        phi_obs = np.array(hf.get('/posterior/phi_obs'), dtype=c_double)
        posterior = cls(theta_0, prior_covariance, inv_prior_covariance,
            f_0, C_0, inv_C_0, grad_f, phi_obs)
        posterior.inv_covariance = np.array(hf.get(
            '/posterior/inv_covariance'), dtype=c_double)
        posterior.mean = np.array(hf.get('/posterior/mean'), dtype=c_double)
        posterior.covariance = np.array(hf.get('/posterior/covariance'),
            dtype=c_double)
    PrintMessage(3, "Reading posterior in data file '{}' done.".format(fname))
    return posterior


@conf
def fortran_modifier_darwin(conf):
    """
	Defines Fortran flags and extensions for OSX systems
	"""
    v = conf.env
    v.FCFLAGS_fcshlib = ['-fPIC']
    v.LINKFLAGS_fcshlib = ['-dynamiclib']
    v.fcshlib_PATTERN = 'lib%s.dylib'
    v.FRAMEWORKPATH_ST = '-F%s'
    v.FRAMEWORK_ST = ['-framework']
    v.LINKFLAGS_fcstlib = []
    v.FCSHLIB_MARKER = ''
    v.FCSTLIB_MARKER = ''
    v.SONAME_ST = ''


def __str__():
    """ Return a representation of the action information (including
        source code from file, if possible) """


def nameify(f, cast=lambda v: v):
    """ tries to give a name to an item"""
    return '.'.join([f.__module__, f.__name__]) if callable(f) else getattr(f,
        'name', cast(f))


def get_sequence_number():
    """Return the sequence number of this version."""


def merge_location_dict(location_dict_list):
    """
    Takes a list of location_dicts and returns a single location_dict with all the
    users and locations. Automatically merges duplicates. Requires unique user ids/names.
    """
    assert type(location_dict_list) is list, 'Must be passed a list of dicts'
    merged_loc_dict = {}
    for loc_dict in location_dict_list:
        for user, loc in loc_dict.items():
            merged_loc_dict[user] = loc
    return merged_loc_dict


def get_permission_actions():
    """Return a list of actions defined by this component.

        The items in the list may either be simple strings, or
        `(string, sequence)` tuples. The latter are considered to be "meta
        permissions" that group several simple actions under one name for
        convenience, adding to it if another component already defined that
        name.
        """


@staticmethod
def zero_property_flags(property_flags):
    """
        Given a binary property_flags, set all bit properties to 0.

        This leaves us with a canonical representation, that can be used
        in obtaining a particular property list

        :param property_flags: binary
        :return: binary
        """
    return property_flags


def select_linked(extend: bool=False):
    """Select all UV vertices linked to the active UV map

    :param extend: Extend, Extend selection rather than clearing the existing selection
    :type extend: bool
    """
    pass


def time_in_seconds(time_str):
    """Takes time code string, returns integer time in seconds"""
    hours = int(time_str[:2])
    minutes = int(time_str[3:5])
    seconds = int(time_str[6:])
    seconds_total = hours * 3600 + minutes * 60 + seconds
    return seconds_total


def _get_default_unit_format(config):
    """
    Get the default unit format as specified in the VOTable spec.
    """
    return 'cds'


def _applySpecial_SceneOpts_movieSyncRefresh(args, overlayList, displayCtx,
    target):
    """Applies the ``SceneOpts.movieSyncRefresh`` option. """
    if args.movieSync:
        target.movieSyncRefresh = not target.defaultMovieSyncRefresh


def aix_normal():
    """ Returns a string that will set the foreground and background
        to their default colors. """
    return '\x1b[0m'


@classmethod
def _build_request_type(cls, is_in, req_type, recipient):
    """ Builds the request type field for a USB request.

        is_in -- True iff this is a DEVICE-to-HOST request.
        req_type -- The type of request to be used.
        recipient -- The context in which this request should be interprted.

        returns -- a request_type byte
        """
    request_type = 0
    if is_in:
        request_type |= cls.ENDPOINT_DIRECTION_IN
    request_type |= req_type << 5
    request_type |= recipient
    return request_type


def getid(obj):
    """Retrieves an id from object or integer.

    Abstracts the common pattern of allowing both an object or an object's
    ID as a parameter when dealing with relationships.
    """
    try:
        return obj.id
    except AttributeError:
        return obj


def lopen_loc(x):
    """Extracts the line and column number for a node that may have an opening
    parenthesis, brace, or bracket.
    """
    lineno = x._lopen_lineno if hasattr(x, '_lopen_lineno') else x.lineno
    col = x._lopen_col if hasattr(x, '_lopen_col') else x.col_offset
    return lineno, col


def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16))


def __call__():
    """Return the json."""


def size():
    """Return unicode string: size for dispaly or empty string"""


def p_dotted_as_names_2(p):
    """dotted_as_names : dotted_as_name dotted_as_names_star"""
    p[0] = [p[1]] + p[2]


def split(iterator, criterion):
    """Returns a list of objects that match criterion and those that do not.
    """
    a = []
    b = []
    for x in iterator:
        if criterion(x):
            a.append(x)
        else:
            b.append(x)
    return a, b


def _no_constraint(info_list):
    """
    If there is no constraint set, then anything passes.
    """
    try:
        if len(info_list) == 0:
            return True
    except TypeError:
        return True
    return False


def tuple_to_string(prog_tuple):
    """Create a string from tuples returned by parse_string."""
    roman, acc, suff = prog_tuple
    if acc > 6:
        acc = 0 - acc % 6
    elif acc < -6:
        acc = acc % 6
    while acc < 0:
        roman = 'b' + roman
        acc += 1
    while acc > 0:
        roman = '#' + roman
        acc -= 1
    return roman + suff


@classmethod
def _create_pass_name(cls, passport) ->str:
    """Create passport name."""
    pass_name = '{}-{}-{} {}'.format(passport.params.year, passport.params.
        month, passport.params.day, int(passport.params.number))
    return pass_name


def write_ser(bufferdata, filename='ser'):
    """
    Write a ser file from FTICRData
    """
    with open(filename, 'wb') as f:
        for i in range(len(bufferdata)):
            for j in range(len(bufferdata[0])):
                f.write(bufferdata[i][j].astype('int32').tostring())


def ban(roomJID, entity, reason=None, sender=None):
    """
        Ban a user from a MUC room.

        @param roomJID: The bare JID of the room.
        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @param entity: The bare JID of the entity to be banned.
        @type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @param reason: The reason for banning the entity.
        @type reason: C{unicode}

        @param sender: The entity sending the request.
        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
        """


@classmethod
def coord2str_dd(cls, lon, lat):
    """Convert a longitude, latitude pair into a pretty string,
           in decimal degrees"""
    s = '%.7f E  ' % lon
    if lat >= 0:
        s += '%.7f N' % lat
    else:
        s += '%.5f S' % -lat
    return s


@classmethod
def info(cls, domain, login):
    """Display information about a mailbox."""
    return cls.call('domain.mailbox.info', domain, login)


def view_toggle():
    """Toggle between sequencer views (sequence, preview, both)

    """
    pass


def db_to_float(db, using_amplitude=True):
    """
    Converts the input db to a float, which represents the equivalent
    ratio in power.
    """
    db = float(db)
    if using_amplitude:
        return 10 ** (db / 20)
    else:
        return 10 ** (db / 10)


@classmethod
def from_customer(cls, customer):
    """
        Initialize this class using the information of the customer.
        """
    return cls(firstname=customer.firstname, lastname=customer.lastname,
        address1=customer.address1, address2=customer.address2, housenumber
        =customer.housenumber, zipcode=customer.zipcode, city=customer.city,
        state=customer.state, country=customer.country, phone=customer.
        phone, email=customer.email)


def elemwise_mul(lhs=None, rhs=None, out=None, name=None, **kwargs):
    """Multiplies arguments element-wise.

    The storage type of ``elemwise_mul`` output depends on storage types of inputs

       - elemwise_mul(default, default) = default
       - elemwise_mul(row_sparse, row_sparse) = row_sparse
       - elemwise_mul(default, row_sparse) = row_sparse
       - elemwise_mul(row_sparse, default) = row_sparse
       - elemwise_mul(csr, csr) = csr
       - otherwise, ``elemwise_mul`` generates output with default storage

    Parameters
    ----------
    lhs : NDArray
        first input
    rhs : NDArray
        second input

    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 start_instances(InstanceIds=None, AdditionalInfo=None, DryRun=None):
    """
    Starts an Amazon EBS-backed AMI that you've previously stopped.
    Instances that use Amazon EBS volumes as their root devices can be quickly stopped and started. When an instance is stopped, the compute resources are released and you are not billed for hourly instance usage. However, your root partition Amazon EBS volume remains, continues to persist your data, and you are charged for Amazon EBS volume usage. You can restart your instance at any time. Each time you transition an instance from stopped to started, Amazon EC2 charges a full instance hour, even if transitions happen multiple times within a single hour.
    Before stopping an instance, make sure it is in a state from which it can be restarted. Stopping an instance does not preserve data stored in RAM.
    Performing this operation on an instance that uses an instance store as its root device returns an error.
    For more information, see Stopping Instances in the Amazon Elastic Compute Cloud User Guide .
    See also: AWS API Documentation

    :example: response = client.start_instances(
        InstanceIds=[
            'string',
        ],
        AdditionalInfo='string',
        DryRun=True|False
    )

    :type InstanceIds: list
    :param InstanceIds: [REQUIRED]
            One or more instance IDs.
            (string) --

    :type AdditionalInfo: string
    :param AdditionalInfo: Reserved.

    :type DryRun: boolean
    :param DryRun: Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation . Otherwise, it is UnauthorizedOperation .

    :rtype: dict
    :return: {
        'StartingInstances': [
            {
                'InstanceId': 'string',
                'CurrentState': {
                    'Code': 123,
                    'Name': 'pending'|'running'|'shutting-down'|'terminated'|'stopping'|'stopped'
                },
                'PreviousState': {
                    'Code': 123,
                    'Name': 'pending'|'running'|'shutting-down'|'terminated'|'stopping'|'stopped'
                }
            },
        ]
    }

    :returns:
    0 : pending
    16 : running
    32 : shutting-down
    48 : terminated
    64 : stopping
    80 : stopped

    """
    pass


def load_volume_maps(directory, map_names=None, deferred=True):
    """Read a number of Nifti volume maps from a directory.

    Args:
        directory (str): the directory from which we want to read a number of maps
        map_names (list or tuple): the names of the maps we want to use. If given we only use and return these maps.
        deferred (boolean): if True we return an deferred loading dictionary instead of a dictionary with the values
            loaded as arrays.

    Returns:
        dict: A dictionary with the volumes. The keys of the dictionary are the filenames (without the extension) of the
            files in the given directory.
    """
    from mdt.lib.nifti import get_all_nifti_data
    return get_all_nifti_data(directory, map_names=map_names, deferred=deferred
        )


def valid_sample(sample):
    """Check whether the sample is valid (not empty and not None).

    :param sample: sample, should be a dict
    """
    return sample is not None and sample != {}


def delete(seq, pos, deletions):
    """Return the sequence with a number of deletions from position pos."""
    return seq[:pos] + seq[pos + deletions:]


def _header(settings):
    """
    Writes the Latex header using the settings file.

    The header includes all packages and defines all tikz styles.

    Returns:
        header (string): Header of the Latex document.
    """
    packages = """\\documentclass{standalone}
\\usepackage[margin=1in]{geometry}
\\usepackage[hang,small,bf]{caption}
\\usepackage{tikz}
\\usepackage{braket}
\\usetikzlibrary{backgrounds,shadows.blur,fit,decorations.pathreplacing,shapes}

"""
    init = (
        '\\begin{document}\n\\begin{tikzpicture}[scale=0.8, transform shape]\n\n'
        )
    gate_style = (
        '\\tikzstyle{basicshadow}=[blur shadow={shadow blur steps=8, shadow xshift=0.7pt, shadow yshift=-0.7pt, shadow scale=1.02}]'
        )
    if not (settings['gate_shadow'] or settings['control']['shadow']):
        gate_style = ''
    gate_style += '\\tikzstyle{basic}=[draw,fill=white,'
    if settings['gate_shadow']:
        gate_style += 'basicshadow'
    gate_style += ']\n'
    gate_style += (
        """\\tikzstyle{operator}=[basic,minimum size=1.5em]
\\tikzstyle{phase}=[fill=black,shape=circle,"""
         + 'minimum size={}'.format(settings['control']['size']) +
        'cm,inner sep=0pt,outer sep=0pt,draw=black')
    if settings['control']['shadow']:
        gate_style += ',basicshadow'
    gate_style += (
        """]
\\tikzstyle{none}=[inner sep=0pt,outer sep=-.5pt,minimum height=0.5cm+1pt]
\\tikzstyle{measure}=[operator,inner sep=0pt,minimum """
         + 'height={}cm, minimum width={}cm]\n'.format(settings['gates'][
        'MeasureGate']['height'], settings['gates']['MeasureGate']['width']
        ) + '\\tikzstyle{xstyle}=[circle,basic,minimum height=')
    x_gate_radius = min(settings['gates']['XGate']['height'], settings[
        'gates']['XGate']['width'])
    gate_style += (
        '{x_rad}cm,minimum width={x_rad}cm,inner sep=-1pt,{linestyle}]\n'.
        format(x_rad=x_gate_radius, linestyle=settings['lines']['style']))
    if settings['gate_shadow']:
        gate_style += """\\tikzset{
shadowed/.style={preaction={transform canvas={shift={(0.5pt,-0.5pt)}}, draw=gray, opacity=0.4}},
}
"""
    gate_style += '\\tikzstyle{swapstyle}=['
    gate_style += 'inner sep=-1pt, outer sep=-1pt, minimum width=0pt]\n'
    edge_style = '\\tikzstyle{edgestyle}=[' + settings['lines']['style'
        ] + ']\n'
    return packages + init + gate_style + edge_style


def KK_RC69_fit(params, w, t_values):
    """
    Kramers-Kronig Function: -RC-

    Kristian B. Knudsen (kknu@berkeley.edu / kristianbknudsen@gmail.com)
    """
    Rs = params['Rs']
    R1 = params['R1']
    R2 = params['R2']
    R3 = params['R3']
    R4 = params['R4']
    R5 = params['R5']
    R6 = params['R6']
    R7 = params['R7']
    R8 = params['R8']
    R9 = params['R9']
    R10 = params['R10']
    R11 = params['R11']
    R12 = params['R12']
    R13 = params['R13']
    R14 = params['R14']
    R15 = params['R15']
    R16 = params['R16']
    R17 = params['R17']
    R18 = params['R18']
    R19 = params['R19']
    R20 = params['R20']
    R21 = params['R21']
    R22 = params['R22']
    R23 = params['R23']
    R24 = params['R24']
    R25 = params['R25']
    R26 = params['R26']
    R27 = params['R27']
    R28 = params['R28']
    R29 = params['R29']
    R30 = params['R30']
    R31 = params['R31']
    R32 = params['R32']
    R33 = params['R33']
    R34 = params['R34']
    R35 = params['R35']
    R36 = params['R36']
    R37 = params['R37']
    R38 = params['R38']
    R39 = params['R39']
    R40 = params['R40']
    R41 = params['R41']
    R42 = params['R42']
    R43 = params['R43']
    R44 = params['R44']
    R45 = params['R45']
    R46 = params['R46']
    R47 = params['R47']
    R48 = params['R48']
    R49 = params['R49']
    R50 = params['R50']
    R51 = params['R51']
    R52 = params['R52']
    R53 = params['R53']
    R54 = params['R54']
    R55 = params['R55']
    R56 = params['R56']
    R57 = params['R57']
    R58 = params['R58']
    R59 = params['R59']
    R60 = params['R60']
    R61 = params['R61']
    R62 = params['R62']
    R63 = params['R63']
    R64 = params['R64']
    R65 = params['R65']
    R66 = params['R66']
    R67 = params['R67']
    R68 = params['R68']
    R69 = params['R69']
    return Rs + R1 / (1 + w * 1.0j * t_values[0]) + R2 / (1 + w * 1.0j *
        t_values[1]) + R3 / (1 + w * 1.0j * t_values[2]) + R4 / (1 + w *
        1.0j * t_values[3]) + R5 / (1 + w * 1.0j * t_values[4]) + R6 / (1 +
        w * 1.0j * t_values[5]) + R7 / (1 + w * 1.0j * t_values[6]) + R8 / (
        1 + w * 1.0j * t_values[7]) + R9 / (1 + w * 1.0j * t_values[8]
        ) + R10 / (1 + w * 1.0j * t_values[9]) + R11 / (1 + w * 1.0j *
        t_values[10]) + R12 / (1 + w * 1.0j * t_values[11]) + R13 / (1 + w *
        1.0j * t_values[12]) + R14 / (1 + w * 1.0j * t_values[13]) + R15 / (
        1 + w * 1.0j * t_values[14]) + R16 / (1 + w * 1.0j * t_values[15]
        ) + R17 / (1 + w * 1.0j * t_values[16]) + R18 / (1 + w * 1.0j *
        t_values[17]) + R19 / (1 + w * 1.0j * t_values[18]) + R20 / (1 + w *
        1.0j * t_values[19]) + R21 / (1 + w * 1.0j * t_values[20]) + R22 / (
        1 + w * 1.0j * t_values[21]) + R23 / (1 + w * 1.0j * t_values[22]
        ) + R24 / (1 + w * 1.0j * t_values[23]) + R25 / (1 + w * 1.0j *
        t_values[24]) + R26 / (1 + w * 1.0j * t_values[25]) + R27 / (1 + w *
        1.0j * t_values[26]) + R28 / (1 + w * 1.0j * t_values[27]) + R29 / (
        1 + w * 1.0j * t_values[28]) + R30 / (1 + w * 1.0j * t_values[29]
        ) + R31 / (1 + w * 1.0j * t_values[30]) + R32 / (1 + w * 1.0j *
        t_values[31]) + R33 / (1 + w * 1.0j * t_values[32]) + R34 / (1 + w *
        1.0j * t_values[33]) + R35 / (1 + w * 1.0j * t_values[34]) + R36 / (
        1 + w * 1.0j * t_values[35]) + R37 / (1 + w * 1.0j * t_values[36]
        ) + R38 / (1 + w * 1.0j * t_values[37]) + R39 / (1 + w * 1.0j *
        t_values[38]) + R40 / (1 + w * 1.0j * t_values[39]) + R41 / (1 + w *
        1.0j * t_values[40]) + R42 / (1 + w * 1.0j * t_values[41]) + R43 / (
        1 + w * 1.0j * t_values[42]) + R44 / (1 + w * 1.0j * t_values[43]
        ) + R45 / (1 + w * 1.0j * t_values[44]) + R46 / (1 + w * 1.0j *
        t_values[45]) + R47 / (1 + w * 1.0j * t_values[46]) + R48 / (1 + w *
        1.0j * t_values[47]) + R49 / (1 + w * 1.0j * t_values[48]) + R50 / (
        1 + w * 1.0j * t_values[49]) + R51 / (1 + w * 1.0j * t_values[50]
        ) + R52 / (1 + w * 1.0j * t_values[51]) + R53 / (1 + w * 1.0j *
        t_values[52]) + R54 / (1 + w * 1.0j * t_values[53]) + R55 / (1 + w *
        1.0j * t_values[54]) + R56 / (1 + w * 1.0j * t_values[55]) + R57 / (
        1 + w * 1.0j * t_values[56]) + R58 / (1 + w * 1.0j * t_values[57]
        ) + R59 / (1 + w * 1.0j * t_values[58]) + R60 / (1 + w * 1.0j *
        t_values[59]) + R61 / (1 + w * 1.0j * t_values[60]) + R62 / (1 + w *
        1.0j * t_values[61]) + R63 / (1 + w * 1.0j * t_values[62]) + R64 / (
        1 + w * 1.0j * t_values[63]) + R65 / (1 + w * 1.0j * t_values[64]
        ) + R66 / (1 + w * 1.0j * t_values[65]) + R67 / (1 + w * 1.0j *
        t_values[66]) + R68 / (1 + w * 1.0j * t_values[67]) + R69 / (1 + w *
        1.0j * t_values[68])


def metadata_from_package(variant):
    """Return metadata relative `variant`

    Blocking call, during change of profile.

    IMPORTANT: this function must return at least the
        members part of the original function, else the program
        will not function. Very few safeguards are put in place
        in favour of performance.

    Arguments:
        variant (rez.packages_.Variant): Package from which to retrieve data

    Returns:
        dict: See function for values and types

    """
    data = getattr(variant, '_data', {})
    return dict(data, **{'label': data.get('label', variant.name),
        'background': data.get('background'), 'icon': data.get('icon', ''),
        'hidden': data.get('hidden', False)})


def _envdir_merge_func(command_args, noxfile_args):
    """Ensure that there is always some envdir.

    Args:
        command_args (_option_set.Namespace): The options specified on the
            command-line.
        noxfile_Args (_option_set.Namespace): The options specified in the
            Noxfile.
    """
    return command_args.envdir or noxfile_args.envdir or '.nox'


def target_move_down():
    """Move particle target down in the list

    """
    pass


def merge_endpoints(defaults, additions):
    """
    Given an existing set of endpoint data, this will deep-update it with
    any similarly structured data in the additions.

    :param defaults: The existing endpoints data
    :type defaults: dict

    :param defaults: The additional endpoints data
    :type defaults: dict

    :returns: The modified endpoints data
    :rtype: dict
    """
    for service, region_info in additions.items():
        defaults.setdefault(service, {})
        defaults[service].update(region_info)
    return defaults


@staticmethod
def escape(expression, quote=True):
    """
        >>> Syntax.escape("SELECT 'abcdefgh' FROM foobar") == u"SELECT 'abcdefgh' FROM foobar"
        True
        """
    return expression


@staticmethod
def reduce_by(nominally, dominator):
    """Calculate the ratio."""
    return float(nominally) / float(dominator)