コード例 #1
0
ファイル: utils.py プロジェクト: bugrevelio/tunacell
def iter_timeseries_(exp, observable, conditions, size=None):
    """Iterator over :class:`TimeSeries` instances from lineages in exp.

    TimeSeries are generated by browing Lineages instances from exp,
    retrieving observable values as defined un Observable, under different
    conditions defined in Conditions

    Parameters
    ----------
    exp : :class:`Experiment` instance
    observable : :class:`Observable` or :class:`FunctionalObservable` instance
    conditions : list of :class:`FilterSet` instances

    size : int (default None)
        when not None, limit the iterator to size items.

    Yields
    ------
    :class:`TimeSeries` instance
    """
    all_filters = [exp.fset, ] + conditions
    raw_obs, func_obs = set_observable_list(observable, filters=all_filters)
    # run the iterator
    if exp._counts is None:
        exp.count_items()
    n_lineages = exp._counts['lineages']
    for lineage in tqdm(exp.iter_lineages(size=size), total=n_lineages, desc='sample iteration'):
        ts = lineage.get_timeseries(observable,
                                    raw_obs=raw_obs, func_obs=func_obs,
                                    cset=conditions)
        yield ts
コード例 #2
0
ファイル: utils.py プロジェクト: bugrevelio/tunacell
def iter_timeseries_2(exp, obs1, obs2, conditions, size=None):
    """Iterator over couples :class:`TimeSeries` instances

    :class:`TimeSeries` are generated by browing :class:`Lineage` instances
    from exp, retrieving observable values as defined in obs1 and obs2,
    under different conditions.

    Parameters
    ----------
    exp : :class:`Experiment` instance
    obs1 : :class:`Observable` instance
    obs2 : :class:`Observable` instance
    conditions : list of :class:`FilterSet` instances
    size : int (default None)
        when not None, limit the iterator to size items.

    Yields
    ------
    Couple of :class:`TimeSeries` instances
    """
    all_filters = [exp.fset, ] + conditions
    raw_obs, func_obs = set_observable_list(obs1, obs2, filters=all_filters)
    if exp._counts is None:
        exp.count_items()
    n_lineages = exp._counts['lineages']
    for lineage in tqdm(exp.iter_lineages(size=size), total=n_lineages, desc='sample iteration'):
        ts1 = lineage.get_timeseries(obs1,
                                     raw_obs=raw_obs, func_obs=func_obs,
                                     cset=conditions)
        ts2 = lineage.get_timeseries(obs2,
                                     raw_obs=raw_obs, func_obs=func_obs,
                                     cset=conditions)
        yield (ts1, ts2)
コード例 #3
0
ファイル: samples.py プロジェクト: bugrevelio/tunacell
    def make_plot(self, obs, **kwargs):
        """Produce Figure and save plotted data.

        Parameters
        ----------
        obs : :class:`Observable` isntance
            observable to plot
        kwargs : keyword arguments
            check :fun:`plot_samples` doctring for valid keyword arguments
        """
        self.obs = obs
        raw_obs, func_obs = set_observable_list(obs, filters=self._all_filters)
        raw_obs = raw_obs
        func_obs = func_obs
        samples = []
        for lin in _unroll_samples(self._input_samples):
            ts = lin.get_timeseries(obs, raw_obs, func_obs, self.cset)
            samples.append((lin, ts))
        self._samples = samples
        fig = plot_samples(samples, obs,
                           conditions=self.cset,
                           parser=self.parser,
                           **kwargs)
        self.fig = fig
        return
コード例 #4
0
    def make_plot(self, obs, **kwargs):
        """Produce Figure and save plotted data.

        Parameters
        ----------
        obs : :class:`Observable` isntance
            observable to plot
        kwargs : keyword arguments
            check :fun:`plot_samples` doctring for valid keyword arguments
        """
        self.obs = obs
        raw_obs, func_obs = set_observable_list(obs, filters=self._all_filters)
        raw_obs = raw_obs
        func_obs = func_obs
        samples = []
        for lin in _unroll_samples(self._input_samples):
            ts = lin.get_timeseries(obs, raw_obs, func_obs, self.cset)
            samples.append((lin, ts))
        self._samples = samples
        fig = plot_samples(samples,
                           obs,
                           conditions=self.cset,
                           parser=self.parser,
                           **kwargs)
        self.fig = fig
        return
