def find_file(path, ymd, reg): ''' path: 要遍历的目录 reg: 符合条件的文件 ''' FileLst = [] try: lst = os.walk(path) for root, dirs, files in lst: for name in files: try: m = re.match(reg, name) except Exception as e: print str(e) continue if m: nameClass = pb_name.nameClassManager() info = nameClass.getInstance(name) if info == None: continue if info.dt_s.strftime('%Y%m%d') != ymd: continue FileLst.append(os.path.join(root, name)) except Exception as e: print str(e) return sorted(FileLst)
def MatchMoveList(mdir): # 遍历要迁移的目录 Dict = {} if not os.path.isdir(mdir): return Dict Lst = sorted(os.listdir(mdir), reverse=False) # print mdir for line in Lst: FullPath = os.path.join(mdir, line) if os.path.isfile(FullPath): fileName = line.strip() if '.lock' in fileName: continue else: nameClass = pb_name.nameClassManager() info = nameClass.getInstance(fileName) if info is None: continue ymd = info.dt_s.strftime('%Y%m%d') # hms = info.hms # sec = info.totalSec # 定义key为字典 if ymd not in Dict.keys(): Dict[ymd] = [] Dict[ymd].append(fileName + '\n') return Dict
def _get_time(self): shape = self._get_shape() time = np.full(shape, -999.) name_class = pb_name.nameClassManager() info = name_class.getInstance(os.path.basename(self.l1_1000m)) secs = int((info.dt_s - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()) time[:] = secs if not self.Time: self.Time = time else: self.Time = np.concatenate((self.Time, time))
def Find_data_FromCrossTime(FileList, start_crossTime, end_crossTime): dataList = [] for FileName in FileList: name = os.path.basename(FileName) nameClass = pb_name.nameClassManager() info = nameClass.getInstance(name) if info is None: continue # 获取数据时间段 data_stime1 = info.dt_s data_etime1 = info.dt_e if InCrossTime(data_stime1, data_etime1, start_crossTime, end_crossTime): dataList.append(FileName) return dataList
def GetFileInfo(FtpList): ''' 通过正则类对数据进行解析 ''' FileInfoList = [] for ftpList in FtpList: Filename = ftpList.split()[0].strip() nameClass = pb_name.nameClassManager() info = nameClass.getInstance(Filename) if info is None: continue FileInfoList.append([Filename, info.dt_s, info.dt_e]) return FileInfoList
def Load(self, L1File): print L1File iname = os.path.basename(L1File) i = 0 dataSahpe = [] try: h5File_R = h5py.File(L1File, 'r') for line in h5File_R.items(): print line[0] i = i + 1 data = h5File_R.get(line[0])[:] dataSahpe = data.shape dataT = np.full(data.shape, np.nan) condition = np.logical_and(data > 0, data < 65535) dataT[condition] = data[condition] self.SV['CH_%02d' % i] = None self.BB['CH_%02d' % i] = None if 'NOMChannelVIS' in line[0]: self.Ref['CH_%02d' % i] = dataT / 10000. print 'CH_%02d' % i elif 'NOMChannelIRX' in line[0]: print 'CH_%02d' % i self.Tbb['CH_%02d' % i] = dataT / 100. elif 'NOMSunAzimuth' in line[0]: self.sunAzimuth = dataT / 100. elif 'NOMSunZenith' in line[0]: self.sunZenith = dataT / 100. else: i = i - 1 print 'not', i data = 0 except Exception as e: print str(e) return finally: h5File_R.close() self.Time = np.full(dataSahpe, -999.) nameClass = pb_name.nameClassManager() info = nameClass.getInstance(iname) # print info.dt_s secs = int((info.dt_s - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()) self.Time[:] = secs
def use_ftp_getList(host, user, pawd, port, s_path, regList, ymd): FileList = [] class MySession(ftplib.FTP): def __init__(self, FTP, userid, password, port): """Act like ftplib.FTP's constructor but connect to another port.""" ftplib.FTP.__init__(self) self.connect(FTP, port) self.login(userid, password) try: FTP = ftputil.FTPHost(host, user, pawd, port=port, session_factory=MySession) FTP.chdir(s_path) nameList = FTP.listdir(FTP.curdir) for name in nameList: for reg in regList: # 符合正则的进行处理 m = re.match(reg, name) if m is not None: nameClass = pb_name.nameClassManager() info = nameClass.getInstance(name) if info is None: continue if info.dt_s.strftime('%Y%m%d') != ymd: continue stat = FTP.lstat(name) size = stat[6] Line = name + ' ' + str(size) FileList.append(Line) FTP.close() except Exception as e: print(u'----%s' % str(e)) return FileList
def use_http_getList(pact, host, user, pawd, port, s_path, regList, ymd): FileList = [] url = '%s://%s:%s' % (pact, host, port) + s_path html = getHtml(url) if html is None: return FileList dm = DM() dm.feed(html) dm.close() htmlList = dm.getStr() for Name in htmlList: for reg in regList: m = re.match(reg, Name) if m is not None: try: nameClass = pb_name.nameClassManager() info = nameClass.getInstance(Name) if info is None: continue if info.dt_s.strftime('%Y%m%d') != ymd: continue # huangyj 2017/03/28 由于nasa无法通过身份验证,暂时通过网页抓取数据的大小 size = GetFileSize(html, Name) # f = urllib2.urlopen(url + '/' + Name) # if "Content-Length" in f.headers: # print f.headers # size = int (f.headers["Content-Length"]) # else: # # 如果没有Length信息则把长度设置为0,无法做完整性检查 # # size = len (f.read ()) # size = 0 Line = Name + ' ' + str(size) FileList.append(Line) except Exception, e: print "ERROR: ", e FileList = []
def Load(self, L1File): print(u'读取 L1 %s' % L1File) iname = os.path.basename(L1File) try: h4File = SD(L1File, SDC.READ) # 读取1-2通道数据 in_data_r250 = h4File.select('EV_250_Aggr1km_RefSB').get() in_data_r250_s = h4File.select( 'EV_250_Aggr1km_RefSB').attributes()['reflectance_scales'] in_data_r250_o = h4File.select( 'EV_250_Aggr1km_RefSB').attributes()['reflectance_offsets'] # 读取 3-7通道数据 in_data_r500 = h4File.select('EV_500_Aggr1km_RefSB').get() in_data_r500_s = h4File.select( 'EV_500_Aggr1km_RefSB').attributes()['reflectance_scales'] in_data_r500_o = h4File.select( 'EV_500_Aggr1km_RefSB').attributes()['reflectance_offsets'] # 读取8-20通道, 包含26通道 in_data_r1km = h4File.select('EV_1KM_RefSB').get() in_data_r1km_s = h4File.select( 'EV_1KM_RefSB').attributes()['reflectance_scales'] in_data_r1km_o = h4File.select( 'EV_1KM_RefSB').attributes()['reflectance_offsets'] # 读取20-36通道 不包含26通道 in_data_t1km = h4File.select('EV_1KM_Emissive').get() in_data_t1km_s = h4File.select( 'EV_1KM_Emissive').attributes()['radiance_scales'] in_data_t1km_o = h4File.select( 'EV_1KM_Emissive').attributes()['radiance_offsets'] except Exception as e: print str(e) finally: h4File.end() # 处理定位文件,默认和L1同一目录 geoFile = find_modis_geo_file(L1File) print(u'读取geo %s' % geoFile) try: h4File = SD(geoFile, SDC.READ) in_data_lon = h4File.select('Longitude').get() in_data_lat = h4File.select('Latitude').get() # in_data_LandSeaMask = h4File.select('Land/SeaMask').get() # # 多个/不知道是bug还是就这样 in_data_satz = h4File.select('SensorZenith').get() in_data_satz_s = h4File.select( 'SensorZenith').attributes()['scale_factor'] in_data_sata = h4File.select('SensorAzimuth').get() in_data_sata_s = h4File.select( 'SensorAzimuth').attributes()['scale_factor'] in_data_sunz = h4File.select('SolarZenith').get() in_data_sunz_s = h4File.select( 'SolarZenith').attributes()['scale_factor'] in_data_suna = h4File.select('SolarAzimuth').get() in_data_suna_s = h4File.select( 'SolarAzimuth').attributes()['scale_factor'] except Exception as e: print(str(e)) finally: h4File.end() # 角度信息赋值 self.satZenith = in_data_satz * in_data_satz_s self.satAzimuth = in_data_sata * in_data_sata_s self.sunZenith = in_data_sunz * in_data_sunz_s self.sunAzimuth = in_data_suna * in_data_suna_s self.Lons = in_data_lon self.Lats = in_data_lat # 1-2通道 modis_shape2 = in_data_r250.shape[1:] modis_shape3 = (38, ) + modis_shape2 data_ch38 = np.full(modis_shape3, np.nan) for i in range(0, 2, 1): # 过滤 无效值 condition = np.logical_and(in_data_r250[i] < 32767, in_data_r250[i] > 0) idx = np.where(condition) data_ch38[i][idx] = (in_data_r250[i][idx] - in_data_r250_o[i]) * in_data_r250_s[i] # 3-7通道 for i in range(2, 7, 1): # 过滤 无效值 condition = np.logical_and(in_data_r500[i - 2] < 32767, in_data_r500[i - 2] > 0) idx = np.where(condition) data_ch38[i][idx] = (in_data_r500[i - 2][idx] - in_data_r500_o[i - 2]) * in_data_r500_s[i - 2] # 8-19 外加一个 26通道 for i in range(7, 22, 1): # 过滤 无效值 condition = np.logical_and(in_data_r1km[i - 7] < 32767, in_data_r1km[i - 7] > 0) idx = np.where(condition) data_ch38[i][idx] = (in_data_r1km[i - 7][idx] - in_data_r1km_o[i - 7]) * in_data_r1km_s[i - 7] # 20-36通道 不包括26通道 for i in range(22, 38, 1): # 过滤 无效值 condition = np.logical_and(in_data_t1km[i - 22] < 32767, in_data_t1km[i - 22] > 0) idx = np.where(condition) data_ch38[i][idx] = (in_data_t1km[i - 22][idx] - in_data_t1km_o[i - 22]) * in_data_t1km_s[i - 22] # 删除通道13hi 和 14 hi data_ch36 = np.delete(data_ch38, (13, 15), 0) newRad = np.full((16, ) + modis_shape2, np.nan) # 对时间进行赋值 self.Time = np.full(modis_shape2, -999.) nameClass = pb_name.nameClassManager() info = nameClass.getInstance(iname) ymd = info.dt_s.strftime('%Y%m%d') print ymd dsol = sun_earth_dis_correction(ymd) # print info.dt_s secs = int((info.dt_s - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()) self.Time[:] = secs # 把modis的rad转换和FY的单位一致 # 20,21, 22,23,24,25,27,28,29,30,31,32,33,34,35,36 cwn = [ 2.647409E+03, 2.511760E+03, 2.517908E+03, 2.462442E+03, 2.248296E+03, 2.209547E+03, 1.474262E+03, 1.361626E+03, 1.169626E+03, 1.028740E+03, 9.076813E+02, 8.308411E+02, 7.482978E+02, 7.307766E+02, 7.182094E+02, 7.035007E+02 ] for i in xrange(16): newRad[i] = data_ch36[i + 20] * \ ((10000 / cwn[i]) ** 2) / 10. * dsol if i <= 5: self.Rad['CH_%02d' % (i + 20)] = newRad[i] else: self.Rad['CH_%02d' % (i + 21)] = newRad[i] # 把rad转亮温 radiance2tbb(data_ch36) # 整理通道顺序,把26通道放在对应的26通道 # del26_data_ch35 = np.delete(data_ch36, 19, 0) # order_data_ch36 = np.insert(del26_data_ch35, 25, data_ch36[19], 0) for i in range(0, 36, 1): # self.CA['CH_%02d' % (i + 1)] = order_data_ch36[i] if i < 19: self.Ref['CH_%02d' % (i + 1)] = data_ch36[i] elif i == 19: # 26 self.Ref['CH_%02d' % (i + 7)] = data_ch36[i] elif i > 19 and i <= 25: self.Tbb['CH_%02d' % (i)] = data_ch36[i] elif i > 25: self.Tbb['CH_%02d' % (i + 1)] = data_ch36[i]
:return: """ d = {} try: with h5py.File(self.file_path, 'r') as hdf5_file: for k, v in hdf5_file.attrs.items(): d[k] = v except Exception as why: print why self.error = True return d @staticmethod def read_dataset_attr(dataset): """ 读取HDF5文件dataset的属性 :return: """ d = {} for k, v in dataset.attrs.items(): d[k] = v return d if __name__ == '__main__': g_test_file = r'D:\nsmc\fix_data\FY3ABC\FY3A_VIRRX_GBAL_L1_20131206_1355_1000M_MS.HDF' name_class = nameClassManager() g_info = name_class.getInstance(g_test_file) g_sec = int((g_info.dt_s - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()) print g_sec
def Load(self, L1File): ipath = os.path.dirname(L1File) iname = os.path.basename(L1File) geoFile = os.path.join(ipath, iname[0:-12] + 'GEO1K_MS.HDF') print L1File print geoFile if 'FY3C' in iname[:4]: try: h5File_R = h5py.File(L1File, 'r') ary_ch1 = h5File_R.get('/Data/EV_250_Aggr.1KM_RefSB')[:] ary_ch5 = h5File_R.get('/Data/EV_250_Aggr.1KM_Emissive')[:] ary_ch6 = h5File_R.get('/Data/EV_1KM_RefSB')[:] ary_Cal_Coeff = h5File_R.get('/Calibration/VIS_Cal_Coeff')[:] ary_svdn = h5File_R.get('/Calibration/SV_DN_average')[:] ary_bbdn = h5File_R.get('/Calibration/BB_DN_average')[:] except Exception as e: print str(e) return finally: h5File_R.close() print sys.getsizeof(ary_ch1) / 1024. / 1024. try: # 读取GEO文件 h5File_R = h5py.File(geoFile, 'r') ary_satz = h5File_R.get('/Geolocation/SensorZenith')[:] ary_sata = h5File_R.get('/Geolocation/SensorAzimuth')[:] ary_sunz = h5File_R.get('/Geolocation/SolarZenith')[:] ary_suna = h5File_R.get('/Geolocation/SolarAzimuth')[:] ary_lon = h5File_R.get('/Geolocation/Longitude')[:] ary_lat = h5File_R.get('/Geolocation/Latitude')[:] ary_LandCover = h5File_R.get('/Geolocation/LandCover')[:] ary_LandSeaMask = h5File_R.get('/Geolocation/LandSeaMask')[:] ary_day = h5File_R.get('/Timedata/Day_Count')[:] ary_time = h5File_R.get('/Timedata/Millisecond_Count')[:] except Exception as e: print str(e) return finally: h5File_R.close() else: # FY3A/FY3B MERSI # 读取L1文件 try: h5File_R = h5py.File(L1File, 'r') ary_lon = h5File_R.get('/Longitude')[:] ary_lat = h5File_R.get('/Latitude')[:] ary_svdn = np.full_like(ary_lon, -999.) ary_bbdn = np.full_like(ary_lon, -999.) ary_ch1 = h5File_R.get('/EV_250_Aggr.1KM_RefSB')[:] ary_ch5 = h5File_R.get('/EV_250_Aggr.1KM_Emissive')[:] ary_ch6 = h5File_R.get('/EV_1KM_RefSB')[:] ary_Cal_Coeff = h5File_R.attrs['VIR_Cal_Coeff'] ary_satz = h5File_R.get('/SensorZenith')[:] ary_sata = h5File_R.get('/SensorAzimuth')[:] ary_sunz = h5File_R.get('/SolarZenith')[:] ary_suna = h5File_R.get('/SolarAzimuth')[:] ary_LandCover = h5File_R.get('/LandCover')[:] ary_LandSeaMask = h5File_R.get('/LandSeaMask')[:] ary_svdn = h5File_R.get('/SV_DN_average')[:] ary_bbdn = h5File_R.get('/BB_DN_average')[:] except Exception as e: print str(e) return finally: h5File_R.close() # 通道的中心波数和光谱响应 # for i in xrange(self.Band): # BandName = 'CH_%02d' % (i + 1) # srfFile = os.path.join( # MainPath, 'SRF', '%s_%s_SRF_CH%02d_Pub.txt' % (self.sat, self.sensor, (i + 1))) # dictWave = np.loadtxt( # srfFile, dtype={'names': ('num', 'rad'), 'formats': ('f4', 'f4')}) # waveNum = 10 ** 7 / dictWave['num'][::-1] # waveRad = dictWave['rad'][::-1] # self.waveNum[BandName] = waveNum # self.waveRad[BandName] = waveRad # 数据大小 使用经度维度 ############### dshape = ary_lon.shape # 通道信息赋值 ####################### # 读取FY3C查找表 # LutAry = np.loadtxt(self.LutFile, dtype={'names': ('TBB', '05'), # 'formats': ('i4', 'f4')}) # RefSB_Cal_Coefficients这个属性直接写到hdf中,FY3A/B 需要转成19*3 proj_Cal_Coeff = np.full((19, 3), -999.) if 'FY3C' in iname[:4]: proj_Cal_Coeff = ary_Cal_Coeff else: for i in range(19): for j in range(3): proj_Cal_Coeff[i, j] = ary_Cal_Coeff[i * 3 + j] # 定标系数 19*3 转 20*3 values = np.array([0, 0, 0]) K = np.insert(proj_Cal_Coeff, 4, values, 0) pat = u'\w{4}_\w{5}_\w{4}_L1_(\d{8})_(\d{4})_\w{5}_MS.HDF$' g = re.match(pat, iname) if g: ymd = g.group(1) hms = g.group(2) else: raise ValueError('Cant get the ymdhms from file name.') # 可见 for i in xrange(self.Band): BandName = 'CH_%02d' % (i + 1) if i < 4: DN = np.full(dshape, np.nan) idx = np.logical_and(ary_ch1[i] < 10000, ary_ch1[i] > 0) DN[idx] = ary_ch1[i][idx] if int(ymd + hms) <= 201303060015: Ref = (DN ** 2 * K[i, 2] + DN * K[i, 1] + K[i, 0]) / 100. print 'ref', Ref, BandName else: Ref = (DN ** 2 * K[i, 2] + DN * K[i, 1] + K[i, 0]) / 10000. self.Dn[BandName] = DN self.Ref[BandName] = Ref elif i > 4: k = i - 5 DN = np.full(dshape, np.nan) idx = np.logical_and(ary_ch6[k] < 10000, ary_ch6[k] > 0) DN[idx] = ary_ch6[k][idx] if int(ymd + hms) <= 201303060015: Ref = (DN ** 2 * K[i, 2] + DN * K[i, 1] + K[i, 0]) / 100. print 'ref', Ref, BandName else: Ref = (DN ** 2 * K[i, 2] + DN * K[i, 1] + K[i, 0]) / 10000. self.Dn[BandName] = DN self.Ref[BandName] = Ref # 红外 elif i == 4: # 数据空间 DN = np.full(dshape, np.nan) Rad = np.full(dshape, np.nan) Tbb = np.full(dshape, np.nan) # 过滤无效值 idx = np.logical_and(ary_ch5 < 10000, ary_ch5 >= 0) # dn DN[idx] = ary_ch5[idx] self.Dn[BandName] = DN # rad Rad = DN / 100. idx1 = np.where(Rad <= 0.) Rad[idx1] = np.nan self.Rad[BandName] = Rad # tbb Tbb = pb_sat.planck_r2t( Rad, self.WN[BandName], self.TeA[BandName], self.TeB[BandName]) self.Tbb[BandName] = Tbb # CA = interpolate.InterpolatedUnivariateSpline(LutAry['%02d' % (i + 1)], LutAry['TBB'])(DN[idx]) # self.CA[BandName] = np.full(dshape, np.nan) # self.CA[BandName][idx] = CA / 100. # 全局信息赋值 ############################ # 对时间进行赋值合并 if 'FY3C' in iname[:4]: v_ymd2seconds = np.vectorize(fy3_ymd2seconds) T1 = v_ymd2seconds(ary_day, ary_time) Time = np.full(dshape, -999) for i in xrange(ary_lon.shape[0]): Time[i, :] = T1[i / 10, 0] if self.Time == []: self.Time = Time else: self.Time = np.concatenate((self.Time, Time)) else: time = np.full(dshape, -999.) name_class = pb_name.nameClassManager() info = name_class.getInstance(iname) secs = int( (info.dt_s - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()) time[:] = secs if not self.Time: self.Time = time else: self.Time = np.concatenate((self.Time, time)) # SV, BB for i in xrange(self.Band): SV = np.full(dshape, np.nan) BB = np.full(dshape, np.nan) for j in xrange(ary_lon.shape[0]): SV[j, :] = ary_svdn[i][j / 10] BB[j, :] = ary_bbdn[i][j / 10] SV = np.ma.masked_where(SV < 0, SV) BB = np.ma.masked_where(BB < 0, BB) np.ma.filled(SV, np.nan) np.ma.filled(BB, np.nan) # 数据合并 BandName = 'CH_%02d' % (i + 1) if BandName not in self.SV.keys(): self.SV[BandName] = SV self.BB[BandName] = BB else: self.SV[BandName] = np.concatenate((self.SV[BandName], SV)) self.BB[BandName] = np.concatenate((self.BB[BandName], BB)) # 土地覆盖 ary_LandCover_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_LandCover >= 0, ary_LandCover <= 254) ary_LandCover_idx[condition] = ary_LandCover[condition] if self.LandCover == []: self.LandCover = ary_LandCover_idx else: self.LandCover = np.concatenate( (self.LandCover, ary_LandCover_idx)) # 海陆掩码 ary_LandSeaMask_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_LandSeaMask >= 0, ary_LandSeaMask <= 7) ary_LandSeaMask_idx[condition] = ary_LandSeaMask[condition] if self.LandSeaMask == []: self.LandSeaMask = ary_LandSeaMask_idx else: self.LandSeaMask = np.concatenate( (self.LandSeaMask, ary_LandSeaMask_idx)) # 经纬度 ary_lon_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_lon > -180., ary_lon < 180.) ary_lon_idx[condition] = ary_lon[condition] if self.Lons == []: self.Lons = ary_lon_idx else: self.Lons = np.concatenate((self.Lons, ary_lon_idx)) ary_lat_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_lat > -90., ary_lat < 90.) ary_lat_idx[condition] = ary_lat[condition] if self.Lats == []: self.Lats = ary_lat_idx else: self.Lats = np.concatenate((self.Lats, ary_lat_idx)) # 卫星方位角 天顶角 ary_sata_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_sata > -18000, ary_sata < 18000) ary_sata_idx[condition] = ary_sata[condition] if self.satAzimuth == []: self.satAzimuth = ary_sata_idx / 100. else: self.satAzimuth = np.concatenate( (self.satAzimuth, ary_sata_idx / 100.)) ary_satz_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_satz > 0, ary_satz < 18000) ary_satz_idx[condition] = ary_satz[condition] if self.satZenith == []: self.satZenith = ary_satz_idx / 100. else: self.satZenith = np.concatenate( (self.satZenith, ary_satz_idx / 100.)) # 太阳方位角 天顶角 ary_suna_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_suna > -18000, ary_suna < 18000) ary_suna_idx[condition] = ary_suna[condition] if self.sunAzimuth == []: self.sunAzimuth = ary_suna_idx / 100. else: self.sunAzimuth = np.concatenate( (self.sunAzimuth, ary_suna_idx / 100.)) ary_sunz_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_sunz > 0, ary_sunz < 18000) ary_sunz_idx[condition] = ary_sunz[condition] if self.sunZenith == []: self.sunZenith = ary_sunz_idx / 100. else: self.sunZenith = np.concatenate( (self.sunZenith, ary_sunz_idx / 100.))
def create_leo_leo_fine(sat_pair, ymd, job_id): ''' 创建精匹配配置接口文件 ''' Log.info(u'[%s] [%s]' % (sat_pair, ymd)) # 解析mathcing: FY3A+MERSI_AQUA+MODIS ,根据下划线分割获取 卫星+传感器 ,再次分割获取俩颗卫星短名 shortsat1 = (sat_pair.split('_')[0]).split('+')[0] shortsat2 = (sat_pair.split('_')[1]).split('+')[0] # 解析global.cfg中的信息 NUM1 = inCfg['PAIRS'][sat_pair]['num1'] NUM2 = inCfg['PAIRS'][sat_pair]['num2'] sec1 = inCfg['PAIRS'][sat_pair]['sec1'] sec2 = inCfg['PAIRS'][sat_pair]['sec2'] # 根据编号在dm_odm.cfg中查找到对应的数据描述信息 sat1 = odmCfg['ORDER'][NUM1[0]]['SELF_SAT'] sensor1 = odmCfg['ORDER'][NUM1[0]]['SELF_SENSOR'] product1 = odmCfg['ORDER'][NUM1[0]]['SELF_PRODUCT'] interval1 = odmCfg['ORDER'][NUM1[0]]['SELF_INTERVAL'] reg1 = odmCfg['ORDER'][NUM1[0]]['SELF_REG'][0] sat2 = odmCfg['ORDER'][NUM2[0]]['SELF_SAT'] sensor2 = odmCfg['ORDER'][NUM2[0]]['SELF_SENSOR'] product2 = odmCfg['ORDER'][NUM2[0]]['SELF_PRODUCT'] interval2 = odmCfg['ORDER'][NUM2[0]]['SELF_INTERVAL'] reg2 = odmCfg['ORDER'][NUM2[0]]['SELF_REG'][0] # 存放俩颗卫星的原始数据目录位置 inpath1 = os.path.join( DATA_DIR, '%s/%s/%s/%s' % (sat1, sensor1, product1, interval1), ymd[:6]) inpath2 = os.path.join( DATA_DIR, '%s/%s/%s/%s' % (sat2, sensor2, product2, interval2), ymd[:6]) file_list1 = find_file(inpath1, ymd, reg1) file_list2 = find_file(inpath2, ymd, reg2) # file_list2是高光普数据,根据list2找list1符合条件的数据 for filename2 in file_list2: name2 = os.path.basename(filename2) nameClass = pb_name.nameClassManager() info = nameClass.getInstance(filename2) if info == None: continue # 获取数据时间段 data_stime2 = info.dt_s - timedelta(minutes=5) data_etime2 = info.dt_e + timedelta(minutes=5) ymdhms = info.dt_s.strftime('%Y%m%d%H%M%S') new_file_list1 = Find_data_FromCrossTime(file_list1, data_stime2, data_etime2) yaml_file = os.path.join(JOBCFG_DIR, sat_pair, 'job_%s' % job_id, ymdhms[:8], '%s_%s_%s.yaml' % (ymdhms, sensor1, sensor2)) # 输出文件命名 filename = 'W_CN-CMA-NSMC,SATCAL+NRTC,GSICS+MATCHEDPOINTS,%s_C_BABJ_%s.hdf5' % ( sat_pair, ymdhms) # 输出完整路径 full_filename = os.path.join(MATCH_DIR, sat_pair, ymdhms[:4], ymdhms[:8], filename3) if len(new_file_list1) > 0: dict1 = { 'INFO': { 'sat1': sat1, 'sensor1': sensor1, 'sat2': sat2, 'sensor2': sensor2, 'ymd': ymdhms }, 'PATH': { 'opath': full_filename, 'ipath1': new_file_list1, 'ipath2': [filename2] } } CreateYamlCfg(dict, yaml_file)