def Krige_Interpolate(
    X, Y, new_X, variogram_parameters={"slope": 1e-4, "nugget": 1e-5}
):
    # X, Y, new_X, variogram_parameters={"sill": 1e3, "range": 1e2, "nugget": 0.0001}

    uk = OrdinaryKriging(
        X,
        np.zeros(X.shape),
        Y,
        pseudo_inv=True,
        # weight=True,
        # nlags=2,
        # variogram_model="gaussian",
        # exact_values = False,
        variogram_model="linear",
        variogram_parameters=variogram_parameters
        # variogram_model="gaussian",
        # variogram_parameters=variogram_parameters,
    )

    y_pred, y_std = uk.execute("grid", new_X, np.array([0.0]))
    y_pred = np.squeeze(y_pred)
    y_std = np.squeeze(y_std)

    return new_X, y_pred, y_std
Esempio n. 2
0
def do_krigin_for_one_sigma(sig):
    T = get_T_from_metric_and_sigma(Metric, sig)
    x = np.arange(min, max, T)
    y = np.copy(x)
    for i in range(len(x)):
        y[i] = np.random.normal(fonction_to_follow(x[i]), sig)
    uk = OrdinaryKriging(x, np.zeros(x.shape), y, variogram_model="gaussian", variogram_parameters={'nugget': sig, 'psill': 0.1, 'range' : 3})
    y_pred, y_std = uk.execute("grid", inputs, np.array([0.0]))
    y_pred = np.squeeze(y_pred)
    y_std = np.squeeze(y_std)

    fig, ax = plt.subplots(1, 1, figsize=(10, 4))
    ax.scatter(x, y, s=40, label="Input data")

    ax.plot(inputs, y_pred, label="Predicted values")
    ax.fill_between(
        inputs,
        y_pred - 3 * y_std,
        y_pred + 3 * y_std,
        alpha=0.3,
        label="Confidence interval",
    )
    ax.legend(loc=9)
    ax.set_xlabel("x")
    ax.set_ylabel("y")
    plt.show()
    return y_pred, y_std
Esempio n. 3
0
def krige_greenery(green_res, lat_grid, long_grid, init_kwargs={}, **kwargs):

    coor, green = _stack_green_res(green_res)
    OK = OrdinaryKriging(coor[:, 0], coor[:, 1], green,
                         **init_kwargs)

    lat_grid, long_grid = _lat_long_to_metric(lat_grid, long_grid)
    z, _ = OK.execute('grid', long_grid, lat_grid, backend='loop',
                      **kwargs)
    return z
Esempio n. 4
0
def create_kriged_overlay(green_res, grid=[200, 200], cmap="gist_rainbow",
                          overlay_fp="krige_map.json", name=None,
                          n_closest_points=None):
    """
    Create an overlay for openstreetmap using kriging as interpolation.

    Arguments
    ---------
    green_res: dict
        Contains greenery values with coordinates.
    n_grid: int
        Number of grid points.
    cmap: str
        Matplotlib color map.
    overlay_fp: str
        Filepath to store kriged map. Use as cache if available.
    name: str
        Name to give to the overlay.
    n_closest_points: int
        Used in kriging procedure to limit memory/compute time.
    """
#     Load overlay from file if available.
#     try:
#         overlay = MapImageOverlay(overlay_fp)
#         return overlay
#     except FileNotFoundError:
#         pass

    if name is None:
        name = overlay_fp

    lat = np.array(green_res['lat'])
    long = np.array(green_res['long'])

    lat_grid = np.linspace(lat.min(), lat.max(), num=grid[1])
    long_grid = np.linspace(long.min(), long.max(), num=grid[0])

    green = np.zeros((len(green_res["green"]), 3))
    for i in range(len(green_res["green"])):
        green[i][0] = green_res["long"][i]
        green[i][1] = green_res["lat"][i]
        green[i][2] = green_res["green"][i]

    OK = OrdinaryKriging(green[:, 0], green[:, 1], green[:, 2],
                         variogram_model='spherical')
    z, _ = OK.execute('grid', long_grid, lat_grid, backend='loop',
                      n_closest_points=n_closest_points)

    alpha_map = _alpha_from_coordinates(lat, long, grid)
    overlay = MapImageOverlay(z, lat_grid=lat_grid, long_grid=long_grid,
                              alpha_map=alpha_map,
                              cmap=cmap, name=name)
    overlay.save(overlay_fp)
    return overlay
