rasterio 数据 - python - 执行时间 - 预处理

问题描述 投票:0回答:0

我正在使用 Rasterio 处理卫星图像,我需要遍历整个文件。并将公式应用于每个像素。这个过程需要很长时间,让我很难尝试不同的修改,因为每次都需要很长时间才能看到结果。 有什么改进时间执行的建议吗? 在本地或通过 Jupiter、Google Colab 或其他工具处理这个项目哪个更好?

def dn_to_radiance(data_array, band_number):
    # getting the G value
    channel_gain = float(Landsat8_mlt_dict['RADIANCE_MULT_BAND_' + str(band_number) + ' '])
    # Getting the B value
    channel_offset = float(Landsat8_mlt_dict['RADIANCE_ADD_BAND_' + str(band_number) + ' '])
    # creating a temp array to store the radiance value
    # np.empty_like Return a new array with the same shape and type as a given array.
    new_data_array = np.empty_like(data_array)

    # loooping through the image
    for i, row in enumerate(data_array):
        for j, col in enumerate(row):

            # checking if the pixel value is not nan, to avoid background correction
            if data_array[i][j].all() != np.nan:
                new_data_array[i][j] = data_array[i][j] * channel_gain + channel_offset
    print(f'Radiance calculated for band {band_number}')
    return new_data_array
Landsat8_mlt_dict = {}
with open('LC08_L2SP_190037_20190619_20200827_02_T1_MTL.txt', 'r') as _:
    # print(type(_))
    for line in _:
        line = line.strip()
        if line != 'END':
            key, value = line.split('=')
            Landsat8_mlt_dict[key] = value


# print(Landsat8_mlt_dict)
def radiance_to_reflectance(arr, ESUN, ):
    # getting the d value
    d = float(Landsat8_mlt_dict['EARTH_SUN_DISTANCE '])
    # calculating rh phi value from theta
    phi = 90 - float(Landsat8_mlt_dict['SUN_ELEVATION '])
    # creating the temp array
    new_data_array = np.empty_like(arr)
    # loop to finf the reflectance
    for i, row in enumerate(arr):
        for j, col in enumerate(row):
            if arr[i][j].all() != np.nan:
                new_data_array[i][j] = np.pi * arr[i][j] * d ** 2 / (ESUN * cos(phi * math.pi / 180))
    print(f"Reflectance of Band calculated")
    return new_data_array
python preprocessor rasterio
© www.soinside.com 2019 - 2024. All rights reserved.