def display_images():
    """
    This function obtains results from generators and plot image and image intensity
    """
    vc = setup_camera_and_plot()
    ims = stream_frames(vc)  # Get the generator

    fig, ax = plt.subplots(1, 2, figsize=(10, 5))
    im = setup_plotting(imagestream=ims, imageaxis=ax[0], traceaxis=ax[1])

    x_width = 50
    starttime = time.time()  # Time this

    try:
        pipeline = tz.pipe(ims,
                           c.map(lambda x: cv2.cvtColor(x, cv2.COLOR_BGR2RGB)),
                           c.map(c.do(im.set_array)),
                           c.map(lambda x: np.mean(x)),
                           c.sliding_window(x_width))

        for n, i in enumerate(pipeline):
            xdata = np.linspace(n, n + x_width, x_width)
            plot_intensity(axis=ax[1], xdata=xdata, imageintensity=i)
            plt.show(block=False)
            plt.pause(0.001)

    except KeyboardInterrupt:
        elapsedtime = time.time() - starttime
        print('The collection FPS was {:0.2f}'.format(n / elapsedtime))
        vc.release()
Example #2
0
    def __init__(
        self,
        frame: pd.DataFrame,
        window: int = 10,
        window_two: int = 3,
        is_fold: bool = False,
        x_label: List[str] = ["state"],
        y_label: List[str] = ["reward"]
    ):
        self.n = 0
        self.is_fold = is_fold
        local_frame = frame.copy()
        np_conv = lambda x: x.to_numpy()
        swindows = sliding_window(window)

        func = lambda x: pipe(x, np_conv, swindows)
        stay = stack_array(window_two)
        _slice_target = slice_target(window, window_two)
        self.x_axis = pipe(
            local_frame[x_label], np_conv, map(compress_row), swindows,
            map(compose(concat_tuple)), map(stay)
        )
        self.y_axis = pipe(
            frame[y_label], func, map(lambda x: torch.tensor(x).view(-1)),
            map(log_el), map(_slice_target)
        )

        self.count = toolz.count(self.copy()[0])

        self.zip_list = None
Example #3
0
    def _word_skip_grams(self, tokens, stop_words=None):
        # handle stop words
        if stop_words is not None:
            tokens = [w for w in tokens if w not in stop_words]

        return compose(cmap(' '.join), pluck([0, 2]),
                       sliding_window(3))(tokens)
Example #4
0
    def inner(avg_window_size, df_source_seq):
        """
        Arguments:
        - avg_window_size: Number of periods (of target resolution) to average over
        """
        def to_sample(ohlc_data):
            if any(
                    map(
                        lambda p: len(p) == 0 or p is None or np.isnan(p).any(
                        ), ohlc_data)):
                return None

            v200davg = np.average(
                [np.average(t[:, 3], axis=0) for t in ohlc_data],
                axis=0)  # Average the close

            # Pick out high rew: (left, middle, right) OHLC, and build the low res ohlc (low_res_ohlc)
            left, middle, right = [k[:5] / v200davg for k in ohlc_data[-3:]]

            x = list(map(analysis.ohlc_collapse, [left, middle, right]))
            y = [x[0], middle, x[2]]

            return v200davg, x, y

        return tz.pipe(tz.sliding_window(avg_window_size, df_source_seq),
                       tz.map(to_sample))
Example #5
0
def split_at_breaks(array, breaks, axis=0):
    """ Split an array into a list of arrays (using slices) at the given breaks

    >>> split_at_breaks(np.arange(6), [3, 5])
    [array([0, 1, 2]), array([3, 4]), array([5])]
    """
    padded_breaks = concat([[None], breaks, [None]])
    slices = [slice(i, j) for i, j in sliding_window(2, padded_breaks)]
    preslice = (slice(None),) * axis
    split_array = [array[preslice + (s,)] for s in slices]
    return split_array
Example #6
0
def split_at_breaks(array, breaks, axis=0):
    """ Split an array into a list of arrays (using slices) at the given breaks

    >>> split_at_breaks(np.arange(6), [3, 5])
    [array([0, 1, 2]), array([3, 4]), array([5])]
    """
    padded_breaks = concat([[None], breaks, [None]])
    slices = [slice(i, j) for i, j in sliding_window(2, padded_breaks)]
    preslice = (slice(None), ) * axis
    split_array = [array[preslice + (s, )] for s in slices]
    return split_array
Example #7
0
def markov(seq):
    '''
    @Description: 
        get a 1st-order Markov model from a sequence of nucleotides
    '''
    model = np.zeros((8, 8))
    tz.last(
        tz.pipe(seq, c.sliding_window(2), c.map(PDICT.__getitem__),
                c.map(increment_model(model))))
    # 将计数矩阵转为概率矩阵
    model /= np.sum(model, axis=1)[:, np.newaxis]
    return model
