借鉴https://blog.csdn.net/m0_46671865/article/details/123518243
from pathlib import Path
import xarray as xr
import cfgrib
import numpy as np
import pygrib as pg
import matlibplot
model = 'EC'
dir_path = Path(f'/data1/luox/2023021400')
dict=list(dir_path.glob('W_NAFP*'))[2:] # list the files from last 3rd file
# module to get the time information of EC forecast results
filename = grib_file
year = filename.name.split('_')[4][0:4] # 从文件名中提取时间信息 year
mmddHH = filename.name.split('_')[6][11:17] # the time of the end of forecast
forecast_time = datetime.datetime.strptime(year + mmddHH, '%Y%m%d%H') # 输出预报时间 the end of forecast
datetime_str_to = forecast_time.strftime("%Y%m%d%H%M%S") # the other form of the end of forecast time
cycle_str = filename.name.split('_')[6][3:9]
cycle = year + cycle_str # the start time of forecast
d_time = self.forecast_time - da