コード例 #1
0
def download_ec():
    ip, port = nvb.read_gds_ip_port(r"H:\test_data\input\nvb\ip_port.txt")
    filename_list = nvb.path_tools.get_gds_file_list_in_one_dir(
        ip, port, r"ECMWF_HR/UGRD/800")
    #filename_list = ["20011008.015"]
    for filename in filename_list:
        path_output = r"H:\test_data\ecmwf\ugrd\800" + "\\" + filename
        if not os.path.exists(path_output):
            path_input = "ECMWF_HR/UGRD/800/" + filename
            grd = nvb.read_griddata_from_gds(ip, port, path_input)
            if grd is not None:
                nvb.write_griddata_to_nc(grd, path_output, creat_dir=True)

    filename_list = nvb.path_tools.get_gds_file_list_in_one_dir(
        ip, port, r"ECMWF_HR/VGRD/800")
    #filename_list = ["20011008.015"]
    for filename in filename_list:
        path_output = r"H:\test_data\ecmwf\vgrd\800" + "\\" + filename
        if not os.path.exists(path_output):
            path_input = "ECMWF_HR/VGRD/800/" + filename
            grd = nvb.read_griddata_from_gds(ip, port, path_input)
            if grd is not None:
                nvb.write_griddata_to_nc(grd, path_output, creat_dir=True)

    time0 = datetime.datetime(2020, 1, 7, 8, 0)
    end_time = datetime.datetime.now()
    dir_u = r"H:\test_data\ecmwf\ugrd\800\YYMMDDHH.TTT"
    dir_v = r"H:\test_data\ecmwf\vgrd\800\YYMMDDHH.TTT"
    dir_speed = r"H:\test_data\ecmwf\speed\800\BTYYMMDDHH.TTT.nc"
    while time0 < end_time:
        for dh in range(0, 241, 3):
            path_output = nvb.get_path(dir_speed, time0, dh)
            if not os.path.exists(path_output):
                path_u = nvb.get_path(dir_u, time0, dh)
                path_v = nvb.get_path(dir_v, time0, dh)
                grd_u = nvb.read_griddata_from_nc(path_u)
                if grd_u is not None:
                    grid0 = nvb.get_grid_of_data(grd_u)
                    grd_v = nvb.read_griddata_from_nc(path_v)
                    if grd_v is not None:
                        grd_speed = nvb.grid_data(grid0)
                        grd_speed.values[...] = np.sqrt(
                            np.power(grd_u.values[...], 2) +
                            np.power(grd_v.values[...], 2))
                        path_output = nvb.get_path(dir_speed, time0, dh)
                        nvb.write_griddata_to_nc(grd_speed,
                                                 path_output,
                                                 creat_dir=True)
                    #print()
        time0 = time0 + datetime.timedelta(hours=12)
コード例 #2
0
def extract(output_path, input_path, data_name):

    df = {"id": ["1701"], "lon": [115.8136], "lat": [40.55861], "data0": [0]}
    df = pd.DataFrame(df)
    sta = nvb.sta_data(df)
    time0 = datetime.datetime(2020, 1, 7, 8, 0)
    end_time = datetime.datetime.now()

    sta_speed_all = nvb.read_stadata_from_csv(output_path)
    while time0 < end_time:
        sta_t = nvb.in_time_list(sta_speed_all, [time0])
        if len(sta_t.index) == 0:
            for dh in range(0, 241, 3):
                sta_dt = nvb.in_dtime_list(sta_t, [dh])
                if len(sta_dt.index) == 0:
                    path_speed = nvb.get_path(input_path, time0, dh)
                    if os.path.exists(path_speed):
                        grd_speed = nvb.read_griddata_from_nc(path_speed)
                        print(path_speed)
                        if grd_speed is not None:
                            sta1 = nvb.interp_gs_linear(grd_speed, sta)
                            nvb.set_stadata_coords(sta1,
                                                   level=0,
                                                   time=time0,
                                                   dtime=dh)
                            sta_speed_all = nvb.combine_join(
                                sta_speed_all, sta1)
                    #print(sta_speed_all)
        time0 = time0 + datetime.timedelta(hours=12)
    nvb.set_stadata_names(sta_speed_all, [data_name])
    sta_speed_all.to_csv(output_path)
