import meteva
import datetime
import os

def acc_climate_pre(input_dir,output_path):
    time1 = datetime.datetime(2020,1,1,0)
    grd_list = []
    for i in range(732):
        path = input_dir + r"\\"+str(i+1)+".grib"
        grd = meteva.base.read_griddata_from_grib(path)
        time2 = time1 + datetime.timedelta(hours=12*i)
        meteva.base.set_griddata_coords(grd,gtime=[time2])
        grd_list.append(grd)
    grd_all = meteva.base.concat(grd_list)
    meteva.base.write_griddata_to_nc(grd_all,save_path=output_path,effectiveNum=6)


if __name__ == "__main__":
    #input_dir = r"H:\test_data\input\mem\era-dailyclim\t700_mean"
    #output_path = r"H:\test_data\input\mem\era-dailyclim\t700_mean.nc"
    #acc_climate_pre(input_dir,output_path)

    #meteva.base.path_tools.get_path_list_in_dir()
    path = r"H:\test_data\input\mem\era-dailyclim\nc\z500hPa_mean.nc"
    grd1 = meteva.base.read_griddata_from_nc(path)
    print(grd1)
    # path2 = r"H:\test_data\input\mem\era-dailyclim\z500_mean.nc"
    # grd2 = meteva.base.read_griddata_from_nc(path2)
    # import numpy as np
    # #print(grd1)
    # # print(grd2)
    # print(np.max(np.abs(grd1.values - grd2.values)))
    # # path = r"H:\test_data\input\mem\era-dailyclim\nc\1.grib"
    # # grd = meteva.base.read_griddata_from_grib(path)
    # # print(grd)
    meteva.base.cmaps.rain_24h