问题
I'm using mlab.griddata to interpolate some data when I encountered a strange and what looks like floating point precision bug. This is calling sequence:
nvals = matplotlib.mlab.griddata(lon_old.ravel(),
lat_old.ravel(),
ivals.ravel(),
lon_new,
lat_new,interp='linear').T
lat_old = array([ 19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483,
-2.8037247 , 19.62606908, 18.50457985, 17.38309053,
16.26160115, 15.14011169, 14.01862218, 12.8971326 ,
11.77564298, 10.65415331, 9.53266359, 8.41117384,
7.28968406, 6.16819425, 5.04670442, 3.92521457,
2.8037247 , 1.68223483, 0.56074494, -0.56074494,
-1.68223483, -2.8037247 , 19.62606908, 18.50457985,
17.38309053, 16.26160115, 15.14011169, 14.01862218,
12.8971326 , 11.77564298, 10.65415331, 9.53266359,
8.41117384, 7.28968406, 6.16819425, 5.04670442,
3.92521457, 2.8037247 , 1.68223483, 0.56074494,
-0.56074494, -1.68223483, -2.8037247 , 19.62606908,
18.50457985, 17.38309053, 16.26160115, 15.14011169,
14.01862218, 12.8971326 , 11.77564298, 10.65415331,
9.53266359, 8.41117384, 7.28968406, 6.16819425,
5.04670442, 3.92521457, 2.8037247 , 1.68223483,
0.56074494, -0.56074494, -1.68223483, -2.8037247 ,
19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483,
-2.8037247 , 19.62606908, 18.50457985, 17.38309053,
16.26160115, 15.14011169, 14.01862218, 12.8971326 ,
11.77564298, 10.65415331, 9.53266359, 8.41117384,
7.28968406, 6.16819425, 5.04670442, 3.92521457,
2.8037247 , 1.68223483, 0.56074494, -0.56074494,
-1.68223483, -2.8037247 , 19.62606908, 18.50457985,
17.38309053, 16.26160115, 15.14011169, 14.01862218,
12.8971326 , 11.77564298, 10.65415331, 9.53266359,
8.41117384, 7.28968406, 6.16819425, 5.04670442,
3.92521457, 2.8037247 , 1.68223483, 0.56074494,
-0.56074494, -1.68223483, -2.8037247 , 19.62606908,
18.50457985, 17.38309053, 16.26160115, 15.14011169,
14.01862218, 12.8971326 , 11.77564298, 10.65415331,
9.53266359, 8.41117384, 7.28968406, 6.16819425,
5.04670442, 3.92521457, 2.8037247 , 1.68223483,
0.56074494, -0.56074494, -1.68223483, -2.8037247 ,
19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483,
-2.8037247 , 19.62606908, 18.50457985, 17.38309053,
16.26160115, 15.14011169, 14.01862218, 12.8971326 ,
11.77564298, 10.65415331, 9.53266359, 8.41117384,
7.28968406, 6.16819425, 5.04670442, 3.92521457,
2.8037247 , 1.68223483, 0.56074494, -0.56074494,
-1.68223483, -2.8037247 , 19.62606908, 18.50457985,
17.38309053, 16.26160115, 15.14011169, 14.01862218,
12.8971326 , 11.77564298, 10.65415331, 9.53266359,
8.41117384, 7.28968406, 6.16819425, 5.04670442,
3.92521457, 2.8037247 , 1.68223483, 0.56074494,
-0.56074494, -1.68223483, -2.8037247 , 19.62606908,
18.50457985, 17.38309053, 16.26160115, 15.14011169,
14.01862218, 12.8971326 , 11.77564298, 10.65415331,
9.53266359, 8.41117384, 7.28968406, 6.16819425,
5.04670442, 3.92521457, 2.8037247 , 1.68223483,
0.56074494, -0.56074494, -1.68223483, -2.8037247 ,
19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483,
-2.8037247 , 19.62606908, 18.50457985, 17.38309053,
16.26160115, 15.14011169, 14.01862218, 12.8971326 ,
11.77564298, 10.65415331, 9.53266359, 8.41117384,
7.28968406, 6.16819425, 5.04670442, 3.92521457,
2.8037247 , 1.68223483, 0.56074494, -0.56074494,
-1.68223483, -2.8037247 , 19.62606908, 18.50457985,
17.38309053, 16.26160115, 15.14011169, 14.01862218,
12.8971326 , 11.77564298, 10.65415331, 9.53266359,
8.41117384, 7.28968406, 6.16819425, 5.04670442,
3.92521457, 2.8037247 , 1.68223483, 0.56074494,
-0.56074494, -1.68223483, -2.8037247 , 19.62606908,
18.50457985, 17.38309053, 16.26160115, 15.14011169,
14.01862218, 12.8971326 , 11.77564298, 10.65415331,
9.53266359, 8.41117384, 7.28968406, 6.16819425,
5.04670442, 3.92521457, 2.8037247 , 1.68223483,
0.56074494, -0.56074494, -1.68223483, -2.8037247 ,
19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483,
-2.8037247 , 19.62606908, 18.50457985, 17.38309053,
16.26160115, 15.14011169, 14.01862218, 12.8971326 ,
11.77564298, 10.65415331, 9.53266359, 8.41117384,
7.28968406, 6.16819425, 5.04670442, 3.92521457,
2.8037247 , 1.68223483, 0.56074494, -0.56074494,
-1.68223483, -2.8037247 , 19.62606908, 18.50457985,
17.38309053, 16.26160115, 15.14011169, 14.01862218,
12.8971326 , 11.77564298, 10.65415331, 9.53266359,
8.41117384, 7.28968406, 6.16819425, 5.04670442,
3.92521457, 2.8037247 , 1.68223483, 0.56074494,
-0.56074494, -1.68223483, -2.8037247 , 19.62606908,
18.50457985, 17.38309053, 16.26160115, 15.14011169,
14.01862218, 12.8971326 , 11.77564298, 10.65415331,
9.53266359, 8.41117384, 7.28968406, 6.16819425,
5.04670442, 3.92521457, 2.8037247 , 1.68223483,
0.56074494, -0.56074494, -1.68223483, -2.8037247 ,
19.62606908, 18.50457985, 17.38309053, 16.26160115,
15.14011169, 14.01862218, 12.8971326 , 11.77564298,
10.65415331, 9.53266359, 8.41117384, 7.28968406,
6.16819425, 5.04670442, 3.92521457, 2.8037247 ,
1.68223483, 0.56074494, -0.56074494, -1.68223483, -2.8037247 ])
lon_old = array([ 228.375, 228.375, 228.375, 228.375, 228.375, 228.375,
228.375, 228.375, 228.375, 228.375, 228.375, 228.375,
228.375, 228.375, 228.375, 228.375, 228.375, 228.375,
228.375, 228.375, 228.375, 229.5 , 229.5 , 229.5 ,
229.5 , 229.5 , 229.5 , 229.5 , 229.5 , 229.5 ,
229.5 , 229.5 , 229.5 , 229.5 , 229.5 , 229.5 ,
229.5 , 229.5 , 229.5 , 229.5 , 229.5 , 229.5 ,
230.625, 230.625, 230.625, 230.625, 230.625, 230.625,
230.625, 230.625, 230.625, 230.625, 230.625, 230.625,
230.625, 230.625, 230.625, 230.625, 230.625, 230.625,
230.625, 230.625, 230.625, 231.75 , 231.75 , 231.75 ,
231.75 , 231.75 , 231.75 , 231.75 , 231.75 , 231.75 ,
231.75 , 231.75 , 231.75 , 231.75 , 231.75 , 231.75 ,
231.75 , 231.75 , 231.75 , 231.75 , 231.75 , 231.75 ,
232.875, 232.875, 232.875, 232.875, 232.875, 232.875,
232.875, 232.875, 232.875, 232.875, 232.875, 232.875,
232.875, 232.875, 232.875, 232.875, 232.875, 232.875,
232.875, 232.875, 232.875, 234. , 234. , 234. ,
234. , 234. , 234. , 234. , 234. , 234. ,
234. , 234. , 234. , 234. , 234. , 234. ,
234. , 234. , 234. , 234. , 234. , 234. ,
235.125, 235.125, 235.125, 235.125, 235.125, 235.125,
235.125, 235.125, 235.125, 235.125, 235.125, 235.125,
235.125, 235.125, 235.125, 235.125, 235.125, 235.125,
235.125, 235.125, 235.125, 236.25 , 236.25 , 236.25 ,
236.25 , 236.25 , 236.25 , 236.25 , 236.25 , 236.25 ,
236.25 , 236.25 , 236.25 , 236.25 , 236.25 , 236.25 ,
236.25 , 236.25 , 236.25 , 236.25 , 236.25 , 236.25 ,
237.375, 237.375, 237.375, 237.375, 237.375, 237.375,
237.375, 237.375, 237.375, 237.375, 237.375, 237.375,
237.375, 237.375, 237.375, 237.375, 237.375, 237.375,
237.375, 237.375, 237.375, 238.5 , 238.5 , 238.5 ,
238.5 , 238.5 , 238.5 , 238.5 , 238.5 , 238.5 ,
238.5 , 238.5 , 238.5 , 238.5 , 238.5 , 238.5 ,
238.5 , 238.5 , 238.5 , 238.5 , 238.5 , 238.5 ,
239.625, 239.625, 239.625, 239.625, 239.625, 239.625,
239.625, 239.625, 239.625, 239.625, 239.625, 239.625,
239.625, 239.625, 239.625, 239.625, 239.625, 239.625,
239.625, 239.625, 239.625, 240.75 , 240.75 , 240.75 ,
240.75 , 240.75 , 240.75 , 240.75 , 240.75 , 240.75 ,
240.75 , 240.75 , 240.75 , 240.75 , 240.75 , 240.75 ,
240.75 , 240.75 , 240.75 , 240.75 , 240.75 , 240.75 ,
241.875, 241.875, 241.875, 241.875, 241.875, 241.875,
241.875, 241.875, 241.875, 241.875, 241.875, 241.875,
241.875, 241.875, 241.875, 241.875, 241.875, 241.875,
241.875, 241.875, 241.875, 243. , 243. , 243. ,
243. , 243. , 243. , 243. , 243. , 243. ,
243. , 243. , 243. , 243. , 243. , 243. ,
243. , 243. , 243. , 243. , 243. , 243. ,
244.125, 244.125, 244.125, 244.125, 244.125, 244.125,
244.125, 244.125, 244.125, 244.125, 244.125, 244.125,
244.125, 244.125, 244.125, 244.125, 244.125, 244.125,
244.125, 244.125, 244.125, 245.25 , 245.25 , 245.25 ,
245.25 , 245.25 , 245.25 , 245.25 , 245.25 , 245.25 ,
245.25 , 245.25 , 245.25 , 245.25 , 245.25 , 245.25 ,
245.25 , 245.25 , 245.25 , 245.25 , 245.25 , 245.25 ,
246.375, 246.375, 246.375, 246.375, 246.375, 246.375,
246.375, 246.375, 246.375, 246.375, 246.375, 246.375,
246.375, 246.375, 246.375, 246.375, 246.375, 246.375,
246.375, 246.375, 246.375, 247.5 , 247.5 , 247.5 ,
247.5 , 247.5 , 247.5 , 247.5 , 247.5 , 247.5 ,
247.5 , 247.5 , 247.5 , 247.5 , 247.5 , 247.5 ,
247.5 , 247.5 , 247.5 , 247.5 , 247.5 , 247.5 ,
248.625, 248.625, 248.625, 248.625, 248.625, 248.625,
248.625, 248.625, 248.625, 248.625, 248.625, 248.625,
248.625, 248.625, 248.625, 248.625, 248.625, 248.625,
248.625, 248.625, 248.625, 249.75 , 249.75 , 249.75 ,
249.75 , 249.75 , 249.75 , 249.75 , 249.75 , 249.75 ,
249.75 , 249.75 , 249.75 , 249.75 , 249.75 , 249.75 ,
249.75 , 249.75 , 249.75 , 249.75 , 249.75 , 249.75 ,
250.875, 250.875, 250.875, 250.875, 250.875, 250.875,
250.875, 250.875, 250.875, 250.875, 250.875, 250.875,
250.875, 250.875, 250.875, 250.875, 250.875, 250.875,
250.875, 250.875, 250.875])
lon_new = array([ 229.078125, 229.78125 , 230.484375, 231.1875 , 231.890625,
232.59375 , 233.296875, 234. , 234.703125, 235.40625 ,
236.109375, 236.8125 , 237.515625, 238.21875 , 238.921875,
239.625 , 240.328125, 241.03125 , 241.734375, 242.4375 ,
243.140625, 243.84375 , 244.546875, 245.25 , 245.953125,
246.65625 , 247.359375, 248.0625 , 248.765625, 249.46875 ,
250.171875])
lat_new = array([ 18.95804884, 18.25492384, 17.55179884, 16.84867384,
16.14554884, 15.44242384, 14.73929884, 14.03617384,
13.33304884, 12.62992384, 11.92679884, 11.22367384,
10.52054884, 9.81742384, 9.11429884, 8.41117384,
7.70804884, 7.00492384, 6.30179884, 5.59867384,
4.89554884, 4.19242384, 3.48929884, 2.78617384,
2.08304884, 1.37992384, 0.67679884, -0.02632616,
-0.72945116, -1.43257616, -2.13570116])
dlon_new = dx = array([-0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7,
-0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7,
-0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7])
dlat_new = dy = array([ 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7])
epsy = 1.0000000000000001e-15
epsx = 1.0000000000000001e-15
ivals = array([[ 1.51914963e-03, 4.84249834e-03, 1.24178734e-02,
1.78842712e-02, 2.73387861e-02, 3.49708572e-02,
3.76453847e-02, 3.83761562e-02, 3.42653096e-02,
2.37101801e-02, 1.05387643e-02, 6.25021639e-04,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 2.35232967e-03, 6.95531536e-03, 1.20530156e-02,
1.50254052e-02, 2.06609517e-02, 2.70908102e-02,
2.68270355e-02, 1.82730909e-02, 1.43693918e-02,
1.78140309e-02, 1.54578537e-02, 4.77255462e-03,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 5.49260434e-03, 1.21264756e-02, 1.16909835e-02,
1.09791821e-02, 1.34972855e-02, 1.25683891e-02,
7.35369883e-03, 5.41831227e-03, 4.72079264e-05,
6.89811632e-03, 7.71775097e-03, 2.97224917e-03,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 1.13926865e-02, 1.21114589e-02, 8.51153489e-03,
5.64892637e-03, 4.42338269e-03, 2.71651126e-03,
6.50693983e-05, 1.18285546e-03, 1.15790730e-03,
1.27750791e-05, 1.16404856e-03, 3.87609383e-04,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 9.99477133e-03, 7.84504320e-03, 4.12580743e-03,
1.95651152e-03, 6.27938076e-04, 3.64340417e-06,
0.00000000e+00, 5.80144624e-05, 9.30973620e-05,
6.09520539e-05, 3.19228930e-05, 2.95944778e-06,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 5.62612992e-03, 3.11897229e-03, 1.35576469e-03,
2.72712990e-04, 2.18278728e-08, 2.77736224e-04,
2.15023640e-04, 2.99098410e-05, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
5.45696821e-09, 6.18456397e-08, 1.00044417e-07],
[ 1.80969934e-03, 7.60903757e-04, 3.29161890e-06,
5.94062985e-05, 9.03553300e-05, 1.88442812e-06,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 8.96955896e-07,
5.46621823e-06, 6.86217982e-06, 9.91616434e-06],
[ 5.55361272e-04, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 7.27595761e-09,
1.27329258e-08, 8.64968388e-06, 3.59374013e-07,
9.28682766e-06, 9.36674860e-06, 5.86172609e-06,
3.51247800e-05, 1.05878571e-04, 2.21810909e-03],
[ 4.81493998e-07, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 3.76954704e-05,
3.13774217e-06, 4.10084112e-06, 1.22585889e-05,
1.23064645e-04, 3.22126038e-02, 4.12977114e-03,
4.40907385e-03, 8.58011283e-03, 1.13403024e-02,
1.39989899e-02, 1.55630931e-02, 1.62743106e-02],
[ 3.06865149e-06, 1.18992730e-05, 2.90403641e-05,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 3.26428679e-04,
5.05644502e-03, 7.92237557e-03, 8.84909835e-03,
9.39421635e-03, 4.13218886e-02, 5.75748496e-02,
1.31889293e-02, 1.34845898e-01, 1.13798976e-01,
1.20008864e-01, 1.56037509e-01, 1.93280712e-01],
[ 5.33699116e-04, 1.72329973e-03, 3.17315105e-03,
1.14819378e-01, 4.43908386e-02, 0.00000000e+00,
0.00000000e+00, 5.74506557e-05, 5.10447251e-04,
1.71848107e-03, 5.27862227e-03, 1.52162453e-02,
8.03043172e-02, 7.01455697e-02, 1.05249695e-01,
1.42122656e-01, 2.22821265e-01, 2.02459455e-01,
2.06677437e-01, 2.46986017e-01, 2.63066918e-01],
[ 7.62831494e-02, 1.11132614e-01, 1.37192637e-01,
1.43570632e-01, 1.15425527e-01, 0.00000000e+00,
2.89876079e-05, 3.49933194e-04, 9.58649849e-04,
2.01611011e-03, 4.83151386e-03, 1.83595419e-02,
1.03671178e-01, 9.63126644e-02, 5.50910681e-02,
1.36725232e-01, 1.64533973e-01, 7.98287913e-02,
1.73291177e-01, 1.81056723e-01, 2.02676117e-01],
[ 1.07610516e-01, 1.21951140e-01, 1.01695523e-01,
4.15301125e-04, 0.00000000e+00, 0.00000000e+00,
2.18786477e-06, 3.11349390e-06, 1.33068315e-04,
3.67084111e-04, 1.08024117e-03, 3.34545830e-03,
8.69611651e-03, 1.37638608e-02, 2.27879807e-02,
4.41205539e-02, 5.16842529e-02, 3.70345488e-02,
5.38833812e-02, 6.32722452e-02, 1.56152964e-01],
[ 1.10440794e-02, 3.89250601e-03, 2.37991480e-05,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
1.04574056e-07, 8.74274861e-07, 2.26301170e-04,
8.31953774e-04, 1.92522176e-03, 4.67427028e-03,
1.10447202e-02, 1.51307033e-02, 1.29928729e-02,
2.08757464e-02, 2.11046692e-02, 3.58685926e-02],
[ 1.40534030e-04, 6.79020388e-07, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 6.55058902e-05, 2.59673747e-04,
7.57753383e-04, 1.35594222e-03, 1.73954351e-03,
4.76868916e-03, 5.21047926e-03, 9.71581228e-03],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 3.23413442e-05, 3.17198865e-05,
3.07607057e-04, 2.70675024e-04, 1.48168497e-03],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 6.51265509e-05],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00]], dtype=float32)
This is the part of the mlab code that flags the error:
dx.max()-dx.min() = 1.7763568394002505e-15
dy.max()-dy.min() = 0.0
epsy = np.finfo(yi.dtype).resolution
if dx.max()-dx.min() > epsx or dy.max()-dy.min() > epsy:
raise ValueError("output grid must have constant spacing"
" when using interp='linear'")
I would love to know how to get around this problem. I don't own this python installation so I cannot modify the if statement. Sometimes this works and sometimes it doesn't, it seems to depend on the data input but in this case when it does break, the dy and dy are all the same. Is this a bug in mlab? If I change to 'nn' instead of linear, the problem goes away but I need the 'linear' interpolation.
Thanks, /Shejo284
回答1:
I've had no luck with mlab. Switched to scipy.interpolate.griddata instead. It seems to work and the results look good.
nvals = scipy.interpolate.griddata((lon_old.ravel(),
lat_old.ravel()),
tmp.ravel(),
(lon_new,lat_new),
method='linear')
Thanks for your contributions.
回答2:
Strangely, on my machine copying and pasting the input arrays from your output works perfectly. This suggests that the following will fix your problems:
lat_new = numpy.round(lat_new, 10)
lon_new = numpy.round(lon_new, 10)
It also suggests that you may be able to change the code that created them in the first place.
来源:https://stackoverflow.com/questions/12338649/mlab-griddata-bug