Exemplo n.º 1
0
def test_garbage_collection():
    """Test that recipe execution discards intermediate results that are no longer necessary."""
    recipe_str = """
a = compute(Filter.SimpleFilterAlgorithm, file_inputs[0], multiplicand=0.5)
b = compute(Filter.SimpleFilterAlgorithm, a, multiplicand=0.3)
c = compute(Filter.SimpleFilterAlgorithm, b, multiplicand=4.)
d = compute(Filter.SimpleFilterAlgorithm, c, multiplicand=0.5)
file_outputs[0] = compute(Filter.SimpleFilterAlgorithm, d, multiplicand=0.5)
    """

    with tempfile.TemporaryDirectory() as tempdir:
        output_path = os.path.join(tempdir, "output.json")
        recipe = Recipe(recipe_str, [URL], [output_path])

        execution = recipe._execution()
        execution._run_one_tick()
        execution._run_one_tick()

        assert len(execution._completed_results) == 1

        execution.run_and_save()

        result_stack = ImageStack.from_path_or_url(output_path)
        assert np.allclose(BASE_EXPECTED * .15,
                           result_stack.xarray[2, 2, 0, 40:50, 40:50])
Exemplo n.º 2
0
def test_simple_recipe():
    """Test that a simple recipe can execute correctly."""
    recipe_str = """
file_outputs[0] = compute(Filter.SimpleFilterAlgorithm, file_inputs[0], multiplicand=0.5)
    """

    with tempfile.TemporaryDirectory() as tempdir:
        output_path = os.path.join(tempdir, "output.json")
        recipe = Recipe(recipe_str, [URL], [output_path])

        execution = recipe._execution()
        execution.run_and_save()

        result_stack = ImageStack.from_path_or_url(output_path)
        assert np.allclose(BASE_EXPECTED * .5,
                           result_stack.xarray[2, 2, 0, 40:50, 40:50])
Exemplo n.º 3
0
def test_recipe_constructor_extra_args():
    """Test that recipe construction detects missing arguments to the constructor."""
    recipe_str = """
file_outputs[0] = compute(Filter.SimpleFilterAlgorithm, file_inputs[0], multiplicand=.5, x=1)
"""

    with tempfile.TemporaryDirectory() as tempdir:
        output_path = os.path.join(tempdir, "output.json")
        with warnings.catch_warnings(record=True) as w:
            recipe = Recipe(recipe_str, [URL], [output_path])

            assert len(w) == 1
            assert issubclass(w[-1].category, ConstructorExtraParameterWarning)

        execution = recipe._execution()
        execution.run_and_save()

        result_stack = ImageStack.from_path_or_url(output_path)
        assert np.allclose(BASE_EXPECTED * .5,
                           result_stack.xarray[2, 2, 0, 40:50, 40:50])
Exemplo n.º 4
0
def test_chained_recipe():
    """Test that a recipe with a complex graph can execute correctly."""
    recipe_str = """
a = compute(Filter.SimpleFilterAlgorithm, file_inputs[0], multiplicand=0.5)
b = compute(Filter.SimpleFilterAlgorithm, a, multiplicand=.3)
file_outputs[0] = compute(Filter.SimpleFilterAlgorithm, b, multiplicand=0.2)
c = compute(Filter.SimpleFilterAlgorithm, a, multiplicand=.2)
file_outputs[1] = compute(Filter.SimpleFilterAlgorithm, c, multiplicand=.3)
    """

    with tempfile.TemporaryDirectory() as tempdir:
        output_0_path = os.path.join(tempdir, "output_0.json")
        output_1_path = os.path.join(tempdir, "output_1.json")
        recipe = Recipe(recipe_str, [URL], [output_0_path, output_1_path])

        execution = recipe._execution()
        execution.run_and_save()

        for path in (output_0_path, output_1_path):
            result_stack = ImageStack.from_path_or_url(path)
            assert np.allclose(BASE_EXPECTED * .03,
                               result_stack.xarray[2, 2, 0, 40:50, 40:50])
Exemplo n.º 5
0
 def _cli(ctx, imagestack):
     ctx.obj["component"]._cli_run(
         ctx,
         FilterAlgorithmWithMissingConstructorTyping(
             additive=ImageStack.from_path_or_url(imagestack)))
Exemplo n.º 6
0
 def _cli(ctx, imagestack):
     ctx.obj["component"]._cli_run(
         ctx,
         AdditiveFilterAlgorithm(additive=ImageStack.from_path_or_url(imagestack)))