#!/usr/bin/env python """ НАЗВАНИЕ: 05_srctool.py НАЗНАЧЕНИЕ: Запускает scrtool для самого широкого канала 0.2-10 кэВ, чтобы спектры имели самое полное покрытие по энергиям. Список источников берется из 0.3-2.3 кэВ. ВЫЗОВ: esass ./05_srctool.py УПРАВЛЕНИЕ: Требуется запуск предыдущего скрипта 04_mosaics.py ПАРАМЕТРЫ: index=4 : Выбранный энергетический диапазон ВЫВОД: Выходные файлы записываются в директорию outfile_dir/srctool_dir ИСТОРИЯ: Роман Кривонос, ИКИ РАН, krivonos@cosmos.ru Март 2023 """ from astropy.wcs import WCS from astropy.io import fits import sys, os, os.path, time, subprocess from pathlib import Path import numpy as np import glob from os.path import dirname import inspect import pickle import coma from coma.utils import * from coma.config import * #from coma.sherpa import * """ find UDS root dir """ #root_path=dirname(dirname(dirname(inspect.getfile(uds)))) """ ftools does not like long file path names, for this reason, we use relative path here """ root_path='..' print("Coma root path: {}".format(root_path)) infile_dir=root_path+'/data/processed' outfile_dir=root_path+'/products' create_folder(outfile_dir) srctool_dir="{}/{}".format(outfile_dir,"srctool-products-joint") create_folder(srctool_dir) outkey="mosa_joint_tm0_attcorr" outfile_srctool="{}_SrcTool_".format(outkey) do_srctool = False do_grppha = False do_catalog = False do_extended = False do_ds9reg = False do_coma_final = False do_euds_dr12 = False # crossmatch eUDS with DR12 do_euds_stat = False do_euds_cds = False do_xmm_catalog = False do_xmm_final = False do_xmm_xmatch = False do_xmm_ds9reg = False do_xmm_cds = False do_euds_cosmatch = False do_cross_check = False # Check whether all E3,E6 sources are detected in E0 index=5 """ чтобы спектры покрывали все энергии работаем в диапазоне 5 """ vign=True vignetting = 'vign' if (vign==True) else 'novign' events=[] expmaps=[] bkgmaps=[] """ Собираем общий список событий """ outfile_evtool="{}_EventList_en{:02d}.fits".format(os.path.join(outfile_dir,outkey), eband[index]) outfile_expmap="{}_ExposureMap_en{:02d}.fits".format(os.path.join(outfile_dir,outkey), eband[index]) suffix_srctool=".fits" """ Output filename suffix - all output filenames appended with this string. If suffix contains no filename extension (does not contain a "."), then ".fits" is also appended to the filename. """ catprep="{}_SourceCatalog_en{:02d}{}".format(os.path.join(outfile_dir,outkey), eband[0], outfile_post) """ take source catalog from 0.3-2.3 keV band """ if not (os.path.isfile(catprep)==True): print("{} not found, run 04_mosaics.py?".format(catprep)) sys.exit() if(do_srctool==True): test_exe('srctool') cmd=['srctool', "todo=\'SPEC RMF ARF\'", "insts=\'1 2 3 4 5 6 7\'", "eventfiles={}".format(outfile_evtool), "prefix=\'{}\'".format(os.path.join(srctool_dir,outfile_srctool)), "suffix=\'{}\'".format(suffix_srctool), "srccoord={}".format("../products/eUDS_for_srctool_test.fits"), # the same as original file eUDS.fits, but changed ML_CTS --> ML_CTS_0, ML_BKG --> ML_BKG_0, ML_EXP --> ML_EXP_0 #"srcreg=\'fk5;circle * * 60s\'", #"backreg=\'fk5;annulus * * 90s 120s\'", "srcreg=AUTO", "backreg=AUTO", "clobber=yes",] #print((" ").join(cmd)) #os.system((" ").join(cmd)) #print((" ").join(cmd)) runme(cmd, local_run=True) if(do_grppha==True): group_spectra("{}/*020_SourceSpec_*.fits".format(srctool_dir)) index=0 catprep="{}_SourceCatalog_en{:02d}{}".format(os.path.join(outfile_dir,outkey), eband[index], outfile_post) rawcat="{}_SourceCatalog_en{:02d}.dl10.pickle".format(os.path.join(outfile_dir,outkey), eband[index]) if(do_catalog==True): """ forced_xmm_sources="{}_MaxLikSourceList_en{:02d}.xmm.pickle".format(os.path.join(outfile_dir,outkey), eband[index]) with open(forced_xmm_sources, 'rb') as f: print("Reading forced XMM sources from {}".format(forced_xmm_sources)) srcs_forced = pickle.load(f) print() print(srcs_forced) print() """ make_coma_catalog(infile='../products/mosa_joint_tm0_attcorr_SourceCatalog_en00.forced.fits', rawcat=rawcat, dlmin=10.0, dlmax=10000000, ext_like=1000, emin=emin_kev[index], emax=emax_kev[index], eband=eband[index], infile_en00cat=catprep, infile_en01cat='../products/mosa_joint_tm0_attcorr_SourceCatalog_en01.forced.fits', infile_en02cat='../products/mosa_joint_tm0_attcorr_SourceCatalog_en02.forced.fits', infile_en03cat='../products/mosa_joint_tm0_attcorr_SourceCatalog_en03.forced.fits', infile_en04cat='../products/mosa_joint_tm0_attcorr_SourceCatalog_en04.forced.fits', infile_en00sens='../products/mosa_joint_tm0_attcorr_SensitivityMap_nearest_dl10_en00.fits', infile_en01sens='../products/mosa_joint_tm0_attcorr_SensitivityMap_nearest_dl10_en01.fits', infile_en02sens='../products/mosa_joint_tm0_attcorr_SensitivityMap_nearest_dl10_en02.fits', infile_en03sens='../products/mosa_joint_tm0_attcorr_SensitivityMap_nearest_dl10_en03.fits', infile_en04sens='../products/mosa_joint_tm0_attcorr_SensitivityMap_nearest_dl10_en04.fits', #srcs_forced=srcs_forced, ) if(do_extended==True): make_extended(infile=rawcat,outreg="{}_ExtendedCat_en{:02d}.reg".format(os.path.join(outfile_dir,outkey), eband[index])) if(do_ds9reg==True): #make_final_ds9reg(infile=rawcat,outreg="{}_FinalCat_dl10.reg".format(os.path.join(outfile_dir,outkey))) make_final_ds9reg(infile=rawcat,scale=(60*60)/10,outreg="{}_FinalCat_dl10_talk.reg".format(os.path.join(outfile_dir,outkey))) make_final_ds9reg(infile=rawcat,scale=(60*60)/10,noname=True,outreg="{}_FinalCat_dl10_noname.reg".format(os.path.join(outfile_dir,outkey))) if(do_coma_final==True): """ make final Coma catalog """ final_coma_catalog(infile=rawcat, outfile_fits='../products/eCFDS.fits') if(do_euds_dr12==True): crossmatch_dr12('../products/eUDS.fits', catalog=root_path+"/data/4XMM-DR12/4XMM_DR12cat_slim_v1.0_UDS.fits.catalog", devmax=15) if(do_euds_stat==True): make_euds_stat(infile="../products/eUDS.fits",fluxlim=5e-14) if(do_euds_cds==True): make_euds_cds(infile="../products/eUDS.fits",outfile='../products/eUDS.cds') if(do_cross_check==True): """ cross check final eUDS catalog """ cross_check_euds(infile=catprep, euds='../products/eUDS.fits', outkey="../products/en{:02d}_FinalCat_dl10".format(index)) if(do_xmm_catalog==True): """ complile raw forced XMM catalog """ make_xmm_catalog(infile_en00cat='../products/tm0_SourceCatalog_en0.forced-xmm.fits', infile_en01cat='../products/tm0_SourceCatalog_en1.forced-xmm.fits', infile_en02cat='../products/tm0_SourceCatalog_en2.forced-xmm.fits', infile_en03cat='../products/tm0_SourceCatalog_en3.forced-xmm.fits', infile_en06cat='../products/tm0_SourceCatalog_en6.forced-xmm.fits', forced_xmm_sources='../products/tm0_MaxLikSourceList_en0.fixed-xmm.pickle', outfile='../products/tm0_4XMM-DR12.pickle') if(do_xmm_final==True): """ make final XMM-forced catalog """ final_xmm_catalog(infile='../products/tm0_4XMM-DR12.pickle', outfile_fits='../products/eUDS_4XMM-DR12.fits') if(do_xmm_xmatch==True): """ cross-match XMM-forced catalog outfile_cvs contains 0.3-2.3 keV eUDS flux (col1=flux,col2=err) vs. 4XMM-DR12 flux (col3=flux, col4=err) XMM flux was converted from 0.2-2.0 keV to 0.3-2.3 keV using wabs*powerlow with wabs=0.02 gamma=2.0 """ final_xmm_xmatch(infile='../products/eUDS_4XMM-DR12.fits', xmmslim='../data/4XMM-DR12/4XMM_DR12cat_slim_v1.0_UDS.fits.catalog', xmmfull='../data/4XMM-DR12/4XMM_DR12cat_v1.0_UDS.fits.catalog', xmmlim=2e-14, outfile_flux="../products/eUDS_4XMM-DR12.flux.csv") if(do_xmm_ds9reg==True): """ show XMM-forced catalog """ make_xmm_ds9reg_confused(infile='../products/eUDS_4XMM-DR12.fits', outfile='../products/eUDS_4XMM-DR12.confused.reg') """ obsolete """ if(do_xmm_cds==True): make_xmm_cds(infile="../products/eUDS_4XMM-DR12.fits", outfile='../products/eUDS_4XMM-DR12.cds') if(do_euds_cosmatch==True): """ prepare eUDS catalog for CosMatch (Mescheryakov) """ make_euds_cosmatch(infile='../products/eUDS.fits', outfile='../products/eUDS-CosMatch.fits')