{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pykrige import OrdinaryKriging" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "ok = OrdinaryKriging(data[:,0],data[:,1],data[:,2])\n", "ok.ex" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "a,b = ok.execute('grid',x[0],y[:,0])" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "from pykrige import OrdinaryKriging\n", "import pandas as pd\n", "import numpy as np\n", "\n", "def ordinary_kriging(dataset, resolution='standard', coordinate_type='euclidean',verbose='False',method='grid', isvariance = False):\n", " if coordinate_type == 'latlong_small':\n", " \"\"\"\n", " Assume that the Earth is a Sphere, and use polar coordinates\n", " $| \\vec{r_2}− \\vec{r_1}| ≈ \\text{R }\\times \\sqrt[]{(Lat_2 - Lat_1)^{2} + (Long_2 - Long_1)^{2}}$\n", " \"\"\"\n", " return \"To be done later\"\n", " if coordinate_type == 'latlong_large':\n", " \"\"\"\n", " Code to be written after understanding all the projections.\n", " \"\"\"\n", " return \"To be done later\"\n", " if coordinate_type==\"euclidean\":\n", " \n", " ok = OrdinaryKriging(dataset[:,0],dataset[:,1],dataset[:,2])\n", " X = dataset[:,0]\n", " y = dataset[:,1]\n", " \n", " if resolution=='high':\n", " xx,yy = make_grid(X,y,1000)\n", " \n", " elif resolution=='low':\n", " xx,yy = make_grid(X,y,10)\n", " \n", " elif resolution=='standard':\n", " xx,yy = make_grid(X,y,100)\n", " \n", " else:\n", " print('Value Error - Resolution can only be one of \\nhigh, low or standard')\n", " \n", " values, variances = ok.execute(method, xx[0], yy[:,0])\n", " \n", " if isvariance:\n", " return values, variances\n", " else:\n", " del variances\n", " return np.array(values)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[129.94984945, 129.7682324 , 129.58820662, ..., 159.34079485,\n", " 159.99175016, 160.63241067],\n", " [130.22090025, 130.03615966, 129.8529146 , ..., 159.9575165 ,\n", " 160.61228126, 161.25625641],\n", " [130.50105231, 130.31324536, 130.12683652, ..., 160.59265384,\n", " 161.25084023, 161.8977369 ],\n", " ...,\n", " [207.22133238, 207.82739139, 208.44615116, ..., 248.64646661,\n", " 248.3790241 , 248.11033441],\n", " [207.92838926, 208.53490708, 209.15376273, ..., 248.91678379,\n", " 248.65601627, 248.39371596],\n", " [208.61942088, 209.22595474, 209.84445913, ..., 249.17442481,\n", " 248.9203453 , 248.66446245]])" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ordinary_kriging(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* What does ok('points') really do?\n", "* Specifically test when points aren't really passed - they are let's say the point of an array\n", "* Returns the diagonal matrix of all these coordinates" ] }, { "cell_type": "code", "execution_count": 63, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "array([129.94984945, 130.03615966, 130.12683652, 130.22219703,\n", " 130.32258826, 130.42839089, 130.54002324, 130.65794596,\n", " 130.7826674 , 130.91474976, 131.05481629, 131.20355964,\n", " 131.36175158, 131.53025441, 131.71003442, 131.90217771,\n", " 132.107909 , 132.32861401, 132.56586607, 132.82145795,\n", " 133.0974399 , 133.39616477, 133.72034153, 134.07309736,\n", " 134.45804822, 134.87937482, 135.34189663, 135.85112772,\n", " 136.41328222, 137.03517039, 137.72388496, 138.48612122,\n", " 139.326921 , 140.24763047, 141.24300526, 142.29757046,\n", " 143.37881815, 144.38425962, 144.49187978, 143.1202101 ,\n", " 141.66667134, 140.45686022, 139.66795657, 142.48270308,\n", " 147.03665055, 151.8487008 , 156.90272514, 162.25791164,\n", " 168.04938768, 173.63870768, 180.93567147, 190.3440156 ,\n", " 199.86834472, 208.48375248, 215.75635742, 222.1915652 ,\n", " 228.08641413, 233.15249702, 236.89713686, 239.83524192,\n", " 242.45744315, 244.57483343, 245.52139699, 245.88236757,\n", " 246.12295211, 246.3306567 , 246.52369882, 246.70598807,\n", " 246.87792737, 247.03919426, 247.18952217, 247.3288843 ,\n", " 247.45749059, 247.57573348, 247.68412862, 247.78326467,\n", " 247.87376505, 247.95626051, 248.03137024, 248.09968963,\n", " 248.16178271, 248.21817801, 248.26936683, 248.31580309,\n", " 248.35790422, 248.39605277, 248.43059841, 248.46186013,\n", " 248.49012851, 248.51566797, 248.53871897, 248.55950011,\n", " 248.57821004, 248.59502931, 248.61012204, 248.62363741,\n", " 248.63571111, 248.64646661, 248.65601627, 248.66446245])" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ordinary_kriging(data,method='points')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def make_grid(X,y,res):\n", " y_min = y.min()-0.2\n", " y_max = y.max()+0.2\n", " x_min = X.min()-0.2\n", " x_max = X.max()+0.2\n", " x_arr = np.linspace(x_min,x_max,res)\n", " y_arr = np.linspace(y_min,y_max,res)\n", " xx,yy = np.meshgrid(x_arr,y_arr) \n", " return xx,yy\n", "x, y = make_grid(data[:,0],data[:,1],100)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }