使用Python使用大气校正法计算地表温度

本文介绍了使用Python进行地表温度计算的方法,通过读取遥感数据、定标处理、NDVI计算、植被覆盖度分析,最终得出地表比辐射率和地表温度。过程包括大气参数查询和一系列的图像处理步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用Python使用大气校正法计算地表温度

前言

也有段时间没有跟新博客了,这次博客就是用新学的python语言来进行一个地表温度的计算,也算是承接了之前的内容吧!


一、具体原理及方法

这里不再赘述,有关原理及方法可以查阅我之前的博客文章https://blog.youkuaiyun.com/qq_44935981/article/details/90319487?spm=1001.2014.3001.5501

二、代码及步骤如下

1.引入库

代码如下:

import os
import numpy as np
from osgeo import gdal
import glob
import math
import matplotlib.pyplot as plt
#author sansuixueshi

2.读入数据及处理

代码如下:

input_path = 'E:/study/2018.4.09/2018.4.9/LC81300372018099LGN00/'
output_path = 'E:/study/2018.4.09/2018.4.9/LC81300372018099LGN00/out_data/'
file_all = os.listdir(input_path)
file_tail='.TIF'
radiance_scale=[1.2519E-02,1.2819E-02,1.1813E-02,9.9612E-03,6.0957E-03,1.5160E-03,5.1096E-04,1.1273E-02,2.3824E-03,3.3420E-04,3.3420E-04]
radiance_add=[-62.59278,-64.09577,-59.06370,-49.80584,-30.47869,-7.57977,-2.55479,-56.36651,-11.91176,0.10000,0.10000]
i=0

if not os.path.exists(output_path):
    os.mkdir(output_path)

for file_i in file_all:
    if file_i.endswith(file_tail):
        file_name = input_path + file_i
        (prename,suffix) = os.path.split(file_i)
        if i == 5:
            band = gdal.Open(file_name)
            red = band.ReadAsArray()*radiance_scale[3]+radiance_add[3]
            red = red.astype(np.float32)
        
        if i==6:
            band = gdal.Open(file_name)
            nir = band.ReadAsArray()*radiance_scale[4]+radiance_add[4]
            nir = nir.astype(np.float32)
        
        if i==1:
            band = gdal.Open(file_name)
            thermal = band.ReadAsArray()*radiance_scale[9]+radiance_add[9]
            thermal = thermal.astype(np.float32)
            #输出第十波段影像
            gtiff_driver=gdal.GetDriverByName('GTiff')
            out_file = gtiff_driver.Create(
            output_path + 'band_10.tif',
            thermal.shape[1],thermal.shape[0],1,6
            )
            out_file.SetProjection(out_file.GetProjection())
            out_file.SetGeoTransform(out_file.GetGeoTransform())
            out_band=out_file.GetRasterBand(1)
            out_band.WriteArray(thermal)
            out_band.FlushCache()
        
        i=i+1

ndvi = (nir - red)/(nir + red)
nan_index=np.isnan(ndvi)
ndvi[nan_index]=0
#将输出影像转为geotiff格式
gtiff_driver=gdal.GetDriverByName('GTiff')
out_file = gtiff_driver.Create(
    output_path + 'ndvi.tif',
    ndvi.shape[1],ndvi.shape[0],1,6
)
out_file.SetProjection(out_file.GetProjection())
out_file.SetGeoTransform(out_file.GetGeoTransform())
#将影像展示,这一步可以省略
out_band=out_file.GetRasterBand(1)
out_band.WriteArray(ndvi)
out_band.FlushCache()
plt.imshow(ndvi)
plt.axis('off')
plt.show()

#计算植被覆盖度
one_index = np.where(ndvi > 0.7)
zero_index = np.where(ndvi < 0.05)
ndvi[one_index] = 1.0
ndvi[zero_index] = 0.0
pv = ndvi

#计算地表比辐射率
bfsl = pv*0.004 + 0.986

#查询大气剖面参数,网站:http://atmcorr.gsfc.nasa.gov/
t=0.96
lu=0.26
ld=0.46
black_lightness=(thermal - lu - t*(1 - bfsl)*ld)/(t*bfsl)

#计算地表温度
num = 774.89/black_lightness + 1
LST=(1321.08)/np.log(num)#减去273即为摄氏温度

