Exemplo n.º 1
0
def sta_to_sta_idw(sta0, station, effectR=1000, nearNum=16):
    sta1 = station.copy()
    xyz_sta0 = lon_lat_to_cartesian(sta0.ix[:, 0], sta0.ix[:, 1], R=bd.ER)
    xyz_sta1 = lon_lat_to_cartesian(sta1.ix[:, 0], sta1.ix[:, 1], R=bd.ER)
    tree = cKDTree(xyz_sta0)
    d, inds = tree.query(xyz_sta1, k=nearNum)
    d += 1e-6
    w = 1.0 / d**2
    input_dat = sta0.ix[:, 2]
    dat = np.sum(w * input_dat[inds], axis=1) / np.sum(w, axis=1)
    dat[:] = np.where(d[:, 0] > effectR, 0, dat[:])
    sta1.ix[:, 2] = dat
    return sta1
def get_nearby_sta_index_ensemble(sta, grid, nearNum=1):
    grd_en = bd.grid_data_ensemble(grid, nearNum)
    xyz_sta = lon_lat_to_cartesian(sta.ix[:, 0], sta.ix[:, 0], R=bd.ER)
    lon = np.arange(grd_en.nlon) * grd_en.dlon + grd_en.slon
    lat = np.arange(grd_en.nlat) * grd_en.dlat + grd_en.slat
    grid_lon, grid_lat = np.meshgrid(lon, lat)
    xyz_grid = lon_lat_to_cartesian(grid_lon.flatten(),
                                    grid_lat.flatten(),
                                    R=bd.ER)
    tree = cKDTree(xyz_sta)
    _, inds = tree.query(xyz_grid, k=nearNum)
    grd_en.dat = inds.reshape((nearNum, grd_en.nlat, grd_en.nlon))
    return grd_en
def get_nearby_sta_index_ensemble(sta_to, nearNum=100, sta_from=None):
    if (sta_to is None):
        return None
    sta_ensemble = bd.sta_data_ensemble(sta_to, nearNum)
    if (sta_from is None):
        sta_from = sta_to.copy()
    xyz_sta0 = lon_lat_to_cartesian(sta_to.ix[:, 0], sta_to.ix[:, 1], R=bd.ER)
    xyz_sta1 = lon_lat_to_cartesian(sta_from.ix[:, 0],
                                    sta_from.ix[:, 1],
                                    R=bd.ER)
    tree = cKDTree(xyz_sta0)
    _, indexs = tree.query(xyz_sta1, k=nearNum)
    sta_ensemble.ix[:, 2:] = indexs
    return sta_ensemble
def sta_to_grid_idw(sta, grid, background=None, effectR=1000, nearNum=16):
    grd = bd.grid_data(grid)
    xyz_sta = lon_lat_to_cartesian(sta.ix[:, 0], sta.ix[:, 1], R=bd.ER)
    lon = np.arange(grd.nlon) * grd.dlon + grd.slon
    lat = np.arange(grd.nlat) * grd.dlat + grd.slat
    grid_lon, grid_lat = np.meshgrid(lon, lat)
    xyz_grid = lon_lat_to_cartesian(grid_lon.flatten(),
                                    grid_lat.flatten(),
                                    R=bd.ER)
    tree = cKDTree(xyz_sta)
    d, inds = tree.query(xyz_grid, k=nearNum)
    d += 1e-6
    w = 1.0 / d**2
    input_dat = sta.ix[:, 2]
    dat = np.sum(w * input_dat[inds], axis=1) / np.sum(w, axis=1)
    bg = bd.grid_data(grid)
    if (background is not None):
        bg = ggf.linearInterpolation(background, grid)
    bg_dat = bg.dat.flatten()
    dat = np.where(d[:, 0] > effectR, bg_dat, dat)
    grd.dat = dat.reshape((grd.nlat, grd.nlon))
    return grd