SAMT2 a spatial simulation toolkit implemented as Python module

Example for classification of a yield map.

The application shows the investigation field ``wu141'' of a farm located in the region of Köthen, a town in middle of Germany. The region is very dry with a mean precipitation of 504mm/a. The farm was a partner of the project ``pre agro 2'' supported by the German Federal Ministry of Education and Research. The relyield map, produced by the measurement equipment of the combine harvester.

In [8]:
%matplotlib inline
# load the module 
import grid
# load the relyield from an HDF 
relyield=grid.grid()
relyield.read_hdf('training.h5','relyield')
relyield.show()


show: 0.451764971018 1.71612787247 -9999
Out[8]:
True
This map show also all the obvious errors produced by the measurement equipment. The aim of this tutorial ist to show how this noise can be removed from the relyield map and build a classification which can be used to control the fertilizer appication accroding to the expected yield.
The idea is to select 100 random points from the relyield and use this data for a thin-plate interpolation. This removes the noise efficiently.

In [9]:
# take a random sample of 100 data points
sample=relyield.sample(100)
# take the rows, cols and values from the sample
rows=sample[0]
cols=sample[1]
vals=sample[2]
print rows
print cols
print vals


[ 46  76 116 147 128   7  95   6 133  72 119 101  90 132 115 131  33  21
  87 113 144 124  10  98 119  88  80   7 111  17 144  55 135 109 146  34
 100 111 132 144 110 131  12   6 119 123  76  61  50  56  70   8  72  75
  48  48  37 130  81 140  89 135  97  54 116  29  37  82 132  83 117 111
 123 142 103   7 133  57  37 124  99  24  69 118  69  19   7 100  49 102
  11   1  29 130  49  14  74  50  60  87]
[ 38 137 111 110  37 113  31  60  45 124  37  94  99 105  13  64  46  82
 121  51  27  96  82  25  73 118  73  63  54 102  81  34  40  65  40 138
  48  37  19  62 121  61 123  71  33  75  87  72 157 122  74  82  89  43
 161  77  58  63  47  79 146  92  51  80 104  53  51  78  37  23  95 135
 110 106 112 138 131  75 121  95  67  70  39  65  29 140 135 127 143  94
 117  57 102  83 158 124 151  35  93 148]
[ 0.79340661  0.75700337  0.91556287  1.17739189  1.03817594  1.15241206
  0.77299637  1.06269896  0.74771214  0.79660523  0.84961063  1.38453901
  1.01167297  1.145558    0.8454982   1.03116989  1.46069694  1.32848799
  0.70993817  0.75989735  0.55686212  1.08204293  1.40555894  0.8256973
  1.47684205  0.79584372  1.25172091  1.24075401  0.99689883  1.46069694
  0.84275651  0.93551612  0.79858524  1.33991098  0.5854972   0.92698646
  1.12773693  1.19597399  0.80102223  0.56006068  0.67185956  0.99034923
  1.41180396  1.25431097  0.75608963  1.29985309  1.16429293  0.89500052
  0.76720846  0.70613033  0.80056542  1.29924297  0.94008553  1.10108197
  0.89713275  0.74283814  1.34828901  1.02066004  0.84123337  0.99826974
  0.92241704  1.00512397  0.90992725  0.78777099  0.83757782  1.51842403
  1.49085486  1.04381204  0.88708007  1.57523692  1.08539391  0.6328671
  0.91769528  0.99202472  0.83514076  0.94907206  0.76142049  0.78472471
  0.76705617  1.09879696  1.33762693  1.55650294  1.08036697  1.23618495
  1.10153902  1.26923692  1.05691099  0.72532201  0.66561466  1.366871
  1.27075994  1.14205492  1.11463797  1.14890897  0.78274459  1.30442202
  0.76340073  0.93901932  0.73202378  0.93764848]

In [10]:
# perform the thin-plate interpolation using the samled points: gout is the interpolated grid
gout=grid.copy_grid(relyield)
gout.interpolate(rows,cols,vals,'thin_plate')
gout.show()


show: 0.275622397661 1.64517343044 -9999
Out[10]:
True

In [11]:
# remove the values outside of the investigation area
gout.and_grid(relyield)
gout.show()


show: 0.33342063427 1.58434855938 -9999
Out[11]:
True

In [12]:
# calculate the difference between the grids (relyield is overwritten)
relyield.diff_grid(gout)
relyield.show()


show: -0.427720725536 0.572366952896 -9999
Out[12]:
True

In [13]:
# show the histogram of the difference grid
relyield.show_hist()


Out[13]:
True

In [14]:
# finally reclass the interpolated grid using 5 classes
gout.classify(5)
gout.show()


classify: 0.0 2.0 2.0
show: 0.0 3.0 -9999
Out[14]:
True
Please feel free to change the number of sample points and look how the interpolation is affected.