1 Star 1 Fork 0

Haixu He/Bayesian Temporal Tensor Factorization-Based Interpolation for Time Series Remote Sensing Data with Large-Area Missing Observations Code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
Haixu He 提交于 2022-01-10 23:00 . HTR-BTTF
"""
基础函数:tif文件的读写
"""
import numpy as np
import random
from numpy.random import multivariate_normal as mvnrnd
from numpy.linalg import inv as inv
from osgeo import gdal, osr
import matplotlib.pylab as plt
import pandas as pd
import os
def CreateGeoTiff(outRaster, image, geo_transform, projection):
no_bands = 0
rows = 0
cols = 0
driver = gdal.GetDriverByName('GTiff')
# print("元组长度:", len(image.shape))
if len(image.shape) == 2:
no_bands = 1
rows, cols = image.shape
elif len(image.shape) == 3:
no_bands, rows, cols = image.shape
# print("波段:", no_bands, "Rows:", rows, "Cols:", cols)
# DataSet = driver.Create(outRaster, cols, rows, no_bands, gdal.GDT_Byte)
DataSet = driver.Create(outRaster, cols, rows, no_bands, gdal.GDT_Float32)
# # follow code is adding GeoTranform and Projection
DataSet.SetGeoTransform(geo_transform)
DataSet.SetProjection(projection)
if no_bands == 1:
DataSet.GetRasterBand(1).WriteArray(image) # 写入数组数据
else:
for i in range(no_bands):
DataSet.GetRasterBand(i + 1).WriteArray(image[i])
del DataSet
def readGeoTIFF(fileName):
dataset = gdal.Open(fileName)
if dataset == None:
print(fileName + "文件无法打开")
im_width = dataset.RasterXSize # 栅格矩阵的列数
im_height = dataset.RasterYSize # 栅格矩阵的行数
im_data = dataset.ReadAsArray(0, 0, im_width, im_height) # 获取数据
im_geotrans = dataset.GetGeoTransform() # 获取仿射矩阵信息
im_proj = dataset.GetProjection() # 获取投影信息
return im_data, im_geotrans, im_proj
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/HaixuHe/bayesian-temporal-tensor-factorization-based-interpolation-for-time-series-remote-sensing-data-with-large-area-missing-observations-code.git
git@gitee.com:HaixuHe/bayesian-temporal-tensor-factorization-based-interpolation-for-time-series-remote-sensing-data-with-large-area-missing-observations-code.git
HaixuHe
bayesian-temporal-tensor-factorization-based-interpolation-for-time-series-remote-sensing-data-with-large-area-missing-observations-code
Bayesian Temporal Tensor Factorization-Based Interpolation for Time Series Remote Sensing Data with Large-Area Missing Observations Code
master

搜索帮助