Esempio n. 5
0
def krige_greenery(greenery_dict, krige_tiles, tile, init_kwargs={},
                   dots_per_tile=10):

    coor, green = _compile_greenery(greenery_dict, krige_tiles)
    OK = OrdinaryKriging(coor[:, 0], coor[:, 1], green,
                         **init_kwargs)

    bbox = tile["bbox"]
    lat_grid_degree = np.linspace(bbox[0][0], bbox[1][0], dots_per_tile, endpoint=False)
    long_grid_degree = np.linspace(bbox[0][1], bbox[1][1], dots_per_tile, endpoint=False)
    lat_grid, long_grid = _lat_long_to_metric(lat_grid_degree, long_grid_degree)
    z, _ = OK.execute('grid', long_grid, lat_grid, backend='loop')
    return z
Esempio n. 6
0
    def _interpol_func(self, x, y, z, xi, yi):
        ok = OrdinaryKriging(x,
                             y,
                             z,
                             nlags=self.nlags,
                             variogram_model=self.variogram_model,
                             weight=self.weight)
        # coordinates_type=self.coordinates_type)

        zi, sigma = ok.execute(style='points',
                               xpoints=xi,
                               ypoints=yi,
                               n_closest_points=self.n_closest_points,
                               backend=self.backend)

        self.sigma = sigma
        return zi
Esempio n. 7
0
def Krige_Interpolate(
    X, Y, new_X, variogram_parameters={"slope": 1e-4, "nugget": 1e-5}
):
   
    uk = OrdinaryKriging(
        X,
        np.zeros(X.shape),
        Y,
        pseudo_inv=True,
        variogram_model="linear",
        variogram_parameters=variogram_parameters
    )

    y_pred, y_std = uk.execute("grid", new_X, np.array([0.0]))
    y_pred = np.squeeze(y_pred)
    y_std = np.squeeze(y_std)

    return new_X, y_pred, y_std
Esempio n. 8
0
class Interpolator1D(BaseEstimator):
    def __init__(self, interpolation_type):
        self.interpolation_type = interpolation_type

    def fit_density(self, X):
        if frequency_interpolation_type == 'linear_density':
            self.model = scipy.interpolate.interp1d(list(Counter(X).keys()),
                                                    list(Counter(X).values()),
                                                    fill_value="extrapolate")

        if self.interpolation_type == 'kde':
            self.model = mlab.GaussianKDE(X, 'scott')

    def fit(self, X, y):
        if self.interpolation_type == 'kriging':
            # pykrige doesn't support 1D data for now, only 2D or 3D
            # adapting the 1D input to 2D
            self.model = OrdinaryKriging(X,
                                         np.zeros(X.shape),
                                         y,
                                         variogram_model='gaussian')

        if self.interpolation_type == 'linear':
            self.model = scipy.interpolate.interp1d(X,
                                                    y,
                                                    fill_value="extrapolate")

        if self.interpolation_type == 'gmm':
            self.model = cluster_utils.gmr(X, y)

    def predict(self, X_pred):
        if self.interpolation_type == 'kriging':
            y_pred, y_std = self.model.execute('grid', X_pred, np.array([0.]))
            return np.squeeze(y_pred)

        if self.interpolation_type in ['linear', 'linear_density']:
            return self.model(X_pred)

        if self.interpolation_type == 'kde':
            return self.model.evaluate(X_pred)

        if self.interpolation_type == 'gmm':
            return self.model.predict(np.array([0]),
                                      X_pred[:, np.newaxis]).ravel()
def Krige_Interpolate(X, Y, new_X):
    uk = OrdinaryKriging(
        X,
        np.zeros(X.shape),
        Y,
        pseudo_inv=True,
        weight=True,
        # nlags=3,
        # exact_values=False,
        variogram_model="linear",
        variogram_parameters={"slope": 3e-5, "nugget": 0.0002}
        # variogram_model="gaussian",
        # variogram_parameters={"sill": 1e2, "range": 1e2, "nugget": 0.0006},
    )

    y_pred, y_std = uk.execute("grid", new_X, np.array([0.0]), backend="loop")
    y_pred = np.squeeze(y_pred)
    y_std = np.squeeze(y_std)

    return new_X, y_pred, y_std
print(co2)

gridx = np.linspace(70.0, 75.0, 737)
#print(gridx)
gridy = np.linspace(22.0, 26.0, 448)
#print(gridy)

