def test_segmap_from_classified_fails(): """Test the segmap_from_classified method.""" data = dh.get_expected_morpheus_output() h, _, _, _ = example.get_sample() mask = np.zeros_like(h, dtype=np.int) mask[5:-5, 5:-5] = 1 with pytest.raises(ValueError): Classifier.segmap_from_classified(data, h, mask=mask, bkg_src_threshold=1.0)
def test_segmap_from_classified(): """Test the segmap_from_classified method.""" data = dh.get_expected_morpheus_output() h, _, _, _ = example.get_sample() mask = np.zeros_like(h, dtype=np.int) mask[5:-5, 5:-5] = 1 expected_segmap = dh.get_expected_segmap()["segmap"] actual_segmap = Classifier.segmap_from_classified(data, h, mask=mask) np.testing.assert_array_equal(expected_segmap, actual_segmap)
def main(): args = _parse_args(sys.argv[1:]) if args.action == "None": Classifier.classify( h=args.h, j=args.j, v=args.v, z=args.z, batch_size=args.batch_size, out_dir=args.out_dir, gpus=args.gpus, cpus=args.cpus, ) elif args.action == "catalog": classified = Classifier.classify( h=args.h, j=args.j, v=args.v, z=args.z, batch_size=args.batch_size, out_dir=args.out_dir, gpus=args.gpus, cpus=args.cpus, ) segmap = Classifier.segmap_from_classified(classified, args.h, out_dir=args.out_dir) Classifier.catalog_from_classified( classified, args.h, segmap, out_file=os.path.join(args.out_dir, "colorized.png"), ) elif args.action == "segmap": classified = Classifier.classify( h=args.h, j=args.j, v=args.v, z=args.z, batch_size=args.batch_size, out_dir=args.out_dir, gpus=args.gpus, cpus=args.cpus, ) Classifier.segmap_from_classified(classified, args.h, out_dir=args.out_dir) elif args.action == "colorize": classified = Classifier.classify( h=args.h, j=args.j, v=args.v, z=args.z, batch_size=args.batch_size, out_dir=args.out_dir, gpus=args.gpus, cpus=args.cpus, ) Classifier.colorize_classified(classified, out_dir=args.out_dir) elif args.action == "all": classified = Classifier.classify( h=args.h, j=args.j, v=args.v, z=args.z, batch_size=args.batch_size, out_dir=args.out_dir, gpus=args.gpus, cpus=args.cpus, ) segmap = Classifier.segmap_from_classified(classified, args.h, out_dir=args.out_dir) Classifier.catalog_from_classified( classified, args.h, segmap, out_file=os.path.join(args.out_dir, "colorized.png"), ) Classifier.colorize_classified(classified, out_dir=args.out_dir)