if trial_parameter_name:<EOL><INDENT>if remove_duplicates:<EOL><INDENT>self._logger.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>remove_duplicates = False<EOL><DEDENT><DEDENT>params_to_change = {}<EOL>if trial_parameter_name:<EOL><INDENT>my_trial_parameter = self.f_get(trial_parameter_name)<EOL>other_trial_parameter = other_trajectory.f_get(trial_parameter_name)<EOL>if not isinstance(my_trial_parameter, BaseParameter):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' % trial_parameter_name)<EOL><DEDENT>if my_trial_parameter.f_has_range():<EOL><INDENT>my_trial_list = my_trial_parameter.f_get_range(copy=False)<EOL><DEDENT>else:<EOL><INDENT>my_trial_list = [my_trial_parameter.f_get()]<EOL><DEDENT>if other_trial_parameter.f_has_range():<EOL><INDENT>other_trial_list = other_trial_parameter.f_get_range(copy=False)<EOL><DEDENT>else:<EOL><INDENT>other_trial_list = [other_trial_parameter.f_get()]<EOL><DEDENT>mytrialset = set(my_trial_list)<EOL>mymaxtrial_T1 = max(mytrialset)  <EOL>if mytrialset != set(range(mymaxtrial_T1 + <NUM_LIT:1>)):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (mymaxtrial_T1, str(mytrialset)))<EOL><DEDENT>othertrialset = set(other_trial_list)<EOL>othermaxtrial_T2 = max(othertrialset)  <EOL>if othertrialset != set(range(othermaxtrial_T2 + <NUM_LIT:1>)):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(othermaxtrial_T2, str(othertrialset)))<EOL><DEDENT>trial_parameter_name = my_trial_parameter.v_full_name<EOL>if not trial_parameter_name in self._explored_parameters:<EOL><INDENT>self._explored_parameters[trial_parameter_name] = my_trial_parameter<EOL><DEDENT>params_to_change[trial_parameter_name] = (my_trial_parameter, other_trial_parameter)<EOL><DEDENT>params_to_merge = other_trajectory._parameters.copy()<EOL>params_to_merge.update(other_trajectory._derived_parameters)<EOL>for ignore in ignore_data:<EOL><INDENT>if ignore in params_to_merge:<EOL><INDENT>del params_to_merge[ignore]<EOL><DEDENT><DEDENT>run_name_dummys = set([f(-<NUM_LIT:1>) for f in other_trajectory._wildcard_functions.values()])<EOL>for key in params_to_merge:<EOL><INDENT>other_param = params_to_merge[key]<EOL>split_key = key.split('<STR_LIT:.>')<EOL>if any(x in other_trajectory._reversed_wildcards for x in split_key):<EOL><INDENT>continue<EOL><DEDENT>my_param = self.f_get(key)<EOL>if not my_param._values_of_same_type(my_param.f_get(), other_param.f_get()):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' % key)<EOL><DEDENT>if my_param.v_full_name == trial_parameter_name:<EOL><INDENT>continue<EOL><DEDENT>if (my_param.f_has_range() or<EOL>other_param.f_has_range() or<EOL>not my_param._equal_values(my_param.f_get(), other_param.f_get())):<EOL><INDENT>params_to_change[key] = (my_param, other_param)<EOL>if not my_param.f_has_range() and not other_param.f_has_range():<EOL><INDENT>remove_duplicates = False<EOL><DEDENT><DEDENT><DEDENT>used_runs = {}<EOL>for idx in range(len(other_trajectory)):<EOL><INDENT>used_runs[idx] = idx<EOL><DEDENT>if remove_duplicates:<EOL><INDENT>for irun in range(len(other_trajectory)):<EOL><INDENT>for jrun in range(len(self)):<EOL><INDENT>change = True<EOL>for my_param, other_param in params_to_change.values():<EOL><INDENT>if other_param.f_has_range():<EOL><INDENT>other_param._set_parameter_access(irun)<EOL><DEDENT>if my_param.f_has_range():<EOL><INDENT>my_param._set_parameter_access(jrun)<EOL><DEDENT>val1 = my_param.f_get()<EOL>val2 = other_param.f_get()<EOL>if not my_param._equal_values(val1, val2):<EOL><INDENT>change = False<EOL>break<EOL><DEDENT><DEDENT>if change:<EOL><INDENT>del used_runs[irun]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>for my_param, other_param in params_to_change.values():<EOL><INDENT>other_param._restore_default()<EOL>my_param._restore_default()<EOL><DEDENT><DEDENT>adding_length = len(used_runs)<EOL>starting_length = len(self)<EOL>if adding_length == <NUM_LIT:0>:<EOL><INDENT>return used_runs, []<EOL><DEDENT>count = <NUM_LIT:0><EOL>for key in sorted(used_runs.keys()):<EOL><INDENT>used_runs[key] = starting_length + count<EOL>count += <NUM_LIT:1><EOL><DEDENT>for my_param, other_param in params_to_change.values():<EOL><INDENT>fullname = my_param.v_full_name<EOL>if fullname == trial_parameter_name:<EOL><INDENT>other_range = [x + mymaxtrial_T1 + <NUM_LIT:1> for x in other_trial_list]<EOL><DEDENT>else:<EOL><INDENT>if other_param.f_has_range():<EOL><INDENT>other_range = (x for jdx, x in enumerate(other_param.f_get_range(copy=False))<EOL>if jdx in used_runs)<EOL><DEDENT>else:<EOL><INDENT>other_range = (other_param.f_get() for _ in range(adding_length))<EOL><DEDENT><DEDENT>if not my_param.f_has_range():<EOL><INDENT>my_param.f_unlock()<EOL>my_param._explore((my_param.f_get() for _ in  range(len(self))))<EOL><DEDENT>my_param.f_unlock()<EOL>my_param._expand(other_range)<EOL>if not fullname in self._explored_parameters:<EOL><INDENT>self._explored_parameters[fullname] = my_param<EOL><DEDENT><DEDENT>return used_runs, list(params_to_change.keys())<EOL>

Merges parameters from the other trajectory into the current one.

        The explored parameters in the current trajectory are directly enlarged (in RAM),
        no storage service is needed here. Later on in `f_merge` the storage service
        will be requested to store the enlarge parameters to disk.

        Note explored parameters are always enlarged. Unexplored parameters might become
        new explored parameters if they differ in their default values
        in the current and the other trajectory, respectively.

        :return: A tuple with two elements:

            1.

                Dictionary of run index mappings from old trajectroy to the new one.

            2.

                List of names of parameters that were altered.


def f_store_items(self, iterator, *args, **kwargs):

if not self._stored:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>fetched_items = self._nn_interface._fetch_items(STORE, iterator, args, kwargs)<EOL>if fetched_items:<EOL><INDENT>self._storage_service.store(pypetconstants.LIST, fetched_items,<EOL>trajectory_name=self.v_name)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Stores individual items to disk.

        This function is useful if you calculated very large results (or large derived parameters)
        during runtime and you want to write these to disk immediately and empty them afterwards
        to free some memory.

        Instead of storing individual parameters or results you can also store whole subtrees with
        :func:`~pypet.naturalnaming.NNGroupNode.f_store_child`.

        You can pass the following arguments to `f_store_items`:

        :param iterator:

            An iterable containing the parameters or results to store, either their
            names or the instances. You can also pass group instances or names here
            to store the annotations of the groups.

        :param non_empties:

            Optional keyword argument (boolean),
            if `True` will only store the subset of provided items that are not empty.
            Empty parameters or results found in `iterator` are simply ignored.

        :param args: Additional arguments passed to the storage service

        :param kwargs:

            If you use the standard hdf5 storage service, you can pass the following additional
            keyword argument:

            :param overwrite:

                List names of parts of your item that should
                be erased and overwritten by the new data in your leaf.
                You can also set `overwrite=True`
                to overwrite all parts.

                For instance:

                    >>> traj.f_add_result('mygroup.myresult', partA=42, partB=44, partC=46)
                    >>> traj.f_store()
                    >>> traj.mygroup.myresult.partA = 333
                    >>> traj.mygroup.myresult.partB = 'I am going to change to a string'
                    >>> traj.f_store_item('mygroup.myresult', overwrite=['partA', 'partB'])

                Will store `'mygroup.myresult'` to disk again and overwrite the parts
                `'partA'` and `'partB'` with the new values `333` and
                `'I am going to change to a string'`.
                The data stored as `partC` is not changed.

                Be aware that you need to specify the names of parts as they were stored
                to HDF5. Depending on how your leaf construction works, this may differ
                from the names the data might have in your leaf in the trajectory container.

                Note that massive overwriting will fragment and blow up your HDF5 file.
                Try to avoid changing data on disk whenever you can.

        :raises:

            TypeError:

                If the (parent) trajectory has never been stored to disk. In this case
                use :func:`pypet.trajectory.f_store` first.

            ValueError: If no item could be found to be stored.

        Note if you use the standard hdf5 storage service, there are no additional arguments
        or keyword arguments to pass!


return self._storage_service<EOL>

The service that can store the trajectory to disk or wherever.

        Default is None or if a filename was provided on construction
        the :class:`~pypet.storageservice.HDF5StorageService`.


return self._standard_parameter<EOL>

The standard parameter used for parameter creation


for wildcards, function in func_dict.items():<EOL><INDENT>if not isinstance(wildcards, tuple):<EOL><INDENT>wildcards = (wildcards,)<EOL><DEDENT>for wildcard in wildcards:<EOL><INDENT>if wildcard in self._wildcard_keys:<EOL><INDENT>raise ValueError('<STR_LIT>' % wildcard)<EOL><DEDENT>self._wildcard_keys[wildcard] = wildcards<EOL><DEDENT>self._wildcard_functions[wildcards] = function<EOL>self._logger.debug('<STR_LIT>' % str(wildcards))<EOL><DEDENT>


if len(self._reversed_wildcards) > <NUM_LIT:0>:<EOL><INDENT>start = old_length<EOL><DEDENT>else:<EOL><INDENT>start = -<NUM_LIT:1><EOL><DEDENT>for wildcards, func in self._wildcard_functions.items():<EOL><INDENT>for irun in range(start, len(self)):<EOL><INDENT>translated_name = func(irun)<EOL>if not translated_name in self._reversed_wildcards:<EOL><INDENT>self._reversed_wildcards[translated_name] = ([], wildcards)<EOL><DEDENT>self._reversed_wildcards[translated_name][<NUM_LIT:0>].append(irun)<EOL><DEDENT><DEDENT>

Creates a full mapping from all wildcard translations to the corresponding wildcards


init_time = time.time()<EOL>formatted_time = datetime.datetime.fromtimestamp(init_time).strftime('<STR_LIT>')<EOL>run_info_dict = self._run_information[self.v_crun]<EOL>run_info_dict['<STR_LIT>'] = init_time<EOL>run_info_dict['<STR_LIT:time>'] = formatted_time<EOL>if self._environment_hexsha is not None:<EOL><INDENT>run_info_dict['<STR_LIT>'] = self._environment_hexsha[<NUM_LIT:0>:<NUM_LIT:7>]<EOL><DEDENT>

Sets the start timestamp and formatted time to the current time.


for run_idx in range(len(self)):<EOL><INDENT>if self.f_is_completed(run_idx):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>added_explored_parameters = []<EOL>try:<EOL><INDENT>length = len(self)<EOL>for key, builditerable in build_dict.items():<EOL><INDENT>act_param = self.f_get(key)<EOL>if not act_param.v_is_leaf or not act_param.v_is_parameter:<EOL><INDENT>raise ValueError('<STR_LIT>' % key)<EOL><DEDENT>act_param.f_unlock()<EOL>act_param._explore(builditerable)<EOL>added_explored_parameters.append(act_param)<EOL>full_name = act_param.v_full_name<EOL>self._explored_parameters[full_name] = act_param<EOL>act_param._explored = True<EOL>if len(self._explored_parameters) == <NUM_LIT:1>:<EOL><INDENT>length = act_param.f_get_range_length()<EOL><DEDENT>elif not length == act_param.f_get_range_length():<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>for irun in range(length):<EOL><INDENT>self._add_run_info(irun)<EOL><DEDENT>self._test_run_addition(length)<EOL><DEDENT>except Exception:<EOL><INDENT>for param in added_explored_parameters:<EOL><INDENT>param.f_unlock()<EOL>param._shrink()<EOL>param._explored = False<EOL>full_name = param.v_full_name<EOL>del self._explored_parameters[full_name]<EOL><DEDENT>if len(self._explored_parameters) == <NUM_LIT:0>:<EOL><INDENT>self.f_shrink(force=True)<EOL><DEDENT>raise<EOL><DEDENT>