coords = np.transpose(
    [np.tile(gridx, len(gridy)),
     np.repeat(gridy, len(gridx))])
model = OrdinaryKriging(lon,
                        lat,
                        co2,
                        variogram_model='linear',
                        enable_plotting=True)
z, ss = model.execute('grid', gridx, gridy)
#
##read data from tif images for fpar values
fpar = rasterio.open('2010_01_01.tif')
#print(fpar.width)
fpar = fpar.read(1)
fpar = fpar.flatten()
print(len(fpar))

#
ndvi = rasterio.open('2010_01_01-737x448-ndvi.tif')
ndvi = ndvi.read(1)
ndvi = ndvi.flatten()
print(len(ndvi))

gpp = rasterio.open('2010_01_01-gpp.tif')
Esempio n. 11
0
import pandas as pd
import numpy as np
from mpl_toolkits.basemap import Basemap
import fiona
from pykrige import OrdinaryKriging
from shapely.geometry import Polygon, Point

workbook = pd.read_excel("pmdata.xlsx")
lon, lat, pm = workbook['lon'], workbook['lat'], workbook['PM2.5']

#116.362   30.7578 121.9752  35.1245
un_lon = np.linspace(116.362, 121.9752, 400)
un_lat = np.linspace(30.7578, 35.1245, 400)

OK = OrdinaryKriging(lon, lat, pm, variogram_model='gaussian', nlags=6)
zgrid, ss = OK.execute('grid', un_lon, un_lat)

xgrid, ygrid = np.meshgrid(un_lon, un_lat)

shp = fiona.open('shp/江苏省_行政边界.shp')
pol = shp.next()
polygon = Polygon(pol['geometry']['coordinates'][0][0])

#np.nan
for i in range(xgrid.shape[0]):
    for j in range(xgrid.shape[1]):
        plon = xgrid[i][j]
        plat = ygrid[i][j]
        if not polygon.contains(Point(plon, plat)):
            zgrid[i][j] = np.nan
