Exemple #1
0
def online_dark():
    f = open(r"/home/wangxinhua/level1/Level1rev02/json.txt", 'r')
    para = json.load(f)
    f.close()
    path = para['path']  #"/home/wangxinhua/20190518/HA"
    redrive = para['redrive']  #"/home/wangxinhua/nvst"
    dark_flag = int(para['dark_flag'])
    flat_flag = int(para['flat_flag'])
    darked_path = para['darked_path']
    datapath, flatpath, darkpath = xyy.path_paser(path)
    #path of a group of fits
    try:
        path.split(':')[1]
        path = path[2:]
    except Exception as e:
        path = path[1:]
    print(os.path.join(redrive, path, 'Dark', 'dark.fits'))
    if os.path.exists(os.path.join(redrive, path, 'Dark', 'dark.fits')):
        print('dark have been calculated,pass')
    else:
        for i in darkpath:
            darkeddata = xyy.online_mean(i)
            xyy.mkdir(os.path.join(redrive, path, 'Dark'))
            #print(os.path.join(redrive,path,'Dark'))
            xyy.writefits(os.path.join(redrive, path, 'Dark', 'dark.fits'),
                          darkeddata)
    print('Dark is over')
Exemple #2
0
def online_flat():
    f = open(r"/home/wangxinhua/level1/Level1/json.txt", 'r')
    para = json.load(f)
    f.close()
    path = para['path']  #"/home/wangxinhua/20190518/HA"
    redrive = para['redrive']  #"/home/wangxinhua/nvst"
    dark_flag = int(para['dark_flag'])
    flat_flag = int(para['flat_flag'])
    darked_path = para['darked_path']
    datapath, flatpath, darkpath = xyy.path_paser(path)
    #mean flat
    darkdata = xyy.readfits(
        os.path.join(redrive, path[1:], 'Dark', 'dark.fits'))[0]
    for i in flatpath:
        if os.path.exists(os.path.join(redrive, i[1:], 'flat.fits')):
            print('flat have been calculated')
        else:
            xyy.mkdir(os.path.join(redrive, i[1:]))
            flatdata = xyy.online_mean(i)
            xyy.writefits(os.path.join(redrive, i[1:], 'flat.fits'), flatdata)
            print(os.path.join(redrive, i[1:], 'flat.fits'))
            #(data-dark)/(flat-dark)*max(flat-dark)
            for j in datapath:
                bandoff = i.split('/')[-1]
                if bandoff in j and bandoff in i:
                    datafitspath = os.listdir(j)
                    for k in datafitspath:
                        xyy.mkdir(os.path.join(redrive, j[1:]))
                        print(os.path.join(redrive, j[1:], k))
                        data = xyy.readfits(os.path.join(j, k))[0]
                        xyy.writefits(os.path.join(redrive, j[1:],
                                                   k), (data - darkdata) /
                                      (flatdata - darkdata) *
                                      np.max(flatdata - darkdata))
                '''elif 'CENT' in j and 'CENT' in i:
                    datafitspath = os.listdir(j)
                    for k in datafitspath:
                        xyy.mkdir(os.path.join(redrive,j[1:]))
                        print(os.path.join(redrive,j[1:],k))
                        data = xyy.readfits(os.path.join(j,k))[0]
                        xyy.writefits(os.path.join(redrive,j[1:],k),(data-darkdata)/(flatdata-darkdata)*np.max(flatdata-darkdata))
                elif 'R050' in j and 'R050' in i:
                    datafitspath = os.listdir(j)
                    for k in datafitspath:
                        xyy.mkdir(os.path.join(redrive,j[1:]))
                        print(os.path.join(redrive,j[1:],k))
                        data = xyy.readfits(os.path.join(j,k))[0]
                        xyy.writefits(os.path.join(redrive,j[1:],k),(data-darkdata)/(flatdata-darkdata)*np.max(flatdata-darkdata))'''
    print('flat is over')
def online_dark(path):
    f = open(r"/home/wangxinhua/level1/Level1rev06/json.txt", 'r')
    para = json.load(f)
    f.close()
    #path = para['path']#"/home/wangxinhua/20190518/HA"

    archivedarkdir = para['archivedarkdir']

    redrive = para['redrive']  #"/home/wangxinhua/nvst"
    dark_flag = int(para['dark_flag'])

    darked_path = para['darked_path']
    datapath, flatpath, darkpath = xyy.path_paser(path)
    #path of a group of fits
    flag = 1
    try:
        os.makedirs(archivedarkdir)
    except Exception as e:
        print(e)
    today_time = time.strftime("%Y%m%d", time.localtime())
    workdir = path
    use_other_dark = 0
    t0 = 0  #count time

    while flag:
        if use_other_dark == 0 and t0 < 300:
            if darkpath != None:
                print('Using ' + darkpath[0])
                flag = 0
                operating_sys = platform.system()
                if operating_sys == 'Linux':
                    try:
                        path = path[path.index('\\') + 1:]
                    except ValueError:
                        path = path[path.index('/') + 1:]
                elif operating_sys == 'Windows':
                    path = path.split(':')[1]
                    try:
                        path = path[path.index('\\') + 1:]
                    except ValueError:
                        path = path[path.index('/') + 1:]
                print(os.path.join(redrive, path, 'Dark', 'dark.fits'))
                #decide which dark will be used    writting
                if os.path.exists(
                        os.path.join(redrive, path, 'Dark', 'dark.fits')):
                    print('dark have been calculated,pass')
                else:
                    for i in darkpath:
                        darkeddata = xyy.online_mean(i)
                        xyy.mkdir(os.path.join(redrive, path, 'Dark'))
                        #print(os.path.join(redrive,path,'Dark'))
                        xyy.writefits(
                            os.path.join(redrive, path, 'Dark', 'dark.fits'),
                            darkeddata)
                #copy dark file to a folder
                copyfile(os.path.join(redrive, path, 'Dark', 'dark.fits'),
                         archivedarkdir + '/' + today_time + 'dark.fits')
                dark_log = open(
                    r'/home/wangxinhua/Observation_log/' + today_time + '.log',
                    'a+')
                dark_log.writelines('\nused Dark:' + os.path.join(
                    redrive, path, 'Dark',
                    'dark.fits'))  #which dark file is used     writting
                dark_log.close()
            else:
                datapath, flatpath, darkpath = xyy.path_paser(path)
                flag = 1
            time.sleep(1)
            t0 += 1
        else:
            #5min have no new dark file then use the latest dark file
            #define a folder that record all dark fits
            latestdarkpath = os.listdir(archivedarkdir)[-1]
            latestdarkfile = archivedarkdir + '\\' + latestdarkpath
            dark_log = open(
                r'/home/wangxinhua/Observation_log/' + today_time + '.log',
                'w')
            dark_log.writelines(
                'used Dark:' +
                latestdarkfile)  #which dark file is used     writting
            dark_log.close()
    print('Dark is over')