コード例 #3
0
def extract_ob(output_path, input_dir, station, data_name):
    ids = station["id"].values.tolist()
    now = datetime.datetime.now()
    end_time = datetime.datetime(now.year, now.month, now.day, now.hour, 0)
    time0 = end_time - datetime.timedelta(hours=240)

    sta_speed_all = nvb.read_stadata_from_csv(output_path)
    while time0 < end_time:
        sta_t = nvb.in_time_list(sta_speed_all, [time0])
        if len(sta_t.index) == 0:
            path_in = nvb.get_path(input_dir, time0)
            if os.path.exists(path_in):
                sta = nvb.read_stadata_from_micaps3(path_in)
                print(path_in)
                if sta is not None:
                    #print(sta)
                    sta1 = nvb.put_stadata_on_station(sta, station)
                    print(sta1)
                    #sta1 = nvb.in_id_list(sta,ids)
                    nvb.set_stadata_coords(sta1, level=0, time=time0)
                    sta_speed_all = nvb.combine_join(sta_speed_all, sta1)
                    # print(sta_speed_all)
        time0 = time0 + datetime.timedelta(hours=1)
    nvb.set_stadata_names(sta_speed_all, [data_name])
    sta_speed_all.to_csv(output_path)
コード例 #4
0
def extract_fo(output_path, input_dir, station, data_name):
    sta = copy.deepcopy(station)
    now = datetime.datetime.now()
    end_time = datetime.datetime(now.year, now.month, now.day, 20, 0)

    time0 = end_time - datetime.timedelta(hours=240)
    if os.path.exists(output_path):
        sta_speed_all = nvb.read_stadata_from_csv(output_path)
    else:
        sta_speed_all = None
    while time0 < end_time:
        if sta_speed_all is not None:
            sta_t = nvb.in_time_list(sta_speed_all, [time0])
        else:
            sta_t = None
        if sta_t is None or len(sta_t.index) == 0:
            for dh in range(0, 241, 3):
                if sta_t is not None:
                    sta_dt = nvb.in_dtime_list(sta_t, [dh])
                else:
                    sta_dt = None
                if sta_dt is None or len(sta_dt.index) == 0:
                    path_speed = nvb.get_path(input_dir, time0, dh)
                    print(path_speed)
                    if os.path.exists(path_speed):
                        grd_speed = nvb.read_griddata_from_nc(path_speed)
                        print(path_speed)
                        if grd_speed is not None:
                            #print(grd_speed)
                            sta1 = nvb.interp_gs_linear(grd_speed, sta)
                            nvb.set_stadata_coords(sta1,
                                                   level=0,
                                                   time=time0,
                                                   dtime=dh)
                            sta_speed_all = nvb.combine_join(
                                sta_speed_all, sta1)
                    #print(sta_speed_all)
        time0 = time0 + datetime.timedelta(hours=12)
    nvb.set_stadata_names(sta_speed_all, [data_name])
    sta_speed_all.to_csv(output_path)
コード例 #5
0
def merge1():
    time0 = datetime.datetime(2020, 1, 7, 0, 0)
    dir = r"H:\task\other\201911-预报司-冬奥会检验\冬奥观测数据\延庆赛区\10分钟数据集\A1701\YYYYMM\YYYYMMDD.csv"
    end_time = datetime.datetime.now()
    sta_ob_all = None
    while time0 < end_time:
        filename = nvb.get_path(dir, time0, 0)
        if os.path.exists(filename):
            file = open(filename, 'r')
            sta = pd.read_csv(file, parse_dates=['观测时间'])
            sta = sta[["观测时间", "2分钟平均风速"]]
            sta.columns = ["time", "ob"]
            sta["id"] = 1701
            sta = nvb.sta_data(sta)
            nvb.set_stadata_coords(sta,
                                   level=0,
                                   dtime=0,
                                   lon=115.8136,
                                   lat=40.55861)

            sta_ob_all = nvb.combine_join(sta_ob_all, sta)
            #print(sta_ob_all)
        time0 = time0 + datetime.timedelta(hours=24)
    sta_ob_all.to_csv(r"H:\task\other\201911-预报司-冬奥会检验\冬奥观测数据\ob\speed_ob.txt")
