コード例 #1
0
    def set_file_attr(self):
        """
        seft self.file_att is dict
        """
        data = dict()
        if self.resolution == 40000:
            satellite_type1 = ['METOP-A', 'METOP-B']
            if self.satellite in satellite_type1:

                try:
                    fp = coda.open(self.in_file)
                    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)
                    coda.close(fp)
                except Exception as e:
                    print str(e)
                    return

                data['class'] = product_class
                data['size'] = product_size
                data['type'] = product_type
                data['version'] = product_version
                data['format'] = product_format
                self.file_attr = data
            else:
                raise ValueError('Cant read this satellite`s data.: {}'.format(
                    self.satellite))
コード例 #2
0
    def set_file_attr(self):
        """
        seft self.file_att is dict
        """
        data = dict()
        if self.resolution == 24000:
            satellite_type1 = ['METOP-A', 'METOP-B']
            if self.satellite in satellite_type1:

                try:
                    fp = coda.open(self.in_file)
                    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)
                    coda.close(fp)
                except Exception as e:
                    print str(e)
                    return

                data['class'] = product_class
                data['size'] = product_size
                data['type'] = product_type
                data['version'] = product_version
                data['format'] = product_format
                self.file_attr = data
            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.ncattrs()
                    ncr.close()

                except Exception as e:
                    print str(e)
                    return

                self.file_attr = data
            else:
                raise ValueError('Cant read this satellite`s data.: {}'.format(
                    self.satellite))
        else:
            raise ValueError("Cant handle this resolution: ".format(
                self.resolution))
