Beispiel #1
0
    def run(self):
        try:
            #print(self.log_dir)
            f = open(self.Dir_NewFile_offband, 'a')
            f.close()
            xyy.JsonWrite(self.log_dir, 'NewFile', [self.Dir_NewFile_offband])
        except Exception as e:
            #print(e)
            xyy.JsonWrite(self.log_dir, 'NewFile', [self.Dir_NewFile_offband])
            pass

        inotify(self.NewFile, self.Dir_NewFile_offband)
Beispiel #2
0
def inotify(jsonfile):
    global today_dir, mask,workdir,wm,notifier
    jsonfile = jsonfile
    f = open(jsonfile,'r')
    paras = json.load(f)
    f.close()
    workdir = paras['workdir']#"/home/user/data/2020"
    log_dir = paras['log_dir']
    DirSaveDark = paras['DirSaveDark']
    DirSaveFlat = paras['DirSaveFlat']
    rootdir = os.path.dirname(workdir)
    xyy.JsonWrite(log_dir,'ArchiveDark',[DirSaveDark])
    xyy.JsonWrite(log_dir,'ArchiveFlat',[DirSaveFlat])
    #handler = EventHandler()
    #handler.passlogdir(log_dir)
    #wm = pyinotify.WatchManager()
    #mask = pyinotify.IN_CREATE
    #notifier = pyinotify.Notifier(wm,handler)
    #mask2 = pyinotify.IN_DELETE
    while 1:
        try:
            today = datetime.datetime.now().strftime('%Y%m%d')
            today_dir = os.path.join(workdir,today)
            #if os.path.exists(today_dir) == False:
            #    wm.add_watch(rootdir,mask2)
            #    notifier.loop()
               #else:
            if os.path.exists(today_dir) == True:
                DelayProcess(log_dir,today_dir)
                break
            '''if os.path.exists(workdir) and os.path.exists(today_dir) == False:
                print(258)
                wm.add_watch(workdir,mask)
                notifier.loop()
                break
            elif os.path.exists(today_dir):
                DelayProcess(log_dir,today_dir)
                break
            else:
                pass'''
        except Exception as e:
            pass
Beispiel #3
0
def AveDark(DirDark, DirSaveDark, DirLog):
    #1000张不分偏带
    #DirDark:Dark的路径
    #DirSaveDark:处理后Dark保存的路径
    #Dirlog:日志的路径,dark处理好后将dark的路径写入日志
    today_time = datetime.datetime.now().strftime('%Y%m%d')
    DirLog = DirLog
    DirDark = DirDark
    DirSaveDark = DirSaveDark
    while os.path.exists(os.path.join(DirSaveDark,
                                      today_time + 'dark.fits')) == False:
        number = 10
        DirLog = DirLog
        DirDark = DirDark
        DarkFits = os.listdir(DirDark)
        if len(DarkFits) >= number:
            t = 0
            DirDarkFits = []
            for i in DarkFits:
                DirDarkFits.append(os.path.join(DirDark, DarkFits[t]))
                t += 1
            data = 0
            Filter = DirDarkFits.copy()
            for i in DirDarkFits:
                if os.path.getsize(i) != 2111040:
                    Filter.remove(i)
            for i in Filter:
                data += np.array(fits.open(i)[0].data, dtype=np.float32)
            data /= len(Filter)
            try:
                os.mkdir(DirSaveDark)
            except Exception as e:
                pass
            #today_time = datetime.datetime.now().strftime('%Y%m%d')
            #today_time = '20190525'
            try:
                fits.writeto(
                    os.path.join(DirSaveDark, today_time + 'dark.fits'),
                    np.array(data))
            except Exception as e:
                pass
            print('Dark 计算完毕')
            #log = open(DirLog,'a+')
            #log.writelines('\n处理后的Dark路径:'+os.path.join(DirSaveDark,today_time+'dark.fits'))
            #log.close()
            xyy.JsonWrite(
                DirLog, 'AveDark',
                [os.path.join(DirSaveDark, today_time + 'dark.fits')])
