def test_setDQ(self): test_out_dir = self.set_outputfolder("test_setDQ") ag = AGAnalysis(self.agilepyConf) # dq out of range self.assertRaises(ConfigurationsNotValidError, ag.setOptions, dq=42) # dq = 0 ag.setOptions(dq=0, albedorad=101, fovradmax=102) self.assertEqual(ag.getOption("albedorad"), 101) self.assertEqual(ag.getOption("fovradmax"), 102) # dq == 5 ag.setOptions(dq=5) self.assertEqual(ag.getOption("albedorad"), 100) self.assertEqual(ag.getOption("fovradmax"), 50) # Try to change albedorad or fovradmax with dq == 5 self.assertRaises(CannotSetNotUpdatableOptionError, ag.setOptions, albedorad=42, fovradmax=42) ag.destroy()
def test_update_gal_iso(self): test_out_dir = self.set_outputfolder("test_update_gal_iso") ag = AGAnalysis(self.agilepyConf, self.sourcesConfTxt) ag.setOptions(tmin=433857532, tmax=433858532, timetype="TT") outDir = Path(ag.getOption("outdir")) ag.config.setOptions(galcoeff=[0.6, 0.8, 0.6, 0.8]) ag.config.setOptions(isocoeff=[10, 15, 10, 15]) galcoeffs = ag.config.getOptionValue("galcoeff") isocoeffs = ag.config.getOptionValue("isocoeff") _ = ag.generateMaps() matrix = ag.parseMaplistFile() for idx, row in enumerate(matrix): self.assertEqual(str(galcoeffs[idx]), row[4]) self.assertEqual(str(isocoeffs[idx]), row[5]) ag.config.setOptions(galcoeff=[0,0,0,0]) ag.config.setOptions(isocoeff=[0,0,0,0]) galcoeffs = ag.config.getOptionValue("galcoeff") isocoeffs = ag.config.getOptionValue("isocoeff") matrix = ag.parseMaplistFile() for idx, row in enumerate(matrix): self.assertEqual(str(galcoeffs[idx]), row[4]) self.assertEqual(str(isocoeffs[idx]), row[5])
def test_generate_maps(self): test_out_dir = self.set_outputfolder("test_generate_maps") ag = AGAnalysis(self.agilepyConf, self.sourcesConfTxt) ag.setOptions(tmin=433857532, tmax=433858532, timetype="TT") outDir = ag.getOption("outdir") maplistFilePath0 = ag.generateMaps() self.assert_maplistfile_lines_number(maplistFilePath0, 4) outDir0 = Path(outDir).joinpath("maps", "0") self.assertEqual(True, outDir0.is_dir()) self.assert_generated_maps_number(outDir0, 16) self.assert_generated_maps_exist(ag.parseMaplistFile(maplistFilePath0)) # second generation (same parameters) maplistFilePath1 = ag.generateMaps() self.assert_maplistfile_lines_number(maplistFilePath1, 4) outDir1 = Path(outDir).joinpath("maps", "1") self.assertEqual(True, outDir1.is_dir()) self.assert_generated_maps_number(outDir1, 16) self.assert_generated_maps_exist(ag.parseMaplistFile(maplistFilePath1)) # third generation with different time interval ag.setOptions(tmin=433957532, tmax=433957632, timetype="TT") maplistFilePath2 = ag.generateMaps() self.assert_maplistfile_lines_number(maplistFilePath2, 4) outDir2 = Path(outDir).joinpath("maps", "2") self.assertEqual(True, outDir2.is_dir()) self.assert_generated_maps_number(outDir2, 16) self.assert_generated_maps_exist(ag.parseMaplistFile(maplistFilePath2)) # fourth generation with different glon and glat ag.setOptions(glon=265, glat=-3, timetype="TT") maplistFilePath3 = ag.generateMaps() self.assert_maplistfile_lines_number(maplistFilePath3, 4) outDir3 = Path(outDir).joinpath("maps", "3") self.assertEqual(True, outDir3.is_dir()) self.assert_generated_maps_number(outDir3, 16) self.assert_generated_maps_exist(ag.parseMaplistFile(maplistFilePath3)) # fifth generation with different fovbinnumber, and energy range ag.setOptions(fovbinnumber=1, energybins=[[100,300]]) maplistFilePath4 = ag.generateMaps() self.assert_maplistfile_lines_number(maplistFilePath4, 1) outDir3 = Path(outDir).joinpath("maps", "4") self.assertEqual(True, outDir3.is_dir()) self.assert_generated_maps_number(outDir3, 4) self.assert_generated_maps_exist(ag.parseMaplistFile(maplistFilePath4)) ag.destroy()
def test_delete_output_directory(self): ag = AGAnalysis(self.agilepyconfPath, self.sourcesconfPath) outDir = Path(ag.getOption("outdir")) self.assertEqual(True, outDir.exists() and outDir.is_dir()) ag.deleteAnalysisDir() self.assertEqual(False, outDir.exists())
def test_setOptionEnergybin(self): test_out_dir = self.set_outputfolder("test_setOptionEnergybin") energybin0 = [[100, 10000]] energybin1 = [[100, 50000]] energybin2 = [[100, 300], [300, 1000], [1000, 3000], [3000, 10000]] energybin3 = [[100, 300], [300, 1000], [1000, 3000], [3000, 10000], [10000, 50000]] energybin4 = [[50, 100], [100, 300], [300, 1000], [1000, 3000], [3000, 10000]] energybin5 = [[50, 100], [100, 300], [300, 1000], [1000, 3000], [3000, 10000], [10000, 50000]] ag = AGAnalysis(self.agilepyConf) self.assertRaises(ValueOutOfRange, ag.setOptionEnergybin, 42) ag.setOptionEnergybin(0) self.assertEqual(ag.getOption("energybins"), energybin0) ag.setOptionEnergybin(1) self.assertEqual(ag.getOption("energybins"), energybin1) ag.setOptionEnergybin(2) self.assertEqual(ag.getOption("energybins"), energybin2) ag.setOptionEnergybin(3) self.assertEqual(ag.getOption("energybins"), energybin3) ag.setOptionEnergybin(4) self.assertEqual(ag.getOption("energybins"), energybin4) ag.setOptionEnergybin(5) self.assertEqual(ag.getOption("energybins"), energybin5) ag.destroy()
def test_setOptionTimeMJD(self): test_out_dir = self.set_outputfolder("test_setOptionTimeMJD") ag = AGAnalysis(self.agilepyConf) tmin1 = 58030.0 tmax1 = 58035.0 tmintt = AstroUtils.time_mjd_to_agile_seconds(tmin1) tmaxtt = AstroUtils.time_mjd_to_agile_seconds(tmax1) ag.setOptionTimeMJD(tmin=tmin1, tmax=tmax1) tmin2 = ag.getOption("tmin") tmax2 = ag.getOption("tmax") self.assertEqual(tmintt, tmin2) self.assertEqual(tmaxtt, tmax2) ag.destroy()
def test_delete_output_directory(self): test_out_dir = self.set_outputfolder("test_delete_output_directory") ag = AGAnalysis(self.agilepyConf, self.sourcesConfTxt) outDir = Path(ag.getOption("outdir")) self.assertEqual(True, outDir.exists() and outDir.is_dir()) ag.deleteAnalysisDir() self.assertEqual(False, outDir.exists())
def test_generate_maps(self): ag = AGAnalysis(self.agilepyconfPath, self.sourcesconfPath) outDir = ag.getOption("outdir") maplistFilePath = ag.generateMaps() self.assertEqual(True, os.path.isfile(maplistFilePath)) maps = os.listdir(Path(outDir).joinpath("maps")) self.assertEqual(16, len(maps)) lines = None with open(maplistFilePath) as mfp: lines = mfp.readlines() self.assertEqual(4, len(lines)) ag.destroy()
def test_update_gal_iso(self): ag = AGAnalysis(self.agilepyconfPath, self.sourcesconfPath) outDir = Path(ag.getOption("outdir")) ag.config.setOptions(galcoeff=[0.6, 0.8, 0.6, 0.8]) ag.config.setOptions(isocoeff=[10, 15, 10, 15]) galcoeffs = ag.config.getOptionValue("galcoeff") isocoeffs = ag.config.getOptionValue("isocoeff") maplistFilePath = ag.generateMaps() matrix = ag.parseMaplistFile() for idx, row in enumerate(matrix): self.assertEqual(str(galcoeffs[idx]), row[4]) self.assertEqual(str(isocoeffs[idx]), row[5]) if outDir.joinpath("maps").exists() and outDir.joinpath( "maps").is_dir(): shutil.rmtree(outDir.joinpath("maps")) outDir.joinpath("maps").mkdir(parents=False, exist_ok=True) ag.config.setOptions(galcoeff=[0, 0, 0, 0]) ag.config.setOptions(isocoeff=[0, 0, 0, 0]) galcoeffs = ag.config.getOptionValue("galcoeff") isocoeffs = ag.config.getOptionValue("isocoeff") matrix = ag.parseMaplistFile() for idx, row in enumerate(matrix): self.assertEqual(str(galcoeffs[idx]), row[4]) self.assertEqual(str(isocoeffs[idx]), row[5]) ag.destroy()