Esempio n. 1
0
    def attach_ds(self, fn, serial=0):
        DS = self.get_file_DS(fn)
        f_ds = pyfits.open(fn)
        f_ds.writeto(self.DS_to_fn(DS, serial), clobber=True)

        da = pilton.heatool("dal_attach")
        da['Parent'] = self.DS_to_idx_fn(DS)
        da['Child1'] = self.DS_to_fn(DS, serial)
        da.run()

        f_idx = pyfits.open(da['Parent'].value)

        f_ds[1].header['VSTOP'] = 99999

        for k in ['VERSION', 'VSTART', 'VSTOP']:
            f_idx[1].data[-1][k] = f_ds[1].header[k]
            logging.info("%s %s %s", k, f_idx[1].data[-1][k],
                         f_ds[1].header[k])

        f_idx.writeto(da['Parent'].value, clobber=True)

        dv = pilton.heatool("dal_verify")
        dv["indol"] = self.DS_to_idx_fn(DS)
        dv['checksums'] = "yes"
        dv['backpointers'] = "yes"
        dv['detachother'] = "yes"
        dv.run()
Esempio n. 2
0
    def main(self):
        new_e = fits.open(self.input_ebins.ebds_mod_fn)[1]
        new_bins = zip(new_e.data['E_MIN'], new_e.data['E_MAX'])
        print("new bins:", new_bins)

        orig_e = fits.open(self.input_ic_ebds.member_location)[1]
        orig_bins = zip(orig_e.data['E_MIN'], orig_e.data['E_MAX'])
        print("original bins", orig_bins)

        print("original rmf", self.input_rsp.rmf_path)

        rmf_e = fits.open(self.input_rsp.rmf_path)[1]

        orig_rsp_fn = "original_rsp_assembled.fits"
        fits.HDUList([fits.PrimaryHDU(), orig_e,
                      rmf_e]).writeto(orig_rsp_fn, overwrite=True)

        ebins_compress_fn = "ebins.txt"
        with open(ebins_compress_fn, "w") as f:
            for oi, (e1, e2) in enumerate(new_bins):
                i1 = list(orig_e.data['E_MIN']).index(e1)
                i2 = list(orig_e.data['E_MAX']).index(e2)
                print(oi, i1, i2, e1, e2)
                f.write("%i %i %i\n" % (i1, i2, i2 - i1 + 1))

        new_rsp_fn = "rsp_rebinned.fits"

        ht = pilton.heatool("rbnrmf")
        ht['infile'] = orig_rsp_fn
        ht['binfile'] = ebins_compress_fn
        ht['outfile'] = new_rsp_fn
        ht['clobber'] = "yes"
        ht.run()
        self.rmf = da.DataFile(new_rsp_fn)
Esempio n. 3
0
 def create_index_empty(self, DS):
     dc = pilton.heatool("dal_create")
     dc["obj_name"] = self.DS_to_idx_fn(DS)
     dc["template"] = DS + "-IDX.tpl"
     remove_withtemplate(dc["obj_name"].value + "(" + dc["template"].value +
                         ")")
     dc.run()
Esempio n. 4
0
    def create_index_from_list(self,
                               DS,
                               fns=None,
                               fns_list=None,
                               update=True,
                               recreate=True):
        if fns_list is None:
            if fns is None:
                raise Exception("what?")

            fns_list_handle, fns_list_fn = tempfile.mkstemp()
            logging.info("\n".join(fns))
            os.write(fns_list_handle, ("\n".join(fns) + "\n").encode())

        else:
            if fns is not None:
                raise Exception("what?")

        logging.info("files: %s", fns)

        if os.path.exists(self.DS_to_idx_fn(DS)) and recreate:
            os.remove(self.DS_to_idx_fn(DS))

        da = pilton.heatool("txt2idx")
        da['index'] = self.DS_to_idx_fn(DS)
        da['template'] = DS + "-IDX.tpl"
        da['update'] = 1 if update else 0
        da['element'] = fns_list_fn
        da.run()

        f = pyfits.open(da['index'].value)
        f[1].header['CREATOR'] = "Volodymyr Savchenko"
        f[1].header['CONFIGUR'] = "dev"
        f.writeto(da['index'].value, clobber=True)
Esempio n. 5
0
    def test_run(self):
        import pilton
        pt = pilton.heatool("converttime")
        pt['informat'] = "IJD"
        pt['intime'] = "3000"
        pt['outformat'] = "UTC"
        pt.run()

        self.assertFalse(
            re.search("2008-03-18T23:58:54.815", pt.output) is None)
Esempio n. 6
0
def converttime(informat,intime,outformat):
    ct=pilton.heatool("converttime")
    ct['informat']=informat
    ct['intime']=intime
    ct['outformat']=outformat
    ct.run()

    c=dict(re.findall("Output Time\((.*)\): (.*)",ct.output))
    if outformat=="":
        return c
    else:
        return c[outformat]
Esempio n. 7
0
def converttime_rbp(rbp_var_suffix, informat, intime, outformat):
    ct = pilton.heatool("converttime")

    ct['informat'] = informat
    ct['intime'] = intime
    ct['outformat'] = outformat

    env = copy.deepcopy(os.environ)
    env['REP_BASE_PROD'] = env['REP_BASE_PROD_' + rbp_var_suffix]

    ct.run(env=env)

    return ct.output if hasattr(ct, 'output') else None
Esempio n. 8
0
 def attach_idx_to_master(self, DS):
     da = pilton.heatool("dal_attach")
     da['Parent'] = self.icmaster + "[2]"
     da['Child1'] = self.DS_to_idx_fn(DS)
     da.run()
Esempio n. 9
0
 def test_print(self):
     import pilton
     pt = pilton.heatool("converttime")
     pilton.log(pt)