def set_data_shape(self): """ set self.data_shape """ if self.resolution == 24000: satellite_type1 = ['METOP-A', 'METOP-B'] if self.satellite in satellite_type1: try: self.record = beatl2.ingest(self.in_file) # iasi 的观测点会变化 2640 2760等,所以根据数据长度获取,另外统一转成2维 self.data_shape = (self.record.time.shape[0], 1) print self.data_shape except Exception as e: print 'Open file error {}'.format(e) return else: raise ValueError('Cant read this satellite`s data.: {}'.format( self.satellite)) elif self.resolution == 24001: satellite_type1 = ['METOP-A', 'METOP-B'] if self.satellite in satellite_type1: try: # 'NCETCDF4' ncr = Dataset(self.in_file, 'r', format='NETCDF3_CLASSIC') data = ncr.variables['lat'][:] ncr.close() self.data_shape = (data.reshape(data.size, 1)).shape except Exception as e: print 'Open file error {}'.format(e) return else: raise ValueError("Cant handle this resolution: ".format( self.resolution))
def set_data_shape(self): """ set self.data_shape """ if self.resolution == 40000: satellite_type1 = ['METOP-A', 'METOP-B'] if self.satellite in satellite_type1: try: self.record = beatl2.ingest(self.in_file) # iasi 的观测点会变化 2640 2760等,所以根据数据长度获取,另外统一转成2维 self.data_shape = (self.record.time.shape[0], 1) print self.data_shape except Exception as e: print 'Open file error {}'.format(e) return else: raise ValueError('Cant read this satellite`s data.: {}'.format( self.satellite))
class CLASS_GOME_L1(): def __init__(self, BandLst): self.k = 1.98644746103858e-9 # 字典类型物理量 self.Ref = {} # 二维矩阵 self.Lons = [] self.Lats = [] self.Time = [] self.satAzimuth = [] self.satZenith = [] self.sunAzimuth = [] self.sunZenith = [] # 光谱信息 self.wavenumber = [] self.radiance = [] def Load(self, L1File): print u'读取 LEO所有数据信息......' if not os.path.isfile(L1File): print 'Error: %s not found' % L1File sys.exit(1) try: fp = coda.open(L1File) except Exception, e: print 'Open file error<%s> .' % (e) return try: # EPS = EUMETSAT Polar System atmospheric products (GOME-2 and IASI) # EPS = EUMETSAT极地大气系统产品(GOME-2和IASI)' # 获取文件头信息 product_class = coda.get_product_class(fp) product_type = coda.get_product_type(fp) product_version = coda.get_product_version(fp) product_format = coda.get_product_format(fp) product_size = coda.get_product_file_size(fp) print 'product_class ', product_class print 'product_type', product_type print 'product_version', product_version print 'product_format', product_format print 'product_size', product_size record = beatl2.ingest(L1File) WAVE_3 = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'WAVELENGTH_3') WAVE_4 = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'WAVELENGTH_4') LAMBDA_SMR = coda.fetch(fp, 'VIADR_SMR', -1, 'LAMBDA_SMR') SMR = coda.fetch(fp, 'VIADR_SMR', -1, 'SMR') print 'gome data is:' print record self.rec = record SUN_Z = coda.fetch( fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'SOLAR_ZENITH') SUN_A = coda.fetch( fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'SOLAR_AZIMUTH') SAT_Z = coda.fetch( fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'SAT_ZENITH') SAT_A = coda.fetch( fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'SAT_AZIMUTH') print '太阳方位角度长度', SUN_Z.shape, SUN_Z[0].shape # 数据观测总长度 dataLen = record.latitude.size dataCol = SUN_Z[0].shape[1] dataRow = SUN_Z.shape[0] # 角度存放内存 self.satZenith = np.full((dataLen, 1), -999.) self.satAzimuth = np.full((dataLen, 1), -999.) self.sunZenith = np.full((dataLen, 1), -999.) self.sunAzimuth = np.full((dataLen, 1), -999.) # 开始赋值 for i in xrange(dataLen): row, col = np.unravel_index(i, (dataRow, dataCol)) self.satAzimuth[i] = SAT_A[row][1][col] self.satZenith[i] = SAT_Z[row][1][col] self.sunAzimuth[i] = SUN_A[row][1][col] self.sunZenith[i] = SUN_Z[row][1][col] self.Lons = (record.longitude).reshape(dataLen, 1) self.Lats = (record.latitude).reshape(dataLen, 1) # 计算gome的辐亮度 self.radiance = record.spectral_radiance[:, 2048:] for m in xrange(dataLen): row, col = np.unravel_index(m, (dataRow, dataCol)) for i in xrange(2048): if i < 1024: self.radiance[m, i] = self.radiance[ m, i] * self.k / WAVE_3[row][i] else: self.radiance[m, i] = self.radiance[ m, i] * self.k / WAVE_4[row][i - 1024] # 计算太阳辐亮度 self.vec_Solar_L = np.zeros((2048,)) # 太阳辐亮度 self.vec_Solar_WL = np.zeros((2048,)) # 太阳辐亮度对应的波长 for i in xrange(2048): if i < 1024: self.vec_Solar_L[i] = ( SMR[0][2][i] * self.k) / LAMBDA_SMR[0][2][i] self.vec_Solar_WL[i] = LAMBDA_SMR[0][2][i] else: self.vec_Solar_L[i] = ( SMR[0][3][i - 1024] * self.k) / LAMBDA_SMR[0][3][i - 1024] self.vec_Solar_WL[i] = LAMBDA_SMR[0][3][i - 1024] print 'GOME数据观测长度 %d' % dataLen print '太阳辐亮度波长最小最大值' print np.min(self.vec_Solar_WL), self.vec_Solar_WL[0:3] print np.max(self.vec_Solar_WL) # 暂时取一个观测的光谱波数 self.wavenumber = record.wavelength[0, 2048:] print 'GOME辐亮度波长最小最大值,取第一个观测点' print np.min(self.wavenumber), self.wavenumber[0:3] print np.max(self.wavenumber) self.wavenumber = record.wavelength[9, 2048:] print 'GOME辐亮度波长最小最大值,取第十个观测点' print np.min(self.wavenumber), self.wavenumber[0:3] print np.max(self.wavenumber) v_ymd2seconds = np.vectorize(metop_ymd2seconds) T1 = v_ymd2seconds(record.time) self.Time = T1.reshape(dataLen, 1) # print time.gmtime(self.Time[0, 0]) except Exception as e: print str(e) sys.exit(1) finally: coda.close(fp)
class CLASS_IASI_L1(): def __init__(self, BandLst): # 字典类型物理量 self.Tbb = {} self.Rad = {} # 二维矩阵 self.Lons = [] self.Lats = [] self.Time = [] self.satAzimuth = [] self.satZenith = [] self.sunAzimuth = [] self.sunZenith = [] # 光谱信息 self.wavenumber = [] self.radiance = [] def Load(self, L1File): print u'读取 LEO所有数据信息......' if not os.path.isfile(L1File): print 'Error: %s not found' % L1File sys.exit(1) try: fp = coda.open(L1File) except Exception, e: print 'Open file error<%s> .' % (e) return try: # EPS = EUMETSAT Polar System atmospheric products (GOME-2 and IASI) # EPS = EUMETSAT极地大气系统产品(GOME-2和IASI)' # 获取文件头信息 product_class = coda.get_product_class(fp) product_type = coda.get_product_type(fp) product_version = coda.get_product_version(fp) product_format = coda.get_product_format(fp) product_size = coda.get_product_file_size(fp) print 'product_class ', product_class print 'product_type', product_type print 'product_version', product_version print 'product_format', product_format print 'product_size', product_size record = beatl2.ingest(L1File) print record SAT_angle = coda.fetch(fp, 'MDR', -1, 'MDR', 'GGeoSondAnglesMETOP') SUN_angle = coda.fetch(fp, 'MDR', -1, 'MDR', 'GGeoSondAnglesSUN') all_sun_angle = [] all_sat_angle = [] for i in xrange(len(SAT_angle)): tmp_sat = SAT_angle[i].reshape(-1) tmp_sun = SUN_angle[i].reshape(-1) if len(all_sat_angle) == 0: all_sat_angle = tmp_sat all_sun_angle = tmp_sun else: all_sat_angle = np.concatenate((all_sat_angle, tmp_sat), 0) all_sun_angle = np.concatenate((all_sun_angle, tmp_sun), 0) iasiLen = len(record.longitude) self.satZenith = (all_sat_angle[0::2]).reshape(iasiLen, 1) self.satAzimuth = (all_sat_angle[1::2]).reshape(iasiLen, 1) self.sunZenith = (all_sun_angle[0::2]).reshape(iasiLen, 1) self.sunAzimuth = (all_sun_angle[1::2]).reshape(iasiLen, 1) self.Lons = (record.longitude).reshape(iasiLen, 1) self.Lats = (record.latitude).reshape(iasiLen, 1) self.radiance = record.spectral_radiance * 10**7 # 暂时取一个观测的光谱波数 self.wavenumber = record.wavenumber[0, :] v_ymd2seconds = np.vectorize(metop_ymd2seconds) T1 = v_ymd2seconds(record.time) self.Time = T1.reshape(iasiLen, 1) except Exception as e: print str(e) sys.exit(1) finally: coda.close(fp)