def draw_function():
    if markclick == 0:  # mclick 如果不存在,则鼠标未点击色阶级数,则给mark1和mnum赋初始值
        mark1 = 0
        mnum = None
    else:
        mark1 = mark1_1
        mnum = mnum_1
    if btn_legendmin.get() == '默认':
        mark2 = 0
        mmin = None
    else:
        mark2 = 1
        mmin = float(btn_legendmin.get())
    if btn_legendmax.get() == '默认':
        mark3 = 0
        mmax = None
    else:
        mark3 = 1
        mmax = float(btn_legendmax.get())
        if mmax <= mmin:
            tm.showwarning('警告', '图例最大值应大于最小值!')

    # ------------警告提示框---------
    if (mark1 == 0 or mark1 == 1) and mark2 == 0 and mark3 == 0:
        pass
    elif color_mark == 6:
        pass
    elif mark1 == 0 and (mark2 == 1 or mark3 == 1):
        tm.showwarning('警告', '色阶级数默认情况下,图例最小值和图例最大值均应为“默认”。')
        return
    elif mark1 == 1 and mark2 == 1 and mark3 == 1:
        pass
    else:
        tm.showinfo('提示', '色阶级数非默认情况下,需同时自定义设置图例最小值和图例最大值;否则图例最大值和最小值以默认值绘出。')
        pass

    path0 = 'DTool/dishi.shp'
    file = shapefile.Reader(path0)
    rec = file.shapeRecords()
    polygon = list()
    for r in rec:
        polygon.append(Polygon(r.shape.points))
    poly = cascaded_union(polygon)  # 并集
    ext = list(poly.exterior.coords)  # 外部点
    codes = [Path.MOVETO] + [Path.LINETO] * (len(ext) - 1) + [Path.CLOSEPOLY]
    #    codes += [Path.CLOSEPOLY]
    ext.append(ext[0])  # 起始点
    path = Path(np.array(ext), codes)
    patch = PathPatch(path, facecolor='None')

    x, y = df['经度'], df['纬度']
    xi = np.arange(113, 118.5, 0.01)
    yi = np.arange(24, 31, 0.01)
    olon, olat = np.meshgrid(xi, yi)

    # Rbf空间插值
    # func = Rbf(x, y, z, function='linear')
    # oz = func(olon, olat)

    # 克里金插值
    ok = OrdinaryKriging(x, y, z, variogram_model='linear')
    oz, ss = ok.execute('grid', xi, yi)

    ax = plt.axes(projection=ccrs.PlateCarree())
    box = [113.4, 118.7, 24.1, 30.4]
    ax.set_extent(box, crs=ccrs.PlateCarree())
    ax.add_patch(patch)
    shp = list(shpreader.Reader(path0).geometries())
    ax.add_geometries(shp,
                      ccrs.PlateCarree(),
                      edgecolor='black',
                      facecolor='none',
                      alpha=0.3,
                      linewidth=0.5)  # 加底图
    if mark1 == 1 and mark2 == 1 and mark3 == 1 and btn_style.get(
    ) != 'CMA_Rain':
        v = np.linspace(mmin, mmax, num=mnum, endpoint=True)  # 设置显示数值范围和级数
        if color_mark == 1:
            pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.jet)
        elif color_mark == 2:
            pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.rainbow)
        elif color_mark == 3:
            pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.gist_rainbow)
        elif color_mark == 4:
            pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.OrRd)
    elif btn_style.get() == 'CMA_Rain':
        # 应加入超出levels的提示
        try:
            rain_levels = [0, 0.1, 10, 25, 50, 100, 250, 2500]
            rain_colors = [
                '#FFFFFF', '#A6F28F', '#38A800', '#61B8FF', '#0000FF',
                '#FA00FA', '#730000', '#400000'
            ]
            pic = plt.contourf(olon,
                               olat,
                               oz,
                               levels=rain_levels,
                               colors=rain_colors)
            # cbar = plt.colorbar(pic, ticks=[0, 0.1, 10, 25, 50, 100, 250])
            # position = fig.add_axes([0.65, 0.15, 0.03, 0.3])  # 位置
            # plt.colorbar(pic, ticks=[0, 0.1, 10, 25, 50, 100, 250], cax=position, orientation='vertical')
            # cbar.set_label(btn9.get(), fontproperties='SimHei')  # 图例label在右边
        except:
            if np.min(z) < 0:
                tm.showinfo(message='存在负数,超出降水图例范围!请换其他颜色样式。')
            elif np.max(z) > 2500:
                tm.showinfo(message='降水量过大,请何查数据!或请换其他颜色样式。')
                # cbar.make_axes(locations='top')
        # cbar.ax.set_xlabel(btn9.get(),fontproperties='SimHei')
    else:
        if color_mark == 1:
            if mark1 == 0:  # 未设置级数
                pic = plt.contourf(olon, olat, oz, cmap=plt.cm.jet)
            else:
                v = np.linspace(np.min(oz),
                                np.max(oz),
                                num=mnum,
                                endpoint=True)  # 设置显示数值范围和级数
                pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.jet)
        elif color_mark == 2:
            if mark1 == 0:
                pic = plt.contourf(olon, olat, oz, cmap=plt.cm.rainbow)
            else:
                v = np.linspace(np.min(oz),
                                np.max(oz),
                                num=mnum,
                                endpoint=True)
                pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.rainbow)
        elif color_mark == 3:
            if mark1 == 0:
                pic = plt.contourf(olon, olat, oz, cmap=plt.cm.gist_rainbow)
            else:
                v = np.linspace(np.min(oz),
                                np.max(oz),
                                num=mnum,
                                endpoint=True)
                pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.gist_rainbow)
        elif color_mark == 4:
            if mark1 == 0:
                pic = plt.contourf(olon, olat, oz, cmap=plt.cm.OrRd)
            else:
                v = np.linspace(np.min(oz),
                                np.max(oz),
                                num=mnum,
                                endpoint=True)
                pic = plt.contourf(olon, olat, oz, v, cmap=plt.cm.OrRd)
        elif color_mark == 6:  # 自定义颜色
            # 判断出自定义颜色级数
            jishu_colors = []
            for index, r in enumerate(rgb):
                if r == None:
                    num_color = index
                    break
                else:
                    jishu_colors.append(r)

            if mark2 == 1 and mark3 == 1:  # mark2最小值;mark3最大值
                v = np.linspace(mmin, mmax, num=num_color + 1,
                                endpoint=True)  # 设置显示数值范围和级数
                pic = plt.contourf(olon, olat, oz, v, colors=jishu_colors)
            else:
                v = np.linspace(np.min(oz),
                                np.max(oz),
                                num=len(jishu_colors) + 1,
                                endpoint=True)
                pic = plt.contourf(olon, olat, oz, v, colors=jishu_colors)

    for collection in pic.collections:
        collection.set_clip_path(patch)  # 设置显示区域

    plt.scatter(x, y, marker='.', c='k', s=10)  # 绘制站点

    # 添加显示站名、数值等标签
    for i in range(len(z)):
        plt.text(x[i], y[i] + 0.05, df['站名'][i], size=5.5, weight=2, wrap=True)
    # 添加单位标注
    plt.text(117.75, 27.1, btn_legendunit.get(), size=8, weight=2)
    fig = plt.gcf()
    fig.set_size_inches(6, 4)  # 设置图片大小
    plt.axis('off')  # 去除四边框框
    if btn_style.get() == 'CMA_Rain':
        position = fig.add_axes([0.65, 0.15, 0.03, 0.3])  # 位置
        plt.colorbar(pic,
                     ticks=[0, 0.1, 10, 25, 50, 100, 250],
                     cax=position,
                     orientation='vertical')
    else:
        position = fig.add_axes([0.65, 0.15, 0.03, 0.3])  # 位置
        plt.colorbar(pic, cax=position, orientation='vertical')

    plt.savefig('pics_dpi100.png', dpi=100, bbox_inches='tight')
    plt.savefig('pics_dpi300.png', dpi=300, bbox_inches='tight')
    plt.close()
    wifi_img = Image.open('pics_dpi100.png')
    img = ImageTk.PhotoImage(wifi_img)
    window.img = img  # to prevent the image garbage collected.
    canvas.create_image(200, 180, anchor='center', image=img)  # 设置生成的图片位置