def markov(seq):
    """Get a 1st-order Markov model from a sequence of nucleotides."""
    model = np.zeros((4, 4))
    tz.last(
        tz.pipe(
            seq,
            cur.sliding_window(2),
            # each successive tuple
            cur.map(PDICT.__getitem__),
            # location in matrix of tuple
            cur.map(increment_model(model))))  # increment matrix
    # convert counts to transition probability matrix
    model /= np.sum(model, axis=1)[:, np.newaxis]
    return model
Example #9
0
def get_history(name):
    booking_logs = frappe.get_all(
        "Booking Log",
        filters={"booking_order": name},
        fields=[
            "'Booking Log' as doctype",
            "posting_datetime",
            "booking_order",
            "shipping_order",
            "station",
            "activity",
            "loading_operation",
            "loading_unit",
            "sum(no_of_packages) as no_of_packages",
            "sum(weight_actual) as weight_actual",
        ],
        order_by="posting_datetime",
        group_by="posting_datetime,activity",
    )

    get_shipping_logs = compose(
        concat,
        map(lambda x: frappe.get_all(
            "Shipping Log",
            filters={
                "shipping_order":
                x[0].get("shipping_order"),
                "activity": ("in", ["Stopped", "Moving"]),
                "posting_datetime": (
                    "between",
                    [
                        x[0].get("posting_datetime"), x[1].get(
                            "posting_datetime")
                    ],
                ),
            },
            fields=[
                "'Shipping Log' as doctype",
                "posting_datetime",
                "shipping_order",
                "station",
                "activity",
            ],
            order_by="posting_datetime",
        ) if x[0].get("shipping_order") else []),
        sliding_window(2),
    )

    shipping_logs = get_shipping_logs(
        booking_logs + [{
            "posting_datetime": frappe.utils.now()
        }])

    def get_message(log):
        if log.get("doctype") == "Booking Log":
            if log.get("loading_unit") == "Weight":
                return "{} {} units by weight at {}".format(
                    log.get("activity"),
                    abs(log.get("weight_actual")),
                    log.get("station"),
                )
            return "{} {} packages at {}".format(
                log.get("activity"), abs(log.get("no_of_packages")),
                log.get("station"))

        if log.get("doctype") == "Shipping Log":
            prepo = "to" if log.get("activity") == "Moving" else "at"
            return "{} {} {}".format(log.get("activity"), prepo,
                                     log.get("station"))

        return ""

    def get_link(log):
        if log.get("doctype") == "Shipping Log":
            return "#Form/Shipping Order/{}".format(log.get("shipping_order"))

        if log.get("doctype") == "Booking Log" and log.get(
                "loading_operation"):
            return "#Form/Loading Operation/{}".format(
                log.get("loading_operation"))

        return ""

    def get_event(log):
        return {
            "datetime": log.get("posting_datetime"),
            "status": log.get("activity"),
            "message": get_message(log),
            "link": get_link(log),
        }

    return sorted(
        [get_event(x) for x in concat([booking_logs, shipping_logs])],
        key=lambda x: frappe.utils.get_datetime(x.get("datetime")),
    )
Example #10
0
                                        batch_size=batch_size)
    _ = list(tz.pipe(samples, curried.partition(batch_size),
                     curried.map(np.array),
                     curried.map(ipca.partial_fit)))
    return ipca
def array_from_txt(line):
    return np.array(line.rstrip().split(','), dtype=np.float)
with open('iris.csv') as fin:
    pca_obj = tz.pipe(fin, curried.map(array_from_txt), streaming_pca)
    
with open('iris.csv') as fin:
    components = np.squeeze(list(tz.pipe(fin,
                                         curried.map(array_from_txt),
                                  curried.map(pca_obj.transform))))
    
from matplotlib import pyplot as plt
plt.scatter(*components.T)
type(open('iris.csv').readlines())
import glob
counts = tz.pipe(glob.glob('sample.fasta'), curried.map(open),
                 tz.concat, curried.filter(lambda x: not x.startswith('>')),
                 curried.interpose('$'), tz.concat,
                 curried.sliding_window(6), curried.map(''.join),
                 curried.filter(lambda x: '$' not in x),
                 tz.frequencies)
for k in counts:
    print(k, counts[k])
    break
counts_list = list(counts.values())
plt.hist(counts_list, bins=25)
Example #11
0
def outer_edges_from_cycle(c: Cycle) -> Complex:
    return pipe(c, sliding_window(2), map(pset), pset)
Example #12
0
def edges_from_cycle(c: Cycle) -> Complex:
    return pipe(c, cycle, sliding_window(2), take(len(c)), map(pset), pset)
Example #13
0
def random_window(window_range, window):
    return sliding_window(random.randint(*window_range), window)
Example #14
0
def stack_array(size, x):
    if size <= 0: return stack_process(x)
    slide_size = sliding_window((size + 1))
    slide_stack = map(stack_process, slide_size(x))
    tuple_stack = tuple(slide_stack)
    return (torch.stack(tuple_stack, dim=1)).squeeze(0)