コード例 #6
0
def ob_multi_time_fo(para):
    begin = time.time()
    now = datetime.datetime.now()
    now = datetime.datetime(now.year, now.month, now.day, now.hour, 0)
    station = nvb.read_stadata_from_micaps3(para["station_file"])
    id_list = station["id"].values.tolist()
    ip, port = nvb.read_gds_ip_port(r"H:\test_data\input\nvb\ip_port.txt")
    if para["value_type"] == "wind":
        sta_ob_s_all = None
        sta_ob_d_all = None
        for i in range(para["max_dh"] + 12):
            time0 = now - datetime.timedelta(hours=i)
            path = nvb.get_path(para["ob_dir"], time0)
            sta_s = nvb.read_stadata_from_gds(
                ip,
                port,
                filename=path,
                element_id=nvb.gds_element_id.平均风速_2分钟)
            if sta_s is None: continue
            sta_ob_s_all = nvb.combine_join(sta_ob_s_all, sta_s)
            sta_d = nvb.read_stadata_from_gds(
                ip,
                port,
                filename=path,
                element_id=nvb.gds_element_id.平均风向_2分钟)
            if sta_d is None: continue
            sta_ob_d_all = nvb.combine_join(sta_ob_s_all, sta_d)
        sta_ob_all = nvb.diag.speed_angle_to_wind(sta_ob_s_all, sta_ob_d_all)

        dir_u, file_u = os.path.split(para["fo_grd_dir_u"])
        file_list_u = nvb.path_tools.get_gds_file_list_in_one_dir(
            ip, port, dir_u)
        dir_v, file_v = os.path.split(para["fo_grd_dir_v"])
        file_list_v = nvb.path_tools.get_gds_file_list_in_one_dir(
            ip, port, dir_v)
        # 读取预报数据
        sta_fo_all = None
        for i in range(para["max_dh"] + 12):
            time0 = now - datetime.timedelta(hours=i)
            for dh in range(para["max_dh"]):
                filename = nvb.get_path(file_u, time0, dh)
                if not filename in file_list_u: continue
                # grd = nvb.read_griddata_from_gds(ip,port,dir_u + "/"+filename)
                # if(grd is None):continue
                # sta_u = nvb.interp_gs_linear(grd,station)
                sta_u = nvb.read_stadata_from_gds_griddata(
                    ip, port, dir_u + "/" + filename, station)
                if (sta_u is None): continue
                nvb.set_stadata_coords(sta_u, time=time0, dtime=dh)
                path = nvb.get_path(file_v, time0, dh)
                if not filename in file_list_v: continue
                # grd = nvb.read_griddata_from_gds(ip,port,dir_v + "/" + filename)
                # if (grd is None): continue
                # sta_v = nvb.interp_gs_linear(grd,station)
                sta_v = nvb.read_stadata_from_gds_griddata(
                    ip, port, dir_v + "/" + filename, station)
                if sta_v is None: continue
                nvb.set_stadata_coords(sta_v, time=time0, dtime=dh)
                sta_uv = nvb.combine_on_all_coords(sta_u, sta_v)

                nvb.set_stadata_names(
                    sta_uv,
                    data_name_list=["u" + para["title"], "v" + para["title"]])
                sta_fo_all = nvb.combine_join(sta_fo_all, sta_uv)

        for id in id_list:
            output_path = para["output_dir"]
            if (output_path is not None):
                output_path = nvb.get_path(output_path, now)
                output_path = output_path + "/" + str(id) + ".png"
            sta_ob = nvb.in_id_list(sta_ob_all, [id])
            sta_fo = nvb.in_id_list(sta_fo_all, [id])
            nvp.continuous.wind_ob_and_multi_time_fo(sta_ob,
                                                     sta_fo,
                                                     pic_path=output_path,
                                                     max_dh=para["max_dh"],
                                                     plot_error=True)
    else:
        sta_ob_all = None
        sta_ob_all = None
        for i in range(para["max_dh"] + 12):
            time0 = now - datetime.timedelta(hours=i)
            path = nvb.get_path(para["ob_dir"], time0)
            sta_s = nvb.read_stadata_from_gds(
                ip,
                port,
                filename=path,
                element_id=nvb.gds_element_id_dict[para["value_type"]])
            if sta_s is None: continue
            sta_ob_all = nvb.combine_join(sta_ob_all, sta_s)

        dir_u, file_u = os.path.split(para["fo_grd_dir_u"])
        file_list_u = nvb.path_tools.get_gds_file_list_in_one_dir(
            ip, port, dir_u)
        # 读取预报数据
        sta_fo_all = None
        for i in range(para["max_dh"] + 12):
            time0 = now - datetime.timedelta(hours=i)
            for dh in range(para["max_dh"]):
                filename = nvb.get_path(file_u, time0, dh)
                if not filename in file_list_u: continue
                sta_u = nvb.read_stadata_from_gds_griddata(
                    ip, port, dir_u + "/" + filename, station)
                if (sta_u is None): continue
                nvb.set_stadata_names(sta_u, data_name_list=[para["title"]])
                sta_fo_all = nvb.combine_join(sta_fo_all, sta_u)

        for id in id_list:
            output_path = para["output_dir"]
            if (output_path is not None):
                output_path = nvb.get_path(output_path, now)
                output_path = output_path + "/" + str(id) + ".png"
            sta_ob = nvb.in_id_list(sta_ob_all, [id])
            sta_fo = nvb.in_id_list(sta_fo_all, [id])
            if para["value_type"] == "温度":
                nvp.continuous.temp_ob_and_multi_time_fo(sta_ob,
                                                         sta_fo,
                                                         pic_path=output_path,
                                                         max_dh=para["max_dh"],
                                                         plot_error=True)
            elif para["value_type"] == "降水1h":
                pass
