예제 #1
0
def test_czi_parallel_processor(filename):
    mock_ssm().start()
    mock_s3().start()
    init_ssm()
    # init task
    for x in range(2):
        for y in range(2):
            for z in range(2):
                for c in range(2):
                    for t in range(2):
                        # Create sub_region file
                        open(
                            'sub_x_{}_2_y_{}_2_z_{}_2_c_{}_2_t_{}_2.txt'.
                            format(x, y, z, c, t), 'w').write("")
                        # Setup task with inputs
                        inputs = {
                            'file':
                            os.path.join('/test-resources', filename),
                            'sub_region_file':
                            'sub_x_{}_2_y_{}_2_z_{}_2_c_{}_2_t_{}_2.txt'.
                            format(x, y, z, c, t)
                        }
                        task = CZIProcessor(inputs=inputs)
                        setup_processor(task)
                        # run
                        task.run()
    mock_s3().stop()
    mock_ssm().stop()
예제 #2
0
def test_standard_image_processor(filename):
    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    # init task
    inputs = {'file': os.path.join('/test-resources', filename)}
    task = StandardImageProcessor(inputs=inputs)

    setup_processor(task)

    # run
    task.run()

    # Check outputs
    assert os.path.isfile('view_asset_info.json')
    json_dict = json.load(open('view_asset_info.json'))
    print json_dict

    if 'huge' in filename or 'tif' in filename.lower():
        assert os.path.isdir('view')
        assert os.path.isfile('view/slide.dzi')
        assert os.path.isfile('view/dimensions.json')
    elif filename.endswith('.jp2'):
        assert os.path.isfile('output.png')
    else:
        assert not os.path.isdir('view')
        assert not os.path.isfile('view/slide.dzi')
    assert os.path.isfile('metadata.json')
def test_sub_region_standard_image_processor(filename):
    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    # init task
    for a in range(1):
        for b in range(1):
            open('{}_{}.txt'.format(
                a,
                b,
            ), 'w').write("4,4")
            inputs = {
                'file': os.path.join('/test-resources', filename),
                'sub_region_file': '{}_{}.txt'.format(
                    a,
                    b,
                )
            }
            task = StandardImageProcessor(inputs=inputs)

            setup_processor(task)

            # run
            task.run()

            assert os.path.isdir('view')
            assert os.path.isfile('view/slide.dzi')
def test_ometiff_processor(filename):
    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    # init task
    inputs = {'file': os.path.join('/test-resources', filename)}
    task = OMETIFFProcessor(inputs=inputs)

    setup_processor(task)

    # run
    task.run()

    # Check outputs
    assert os.path.isfile('view_asset_info.json')
    json_dict = json.load(open('view_asset_info.json'))
    assert 'size' in json_dict.keys()
    assert 'fileType' in json_dict.keys()

    assert os.path.isdir('%s-zoomed' %
                         os.path.basename(task.outputs[0].file_path))
    assert os.path.isfile('%s-zoomed/dimensions.json' %
                          os.path.basename(task.outputs[0].file_path))
    assert os.path.isfile('metadata.json')

    # Check hack for backwards compatibility with viewer
    assert os.path.isfile('%s-zoomed/slide.dzi' %
                          os.path.basename(task.outputs[0].file_path))
    # assert os.path.isfile('%s-zoomed/slide.png' % os.path.basename(task.outputs[0].file_path))

    mock_s3().stop()
    mock_ssm().stop()
예제 #5
0
def test_czi_processor(filename):
    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    # init task
    inputs = {
        'file': os.path.join('/test-resources', filename),
        'optimize_view': "y"
    }
    task = CZIProcessor(inputs=inputs)

    setup_processor(task)

    # run
    task.run()

    # Check outputs
    first_slice_set = sorted(
        glob.glob('%s-zoomed/*.dzi' % os.path.basename(task.file)))[0]

    assert os.path.isfile('%s-zoomed/slide.dzi' % os.path.basename(task.file))
    assert os.path.isfile('metadata.json')

    mock_s3().stop()
    mock_ssm().stop()
