tests.test_tiles API documentation

# tests.test_tiles

View Source

      1from csi_images.csi_scans import Scan
      2from csi_images.csi_tiles import Tile
      3
      4
      5def test_axioscan_tiles():
      6    scan = Scan.load_yaml("tests/data")
      7    tile = Tile(scan, 0)
      8    # Assert that the tile is in the top-left corner
      9    assert (tile.x, tile.y) == (0, 0)
     10    assert tile.position_to_n() == 0
     11    assert tile.n_to_position() == (0, 0)
     12
     13    # Assert that position_to_n() and n_to_position() work with different positions
     14    assert tile.position_to_n((1, 0)) == 1
     15    assert tile.n_to_position(1) == (1, 0)
     16
     17    assert tile.position_to_n((0, 1)) == scan.roi[0].tile_cols
     18    assert tile.n_to_position(scan.roi[0].tile_cols) == (0, 1)
     19
     20    assert (
     21        tile.position_to_n((scan.roi[0].tile_cols - 1, scan.roi[0].tile_rows - 1))
     22        == scan.roi[0].tile_cols * scan.roi[0].tile_rows - 1
     23    )
     24    assert tile.n_to_position(scan.roi[0].tile_cols * scan.roi[0].tile_rows - 1) == (
     25        scan.roi[0].tile_cols - 1,
     26        scan.roi[0].tile_rows - 1,
     27    )
     28
     29    # Assert that creating a tile with a position works correctly
     30    tile = Tile(scan, (1, 0))
     31    assert tile.n == 1
     32
     33    # Assert that creating a tile with a bad n_roi raises an error
     34    try:
     35        Tile(scan, 0, 1)
     36        assert False
     37    except ValueError:
     38        assert True
     39
     40
     41def test_bzscanner_tiles():
     42    scan = Scan.load_txt("tests/data")
     43    tile = Tile(scan, 0)
     44    # Assert that the tile is in the top-left corner
     45    assert tile.x == 0
     46    assert tile.y == 0
     47    # Assert row-major indexing
     48    tile = Tile(scan, scan.roi[0].tile_cols - 1)
     49    assert tile.x == scan.roi[0].tile_cols - 1
     50    assert tile.y == 0
     51    # Assert snake indexing
     52    tile = Tile(scan, scan.roi[0].tile_cols)
     53    assert tile.x == scan.roi[0].tile_cols - 1
     54    assert tile.y == 1
     55    # Assert snake indexing again
     56    tile = Tile(scan, 2 * scan.roi[0].tile_cols)
     57    assert tile.x == 0
     58    assert tile.y == 2
     59
     60
     61def test_getting_tiles():
     62    scan = Scan.load_yaml("tests/data")
     63    # All tiles
     64    tiles = Tile.get_tiles(scan)
     65    assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
     66    # All tiles, as a grid
     67    tiles = Tile.get_tiles(scan, as_flat=False)
     68    assert len(tiles) == scan.roi[0].tile_rows
     69    assert len(tiles[0]) == scan.roi[0].tile_cols
     70
     71    # Just the first row
     72    tiles = Tile.get_tiles_by_row_col(scan, rows=[0])
     73    assert len(tiles) == scan.roi[0].tile_cols
     74    assert all(tile.y == 0 for tile in tiles)
     75    assert all(tile.x == i for i, tile in enumerate(tiles))
     76
     77    # Just the first column
     78    tiles = Tile.get_tiles_by_row_col(scan, cols=[0])
     79    assert len(tiles) == scan.roi[0].tile_rows
     80    assert all(tile.x == 0 for tile in tiles)
     81    assert all(tile.y == i for i, tile in enumerate(tiles))
     82
     83    # The bottom-right corner, with 4 tiles total
     84    tiles = Tile.get_tiles_by_xy_bounds(
     85        scan,
     86        (
     87            scan.roi[0].tile_cols - 2,
     88            scan.roi[0].tile_rows - 2,
     89            scan.roi[0].tile_cols,
     90            scan.roi[0].tile_rows,
     91        ),
     92    )
     93    assert len(tiles) == 4
     94    assert tiles[0].x == scan.roi[0].tile_cols - 2
     95    assert tiles[0].y == scan.roi[0].tile_rows - 2
     96    assert tiles[1].x == scan.roi[0].tile_cols - 1
     97    assert tiles[1].y == scan.roi[0].tile_rows - 2
     98    assert tiles[2].x == scan.roi[0].tile_cols - 2
     99    assert tiles[2].y == scan.roi[0].tile_rows - 1
    100    assert tiles[3].x == scan.roi[0].tile_cols - 1
    101    assert tiles[3].y == scan.roi[0].tile_rows - 1