Prepares the trajectory to explore the parameter space.

        To explore the parameter space you need to provide a dictionary with the names of the
        parameters to explore as keys and iterables specifying the exploration ranges as values.

        All iterables need to have the same length otherwise a ValueError is raised.
        A ValueError is also raised if the names from the dictionary map to groups or results
        and not parameters.

        If your trajectory is already explored but not stored yet and your parameters are
        not locked you can add new explored parameters to the current ones if their
        iterables match the current length of the trajectory.

        Raises an AttributeError if the names from the dictionary are not found at all in
        the trajectory and NotUniqueNodeError if the keys not unambiguously map
        to single parameters.

        Raises a TypeError if the trajectory has been stored already, please use
        :func:`~pypet.trajectory.Trajectory.f_expand` then instead.

        Example usage:

        >>> traj.f_explore({'groupA.param1' : [1,2,3,4,5], 'groupA.param2':['a','b','c','d','e']})

        Could also be called consecutively:

        >>> traj.f_explore({'groupA.param1' : [1,2,3,4,5]})
        >>> traj.f_explore({'groupA.param2':['a','b','c','d','e']})

        NOTE:

        Since parameters are very conservative regarding the data they accept
        (see :ref:`type_conservation`), you sometimes won't be able to use Numpy arrays
        for exploration as iterables.

        For instance, the following code snippet won't work:

        ::

            import numpy a np
            from pypet.trajectory import Trajectory
            traj = Trajectory()
            traj.f_add_parameter('my_float_parameter', 42.4,
                                 comment='My value is a standard python float')

            traj.f_explore( { 'my_float_parameter': np.arange(42.0, 44.876, 0.23) } )

        This will result in a `TypeError` because your exploration iterable
        `np.arange(42.0, 44.876, 0.23)` contains `numpy.float64` values
        whereas you parameter is supposed to use standard python floats.

        Yet, you can use Numpys `tolist()` function to overcome this problem:

        ::

            traj.f_explore( { 'my_float_parameter': np.arange(42.0, 44.876, 0.23).tolist() } )

        Or you could specify your parameter directly as a numpy float:

        ::

            traj.f_add_parameter('my_float_parameter', np.float64(42.4),
                                   comment='My value is a numpy 64 bit float')


def f_find_idx(self, name_list, predicate):

if self._is_run and not self.v_full_copy:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if isinstance(name_list, str):<EOL><INDENT>name_list = [name_list]<EOL><DEDENT>iter_list = []<EOL>for name in name_list:<EOL><INDENT>param = self.f_get(name)<EOL>if not param.v_is_parameter:<EOL><INDENT>raise TypeError('<STR_LIT>' %<EOL>(name, str(type(param))))<EOL><DEDENT>if param.f_has_range():<EOL><INDENT>iter_list.append(iter(param.f_get_range(copy=False)))<EOL><DEDENT>else:<EOL><INDENT>iter_list.append(itools.repeat(param.f_get(), len(self)))<EOL><DEDENT><DEDENT>logic_iter = map(predicate, *iter_list)<EOL>for idx, item in enumerate(logic_iter):<EOL><INDENT>if item:<EOL><INDENT>yield idx<EOL><DEDENT><DEDENT>

Finds a single run index given a particular condition on parameters.

        ONLY useful for a single run if ``v_full_copy` was set to ``True``.
        Otherwise a TypeError is thrown.

        :param name_list:

            A list of parameter names the predicate applies to, if you have only a single
            parameter name you can omit the list brackets.

        :param predicate:

            A lambda predicate for filtering that evaluates to either ``True`` or  ``False``

        :return: A generator yielding the matching single run indices

        Example:

        >>> predicate = lambda param1, param2: param1==4 and param2 in [1.0, 2.0]
        >>> iterator = traj.f_find_idx(['groupA.param1', 'groupA.param2'], predicate)
        >>> [x for x in iterator]
        [0, 2, 17, 36]


return self._timestamp<EOL>


self._no_clobber = bool(value)<EOL>


@kwargs_api_change('<STR_LIT>')<EOL><INDENT>@kwargs_api_change('<STR_LIT>')<EOL>@kwargs_mutual_exclusive('<STR_LIT>', '<STR_LIT>', lambda x: not x)<EOL>def f_store(self, only_init=False, store_data=pypetconstants.STORE_DATA,<EOL>max_depth=None):<DEDENT>

if self._is_run:<EOL><INDENT>if self._new_nodes or self._new_links:<EOL><INDENT>self._storage_service.store(pypetconstants.SINGLE_RUN, self,<EOL>trajectory_name=self.v_name,<EOL>recursive=not only_init,<EOL>store_data=store_data,<EOL>max_depth=max_depth)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._storage_service.store(pypetconstants.TRAJECTORY, self,<EOL>trajectory_name=self.v_name,<EOL>only_init=only_init,<EOL>store_data=store_data,<EOL>max_depth=max_depth)<EOL>self._stored = True<EOL><DEDENT>

Stores the trajectory to disk and recursively all data in the tree.

        :param only_init:

            If you just want to initialise the store. If yes, only meta information about
            the trajectory is stored and none of the groups/leaves within the trajectory.
            Alternatively, you can pass `recursive=False`.

        :param store_data:

            Only considered if ``only_init=False``. Choose of the following:

                * :const:`pypet.pypetconstants.STORE_NOTHING`: (0)

                    Nothing is store.

                * :const:`pypet.pypetconstants.STORE_DATA_SKIPPING`: (1)

                    Speedy version of normal ``STORE_DATA`` will entirely skip groups
                    (but not their children) and leaves if they have been stored before.
                    No new data is added in this case.

                * :const:`pypet.pypetconstants.STORE_DATA`: (2)

                    Stores every group and leave node. If they contain data that is not yet stored
                    to disk it is added.

                * :const:`pypet.pypetconstants.OVERWRITE_DATA`: (3)

                    Stores all groups and leave nodes and will delete all data on disk
                    and overwrite it with the current data in RAM.

                    **NOT RECOMMENDED**! Overwriting data on disk fragments the HDF5 file and
                    yields badly compressed large files. Better stick to the concept
                    write once and read many!

        If you use the HDF5 Storage Service usually (STORE_DATA (2)) only novel data
        is stored to disk.
        If you have results that have been stored to disk before only new data items are added and
        already present data is NOT overwritten.

        Overwriting (OVERWRITE_DATA (3)) existing data with the HDF5 storage service
        is not recommended due to fragmentation of the HDF5 file. Better stick to the concept
        write once, but read often.

        If you want to store individual parameters or results, you might want to
        take a look at :func:`~pypet.Trajectory.f_store_items`.
        To store whole subtrees of your trajectory check out
        :func:`~pypet.naturalnaming.NNGroupNode.f_store_child`.
        Note both functions require that your trajectory was stored to disk with `f_store`
        at least once before.

        **ATTENTION**: Calling `f_store` during a single run the behavior is different.

        To avoid re-storing the full trajectory in every single run, which is redundant,
        only sub-trees of the trajectory are really stored.

        The storage serivce looks for new data that is added below groups called `run_XXXXXXXXXX`
        and stores it where `XXXXXXXXX` is the index of this run. The `only_init` parameter is
        ignored in this case. You can avoid this behavior by using the argument from below.

        :param max_depth:

            Maximum depth to store tree (inclusive). During single runs `max_depth` is also counted
            from root.


if consecutive_merge and trial_parameter is not None:<EOL><INDENT>self._logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if consecutive_merge and backup:<EOL><INDENT>self._logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>timestamp = time.time()<EOL>original_ignore_data = set(ignore_data)<EOL>ignore_data = original_ignore_data.copy()<EOL>old_len = len(self)<EOL>self._check_if_both_have_same_parameters(other_trajectory, ignore_data, consecutive_merge)<EOL>self._make_reversed_wildcards(old_length=old_len)<EOL>other_trajectory._make_reversed_wildcards()<EOL>if backup:<EOL><INDENT>other_trajectory.f_backup()<EOL>self.f_backup()<EOL><DEDENT>self._logger.info('<STR_LIT>')<EOL>used_runs, changed_parameters = self._merge_parameters(<EOL>other_trajectory,<EOL>remove_duplicates,<EOL>trial_parameter,<EOL>ignore_data)<EOL>ignore_data.update(set(changed_parameters))<EOL>if len(used_runs) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>rename_dict = {}<EOL>self._logger.info('<STR_LIT>')<EOL>allowed_translations = set([translation for translation, pair in<EOL>other_trajectory._reversed_wildcards.items() if<EOL>any(x in used_runs for x in pair[<NUM_LIT:0>])])<EOL>self._merge_single_runs(other_trajectory, used_runs)<EOL>self._logger.info('<STR_LIT>')<EOL>self._merge_derived_parameters(other_trajectory=other_trajectory,<EOL>used_runs=used_runs,<EOL>rename_dict=rename_dict,<EOL>allowed_translations=allowed_translations,<EOL>ignore_data=ignore_data)<EOL>self._merge_results(other_trajectory=other_trajectory,<EOL>used_runs=used_runs,<EOL>rename_dict=rename_dict,<EOL>allowed_translations=allowed_translations,<EOL>ignore_data=ignore_data)<EOL>self._logger.info('<STR_LIT>')<EOL>self._logger.info('<STR_LIT>')<EOL>self._storage_service.store(pypetconstants.PREPARE_MERGE, self,<EOL>trajectory_name=self.v_name,<EOL>changed_parameters=changed_parameters,<EOL>old_length=old_len)<EOL>if not slow_merge:<EOL><INDENT>try:<EOL><INDENT>try:<EOL><INDENT>other_filename = other_trajectory.v_storage_service.filename<EOL><DEDENT>except AttributeError:<EOL><INDENT>self._logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>other_filename = None<EOL><DEDENT>self._storage_service.store(pypetconstants.MERGE, '<STR_LIT>', trajectory_name=self.v_name,<EOL>other_trajectory_name=other_trajectory.v_name,<EOL>rename_dict=rename_dict, move_nodes=move_data,<EOL>delete_trajectory=delete_other_trajectory,<EOL>other_filename=other_filename)<EOL><DEDENT>except pex.NoSuchServiceError as exc:<EOL><INDENT>self._logger.exception('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>slow_merge = True<EOL><DEDENT>except ValueError as exc:<EOL><INDENT>self._logger.exception('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>slow_merge = True<EOL><DEDENT><DEDENT>if slow_merge:<EOL><INDENT>self._merge_slowly(other_trajectory, rename_dict)<EOL><DEDENT>if merge_config:<EOL><INDENT>self._merge_config(other_trajectory)<EOL><DEDENT>self._merge_links(other_trajectory=other_trajectory,<EOL>used_runs=used_runs,<EOL>allowed_translations=allowed_translations,<EOL>ignore_data=original_ignore_data)<EOL>self._logger.info('<STR_LIT>')<EOL>formatted_time = datetime.datetime.fromtimestamp(timestamp).strftime('<STR_LIT>')<EOL>hexsha = hashlib.sha1((self.v_name +<EOL>str(self.v_timestamp) +<EOL>other_trajectory.v_name +<EOL>str(other_trajectory.v_timestamp) +<EOL>VERSION).encode('<STR_LIT:utf-8>')).hexdigest()<EOL>short_hexsha = hexsha[<NUM_LIT:0>:<NUM_LIT:7>]<EOL>if keep_info:<EOL><INDENT>merge_name = '<STR_LIT>' % (short_hexsha, formatted_time)<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, len(used_runs),<EOL>comment='<STR_LIT>')<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, timestamp,<EOL>comment='<STR_LIT>')<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, hexsha,<EOL>comment='<STR_LIT>')<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, remove_duplicates,<EOL>comment='<STR_LIT>')<EOL>if original_ignore_data:<EOL><INDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, tuple(original_ignore_data),<EOL>comment='<STR_LIT>')<EOL><DEDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, len(self),<EOL>comment='<STR_LIT>')<EOL>self.config.merge.v_comment = '<STR_LIT>'<EOL>if self.v_version != VERSION:<EOL><INDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, self.v_version,<EOL>comment='<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if trial_parameter is not None:<EOL><INDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, len(other_trajectory),<EOL>comment='<STR_LIT>')<EOL><DEDENT>if keep_other_trajectory_info:<EOL><INDENT>if other_trajectory.v_version != self.v_version:<EOL><INDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, other_trajectory.v_version,<EOL>comment='<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, other_trajectory.v_name,<EOL>comment='<STR_LIT>')<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, other_trajectory.v_timestamp,<EOL>comment='<STR_LIT>'<EOL>'<STR_LIT>')<EOL>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, len(other_trajectory),<EOL>comment='<STR_LIT>')<EOL>if other_trajectory.v_comment:<EOL><INDENT>config_name = '<STR_LIT>' % merge_name<EOL>self.f_add_config(config_name, other_trajectory.v_comment,<EOL>comment='<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if not consecutive_merge:<EOL><INDENT>self._logger.info('<STR_LIT>')<EOL>self.f_store(store_data=pypetconstants.STORE_DATA)<EOL>self._reversed_wildcards = {}<EOL><DEDENT>other_trajectory._reversed_wildcards = {}<EOL>self._logger.info('<STR_LIT>')<EOL>

Merges another trajectory into the current trajectory.

        Both trajectories must live in the same space. This means both need to have the same
        parameters with similar types of values.

        Note that links are also merged. There are exceptions: Links found under
        a generic run group called `run_ALL` or links linking to a node under such a
        group are NOT merged and simply skipped, because there is no straightforward
        way to resolve the link.

        :param other_trajectory: Other trajectory instance to merge into the current one.

        :param trial_parameter:

            If you have a particular parameter that specifies only the trial
            number, i.e. an integer parameter running form 0 to T1 and
            0 to T2, the parameter is modified such that after merging it will
            cover the range 0 to T1+T2+1. T1 is the number of individual trials in the current
            trajectory and T2 number of trials in the other trajectory.

        :param remove_duplicates:

            Whether you want to remove duplicate parameter points.
            Requires N1 * N2 (quadratic complexity in single runs).
            A ValueError is raised if no runs would be merged.

        :param ignore_data:

            List of full names of data that should be ignored and not merged.

        :param backup:

            If ``True``, backs up both trajectories into files chosen automatically
            by the storage services. If you want to customize your backup use
            the `f_backup` function instead.

        :param move_data:

           Tells the storage service to move data from one trajectory to the other
           instead of copying it.

           If you use the HDF5 storage service and both trajectories are
           stored in the same file, merging is performed fast directly within
           the file. You can choose if you want to copy nodes ('move_nodes=False`)
           from the other trajectory to the current one, or if you want to move them.
           Accordingly, the stored data is no longer accessible in the other trajectory.

        :param delete_other_trajectory:

            If you want to delete the other trajectory after merging.

        :param keep_info:

            If `True`, information about the merge is added to the trajectory `config` tree under
            `config.merge`.

        :param merge_config:

            Whether or not to merge all config parameters under `.config.git`,
            `.config.environment`, and `.config.merge` of the other trajectory
            into the current one.

        :param keep_other_trajectory_info:

            Whether to keep information like length, name, etc. of the other trajectory
            in case you want to keep all the information. Setting of `keep_other_trajectory_info`
            is irrelevant in case `keep_info=False`.

        :param consecutive_merge:
            Can be set to `True` if you are about to merge several trajectories into the current
            one within a loop to avoid quadratic complexity.
            But remember to store your trajectory manually after
            all merges. Also make sure that all parameters and derived parameters are available
            in your current trajectory and load them before the consecutive merging.
            Also avoid specifying a `trial_parameter` and set `backup=False`
            to avoid quadratic complexity in case of consecutive merges.

        :param slow_merge:
            Enforces a slow merging. This means all data is loaded one after the other to
            memory and stored to disk. Otherwise it is tried to directly copy the data
            from one file into another without explicitly loading the data.

        If you cannot directly merge trajectories within one HDF5 file, a slow merging process
        is used. Results are loaded, stored, and emptied again one after the other. Might take
        some time!

        Annotations of parameters and derived parameters under `.derived_parameters.trajectory`
        are NOT merged. If you wish to extract the annotations of these parameters you have to
        do that manually before merging. Note that annotations of results and derived parameters
        of single runs are copied, so you don't have to worry about these.


