tests.test_tiles API documentation

# tests.test_tiles

View Source

     1from csi_images import csi_tiles, csi_scans
     2
     3
     4def test_axioscan_tiles():
     5    scan = csi_scans.Scan.load_yaml("tests/data")
     6    tile_rows = scan.roi[0].tile_rows
     7    tile_cols = scan.roi[0].tile_cols
     8    tile = csi_tiles.Tile(scan, 0)
     9    assert tile.x == 0
    10    assert tile.y == 0
    11
    12    tile = csi_tiles.Tile(scan, tile_cols - 1)
    13    assert tile.x == tile_cols - 1
    14    assert tile.y == 0
    15
    16    tile = csi_tiles.Tile(scan, tile_cols)
    17    assert tile.x == 0
    18    assert tile.y == 1
    19
    20    tile = csi_tiles.Tile(scan, tile_rows * tile_cols - 1)
    21    assert tile.x == tile_cols - 1
    22    assert tile.y == tile_rows - 1
    23    pass
    24
    25
    26def test_bzscanner_tiles():
    27    scan = csi_scans.Scan.load_txt("tests/data")
    28    tile_rows = scan.roi[0].tile_rows
    29    tile_cols = scan.roi[0].tile_cols
    30    tile = csi_tiles.Tile(scan, 0)
    31    assert tile.x == 0
    32    assert tile.y == 0
    33
    34    tile = csi_tiles.Tile(scan, tile_cols - 1)
    35    assert tile.x == tile_cols - 1
    36    assert tile.y == 0
    37
    38    tile = csi_tiles.Tile(scan, tile_cols)
    39    assert tile.x == tile_cols - 1
    40    assert tile.y == 1
    41
    42    tile = csi_tiles.Tile(scan, 2 * tile_cols)
    43    assert tile.x == 0
    44    assert tile.y == 2
    45    pass
    46
    47
    48def test_getting_tiles():
    49    # Test getting all of the tiles
    50    scan = csi_scans.Scan.load_yaml("tests/data")
    51    tiles = csi_tiles.Tile.get_tiles(scan)
    52    assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
    53    tiles = csi_tiles.Tile.get_tiles(scan, as_flat=False)
    54    assert len(tiles) == scan.roi[0].tile_rows
    55    assert len(tiles[0]) == scan.roi[0].tile_cols
    56
    57    # Just the first row
    58    tiles = csi_tiles.Tile.get_tiles_by_row_col(scan, rows=[0])
    59    assert len(tiles) == scan.roi[0].tile_cols
    60    assert all(tile.y == 0 for tile in tiles)
    61    assert all(tile.x == i for i, tile in enumerate(tiles))
    62
    63    # Just the first column
    64    tiles = csi_tiles.Tile.get_tiles_by_row_col(scan, cols=[0])
    65    assert len(tiles) == scan.roi[0].tile_rows
    66    assert all(tile.x == 0 for tile in tiles)
    67    assert all(tile.y == i for i, tile in enumerate(tiles))
    68
    69    # The bottom-right corner, with 4 tiles total
    70    tiles = csi_tiles.Tile.get_tiles_by_xy_bounds(
    71        scan,
    72        (
    73            scan.roi[0].tile_cols - 2,
    74            scan.roi[0].tile_rows - 2,
    75            scan.roi[0].tile_cols,
    76            scan.roi[0].tile_rows,
    77        ),
    78    )
    79    assert len(tiles) == 4
    80    assert tiles[0].x == scan.roi[0].tile_cols - 2
    81    assert tiles[0].y == scan.roi[0].tile_rows - 2
    82    assert tiles[1].x == scan.roi[0].tile_cols - 1
    83    assert tiles[1].y == scan.roi[0].tile_rows - 2
    84    assert tiles[2].x == scan.roi[0].tile_cols - 2
    85    assert tiles[2].y == scan.roi[0].tile_rows - 1
    86    assert tiles[3].x == scan.roi[0].tile_cols - 1
    87    assert tiles[3].y == scan.roi[0].tile_rows - 1