#输出LST影像
gtiff_driver = gdal.GetDriverByName('GTiff')
out_file = gtiff_driver.Create(
    output_path + 'LST.tif',
    LST.shape[1],LST.shape[0],1,6
)
out_file.SetProjection(out_file.GetProjection())
out_file.SetGeoTransform(out_file.GetGeoTransform())
out_band=out_file.GetRasterBand(1)
out_band.WriteArray(LST)
out_band.FlushCache()

#author sansuixueshi

处理结果与全部代码

代码如下:

import os
import numpy as np
from osgeo import gdal
import glob
import math
import matplotlib.pyplot as plt

#读取影像数据对应波段并进行定标操作
input_path = 'E:/study/2018.4.09/2018.4.9/LC81300372018099LGN00/'
output_path = 'E:/study/2018.4.09/2018.4.9/LC81300372018099LGN00/out_data/'
file_all = os.listdir(input_path)
file_tail='.TIF'
radiance_scale=[1.2519E-02,1.2819E-02,1.1813E-02,9.9612E-03,6.0957E-03,1.5160E-03,5.1096E-04,1.1273E-02,2.3824E-03,3.3420E-04,3.3420E-04]
radiance_add=[-62.59278,-64.09577,-59.06370,-49.80584,-30.47869,-7.57977,-2.55479,-56.36651,-11.91176,0.10000,0.10000]
i=0

if not os.path.exists(output_path):
    os.mkdir(output_path)

for file_i in file_all:
    if file_i.endswith(file_tail):
        file_name = input_path + file_i
        (prename,suffix) = os.path.split(file_i)
        if i == 5:
            band = gdal.Open(file_name)
            red = band.ReadAsArray()*radiance_scale[3]+radiance_add[3]
            red = red.astype(np.float32)
        
        if i==6:
            band = gdal.Open(file_name)
            nir = band.ReadAsArray()*radiance_scale[4]+radiance_add[4]
            nir = nir.astype(np.float32)
        
        if i==1:
            band = gdal.Open(file_name)
            thermal = band.ReadAsArray()*radiance_scale[9]+radiance_add[9]
            thermal = thermal.astype(np.float32)
            #输出第十波段影像
            gtiff_driver=gdal.GetDriverByName('GTiff')
            out_file = gtiff_driver.Create(
            output_path + 'band_10.tif',
            thermal.shape[1],thermal.shape[0],1,6
            )
            out_file.SetProjection(out_file.GetProjection())
            out_file.SetGeoTransform(out_file.GetGeoTransform())
            out_band=out_file.GetRasterBand(1)
            out_band.WriteArray(thermal)
            out_band.FlushCache()
        
        i=i+1

ndvi = (nir - red)/(nir + red)
nan_index=np.isnan(ndvi)
ndvi[nan_index]=0
#将输出影像转为geotiff格式
gtiff_driver=gdal.GetDriverByName('GTiff')
out_file = gtiff_driver.Create(
    output_path + 'ndvi.tif',
    ndvi.shape[1],ndvi.shape[0],1,6
)
out_file.SetProjection(out_file.GetProjection())
out_file.SetGeoTransform(out_file.GetGeoTransform())
#将影像展示,这一步可以省略
out_band=out_file.GetRasterBand(1)
out_band.WriteArray(ndvi)
out_band.FlushCache()
plt.imshow(ndvi)
plt.axis('off')
plt.show()

#计算植被覆盖度
one_index = np.where(ndvi > 0.7)
zero_index = np.where(ndvi < 0.05)
ndvi[one_index] = 1.0
ndvi[zero_index] = 0.0
pv = ndvi

#计算地表比辐射率
bfsl = pv*0.004 + 0.986

#查询大气剖面参数,网站:http://atmcorr.gsfc.nasa.gov/
t=0.96
lu=0.26
ld=0.46
black_lightness=(thermal - lu - t*(1 - bfsl)*ld)/(t*bfsl)

#计算地表温度
num = 774.89/black_lightness + 1
LST=(1321.08)/np.log(num)

#输出LST影像
gtiff_driver = gdal.GetDriverByName('GTiff')
out_file = gtiff_driver.Create(
    output_path + 'LST.tif',
    LST.shape[1],LST.shape[0],1,6
)
out_file.SetProjection(out_file.GetProjection())
out_file.SetGeoTransform(out_file.GetGeoTransform())
out_band=out_file.GetRasterBand(1)
out_band.WriteArray(LST)
out_band.FlushCache()