コード例 #5
0
ファイル: utils.py プロジェクト: LeBarbouze/tunacell
def iter_timeseries_2(exp, obs1, obs2, conditions, size=None):
    """Iterator over couples :class:`TimeSeries` instances

    :class:`TimeSeries` are generated by browing :class:`Lineage` instances
    from exp, retrieving observable values as defined in obs1 and obs2,
    under different conditions.

    Parameters
    ----------
    exp : :class:`Experiment` instance
    obs1 : :class:`Observable` instance
    obs2 : :class:`Observable` instance
    conditions : list of :class:`FilterSet` instances
    size : int (default None)
        when not None, limit the iterator to size items.

    Yields
    ------
    Couple of :class:`TimeSeries` instances
    """
    all_filters = [exp.fset, ] + conditions
    raw_obs, func_obs = set_observable_list(obs1, obs2, filters=all_filters)
    if exp._counts is None:
        exp.count_items()
    n_lineages = exp._counts['lineages']
    for lineage in tqdm(exp.iter_lineages(size=size), total=n_lineages, desc='sample iteration'):
        ts1 = lineage.get_timeseries(obs1,
                                     raw_obs=raw_obs, func_obs=func_obs,
                                     cset=conditions)
        ts2 = lineage.get_timeseries(obs2,
                                     raw_obs=raw_obs, func_obs=func_obs,
                                     cset=conditions)
        yield (ts1, ts2)
コード例 #6
0
ファイル: utils.py プロジェクト: LeBarbouze/tunacell
def iter_timeseries_(exp, observable, conditions, size=None):
    """Iterator over :class:`TimeSeries` instances from lineages in exp.

    TimeSeries are generated by browing Lineages instances from exp,
    retrieving observable values as defined un Observable, under different
    conditions defined in Conditions

    Parameters
    ----------
    exp : :class:`Experiment` instance
    observable : :class:`Observable` or :class:`FunctionalObservable` instance
    conditions : list of :class:`FilterSet` instances

    size : int (default None)
        when not None, limit the iterator to size items.

    Yields
    ------
    :class:`TimeSeries` instance
    """
    all_filters = [exp.fset, ] + conditions
    raw_obs, func_obs = set_observable_list(observable, filters=all_filters)
    # run the iterator
    if exp._counts is None:
        exp.count_items()
    n_lineages = exp._counts['lineages']
    for lineage in tqdm(exp.iter_lineages(size=size), total=n_lineages, desc='sample iteration'):
        ts = lineage.get_timeseries(observable,
                                    raw_obs=raw_obs, func_obs=func_obs,
                                    cset=conditions)
        yield ts
コード例 #7
0
def test_unrolling():
    length = Observable(name='length')
    width = Observable(name='width')
    area = FunctionalObservable(name='square-area', f=lambda x, y: x*y, observables=[length, width])
    vol = FunctionalObservable(name='volume', f=lambda x, y: x*y, observables=[area, width])
    raw_obs, func_obs = set_observable_list(vol, filters=[])
    assert length in raw_obs
    assert length not in func_obs
    assert width in raw_obs
    assert width not in func_obs
    assert area in func_obs
    assert area not in raw_obs
    assert vol in func_obs
    assert vol not in raw_obs
コード例 #8
0
def test_unrolling():
    length = Observable(name='length')
    width = Observable(name='width')
    area = FunctionalObservable(name='square-area',
                                f=lambda x, y: x * y,
                                observables=[length, width])
    vol = FunctionalObservable(name='volume',
                               f=lambda x, y: x * y,
                               observables=[area, width])
    raw_obs, func_obs = set_observable_list(vol, filters=[])
    assert length in raw_obs
    assert length not in func_obs
    assert width in raw_obs
    assert width not in func_obs
    assert area in func_obs
    assert area not in raw_obs
    assert vol in func_obs
    assert vol not in raw_obs
