def test_region_mask(self): mask = image_methods.get_region_masks(FITS_FILE, REG_FILE)[0] imarray, header = image_methods.get_image_data(FITS_FILE) mask = np.invert(mask) imarray = mask * imarray image_methods.show(imarray) self.assertEqual(imarray[362, 75] == 0)
def test_detect_frcnn_long(self): for im, name, labels, boxes in utils.tf_record_iterator( f"{BASE_DIR}/frcnn_records/test/annotated.record"): image_methods.show(im, use_log=False, annotations=zip(boxes, labels)) answer = image_methods.detect_comet(im, do_show=True)
def test_preprocess(self): fig, ax = plt.subplots(1) ax.imshow(IMARRAY, cmap="gray") plt.show() im = image_methods.median_filter_nans(IMARRAY) im = image_methods.preprocess(im, resize=False) im = image_methods.resize_image(im, 512) image_methods.show(im, use_log=False)
def test_pyramid_propose(self): image_methods.show(IMARRAY) for sub_im, rect, ax in image_methods.pyramid_propose( IMARRAY, step=64, zoom_step=1.5, box_size=128, orig_zoom=1, do_show=True, interactive=False): time.sleep(.005)
def test_save_data(self): save_file = COMET_PROCESSED_NP_IMAGES[:-4] save_file_original = COMET_ORIG_NP_IMAGES[:-4] ims = image_methods.get_normed_data(FITS_FOLDER, save_file, save_file_original) imarray = ims[0][10] image_methods.show(imarray) image_methods.get_normed_data(NOT_COMET_FITS_FOLDER, file_for_orig=NOT_COMET_NP_IMAGES[:-4], reg_files=False) self.assertEqual(imarray, np.load(COMET_PROCESSED_NP_IMAGES)[0][10])
def test_untrained_comet_detection(self): for images in utils.image_iterator(f"{BASE_DIR}/not_trained_comets"): fits = images[0] arrs = [image_methods.get_image_data(f)[0] for f in fits] preprod = [ image_methods.preprocess(arr, resize=False) for arr in arrs ] resized = [image_methods.resize_image(pre, 512) for pre in preprod] comp = image_methods.get_composite_image(resized) image_methods.show(comp) answer = image_methods.detect_comet(preprod, do_show=True, im_type="composite") print(answer)
def test_detect_3frcnn_long(self): acc, count = (0, 0) for im, name, labels, boxes in utils.tf_record_iterator( f"{BASE_DIR}/data/band_3/c/test.record"): print(name) image_methods.show(im, use_log=False, annotations=zip(boxes, labels)) answer = image_methods.detect_comet(im, do_show=True, im_type="band_3") acc += answer == ("comet" in labels) count += 1 print(f"accuracy: {acc / count}")
def test_pipeline(self): x = utils.image_iterator(FITS_FOLDER) for _ in range(160): scanfiles = next(x) print(scanfiles[0]) ims = scanfiles[0] ims = [image_methods.get_image_data(im)[0] for im in ims] origs = ims.copy() image_methods.show_many(np.array(origs)) preprod = [image_methods.preprocess(im, resize=False) for im in ims] resized = [image_methods.resize_image(im, 512) for im in preprod] image_methods.show_many(np.array(origs), row_2=np.array(resized)) composite = image_methods.get_composite_image(resized) image_methods.show(composite, use_log=False) image_methods.detect_comet(composite, do_show=True, im_type="composite")
def test_median_filter(self): image_methods.show(IMARRAY) IMARRAY = image_methods.median_filter_image(IMARRAY) image_methods.show(IMARRAY)
def test_resize(self): image_methods.show(IMARRAY) IMARRAY = image_methods.resize_image(IMARRAY, 500) image_methods.show(IMARRAY) self.assertEqual(IMARRAY.shape[0], 500)
def test_get_data(self): imarray, header = image_methods.get_image_data(FITS_FILE) image_methods.show(imarray) self.assertEqual(imarray[100, 100], 880.8705444335938) self.assertEqual(header["RA0"], 304.529473280337)
def test_flip(self): image_methods.show(IMARRAY) flipped = image_methods.flip_image(IMARRAY, axis="y") image_methods.show(flipped) self.assertEqual(IMARRAY[0, 0], flipped[0, -1])
def test_rotate(self): image_methods.show(IMARRAY) rotated = image_methods.rotate_image(IMARRAY, 90) image_methods.show(rotated) self.assertEqual(IMARRAY[0, 0], rotated[-1, 0])