风云卫星FullMask_Grid文件RAW格式转nc

2024-06-20 17:28:11 浏览数 (1)

代码语言:javascript复制
import numpy as np
import netCDF4 as nc

def fy4disk(rawfile, dim):
    """
    FY-4A数据行列号和经纬度查找表2km、4km,读取raw文件,存成nc.
    :param rawfile: raw文件全路径
    :param dim: 行列数(2km:5496,4km:2748)
    :return:
    """
    sz = np.fromfile(rawfile, dtype=float, count=dim*dim*2)
    latlon = np.reshape(sz, (dim, dim, 2))

    lat = latlon[:, :, 0]
    lon = latlon[:, :, 1]

    lat[lat > 100] = -9999.
    lon[lon < 0] = lon[lon < 0]   360.
    lon[lon > 361] = -9999.

    return lon, lat

if __name__ == '__main__':
    rawfile = r'D:workfire_pointFullMask_Grid_2000FullMask_Grid_4000.raw'
 #   dim = 5496  # 2km
     dim = 2748 # 4km

    lon, lat = fy4disk(rawfile, dim)

    # 写入NetCDF文件
    ncfile = r"D:workfire_pointFullMask_Grid_2000FullMask_Grid_4000.nc"
    with nc.Dataset(ncfile, 'w', format='NETCDF4') as ds:
        # 创建维度
        ds.createDimension('x', dim)
        ds.createDimension('y', dim)

        # 创建变量
        longitude = ds.createVariable('Lon', 'f4', ('x', 'y'))
        latitude = ds.createVariable('Lat', 'f4', ('x', 'y'))

        # 赋值
        longitude[:, :] = lon
        latitude[:, :] = lat

        # 添加属性
        longitude.units = 'degrees_east'
        latitude.units = 'degrees_north'

参考气象家园帖子

https://bbs.06climate.com/forum.php?mod=viewthread&tid=90074

csdn帖子

https://blog.csdn.net/Monkey_dada/article/details/109052557

文中用到的文件可以从下面网址下载

https://www.heywhale.com/mw/project/61bb07fb7e520c001797a32d/dataset

这时候有朋友要问,这个文件是做什么用的?我的理解较浅,简单说说。

大家知道卫星遥感数据通常是没有所谓经纬度,当处理它们时只能获取到xy的行列号,以上的FullMask_Grid可以帮助将行列号转化为经纬度。

0 人点赞