超友好!气象 Python 训练营 ③ 数组进阶
Q1: 读取 FNL 再分析资料中 2021 年 1 月 1 日 0 时、2021 年 1 月 1 日 6 时、2021 年 1 月 1 日 12 时、2021 年 1 月 1 日 18 时,4 个时次的地表以上 2m 温度的二维数组。对所有温度数据取整(int),然后计算这 4 个时次中,最常出现的温度(单位:K)的值
正常做法
import xarray as xr
import numpy as np
t1 = np.array(xr.open_dataset('/home/mw/input/fnl6384/fnl/fnl_20210101_00_00.grib2',engine="pynio")['TMP_P0_L103_GLL0'].loc[2,:,:]).reshape(-1).astype(int)
t2 = np.array(xr.open_dataset('/home/mw/input/fnl6384/fnl/fnl_20210106_00_00.grib2',engine="pynio")['TMP_P0_L103_GLL0'].loc[2,:,:]).reshape(-1).astype(int)
t3 = np.array(xr.open_dataset('/home/mw/input/fnl6384/fnl/fnl_20210112_00_00.grib2',engine="pynio")['TMP_P0_L103_GLL0'].loc[2,:,:]).reshape(-1).astype(int)
t3 = np.array(xr.open_dataset('/home/mw/input/fnl6384/fnl/fnl_20210118_00_00.grib2',engine="pynio")['TMP_P0_L103_GLL0'].loc[2,:,:]).reshape(-1).astype(int)
t = np.concatenate((t1,t2,t3))
a1 = np.argmax(np.bincount(t))
不正常做法
a1 = 299