#author sansuixueshi


在这里插入图片描述
LST及其统计数据,如果要进行摄氏温度计算可以在计算出减去273
NDVI计算结果图如上
第十波段定标图如上
结果图如上

### 回答1: 地表温度反演是利用遥感技术获取地表温度的方。在Python中,我们可以使用一些常用的遥感数据处理库来进行地表温度反演。 首先,我们可以使用PythonNumPy库来处理遥感数据。通过读取热红外遥感影像数据,可以获取地表的辐射亮温数据。接着,我们可以使用热辐射转换公式来将辐射亮温转换为地表温度。 其次,可以使用Python的GDAL库来读取和处理遥感影像数据。GDAL可以读取各种格式的遥感影像数据,并提供了一些图像处理的函数,例如图像的裁剪、缩放和投影转换。 还可以使用Python的OpenCV库进行图像处理。通过对遥感影像数据进行预处理,例如校正、去除云状物等,可以提高地表温度反演的准确性。 另外,Python的matplotlib库可以帮助我们对地表温度反演结果进行可视化。通过绘制热图或热力图,可以清晰地展示地表温度分布情况,并且可以通过颜色映射来显示温度的不同等级。 总结来说,通过Python中的NumPy、GDAL、OpenCV和matplotlib等库的配合使用,我们可以实现地表温度的反演。这些库提供了丰富的数据处理和图像处理函数,帮助我们处理和分析遥感影像数据,并得到高质量的地表温度结果。 ### 回答2: 地表温度反演指的是通过遥感资料或其他数据,利用计算机程序推算出地表温度分布情况。Python是一种流行的编程语言,在地表温度反演中可以用Python编写相应的程序。 首先,要实现地表温度反演,需要准备相应的遥感资料或其他数据,如卫星遥感数据、地面观测数据等。这些数据可以使用Python的库来读取和处理,如Pandas、Numpy等。 其次,需要借助一些数学、物理模型来推算地表温度。例如,可以使用辐射传输模型,根据遥感数据中的辐射亮度或辐射通量信息,推算出地表温度。这需要运用一些数值计算和优化算Python提供了SciPy等库来支持这些计算任务。 另外,还可以结合机器学习或深度学习的方进行地表温度反演。可以使用Python的一些机器学习库,如Scikit-Learn、TensorFlow等,通过训练模型来预测地表温度。这需要准备一些已知的地表温度数据作为训练集,并进行数据预处理、特征工程、模型训练和预测等步骤。 最后,可以利用Python的可视化库,如Matplotlib、Seaborn等,将反演结果进行可视化展示。通过绘制地表温度分布的热图或等温线图,可以更直观地了解温度变化的情况。 总结起来,地表温度反演是利用遥感数据和计算机程序,推算出地表温度分布情况。Python提供了丰富的库和工具,能够方便地处理数据、应用数学物理模型、进行机器学习和深度学习,并将结果进行可视化展示。 ### 回答3: 地表温度反演是利用遥感数据和气象数据等方来推测地表温度情况。Python是一种广泛应用于科学计算和数据分析的编程语言,具有丰富的库和功能,可以用来实现地表温度反演。 在地表温度反演中,首先需要收集和整理遥感数据和气象数据,比如陆地表温度数据、卫星云图数据、气象站观测数据等。 接下来,通过Python提供的数据处理库,如Pandas和NumPy,可以对数据进行清洗、格式转换和统计分析。比如可以对遥感数据进行空间插值,填补缺失值,以及对气象数据进行时空插值等操作。 然后,可以使用Python的图像处理库,如OpenCV和Pillow,来对遥感图像进行预处理,比如纠正辐射校正,去除雨滴和云状物等。 接着,可以利用Python的机器学习库,如Scikit-learn和TensorFlow,来建立地表温度反演模型。可以使用监督学习算,如线性回归、支持向量机等,来训练模型,并利用已知的温度和遥感数据来进行模型参数的拟合和优化。 最后,可以利用Python的数据可视化库,如Matplotlib和Seaborn,将反演结果可视化,比如绘制温度分布图、温度变化曲线等。 总之,利用Python来进行地表温度反演可以通过多种功能和库的组合实现,从数据处理到模型训练和结果可视化,为地表温度反演提供了灵活和强大的工具。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值