1、micaps4转grid
使用meteva库pip install meteva
import meteva.base as meb
def micaps4_to_grid():filename = r"/test/pre-micaps-1h/1805/20201118_0500_qpf_ml.txt" # 114 127 21 29grid = meb.grid([113.22, 124.28, 0.01], [33.62, 38.98, 0.01])grd = meb.read_griddata_from_micaps4(filename, grid=grid)print(grd)
2、手动
def parse(micaps4):f1 = open(micaps4, mode='rt', encoding='gbk')tmp = f1.readlines()row = int(tmp[1].strip().split()[13]) # 行数column = int(tmp[1].strip().split()[12]) # 列数t0, t1 = '', ''if Path(micaps4).name.__contains__('_0_qpf_ml'):t0 = tmp[0]t1 = tmp[1]tmp.pop(0)tmp.pop(0)point_data = np.zeros((row, column))for i in range(0, row):aa = tmp[i].strip().split()for j in range(len(aa)):point_data[i][j] = float(aa[j])return t0, t1, point_data