Beispiel #4
0
def AveFlat(DirFlat, DirSaveFlat, DirLog):
    #每个偏带3000张
    #DirFlat是flat路径
    #DirSaveFlat是处理过后对应偏带的flat路径
    today_time = datetime.datetime.now().strftime('%Y%m%d')
    DirLog = DirLog
    DirFlat = DirFlat
    DirSaveFlat = DirSaveFlat
    bandoff = DirFlat.split('/')[-1]
    Sig_Flat = DirFlat.split('/')[-2]
    SaveName = os.path.join(DirSaveFlat,
                            today_time + Sig_Flat + bandoff + '.fits')
    while os.path.exists(SaveName) == False:
        #print('一次')
        try:
            os.mkdir(DirSaveFlat)
        except Exception as e:
            pass
        #today_time = datetime.datetime.now().strftime('%Y%m%d')
        #today_time = '20190525'
        #print(DirFlat)
        number = 10
        DirFlatFits = os.listdir(DirFlat)
        if len(DirFlatFits) >= number:
            #print('Flat Starting.....')
            data = 0
            Filter = DirFlatFits.copy()
            for i in DirFlatFits:
                if os.path.getsize(os.path.join(DirFlat, i)) != 2111040:
                    Filter.remove(i)
            for i in Filter:
                data += np.array(fits.open(os.path.join(DirFlat, i))[0].data,
                                 dtype=np.float32)
            data /= len(Filter)
            #today_time = datetime.datetime.now().strftime('%Y%m%d')
            #today_time = '20190518'
            try:
                fits.writeto(SaveName, np.array(data))
                #log = open(DirLog,'a+')
                #log.writelines('\n处理后的Flat路径:'+os.path.join(DirSaveFlat,today_time+'CFlat.fits'))
                #log.close()
                xyy.JsonWrite(DirLog, 'AveFlat', [SaveName])
                print('Flat计算完毕')
            except Exception as e:
                #print(e)
                pass
Beispiel #5
0
    def process_IN_CREATE(self,event):
        #print(1)
        log_dir = self.log_dir
        path = event.pathname#workdir/20201315/
        #today_time = re.findall(r'\d{8}', path)[0]
        today_time = datetime.datetime.now().strftime('%Y%m%d')
        try:
            os.mkdir(log_dir)
        except Exception as e:
            print('Warning '+log_dir+' existed')
        Now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        
        xyy.JsonWrite(log_dir,'BeginTime',[Now_time])
        xyy.JsonWrite(log_dir,'Root',[path])
        DarkoffNew = []
        FlatoffNew = []
        ActiveRegNew = []
        BandoffNew=[]
        while True:
            try:
		#5/4改  
                dir0 = os.listdir(path)[0]
                #dir1 = re.findall(r'\d+[^FLAT00]\d+',str(os.listdir(os.path.join(path,dir0))))[0]#1274
                Imgs = os.listdir(os.path.join(path,dir0))#Imgs:Dark、ActiveRegion、Flat
                #解析dark
                Dark = re.findall(r'[D][a][r][k]',str(Imgs),re.IGNORECASE)#Dark
                #解析flat
                Flat = re.findall(r'[F][L][A][T]\d+',str(Imgs),re.IGNORECASE)#FLAT00,FLAT01
                [Imgs.remove(i) for i in Dark]
                [Imgs.remove(i) for i in Flat]
                
                ActiveReg = Imgs#Disk_centrt,01254
                #print(Dark)
                #print(Flat)
                #print(ActiveReg)
                Darkoff = []
                for i in range(len(Dark)):
                    dark2 = os.listdir(os.path.join(path,dir0,Dark[i]))#001812,001854
                    #print(dark2)
                    for j in range(len(dark2)):
                        dark3 = os.listdir(os.path.join(path,dir0,Dark[i],dark2[j]))#CENT
                        dark4 = os.listdir(os.path.join(path,dir0,Dark[i],dark2[j],dark3[0]))#001812
                        Darkoff.append(os.path.join(path,dir0,Dark[i],dark2[j],dark3[0],dark4[0]))
                if Darkoff != DarkoffNew:
                    xyy.JsonWrite(log_dir,'Darkoff',Darkoff)
                    DarkoffNew = Darkoff
                Flatoff = []
                for i in range(len(Flat)):
                    flat2 = os.listdir(os.path.join(path,dir0,Flat[i]))#B080,CENT,R080
                    for j in range(len(flat2)):
                        Flatoff.append(os.path.join(path,dir0,Flat[i],flat2[j]))
                if Flatoff != FlatoffNew:
                    xyy.JsonWrite(log_dir,'Flatoff',Flatoff)
                    FlatoffNew = Flatoff
                Bandoff = []
                #ActiveRegNew = ActiveReg
                if ActiveReg!= ActiveRegNew:
                    xyy.JsonWrite(log_dir,'ActiveRegion',ActiveReg)
                    ActiveRegNew = ActiveReg
                for i in range(len(ActiveReg)):
                    dir2 = os.listdir(os.path.join(path,dir0,ActiveReg[i]))#010704,025426
                   # xyy.JsonWrite(log_dir,'RecordTime',dir2)
                    for j in range(len(dir2)):
                        dir3 = os.listdir(os.path.join(path,dir0,ActiveReg[i],dir2[j]))#CENT BO50 R050
                        for k in range(len(dir3)):
                            Bandoff.append(os.path.join(path,dir0,ActiveReg[i],dir2[j],dir3[k]))
                if Bandoff != BandoffNew:
                    BandoffNew = Bandoff
                    xyy.JsonWrite(log_dir,'Bandoff',Bandoff)
                    for i in range(len(ActiveReg)):
                        dir2 = os.listdir(os.path.join(path,dir0,ActiveReg[i]))#010704,025426
                        xyy.JsonWrite(log_dir,'RecordTime',dir2)
            except Exception as e:
                #print(e)
                pass