def test_axioscan_tiles(): View Source

     6def test_axioscan_tiles():
     7    scan = Scan.load_yaml("tests/data")
     8    tile = Tile(scan, 0)
     9    # Assert that the tile is in the top-left corner
    10    assert (tile.x, tile.y) == (0, 0)
    11    assert tile.position_to_n() == 0
    12    assert tile.n_to_position() == (0, 0)
    13
    14    # Assert that position_to_n() and n_to_position() work with different positions
    15    assert tile.position_to_n((1, 0)) == 1
    16    assert tile.n_to_position(1) == (1, 0)
    17
    18    assert tile.position_to_n((0, 1)) == scan.roi[0].tile_cols
    19    assert tile.n_to_position(scan.roi[0].tile_cols) == (0, 1)
    20
    21    assert (
    22        tile.position_to_n((scan.roi[0].tile_cols - 1, scan.roi[0].tile_rows - 1))
    23        == scan.roi[0].tile_cols * scan.roi[0].tile_rows - 1
    24    )
    25    assert tile.n_to_position(scan.roi[0].tile_cols * scan.roi[0].tile_rows - 1) == (
    26        scan.roi[0].tile_cols - 1,
    27        scan.roi[0].tile_rows - 1,
    28    )
    29
    30    # Assert that creating a tile with a position works correctly
    31    tile = Tile(scan, (1, 0))
    32    assert tile.n == 1
    33
    34    # Assert that creating a tile with a bad n_roi raises an error
    35    try:
    36        Tile(scan, 0, 1)
    37        assert False
    38    except ValueError:
    39        assert True

def test_bzscanner_tiles(): View Source

    42def test_bzscanner_tiles():
    43    scan = Scan.load_txt("tests/data")
    44    tile = Tile(scan, 0)
    45    # Assert that the tile is in the top-left corner
    46    assert tile.x == 0
    47    assert tile.y == 0
    48    # Assert row-major indexing
    49    tile = Tile(scan, scan.roi[0].tile_cols - 1)
    50    assert tile.x == scan.roi[0].tile_cols - 1
    51    assert tile.y == 0
    52    # Assert snake indexing
    53    tile = Tile(scan, scan.roi[0].tile_cols)
    54    assert tile.x == scan.roi[0].tile_cols - 1
    55    assert tile.y == 1
    56    # Assert snake indexing again
    57    tile = Tile(scan, 2 * scan.roi[0].tile_cols)
    58    assert tile.x == 0
    59    assert tile.y == 2

def test_getting_tiles(): View Source

     62def test_getting_tiles():
     63    scan = Scan.load_yaml("tests/data")
     64    # All tiles
     65    tiles = Tile.get_tiles(scan)
     66    assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
     67    # All tiles, as a grid
     68    tiles = Tile.get_tiles(scan, as_flat=False)
     69    assert len(tiles) == scan.roi[0].tile_rows
     70    assert len(tiles[0]) == scan.roi[0].tile_cols
     71
     72    # Just the first row
     73    tiles = Tile.get_tiles_by_row_col(scan, rows=[0])
     74    assert len(tiles) == scan.roi[0].tile_cols
     75    assert all(tile.y == 0 for tile in tiles)
     76    assert all(tile.x == i for i, tile in enumerate(tiles))
     77
     78    # Just the first column
     79    tiles = Tile.get_tiles_by_row_col(scan, cols=[0])
     80    assert len(tiles) == scan.roi[0].tile_rows
     81    assert all(tile.x == 0 for tile in tiles)
     82    assert all(tile.y == i for i, tile in enumerate(tiles))
     83
     84    # The bottom-right corner, with 4 tiles total
     85    tiles = Tile.get_tiles_by_xy_bounds(
     86        scan,
     87        (
     88            scan.roi[0].tile_cols - 2,
     89            scan.roi[0].tile_rows - 2,
     90            scan.roi[0].tile_cols,
     91            scan.roi[0].tile_rows,
     92        ),
     93    )
     94    assert len(tiles) == 4
     95    assert tiles[0].x == scan.roi[0].tile_cols - 2
     96    assert tiles[0].y == scan.roi[0].tile_rows - 2
     97    assert tiles[1].x == scan.roi[0].tile_cols - 1
     98    assert tiles[1].y == scan.roi[0].tile_rows - 2
     99    assert tiles[2].x == scan.roi[0].tile_cols - 2
    100    assert tiles[2].y == scan.roi[0].tile_rows - 1
    101    assert tiles[3].x == scan.roi[0].tile_cols - 1
    102    assert tiles[3].y == scan.roi[0].tile_rows - 1