Ejemplo n.º 1
0
def pipeline():
    pipeline = Stream()

    b = pipeline.map(generate_data)
    b.sink(plot_data)

    c = b.map(fit_data)
    c.sink(plot_fit)
    return pipeline
Ejemplo n.º 2
0
def make_pipeline(_output_sinks=True):
    # link the pipeline up
    namespace = link(*(pipeline_order + [median_gen, std_gen, z_score_gen]),
                     **general_namespace)

    polarization_array = namespace["polarization_array"]
    mask = namespace["mask"]
    mean = namespace["mean"]
    q = namespace["q"]
    geometry = namespace["geometry"]
    dark_corrected_foreground = namespace["dark_corrected_foreground"]
    dark_corrected_background = namespace["dark_corrected_background"]
    mask_kwargs = namespace["mask_kwargs"]
    mask_setting = namespace["mask_setting"]

    median = namespace["median"]
    std = namespace["std"]
    z_score = namespace["z_score"]

    # Modify graph
    # create filename nodes
    filename_source = Stream(stream_name="filename")
    filename_node = filename_source.map(lambda x: os.path.splitext(x)[0])
    # write out mask
    mask.combine_latest(
        filename_node,
        emit_on=0).sink(lambda x: fit2d_save(np.flipud(x[0]), x[1]))
    mask.combine_latest(
        filename_node,
        emit_on=0).sink(lambda x: np.save(x[1] + "_mask.npy", x[0]))

    if _output_sinks:
        outs = [q, mean, median, std]
        out_tup = tuple([[] for _ in outs])
        out_sinks = tuple([k.sink(L.append) for k, L in zip(outs, out_tup)])

    (mean.zip(q).combine_latest(
        filename_node, emit_on=0).map(lambda l: (*l[0], l[1])).sink(
            lambda x: save_output(x[1], x[0], x[2], "Q")))
    (median.zip(q).combine_latest(
        filename_node, emit_on=0).map(lambda l: (*l[0], l[1])).sink(
            lambda x: save_output(x[1], x[0], x[2] + "_median", "Q")))
    (std.zip(q).combine_latest(
        filename_node, emit_on=0).map(lambda l: (*l[0], l[1])).sink(
            lambda x: save_output(x[1], x[0], x[2] + "_std", "Q")))
    (z_score.combine_latest(
        filename_node, emit_on=0).starsink(lambda img, n: tifffile.imsave(
            n + "_zscore.tif", data=img.astype(np.float32))))
    # If running from a terminal don't output stuff into lists (too much mem)
    return locals()
Ejemplo n.º 3
0
import pyFAI
import tifffile
from skbeam.io.fit2d import fit2d_save, read_fit2d_msk
from skbeam.io.save_powder_output import save_output
from streamz_ext import Stream
from xpdtools.pipelines.raw_pipeline import (polarization_array, mask, mean, q,
                                             geometry,
                                             dark_corrected_foreground,
                                             dark_corrected_background,
                                             z_score, std, median)

img_extensions = {'.tiff', '.edf', '.tif'}
# Modify graph
# create filename nodes
filename_source = Stream(stream_name='filename')
filename_node = (filename_source.map(lambda x: os.path.splitext(x)[0]))
# write out mask
mask.combine_latest(
    filename_node, emit_on=0).sink(lambda x: fit2d_save(np.flipud(x[0]), x[1]))
mask.combine_latest(
    filename_node, emit_on=0).sink(lambda x: np.save(x[1] + '_mask.npy', x[0]))

# write out chi
outs = [q, mean, median, std]
out_tup = tuple([[] for _ in outs])
out_sinks = tuple([k.sink(L.append) for k, L in zip(outs, out_tup)])

(mean.zip(q).combine_latest(filename_node,
                            emit_on=0).map(lambda l: (*l[0], l[1])).sink(
                                lambda x: save_output(x[1], x[0], x[2], 'Q')))