コード例 #9
0
    def prefilter(self, filt=None, verbose=False):
        """Filter at the cell level.

        Parameters
        ----------
        filt : Filter instance
           has to accept Cell instance as argument
           has to be callable
           returns True when cell is acccepted, False when not

        Notes
        -----
        This method acts of self.cells: it removes cells, and updates
        properties of parent/daughters cells when appropriate.

        Apply .prefilter only BEFORE building trees.

        See also
        --------
        The .postfilter method that filters cells at the tree level: when trees
        have been built after reading from file, they can be reconstructed
        upon filtering with this other method.
        """
        erased = []
        if verbose:
            msg = 'Prior to filter, we have {} cells.'.format(len(self.cells))
            print(msg)
        # check for supplementary observables to be computed
        raw_obs, func_obs = set_observable_list(filters=[
            filt,
        ])

        # compute suppl obs for all cells
        if raw_obs:
            for cell in self.cells:
                for obs in raw_obs:
                    cell.build(obs)
        for cell in self.cells:
            if filt is not None:
                if not filt(cell):
                    erased.append(cell)
                    # make Colony.add_cell_recursive non functional
                    cell.bpointer = None
                    if cell.parent:
                        cell.parent.childs.remove(cell)
                    # make daughter cells new roots
                    for ch in cell.childs:
                        ch.bpointer = None
        if verbose:
            msg = '{} cells do not pass filter.'.format(len(erased))
            print(msg)
        for cell in erased:
            self.cells.remove(cell)  # otherwise would be considered root
        # clean-up actions for computing extra obs
        # extra obs computation depends on tree decomposition
        # this will be done in lineage.get_timeseries()
        for cell in self.cells:
            for obs in raw_obs:
                del cell._sdata[obs.label]
        if verbose:
            msg = 'After filtering, we get {} cells.'.format(len(self.cells))
            print(msg)
#        self.metadata.filters.append(repr(boofunc))
        return
コード例 #10
0
ファイル: container.py プロジェクト: bugrevelio/tunacell
    def prefilter(self, filt=None, verbose=False):
        """Filter at the cell level.

        Parameters
        ----------
        filt : Filter instance
           has to accept Cell instance as argument
           has to be callable
           returns True when cell is acccepted, False when not

        Notes
        -----
        This method acts of self.cells: it removes cells, and updates
        properties of parent/daughters cells when appropriate.

        Apply .prefilter only BEFORE building trees.

        See also
        --------
        The .postfilter method that filters cells at the tree level: when trees
        have been built after reading from file, they can be reconstructed
        upon filtering with this other method.
        """
        erased = []
        if verbose:
            msg = 'Prior to filter, we have {} cells.'.format(len(self.cells))
            print(msg)
        # check for supplementary observables to be computed
        raw_obs, func_obs = set_observable_list(filters=[filt, ])

        # compute suppl obs for all cells
        if raw_obs:
            for cell in self.cells:
                for obs in raw_obs:
                    cell.build(obs)
        for cell in self.cells:
            if filt is not None:
                if not filt(cell):
                    erased.append(cell)
                    # make Colony.add_cell_recursive non functional
                    cell.bpointer = None
                    if cell.parent:
                        cell.parent.childs.remove(cell)
                    # make daughter cells new roots
                    for ch in cell.childs:
                        ch.bpointer = None
        if verbose:
            msg = '{} cells do not pass filter.'.format(len(erased))
            print(msg)
        for cell in erased:
            self.cells.remove(cell)  # otherwise would be considered root
        # clean-up actions for computing extra obs
        # extra obs computation depends on tree decomposition
        # this will be done in lineage.get_timeseries()
        for cell in self.cells:
            for obs in raw_obs:
                del cell._sdata[obs.label]
        if verbose:
            msg = 'After filtering, we get {} cells.'.format(len(self.cells))
            print(msg)
#        self.metadata.filters.append(repr(boofunc))
        return