landsat 8 python library

read the true color

def landsat8_rgb_show(file_path):
    """
    show the true color of landsat 8
    file_path: the path of the true color file
    """
    file_name = os.path.join(file_path, os.path.basename(file_path) + ".tif")
    raster_rgb_array = plt.imread(file_name)
    plt.imshow(raster_rgb_array)
    plt.show()

calculate the metadata of Lansat-8:

def landsat8_read_meta(file_path, show_flag=False):
    file_name = os.path.basename(file_path)[:42] + "_MTL" ".txt"
    file_name = os.path.join(file_path, os.path.basename(file_path), file_name)
    i = 0
    metadata = {}
    with open(file_name, "r") as mtl_obj:
        data = mtl_obj.readline()
        cur_first_key = data.split(" = ")[1].split("\n")[0]
        metadata[cur_first_key] = {}
        while data[:9] != "END_GROUP":
            i = i + 1
            data = mtl_obj.readline()
            cur_sec_key = data.split(" = ")[1].split("\n")[0]
            metadata[cur_first_key][cur_sec_key] = {}
            data = mtl_obj.readline()
            if data == "END\n":
                break
            while data[:11] != "  END_GROUP":
                meta_key = data.split("    ")[1].split(" = ")
                if meta_key[1].find("\"") != -1:
                    metadata[cur_first_key][cur_sec_key][meta_key[0]] = meta_key[1].split("\"")[1]
                else:
                    if meta_key[0] == "FILE_DATE":
                        metadata[cur_first_key][cur_sec_key][meta_key[0]] = meta_key[1].split("\n")[0]
                    else:
                        metadata[cur_first_key][cur_sec_key][meta_key[0]] = meta_key[1].split("\n")[0]
                data = mtl_obj.readline()
                i = i + 1
                if i > 3000:
                    return
    if show_flag:
        for key in metadata.keys():
            metadata_sec = metadata[key]
            for key_sec in metadata_sec.keys():
                print("\t" + key_sec)
                metadata_third = metadata_sec[key_sec]
                for key_third in metadata_third.keys():
                    print("\t\t" + key_third + "\t:\t" + metadata_third[key_third])
    return metadata

Download the srtm dem data from the earthdata.nasa website, conduct the topographic correction.
image mosaic with arcgis
Arcmap->Data Management Tools->Raster->Mosaic Dataset->Mosaic To New Raster

Calulate the slope from a dem:
method 1 (using the gdal.DEMProcessing):

from osgeo import gdal
import numpy as np
import rasterio.io
import matplotlib.pyplot as plt
import os

def slope_and_aspect_cal(file_path, show_flag=False):  # uncompleted

    # read the dem
    dem_path = os.path.join(file_path, "dem_RimFire.tif")
    dem_raster = gdal.Open(dem_path)
    dem_array = dem_raster.GetRasterBand(1).ReadAsArray()  # get the dem raster

    def calculate_slope(DEM):
        slope_path = os.path.join(file_path, "slope.tif")
        gdal.DEMProcessing(slope_path, DEM, 'slope')
        with rasterio.open(slope_path) as dataset:
            slope = dataset.read(1)
        return slope

    def calculate_aspect(DEM):
        slope_path = os.path.join(file_path, "slope.tif")
        gdal.DEMProcessing(slope_path, DEM, 'aspect')
        with rasterio.open(slope_path) as dataset:
            aspect = dataset.read(1)
        return aspect

    slope = calculate_slope(dem_path)
    aspect = calculate_aspect(dem_path)

    print(type(slope), slope.dtype, slope.shape)
    print(slope.min(), slope.max())
    print("The number of pixels less than 0: %d" % len(slope < 0))

    plt.hist(slope.flatten(), bins=256)
    plt.title(r'Histogram of slope')
    plt.show()

    slope[slope <0] = 255

    if show_flag is True:
        plt.imshow(slope)
        plt.title("slope")
        plt.show()
    return slope

method 2 (using the richdem.

import os
from osgeo import gdal

def topo_correction_cal(file_path, show_flag=False):  # uncompleted
    # read the dem
    dem_path = os.path.join(file_path, "dem_RimFire.tif")
    dem_raster = gdal.Open(dem_path)
    dem_array = dem_raster.GetRasterBand(1).ReadAsArray()  # get the dem raster
    import richdem as rd
    shasta_dem = rd.LoadGDAL(dem_path, no_data=0)
    slope = rd.TerrainAttribute(shasta_dem, attrib='slope_riserun')
    rd.rdShow(slope, axes=False, cmap='magma', figsize=(8, 5.5))
    plt.show()
    return slope

atmospheric correction with ARCSI

In the view of the atmospheric correction, ARCSI is a interface using the python.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Landsat 8是一颗遥感卫星,用于收集地球表面的高分辨率图像。Python是一种流行的程序设计语言,提供了许多功能强大的库和工具来处理遥感数据。 在使用Python进行Landsat 8温度数据处理时,主要有以下几个步骤: 1. 数据获取:通过合适的数据源,比如美国地质调查局(USGS)的数据存档,可以获取到Landsat 8的温度数据集。 2. 数据解析:使用Python中的GDAL库或其他相关库,可以读取并解析Landsat 8的数据文件。这些数据文件通常是以GeoTIFF(地理标记图像文件格式)的形式存储的。 3. 数据预处理:在对温度数据进行分析之前,通常需要进行预处理。这可能包括去除云层遮挡、空间插值或差值方法进行修复等操作。 4. 温度计算:使用提供的辐射定标系数,可以将Landsat 8的原始辐射数据转换为表面温度数据。这些辐射定标系数可以在Landsat 8的技术文档中找到。 5. 数据分析:使用Python中的各种数据分析库,如NumPy、Pandas和Matplotlib等,可以对Landsat 8温度数据进行各种统计和可视化分析。比如制作温度分布图、温度时间序列图等。 通过这些步骤,我们可以使用PythonLandsat 8的温度数据进行处理和分析,从而获取更多关于地表温度的信息,进而应用于环境监测、气候研究和自然资源管理等领域。Python的开源特性以及强大的科学计算能力,使得分析Landsat 8温度数据变得更加高效和便捷。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值