def test_extract_structure_as_json(filename):
    inputs = {'file': os.path.join('/test-resources', filename)}

    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    task = HDF5StructureProcessor(inputs=inputs)
    setup_processor(task)
    task.run()

    # Verify the payload JSON is written out:
    assert task.payload_output_path and os.path.exists(
        task.payload_output_path)
    with open(task.payload_output_path, 'r') as f:
        payload = json.load(f)
        assert len(payload) > 0
        entry = payload[0]
        assert 'path' in entry and isinstance(entry['path'], list)
        assert 'path_key' in entry and isinstance(entry['path_key'],
                                                  string_types)
        assert 'name' in entry and isinstance(entry['name'], string_types)
        assert 'metadata' in entry and isinstance(entry['metadata'], list)
        assert 'type' in entry and isinstance(entry['type'],
                                              (dict, string_types))
        if isinstance(entry['type'], dict) and \
           entry['type']['dimensions'] == 1 and \
           entry['type']['size'] == 1:
            assert 'value' in entry

    # Verify the asset JSON is written out:
    assert task.asset_output_path and os.path.exists(task.asset_output_path)
    with open(task.asset_output_path, 'r') as f:
        asset_info = json.load(f)
        print(asset_info)
def test_explode_assets(filename):
    print "~" * 60
    print " Using test file %s to test exploding PNG assets " % filename
    print "~" * 60

    mock_dynamodb2().start()
    mock_ssm().start()
    mock_s3().start()

    init_ssm()

    # init task
    inputs = {'file': os.path.join('/test-resources', filename)}
    task = OMETIFFProcessor(inputs=inputs)

    setup_processor(task)

    # Load image
    output_file = OMETIFFOutputFile()
    output_file.file_path = task.file
    output_file.load_and_save_assets(output_file.file_path,
                                     i_xyzct=(-1, -1, -1, -1, -1),
                                     n_xyzct=(-1, -1, -1, -1, -1),
                                     asset_format='png')

    # Since we know first two dimensions are are X and Y
    assert output_file.img_dimensions['dimensions'][0]['assignment'] == 'X'
    assert output_file.img_dimensions['dimensions'][1]['assignment'] == 'Y'

    # Get number of files generated
    num_png_files = len(
        glob.glob('%s-zoomed/*.png' % os.path.basename(output_file.file_path)))
    print glob.glob('%s-zoomed/*.png' %
                    os.path.basename(output_file.file_path))

    # Ensure correct number of png outputs
    if output_file.isRGB:
        # Compute combinatorial number of files expected
        shape = [
            output_file.SizeX, output_file.SizeY, output_file.SizeZ,
            output_file.SizeC, output_file.SizeT
        ]
        # Remove RGB dimension from combinatorial count
        shape.pop(output_file.RGBDimension)
    else:
        # Compute combinatorial number of files expected
        shape = [
            output_file.SizeX, output_file.SizeY, output_file.SizeZ,
            output_file.SizeC, output_file.SizeT
        ]

    total_count = np.prod(shape[2:])
    print shape, output_file.isRGB

    # Make sure same number of files generated
    assert num_png_files == total_count

    # Save to local storage output deepzoom files
    output_file.load_and_save_assets(output_file.file_path,
                                     i_xyzct=(-1, -1, -1, -1, -1),
                                     n_xyzct=(-1, -1, -1, -1, -1),
                                     asset_format='dzi')

    # Get number of files generated
    num_dzi_files = len(
        glob.glob('%s-zoomed/*.dzi' % os.path.basename(output_file.file_path)))
    print glob.glob('%s-zoomed/*.dzi' %
                    os.path.basename(output_file.file_path))

    # Ensure correct number of dzi outputs
    if output_file.isRGB:
        # Compute combinatorial number of files expected
        shape = [
            output_file.SizeX, output_file.SizeY, output_file.SizeZ,
            output_file.SizeC, output_file.SizeT
        ]
        # Remove RGB dimension from combinatorial count
        shape.pop(output_file.RGBDimension)
    else:
        # Compute combinatorial number of files expected
        shape = [
            output_file.SizeX, output_file.SizeY, output_file.SizeZ,
            output_file.SizeC, output_file.SizeT
        ]

    total_count = np.prod(shape[2:])
    print shape

    # Make sure same number of files generated
    assert num_dzi_files == total_count

    # Clean up
    os.system('rm %s-zoomed/*.png' % os.path.basename(output_file.file_path))
    os.system('rm %s-zoomed/*.dzi' % os.path.basename(output_file.file_path))

    mock_s3().stop()
    mock_ssm().stop()
    mock_dynamodb2().stop()