コード例 #7
0
import nmc_verification.nmc_vf_base as nvb
import datetime

dir_input = r"Z:\data\surface\t1\YYMMDDHH.000"
dir_output = r"H:\test_data\input\nvp\ob\temp_2m\BTYYMMDDHH.000"
time0 = datetime.datetime(2019, 1, 1, 2, 0)
now = datetime.datetime(2020, 1, 29, 8, 0)
station = nvb.read_station(nvb.station_国家站)

grid0 = nvb.grid([116, 117, 0.5], [40, 41, 0.5])
station = nvb.in_grid_xy(station, grid0)
station["data0"] = nvb.IV
print(station)
while time0 < now:
    path_input = nvb.get_path(dir_input, time0)
    sta = nvb.read_stadata_from_micaps3(path_input,
                                        station,
                                        level=0,
                                        time=time0,
                                        dtime=0)
    if sta is not None:
        path_output = nvb.get_path(dir_output, time0)
        nvb.write_stadata_to_micaps3(sta,
                                     save_path=path_output,
                                     creat_dir=True,
                                     effectiveNum=1)
        print(path_output)
    time0 = time0 + datetime.timedelta(hours=3)
コード例 #8
0
                    head_info['year'][0], head_info['month'][0],
                    head_info['day'][0], head_info['hour'][0],
                    head_info['minute'][0], head_info['second'][0])
                sta['time'] = time1
                sta['level'] = head_info["level"][0]
                filename1 = os.path.split(filename)[1].split(".")
                sta['dtime'] = int(filename1[1])
                return sta
        else:
            return None
    else:
        return None




print(nvb.gds_element_id.温度)
dir =  r"SURFACE/PLOT_ALL/YYYYMMDDHH0000.000"
time0 = datetime.datetime(2020,1,28,8,0)
path = nvb.get_path(dir,time0)
ip,port  = nvb.read_gds_ip_port(r"H:\test_data\input\nvb\ip_port.txt")
#print(path)

#nvb.print_gds_file_values_names(ip,port,path)
df = pd.DataFrame({"id":[811739],"lon":[114.0942],"lat":[30.5319]})
station = nvb.sta_data(df)
begin = time.time()
time1 = datetime.datetime(2019,1,28,8,0)
sta = nvb.read_stadata_from_gds(ip,port,path,nvb.gds_element_id.温度,time = time1)
print(time.time() - begin)
print(sta)