Esempio n. 13
0
                 [2.63, -1.37], [2.72, -0.99], [2.80, -1.92], [2.83, -1.94],
                 [2.91, -1.32], [3.00, -1.69], [3.13, -1.84], [3.21, -2.05],
                 [3.30, -1.69], [3.41, -0.53], [3.52, -0.55], [3.63, -0.92],
                 [3.72, -0.76], [3.80, -0.41], [3.91, 0.12], [4.04, 0.25],
                 [4.13, 0.16], [4.24, 0.26], [4.32, 0.62], [4.44, 1.69],
                 [4.52, 1.11], [4.65, 0.36], [4.74, 0.79], [4.84, 0.87],
                 [4.93, 1.01], [5.02, 0.55]]).T
# fmt: on

X_pred = np.linspace(-6, 6, 200)

# pykrige doesn't support 1D data for now, only 2D or 3D
# adapting the 1D input to 2D
uk = OrdinaryKriging(X, np.zeros(X.shape), y, variogram_model="gaussian")

y_pred, y_std = uk.execute("grid", X_pred, np.array([0.0]))

y_pred = np.squeeze(y_pred)
y_std = np.squeeze(y_std)

fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.scatter(X, y, s=40, label="Input data")

ax.plot(X_pred, y_pred, label="Predicted values")
ax.fill_between(
    X_pred,
    y_pred - 3 * y_std,
    y_pred + 3 * y_std,
    alpha=0.3,
    label="Confidence interval",
)
Esempio n. 14
0
     [3.00 ,-1.69], [3.13 ,-1.84], [3.21 ,-2.05], [3.30 ,-1.69], [3.41 ,-0.53],
     [3.52 ,-0.55], [3.63 ,-0.92], [3.72 ,-0.76], [3.80 ,-0.41], [3.91 , 0.12],
     [4.04 , 0.25], [4.13 , 0.16], [4.24 , 0.26], [4.32 , 0.62], [4.44 , 1.69],
     [4.52 , 1.11], [4.65 , 0.36], [4.74 , 0.79], [4.84 , 0.87], [4.93 , 1.01],
     [5.02 , 0.55]]).T


from pykrige import OrdinaryKriging

X_pred = np.linspace(-6, 6, 200)

# pykrige doesn't support 1D data for now, only 2D or 3D
# adapting the 1D input to 2D
uk = OrdinaryKriging(X, np.zeros(X.shape), y, variogram_model='gaussian',)

y_pred, y_std = uk.execute('grid', X_pred, np.array([0.]))

y_pred = np.squeeze(y_pred)
y_std = np.squeeze(y_std)

fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.scatter(X, y, s=40, label='Input data')


ax.plot(X_pred, y_pred, label='Predicted values')
ax.fill_between(X_pred, y_pred - 3*y_std, y_pred + 3*y_std, alpha=0.3, label='Confidence interval')
ax.legend(loc=9)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim(-6, 6)
ax.set_ylim(-2.8, 3.5)
t = np.array(range(0, nt))
x = lon_u
y = lat_u
nx = len(x)
ny = len(y)