(median.zip(q).combine_latest(
Ejemplo n.º 4
0
                            overlay_mask, fq_getter, pdf_getter, sq_getter)

mask_setting = {'setting': 'auto'}
# Default kwargs
mask_kwargs = {}
fq_kwargs = dict(dataformat='QA', qmaxinst=28, qmax=25, rstep=np.pi / 25)
pdf_kwargs = dict(dataformat='QA', qmaxinst=28, qmax=22, rstep=np.pi / 22)

# Detector corrections
raw_foreground = Stream(stream_name='raw foreground')
raw_foreground_dark = Stream(stream_name='raw foreground dark')
raw_background = Stream(stream_name='raw background')
raw_background_dark = Stream(stream_name='raw background dark')

# Get the image shape for the binner
img_shape = raw_foreground.map(np.shape).unique(history=1)
dark_corrected_foreground = (raw_foreground.combine_latest(raw_foreground_dark,
                                                           emit_on=0).starmap(
                                                               op.sub))
dark_corrected_background = (raw_background.combine_latest(raw_background_dark,
                                                           emit_on=0).starmap(
                                                               op.sub))
bg_corrected_img = (dark_corrected_foreground.combine_latest(
    dark_corrected_background,
    emit_on=0).starmap(op.sub, stream_name='background corrected img'))

# Calibration management
wavelength = Stream(stream_name='wavelength')
calibrant = Stream(stream_name='calibrant')
detector = Stream(stream_name='detector')
is_calibration_img = Stream(stream_name='Is Calibration')
Ejemplo n.º 5
0
source = Stream()


def sleep_inc(x):
    if x == 9:
        raise RuntimeError()
    plt.pause(1)
    return x + 1


def print_sleep(x):
    plt.pause(.1)
    print(x)


b = source.map(sleep_inc)
b.sink(print_sleep)
c = b.map(sleep_inc)
c.sink(print_sleep)


gv = run_vis(
    source,
    source_node=True,
    edge_style={"color": "k"},
    node_label_style={"font_size": 15},
    edge_label_style=lambda x: {"label": x["label"], "font_size": 15},
    node_style=node_style,
    force_draw=True,
)
plt.pause(.1)
Ejemplo n.º 6
0
def test_destroy_pipeline():
    source = Stream()
    pipeline = source.map(op.add).zip(source).sink(print)
    destroy_pipeline(source)
    assert pipeline.upstreams == []
Ejemplo n.º 7
0
 def make_a():
     in_a = Stream()
     out_a = in_a.map(lambda x: x + 1)
     return locals()
Ejemplo n.º 8
0
 def make_a():
     source = Stream()
     out_a = source.map(lambda x: x + 1)
     return locals()
Ejemplo n.º 9
0
    gfit = GaussianFit(x, y)
    gfit.refine()
    plt.pause(1)
    return gfit


def plot_fit(gfit):
    ax2.cla()
    l2a = ax2.plot(gfit.x, gfit.y, 'b.', label="observed Gaussian")
    l2b = ax2.plot(gfit.x, gfit.yg, 'g-', label="calculated Gaussian")
    ax2.legend()
    fig.canvas.draw()
    plt.pause(0.1)


b = source.map(generate_data)
b.sink(plot_data)

c = b.map(fit_data)
c.sink(plot_fit)

gv = run_vis(
    source,
    source_node=True,
    edge_style={"color": "k"},
    node_label_style={"font_size": 15},
    edge_label_style=lambda x: {
        "label": x["label"],
        "font_size": 15
    },
    node_style=node_style,
Ejemplo n.º 10
0
 def make_b():
     out_a = Stream()
     out_b = out_a.map(lambda x: x * 2)
     return {"out_a": out_a, "out_b": out_b}
Ejemplo n.º 11
0
 def make_a():
     source = Stream()
     out_a = source.map(lambda x: x + 1)
     return {"in_a": source, "out_a": out_a}