示例#1
0
def AtmosphericCorrection(BandId):
    global metedata, config, SatelliteID, SensorID
    #读取头文件
    dom = xml.dom.minidom.parse(metedata)

    # 6S模型
    s = SixS()

    # 传感器类型 自定义
    s.geometry = Geometry.User()
    s.geometry.solar_z = 90 - float(
        dom.getElementsByTagName('SolarZenith')[0].firstChild.data)
    s.geometry.solar_a = float(
        dom.getElementsByTagName('SolarAzimuth')[0].firstChild.data)
    # s.geometry.view_z = float(dom.getElementsByTagName('SatelliteZenith')[0].firstChild.data)
    # s.geometry.view_a = float(dom.getElementsByTagName('SatelliteAzimuth')[0].firstChild.data)
    s.geometry.view_z = 0
    s.geometry.view_a = 0
    # 日期
    DateTimeparm = dom.getElementsByTagName('CenterTime')[0].firstChild.data
    DateTime = DateTimeparm.split(' ')
    Date = DateTime[0].split('-')
    s.geometry.month = int(Date[1])
    s.geometry.day = int(Date[2])

    # print(s.geometry)
    # 中心经纬度
    TopLeftLat = float(
        dom.getElementsByTagName('TopLeftLatitude')[0].firstChild.data)
    TopLeftLon = float(
        dom.getElementsByTagName('TopLeftLongitude')[0].firstChild.data)
    TopRightLat = float(
        dom.getElementsByTagName('TopRightLatitude')[0].firstChild.data)
    TopRightLon = float(
        dom.getElementsByTagName('TopRightLongitude')[0].firstChild.data)
    BottomRightLat = float(
        dom.getElementsByTagName('BottomRightLatitude')[0].firstChild.data)
    BottomRightLon = float(
        dom.getElementsByTagName('BottomRightLongitude')[0].firstChild.data)
    BottomLeftLat = float(
        dom.getElementsByTagName('BottomLeftLatitude')[0].firstChild.data)
    BottomLeftLon = float(
        dom.getElementsByTagName('BottomLeftLongitude')[0].firstChild.data)

    ImageCenterLat = (TopLeftLat + TopRightLat + BottomRightLat +
                      BottomLeftLat) / 4

    # 大气模式类型
    if ImageCenterLat > -15 and ImageCenterLat < 15:
        s.atmos_profile = AtmosProfile.PredefinedType(AtmosProfile.Tropical)

    if ImageCenterLat > 15 and ImageCenterLat < 45:
        if s.geometry.month > 4 and s.geometry.month < 9:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.MidlatitudeSummer)
        else:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.MidlatitudeWinter)

    if ImageCenterLat > 45 and ImageCenterLat < 60:
        if s.geometry.month > 4 and s.geometry.month < 9:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.SubarcticSummer)
        else:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.SubarcticWinter)

    # 气溶胶类型大陆
    s.aero_profile = AtmosProfile.PredefinedType(AeroProfile.Continental)

    # 下垫面类型
    s.ground_reflectance = GroundReflectance.HomogeneousLambertian(0.36)

    # 550nm气溶胶光学厚度,对应能见度为40km
    s.aot550 = 0.14497

    # 通过研究去区的范围去求DEM高度。
    pointUL = dict()
    pointDR = dict()
    pointUL["lat"] = max(TopLeftLat, TopRightLat, BottomRightLat,
                         BottomLeftLat)
    pointUL["lon"] = min(TopLeftLon, TopRightLon, BottomRightLon,
                         BottomLeftLon)
    pointDR["lat"] = min(TopLeftLat, TopRightLat, BottomRightLat,
                         BottomLeftLat)
    pointDR["lon"] = max(TopLeftLon, TopRightLon, BottomRightLon,
                         BottomLeftLon)
    meanDEM = (MeanDEM(pointUL, pointDR)) * 0.001

    # 研究区海拔、卫星传感器轨道高度
    s.altitudes = Altitudes()
    s.altitudes.set_target_custom_altitude(meanDEM)
    s.altitudes.set_sensor_satellite_level()

    # 校正波段(根据波段名称)
    if BandId == 1:
        SRFband = config["Parameter"][SatelliteID][SensorID]["SRF"]["1"]
        s.wavelength = Wavelength(0.450, 0.520, SRFband)

    elif BandId == 2:
        SRFband = config["Parameter"][SatelliteID][SensorID]["SRF"]["2"]

        s.wavelength = Wavelength(0.520, 0.590, SRFband)

    elif BandId == 3:
        SRFband = config["Parameter"][SatelliteID][SensorID]["SRF"]["3"]

        s.wavelength = Wavelength(0.630, 0.690, SRFband)

    elif BandId == 4:
        SRFband = config["Parameter"][SatelliteID][SensorID]["SRF"]["4"]
        s.wavelength = Wavelength(0.770, 0.890, SRFband)

    s.atmos_corr = AtmosCorr.AtmosCorrLambertianFromReflectance(-0.1)

    # 运行6s大气模型
    s.run()
    xa = s.outputs.coef_xa
    xb = s.outputs.coef_xb
    xc = s.outputs.coef_xc
    # x = s.outputs.values
    return (xa, xb, xc)
