def build_from_ddosa_res(cls,
                             name,
                             file_name,
                             res,
                             src_name='ciccio',
                             prod_prefix=None,
                             out_dir=None):

        #hdu_list = pf.open(res.lightcurve)
        hdu_list = FitsFile(res.lightcurve).open()
        data = None
        header = None

        for hdu in hdu_list:
            if hdu.name == 'ISGR-SRC.-LCR':
                print('name', hdu.header['NAME'])
                if hdu.header['NAME'] == src_name:
                    data = hdu.data
                    header = hdu.header

            lc = cls(name=name,
                     data=data,
                     header=header,
                     file_name=file_name,
                     out_dir=out_dir,
                     prod_prefix=prod_prefix,
                     src_name=src_name)

        return lc
Exemple #2
0
    def build_list_from_ddosa_res(cls, res, prod_prefix=None, out_dir=None):

        data = None
        header = None

        spec_list = []

        if out_dir is None:
            out_dir = './'
        for source_name, spec_attr, rmf_attr, arf_attr in res.extracted_sources:

            print('spec file-->', getattr(res, spec_attr), spec_attr)
            print('arf file-->', getattr(res, arf_attr), arf_attr)
            print('rmf file-->', getattr(res, rmf_attr), rmf_attr)

            #spectrum = pf.open(getattr(res, spec_attr))[1]
            spectrum = FitsFile(getattr(res, spec_attr)).open()[1]

            arf_filename = getattr(res, arf_attr)
            rmf_filename = getattr(res, rmf_attr)

            data = spectrum.data
            header = spectrum.header

            file_name = prod_prefix + '_' + Path(getattr(
                res, spec_attr)).resolve().stem

            print('out spec file_name', file_name)

            out_arf_file = prod_prefix + '_' + Path(getattr(res,
                                                            arf_attr)).name
            out_arf_file = FilePath(file_dir=out_dir,
                                    file_name=out_arf_file).path
            print('out arf file_path', out_arf_file)

            out_rmf_file = prod_prefix + '_' + Path(
                out_dir, getattr(res, rmf_attr)).name
            out_rmf_file = FilePath(file_dir=out_dir,
                                    file_name=out_rmf_file).path
            print('out rmf file_path', out_rmf_file)

            name = source_name

            spec = cls(name=name,
                       file_name=file_name,
                       data=data,
                       header=header,
                       rmf_file=rmf_filename,
                       arf_file=arf_filename,
                       out_dir=out_dir)

            spec.set_arf_file(arf_kw='ANCRFILE', out_arf_file=out_arf_file)
            spec.set_rmf_file(rmf_kw='RESPFILE', out_rmf_file=out_rmf_file)
            spec_list.append(spec)

        return spec_list
Exemple #3
0
 def build_from_ddosa_skyima(cls,
                             name,
                             file_name,
                             skyima,
                             out_dir=None,
                             prod_prefix=None):
     skyima = FitsFile(skyima).open()
     return cls(name,
                skyima=skyima[4],
                out_dir=out_dir,
                prod_prefix=prod_prefix,
                file_name=file_name)
 def build_from_ddosa_srclres(cls, srclres,prod_prefix=None):
     #catalog = pf.open(srclres)[1]
     catalog = FitsFile(srclres).open()[1]
     print ('cat file',srclres)
     frame = catalog.header['RADECSYS'].lower()
     catalog=catalog.data
     return cls( [n.strip() for n in catalog['NAME']],
                 catalog['RA_OBJ'],
                 catalog['DEC_OBJ'],
                 significance=catalog['DETSIG'],
                 frame=frame,
                 #NEW_SOURCE=catalog['NEW_SOURCE'],
                 #ISGRI_FLAG=catalog['ISGRI_FLAG'],
                 FLAG=catalog['FLAG'],
                 ERR_RAD=catalog['ERR_RAD'] )
Exemple #5
0
    def get_dummy_products(self, instrument, config, out_dir='./'):

        if out_dir is None:
            out_dir = './'
        import glob, os
        print('config.dummy_cache', config.dummy_cache)
        print('out_dir', out_dir)
        spec_files = glob.glob(config.dummy_cache +
                               '/query_spectrum_isgri_sum*.fits')

        print(spec_files)
        spec_list = []
        for spec_file in spec_files:
            src_name = os.path.basename(spec_file)
            src_name = src_name.replace('query_spectrum_isgri_sum_', '')
            src_name = src_name.replace('.fits', '')
            print('->', src_name)
            arf_file = glob.glob(config.dummy_cache +
                                 '/query_spectrum_arf_sum*%s*.fits.gz' %
                                 src_name)[0]
            rmf_file = glob.glob(config.dummy_cache +
                                 '/query_spectrum_rmf_sum*%s*.fits.gz' %
                                 src_name)[0]
            print('spec file-->', spec_file)
            print('arf file-->', arf_file)
            print('rmf file-->', rmf_file)
            #spectrum = pf.open(spec_file)[1]

            spectrum = FitsFile(spec_file).open()[1]

            arf_filename = arf_file
            rmf_filename = rmf_file

            data = spectrum.data
            header = spectrum.header

            file_name = Path(spec_file).name

            print('out spec file_name', file_name)
            out_arf_file = Path(arf_filename).name
            out_arf_file = str(Path(out_dir, out_arf_file))
            print('out arf file_name', out_arf_file)
            out_rmf_file = Path(rmf_filename).name
            out_rmf_file = str(Path(out_dir, out_rmf_file)).strip()
            print('out rmf file_name', out_rmf_file)

            name = header['NAME']

            spec = IsgriSpectrumProduct(name=name,
                                        file_name=file_name,
                                        data=data,
                                        header=header,
                                        rmf_file=rmf_filename,
                                        arf_file=arf_filename,
                                        out_dir=out_dir)
            spec.set_arf_file(arf_kw='ANCRFILE',
                              out_arf_file=out_arf_file.strip())
            spec.set_rmf_file(rmf_kw='RESPFILE',
                              out_rmf_file=out_rmf_file.strip())
            spec_list.append(spec)

        prod_list = QueryProductList(prod_list=spec_list)

        return prod_list