if exp == "interpolated":
    # Interpolation of (TAHMO) stations on the regular grid
    v_input = np.zeros((nt,37,37))
    for k in range(nt):
        OK = OrdinaryKriging(lon_v, lat_v, np.sqrt(v_station[k, :]), variogram_model='exponential',
                             variogram_parameters={'sill': 1.0, 'range': 2, 'nugget': 0.01}, nlags=50, verbose=False,
                             enable_plotting=False, weight=True, coordinates_type='geographic')
        z, ss = OK.execute('grid', lon_u[14:-14], lat_u[14:-14])
        v_input[k, :, :] = (z ** 2).T

elif exp == "full":
    # For the "full" experiment, the reference data is already on the grid. We only have to select the domain we want (37 by 37 grid points)
    v_input = v_truth[:,14:-14,14:-14]



#==================================================================
# Pre-processing
print('\nStart pre-processing')

# Extend the domain
u = np.zeros((nt, nx, ny))
u[:, 14:-14, 14:-14] = u_input
Esempio n. 16
0
                 [4.93, 1.01], [5.02, 0.55]]).T

from pykrige import OrdinaryKriging

X_pred = np.linspace(-6, 6, 200)

# pykrige doesn't support 1D data for now, only 2D or 3D
# adapting the 1D input to 2D
uk = OrdinaryKriging(
    X,
    np.zeros(X.shape),
    y,
    variogram_model='gaussian',
)

y_pred, y_std = uk.execute('grid', X_pred, np.array([0.]))

y_pred = np.squeeze(y_pred)
y_std = np.squeeze(y_std)

fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.scatter(X, y, s=40, label='Input data')

ax.plot(X_pred, y_pred, label='Predicted values')
ax.fill_between(X_pred,
                y_pred - 3 * y_std,
                y_pred + 3 * y_std,
                alpha=0.3,
                label='Confidence interval')
ax.legend(loc=9)
ax.set_xlabel('x')
Esempio n. 17
0
for k in range(nt):
    OK = OrdinaryKriging(lon_v,
                         lat_v,
                         np.sqrt(v_station[k, :]),
                         variogram_model='exponential',
                         variogram_parameters={
                             'sill': 1.0,
                             'range': 2,
                             'nugget': 0.01
                         },
                         nlags=50,
                         verbose=False,
                         enable_plotting=False,
                         weight=True,
                         coordinates_type='geographic')
    z, ss = OK.execute('grid', lon_u, lat_u)
    v[k, :, :] = (z**2).T

u_input = u.copy()
v_input = v.copy()

#==================================================================
# Pre-processing
print('\nPre-processing')

# Extend the domain
x = np.array(np.arange(-4.75, 1.75, 0.1))
y = np.array(np.arange(3.25, 9.75, 0.1))
xx, yy = np.meshgrid(x, y, indexing='ij')
ny = len(y)
nx = len(x)
Esempio n. 18
0
    file = '..\\database\\dataSet60_' + str(x) + '.csv'
    data = np.array(np.loadtxt(file, delimiter=','))
    dataOld = np.array(
        pd.read_csv('..\\database\\ptr.water.csv', delimiter=','))
    dataInt = open('..\\database\\dataSetInterpolatedKringing.csv', 'w')

    gridx = np.arange(0.0, 72, 0.5)
    gridy = np.arange(0.0, 37, 0.5)

    OK = OrdinaryKriging(data[:, 0],
                         data[:, 1],
                         data[:, 2],
                         variogram_model='linear',
                         verbose=False,
                         enable_plotting=False)
    z, ss = OK.execute('grid', gridx, gridy)
    kt.write_asc_grid(gridx, gridy, z, filename="output.asc")

    valor = 0
    suma = 0
    for k in range(1, 2, 1):
        print('Iteracion ', k)
        for i in range(0, 72, 1):
            for j in range(0, 144, 1):
                valor = round(data[i][j], 4)
                valorOld = round(dataOld[i][j], 4)
                if (i == 0 and j < 143) or (j == 0 and j < 143):
                    dataInt.write(str(valor) + ',')
                    #print('test', i, rows - 1, j, columns - 1)
                elif (i == 73 and j < 143):
                    dataInt.write(valor + ',')