def AtmosphericCorrection(BandId):
    global data
    # 6S模型
    s = SixS()

    s.geometry = Geometry.User()
    s.geometry.solar_z = 90 - float(''.join(
        re.findall('SUN_ELEVATION.+', data2)).split("=")[1])
    s.geometry.solar_a = float(''.join(re.findall('SUN_AZIMUTH.+',
                                                  data2)).split("=")[1])
    s.geometry.view_z = 0
    s.geometry.view_a = 0

    # 日期
    Dateparm = ''.join(re.findall('DATE_ACQUIRED.+', data2)).split("=")
    Date = Dateparm[1].split('-')

    s.geometry.month = int(Date[1])
    s.geometry.day = int(Date[2])

    # 中心经纬度
    point1lat = float(''.join(re.findall('CORNER_UL_LAT_PRODUCT.+',
                                         data2)).split("=")[1])
    point1lon = float(''.join(re.findall('CORNER_UL_LON_PRODUCT.+',
                                         data2)).split("=")[1])
    point2lat = float(''.join(re.findall('CORNER_UR_LAT_PRODUCT.+',
                                         data2)).split("=")[1])
    point2lon = float(''.join(re.findall('CORNER_UR_LON_PRODUCT.+',
                                         data2)).split("=")[1])
    point3lat = float(''.join(re.findall('CORNER_LL_LAT_PRODUCT.+',
                                         data2)).split("=")[1])
    point3lon = float(''.join(re.findall('CORNER_LL_LON_PRODUCT.+',
                                         data2)).split("=")[1])
    point4lat = float(''.join(re.findall('CORNER_LR_LAT_PRODUCT.+',
                                         data2)).split("=")[1])
    point4lon = float(''.join(re.findall('CORNER_LR_LON_PRODUCT.+',
                                         data2)).split("=")[1])

    sLongitude = (point1lon + point2lon + point3lon + point4lon) / 4
    sLatitude = (point1lat + point2lat + point3lat + point4lat) / 4

    # 大气模式类型
    if sLatitude > -15 and sLatitude <= 15:
        s.atmos_profile = AtmosProfile.PredefinedType(AtmosProfile.Tropical)

    if sLatitude > 15 and sLatitude <= 45:
        if s.geometry.month > 4 and s.geometry.month <= 9:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.MidlatitudeSummer)
        else:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.MidlatitudeWinter)

    if sLatitude > 45 and sLatitude <= 60:
        if s.geometry.month > 4 and s.geometry.month <= 9:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.SubarcticSummer)
        else:
            s.atmos_profile = AtmosProfile.PredefinedType(
                AtmosProfile.SubarcticWinter)

    # 气溶胶类型大陆
    s.aero_profile = AtmosProfile.PredefinedType(AeroProfile.Continental)

    # 目标地物??????
    s.ground_reflectance = GroundReflectance.HomogeneousLambertian(0.36)

    # 550nm气溶胶光学厚度,根据日期从MODIS处获取。
    #s.visibility=40.0
    s.aot550 = 0.14497

    # 通过研究去区的范围去求DEM高度。
    pointUL = dict()
    pointDR = dict()
    pointUL["lat"] = point1lat
    pointUL["lon"] = point1lon
    pointDR["lat"] = point4lat
    pointDR["lon"] = point2lon
    meanDEM = (MeanDEM(pointUL, pointDR)) * 0.001

    # 研究区海拔、卫星传感器轨道高度
    s.altitudes = Altitudes()
    s.altitudes.set_target_custom_altitude(meanDEM)
    s.altitudes.set_sensor_satellite_level()

    # 校正波段(根据波段名称)
    if BandId == '1':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B1)

    elif BandId == '2':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B2)

    elif BandId == '3':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B3)

    elif BandId == '4':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B4)

    elif BandId == '5':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B5)

    elif BandId == '6':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B6)

    elif BandId == '7':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B7)

    elif BandId == '8':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B8)

    elif BandId == '9':
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_OLI_B9)

    # 下垫面非均一、朗伯体
    s.atmos_corr = AtmosCorr.AtmosCorrLambertianFromReflectance(-0.1)

    # 运行6s大气模型
    s.run()

    xa = s.outputs.coef_xa
    xb = s.outputs.coef_xb
    xc = s.outputs.coef_xc
    x = s.outputs.values
    return (xa, xb, xc)