return self.v_crun if self.v_crun is not None else self.f_wildcard('<STR_LIT:$>', -<NUM_LIT:1>)<EOL>

Similar to ``v_crun`` but returns ``'run_ALL'`` if ``v_crun`` is ``None``.


for param in self._explored_parameters.values():<EOL><INDENT>if param._stored:<EOL><INDENT>try:<EOL><INDENT>self.f_delete_item(param)<EOL><DEDENT>except Exception:<EOL><INDENT>self._logger.exception('<STR_LIT>'<EOL>'<STR_LIT>' % param.v_full_name)<EOL><DEDENT><DEDENT><DEDENT>

Called if trajectory is expanded, deletes all explored parameters from disk


@not_in_run<EOL><INDENT>def f_preset_parameter(self, param_name, *args, **kwargs):<DEDENT>

if not param_name.startswith('<STR_LIT>'):<EOL><INDENT>param_name = '<STR_LIT>' + param_name<EOL><DEDENT>self._preset(param_name, args, kwargs)<EOL>

Presets parameter value before a parameter is added.

        Can be called before parameters are added to the Trajectory in order to change the
        values that are stored into the parameter on creation.

        After creation of a parameter, the instance of the parameter is called
        with `param.f_set(*args,**kwargs)` with `*args`, and `**kwargs` provided by the user
        with `f_preset_parameter`.

        Before an experiment is carried out it is checked if all parameters that were
        marked were also preset.

        :param param_name:

            The full name (!) of the parameter that is to be changed after its creation.

        :param args:

            Arguments that will be used for changing the parameter's data

        :param kwargs:

            Keyword arguments that will be used for changing the parameter's data

        Example:

        >>> traj.f_preset_parameter('groupA.param1', data=44)
        >>> traj.f_add_parameter('groupA.param1', data=11)
        >>> traj.parameters.groupA.param1
        44


other_derived_parameters = other_trajectory._derived_parameters.copy()<EOL>new_first_run_idx = min(used_runs.values())<EOL>run_name_dummy = other_trajectory.f_wildcard('<STR_LIT:$>', -<NUM_LIT:1>)<EOL>for param_name in other_derived_parameters:<EOL><INDENT>if param_name in ignore_data:<EOL><INDENT>continue<EOL><DEDENT>split_name = param_name.split('<STR_LIT:.>')<EOL>if not any(x in run_name_dummy for x in split_name):<EOL><INDENT>continue<EOL><DEDENT>ignore_data.add(param_name)<EOL>param = other_derived_parameters[param_name]<EOL>new_param_name = self._rename_full_name(param_name, other_trajectory,<EOL>used_runs=used_runs)<EOL>if new_param_name in self:<EOL><INDENT>my_param = self.f_get(new_param_name, fast_access=False)<EOL>if (my_param._equal_values(my_param.f_get(), param.f_get()) and<EOL>not (my_param.f_has_range() or param.f_has_range())):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>first_new_param_name = self._rename_full_name(param_name,<EOL>other_trajectory,<EOL>new_run_idx=new_first_run_idx)<EOL>rename_dict[param_name] = first_new_param_name<EOL>comment = param.v_comment<EOL>param_type = param.f_get_class_name()<EOL>param_type = self._create_class(param_type)<EOL>first_param = self.f_add_leaf(param_type,<EOL>first_new_param_name,<EOL>comment=comment)<EOL>for run_idx in used_runs.values():<EOL><INDENT>if run_idx == new_first_run_idx:<EOL><INDENT>continue<EOL><DEDENT>next_name = self._rename_full_name(param_name, other_trajectory,<EOL>new_run_idx=run_idx)<EOL>split_name = next_name.split('<STR_LIT:.>')<EOL>link_name = split_name.pop()<EOL>location_name = '<STR_LIT:.>'.join(split_name)<EOL>if not self.f_contains(location_name, shortcuts=False):<EOL><INDENT>the_group = self.f_add_group(location_name)<EOL><DEDENT>else:<EOL><INDENT>the_group = self.f_get(location_name)<EOL><DEDENT>the_group.f_add_link(link_name, first_param)<EOL><DEDENT><DEDENT>for param_name in other_derived_parameters:<EOL><INDENT>if param_name in ignore_data:<EOL><INDENT>continue<EOL><DEDENT>split_name = param_name.split('<STR_LIT:.>')<EOL>ignore_data.add(param_name)<EOL>if any(x in other_trajectory._reversed_wildcards and x not in allowed_translations<EOL>for x in split_name):<EOL><INDENT>continue<EOL><DEDENT>new_name = self._rename_full_name(param_name, other_trajectory,<EOL>used_runs=used_runs)<EOL>if self.f_contains(new_name):<EOL><INDENT>my_param = self.f_get(new_name, fast_access=False)<EOL>param = other_derived_parameters[param_name]<EOL>if (my_param._equal_values(my_param.f_get(), param.f_get()) and<EOL>not (my_param.f_has_range() or param.f_has_range())):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>self._logger.error('<STR_LIT>'<EOL>'<STR_LIT>' % new_name)<EOL><DEDENT><DEDENT>rename_dict[param_name] = new_name<EOL><DEDENT>

Merges derived parameters that have the `run_ALL` in a name.

        Creates a new parameter with the name of the first new run and links to this
        parameter to avoid copying in all other runs.


Changes the run name to make the trajectory behave as during a single run


return self._python<EOL>

The version of python as a string that was used to create the trajectory


@not_in_run<EOL><INDENT>def f_iter_runs(self, start=<NUM_LIT:0>, stop=None, step=<NUM_LIT:1>, yields='<STR_LIT:name>'):<DEDENT>

if stop is None:<EOL><INDENT>stop =len(self)<EOL><DEDENT>elif stop > len(self):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>yields = yields.lower()<EOL>if yields == '<STR_LIT:name>':<EOL><INDENT>yield_func = lambda x: self.f_idx_to_run(x)<EOL><DEDENT>elif yields == '<STR_LIT>':<EOL><INDENT>yield_func = lambda x: x<EOL><DEDENT>elif yields == '<STR_LIT>':<EOL><INDENT>yield_func = lambda x: self<EOL><DEDENT>elif yields == '<STR_LIT>':<EOL><INDENT>yield_func = lambda x: self.__copy__()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>for idx in range(start, stop, step):<EOL><INDENT>self.f_set_crun(idx)<EOL>yield yield_func(idx)<EOL><DEDENT>self.f_set_crun(None)<EOL>

Makes the trajectory iterate over all runs.

        :param start: Start index of run

        :param stop: Stop index, leave ``None`` for length of trajectory

        :param step: Stepsize

        :param yields:

            What should be yielded: ``'name'`` of run, ``idx`` of run
            or ``'self'`` to simply return the trajectory container.

            You can also pick ``'copy'`` to get **shallow** copies (ie the tree is copied but
            no leave nodes except explored ones.) of your trajectory,
            might lead to some of overhead.

        Note that after a full iteration, the trajectory is set back to normal.

        Thus, the following code snippet

        ::

            for run_name in traj.f_iter_runs():

                 # Do some stuff here...

        is equivalent to

        ::

            for run_name in traj.f_get_run_names(sort=True):
                traj.f_set_crun(run_name)

                # Do some stuff here...

            traj.f_set_crun(None)

        :return:

            Iterator over runs. The iterator itself will return the run names but modify
            the trajectory in each iteration and set it back do normal in the end.


def f_start_run(self, run_name_or_idx=None, turn_into_run=True):

if self._run_started:<EOL><INDENT>return self<EOL><DEDENT>if run_name_or_idx is None:<EOL><INDENT>if self.v_idx == -<NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.f_set_crun(run_name_or_idx)<EOL><DEDENT>self._run_started = True<EOL>if turn_into_run:<EOL><INDENT>self._make_single_run()<EOL><DEDENT>self._set_start()<EOL>return self<EOL>

Can be used to manually allow running of an experiment without using an environment.

        :param run_name_or_idx:

            Can manually set a trajectory to a particular run. If `None` the current run
            the trajectory is set to is used.

        :param turn_into_run:

            Turns the trajectory into a run, i.e. reduces functionality but makes storing
            more efficient.


idx = run_information_dict['<STR_LIT>']<EOL>name = run_information_dict['<STR_LIT:name>']<EOL>self._run_information[name] = run_information_dict<EOL>self._updated_run_information.add(idx)<EOL>

Overwrites the run information of a particular run


def _merge_slowly(self, other_trajectory, rename_dict):

