def test_ImageDict_make_dict(): ImgDict = image_prep.ImageDict() ImgDict.add_class("test", IMG_URLS) ImgDict.group_image_channels() ImgDict.train_test_split() out = ImgDict.make_dict() assert isinstance(out, dict)
def test_ImageDict_get_wells_str(): ImgDict = image_prep.ImageDict() well_to_get = "B02" wanted = ImgDict.get_wells(IMG_URLS, well_to_get) # parse well info from image urls wanted_wells = [parse.img_well(url) for url in wanted] for well in wanted_wells: assert well in well_to_get
def test_ImageDict_keep_channels(): channels_to_keep = [1, 2, 3] ImgDict = image_prep.ImageDict() ans = ImgDict.keep_channels(IMG_URLS, channels_to_keep) # parse channel numbers out of ans img_names = [parse.img_filename(f) for f in ans] img_channels = [parse.img_channel(name) for name in img_names] for channel in img_channels: assert channel in channels_to_keep
def test_ImageDict_remove_channels(): channels_to_remove = [4, 5] ImgDict = image_prep.ImageDict() ans = ImgDict.remove_channels(IMG_URLS, channels_to_remove) # parse channel numbers out of ans img_names = [parse.img_filename(f) for f in ans] img_channels = [parse.img_channel(name) for name in img_names] for channel in img_channels: assert channel not in channels_to_remove
def test_ImageDict_sort_channels(): ImgDict = image_prep.ImageDict() # un-sorted channels # reverse channels as already sorted rev_img_urls = IMG_URLS[::-1] ImgDict.add_class("foo", rev_img_urls) ImgDict.group_image_channels(order=False) order_false_dict = ImgDict.parent_dict order_false_vals = order_false_dict["foo"][0] order_false_chnnls = [parse.img_channel(val) for val in order_false_vals] assert sorted(order_false_chnnls) != order_false_chnnls # sort channels # need to create new ImageDict class otherwise we get a warning due to # adding a new class to already grouped data ImgDict2 = image_prep.ImageDict() ImgDict2.add_class("bar", IMG_URLS) ImgDict2.group_image_channels(order=True) order_true_dict = ImgDict2.parent_dict order_true_vals = order_true_dict["bar"][0] order_true_chnnls = [parse.img_channel(val) for val in order_true_vals] assert sorted(order_true_chnnls) == order_true_chnnls
def test_ImageDict_train_test_split(): ImgDict = image_prep.ImageDict() ImgDict.add_class("test", IMG_URLS) ImgDict.group_image_channels() ImgDict.train_test_split() out = ImgDict.make_dict() assert isinstance(out, dict) assert set(out.keys()) == set(["train", "test"]) # train test split doesn't lose any images n_train = len(out["train"]["test"]) n_test = len(out["test"]["test"]) n_images = len(ImgDict._group_channels(IMG_URLS, order=False)) assert n_train + n_test == n_images
def test_ImageDict_group_channels(): ImgDict = image_prep.ImageDict() ImgDict.add_class("test", IMG_URLS) ImgDict.group_image_channels() out = ImgDict.parent_dict assert isinstance(out, dict)
def test_ImageDict_add_class(): ImgDict = image_prep.ImageDict() ImgDict.add_class("test", IMG_URLS) out = ImgDict.parent_dict assert isinstance(out, dict) assert list(out.keys()) == ["test"]