def test_map_data_ranges(): map_data_table = compare_survey_footprints.load_map_data(TEST_MAP_PATH) for column in map_data_table.columns: map_data = map_data = getattr(map_data_table, column.name) print(column.name, map_data.min(), map_data.max())
def test_NObsPriority(): runName = os.path.split(TEST_DB_PATH)[-1].replace('.db', '') opsim_db = maf.OpsimDatabase(TEST_DB_PATH) map_data_table = compare_survey_footprints.load_map_data(TEST_MAP_PATH) #print(map_data_table.columns) mapName = 'combined_map' tau_obs = 20.0 log = open('./results/test_data.log', 'w') nLoop = 10 for i in range(0, nLoop, 1): log.write('mapName: ' + mapName + '\n') log.write('runName: ' + runName + '\n') log.write('tau_obs: ' + str(tau_obs) + '\n') FoM = compare_survey_footprints.FiguresOfMerit() bundleDict = compare_survey_footprints.calcNVisits( opsim_db, runName, mapName) rootName = 'GalplaneFootprintMetric_' + mapName + '_' #outputName = rootName+'NObsPriority' outputName = rootName + 'Tau_' + str(tau_obs).replace('.', '_') log.write('OutputName: ' + outputName + '\n') metricData = bundleDict[outputName].metricValues log.write('metricData: ' + repr(metricData) + '\n') rubin_visibility_zone = compare_survey_footprints.calc_rubin_visibility( bundleDict, runName) log.write('rubin_visibility_zone: ' + repr(rubin_visibility_zone) + '\n') map_data = getattr(map_data_table, mapName) log.write('map_data: ' + repr(map_data) + '\n') desired_healpix = compare_survey_footprints.calc_desired_survey_map( mapName, map_data, rubin_visibility_zone) log.write('N survey pixels: ' + str(len(desired_healpix)) + '\n') #log.write('Desired survey pixels: '+repr(desired_healpix)+'\n') FoM = compare_survey_footprints.calcFootprintOverlap( runName, mapName, tau_obs, desired_healpix, bundleDict, FoM) log.write('Overlap pixels: ' + str(FoM.overlap_healpix) + '\n') log.write('Overlap percent: ' + str(FoM.overlap_percent) + '\n') log.write('Missing pixels: ' + str(FoM.missing_healpix) + '\n') log.write('Missing percent: ' + str(FoM.missing_percent) + '\n') idx = np.argwhere(np.isnan(metricData)) log.write('NaN values: ' + repr(idx) + '\n') log.write('metricData entries: ' + repr(metricData[idx]) + '\n') log.write('Metric sum values: ' + repr(metricData.sum()) + '\n') log.write('-------------------------------------------\n') log.close()
def time_per_filter(): params = get_args() # Load the current OpSim database runName = os.path.split(params['opSim_db_file'])[-1].replace('.db', '') opsim_db = maf.OpsimDatabase(params['opSim_db_file']) # Load the Galactic Plane Survey footprint map data map_data_table = compare_survey_footprints.load_map_data( params['map_file_path']) print('Total number of pixels in map: ' + str(len(map_data_table))) # Start logfile logfile = open( os.path.join(output_dir, runName + '_time_per_filter_metric_data.txt'), 'w') logfile.write( 'runName mapName filter mean(fexpt_ratio) stddev(fexpt_ratio) npix_obs %desired_pixels\n' ) # Loop over all science maps: for mapName in SCIENCE_MAPS: map_data = getattr(map_data_table, mapName) # Compute metrics bundleDict = calc_filter_metric(opsim_db, runName, mapName) print(bundleDict.keys()) # Calculate the Rubin visibility zone: rubin_visibility_zone = compare_survey_footprints.calc_rubin_visibility( bundleDict, runName) # Determine the HEALpix index of the desired science survey region, # taking the Rubin visbility zone into account: desired_healpix = compare_survey_footprints.calc_desired_survey_map( mapName, map_data, rubin_visibility_zone) eval_filters_by_region(params, bundleDict, runName, mapName, map_data, desired_healpix) logfile.close()
def eval_nobs_priority_function(): params = get_args() # Load the current OpSim database runName = os.path.split(params['opSim_db_file'])[-1].replace('.db', '') opsim_db = maf.OpsimDatabase(params['opSim_db_file']) # Load the Galactic Plane Survey footprint map data map_data_table = compare_survey_footprints.load_map_data( params['map_file_path']) mapName = 'combined_map' map_data = getattr(map_data_table, mapName) # Compute metric data: bundleDict = calcMetrics(opsim_db, runName, mapName) # Plot the number of visits per HEALpixel as a function of space and # scientific priority: plot_3d_healpix_nvis_priority(runName, bundleDict, map_data)
def test_metric_calculation(): runName = os.path.split(TEST_DB_PATH)[-1].replace('.db', '') opsim_db = maf.OpsimDatabase(TEST_DB_PATH) map_data_table = compare_survey_footprints.load_map_data(TEST_MAP_PATH) #print(map_data_table.columns) mapName = 'combined_map' tau_obs = 11.0 tau_var = tau_obs * 5.0 log = open('./cadence_results/test_data.log', 'w') nLoop = 10 for i in range(0, nLoop, 1): log.write('mapName: ' + mapName + '\n') log.write('runName: ' + runName + '\n') log.write('tau_obs: ' + str(tau_obs) + '\n') FoM = eval_survey_cadence.TimeFiguresOfMerit() bundleDict = eval_survey_cadence.calc_cadence_metrics( opsim_db, runName, mapName) outputName1 = 'GalPlaneVisitIntervalsTimescales_' + mapName + '_Tau_' + str( tau_obs).replace('.', '_') outputName2 = 'GalPlaneSeasonGapsTimescales_' + mapName + '_Tau_' + str( tau_var).replace('.', '_') metric1_data = bundleDict[outputName1].metricValues metric2_data = bundleDict[outputName2].metricValues np.savetxt( os.path.join('./cadence_results/', outputName1 + '_run' + str(i) + '.txt'), metric1_data) np.savetxt( os.path.join('./cadence_results/', outputName2 + '_run' + str(i) + '.txt'), metric2_data) log.write('OutputName: ' + outputName1 + '\n') log.write('OutputName: ' + outputName2 + '\n') log.write('metricData 1: ' + repr(metric1_data) + '\n') log.write('metricData 2: ' + repr(metric2_data) + '\n') rubin_visibility_zone = compare_survey_footprints.calc_rubin_visibility( bundleDict, runName) log.write('rubin_visibility_zone: ' + repr(rubin_visibility_zone) + '\n') log.write('Npix rubin_visibility_zone: ' + str(len(rubin_visibility_zone)) + '\n') map_data = getattr(map_data_table, mapName) log.write('map_data: ' + repr(map_data) + '\n') log.write('Npix map_data: ' + str(len(map_data)) + '\n') desired_healpix = compare_survey_footprints.calc_desired_survey_map( mapName, map_data, rubin_visibility_zone) log.write('N survey pixels: ' + str(len(desired_healpix)) + '\n') log.write('Desired survey pixels: ' + repr(desired_healpix[0:10]) + '\n') FoM = eval_survey_cadence.eval_metrics_by_region(bundleDict, map_data, runName, mapName, tau_obs, rubin_visibility_zone, desired_healpix, datalog=log) log.write('VIM: ' + str(FoM.sumVIM) + '\n') log.write('Percent VIM: ' + str(FoM.percent_sumVIM) + '\n') log.write('SVGM: ' + str(FoM.sumSVGM) + '\n') log.write('Percent SVGM: ' + str(FoM.percent_sumSVGM) + '\n') log.write('VIP: ' + str(FoM.sumVIP) + '\n') log.write('Percent VIP: ' + str(FoM.percent_sumVIP) + '\n') idx = np.argwhere(np.isnan(metric1_data)) log.write('NaN values metric 1: ' + repr(idx) + '\n') log.write('metricData entries: ' + repr(metric1_data[idx]) + '\n') log.write('Metric sum values: ' + repr(metric1_data.sum()) + '\n') log.write('-------------------------------------------\n') log.close()