for other_key in rename_dict:<EOL><INDENT>new_key = rename_dict[other_key]<EOL>other_instance = other_trajectory.f_get(other_key)<EOL>if other_instance.f_is_empty():<EOL><INDENT>with self._nn_interface._disable_logging:<EOL><INDENT>other_trajectory.f_load_item(other_instance)<EOL><DEDENT><DEDENT>if not self.f_contains(new_key):<EOL><INDENT>class_name = other_instance.f_get_class_name()<EOL>class_ = self._create_class(class_name)<EOL>my_instance = self.f_add_leaf(class_, new_key)<EOL><DEDENT>else:<EOL><INDENT>my_instance = self.f_get(new_key, shortcuts=False)<EOL><DEDENT>if not my_instance.f_is_empty():<EOL><INDENT>raise RuntimeError('<STR_LIT>' % new_key)<EOL><DEDENT>load_dict = other_instance._store()<EOL>my_instance._load(load_dict)<EOL>my_instance.f_set_annotations(**other_instance.v_annotations.f_to_dict(copy=False))<EOL>my_instance.v_comment = other_instance.v_comment<EOL>self.f_store_item(my_instance)<EOL>if other_instance.v_is_parameter:<EOL><INDENT>other_instance.f_unlock()<EOL>my_instance.f_unlock()<EOL><DEDENT>other_instance.f_empty()<EOL>my_instance.f_empty()<EOL><DEDENT>

Merges trajectories by loading iteratively items of the other trajectory and
        store it into the current trajectory.

        :param rename_dict:

            Dictionary containing mappings from the old result names in the `other_trajectory`
            to the new names in the current trajectory.


result = super(Trajectory, self).__dir__()<EOL>if self._is_run:<EOL><INDENT>result = [x for x in result if not x.startswith('<STR_LIT>') or<EOL>not getattr(getattr(self, x), '<STR_LIT>', False)]<EOL><DEDENT>if not is_debug():<EOL><INDENT>result.extend(self._children.keys())<EOL><DEDENT>return result<EOL>

Adds all children to auto-completion

        In case of a single run it spares all non-available functions


self._standard_leaf = leaf<EOL>


return self._single_run_ids[name_or_idx]<EOL>

Converts an integer idx to the corresponding single run name and vice versa.

        Note during a single run ONLY useful if ``v_full_copy`` was set to True.

        :param name_or_idx: Name of a single run or an integer index

        :return: The corresponding idx or name of the single run

        Example usage:

        >>> traj.f_idx_to_run(4)
        'run_00000004'
        >>> traj.f_idx_to_run('run_00000000')
        0


return self._standard_leaf<EOL>

The standard constructor used if you add a generic leaf.

        The constructor is only used if you do not add items under the usual four subtrees
        (`parameters`, `derived_parameters`, `config`, `results`).


if self._data is not None:<EOL><INDENT>store_dict = {'<STR_LIT:data>': ObjectTable(data={'<STR_LIT:data>': [self._data]})}<EOL><DEDENT>if self.f_has_range():<EOL><INDENT>store_dict['<STR_LIT>'] = ObjectTable(data={'<STR_LIT:data>': self._explored_range})<EOL><DEDENT>self._locked = True<EOL>return store_dict<EOL>

Returns a dictionary of formatted data understood by the storage service.

        The data is put into an :class:`~pypet.parameter.ObjectTable` named 'data'.
        If the parameter is explored, the exploration range is also put into another table
        named 'explored_data'.

        :return: Dictionary containing the data and optionally the exploration range.


def _build_names_old(self, name_idx, is_dia):

name_list = self._get_name_list(is_dia)<EOL>return tuple(['<STR_LIT>' % (SparseParameter.IDENTIFIER, name,<EOL>SparseParameter.IDENTIFIER, name_idx)<EOL>for name in name_list])<EOL>


dtype = type(data)<EOL>if dtype is tuple or dtype is list and len(data) == <NUM_LIT:0>:<EOL><INDENT>return True  <EOL><DEDENT>elif dtype is np.ndarray and data.size == <NUM_LIT:0> and data.ndim == <NUM_LIT:1>:<EOL><INDENT>return True  <EOL><DEDENT>else:<EOL><INDENT>return super(ArrayParameter, self).f_supports(data)<EOL><DEDENT>

Checks if input data is supported by the parameter.


dtype = type(data)<EOL>if dtype is tuple or dtype is list:<EOL><INDENT>if len(data) == <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>old_type = None<EOL>for item in data:<EOL><INDENT>if not type(item) in pypetconstants.PARAMETER_SUPPORTED_DATA:<EOL><INDENT>return False<EOL><DEDENT>if not old_type is None and old_type != type(item):<EOL><INDENT>return False<EOL><DEDENT>old_type = type(item)<EOL><DEDENT>return True<EOL><DEDENT>elif dtype is np.ndarray or dtype is np.matrix:<EOL><INDENT>if data.size == <NUM_LIT:0>:<EOL><INDENT>return False <EOL><DEDENT>dtype = data.dtype<EOL>if np.issubdtype(dtype, np.str):<EOL><INDENT>dtype = np.str<EOL><DEDENT><DEDENT>return dtype in pypetconstants.PARAMETER_SUPPORTED_DATA<EOL>


return type(data) in pypetconstants.PARAMETER_SUPPORTED_DATA<EOL>

Checks whether the data is supported by the parameter.


if args and self.v_name is None:<EOL><INDENT>raise AttributeError('<STR_LIT>')<EOL><DEDENT>for idx, arg in enumerate(args):<EOL><INDENT>valstr = self.f_translate_key(idx)<EOL>self.f_set_single(valstr, arg)<EOL><DEDENT>for key, arg in kwargs.items():<EOL><INDENT>self.f_set_single(key, arg)<EOL><DEDENT>

Method to put data into the result.

        :param args:

            The first positional argument is stored with the name of the result.
            Following arguments are stored with `name_X` where `X` is the position
            of the argument.

        :param kwargs: Arguments are stored with the key as name.

        :raises: TypeError if outer data structure is not understood.

        Example usage:

        >>> res = Result('supergroup.subgroup.myresult', comment='I am a neat example!')
        >>> res.f_set(333,42.0, mystring='String!')
        >>> res.f_get('myresult')
        333
        >>> res.f_get('myresult_1')
        42.0
        >>> res.f_get(1)
        42.0
        >>> res.f_get('mystring')
        'String!'


for key in list(load_dict.keys()):<EOL><INDENT>if key in load_dict:<EOL><INDENT>if SparseResult.IDENTIFIER in key:<EOL><INDENT>new_key = key.split(SparseResult.IDENTIFIER)[<NUM_LIT:0>]<EOL>is_dia = load_dict.pop(new_key + SparseResult.IDENTIFIER + '<STR_LIT>')<EOL>name_list = SparseParameter._get_name_list(is_dia)<EOL>rename_list = ['<STR_LIT>' % (new_key, SparseResult.IDENTIFIER, name)<EOL>for name in name_list]<EOL>data_list = [load_dict.pop(name) for name in rename_list]<EOL>matrix = SparseParameter._reconstruct_matrix(data_list)<EOL>self._data[new_key] = matrix<EOL><DEDENT>else:<EOL><INDENT>self._data[key] = load_dict[key]<EOL><DEDENT><DEDENT><DEDENT>

Loads data from `load_dict`

        Reconstruction of sparse matrices similar to the :class:`~pypet.parameter.SparseParameter`.


if self.v_locked:<EOL><INDENT>raise pex.ParameterLockedException('<STR_LIT>' % self.v_full_name)<EOL><DEDENT>if '<STR_LIT:data>' in load_dict:<EOL><INDENT>dump = load_dict['<STR_LIT:data>']<EOL>self._data = pickle.loads(dump)<EOL><DEDENT>else:<EOL><INDENT>self._logger.warning('<STR_LIT>'<EOL>'<STR_LIT>' % self.v_full_name)<EOL><DEDENT>try:<EOL><INDENT>self.v_protocol = load_dict[PickleParameter.PROTOCOL]<EOL><DEDENT>except KeyError:<EOL><INDENT>self.v_protocol = PickleParameter._get_protocol(dump)<EOL><DEDENT>if '<STR_LIT>' in load_dict:<EOL><INDENT>explore_table = load_dict['<STR_LIT>']<EOL>name_col = explore_table['<STR_LIT>']<EOL>explore_list = []<EOL>for name_id in name_col:<EOL><INDENT>arrayname = self._build_name(name_id)<EOL>loaded = pickle.loads(load_dict[arrayname])<EOL>explore_list.append(loaded)<EOL><DEDENT>self._explored_range = explore_list<EOL>self._explored = True<EOL><DEDENT>self._default = self._data<EOL>self._locked = True<EOL>

Reconstructs objects from the pickle dumps in `load_dict`.

        The 'explored_data' entry in `load_dict` is used to reconstruct
        the exploration range in the correct order.

        Sets the `v_protocol` property to the protocol used to store 'data'.


raise NotImplementedError("<STR_LIT>")<EOL>

Restores original data if changed due to exploration.

        If a Parameter is explored, the actual data is changed over the course of different
        simulations. This method restores the original data assigned before exploration.

        ABSTRACT: Needs to be defined in subclass


return not self.f_is_empty()<EOL>

Checks if parameter supports fast access.

        A parameter supports fast access if it is NOT empty!


self._protocol = value<EOL>


self._locked = False<EOL>

Unlocks the locked parameter.

        Please use it very carefully, or best do not use this function at all.
        There should better be no reason to unlock a locked parameter!
        The only exception I can think of is to unlock a large derived parameter
        after usage to subsequently call :func:`~pypet.parameter.BaseParameter.f_empty`
        to clear memory.


Similar to :func:`~pypet.parameter.BaseParameter._explore` but appends to
        the exploration range.

        :param iterable: An iterable specifying the exploration range.

        :raises:

            ParameterLockedException: If the parameter is locked

            TypeError: If the parameter did not have a range before

        Example usage:

        >>> param = Parameter('groupA.groupB.myparam', data=3.13, comment='I am a neat example')
        >>> param._explore([3.0,2.0,1.0])
        >>> param._expand([42.0,43.0])
        >>> param.f_get_range()
        (3.0,2.0,1.0,42.0,43.0)

        ABSTRACT: Needs to be defined in subclass


return len(self._explored_range) > <NUM_LIT:0><EOL>

If the parameter has a range.

        Does not have to be `True` if the parameter is explored.
        The range might be removed during pickling to save memory.
        Accordingly, `v_explored` remains `True` whereas `f_has_range` is `False`.


result = super(Result, self).__dir__()<EOL>if self._data_ is not None:<EOL><INDENT>result.extend(self._data.keys())<EOL><DEDENT>return result<EOL>


data_list = []<EOL>for val in explore_iterable:<EOL><INDENT>if not self.f_supports(val):<EOL><INDENT>raise TypeError('<STR_LIT>' % (repr(val), str(type(val))))<EOL><DEDENT>if not self._values_of_same_type(val, self._default):<EOL><INDENT>raise TypeError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(self.v_full_name, str(type(val)), str(type(self._default))))<EOL><DEDENT>data_list.append(val)<EOL><DEDENT>if len(data_list) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return data_list<EOL>

Checks if data values are  valid.

        Checks if the data values are supported by the parameter and if the values are of the same
        type as the default value.


return self._data.__iter__()<EOL>

Equivalent to iterating over the keys of the data dictionary.


return self._locked<EOL>

Whether or not the parameter is locked and prevents further modification


if self.v_locked:<EOL><INDENT>raise pex.ParameterLockedException('<STR_LIT>' % self.v_full_name)<EOL><DEDENT>if self.f_has_range():<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' % self._name)<EOL><DEDENT>if self._data is None:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' % self.v_full_name)<EOL><DEDENT>data_list = self._data_sanity_checks(explore_iterable)<EOL>self._explored_range = data_list<EOL>self._explored = True<EOL>self.f_lock()<EOL>

Explores the parameter according to the iterable.

        Raises ParameterLockedException if the parameter is locked.
        Raises TypeError if the parameter does not support the data,
        the types of the data in the iterable are not the same as the type of the default value,
        or the parameter has already an exploration range.

        Note that the parameter will iterate over the whole iterable once and store
        the individual data values into a tuple. Thus, the whole exploration range is
        explicitly stored in memory.

        :param explore_iterable: An iterable specifying the exploration range

        For example:

        >>> param._explore([3.0,2.0,1.0])
        >>> param.f_get_range()
        (3.0, 2.0, 1.0)

        :raises TypeError,ParameterLockedException


def _values_of_same_type(self, val1, val2):

if self.f_supports(val1) != self.f_supports(val2):<EOL><INDENT>return False<EOL><DEDENT>if not self.f_supports(val1) and not self.f_supports(val2):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>str(type(val1)), str(type(val2)))<EOL><DEDENT>return type(val1) is type(val2)<EOL>