コード例 #3
0
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)
コード例 #4
0
ファイル: pb_drc_IASI_L1.py プロジェクト: NingAnMe/pb
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)
コード例 #5
0
class GOME_COMM():
    def __init__(self):

        self.k = 1.98644746103858e-9

        # 中心 纬度 经度
        self.centre_lat = np.zeros((30, 24))
        self.centre_lon = np.zeros((30, 24))
        self.centre_row = np.zeros((30, 24))
        self.centre_col = np.zeros((30, 24))
        # 角点 纬度 经度
        self.corner_lat = np.zeros((30, 24, 4))
        self.corner_lon = np.zeros((30, 24, 4))
        self.corner_row = np.zeros((30, 24, 4))
        self.corner_col = np.zeros((30, 24, 4))

        self.sun_Z = np.zeros((30, 24))  # 太阳天顶角
        self.sun_A = np.zeros((30, 24))  # 太阳方位角
        self.sat_Z = np.zeros((30, 24))  # 卫星天顶角
        self.sat_A = np.zeros((30, 24))  # 卫星方位角

        self.band3 = np.zeros((30, 24, 1024))  # 辐射值
        self.band4 = np.zeros((30, 24, 1024))
        self.band3_ERR_RAD = np.zeros((30, 24, 1024))
        self.band3_STOKES_FRACTION = np.zeros((30, 24, 1024))
        self.band4_ERR_RAD = np.zeros((30, 24, 1024))
        self.band4_STOKES_FRACTION = np.zeros((30, 24, 1024))
        self.wave3 = np.zeros((30, 1024))  # 波长
        self.wave4 = np.zeros((30, 1024))

        #         self.LAMBDA_SMR3 = np.zeros((1, 1024))
        #         self.LAMBDA_SMR4 = np.zeros((1, 1024))
        #         self.SMR3 = np.zeros((1, 1024))
        #         self.SMR4 = np.zeros((1, 1024))
        #         self.E_SMR3 = np.zeros((1, 1024))
        #         self.E_SMR4 = np.zeros((1, 1024))
        #         self.E_REL_SUN3 = np.zeros((1, 1024))
        #         self.E_REL_SUN4 = np.zeros((1, 1024))

        self.E_SMR3 = np.zeros((1024))
        self.E_SMR4 = np.zeros((1024))
        self.E_REL_SUN3 = np.zeros((1024))
        self.E_REL_SUN4 = np.zeros((1024))

        self.arr_GOME_L = np.zeros((2048, 30, 24))  # 辐亮度
        self.arr_GOME_WL = np.zeros((2048, 30, 24))  # 辐亮度对应的波长

        self.vec_Solar_L = np.zeros((2, 1024))  # 太阳辐亮度
        self.vec_Solar_WL = np.zeros((2, 1024))  # 太阳辐亮度对应的波长

        # 如下变量是通过卷积计算的
        self.vec_Radiance_Solar = np.zeros(15)
        self.vec_Radiance = np.zeros((15, 30, 24))
        self.arr_Ref = np.zeros((15, 30, 24))

    def init_gome(self, in_proj_cfg, des_sensor):
        '''
        读取yaml格式配置文件
        '''
        if not os.path.isfile(in_proj_cfg):
            print 'Not Found %s' % in_proj_cfg
            sys.exit(-1)

        with open(in_proj_cfg, 'r') as stream:
            cfg = yaml.load(stream)

        self.sat1 = cfg['INFO']['sat']
        self.sensor1 = cfg['INFO']['sensor']
        self.sensor2 = des_sensor
        self.ymd = cfg['INFO']['ymd']

        self.ifile = cfg['PATH']['ipath']
        self.ofile = cfg['PATH']['opath']

        self.cmd = cfg['PROJ']['cmd']
        self.col = cfg['PROJ']['col']
        self.row = cfg['PROJ']['row']
        self.res = cfg['PROJ']['res']

    def read_gome(self, infile):
        # 打开gome文件
        try:
            fp = coda.open(infile)
        except Exception, e:
            print 'Open file error<%s> .' % (e)
            return
        # 获取文件头信息
        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)
        # EPS = EUMETSAT Polar System atmospheric products (GOME-2 and IASI)
        # EUMETSAT极地大气系统产品(GOME-2和IASI)'
        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

        CENTRE = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'CENTRE')
        CORNER = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'GEO_EARTH', 'CORNER')
        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')
        BAND_3 = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'BAND_3')
        BAND_4 = coda.fetch(fp, 'MDR', -1, 'Earthshine', 'BAND_4')
        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')
        E_SMR = coda.fetch(fp, 'VIADR_SMR', -1, 'E_SMR')
        E_REL_SUN = coda.fetch(fp, 'VIADR_SMR', -1, 'E_REL_SUN')

        #         fp.close()

        #         print 'CENTRE', CENTRE.shape, CENTRE[0].shape
        #         print 'CORNER', CORNER.shape, CORNER[0].shape
        #         print 'SUN_Z', SUN_Z.shape, SUN_Z[0].shape
        #         print 'SUN_A', SUN_A.shape, SUN_A[0].shape
        #         print 'SAT_Z', SAT_Z.shape, SAT_Z[0].shape
        #         print 'SAT_A', SAT_A.shape, SAT_A[0].shape
        #         print 'BAND_3', BAND_3.shape, BAND_3[0].shape
        #         print 'BAND_4', BAND_4.shape, BAND_4[0].shape
        #         print 'WAVE_3', WAVE_3.shape, WAVE_3[0].shape
        #         print 'WAVE_4', WAVE_4.shape, WAVE_4[0].shape
        #         print 'LAMBDA_SMR', LAMBDA_SMR.shape, LAMBDA_SMR[0].shape
        #         print 'SMR', SMR.shape, SMR[0].shape
        #         print 'E_SMR', E_SMR.shape, E_SMR[0].shape
        #         print 'E_REL_SUN', E_REL_SUN.shape, E_REL_SUN[0].shape
        #         print LAMBDA_SMR[0][0][1023]
        #         print BAND_3[0][23][1023].RAD
        #         print self.band3.shape

        for i in range(30):
            count = coda.get_size(fp, 'MDR', i, 'Earthshine', 'BAND_3')
            for j in range(int(count[0] * 0.75)):
                for m in range(1024):

                    self.band3[i][j][m] = BAND_3[i][j][m].RAD
                    self.band3_ERR_RAD[i][j][m] = BAND_3[i][j][m].ERR_RAD
                    self.band3_STOKES_FRACTION[i][j][m] = BAND_3[i][j][
                        m].STOKES_FRACTION
                    self.band4[i][j][m] = BAND_4[i][j][m].RAD
                    self.band4_ERR_RAD[i][j][m] = BAND_4[i][j][m].ERR_RAD
                    self.band4_STOKES_FRACTION[i][j][m] = BAND_4[i][j][
                        m].STOKES_FRACTION

        for m in range(2048):
            for i in range(30):
                count = coda.get_size(fp, 'MDR', i, 'Earthshine', 'BAND_3')
                for j in range(int(count[0] * 0.75)):
                    if m < 1024:
                        if BAND_3[i][j][m].RAD < 0:
                            BAND_3[i][j][m].RAD = 0
                        self.arr_GOME_L[m][i][j] = (BAND_3[i][j][m].RAD *
                                                    self.k) / WAVE_3[i][m]
                        self.arr_GOME_WL[m][i][j] = WAVE_3[i][m]

                    else:
                        if BAND_4[i][j][m - 1024].RAD < 0:
                            BAND_4[i][j][m - 1024].RAD = 0
                        self.arr_GOME_L[m][i][j] = (
                            BAND_4[i][j][m - 1024].RAD *
                            self.k) / WAVE_4[i][m - 1024]
                        self.arr_GOME_WL[m][i][j] = WAVE_4[i][m - 1024]

        for i in range(2):
            for j in range(1024):
                if i == 0:
                    self.vec_Solar_L[i][j] = (
                        SMR[0][2][j] * self.k) / LAMBDA_SMR[0][2][j]  # 太阳辐亮度
                    self.vec_Solar_WL[i][j] = LAMBDA_SMR[0][2][j]
                    self.E_SMR3[j] = E_SMR[0][2][j]
                    self.E_REL_SUN3[j] = E_REL_SUN[0][2][j]
                elif i == 1:
                    self.vec_Solar_L[i][j] = (
                        SMR[0][3][j] * self.k) / LAMBDA_SMR[0][3][j]  # 太阳辐亮度
                    self.vec_Solar_WL[i][j] = LAMBDA_SMR[0][3][j]
                    self.E_SMR4[j] = E_SMR[0][3][j]
                    self.E_REL_SUN4[j] = E_REL_SUN[0][3][j]

        for i in range(30):
            for j in range(24):
                self.sun_A[i][j] = SUN_A[i][1][j]
                self.sun_Z[i][j] = SUN_Z[i][1][j]
                self.sat_A[i][j] = SAT_A[i][1][j]
                self.sun_Z[i][j] = SAT_Z[i][1][j]
                self.centre_lat[i][j] = CENTRE[i][j].latitude
                self.centre_lon[i][j] = CENTRE[i][j].longitude

        for i in range(30):
            for j in range(24):
                for m in range(4):
                    self.corner_lat[i][j][m] = CORNER[i][m][j].latitude
                    self.corner_lon[i][j][m] = CORNER[i][m][j].longitude
        coda.close(fp)