#!/usr/bin/env python """Создает объедененный список событий и помещает его в uds/products Этот список событий нужен, в основном для извлечения спектров с помощью srctool """ 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 coma from coma.utils import * from coma.config import * """ find 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) do_init = True do_merge = False do_rate = False do_adapt = False # requires CIAO index=0 # select energy band width=10000 vign=True vignetting = 'vign' if (vign==True) else 'novign' outkey="mosa_all_tm0" events=[] expmaps=[] bkgmaps=[] keylist=keylist_survey for tmkey in keylist.keys(): #if not (tmkey == '2'): # continue print("TM{} in work... init events".format(tmkey)) for datakey in keylist[tmkey]: #if not ("survey" in datakey): # continue print("--> {}".format(datakey)) """ Подготавливаем списки событий индивидуальных наблюдений """ outfile_evtool,outfile_expmap=init_events(key=datakey, eband_index=eband[index], infile_dir=infile_dir, outfile_dir=outfile_dir, do_init=do_init, do_obsmode=True, # also controlled by lock file! do_center=True, # also controlled by lock file! do_evtool=True, do_expmap=False, vign=vign, ra_cen=ra_cen, de_cen=de_cen, width=width, emin_kev=emin_kev[index], emax_kev=emax_kev[index]) events.append(outfile_evtool) expmaps.append(outfile_expmap) bkgmaps.append("{}_BackMap3_en{:02d}.fits".format(os.path.join(outfile_dir,datakey), eband[0])) """ Собираем общий список событий """ 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], vignetting) outfile_bkgmap="{}_BackMap_en{:02d}.{}.fits".format(os.path.join(outfile_dir,outkey), eband[index], vignetting) if(do_merge==True): evlist="{}.evlist.txt".format(os.getpid()) f = open(evlist, "w") for s in events: f.write("{}\n".format(s)) f.close() do_evtool_esass(evlist=evlist, outfile=outfile_evtool, width=width) # old version, does not work with long list of files #do_evtool_esass(events=events, outfile=outfile_evtool) do_fimgmerge_ftools(maps=expmaps, outfile=outfile_expmap) #do_fimgmerge_ftools(maps=bkgmaps, outfile=outfile_bkgmap) if(os.path.isfile(evlist)==True): os.remove(evlist) outfile_rate="{}_RateMap_en{:02d}.{}.fits".format(os.path.join(outfile_dir,outkey), eband[index], vignetting) if(do_rate==True): make_rate_map(cntmap=outfile_evtool, expmap=outfile_expmap, outfile=outfile_rate) function='gaussian' outfile_adapt="{}_ImageAdapt_en{:02d}.{}.{}.fits".format(os.path.join(outfile_dir,outkey), eband[index], function, vignetting) if(do_adapt==True): do_adapt_ciao(infile=outfile_evtool, outfile=outfile_adapt, expmap=outfile_expmap, function=function, expcut=100)