Checks if two values agree in type.

        For example, two 32 bit integers would be of same type, but not a string and an integer,
        nor a 64 bit and a 32 bit integer.

        This is important for exploration. You are only allowed to explore data that
        is of the same type as the default value.

        One could always come up with a trivial solution of `type(val1) is type(val2)`.
        But sometimes your parameter does want even more strict equality or
        less type equality.

        For example, the :class:`~pypet.parameter.Parameter` has a stricter sense of
        type equality regarding numpy arrays. In order to have two numpy arrays of the same type,
        they must also agree in shape. However, the :class:`~pypet.parameter.ArrayParameter`,
        considers all numpy arrays as of being of same type regardless of their shape.

        Moreover, the :class:`~pypet.parameter.SparseParameter` considers all supported
        sparse matrices (csc, csr, bsr, dia) as being of the same type. You can make
        explorations using all these four types at once.

        The difference in how strict types are treated arises from the way parameter data
        is stored to disk and how the parameters hand over their data to the storage service
        (see :func:`pypet.parameter.BaseParameter._store`).

        The :class:`~pypet.parameter.Parameter` puts all it's data in an
        :class:`~pypet.parameter.ObjectTable` which
        has strict constraints on the column sizes. This means that numpy array columns only
        accept numpy arrays with a particular size. In contrast, the array and sparse
        parameter hand over their data as individual items which yield individual entries
        in the hdf5 node. In order to see what I mean simply run an experiment with all 3
        parameters, explore all of them, and take a look at the resulting hdf5 file!

        However, this BaseParameter class implements the straightforward version of
        `type(val1) is type(val2)` to consider data to be of the same type.

        :raises: TypeError: if both values are not supported by the parameter.


Erases all data in the parameter.

        Does not erase data from disk. So if the parameter has
        been stored with a service to disk and is emptied,
        it can be restored by loading from disk.

        :raises: ParameterLockedException: If the parameter is locked.

        ABSTRACT: Needs to be defined in subclass


return (spsp.isspmatrix_csc(data) or<EOL>spsp.isspmatrix_csr(data) or<EOL>spsp.isspmatrix_bsr(data) or<EOL>spsp.isspmatrix_dia(data))<EOL>

Checks if a data is csr, csc, bsr, or dia Scipy sparse matrix


if item == '<STR_LIT:data>':<EOL><INDENT>return self.f_get()<EOL><DEDENT>elif item == '<STR_LIT:default>':<EOL><INDENT>return self.f_get_default()<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError('<STR_LIT>' % (self.f_get_class_name(),<EOL>item))<EOL><DEDENT>

Allows to query for `.data` as an attribute


Returns an iterable to iterate over the values of the exploration range.

        Note that the returned values should be either a copy of the exploration range
        unless explicetly requested otherwise.

        :param copy:

            If range should be copied to avoid tempering with data.

        :return: Iterable

        :raises: TypeError if the parameter is not explored

        Example usage:

        >>> param = Parameter('groupA.groupB.myparam',data=22, comment='I am a neat example')
        >>> param._explore([42,43,43])
        >>> param.f_get_range()
        (42,43,44)

        ABSTRACT: Needs to be defined in subclass


return self._protocol<EOL>

The protocol used to pickle data, default is 0.

        See pickle_ documentation for the protocols.

        .. _pickle: http://docs.python.org/2/library/pickle.html


steps = traj.steps<EOL>initial_conditions = traj.initial_conditions<EOL>dimension = len(initial_conditions)<EOL>result_array = np.zeros((steps,dimension))<EOL>func_params_dict = traj.func_params.f_to_dict(short_names=True, fast_access=True)<EOL>result_array[<NUM_LIT:0>] = initial_conditions<EOL>for idx in range(<NUM_LIT:1>,steps):<EOL><INDENT>result_array[idx] = diff_func(result_array[idx-<NUM_LIT:1>], **func_params_dict) * traj.dt +result_array[idx-<NUM_LIT:1>]<EOL><DEDENT>traj.f_add_result('<STR_LIT>', data=result_array, comment='<STR_LIT>')<EOL>

Simulation function for Euler integration.

    :param traj:

        Container for parameters and results

    :param diff_func:

        The differential equation we want to integrate


def diff_lorenz(value_array, sigma, beta, rho):

diff_array = np.zeros(<NUM_LIT:3>)<EOL>diff_array[<NUM_LIT:0>] = sigma * (value_array[<NUM_LIT:1>]-value_array[<NUM_LIT:0>])<EOL>diff_array[<NUM_LIT:1>] = value_array[<NUM_LIT:0>] * (rho - value_array[<NUM_LIT:2>]) - value_array[<NUM_LIT:1>]<EOL>diff_array[<NUM_LIT:2>] = value_array[<NUM_LIT:0>] * value_array[<NUM_LIT:1>] - beta * value_array[<NUM_LIT:2>]<EOL>return diff_array<EOL>

The Lorenz attractor differential equation

    :param value_array: 3d array containing the x,y, and z component values.
    :param sigma: Constant attractor parameter
    :param beta: FConstant attractor parameter
    :param rho: Constant attractor parameter

    :return: 3d array of the Lorenz system evaluated at `value_array`


<EOL>traj.last_process_name = mp.current_process().name<EOL>traj.results.f_store(store_data=<NUM_LIT:3>)<EOL>

Target function that manipulates the trajectory.

    Stores the current name of the process into the trajectory and
    **overwrites** previous settings.

    :param traj:

        Trajectory container with multiprocessing safe storage service


print_folder = os.path.join(traj.analysis.plot_folder,<EOL>traj.v_name, traj.v_crun)<EOL>print_folder = os.path.abspath(print_folder)<EOL>if not os.path.isdir(print_folder):<EOL><INDENT>os.makedirs(print_folder)<EOL><DEDENT>return print_folder<EOL>

Makes a subfolder for plots.

        :return: Path name to print folder


def _add_monitors(self, traj,  network, network_dict):

neurons_e = network_dict['<STR_LIT>']<EOL>monitor_list = []<EOL>self.spike_monitor = SpikeMonitor(neurons_e)<EOL>monitor_list.append(self.spike_monitor)<EOL>self.V_monitor = StateMonitor(neurons_e,'<STR_LIT>',<EOL>record=list(traj.neuron_records))<EOL>monitor_list.append(self.V_monitor)<EOL>self.I_syn_e_monitor = StateMonitor(neurons_e, '<STR_LIT>',<EOL>record=list(traj.neuron_records))<EOL>monitor_list.append(self.I_syn_e_monitor)<EOL>self.I_syn_i_monitor = StateMonitor(neurons_e, '<STR_LIT>',<EOL>record=list(traj.neuron_records))<EOL>monitor_list.append(self.I_syn_i_monitor)<EOL>network.add(*monitor_list)<EOL>network_dict['<STR_LIT>'] = monitor_list<EOL>


def analyse(self, traj, network, current_subrun, subrun_list, network_dict):

