def get_tbb_test2(self): """ return tbb """ data = dict() if self.resolution == 4000: # 分辨率为 1000 satellite_type1 = ['FY4A'] # dn = self.get_dn() if self.satellite in satellite_type1: # rad转tbb的修正系数,所有时次都是固定值 tbb_k0 = self.get_tbb_k0() tbb_k1 = self.get_tbb_k1() rads = self.get_rad() central_wave_numbers = self.get_central_wave_number() # 逐个通道处理 for i in xrange(self.channels): band = 'CH_{:02d}'.format(i + 1) if band in rads.keys(): k0 = tbb_k0[band] k1 = tbb_k1[band] central_wave_number = central_wave_numbers[band] rad = 36 tbb = planck_r2t(rad, central_wave_number) data[band] = tbb * k1 + k0 else: raise ValueError('Cant read this satellite`s data.: {}'.format( self.satellite)) else: raise ValueError( 'Cant read this data, please check its resolution: {}'.format( self.in_file)) return data
def get_tbb(self): data = dict() if self.resolution == 1000: # 分辨率为 1000 satellite_type1 = ['FY3A', 'FY3B', 'FY3C'] # 红外转tbb的修正系数,所有时次都是固定值 tbb_k0 = self.get_tbb_k0() tbb_k1 = self.get_tbb_k1() if self.satellite in satellite_type1: lut = self.get_lut_bt() rads = self.get_rad() central_wave_numbers = self.get_central_wave_number() for band in rads: rad = rads[band] central_wave_number = central_wave_numbers[band] if lut: print 'f3 lut' tbb = np.interp(rad, lut['rad'][band], lut['tbb']) else: print 'f3 plank' tbb = planck_r2t(rad, central_wave_number) k0 = tbb_k0[band] k1 = tbb_k1[band] tbb = tbb * k1 + k0 data[band] = tbb else: raise ValueError( 'Cant read this satellite`s data.: {}'.format(self.satellite)) else: raise ValueError( 'Cant read this data, please check its resolution: {}'.format(self.in_file)) return data
def get_rad_tbb(self, D1, BandLst): ''' D1是目标类的实例 ''' # iasi 的光谱波数范围 WaveNum2 = self.wavenumber for Band in BandLst: WaveNum1 = D1.waveNum[Band] WaveRad1 = D1.waveRad[Band] WaveRad2 = pb_sat.spec_interp(WaveNum1, WaveRad1, WaveNum2) newRad = pb_sat.spec_convolution(WaveNum2, WaveRad2, self.radiance) tbb = pb_sat.planck_r2t(newRad, D1.WN[Band]) tbb = tbb * D1.TeA[Band] + D1.TeB[Band] self.Tbb[Band] = tbb.reshape(tbb.size, 1) self.Rad[Band] = newRad.reshape(newRad.size, 1)
def get_tbb(self, wave_nums, wave_spec, band_list, central_wave_nums, a, b, lut): """ use 卫星1的光谱和响应wave_nums,wave_spec(字典形式,key是通道信息,针对FY数据) a,b 分别是红外tbb修正系数,字典 ,key是通道信息 return channel rad """ data = dict() if self.resolution == 24000 or self.resolution == 24001: satellite_type1 = ['METOP-A', 'METOP-B'] if self.satellite in satellite_type1: # 目标数据通道信息 # 获取通道的rads rads = self.get_rad(wave_nums, wave_spec, band_list, central_wave_nums, a, b, lut) for band in band_list: rad = rads[band] if lut: print 'lut' tbb = np.interp(rad, lut['rad'][band], lut['tbb']) data[band] = tbb else: central_wave_number = central_wave_nums[band] tbb = planck_r2t(rad, central_wave_number) if a is not None: k1 = a[band] k0 = b[band] data[band] = tbb * k1 + k0 else: data[band] = tbb else: raise ValueError('Cant read this satellite`s data.: {}'.format( self.satellite)) else: raise ValueError( 'Cant read this data, please check its resolution: {}'.format( self.in_file)) return data
def Load(self, L1File): ipath = os.path.dirname(L1File) iname = os.path.basename(L1File) self.file_attr = self.read_file_attr(L1File) if 'FY3C' in iname[:4]: # 根据输入的L1文件自动拼接GEO文件 geoFile = os.path.join(ipath, iname[0:-12] + 'GEOXX_MS.HDF') obcFile = os.path.join(ipath, iname[0:-12] + 'OBCXX_MS.HDF') print u'%s' % L1File print u'%s' % geoFile print u'%s' % obcFile #################### 读取L1文件 ###################### try: with h5py.File(L1File, 'r') as h5File_R: ary_ch3 = h5File_R.get('/Data/EV_Emissive')[:] ary_ch7 = h5File_R.get('/Data/EV_RefSB')[:] ary_offsets = h5File_R.get( '/Data/Emissive_Radiance_Offsets')[:] ary_scales = h5File_R.get( '/Data/Emissive_Radiance_Scales')[:] ary_ref_cal = h5File_R.attrs['RefSB_Cal_Coefficients'] ary_Nonlinear = h5File_R.attrs[ 'Prelaunch_Nonlinear_Coefficients'] try: ary_tb_coeff = h5File_R.attrs[ 'Emmisive_BT_Coefficients'] except Exception: ary_tb_coeff = h5File_R.attrs[ 'Emissive_BT_Coefficients'] except Exception as e: self.error = True print str(e) return #################### 读取GEO文件 ###################### try: with h5py.File(geoFile, 'r') as h5File_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_height = h5File_R.get('/Geolocation/DEM')[:] ary_LandCover = h5File_R.get('/Geolocation/LandCover')[:] ary_LandSeaMask = h5File_R.get( '/Geolocation/LandSeaMask')[:] except Exception as e: self.error = True print str(e) return #################### 读取OBC文件 #################### try: with h5py.File(obcFile, 'r') as h5File_R: ary_sv = h5File_R.get('/Calibration/Space_View')[:] ary_bb = h5File_R.get('/Calibration/Blackbody_View')[:] except Exception as e: self.error = True print str(e) return else: # FY3A/FY3B VIRR # 根据输入的L1文件自动拼接OBC文件 obcFile = os.path.join(ipath, iname[0:-12] + 'OBCXX_MS.HDF') print u'%s' % L1File print u'%s' % obcFile #################### 读取L1文件 #################### try: with h5py.File(L1File, 'r') as h5File_R: ary_ch3 = h5File_R.get('/EV_Emissive')[:, 0:1800, 0:2048] ary_ch7 = h5File_R.get('/EV_RefSB')[:, 0:1800, 0:2048] ary_offsets = h5File_R.get('/Emissive_Radiance_Offsets')[ 0:1800, :] ary_scales = h5File_R.get('/Emissive_Radiance_Scales')[ 0:1800, :] ary_ref_cal = h5File_R.attrs['RefSB_Cal_Coefficients'] ary_Nonlinear = h5File_R.attrs[ 'Prelaunch_Nonlinear_Coefficients'] try: ary_tb_coeff = h5File_R.attrs[ 'Emmisive_BT_Coefficients'] except Exception: ary_tb_coeff = h5File_R.attrs[ 'Emissive_BT_Coefficients'] ary_satz = h5File_R.get('/SensorZenith')[0:1800, 0:2048] ary_sata = h5File_R.get('/SensorAzimuth')[0:1800, 0:2048] ary_sunz = h5File_R.get('/SolarZenith')[0:1800, 0:2048] ary_suna = h5File_R.get('/SolarAzimuth')[0:1800, 0:2048] ary_lon = h5File_R.get('/Longitude')[0:1800, 0:2048] ary_lat = h5File_R.get('/Latitude')[0:1800, 0:2048] ary_height = h5File_R.get('/Height')[0:1800, 0:2048] ary_LandCover = h5File_R.get('/LandCover')[0:1800, 0:2048] ary_LandSeaMask = h5File_R.get('/LandSeaMask')[0:1800, 0:2048] except Exception as e: self.error = True print str(e) return #################### 读取OBC文件 #################### try: with h5py.File(obcFile, 'r') as h5File_R: ary_sv = h5File_R.get('Space_View')[:] ary_bb = h5File_R.get('Blackbody_View')[:] except Exception as e: self.error = True print(str(e)) return # 通道的中心波数和光谱响应 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') }) if BandName in ['CH_03', 'CH_04', 'CH_05']: waveNum = 10**4 / dictWave['num'][::-1] else: waveNum = 10**7 / dictWave['num'][::-1] waveRad = dictWave['rad'][::-1] if BandName not in self.waveNum: self.waveNum[BandName] = waveNum self.waveRad[BandName] = waveRad else: self.waveNum[BandName] = np.concatenate( (self.waveNum[BandName], waveNum)) self.waveRad[BandName] = np.concatenate( (self.waveRad[BandName], waveRad)) ############### 数据大小 使用经度维度 ############### dshape = ary_lon.shape ##################可见光数据进行定标 ######## # LutAry = np.loadtxt(self.LutFile, dtype={'names': ('TBB', 'CH_03', 'CH_04', 'CH_05'), # 'formats': ('i4', 'f4', 'f4', 'f4')}) # 定标系数b,a proj_Cal_Coeff = np.full((7, 2), np.nan) for i in range(7): for j in range(2): proj_Cal_Coeff[i, j] = ary_ref_cal[i * 2 + j - 1] # 1 - 6 通道的ref for i in xrange(self.Band): BandName = 'CH_%02d' % (i + 1) if i < 2 or i >= 5: # 下标k (1 2 6 7 8 9 10存放在一个三维数组中) if i < 2: k = i elif i >= 5: k = i - 3 # DN值存放无效值用nan填充 DN = np.full(dshape, np.nan) idx = np.logical_and(ary_ch7[k] < 32767, ary_ch7[k] > 0) DN[idx] = ary_ch7[k][idx] # 反射率值存放无效值用nan填充 k0 = proj_Cal_Coeff[k][1] k1 = proj_Cal_Coeff[k][0] Ref = (DN * k0 + k1) / 100. K0 = np.full(dshape, k0, dtype=np.float32) K1 = np.full(dshape, k1, dtype=np.float32) if BandName not in self.Dn: self.Dn[BandName] = DN self.Ref[BandName] = Ref self.K0[BandName] = K0 self.K1[BandName] = K1 else: self.Dn[BandName] = np.concatenate((self.Dn[BandName], DN)) self.Ref[BandName] = np.concatenate( (self.Ref[BandName], Ref)) self.K0[BandName] = np.concatenate((self.K0[BandName], K0)) self.K1[BandName] = np.concatenate((self.K1[BandName], K1)) if 2 <= i <= 4: # DN Rad Tbb 值存放,默认 nan填充 k = i - 2 DN = np.full(dshape, np.nan) Rad_pre = np.full(dshape, np.nan) condition = np.logical_and(ary_ch3[k] < 32767, ary_ch3[k] > 0) idx = np.where(condition) # 下标i-2 (3,4,5通道DN存放在一个三维数组中) DN[idx] = ary_ch3[k][idx] Rad_pre[idx] = DN[idx] * ary_scales[idx[0], k] + \ ary_offsets[idx[0], k] k0 = ary_Nonlinear[k] k1 = ary_Nonlinear[3 + k] k2 = ary_Nonlinear[6 + k] Rad_nonlinearity = Rad_pre**2 * k2 + Rad_pre * k1 + k0 K0 = np.full(dshape, np.nan) K0[:] = ary_scales[:, k].reshape(-1, 1) K1 = np.full(dshape, np.nan) K1[:] = ary_offsets[:, k].reshape(-1, 1) self.Rad_pre[BandName] = Rad_pre Rad = Rad_pre + Rad_nonlinearity Tbb = pb_sat.planck_r2t(Rad, self.WN[BandName]) Tbb = Tbb * self.TeA[BandName] + self.TeB[BandName] k0_coeff = ary_tb_coeff[k * 2 + 1] k1_coeff = ary_tb_coeff[k * 2] Tbb_coeff = Tbb * k0_coeff + k1_coeff if BandName not in self.Dn: self.Dn[BandName] = DN self.Rad[BandName] = Rad self.K0[BandName] = K0 self.K1[BandName] = K1 self.Tbb[BandName] = Tbb self.Tbb_coeff[BandName] = Tbb_coeff else: self.Dn[BandName] = np.concatenate((self.Dn[BandName], DN)) self.Rad[BandName] = np.concatenate( (self.Rad[BandName], Rad)) self.K0[BandName] = np.concatenate((self.K0[BandName], K0)) self.K1[BandName] = np.concatenate((self.K1[BandName], K1)) self.Tbb[BandName] = np.concatenate( (self.Tbb[BandName], Tbb)) self.Tbb_coeff[BandName] = np.concatenate( (self.Tbb_coeff[BandName], Tbb_coeff)) # SV, BB for i in xrange(self.Band): BandName = 'CH_%02d' % (i + 1) SV = np.full(dshape, np.nan) BB = np.full(dshape, np.nan) SV[:] = ary_sv[i, :, 0].reshape(-1, 1) BB[:] = ary_bb[i, :, 0].reshape(-1, 1) if BandName not in self.SV: 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)) ##################### 全局信息赋值 ############################ # 对时间进行赋值合并 Time = np.full(dshape, np.nan) ymd = get_ymd(L1File) hm = get_hm(L1File) file_date = datetime.strptime(ymd + hm, '%Y%m%d%H%M') secs = (file_date - datetime(1970, 1, 1, 0, 0, 0)).total_seconds() Time[:] = secs if self.Time == []: self.Time = Time else: self.Time = np.concatenate((self.Time, Time)) # 土地覆盖 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_height_idx = np.full(dshape, np.nan) condition = np.logical_and(ary_height > -1000., ary_height < 10000.) ary_height_idx[condition] = ary_height[condition] if self.Height == []: self.Height = ary_height_idx else: self.Height = np.concatenate((self.Height, ary_height_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.)) self.get_extract_data()
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') clm_name = iname.replace('GBAL_L1', 'ORBT_L2_CLM_MLT_NUL') clm_file = os.path.join(ipath, clm_name) print(u'读取 L1 %s' % L1File) try: h5File_R = h5py.File(L1File, 'r') orbit_direction = h5File_R.attrs.get('Orbit Direction') orbit_num = h5File_R.attrs.get('Orbit Number') self.orbit_direction.append(orbit_direction) self.orbit_num.append(orbit_num) ary_ch1_4 = h5File_R.get('/Data/EV_250_Aggr.1KM_RefSB')[:] ary_ch5_19 = h5File_R.get('/Data/EV_1KM_RefSB')[:] ary_ch20_23 = h5File_R.get('/Data/EV_1KM_Emissive')[:] ary_ch20_23_a = h5File_R.get( '/Data/EV_1KM_Emissive').attrs['Slope'] ary_ch20_23_b = h5File_R.get( '/Data/EV_1KM_Emissive').attrs['Intercept'] ary_ch24_25 = h5File_R.get('/Data/EV_250_Aggr.1KM_Emissive')[:] ary_ch24_25_a = h5File_R.get( '/Data/EV_250_Aggr.1KM_Emissive').attrs['Slope'] ary_ch24_25_b = h5File_R.get( '/Data/EV_250_Aggr.1KM_Emissive').attrs['Intercept'] ary_IR_Coeff = h5File_R.get('/Calibration/IR_Cal_Coeff')[:] ary_VIS_Coeff = h5File_R.get('/Calibration/VIS_Cal_Coeff')[:] ary_sv = h5File_R.get('/Calibration/SV_DN_average')[:] ary_bb = h5File_R.get('/Calibration/BB_DN_average')[:] except Exception as e: print str(e) return finally: h5File_R.close() print(u'读取geo %s' % geoFile) 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() print(u'读取 L1 %s' % L1File) try: h5File_R = h5py.File(clm_file, 'r') data_pre = h5File_R.get('Cloud_Mask')[0, :, :] clm_flag = np.full(data_pre.shape, -999) z = data_pre # 0 表示无效值 z0 = z & 0b1 z12 = (z >> 1) & 0b11 z4 = (z >> 4) & 0b1 z67 = (z >> 6) & 0b11 # Invalid 0 mask = (z == 0) idx = np.where(mask) clm_flag[idx] = 0 # Coastlines mask = (z67 == 0b01) idx = np.where(mask) clm_flag[idx] = 1 # Uncertain mask = (z12 == 0b01) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 2 # Cloud mask = (z12 == 0b00) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 3 # Poss Land Clear mask = ((z67 == 0b11) | (z67 == 0b10)) & (z12 == 0b10) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 4 # Land Clear mask = ((z67 == 0b11) | (z67 == 0b10)) & (z12 == 0b11) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 5 # Poss Sea Clear mask = (z67 == 0b00) & (z12 == 0b10) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 6 # Sea Clear mask = (z67 == 0b00) & (z12 == 0b11) & (z4 == 0b1) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 7 # Sun Glint mask = (z67 == 0b00) & (z12 == 0b11) & (z4 == 0b0) & (z0 == 0b1) idx = np.where(mask) clm_flag[idx] = 8 # print clm_flag data = clm_flag if self.CloudMask == []: self.CloudMask = data else: self.CloudMask = np.concatenate((self.CloudMask, data)) except Exception as e: print str(e) if hasattr(self, 'CloudMask'): delattr(self, 'CloudMask') 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 # 1-19通道的可见光数据进行定标 K = ary_VIS_Coeff for i in range(19): if i < 4: # 统一下标 j = i indata = ary_ch1_4[j] else: j = i - 4 indata = ary_ch5_19[j] # 初始存放dn数据的结构,初始值 Nan DN = np.full(dshape, np.nan) idx = np.logical_and(indata < 65500, indata >= 0) DN[idx] = indata[idx] Ref = ((DN**2 * K[i, 2]) + DN * K[i, 1] + K[i, 0]) / 100. BandName = 'CH_%02d' % (i + 1) if BandName not in self.Dn.keys(): self.Dn[BandName] = DN self.Ref[BandName] = Ref else: self.Dn[BandName] = np.concatenate((self.Dn[BandName], DN)) self.Ref[BandName] = np.concatenate((self.Ref[BandName], Ref)) if BandName not in self.cal_coeff1.keys(): self.cal_coeff1[BandName] = [K[i, 0], K[i, 1], K[i, 2]] # 20-25通道的红外光数据进行定标 ######## K = ary_IR_Coeff a = np.concatenate((ary_ch20_23_a, ary_ch24_25_a)) b = np.concatenate((ary_ch20_23_b, ary_ch24_25_b)) for i in range(6): if i < 4: # 统一下标 j = i indata = ary_ch20_23[j] else: j = i - 4 indata = ary_ch24_25[j] BandName = 'CH_%02d' % (i + 20) # 初始存放dn数据的结构,初始值 Nan DN = np.full(dshape, np.nan) Rad = np.full(dshape, np.nan) # 存放定标系数 if BandName not in self.cal_coeff1.keys(): self.cal_coeff1[BandName] = [ K[i, 0, 0], K[i, 2, 0], K[i, 3, 0] ] # k1 = np.full(dshape, np.nan) # 把红外定标系数拆成4个数据 2000*2048 k1 = (np.repeat(K[i, 1, :], 10 * 2048)).reshape(dshape) if BandName not in self.cal_coeff2.keys(): self.cal_coeff2[BandName] = k1 else: self.cal_coeff2[BandName] = np.concatenate( (self.cal_coeff2[BandName], k1)) # 对无效DN值进行过滤 idx = np.logical_and(indata < 65500, indata > 0) DN[idx] = indata[idx] Rad[idx] = DN[idx] * a[i] + b[i] Tbb = pb_sat.planck_r2t(Rad, self.WN[BandName]) Tbb = Tbb * self.TeA[BandName] + self.TeB[BandName] # 对类成员进行赋值 if BandName not in self.Dn.keys(): self.Dn[BandName] = DN self.Rad[BandName] = Rad self.Tbb[BandName] = Tbb else: self.Dn[BandName] = np.concatenate((self.Dn[BandName], DN)) self.Rad[BandName] = np.concatenate((self.Rad[BandName], Rad)) self.Tbb[BandName] = np.concatenate((self.Tbb[BandName], Tbb)) # 定标方法仿真数据已有描述 # for row_i in range(DN.shape[0]): # # dn数据每10行使用一个定标系数 # jj = int(row_i / 10) # k3 = K[i, 3, jj] # k2 = K[i, 2, jj] # k1 = K[i, 1, jj] # k0 = K[i, 0, jj] # Rad[row_i, :] = (DN[row_i, :] * k3 ** 3 + DN[row_i, :] * k2 ** 2 + # DN[row_i, :] * k1 + k0) # / 100. # 全局信息赋值 ############################ # 对时间进行赋值合并 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)) # SV, BB for i in xrange(self.Band): BandName = 'CH_%02d' % (i + 1) SV = np.full(dshape, np.nan) BB = np.full(dshape, np.nan) for j in xrange(ary_lon.shape[0]): SV[j, :] = ary_sv[i][j / 10] BB[j, :] = ary_bb[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) 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 > 0, ary_sata < 36000) 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 > 0, ary_suna < 36000) 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.)) # 系数先不合并,暂时未用,数据格式无法统一了 # self.IR_Coeff = ary_IR_Coeff self.VIS_Coeff = ary_VIS_Coeff
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.))