examples.scan_exampes
1#!/usr/bin/env python 2 3import os 4from csi_images import csi_scans, csi_tiles, csi_frames, csi_events 5 6 7# Create a basic DatabaseHandler 8def load_in_images(): 9 repository_path = os.path.dirname(os.path.dirname(__file__)) 10 test_data_path = os.path.join(repository_path, "tests", "data") 11 12 # First, let's load in a scan's metadata 13 scan = csi_scans.Scan.load_yaml(test_data_path) 14 15 # Using that metadata, we can load in a tile or a ton of tiles 16 tile = csi_tiles.Tile(scan, 0) 17 tiles = csi_tiles.Tile.get_tiles(scan) 18 19 # By default, these will load in a single list 20 assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 21 22 # But we can also load them in as a grid 23 tiles = csi_tiles.Tile.get_tiles(scan, as_flat=False) 24 assert len(tiles) == scan.roi[0].tile_rows 25 assert len(tiles[0]) == scan.roi[0].tile_cols 26 27 # We can also load in frames for a tile or a ton of tiles 28 frames = csi_frames.Frame.get_frames(tile) 29 all_frames = csi_frames.Frame.get_all_frames(scan) 30 assert len(all_frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 31 assert len(all_frames[0]) == 4 32 all_frames = csi_frames.Frame.get_all_frames(scan, as_flat=False) 33 assert len(all_frames) == scan.roi[0].tile_rows 34 assert len(all_frames[0]) == scan.roi[0].tile_cols 35 assert len(all_frames[0][0]) == 4 36 37 # And for each frame, we can load the actual image 38 # First element is the image array, second element is the file path it came from 39 image = frames[0].get_image() 40 assert image.shape == (scan.tile_height_px, scan.tile_width_px) 41 42 43if __name__ == "__main__": 44 load_in_images()
def
load_in_images():
9def load_in_images(): 10 repository_path = os.path.dirname(os.path.dirname(__file__)) 11 test_data_path = os.path.join(repository_path, "tests", "data") 12 13 # First, let's load in a scan's metadata 14 scan = csi_scans.Scan.load_yaml(test_data_path) 15 16 # Using that metadata, we can load in a tile or a ton of tiles 17 tile = csi_tiles.Tile(scan, 0) 18 tiles = csi_tiles.Tile.get_tiles(scan) 19 20 # By default, these will load in a single list 21 assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 22 23 # But we can also load them in as a grid 24 tiles = csi_tiles.Tile.get_tiles(scan, as_flat=False) 25 assert len(tiles) == scan.roi[0].tile_rows 26 assert len(tiles[0]) == scan.roi[0].tile_cols 27 28 # We can also load in frames for a tile or a ton of tiles 29 frames = csi_frames.Frame.get_frames(tile) 30 all_frames = csi_frames.Frame.get_all_frames(scan) 31 assert len(all_frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 32 assert len(all_frames[0]) == 4 33 all_frames = csi_frames.Frame.get_all_frames(scan, as_flat=False) 34 assert len(all_frames) == scan.roi[0].tile_rows 35 assert len(all_frames[0]) == scan.roi[0].tile_cols 36 assert len(all_frames[0][0]) == 4 37 38 # And for each frame, we can load the actual image 39 # First element is the image array, second element is the file path it came from 40 image = frames[0].get_image() 41 assert image.shape == (scan.tile_height_px, scan.tile_width_px)