out_norej_fn = '%s_%s_rejcomb.fits' % (objname, band) for fn in [out_rej_fn, out_norej_fn]: if os.path.isfile(fn): print("File %s exists." % (fn)) if args.override == True: os.remove(fn) print("File %s removed." % (fn)) else: print('Skip.') fi = sf.FitsInfo(objname=objname, exptime=exptime, band=band, datatype=DT_OBJ) sfl = sf.SacraFile() print('Construction file list...') fnlst = sfl.getFnList('./', fi, subext=args.sub_extention) print('Measuring sky level...') skyarea = sf.StatArea fnlst_tmp = fnlst for fn in fnlst_tmp: result = sfl.imgAddHeaderSkyLevelEstimate(fn, skyarea) if result != 0: fnlst.remove(fn) # remove image with sky estimate error print('Combining...') try: sfl.imgCombine(fnlst, out_rej_fn,
#!/usr/bin/env python # # make dark file # (for FLI-CCDs) # # usage: mkdark band exptime(msec) # # Ver 1.0 2018/03/21 H. Akitaya # Ver 2.0 2018/08/28 H. Akitaya; rename package name # Ver 2.1 2018/09/18 H. Akitaya; debug for package importing # import os, sys import sacrafile as sf from scrredmisc import * if __name__ == '__main__': if len(sys.argv) < 3: exit(1) band = sys.argv[1] try: exptime = float(sys.argv[2]) except: sys.stderr.write("Wrong exposure time") exit(1) #main sfdk = sf.SacraFile(DT_DARK) sfdk.mkDark(band, exptime)
def main(): parser = argparse.ArgumentParser( description='Image shift and combine for MuSaSHI images.') parser.add_argument('--reject-imcomb', help='Imcomb rejection', action='store_true') parser.add_argument('--skip-imshift', help='skip imshift', action='store_true') parser.add_argument('sysargs', metavar='Sysargs', type=str, nargs='+',\ help='usual option') args = parser.parse_args() # print(args.skip_imshift) # exit(1) sfobj = sf.SacraFile(DT_OBJ) try: objname = str(args.sysargs[0]) band = str(args.sysargs[1]) # xy_init = sf.ImgCoord(float(sys.argv[3]), float(sys.argv[4])) # cbox = float(sys.argv[5]) fn_coord = str(args.sysargs[2]) fn_final = str(args.sysargs[3]) fn_pattern = re.compile(args.sysargs[4]) # fn_final = str(sys.argv[6]) # fn_pattern = re.compile(sys.argv[7]) except: exit(1) ftsinf = FitsInfo(objname=objname, band=band, datatype=DT_OBJ) sfobj.setFnPattern(fn_pattern) fnlst = sfobj.getFnList(".", ftsinf) fnlst.sort() # exit(1) # print fnlst # print len(fnlst) if args.skip_imshift: print("Imshift skipping") try: nimg = 0 nimg_rej = 0 exptime_total = 0.0 mjd_ave_tmp = 0.0 fnlist = [] fn0 = "" for fn in fnlst: if not fn_pattern.match(fn): continue # xy = sfobj.getCentroid(fn, xy_init, cbox) if fn0 == "": fn0 = fn fn_out = sfobj.getFnWithSubExtention(fn, SubExt) if not args.skip_imshift: try: csresult = sfobj.getCentroidShift(fn, fn_coord, fn0) dxdy_list = sfobj.analyseImcentroidShift( csresult, 'median') except: print('#%s : imcontroid error. Skip.' % fn) continue #dxdy = xy.calcShift(xy_init, signplus=False) dxdy = sf.ImgCoord(dxdy_list[0], dxdy_list[1]) # dxdy.show() if os.path.exists(fn_out): print("File %s exists. Skip." % fn_out) else: sfobj.imgShift(fn, fn_out, dxdy) else: if not os.path.exists(fn_out): print("File %s not found. Skip." % fn_out) continue # SCRFVMRK Header (for rejection) check sfts = sfts.SacraFits(fn) if sfts.hasHeader('SCRFVMRK'): if sfts.getHeaderValue('SCRFVMRK') == 'true': print("%s marked as SCRFVMRK=false. Skip.", fn) nimg_rej += 1 continue # read fits header (exptime, mjd) exptime = float(sfts.getHeaderValue("EXPTIME")) / 1000.0 mjd = float(sfts.getHeaderValue("MJD")) mjd_ave_tmp += (mjd + exptime / 24.0 / 60.0 / 60.0) exptime_total += exptime fnlist.append(fn_out) sfts.close() nimg += 1 except KeyboardInterrupt: sys.stderr.write("Break.") exit(1) mjd_ave = mjd_ave_tmp / nimg # combine tl_f = sf.writeLstToTmpf(fnlist) # print fnlst try: print "Combined file: %s" % fn_final print "List file: %s" % tl_f.name shutil.copyfile(tl_f.name, "tmppy.lst") if args.reject_imcomb: iraf.imcombine("@%s" % (tl_f.name), "%s" % (fn_final), \ combine="average", reject="avsigclip", \ mclip='yes', lsigma=5.0, hsigma=5.0 ) else: iraf.imcombine("@%s" % (tl_f.name), "%s" % (fn_final), \ combine="average", reject="none" ) print("Combined: %d, Rejected: %d" % (nimg, nimg_rej)) except: sys.stderr.write("Imcombine Error(%s).\n" % fn_final) exit(1) finally: tl_f.close() rslt = sfts.SacraFits(fn_final) rslt.setHeaderValue("MJD_AVE", mjd_ave, "Average MJD for combined images.") rslt.setHeaderValue("EXPTIMET", exptime_total, "Total exposure time (s).") rslt.setHeaderValue("NCOMB", nimg, "Number of combined images.") rslt.addHistory("Processed by imgshiftcomb.py") rslt.close()
if __name__ == "__main__": def usage(): print("Usage: preproc.py object_name filter [exp_time (optional)]") if len(sys.argv) < 3: usage() exit(1) if len(sys.argv) == 4: exptime = float(sys.argv[3]) else: exptime = 5.0 objname = sys.argv[1] band = sys.argv[2] sf1 = sf.SacraFile(DT_DARK) # print exptime sf1.mkDark(band, exptime, overwrite=False) sf1.mkDark(band, 5.0, overwrite=False) sf2 = sf.SacraFile(DT_FLAT) # band="i" exptime_flat = 5.0 sf2.mkFlat(band, exptime_flat, MOD_MIMG, overwrite=False) sf3 = sf.SacraFile(DT_OBJ) if band == 'z': sf3.objDsubFlatten(objname, band, MOD_MIMG, flip=True) else: sf3.objDsubFlatten(objname, band, MOD_MIMG)
#!/usr/bin/env python # # make flat file # (for FLI-CCDs) # # usage: mkflat band exptime(msec) # # Ver 1.0 2018/03/22 H. Akitaya # Ver 1.1 2018/08/21 H. Akitaya # Ver 2.0 2018/08/28 H. Akitaya; rename reference package # import os, sys import sacrafile as sf from scrredmisc import * MKFLAT_MODE = MOD_MIMG if __name__ == '__main__': mode = MOD_MIMG if len(sys.argv) < 3: exit(1) band = sys.argv[1] try: exptime = float(sys.argv[2]) except: sys.stderr.write("Wrong exposure time") exit(1) #main sffl = sf.SacraFile(DT_FLAT) sffl.mkFlat(band, exptime, MKFLAT_MODE)