예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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")
예제 #5
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