WOLFRAM NOTEBOOK

Using kriging functionality from pykrige

Start a session that creates a Python virtual environment with pykrige and also import the UniversalKriging function:
In[]:=
session=StartExternalSession[<|"System"->"Python","Evaluator"-><|"Dependencies"->"pykrige"|>,"SessionProlog"->{"from pykrige.uk import UniversalKriging","import numpy as np"}|>]
Out[]=
ExternalSessionObject
System: Python
Name: None
Evaluator:
/Users/arnoudb/Library/Wolfram/ApplicationData/ExternalEvaluate/Python/Venv/EnvID-0s1aivs/bin/python
Generate some testing data:
In[]:=
{x,y,z}={{0.3`,1.9`,1.1`,3.3`,4.7`},{1.2`,0.6`,3.2`,4.4`,3.8`},{0.47`,0.56`,0.74`,1.47`,1.74`}}
Out[]=
{{0.3,1.9,1.1,3.3,4.7},{1.2,0.6,3.2,4.4,3.8},{0.47,0.56,0.74,1.47,1.74}}
Define a kriging test function:
In[]:=
kriging=ExternalFunction[session,"def kriging_test(x, y, z, gx, gy): uk = UniversalKriging(x,y,z) z, ss = uk.execute('grid', gx, gy) return z"]
Out[]=
ExternalFunction
System: Python
Status: NotEvaluated
Set the x and y range of the data:
In[]:=
gx=gy=Range[0.0,5.5,0.5]
Out[]=
{0.,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5}
Compute the result of the kriging function:
In[]:=
z=kriging[x,y,z,gx,gy]
Out[]=
NumericArray
Type: Real64
Dimensions: {12,12}
In[]:=
ArrayPlot[z,DataRange->{{0.0,5.5},{0.0,5.5}},FrameTicks->True]
Out[]=
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.