def test_axioscan_tiles(): View Source

     5def test_axioscan_tiles():
     6    scan = csi_scans.Scan.load_yaml("tests/data")
     7    tile_rows = scan.roi[0].tile_rows
     8    tile_cols = scan.roi[0].tile_cols
     9    tile = csi_tiles.Tile(scan, 0)
    10    assert tile.x == 0
    11    assert tile.y == 0
    12
    13    tile = csi_tiles.Tile(scan, tile_cols - 1)
    14    assert tile.x == tile_cols - 1
    15    assert tile.y == 0
    16
    17    tile = csi_tiles.Tile(scan, tile_cols)
    18    assert tile.x == 0
    19    assert tile.y == 1
    20
    21    tile = csi_tiles.Tile(scan, tile_rows * tile_cols - 1)
    22    assert tile.x == tile_cols - 1
    23    assert tile.y == tile_rows - 1
    24    pass

def test_bzscanner_tiles(): View Source

    27def test_bzscanner_tiles():
    28    scan = csi_scans.Scan.load_txt("tests/data")
    29    tile_rows = scan.roi[0].tile_rows
    30    tile_cols = scan.roi[0].tile_cols
    31    tile = csi_tiles.Tile(scan, 0)
    32    assert tile.x == 0
    33    assert tile.y == 0
    34
    35    tile = csi_tiles.Tile(scan, tile_cols - 1)
    36    assert tile.x == tile_cols - 1
    37    assert tile.y == 0
    38
    39    tile = csi_tiles.Tile(scan, tile_cols)
    40    assert tile.x == tile_cols - 1
    41    assert tile.y == 1
    42
    43    tile = csi_tiles.Tile(scan, 2 * tile_cols)
    44    assert tile.x == 0
    45    assert tile.y == 2
    46    pass

def test_getting_tiles(): View Source

    49def test_getting_tiles():
    50    # Test getting all of the tiles
    51    scan = csi_scans.Scan.load_yaml("tests/data")
    52    tiles = csi_tiles.Tile.get_tiles(scan)
    53    assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
    54    tiles = csi_tiles.Tile.get_tiles(scan, as_flat=False)
    55    assert len(tiles) == scan.roi[0].tile_rows
    56    assert len(tiles[0]) == scan.roi[0].tile_cols
    57
    58    # Just the first row
    59    tiles = csi_tiles.Tile.get_tiles_by_row_col(scan, rows=[0])
    60    assert len(tiles) == scan.roi[0].tile_cols
    61    assert all(tile.y == 0 for tile in tiles)
    62    assert all(tile.x == i for i, tile in enumerate(tiles))
    63
    64    # Just the first column
    65    tiles = csi_tiles.Tile.get_tiles_by_row_col(scan, cols=[0])
    66    assert len(tiles) == scan.roi[0].tile_rows
    67    assert all(tile.x == 0 for tile in tiles)
    68    assert all(tile.y == i for i, tile in enumerate(tiles))
    69
    70    # The bottom-right corner, with 4 tiles total
    71    tiles = csi_tiles.Tile.get_tiles_by_xy_bounds(
    72        scan,
    73        (
    74            scan.roi[0].tile_cols - 2,
    75            scan.roi[0].tile_rows - 2,
    76            scan.roi[0].tile_cols,
    77            scan.roi[0].tile_rows,
    78        ),
    79    )
    80    assert len(tiles) == 4
    81    assert tiles[0].x == scan.roi[0].tile_cols - 2
    82    assert tiles[0].y == scan.roi[0].tile_rows - 2
    83    assert tiles[1].x == scan.roi[0].tile_cols - 1
    84    assert tiles[1].y == scan.roi[0].tile_rows - 2
    85    assert tiles[2].x == scan.roi[0].tile_cols - 2
    86    assert tiles[2].y == scan.roi[0].tile_rows - 1
    87    assert tiles[3].x == scan.roi[0].tile_cols - 1
    88    assert tiles[3].y == scan.roi[0].tile_rows - 1