示例#1
0
def showimgfn(dir, objname):
    fnlist = []
    fns = os.listdir(dir)
    fns.sort()
    for fn in fns:
        fn_path = os.path.abspath('./%s/%s' % (dir, fn))
        if not os.path.isfile(fn_path):
            sys.stderr.write('%s not file Error\n' % fn_path)
            continue
#        print(fn_path)
        try:
            ftsimg = sfts.SacraFits(fn_path, updatemode=False)
        except:
            #            sys.stderr.write('Error2\n')
            continue
        try:
            objname_header = ftsimg.getHeaderValue('OBJNAME')
        except:
            #            sys.stderr.write('Error\n')
            continue


#        print(objname_header)
        if objname_header == objname:
            fnlist.append(fn_path)
        ftsimg.close()
    printfnlist(fnlist)
示例#2
0
# main routine

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: %s Object_Name" % (sys.argv[0]))
        exit(1)

    obj_aim = sys.argv[1]

    if os.path.exists(TempDir):
        if not os.path.isdir(TempDir):
            print("%s is not directory." % TempDir)
            exit(1)
    else:
        os.mkdir(TempDir)

    fitslist = glob.glob('*.fits')

    for fn in fitslist:
        if not os.path.isfile(fn):
            next
        try:
            ftsf = sf.SacraFits(fn)
            objname = ftsf.getHeaderValue('OBJECT')
        except:
            sys.stderr.write('astropy.fits error. Skip.\n')
            next
        if objname != obj_aim:
            os.rename(fn, './%s/%s' % (TempDir, fn))
            print('%s: mv %s -> ./%s/' % (objname, fn, TempDir))
示例#3
0
#     Ver 1.2  2018/05/24  H. Akitaya
#     Ver 1.3  2018/08/01  H. Akitaya
#     Ver 2.0  2018/08/28  H. Akitaya; change fits files
#     Ver 2.1  2018/08/28  H. Akitaya; error treatment for broken fits file
#     Ver 2.2  2018/11/09  H. AKitaya; declare to use python3
#

import sys
import sacrafits as sfts

# main routine
    
if __name__ == '__main__':
    for fn in sys.argv[1:]:
        try:
            ftsf=sfts.SacraFits(fn)
        except:
            sys.stderr.write('%s open error. Skip.\n' % (fn))
            continue

        try:
            ftsf.setMJDfromOBSTIME()
            ftsf.setOBJECTfromOBJNAME()
            ftsf.setAIRMASSfromZD()
            ftsf.addHistory("Modified by %s" % (sys.argv[0] ))
            ftsf.modifyExptimeToSec()
            ftsf.setDummyHeaderForHonirred()
        
            ftsf.showAllHeaders()
            ftsf.updateFitsFile()
        except:
示例#4
0
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()
示例#5
0
#  modify FILTER header value from NONE to r
#    (for MuSaSHI r-band arm)
#
#      usage: filter_none2r.py r*.fits
#
#    Ver  1.0  2018/03/21  H. Akitaya
#    Ver  2.0  2018/08/28  H. Akitaya; change import style
#

import os, sys
import sacrafits as sfts

if __name__ == '__main__':
    if len(sys.argv) == 1:
        exit
    fnin = sys.argv
    del fnin[0]
    for fn in fnin:
        name, ext = os.path.splitext(fn)
        if ext != ".fits":
            continue
        ftsimg = sfts.SacraFits(fn)
        fltr = ftsimg.getHeaderValue('FILTER')
        #        print fltr
        if fltr == 'NONE':
            ftsimg.setHeaderValue('FILTER', 'r', 'filtername')
            print('%s FILTER header NONE -> r\n' % fn)
            ftsimg.addHistory('%s FILTER header NONE -> r' % fn)
            ftsimg.updateFitsFile()
        ftsimg.close()