利用python和Sen2cor对Sentinel2进行批量大气校正

该博客介绍了如何使用Python脚本结合Sen2cor工具对大量Sentinel2遥感影像进行批量大气校正。通过读取文件夹结构并写入txt文件,然后调用Sen2cor的批处理命令,实现连续校正。适用于大规模影像处理,通常在11-12小时内可完成约20幅影像的校正。注意,2016年前的影像可能需要使用特定版本的Sen2cor进行校正。
摘要由CSDN通过智能技术生成

利用python和Sen2cor对Sentinel2进行批量大气校正

p.s本文只适合大量的批量校正,一般两三幅影像的那种就直接搜批量校正就好了。

废话不多说,直接上代码

import os
import shutil
import subprocess

file_path = "E:\\ESRIRS\\Sentinel2Imag\\"
year_list = ["2016", "2017", "2018", "2019", "2020", "2021", "2022"]
satellite_list = ["Sentinel2A", "Sentinel2B"]


def readNameWriteInTxt():
    for year in year_list:
        for satellite in satellite_list:
            file_path2 = file_path + year + "\\" + satellite
            txt_file_path = file_path + satellite + year + ".txt"
            names = os.listdir(file_path2)
            if names is None:
                names += "Null"
            else:
                with open(txt_file_path, "w+") as log:
                    log.write(file_path2 + "\n")
                    for name in names:
                        name = name + "\n"
                        log.write(name)


def AutomationAtmosphericCorrectionC(satellite_listA, year_listA, bat_sen2cor):
    for satellite in satellite_listA:
        for year in year_listA:
            txt_file_path = foder_path + satellite + year + ".txt"
            with open(txt_file_path, "r+") as txt_file:
                txt_first_line = next(txt_file)
                lines = txt_file.readlines()
                #index = 1
                for line in lines:
                    if line != "":
                        cmd_args = [bat_sen2cor, txt_first_line.strip("\n") + "\\" + line.strip("\n")]
                        print("{} processing begin!".format(line.strip("\n")))
                        subprocess.call(cmd_args)
                        print("{} processing finished!\n".format(line.strip("\n")))
                        line = ""
                        files = open(txt_file_path, "w+")
                        files.write(txt_first_line)
                        line = files.writelines(line)
                        files.close()

readNameWriteInTxt是读取file_path 目录下所有文件夹,并将其保存在txt文件中。txt第一行是影像父文件夹的绝对路径,除第一行外是影像的文件名。.

AutomationAtmosphericCorrectionC是逐行读取之前创建的txt文件,并对影像进行校正,每校正一次影像就会删除一条影像的文件名,这样第一天没校正完的位置也会被记录,第二天再运行脚本即可继续校正。

bat_sen2cor是Sen2cor的绝对路径

楼主电脑是九代i5标压版,一般跑十一二个小时能校正完二十幅影像。

p.s2016及以前的sentinel影像的校正好像有问题,不能用05版sne2cor,目前搜到的时要使用10版的,不过楼主没试验过。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值