def test_add_dark_exposure(self): try: download_folder("dark_test") except: raise DataDownloadException( "Could not download test data for darks." ) excel_path = "src/simmer/Examples/Shane/logsheet.xlsx" copy_path = "src/simmer/Examples/Shane/logsheet_copy.xlsx" copyfile(excel_path, copy_path) raw_dir = "src/simmer/tests/dark_test/" tab = "Sheet1" inst = i.ShARCS() ad.add_dark_exp(inst, copy_path, raw_dir, tab) os.remove(copy_path) delete_folder(raw_dir) self.assertTrue(True)
class TestShARCSSpecific(unittest.TestCase): inst = i.ShARCS() def test_search_headers_no_framenum(self): """ Tests the search_headers function against the original file that caused the issue. """ try: download_folder("search_headers") except: raise DataDownloadException( "Could not download test data for skies." ) raw_dir = "src/simmer/tests/test_search_header/" data, header = pyfits.getdata( raw_dir + "wrong_header.fits", header=True ) del header["FRAMENUM"] pyfits.writeto( raw_dir + "wrong_header.fits", data, header, overwrite=True ) with captured_output() as (out, err): search.search_headers(raw_dir) anticipated_string = "Header Incomplete in src/simmer/tests/test_search_header/wrong_header.fits!!!" # This can go inside or outside the `with` block output = out.getvalue().strip() delete_folder(raw_dir) self.assertEqual(output, anticipated_string) def test_search_headers_no_datafile(self): """ Tests the search_headers function against the original file that caused the issue. """ try: download_folder("search_headers") except: raise DataDownloadException( "Could not download test data for skies." ) raw_dir = "src/simmer/tests/test_search_header/" data, header = pyfits.getdata( raw_dir + "wrong_header.fits", header=True ) del header["DATAFILE"] pyfits.writeto( raw_dir + "wrong_header.fits", data, header, overwrite=True ) with captured_output() as (out, err): search.search_headers(raw_dir) anticipated_string = "Header Incomplete in src/simmer/tests/test_search_header/wrong_header.fits!!!" # This can go inside or outside the `with` block output = out.getvalue().strip() delete_folder(raw_dir) self.assertEqual(output, anticipated_string) def test_search_headers(self): try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies." ) raw_dir, write_dir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) search.search_headers(raw_dir, write_dir) val = True f = open(write_dir + "headers_wrong.txt", "r") for line in f: if "INCOMPLETE" in line: val = False f.close() self.assertTrue(val)
def test_check_logsheet_correct(self): inst = i.ShARCS() excel_path = "src/simmer/Examples/PHARO/logsheet.csv" failed = check.check_logsheet(inst, excel_path) self.assertTrue(failed == 0)
def test_check_logsheet_incorrect(self): inst = i.ShARCS() excel_path = "src/simmer/Examples/Shane/logsheet_incorrect.xlsx" failed = check.check_logsheet(inst, excel_path) self.assertTrue(failed == 7)
class TestDrivers(unittest.TestCase): inst = i.ShARCS() def test_dark_driver(self): print("Testing dark driver") try: download_folder("dark_test") except: raise DataDownloadException( "Could not download test data for darks.") raw_dir, reddir = ( "src/simmer/tests/dark_test/", "src/simmer/tests/dark_test/", ) config = pd.read_csv(os.getcwd() + "/src/simmer/tests/test_config.csv") try: darks.dark_driver(raw_dir, reddir, config, self.inst) val = "dark_3sec.fits" in os.listdir(raw_dir) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_flat_driver(self): print("Testing flat driver") try: download_folder("flat_test") except: raise DataDownloadException( "Could not download test data for flats.") raw_dir, reddir = ( "src/simmer/tests/flat_test/", "src/simmer/tests/flat_test/", ) config = pd.read_csv(os.getcwd() + "/src/simmer/tests/test_config.csv") source = raw_dir + "flat_J.fits" dest = raw_dir + "temp.fits" os.rename(source, dest) try: flats.flat_driver(raw_dir, reddir, config, self.inst) val = "flat_J.fits" in os.listdir(raw_dir) os.remove(raw_dir + "flat_J.fits") os.rename(dest, source) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_sky_driver(self): print("Testing sky driver") try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies.") raw_dir, reddir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) config = pd.read_csv(os.getcwd() + "/src/simmer/tests/test_config.csv") try: sky.sky_driver(raw_dir, reddir, config, self.inst) val = "sky.fits" in os.listdir(raw_dir + "/K09203794/Ks") delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_image_driver(self): print("Testing image driver") try: download_folder("image_test") except: raise DataDownloadException( "Could not download test data for images.") raw_dir, reddir = ( "src/simmer/tests/image_test/", "src/simmer/tests/image_test/", ) config = pd.read_csv(os.getcwd() + "/src/simmer/tests/test_config.csv") try: method = image.image_driver(raw_dir, reddir, config, self.inst) remove_files = [ "sh00.fits", "sh01.fits", "sh02.fits", "sh03.fits", "shifts.txt", ] val = np.all([ r in os.listdir(raw_dir + f"K09203794/Ks") for r in remove_files ]) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_image_driver_mixed_case(self): """ Previously, methods all needed to be lower case... """ print("Testing image driver mixed case") try: download_folder("image_test") except: raise DataDownloadException( "Could not download test data for images.") raw_dir, reddir = ( "src/simmer/tests/image_test/", "src/simmer/tests/image_test/", ) config = pd.read_csv(os.getcwd() + "/src/simmer/tests/test_config_test_case.csv") try: method = image.image_driver(raw_dir, reddir, config, self.inst) remove_files = [ "sh00.fits", "sh01.fits", "sh02.fits", "sh03.fits", "shifts.txt", ] val = np.all([ r in os.listdir(raw_dir + f"K09203794/Ks") for r in remove_files ]) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False)
class TestCreation(unittest.TestCase): inst = i.ShARCS() def test_create_darks(self): print("Testing darks") try: download_folder("dark_test") except: raise DataDownloadException( "Could not download test data for darks.") raw_dir, reddir = ( "src/simmer/tests/dark_test/", "src/simmer/tests/dark_test/", ) compare_dark = pyfits.getdata(raw_dir + "compare_dark.fits", 0) zero = np.zeros(np.shape(compare_dark)) # only testing flats darklist = range(1357, 1360) try: result = darks.create_darks(raw_dir, reddir, darklist, self.inst) delete_folder(raw_dir) self.assertCountEqual(np.ravel(result - compare_dark), np.ravel(zero)) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_create_flats(self): print("Testing flats") try: download_folder("flat_test") except: raise DataDownloadException( "Could not download test data for flats.") raw_dir, reddir = ( "src/simmer/tests/flat_test/", "src/simmer/tests/flat_test/", ) compare_flat = pyfits.getdata(raw_dir + "compare_flat.fits", 0) zero = np.zeros(np.shape(compare_flat)) # only testing flats flatlist = range(1108, 1114) try: result = flats.create_flats(raw_dir, reddir, flatlist, np.nan, self.inst, test=True) delete_folder(raw_dir) self.assertCountEqual(np.ravel(result - compare_flat), np.ravel(zero)) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_create_skies(self): print("Testing skies") try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies.") raw_dir, reddir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) compare_sky = np.loadtxt(raw_dir + "compare_sky.txt") s_dir = raw_dir skylist = range(1218, 1222) try: result = sky.create_skies(raw_dir, reddir, s_dir, skylist, self.inst) zero = np.zeros(np.shape(compare_sky)) delete_folder(raw_dir) self.assertCountEqual(np.ravel(result - compare_sky), np.ravel(zero)) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_create_imstack(self): print("Testing imstack") try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies.") raw_dir, reddir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) imlist = range(1218, 1222) s_dir = raw_dir try: result, shifts_all = image.create_imstack(raw_dir, reddir, s_dir, imlist, self.inst) compare_list = [ "compare_create_imstack_0", "compare_create_imstack_1", "compare_create_imstack_2", "compare_create_imstack_3", ] compare_imstack = np.array( [np.loadtxt(raw_dir + file) for file in compare_list]) zero = np.zeros(np.shape(compare_imstack)) delete_folder(raw_dir) self.assertCountEqual(np.ravel(result - compare_imstack), np.ravel(zero)) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_create_im_default(self): print("Testing default image creation") try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies.") raw_dir, reddir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) s_dir = raw_dir compare_final_im = pyfits.getdata( raw_dir + "Ks/compare_final_im_default.fits", 0) try: image.create_im(s_dir, 10, method="default") final_im = pyfits.getdata(raw_dir + "Ks/final_im.fits", 0) zero = np.zeros(np.shape(final_im)) val = np.all( np.ravel(final_im - compare_final_im) == np.ravel(zero)) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(False) def test_create_im_saturated(self): print("Testing saturated image creation") try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies.") raw_dir, reddir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) s_dir = raw_dir compare_final_im = pyfits.getdata(raw_dir + "Ks/compare_final_im.fits", 0) try: image.create_im(s_dir, 10, method="saturated") final_im = pyfits.getdata(raw_dir + "Ks/final_im.fits", 0) zero = np.zeros(np.shape(final_im)) val = np.all(np.allclose(final_im, compare_final_im)) delete_folder(raw_dir) self.assertTrue(val) except: e = sys.exc_info()[0] print(e) delete_folder(raw_dir) self.assertTrue(val)