<EOL>if len(subrun_list)==<NUM_LIT:0>:<EOL><INDENT>spikes_e = traj.results.monitors.spikes_e<EOL>time_window = traj.parameters.analysis.statistics.time_window<EOL>start_time = traj.parameters.simulation.durations.initial_run<EOL>end_time = start_time+traj.parameters.simulation.durations.measurement_run<EOL>neuron_ids = traj.parameters.analysis.statistics.neuron_ids<EOL>mean_ff = self._compute_mean_fano_factor(<EOL>neuron_ids, spikes_e, time_window, start_time, end_time)<EOL>traj.f_add_result('<STR_LIT>', mean_ff, comment='<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>print('<STR_LIT>' % (traj.R_ee, mean_ff))<EOL><DEDENT>

Calculates average Fano Factor of a network.

        :param traj:

            Trajectory container

            Expects:

            `results.monitors.spikes_e`: Data from SpikeMonitor for excitatory neurons

            Adds:

            `results.statistics.mean_fano_factor`: Average Fano Factor

        :param network:

            The BRIAN network

        :param current_subrun:

            BrianParameter

        :param subrun_list:

            Upcoming subruns, analysis is only performed if subruns is empty,
            aka the final subrun has finished.

        :param network_dict:

            Dictionary of items shared among componetns


model_eqs = traj.model.eqs<EOL>post_eqs={}<EOL>for name_post in ['<STR_LIT:i>','<STR_LIT:e>']:<EOL><INDENT>variables_dict ={}<EOL>new_model_eqs=model_eqs.replace('<STR_LIT:POST>', name_post)<EOL>for name_pre in ['<STR_LIT:i>', '<STR_LIT:e>']:<EOL><INDENT>conn_eqs = traj.model.synaptic.eqs<EOL>new_conn_eqs = conn_eqs.replace('<STR_LIT>', name_pre)<EOL>new_model_eqs += new_conn_eqs<EOL>tau1 = traj.model.synaptic['<STR_LIT>']<EOL>tau2 = traj.model.synaptic['<STR_LIT>'+name_pre]<EOL>normalization = (tau1-tau2) / tau2<EOL>invtau1=<NUM_LIT:1.0>/tau1<EOL>invtau2 = <NUM_LIT:1.0>/tau2<EOL>variables_dict['<STR_LIT>'+name_pre] = invtau1<EOL>variables_dict['<STR_LIT>'+name_pre] = invtau2<EOL>variables_dict['<STR_LIT>'+name_pre] = normalization<EOL>variables_dict['<STR_LIT>'+name_pre] = tau1<EOL>variables_dict['<STR_LIT>'+name_pre] = tau2<EOL><DEDENT>variables_dict['<STR_LIT>'+name_post] = traj.model['<STR_LIT>'+name_post]<EOL>post_eqs[name_post] = Equations(new_model_eqs, **variables_dict)<EOL><DEDENT>return post_eqs<EOL>

Computes model equations for the excitatory and inhibitory population.

        Equation objects are created by fusing `model.eqs` and `model.synaptic.eqs`
        and replacing `PRE` by `i` (for inhibitory) or `e` (for excitatory) depending
        on the type of population.

        :return: Dictionary with 'i' equation object for inhibitory neurons and 'e' for excitatory


@staticmethod<EOL><INDENT>def _compute_fano_factor(spike_res, neuron_id, time_window, start_time, end_time):<DEDENT>

assert(end_time >= start_time+time_window)<EOL>bins = (end_time-start_time)/time_window<EOL>bins = int(np.floor(bins))<EOL>binned_spikes = np.zeros(bins)<EOL>spike_array_neuron = spike_res.t[spike_res.i==neuron_id]<EOL>for bin in range(bins):<EOL><INDENT>lower_time = start_time+time_window*bin<EOL>upper_time = start_time+time_window*(bin+<NUM_LIT:1>)<EOL>spike_array_interval = spike_array_neuron[spike_array_neuron >= lower_time]<EOL>spike_array_interval = spike_array_interval[spike_array_interval < upper_time]<EOL>spikes = len(spike_array_interval)<EOL>binned_spikes[bin]=spikes<EOL><DEDENT>var = np.var(binned_spikes)<EOL>avg = np.mean(binned_spikes)<EOL>if avg > <NUM_LIT:0>:<EOL><INDENT>return var/float(avg)<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Computes Fano Factor for one neuron.

        :param spike_res:

            Result containing the spiketimes of all neurons

        :param neuron_id:

            Index of neuron for which FF is computed

        :param time_window:

            Length of the consecutive time windows to compute the FF

        :param start_time:

            Start time of measurement to consider

        :param end_time:

            End time of measurement to consider

        :return:

            Fano Factor (float) or
            returns 0 if mean firing activity is 0.


def _build_connections(self, traj, brian_list, network_dict):

connections = traj.connections<EOL>neurons_i = network_dict['<STR_LIT>']<EOL>neurons_e = network_dict['<STR_LIT>']<EOL>print('<STR_LIT>')<EOL>self.conn_ii = Synapses(neurons_i,neurons_i, on_pre='<STR_LIT>' % connections.J_ii)<EOL>self.conn_ii.connect('<STR_LIT>', p=connections.p_ii)<EOL>print('<STR_LIT>')<EOL>self.conn_ei = Synapses(neurons_i,neurons_e, on_pre='<STR_LIT>' % connections.J_ei)<EOL>self.conn_ei.connect('<STR_LIT>', p=connections.p_ei)<EOL>print('<STR_LIT>')<EOL>self.conn_ie = Synapses(neurons_e,neurons_i, on_pre='<STR_LIT>' % connections.J_ie)<EOL>self.conn_ie.connect('<STR_LIT>', p=connections.p_ie)<EOL>conns_list = [self.conn_ii, self.conn_ei, self.conn_ie]<EOL>if connections.R_ee > <NUM_LIT:1.0>:<EOL><INDENT>cluster_list=[]<EOL>cluster_conns_list=[]<EOL>model=traj.model<EOL>clusters = int(model.N_e/connections.clustersize_e)<EOL>traj.f_add_derived_parameter('<STR_LIT>', clusters, comment='<STR_LIT>')<EOL>p_out = (connections.p_ee*model.N_e) /(connections.R_ee*connections.clustersize_e+model.N_e- connections.clustersize_e)<EOL>p_in = p_out * connections.R_ee<EOL>traj.f_add_derived_parameter('<STR_LIT>', p_in ,<EOL>comment='<STR_LIT>')<EOL>traj.f_add_derived_parameter('<STR_LIT>', p_out ,<EOL>comment='<STR_LIT>')<EOL>low_index = <NUM_LIT:0><EOL>high_index = connections.clustersize_e<EOL>for irun in range(clusters):<EOL><INDENT>cluster = neurons_e[low_index:high_index]<EOL>print('<STR_LIT>' % (irun, clusters))<EOL>conn = Synapses(cluster,cluster,<EOL>on_pre='<STR_LIT>' % (connections.J_ee*connections.strength_factor))<EOL>conn.connect('<STR_LIT>', p=p_in)<EOL>cluster_conns_list.append(conn)<EOL>if low_index > <NUM_LIT:0>:<EOL><INDENT>rest_low = neurons_e[<NUM_LIT:0>:low_index]<EOL>print('<STR_LIT>')<EOL>low_conn = Synapses(cluster,rest_low,<EOL>on_pre='<STR_LIT>' % connections.J_ee)<EOL>low_conn.connect('<STR_LIT>', p=p_out)<EOL>cluster_conns_list.append(low_conn)<EOL><DEDENT>if high_index < model.N_e:<EOL><INDENT>rest_high = neurons_e[high_index:model.N_e]<EOL>print('<STR_LIT>')<EOL>high_conn = Synapses(cluster,rest_high,<EOL>on_pre='<STR_LIT>' % connections.J_ee)<EOL>high_conn.connect('<STR_LIT>', p=p_out)<EOL>cluster_conns_list.append(high_conn)<EOL><DEDENT>low_index=high_index<EOL>high_index+=connections.clustersize_e<EOL><DEDENT>self.cluster_conns=cluster_conns_list<EOL>conns_list+=cluster_conns_list<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>self.conn_ee = Synapses(neurons_e,neurons_e,<EOL>on_pre='<STR_LIT>' % connections.J_ee)<EOL>self.conn_ee.connect('<STR_LIT>', p=connections.p_ee)<EOL>conns_list.append(self.conn_ee)<EOL><DEDENT>brian_list.extend(conns_list)<EOL>network_dict['<STR_LIT>'] = conns_list<EOL>

Connects neuron groups `neurons_i` and `neurons_e`.

        Adds all connections to `brian_list` and adds a list of connections
        with the key 'connections' to the `network_dict`.


z=traj.x*traj.y<EOL>traj.f_add_result('<STR_LIT:z>',z=z, comment='<STR_LIT>')<EOL>

Sophisticated simulation of multiplication


z=traj.x*traj.y<EOL>traj.f_add_result('<STR_LIT:z>',z, comment='<STR_LIT>')<EOL>


explored_parameters = traj.f_get_explored_parameters()<EOL>filename = '<STR_LIT>'<EOL>for param in explored_parameters.values():<EOL><INDENT>short_name = param.v_name<EOL>val = param.f_get()<EOL>filename += '<STR_LIT>' % (short_name, str(val))<EOL><DEDENT>return filename[:-<NUM_LIT:2>] + '<STR_LIT>'<EOL>

Function to create generic filenames based on what has been explored


<EOL>logger = logging.getLogger()<EOL>folder = os.path.join(os.getcwd(), '<STR_LIT>', '<STR_LIT>')<EOL>if not os.path.isdir(folder):<EOL><INDENT>os.makedirs(folder)<EOL><DEDENT>filename = os.path.join(folder, '<STR_LIT>')<EOL>env = Environment(trajectory='<STR_LIT>',<EOL>multiproc=True,<EOL>ncores=<NUM_LIT:4>,<EOL>wrap_mode='<STR_LIT>',<EOL>filename=filename,<EOL>overwrite_file=True)<EOL>traj = env.traj<EOL>traj.par.ncells = Parameter('<STR_LIT>', <NUM_LIT>, '<STR_LIT>')<EOL>traj.par.steps = Parameter('<STR_LIT>', <NUM_LIT>, '<STR_LIT>')<EOL>traj.par.rule_number = Parameter('<STR_LIT>', <NUM_LIT:30>, '<STR_LIT>')<EOL>traj.par.initial_name = Parameter('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>traj.par.seed = Parameter('<STR_LIT>', <NUM_LIT>, '<STR_LIT>')<EOL>exp_dict = {'<STR_LIT>' : [<NUM_LIT:10>, <NUM_LIT:30>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>],<EOL>'<STR_LIT>' : ['<STR_LIT>', '<STR_LIT>'],}<EOL>exp_dict = cartesian_product(exp_dict)<EOL>traj.f_explore(exp_dict)<EOL>logger.info('<STR_LIT>')<EOL>env.run(wrap_automaton)<EOL>traj.f_load(load_data=<NUM_LIT:2>)<EOL>logger.info('<STR_LIT>')<EOL>for idx, run_name in enumerate(traj.f_iter_runs()):<EOL><INDENT>filename = os.path.join(folder, make_filename(traj))<EOL>plot_pattern(traj.crun.pattern, traj.rule_number, filename)<EOL>progressbar(idx, len(traj), logger=logger)<EOL><DEDENT>env.disable_logging()<EOL>

Main *boilerplate* function to start simulation


return eval_one_max(*the_tuple)<EOL>

Wrapper function that unpacks a single tuple as arguments to the fitness function.

    The pool's map function only allows a single iterable so we need to zip it first
    and then unpack it here.


@manual_run(store_meta_data=True)   <EOL>def eval_one_max(traj, individual):

traj.f_add_result('<STR_LIT>', list(individual))<EOL>fitness = sum(individual)<EOL>traj.f_add_result('<STR_LIT>', fitness)<EOL>traj.f_store()<EOL>return (fitness,)<EOL>


add_parameters(traj)<EOL>add_exploration(traj)<EOL>return (run_neuron,(),{}), (neuron_postproc,(),{})<EOL>

A pipeline function that defines the entire experiment

    :param traj:

        Container for results and parameters

    :return:

        Two tuples. First tuple contains the actual run function plus additional
        arguments (yet we have none). Second tuple contains the
        postprocessing function including additional arguments.


z=traj.x * traj.y<EOL>traj.f_add_result('<STR_LIT:z>', z, comment='<STR_LIT>')<EOL>


z = traj.x * traj.y<EOL>traj.f_add_result('<STR_LIT:z>', z, comment='<STR_LIT>')<EOL>

Example of a sophisticated simulation that involves multiplying two values.

    :param traj:

        Trajectory containing
        the parameters in a particular combination,
        it also serves as a container for results.


z=traj.x*traj.y<EOL>traj.f_add_result('<STR_LIT:z>',z=z, comment='<STR_LIT>',)<EOL>


fitness = sum(traj.individual)<EOL>return (fitness,)<EOL>


<EOL>api = Api()<EOL>api.authenticate()<EOL>availability = api.check_upload_status(video_id)<EOL>if availability is not True:<EOL><INDENT>video = Video.objects.filter(video_id=video_id).get()<EOL>state = availability["<STR_LIT>"]<EOL>if state == "<STR_LIT>" or state == "<STR_LIT>":<EOL><INDENT>return render_to_response(<EOL>"<STR_LIT>",<EOL>{"<STR_LIT>": video, "<STR_LIT>": video_id, "<STR_LIT:message>":<EOL>_("<STR_LIT>"), "<STR_LIT>": availability},<EOL>context_instance=RequestContext(request)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return render_to_response(<EOL>"<STR_LIT>",<EOL>{"<STR_LIT>": video, "<STR_LIT>": video_id,<EOL>"<STR_LIT:message>": _("<STR_LIT>"), "<STR_LIT>": availability},<EOL>context_instance=RequestContext(request)<EOL>)<EOL><DEDENT><DEDENT>video_params = _video_params(request, video_id)<EOL>return render_to_response(<EOL>"<STR_LIT>",<EOL>video_params,<EOL>context_instance=RequestContext(request)<EOL>)<EOL>


return self.swf_url<EOL>


def _access_control(self, access_control, my_media_group=None):

<EOL>extension = None<EOL>if access_control is AccessControl.Private:<EOL><INDENT>if my_media_group:<EOL><INDENT>my_media_group.private = gdata.media.Private()<EOL><DEDENT><DEDENT>elif access_control is AccessControl.Unlisted:<EOL><INDENT>from gdata.media import YOUTUBE_NAMESPACE<EOL>from atom import ExtensionElement<EOL>kwargs = {<EOL>"<STR_LIT>": YOUTUBE_NAMESPACE,<EOL>"<STR_LIT>": {'<STR_LIT:action>': '<STR_LIT:list>', '<STR_LIT>': '<STR_LIT>'},<EOL>}<EOL>extension = ([ExtensionElement('<STR_LIT>', **kwargs)])<EOL><DEDENT>return extension<EOL>

Prepares the extension element for access control
Extension element is the optional parameter for the YouTubeVideoEntry
We use extension element to modify access control settings

Returns:
    tuple of extension elements


return Api.yt_service.GetYouTubeVideoEntry('<STR_LIT>' % video_id)<EOL>

Retrieve a specific video entry and return it
@see http://gdata-python-client.googlecode.com/hg/pydocs/gdata.youtube.html#YouTubeVideoEntry


<EOL>if not self.authenticated:<EOL><INDENT>raise ApiError(_("<STR_LIT>"))<EOL><DEDENT>entry = self.fetch_video(video_id)<EOL>upload_status = Api.yt_service.CheckUploadStatus(entry)<EOL>if upload_status is not None:<EOL><INDENT>video_upload_state = upload_status[<NUM_LIT:0>]<EOL>detailed_message = upload_status[<NUM_LIT:1>]<EOL>return {"<STR_LIT>": video_upload_state, "<STR_LIT>": detailed_message}<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>

Checks the video upload status
Newly uploaded videos may be in the processing state

Authentication is required

Returns:
    True if video is available
    otherwise a dict containes upload_state and detailed message
    i.e. {"upload_state": "processing", "detailed_message": ""}


return render_to_response('<STR_LIT>', {}, context_instance=RequestContext(request))<EOL>


__, ext = os.path.splitext(path)<EOL>if ext in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>import ruamel.yaml<EOL>loader = ruamel.yaml.safe_load<EOL><DEDENT>else:<EOL><INDENT>loader = json.load<EOL><DEDENT>with open(path) as f:<EOL><INDENT>config = loader(f)<EOL><DEDENT>return config<EOL>

Given a file path, parse it based on its extension (YAML or JSON)
and return the values as a Python dictionary. JSON is the default if an
extension can't be determined.


def __init__(self,<EOL>file_env_var: str = None,<EOL>default_files: List[str] = None,<EOL>load: bool = False):

self.file_env_var = file_env_var<EOL>self.config_file = None<EOL>self.default_files = default_files or []<EOL>if load:<EOL><INDENT>self.load()<EOL><DEDENT>

:param file_env_var: the name of an environment variable which can be
                     used for the name of the configuration file to
                     load
:param default_files: if no file is given, try to load a configuration
                      from these files in order
:param load: load config file on instantiation [default: False].

A docstring defined on the class should be a plain-text description
used as a header when generating a configuration file.


with self.cvar:<EOL><INDENT>self.count.value += <NUM_LIT:1><EOL>self.cvar.notify_all()<EOL>while self.count.value < self.n_procs:<EOL><INDENT>self.cvar.wait()<EOL><DEDENT><DEDENT>

Wait until all processes have reached the barrier.


with self.cvar:<EOL><INDENT>self.count.value = <NUM_LIT:0><EOL><DEDENT>

Re-set the barrier so that it can be used again.


def get_queue(self, path, n_procs=<NUM_LIT:4>, read_ahead=None, cyclic=False, block_size=None, ordered=False):

<EOL>example = self.__get_batch(path, block_size)<EOL>block_size = example.shape[<NUM_LIT:0>]<EOL>if read_ahead is None:<EOL><INDENT>read_ahead = <NUM_LIT:2>*n_procs + <NUM_LIT:1><EOL><DEDENT>cbuf = SharedCircBuf(read_ahead, example)<EOL>stop = multiprocessing.Event()<EOL>barrier = Barrier(n_procs)<EOL>sync = GuardSynchronizer() if ordered else None<EOL>procs = []<EOL>for i in range(n_procs):<EOL><INDENT>process = multiprocessing.Process(target=_Streamer__read_process, args=(<EOL>self, path, block_size, cbuf, stop, barrier, cyclic,<EOL>i * block_size, n_procs * block_size, sync<EOL>))<EOL>process.daemon = True<EOL>process.start()<EOL>procs.append(process)<EOL><DEDENT>if not cyclic:<EOL><INDENT>def monitor():<EOL><INDENT>for p in procs:<EOL><INDENT>p.join()<EOL><DEDENT>cbuf.close()<EOL><DEDENT>monitor_thread = threading.Thread(target=monitor)<EOL>monitor_thread.daemon = True<EOL>monitor_thread.start()<EOL><DEDENT>return Streamer.Queue(cbuf, stop, block_size)<EOL>

Get a queue that allows direct access to the internal buffer. If the dataset to be read is chunked, the
block_size should be a multiple of the chunk size to maximise performance. In this case it is best to leave it
to the default. When cyclic=False, and block_size does not divide the dataset evenly, the remainder elements
will not be returned by the queue. When cyclic=True, the remainder elements will be part of a block that wraps
around the end and includes element from the beginning of the dataset. By default, blocks are returned in the
order in which they become available. The ordered option will force blocks to be returned in on-disk order.

:param path: The HDF5 path to the dataset that should be read.
:param n_procs: The number of background processes used to read the datset in parallel.
:param read_ahead: The number of blocks to allocate in the internal buffer.
:param cyclic: True if the queue should wrap at the end of the dataset.
:param block_size: The size along the outer dimension of the blocks to be read. Defaults to a multiple of
    the chunk size, or to a 128KB sized block if the dataset is not chunked.
:param ordered: Force the reader return data in on-disk order. May result in performance penalty.
:return: A queue object that allows access to the internal buffer.


def __get_batch(self, path, length, last=False):

import tables<EOL>h5_file = tables.open_file(self.filename, '<STR_LIT:r>')<EOL>h5_node = h5_file.get_node(path)<EOL>if len(h5_node) == <NUM_LIT:0>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if length is None:<EOL><INDENT>chunkshape = h5_node.chunkshape<EOL>if chunkshape is None:<EOL><INDENT>default_length = <NUM_LIT>*<NUM_LIT:2>**<NUM_LIT:10>//h5_node[<NUM_LIT:0>].nbytes  <EOL>length = min(h5_node.shape[<NUM_LIT:0>], default_length)<EOL><DEDENT>else:<EOL><INDENT>length = chunkshape[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>if last:<EOL><INDENT>example = h5_node[length*(len(h5_node)//length):].copy()<EOL><DEDENT>else:<EOL><INDENT>example = h5_node[:length].copy()<EOL><DEDENT>h5_file.close()<EOL>return example<EOL>

Get a block of data from the node at path.

:param path: The path to the node to read from.
:param length: The length along the outer dimension to read.
:param last: True if the remainder elements should be read.
:return: A copy of the requested block of data as a numpy array.


self.barrier_A.wait()<EOL>self.barrier_A, self.barrier_B = self.barrier_B, self.barrier_A<EOL>self.barrier_A.reset()<EOL>


def decorator(callback):<EOL><INDENT>self._error_handlers[status] = callback<EOL>return callback<EOL><DEDENT>return decorator<EOL>

Decorator to add a callback that generates error page.

        The *status* parameter specifies the HTTP response status code
        for which the decorated callback should be invoked. If the
        *status* argument is not specified, then the decorated callable
        is considered to be a fallback callback.

        A fallback callback, when defined, is invoked to generate the
        error page for any HTTP response representing an error when
        there is no error handler defined explicitly for the response
        code of the HTTP response.

        Arguments:
          status(int, optional): HTTP response status code.

        Returns:
          function: Decorator function to add error handler.


self._re = []<EOL>self._wildcards = []<EOL>for token in WildcardRoute.tokens(pattern):<EOL><INDENT>if token and token.startswith('<STR_LIT:<>') and token.endswith('<STR_LIT:>>'):<EOL><INDENT>w = Wildcard(token)<EOL>self._wildcards.append(w)<EOL>self._re.append(w.regex())<EOL><DEDENT>else:<EOL><INDENT>self._re.append(re.escape(token))<EOL><DEDENT><DEDENT>self._re = re.compile('<STR_LIT>' + '<STR_LIT>'.join(self._re) + '<STR_LIT:$>')<EOL>self._callback = callback<EOL>

Initialize wildcard route.

        Arguments:
          pattern (str): Pattern associated with the route.
          callback (callable): Route handler.


self.start = start_response_callable<EOL>self.status = <NUM_LIT:200><EOL>self.media_type = '<STR_LIT>'<EOL>self.charset = '<STR_LIT>'<EOL>self._headers = []<EOL>self.body = None<EOL>self.state = {}<EOL>

Initialize the current response object.

        Arguments:
          start_response_callable (callable): Callable that starts response.


return self.route('<STR_LIT:GET>', pattern)<EOL>

Decorator to add route for an HTTP GET request.

        Arguments:
          pattern (str): Routing pattern the path must match.

        Returns:
          function: Decorator to add route for HTTP GET request.


return RegexRoute._group_re.search(pattern) is not None<EOL>

Determine if a pattern looks like a regular expression.

        Arguments:
          pattern (str): Any route pattern.

        Returns:
          ``True`` if the specified pattern looks like a regex,
          ``False`` otherwise.


if self.response.status in self._error_handlers:<EOL><INDENT>return self._error_handlers[self.response.status]<EOL><DEDENT>elif None in self._error_handlers:<EOL><INDENT>return self._error_handlers[None]<EOL><DEDENT>else:<EOL><INDENT>self.response.media_type = '<STR_LIT>'<EOL>return lambda: self.response.status_line<EOL><DEDENT>

Return an error page for the current response status.


self._re = re.compile(pattern)<EOL>self._callback = callback<EOL>

Initialize regular expression route.

        Arguments:
          pattern (str): Pattern associated with the route.
          callback (callable): Route handler.


self.environ = environ<EOL>self.method = environ.get('<STR_LIT>', '<STR_LIT:GET>')<EOL>self.path = environ.get('<STR_LIT>', '<STR_LIT:/>')<EOL>if not self.path:<EOL><INDENT>self.path = '<STR_LIT:/>'<EOL><DEDENT>self.query = MultiDict()<EOL>self.form = MultiDict()<EOL>self.cookies = MultiDict()<EOL>if '<STR_LIT>' in environ:<EOL><INDENT>for k, v in urllib.parse.parse_qsl(environ['<STR_LIT>']):<EOL><INDENT>self.query[k] = v<EOL><DEDENT><DEDENT>if '<STR_LIT>' in environ:<EOL><INDENT>fs = cgi.FieldStorage(fp=environ['<STR_LIT>'],<EOL>environ=environ)<EOL>for k in fs:<EOL><INDENT>for v in fs.getlist(k):<EOL><INDENT>self.form[k] = v<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in environ:<EOL><INDENT>cookies = http.cookies.SimpleCookie(environ['<STR_LIT>'])<EOL>for c in cookies.values():<EOL><INDENT>self.cookies[c.key] = c.value<EOL><DEDENT><DEDENT>

Initialize the current request object.

        Arguments:
          environ (dict): Dictionary of environment variables.


if method in self._literal and path in self._literal[method]:<EOL><INDENT>return self._literal[method][path], [], {}<EOL><DEDENT>else:<EOL><INDENT>return self._resolve_non_literal_route(method, path)<EOL><DEDENT>

Resolve a request to a route handler.

        Arguments:
          method (str): HTTP method, e.g. GET, POST, etc. (type: str)
          path (str): Request path

        Returns:
          tuple or None: A tuple of three items:

            1. Route handler (callable)
            2. Positional arguments (list)
            3. Keyword arguments (dict)

          ``None`` if no route matches the request.


def parse(text, encoding='<STR_LIT:utf-8>', handler=None, **defaults):

<EOL>text = u(text, encoding).strip()<EOL>metadata = defaults.copy()<EOL>handler = handler or detect_format(text, handlers)<EOL>if handler is None:<EOL><INDENT>return metadata, text<EOL><DEDENT>try:<EOL><INDENT>fm, content = handler.split(text)<EOL><DEDENT>except ValueError:<EOL><INDENT>return metadata, text<EOL><DEDENT>fm = handler.load(fm)<EOL>if isinstance(fm, dict):<EOL><INDENT>metadata.update(fm)<EOL><DEDENT>return metadata, content.strip()<EOL>

Parse text with frontmatter, return metadata and content.
Pass in optional metadata defaults as keyword args.

If frontmatter is not found, returns an empty metadata dictionary
(or defaults) and original text content.

::

    >>> with open('tests/hello-world.markdown') as f:
    ...     metadata, content = frontmatter.parse(f.read())
    >>> print(metadata['title'])
    Hello, world!


def load(fd, encoding='<STR_LIT:utf-8>', handler=None, **defaults):

if hasattr(fd, '<STR_LIT>'):<EOL><INDENT>text = fd.read()<EOL><DEDENT>else:<EOL><INDENT>with codecs.open(fd, '<STR_LIT:r>', encoding) as f:<EOL><INDENT>text = f.read()<EOL><DEDENT><DEDENT>handler = handler or detect_format(text, handlers)<EOL>return loads(text, encoding, handler, **defaults)<EOL>

Load and parse a file-like object or filename,
return a :py:class:`post <frontmatter.Post>`.

::

    >>> post = frontmatter.load('tests/hello-world.markdown')
    >>> with open('tests/hello-world.markdown') as f:
    ...     post = frontmatter.load(f)


self.metadata[name] = value<EOL>


raise NotImplementedError<EOL>


if self.FM_BOUNDARY.match(text):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Decide whether this handler can parse the given ``text``,
and return True or False.

Note that this is *not* called when passing a handler instance to
:py:func:`frontmatter.load <frontmatter.load>` or :py:func:`loads <frontmatter.loads>`.


kwargs.setdefault('<STR_LIT>', SafeLoader)<EOL>return yaml.load(fm, **kwargs)<EOL>

Parse YAML front matter. This uses yaml.SafeLoader by default.


http_requests = []<EOL>failures = max_failures<EOL>issues_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issues_next_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issues_empty_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issue_2_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issue_5_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issue_9_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>issue_7311_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>user_3_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>user_4_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>user_24_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>user_25_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>def request_callback(method, uri, headers):<EOL><INDENT>nonlocal failures<EOL>status = <NUM_LIT:200><EOL>last_request = httpretty.last_request()<EOL>params = last_request.querystring<EOL>if uri.startswith(REDMINE_ISSUES_URL):<EOL><INDENT>updated_on = params['<STR_LIT>'][<NUM_LIT:0>]<EOL>offset = params['<STR_LIT>'][<NUM_LIT:0>]<EOL>if (updated_on == '<STR_LIT>' and offset == '<STR_LIT:0>'):<EOL><INDENT>body = issues_body<EOL><DEDENT>elif (updated_on == '<STR_LIT>' and offset == '<STR_LIT:3>'):<EOL><INDENT>body = issues_next_body<EOL><DEDENT>elif (updated_on == '<STR_LIT>' and offset == '<STR_LIT:0>'):<EOL><INDENT>body = issues_next_body<EOL><DEDENT>elif (updated_on == '<STR_LIT>' and offset == '<STR_LIT:0>'):<EOL><INDENT>body = issues_next_body<EOL><DEDENT>else:<EOL><INDENT>body = issues_empty_body<EOL><DEDENT><DEDENT>elif uri.startswith(REDMINE_ISSUE_2_URL):<EOL><INDENT>body = issue_2_body<EOL><DEDENT>elif uri.startswith(REDMINE_ISSUE_5_URL):<EOL><INDENT>body = issue_5_body<EOL><DEDENT>elif uri.startswith(REDMINE_ISSUE_9_URL):<EOL><INDENT>body = issue_9_body<EOL><DEDENT>elif uri.startswith(REDMINE_ISSUE_7311_URL):<EOL><INDENT>if failures > <NUM_LIT:0>:<EOL><INDENT>status = <NUM_LIT><EOL>body = "<STR_LIT>"<EOL>failures -= <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>body = issue_7311_body<EOL><DEDENT><DEDENT>elif uri.startswith(REDMINE_USER_3_URL):<EOL><INDENT>body = user_3_body<EOL><DEDENT>elif uri.startswith(REDMINE_USER_4_URL):<EOL><INDENT>body = user_4_body<EOL><DEDENT>elif uri.startswith(REDMINE_USER_24_URL):<EOL><INDENT>body = user_24_body<EOL><DEDENT>elif uri.startswith(REDMINE_USER_25_URL):<EOL><INDENT>body = user_25_body<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT>http_requests.append(last_request)<EOL>return (status, headers, body)<EOL><DEDENT>for url in REDMINE_URL_LIST:<EOL><INDENT>httpretty.register_uri(httpretty.GET,<EOL>url,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL><DEDENT>return http_requests<EOL>


job_args = {}<EOL>job_args['<STR_LIT>'] = Q_STORAGE_ITEMS<EOL>job_args['<STR_LIT>'] = task.task_id<EOL>job_args['<STR_LIT>'] = task.backend<EOL>backend_args = copy.deepcopy(task.backend_args)<EOL>if '<STR_LIT>' in backend_args:<EOL><INDENT>backend_args['<STR_LIT>'] = backend_args.pop('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in backend_args:<EOL><INDENT>backend_args['<STR_LIT>'] = backend_args.pop('<STR_LIT>')<EOL><DEDENT>job_args['<STR_LIT>'] = backend_args<EOL>job_args['<STR_LIT>'] = task.category<EOL>archiving_cfg = task.archiving_cfg<EOL>job_args['<STR_LIT>'] = archiving_cfg.to_dict() if archiving_cfg else None<EOL>sched_cfg = task.scheduling_cfg<EOL>job_args['<STR_LIT>'] = sched_cfg.max_retries if sched_cfg else MAX_JOB_RETRIES<EOL>return job_args<EOL>

Build the set of arguments required for running a job


try:<EOL><INDENT>self.listen()<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.critical("<STR_LIT>", str(e))<EOL>logger.critical(traceback.format_exc())<EOL><DEDENT>

Run thread to listen for jobs and reschedule successful ones.


self.registry.remove(task_id)<EOL>self._scheduler.cancel_job_task(task_id)<EOL>logger.info("<STR_LIT>", task_id)<EOL>

Cancel or 'un-schedule' a task.

        :param task_id: identifier of the task to cancel

        :raises NotFoundError: raised when the requested task is not
            found in the registry


pubsub = self.conn.pubsub()<EOL>pubsub.subscribe(self.pubsub_channel)<EOL>logger.debug("<STR_LIT>", self.pubsub_channel)<EOL>for msg in pubsub.listen():<EOL><INDENT>logger.debug("<STR_LIT>", str(msg['<STR_LIT:type>']))<EOL>if msg['<STR_LIT:type>'] != '<STR_LIT:message>':<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>continue<EOL><DEDENT>data = pickle.loads(msg['<STR_LIT:data>'])<EOL>job_id = data['<STR_LIT>']<EOL>job = rq.job.Job.fetch(job_id, connection=self.conn)<EOL>if data['<STR_LIT:status>'] == '<STR_LIT>':<EOL><INDENT>logging.debug("<STR_LIT>", job_id)<EOL>handler = self.result_handler<EOL><DEDENT>elif data['<STR_LIT:status>'] == '<STR_LIT>':<EOL><INDENT>logging.debug("<STR_LIT>", job_id)<EOL>handler = self.result_handler_err<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>if handler:<EOL><INDENT>logging.debug("<STR_LIT>", job_id)<EOL>handler(job)<EOL><DEDENT><DEDENT>

Listen for completed jobs and reschedule successful ones.


if archive_path == "<STR_LIT>":<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if archive_path:<EOL><INDENT>self.archive_manager = perceval.archive.ArchiveManager(archive_path)<EOL><DEDENT>

Initialize the archive manager.

        :param archive_path: path where the archive manager is located


payload = cherrypy.request.json<EOL>logger.debug("<STR_LIT>")<EOL>task_ids = {}<EOL>for task_data in payload['<STR_LIT>']:<EOL><INDENT>task_id = task_data['<STR_LIT>']<EOL>removed = super().remove_task(task_id)<EOL>task_ids[task_id] = removed<EOL><DEDENT>result = {'<STR_LIT>': task_ids}<EOL>return result<EOL>


payload = cherrypy.request.json<EOL>logger.debug("<STR_LIT>")<EOL>for task_data in payload['<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>category = task_data['<STR_LIT>']<EOL>backend_args = task_data['<STR_LIT>']<EOL>archive_args = task_data.get('<STR_LIT>', None)<EOL>sched_args = task_data.get('<STR_LIT>', None)<EOL><DEDENT>except KeyError as ex:<EOL><INDENT>logger.error("<STR_LIT>")<EOL>raise ex<EOL><DEDENT>from_date = backend_args.get('<STR_LIT>', None)<EOL>if from_date:<EOL><INDENT>backend_args['<STR_LIT>'] = str_to_datetime(from_date)<EOL><DEDENT>super().add_task(task_data['<STR_LIT>'],<EOL>task_data['<STR_LIT>'],<EOL>category,<EOL>backend_args,<EOL>archive_args=archive_args,<EOL>sched_args=sched_args)<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>return "<STR_LIT>"<EOL>


Remove a task from the registry.

        To remove it, pass its identifier with `taks_id` parameter.
        When the identifier is not found, a `NotFoundError` exception
        is raised.

        :param task_id: identifier of the task to remove

        :raises NotFoundError: raised when the given task identifier
            is not found on the registry


if not sched_args:<EOL><INDENT>return None<EOL><DEDENT>return SchedulingTaskConfig.from_dict(sched_args)<EOL>


self._order_mutex.acquire()<EOL>self._access_mutex.acquire()<EOL>self._order_mutex.release()<EOL>


def __init__(self, api_key, endpoint, domain, start_month, end_month,<EOL>time_granularity="<STR_LIT>", main_domain_only=False):

if endpoint not in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise InvalidEndpointException("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self.endpoint = endpoint<EOL>self.domain = utils.domain_from_url(domain)<EOL>self.start_month = start_month<EOL>self.end_month = end_month<EOL>self.time_granularity = time_granularity<EOL>self.main_domain_only = main_domain_only<EOL>super(EngagementAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

endpoint: string
    Endpoint to use. Can be: pageviews, visitduration, bouncerate

domain: string
    Domain to query.

start_month: string
    Start Month in (M-YYYY) format

end_month: string
    End Month in (M-YYYY) format

time_granularity: string
    Time granularity of report. Can be: Daily, Weekly, Monthly

main_domain_only: boolean
    Get metrics on the Main Domain only (i.e. not including subdomains)


def __init__(self, api_key, domain, start_month, end_month,<EOL>main_domain_only=False, results_page=None):

self.domain = utils.domain_from_url(domain)<EOL>self.start_month = start_month<EOL>self.end_month = end_month<EOL>self.main_domain_only = main_domain_only<EOL>self.results_page = results_page<EOL>super(ReferralsAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

domain: string
    Domain to query.

start_month: string
    Start Month in (M-YYYY) format

end_month: string
    End Month in (M-YYYY) format

main_domain_only: boolean
    Get metrics on the Main Domain only (i.e. not including subdomains)

results_page: integer
    Enter for more than 10 results


def __init__(self, api_key, domain, start_month, end_month,<EOL>time_granularity="<STR_LIT>", main_domain_only=False):

self.domain = utils.domain_from_url(domain)<EOL>self.start_month = start_month<EOL>self.end_month = end_month<EOL>self.time_granularity = time_granularity<EOL>self.main_domain_only = main_domain_only<EOL>super(TrafficAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

domain: string
    Domain to query.

start_month: string
    Start Month in (M-YYYY) format

end_month: string
    End Month in (M-YYYY) format

time_granularity: string
    Time granularity of report. Can be: Daily, Weekly, Monthly

main_domain_only: boolean
    Get metrics on the Main Domain only (i.e. not including subdomains)


def __init__(self, api_key, category=None, country=None):

self.category = category<EOL>self.country = country<EOL>super(TopSitesAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

category: string
    If left blank, `All Categories` will be requested.
    Use `http://api.similarweb.com/v1/TopSites/categories` to get a list of available categories.

country: string
    If left blank, `Worldwide` will be requested.
    Use `http://api.similarweb.com/v1/TopSites/countries` to get a list of available categories.


def __init__(self, api_key, endpoint, domain, start_month, end_month,<EOL>main_domain_only=False, results_page=None):

if endpoint not in ["<STR_LIT>", "<STR_LIT>", ]:<EOL><INDENT>raise InvalidEndpointException("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self.domain = utils.domain_from_url(domain)<EOL>self.endpoint = endpoint<EOL>self.start_month = start_month<EOL>self.end_month = end_month<EOL>self.main_domain_only = main_domain_only<EOL>self.results_page = results_page<EOL>super(SearchKeywordsAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

endpoint: string
    Endpoint to use. Can be: orgsearch, paidsearch

domain: string
    Domain to query.

start_month: string
    Start Month in (M-YYYY) format

end_month: string
    End Month in (M-YYYY) format

main_domain_only: boolean
    Get metrics on the Main Domain only (i.e. not including subdomains)

results_page: integer
    Enter for more than 10 results


self.domain = utils.domain_from_url(domain)<EOL>super(DestinationsAPI, self).__init__(api_key)<EOL>

Parameters
----------
api_key: string
    SimilarWeb API key

domain: string
    Domain to query.


self.domain = utils.domain_from_url(domain)<EOL>super(AlsoVisitedAPI, self).__init__(api_key)<EOL>


self.domain = utils.domain_from_url(domain)<EOL>super(WebsiteTagsAPI, self).__init__(api_key)<EOL>


ext = tldextract.extract(url)<EOL>if not ext.suffix:<EOL><INDENT>raise InvalidURLException()<EOL><DEDENT>new_url = ext.domain + "<STR_LIT:.>" + ext.suffix<EOL>return new_url<EOL>

Get root domain from url.
Will prune away query strings, url paths, protocol prefix and sub-domains
Exceptions will be raised on invalid urls


<EOL>return CarddavObject.from_user_input(<EOL>address_book=mock.Mock(path='<STR_LIT>'), user_input=yaml,<EOL>supported_private_objects=[], version='<STR_LIT>',<EOL>localize_dates=False)<EOL>

Parse some yaml string into a CarddavObject

        :param yaml: the yaml input string to parse
        :type yaml: str
        :returns: the parsed CarddavObject
        :rtype: CarddavObject


def phone_subcommand(search_terms, vcard_list, parsable):

all_phone_numbers_list = []<EOL>matching_phone_number_list = []<EOL>for vcard in vcard_list:<EOL><INDENT>for type, number_list in sorted(vcard.get_phone_numbers().items(),<EOL>key=lambda k: k[<NUM_LIT:0>].lower()):<EOL><INDENT>for number in sorted(number_list):<EOL><INDENT>if config.display_by_name() == "<STR_LIT>":<EOL><INDENT>name = vcard.get_first_name_last_name()<EOL><DEDENT>else:<EOL><INDENT>name = vcard.get_last_name_first_name()<EOL><DEDENT>line_formatted = "<STR_LIT:\t>".join([name, type, number])<EOL>line_parsable = "<STR_LIT:\t>".join([number, name, type])<EOL>if parsable:<EOL><INDENT>phone_number_line = line_parsable<EOL><DEDENT>else:<EOL><INDENT>phone_number_line = line_formatted<EOL><DEDENT>if re.search(search_terms,<EOL>"<STR_LIT>" % (line_formatted, line_parsable),<EOL>re.IGNORECASE | re.DOTALL):<EOL><INDENT>matching_phone_number_list.append(phone_number_line)<EOL><DEDENT>elif len(re.sub("<STR_LIT>", "<STR_LIT>", search_terms)) >= <NUM_LIT:3>:<EOL><INDENT>if re.search(re.sub("<STR_LIT>", "<STR_LIT>", search_terms),<EOL>re.sub("<STR_LIT>", "<STR_LIT>", number), re.IGNORECASE):<EOL><INDENT>matching_phone_number_list.append(phone_number_line)<EOL><DEDENT><DEDENT>all_phone_numbers_list.append(phone_number_line)<EOL><DEDENT><DEDENT><DEDENT>if matching_phone_number_list:<EOL><INDENT>if parsable:<EOL><INDENT>print('<STR_LIT:\n>'.join(matching_phone_number_list))<EOL><DEDENT>else:<EOL><INDENT>list_phone_numbers(matching_phone_number_list)<EOL><DEDENT><DEDENT>elif all_phone_numbers_list:<EOL><INDENT>if parsable:<EOL><INDENT>print('<STR_LIT:\n>'.join(all_phone_numbers_list))<EOL><DEDENT>else:<EOL><INDENT>list_phone_numbers(all_phone_numbers_list)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not parsable:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Print a phone application friendly contact table.

    :param search_terms: used as search term to filter the contacts before
        printing
    :type search_terms: str
    :param vcard_list: the vcards to search for matching entries which should
        be printed
    :type vcard_list: list of carddav_object.CarddavObject
    :param parsable: machine readable output: columns devided by tabulator (\t)
    :type parsable: bool
    :returns: None
    :rtype: None