数据介绍
葵花8号卫星(Himawari-8)是日本发射的静止轨道气象卫星,由日本气象厅(JMA)运营。该卫星自2015年7月7日开始正式启用,主要用于观测东亚和西太平洋区域的天气情况。葵花8号卫星搭载了先进的光学仪器,能够提供高分辨率的气象数据。
卫星分辨率
葵花8号卫星的主要分辨率如下:
-
全圆盘区域的影像空间分辨率一般为5km(2401行/列)和2km(6001行/列)。这些数据集包含albedo(反射率,band1-6)、bt(亮温,band 7-16)、太阳高度角/方位角、卫星高度角/方位角(可用于大气校正)、经度、纬度等信息
-
日本地区和目标区的影像空间分辨率更高,可以达到0.5km(band 3),1km(band 1,2,4),2km(band 5-16)。这些数据提供全球、日本、目标区的影像及真彩图
-
葵花8号卫星的数据通过HimawariCAST系统分发,该系统提供14个通道的数据,包括1个可见光、3个近红外和10个红外通道。数据的重访周期短,为10分钟,有利于提高对台风和暴雨等灾害性天气的预测精度
-
葵花8号卫星的数据还包括高分辨率的光学相机图像,其分辨率可达到0.5km,这对于气象观测和环境监测等领域非常有价值
单波影像导出
from osgeo import gdal, ogr, osr, gdal_array
import numpy as np
import numpy as np
from matplotlib import pyplot as plt
from osgeo import gdal
from netCDF4 import Dataset
from osgeo import gdal
import glob
def arr2tif(
arr:np.ndarray,
out_file_path,
geotrans=(-20, 0.05, 0, 40, 0, -0.05), projection=4326,
):
"""将numpy数组保存为GeoTIFF格式
参数:
arr (np.ndarray): 数据集本身。
out_file_path (str): 输出文件路径。
geotrans (设置(lon, Δlon, 0, lat, 0, -Δlat)): 左上角像素的坐标信息
projection (int 或 str): 坐标系。如果是int类型则是EPSG代码,如果是str类型则是Wkt代码。默认为4326。
"""
rows, cols = arr.shape[0], arr.shape[1]
if arr.ndim==3:
n_bands = arr.shape[2]
elif arr.ndim==2:
n_bands = 1
driver = gdal.GetDriverByName('GTiff')
gdal_type = gdal_array.NumericTypeCodeToGDALTypeCode(arr.dtype) # 将numpy.dtype转换为gdal.DataType
outRaster = driver.Create(out_file_path, cols, rows, n_bands, gdal_type)
outRaster.SetGeoTransform(geotrans)
if arr.ndim==2:
outband = outRaster.GetRasterBand(1)
outband.WriteArray(arr)
elif arr.ndim==3:
for i in range(arr.shape[2]):
outband = outRaster.GetRasterBand(i+1)
outband.WriteArray(arr[:,:,i])
# 如果projection是EPSG代码的处理方式
if type(projection) is int:
outRasterSRS = osr.SpatialReference()
outRasterSRS.ImportFromEPSG(projection)
projection = outRasterSRS.ExportToWkt()
outRaster.SetProjection(projection)
outband.FlushCache()
del outRaster
class Convert:
def __init__(self):
self.img = None # 主要部分(ndarray格式)
self.h = None # 主要部分的高度
self.w = None # 主要部分的宽度
self.dtype = None # 主要部分的dtype
self.in_extension ='.nc' # 输入数据的扩展名
self.out_extension = '.tif' # 输出数据的扩展名
self.arr_extension = '.raw' # ndarray的扩展名(自定义)
self.geotrans = None # 地理信息
##### 需要重写的部分#############################################################
# [输入] -> 提取self.arr及其他多个信息
def in2arr(self, in_file_path):
self.img = None
self.h, self.w, self.dtype = None, None, None
self.geotrans = None
pass
# self.arr -> [输出]
def arr2out(self, out_file_path):
pass
# 决定输出图像的名称(不包括扩展名)
def make_out_file_name(self, in_file_name):
return in_file_name.split('.')[0] + f'.h{self.h}w{self.w}_{self.dtype}' # 不包括扩展名,加上头部信息后输出
# 创建地理信息
def make_geotrans(self):
pass
##### 实际使用的函数(不直接修改) ######################################################
# 将[输入]转换为ndarray并保存(单张)
def save_arr_single(self, in_file_path, out_file_path):
self.in2arr(in_file_path)
self.img.tofile(out_file_path)
print(out_file_path)
# 将[输入]转换为ndarray并保存(目录内)
def save_arr_multi(self, in_dir_path, out_dir_path):
get_file_ls = glob.glob(in_dir_path+'/*'+self.in_extension)
for get_file_name in get_file_ls:
in_file_name = get_file_name.split('\\')[-1]
in_file_path = in_dir_path + '/' + in_file_name
self.in2arr(in_file_path) # 获取self.img
out_file_name = self.make_out_file_name(in_file_name)+self.arr_extension # 输出图像的文件名
out_file_path = f'{out_dir_path}/{out_file_name}'
self.img.tofile(out_file_path) # 保存ndarray
print(out_file_path) # DEBUG
# 将[输入]转换为[输出]并保存(单张)
def save_out_single(self, in_file_path, out_file_path):
self.in2arr(in_file_path) # 将[输入]转换为self.img
self.arr2out(out_file_path) # 将self.img转换为[输出]
# 将[输入]转换为[输出]并保存(目录内)
def save_out_multi(self, in_dir_path, out_dir_path):
get_file_ls = glob.glob(f'{in_dir_path}/*{self.in_extension}')
for get_file_path in get_file_ls:
in_file_name = get_file_path.split('\\')[-1]
in_file_path = in_dir_path + '/' + in_file_name # 输入图像的文件路径
self.in2arr(in_file_path) # [输入] -> 转换为self.img
out_file_name = self.make_out_file_name(in_file_name)+self.out_extension # 输出图像的文件名
out_file_path = f'{out_dir_path}/{out_file_name}' # 输出图像的文件路径
self.arr2out(out_file_path) # 输出
class NC2Tif(Convert):
def __init__(self):
super().__init__()
self.in_extension='.nc'
self.out_extension='.tif'
# 读取netCDF图像 -> self.img
def in2arr(self, in_file_path):
nc = Dataset(in_file_path) # 实例化
data_key = list(nc.variables.keys())[2]
self.img = nc["tbb_15"][:].data # 获取实际数据
# 计算各种参数
self.dtype = self.img.dtype # 实际数据的dtype
self.h, self.w = self.img.shape # 实际数据的高度和宽度
self.make_geotrans(nc)
# 将arr转换为geotif
def arr2out(self, out_file_path):
arr2tif(
arr = self.img, out_file_path=out_file_path,
geotrans=self.geotrans)
# 获取geotrans
def make_geotrans(self, nc):
lat_arr = nc['latitude'][:].data
lon_arr = nc['longitude'][:].data
lat_accuracy = int(np.abs(np.round(np.log10(np.abs(lat_arr[1] - lat_arr[0]))))+2)
lon_accuracy = int(np.abs(np.round(np.log10(np.abs(lon_arr[1] - lon_arr[0]))))+2)
delta_lat = np.round(lat_arr[1] - lat_arr[0], lat_accuracy)
delta_lon = np.round(lon_arr[1] - lon_arr[0], lon_accuracy)
self.geotrans = (
np.round(lon_arr[0] - delta_lon/2, lon_accuracy), delta_lon, 0,
np.round(lat_arr[0] - delta_lat/2, lat_accuracy), 0, delta_lat
)
return self.geotrans
if __name__=='__main__':
ng = NC2Tif()
ng.save_out_multi(r'F:\dataset\himawari\NC_data', r'F:\dataset\himawari\tif')
叠加CLCU数据显示效果
注:数据未进行质量控制