예제 #1
0
def interpolate_func(Station_Info, file_path, file_name_list, feature):
    df = pd.DataFrame(Station_Info)
    # 将DataFrame格式转化为站点格式
    sta_ID = meb.sta_data(df, columns=["id", "lon", "lat"])
    meb.set_stadata_coords(
        sta_ID,
        level=0,
    )

    EC_data = pd.DataFrame()
    for file_name in file_name_list:
        time_ymdh = "20" + file_name[0:8]
        dtime_str = file_name[9:12]

        datetime1 = meb.all_type_time_to_datetime(time_ymdh)
        meb.set_stadata_coords(sta_ID, time=datetime1, dtime=dtime_str)

        # 读取EC原始文件
        read_path = os.path.join(file_path, file_name)
        grd_data = meb.read_griddata_from_micaps4(read_path)
        sta_data = meb.fun.trans_grd_to_sta(grd_data)

        meb.set_stadata_names(sta_ID, [feature])
        meb.set_stadata_names(sta_data, [feature])
        # 将要素的网格信息以站点格式使用反距离权重插值到站点中
        sta_IDW = meb.interp_ss_idw(sta_data, station=sta_ID, nearNum=4)

        sta_IDW["id"] = df["Station_ID"]  # 将id的70改回字符F
        EC_data = EC_data.append(sta_IDW, ignore_index=True)
    EC_data.drop(columns=['level'], inplace=True)
    return EC_data
예제 #2
0
 def dataframe_from_dict_json(j_dict,default=np.nan):
     import pandas as pd
     try:
         LogLib.info('CMADaasAccess Convert dataFrame from JSON_dict {0}'.format(datetime.datetime.now().strftime("%Y%m%d%H%M")))
         pddata = pd.DataFrame.from_dict(j_dict)
         ## 更改dataframe
         sta = meb.sta_data(pddata, columns=['time','id','lat','lon','data0'])
         sta.level = 0
         sta.dtime=0
         sta.time = pd.to_datetime(sta.time)
         sta.level = sta.level.astype(np.int16)
         sta.id = sta.id.astype(np.int32)
         sta.dtime = sta.dtime.astype(np.int16)
         sta.lon = sta.lon.astype(np.float32)
         sta.lat = sta.lat.astype(np.float32)
         sta.data0 = sta.data0.astype(np.float32)
         sta.data0[sta.data0>=10000]=default
         return(sta)            
     except Exception as data:
         LogLib.error('CMADaasAccess Convert dataFrame from JSON_dict {0}'.format(datetime.datetime.now().strftime("%Y%m%d%H%M")))
         return(None)
예제 #3
0
파일: EC_func.py 프로젝트: wlfa/test
def interpolate_MSL(file_path, file_name, ID_list, Longitude_raw,
                    Latitude_raw):
    # process_df = copy.deepcopy(MSL_df)
    df = pd.DataFrame()
    # def interpolate_func(Station_Info, file_path, file_name_list, feature):
    A_Info = GetPositionDelta(ID_list, Longitude_raw, Latitude_raw, 1)
    A_data = interpolate_func(A_Info, file_path, file_name, 'MSL')
    B_Info = GetPositionDelta(ID_list, Longitude_raw, Latitude_raw, 2)
    B_data = interpolate_func(B_Info, file_path, file_name, 'MSL')
    C_Info = GetPositionDelta(ID_list, Longitude_raw, Latitude_raw, 3)
    C_data = interpolate_func(C_Info, file_path, file_name, 'MSL')
    D_Info = GetPositionDelta(ID_list, Longitude_raw, Latitude_raw, 4)
    D_data = interpolate_func(D_Info, file_path, file_name, 'MSL')

    Longitude_list = basic_func.process_position(Longitude_raw, 8)  #字符串长度为8
    Latitude_list = basic_func.process_position(Latitude_raw, 7)  #字符串长度为8
    Station_Info = {
        "Station_ID": ID_list,
        "Longitude": Longitude_list,
        "Latitude": Latitude_list
    }

    df = pd.DataFrame(Station_Info)
    # 将DataFrame格式转化为站点格式
    MSL_df = meb.sta_data(df, columns=["id", "lon", "lat"])
    meb.set_stadata_names(MSL_df, ['MSL'])
    time_ymdh = "20" + file_name[0][0:8]
    dtime_str = file_name[0][9:12]
    datetime1 = meb.all_type_time_to_datetime(time_ymdh)
    meb.set_stadata_coords(MSL_df, time=datetime1, dtime=dtime_str)
    MSL_df.drop(columns=['level'], inplace=True)
    MSL_df["id"] = Station_Info["Station_ID"]  #将id的70改回字符F
    A_B = abs(A_data['MSL'] - B_data['MSL'])
    D_C = abs(D_data['MSL'] - C_data['MSL'])

    df['A-B'] = A_B
    df['D-C'] = D_C
    MSL_df['MSL'] = df[['A-B', 'D-C']].max(axis=1)
    print(MSL_df)
    return MSL_df