示例#3
0
def BasicParameters():
    '''
    获取6s大气校正所需的参数
    '''
    global dom
    SixsParameters = dict()
    #太阳天顶角、方位角
    SunAngle = dom.getElementsByTagName('Mean_Sun_Angle')
    SixsParameters["SolarZenithAngle"] = float(
        SunAngle[0].getElementsByTagName('ZENITH_ANGLE')[0].firstChild.data)
    SixsParameters["SolarAzimuthAngle"] = float(
        SunAngle[0].getElementsByTagName('AZIMUTH_ANGLE')[0].firstChild.data)

    #卫星天顶角、方位角
    ViewAngles = dom.getElementsByTagName('Mean_Viewing_Incidence_Angle')
    ViewZeniths = dict()
    ViewAzimuths = dict()

    for angle in ViewAngles:
        ViewAngle = int(angle.getAttribute('bandId'))
        #print(ViewAngle)
        ViewZeniths[ViewAngle + 1] = float(
            angle.getElementsByTagName('ZENITH_ANGLE')[0].firstChild.data)
        ViewAzimuths[ViewAngle + 1] = float(
            angle.getElementsByTagName('AZIMUTH_ANGLE')[0].firstChild.data)

    SixsParameters["ViewZenithAngle"] = ViewZeniths
    SixsParameters["ViewAzimuthAngle"] = ViewAzimuths
    # 日期:月、日
    Date = dom.getElementsByTagName('SENSING_TIME')[0].firstChild.data.split(
        'T')[0]
    SixsParameters["ImgMonth"] = int(Date.split('-')[1])
    SixsParameters["ImgDay"] = int(Date.split('-')[2])

    #求影像中心经纬度
    PointULX = int(dom.getElementsByTagName('ULX')[0].firstChild.data)
    PointULY = int(dom.getElementsByTagName('ULY')[0].firstChild.data)

    Imgsizes = dom.getElementsByTagName('Size')

    for Imgsize in Imgsizes:
        Resolution = Imgsize.getAttribute('resolution')
        if Resolution == '10':
            SixsParameters["Nrows"] = int(
                Imgsize.getElementsByTagName('NROWS')[0].firstChild.data)
            SixsParameters["Ncols"] = int(
                Imgsize.getElementsByTagName('NCOLS')[0].firstChild.data)

    PointBRX = PointULX + 10 * SixsParameters["Ncols"]
    PointBRY = PointULY - 10 * SixsParameters["Nrows"]

    # 将投影坐标转为经纬度坐标(具体的投影坐标系由给定数据确定)
    Proj = dom.getElementsByTagName('HORIZONTAL_CS_CODE')[0].firstChild.data
    ProjCode = int(Proj.split(':')[1])

    source = osr.SpatialReference()
    source.ImportFromEPSG(ProjCode)
    target = osr.SpatialReference()
    target.ImportFromEPSG(4326)
    ct = osr.CoordinateTransformation(source, target)
    CoordsUL, CoordsBR = ct.TransformPoints([(PointULX, PointULY),
                                             (PointBRX, PointBRY)])

    ULLat = CoordsUL[0]
    ULLon = CoordsUL[1]
    BRLat = CoordsBR[0]
    BRLon = CoordsBR[1]

    sLongitude = (ULLon + BRLon) / 2
    sLatitude = (ULLat + ULLat) / 2

    #大气模式类型
    if sLatitude > -15 and sLatitude <= 15:
        SixsParameters["AtmosphericProfile"] = 1  #Tropical
    elif sLatitude > 15 and sLatitude <= 45:
        if SixsParameters["ImgMonth"] > 4 and SixsParameters["ImgMonth"] <= 9:
            SixsParameters["AtmosphericProfile"] = 2  #MidlatitudeSummer
        else:
            SixsParameters["AtmosphericProfile"] = 3  #MidlatitudeWinter
    elif sLatitude > 45 and sLatitude <= 60:
        if SixsParameters["ImgMonth"] > 4 and SixsParameters["ImgMonth"] <= 9:
            SixsParameters["AtmosphericProfile"] = 4  #SubarctivWinter
        else:
            SixsParameters["AtmosphericProfile"] = 5  #SubarcticWinter

    pointUL = dict()
    pointDR = dict()
    pointUL["lat"] = ULLat
    pointUL["lon"] = ULLon
    pointDR["lat"] = BRLat
    pointDR["lon"] = BRLon
    SixsParameters["meanDEM"] = (MeanDEM(pointUL, pointDR)) * 0.001

    return SixsParameters