def DNtoReflectance(filepath, info, n_band, resultfolder): num_band = str(n_band) band = filepath + '_01_T1_B' + num_band + '.tif' mtl = filepath + '_01_T1_MTL.txt' data = getMTL(mtl) SUN_ELEVATION = float(data['SUN_ELEVATION']) SUN_ELEVATION_Rad = SUN_ELEVATION * math.pi / 180 EARTH_SUN_DISTANCE = float(data['EARTH_SUN_DISTANCE']) image = tifffile.imread(band, key=0) DN = np.array(image) RADIANCE_MAXIMUM_BAND = float(data['RADIANCE_MAXIMUM_BAND_' + num_band]) REFLECTANCE_MAXIMUM_BAND = float(data['REFLECTANCE_MAXIMUM_BAND_' + num_band]) RADIANCE_MULT_BAND = float(data['RADIANCE_MULT_BAND_' + num_band]) RADIANCE_ADD_BAND = float(data['RADIANCE_ADD_BAND_' + num_band]) Radiance = DN * RADIANCE_MULT_BAND + RADIANCE_ADD_BAND Sun_radiance = ( (math.pi * EARTH_SUN_DISTANCE**2)**2 * RADIANCE_MAXIMUM_BAND * np.sin(SUN_ELEVATION_Rad)) / REFLECTANCE_MAXIMUM_BAND Reflectance = Radiance / Sun_radiance b = np.array(Reflectance, dtype=np.float32) np.save(resultfolder + 'Landsat_' + info + '_B' + num_band, b) Reflectance = None b = None gc.collect() print("save " + 'Landsat_' + info + '_B' + num_band)
def DNtoTCelsium(filepath, info, n_band, resultfolder): num_band = str(n_band) band = filepath + '_01_T1_B' + num_band + '.tif' mtl = filepath + '_01_T1_MTL.txt' data = getMTL(mtl) # Open the file: Band = tifffile.imread(band, key=0) RADIANCE_MULT_BAND = float(data['RADIANCE_MULT_BAND_' + num_band]) RADIANCE_ADD_BAND = float(data['RADIANCE_ADD_BAND_' + num_band]) K2_CONSTANT_BAND = float(data['K2_CONSTANT_BAND_' + num_band]) K1_CONSTANT_BAND = float(data['K1_CONSTANT_BAND_' + num_band]) TOARadiance = RADIANCE_MULT_BAND * Band + RADIANCE_ADD_BAND band_log = np.log(K1_CONSTANT_BAND / TOARadiance + 1) band_t = K2_CONSTANT_BAND / band_log - 273.15 print(np.max(band_t), ' Max Temperature') print(np.min(band_t), ' Min Temperature') Band_T_float32 = np.array(band_t, dtype=np.float32) np.save(resultfolder + 'Temperature_Band_' + str(n_band) + '_' + info, Band_T_float32) print('Temperature_Band_' + num_band + '_' + info + ' done')
def Reading_data(path_res, X, mtl): firms = np.load(path_res + r'/Firms_' + X + '.npy') print(firms) result = np.load(path_res + r'/Algrorithm_' + X + '.npy') print(result) points_math = np.load(path_res + r'/Points_match_' + X + '.npy') print(points_math) b1 = np.load(path_res + r'\Landsat_' + X + '_B1.npy') print(b1.shape, 'Shape') data = getMTL(mtl) return firms, result, points_math, b1, data
def FromMaskToCoords(path_res, info, firemask, mtl): b1 = np.load(path_res + r'\Landsat_' + info + '_B1.npy') data = getMTL(mtl) UL_LAT = float(data['CORNER_UL_LAT_PRODUCT']) UL_LON = float(data['CORNER_UL_LON_PRODUCT']) UR_LAT = float(data['CORNER_UR_LAT_PRODUCT']) UR_LON = float(data['CORNER_UR_LON_PRODUCT']) LL_LAT = float(data['CORNER_LL_LAT_PRODUCT']) LL_LON = float(data['CORNER_LL_LON_PRODUCT']) LR_LAT = float(data['CORNER_LR_LAT_PRODUCT']) LR_LON = float(data['CORNER_LR_LON_PRODUCT']) Corners = index_corners(b1) Max_ind_line = Corners[0] Min_ind_line = Corners[1] Max_ind_col = Corners[2] Min_ind_col = Corners[3] Max_Lat = max(UL_LAT,UR_LAT,LL_LAT,LR_LAT) Min_lat = min(UL_LAT,UR_LAT,LL_LAT,LR_LAT) Max_lon = max(UL_LON,UR_LON,LL_LON,LR_LON) Min_lon = min(UL_LON,UR_LON,LL_LON,LR_LON) result = np.load(firemask) shape = result.shape height = shape[0] width = shape[1] lonarr = [] latarr = [] for i in range(height): for j in range(width): if result[i][j]!=0: lon_lat = Coordinates(i,j,Min_lat, Max_Lat, Min_lon, Max_lon, Max_ind_line, Min_ind_line, Max_ind_col, Min_ind_col) latarr.append(lon_lat[0]) lonarr.append(lon_lat[1]) lonarr=np.array(lonarr) latarr=np.array(latarr) print(len(lonarr)) np.save(path_res + r'\lonarr_'+info,lonarr) np.save(path_res + r'\latarr_'+info,latarr) print('coords done')
def Сalculation_E_diff_corners(filepath, np_filepath, info): b1 = np.load(np_filepath + r'Landsat_' + info + '_B1.npy') mtl = filepath + '_01_T1_MTL.txt' data = getMTL(mtl) UL_LAT = float(data['CORNER_UL_LAT_PRODUCT']) UL_LON = float(data['CORNER_UL_LON_PRODUCT']) UR_LAT = float(data['CORNER_UR_LAT_PRODUCT']) UR_LON = float(data['CORNER_UR_LON_PRODUCT']) LL_LAT = float(data['CORNER_LL_LAT_PRODUCT']) LL_LON = float(data['CORNER_LL_LON_PRODUCT']) LR_LAT = float(data['CORNER_LR_LAT_PRODUCT']) LR_LON = float(data['CORNER_LR_LON_PRODUCT']) shape = b1.shape mask = np.zeros(shape) np.putmask(mask, b1 != b1[0][0], 1) ind_lines = [] for i in range(shape[0]): if np.sum(mask[i, :]) <= 5 and np.sum(mask[i, :]) != 0: ind_lines.append(i) ind_columns = [] for j in range(shape[1]): if np.sum(mask[:, j]) <= 5 and np.sum(mask[:, j]) != 0: ind_columns.append(j) Max_ind_line = max(ind_lines) Min_ind_line = min(ind_lines) Max_ind_col = max(ind_columns) Min_ind_col = min(ind_columns) offsetX = Min_ind_col offsetY = Min_ind_line Max_Lat = max(UL_LAT, UR_LAT, LL_LAT, LR_LAT) Min_lat = min(UL_LAT, UR_LAT, LL_LAT, LR_LAT) Max_lon = max(UL_LON, UR_LON, LL_LON, LR_LON) Min_lon = min(UL_LON, UR_LON, LL_LON, LR_LON) p_lat = abs((Max_Lat - Min_lat) / (Max_ind_line - offsetY)) p_lon = abs((Max_lon - Min_lon) / (Max_ind_col - offsetX)) E_diff = (p_lat**2 + p_lon**2)**0.5 return (p_lat, p_lon)
def Max_Min_Lat_Lon(mtl): data = getMTL(mtl) UL_LAT = float(data['CORNER_UL_LAT_PRODUCT']) UL_LON = float(data['CORNER_UL_LON_PRODUCT']) UR_LAT = float(data['CORNER_UR_LAT_PRODUCT']) UR_LON = float(data['CORNER_UR_LON_PRODUCT']) LL_LAT = float(data['CORNER_LL_LAT_PRODUCT']) LL_LON = float(data['CORNER_LL_LON_PRODUCT']) LR_LAT = float(data['CORNER_LR_LAT_PRODUCT']) LR_LON = float(data['CORNER_LR_LON_PRODUCT']) UL = (UL_LAT, UL_LON) LL = (LL_LAT, LL_LON) UR = (UR_LAT, UR_LON) LR = (LR_LAT, LR_LON) Max_lat = max(UL_LAT,UR_LAT,LL_LAT,LR_LAT) Min_lat = min(UL_LAT,UR_LAT,LL_LAT,LR_LAT) Max_lon = max(UL_LON,UR_LON,LL_LON,LR_LON) Min_lon = min(UL_LON,UR_LON,LL_LON,LR_LON) return (Max_lat, Min_lat, Max_lon, Min_lon)
def DNtoReflectance(filepath, info, n_band, mtl, path_res): num_band = str(n_band) band = filepath + r'\LC08_L1TP_' + info + '_01_T1\LC08_L1TP_' + info + '_01_T1_B' + num_band + '.tif' data = getMTL(mtl) image = tifffile.imread(band, key=0) DN = np.array(image) REFLECTANCE_MULT_BAND = float(data['REFLECTANCE_MULT_BAND_' + num_band]) REFLECTANCE_ADD_BAND = float(data['REFLECTANCE_ADD_BAND_' + num_band]) Reflectance = DN * REFLECTANCE_MULT_BAND + REFLECTANCE_ADD_BAND print(np.max(Reflectance), ' Max Value Band ' + num_band) print(np.min(Reflectance), ' Min Value Band ' + num_band) b = np.array(Reflectance, dtype=np.float32) np.save(path_res + r'\Landsat_' + info + '_B' + num_band, b) Reflectance = None b = None gc.collect() print("save " + 'Landsat_' + info + '_B' + num_band)
def FromCoordinatesToValue_b7(filepath, np_folder, info, lat, lon): b7 = np.load(np_folder + r'Landsat_' + info + '_B7.npy') mtl = filepath + '_01_T1_MTL.txt' data = getMTL(mtl) UL_LAT = float(data['CORNER_UL_LAT_PRODUCT']) UL_LON = float(data['CORNER_UL_LON_PRODUCT']) UR_LAT = float(data['CORNER_UR_LAT_PRODUCT']) UR_LON = float(data['CORNER_UR_LON_PRODUCT']) LL_LAT = float(data['CORNER_LL_LAT_PRODUCT']) LL_LON = float(data['CORNER_LL_LON_PRODUCT']) LR_LAT = float(data['CORNER_LR_LAT_PRODUCT']) LR_LON = float(data['CORNER_LR_LON_PRODUCT']) Corners = index_corners(b7) # (Max_ind_line, Min_ind_line, Max_ind_col, Min_ind_col) Max_ind_line = Corners[0] offsetY = Corners[1] Max_ind_col = Corners[2] offsetX = Corners[3] Max_Lat = max(UL_LAT, UR_LAT, LL_LAT, LR_LAT) Min_lat = min(UL_LAT, UR_LAT, LL_LAT, LR_LAT) Max_lon = max(UL_LON, UR_LON, LL_LON, LR_LON) Min_lon = min(UL_LON, UR_LON, LL_LON, LR_LON) p_lat = abs((Max_Lat - Min_lat) / (Max_ind_line - offsetY)) p_lon = abs((Max_lon - Min_lon) / (Max_ind_col - offsetX)) Ind_Y = offsetY + math.ceil((Max_Lat - lat) / p_lat) Ind_X = offsetX + math.ceil((lon - Min_lon) / p_lon) val = b7[Ind_Y][Ind_X] return val