Related
I have 3 lists of equal length of x, y and z coordinates.
With them, I need to triangulate a surface, and retrieve values that lie in a line over that surface. In other words, I need the values that lie on that surface that intersect a given plane.
Problem is, I have no idea where to start.
I have tried scipy interp2d, but it seems I need more z values them what I actually have (like shown in this answer: Python interpolation and extracting value of z for x and y?.
# this is the data I have
x = [0.0, 17.67599999997765, 49.08499999996275, 90.57299999985844, 136.60500000044703]
y = [0.0, 45.22349889159747, 66.50303846438841, 114.04427618243405, 187.7707039612985]
z = [0.0, 1.8700000000000045, 1.9539999999999509, 1.3929999999999154, 1.6299999999999955]
I need a final grid with x y z values that look something like this:
I don't really need too much resolution
My desired final result is to be able to retrieve specific values on top of that surface
Like the point line in this image:
I have also tried looking at geospatial libraries, but I couldn't find a solution either.
Maybe it's possible to interpolate the z values that I need? But I'm not really sure how to do this. I have never used scipy library before, and I'm still struggling to understand it.
I'm using python 3.9
You barely have any data, so if you don't choose your intersecting plane carefully, you'll get no results back (or nonsense back). This includes the case of x=y; you can't do that at all - so the graph you've shown is entirely inapplicable to your data.
import numpy as np
import scipy.interpolate
x = [0.0, 17.6759999999776500, 49.0849999999627500, 90.5729999998584400, 136.6050000004470300]
y = [0.0, 45.2234988915974700, 66.5030384643884100, 114.0442761824340500, 187.7707039612985000]
z = [0.0, 1.8700000000000045, 1.9539999999999509, 1.3929999999999154, 1.6299999999999955]
xyi = np.empty((200, 2))
xyi[:, 0] = np.arange(200)
xyi[:, 1] = xyi[:, 0] * 1.374
zi = scipy.interpolate.griddata(
points=(x, y), values=z,
xi=xyi,
method='cubic',
)
good_vals = ~np.isnan(zi)
xyz = np.empty((np.count_nonzero(good_vals), 3))
xyz[:, :2] = xyi[good_vals, :]
xyz[:, 2] = zi[good_vals]
print(xyz)
[[0.00000000e+00 0.00000000e+00 0.00000000e+00]
[1.00000000e+00 1.37400000e+00 4.68988354e-02]
[2.00000000e+00 2.74800000e+00 9.44855957e-02]
[3.00000000e+00 4.12200000e+00 1.42698116e-01]
[4.00000000e+00 5.49600000e+00 1.91474231e-01]
[5.00000000e+00 6.87000000e+00 2.40751776e-01]
[6.00000000e+00 8.24400000e+00 2.90468585e-01]
[7.00000000e+00 9.61800000e+00 3.40562494e-01]
[8.00000000e+00 1.09920000e+01 3.90971337e-01]
[9.00000000e+00 1.23660000e+01 4.41632950e-01]
[1.00000000e+01 1.37400000e+01 4.92485168e-01]
[1.10000000e+01 1.51140000e+01 5.43465824e-01]
[1.20000000e+01 1.64880000e+01 5.94512755e-01]
[1.30000000e+01 1.78620000e+01 6.45563795e-01]
[1.40000000e+01 1.92360000e+01 6.96556779e-01]
[1.50000000e+01 2.06100000e+01 7.47429542e-01]
[1.60000000e+01 2.19840000e+01 7.98119919e-01]
[1.70000000e+01 2.33580000e+01 8.48565744e-01]
[1.80000000e+01 2.47320000e+01 8.98704854e-01]
[1.90000000e+01 2.61060000e+01 9.48475082e-01]
[2.00000000e+01 2.74800000e+01 9.97814263e-01]
[2.10000000e+01 2.88540000e+01 1.04666023e+00]
[2.20000000e+01 3.02280000e+01 1.09495083e+00]
[2.30000000e+01 3.16020000e+01 1.14262388e+00]
[2.40000000e+01 3.29760000e+01 1.18961722e+00]
[2.50000000e+01 3.43500000e+01 1.23586870e+00]
[2.60000000e+01 3.57240000e+01 1.28131613e+00]
[2.70000000e+01 3.70980000e+01 1.32589737e+00]
[2.80000000e+01 3.84720000e+01 1.36955024e+00]
[2.90000000e+01 3.98460000e+01 1.41221257e+00]
[3.00000000e+01 4.12200000e+01 1.45382221e+00]
[3.10000000e+01 4.25940000e+01 1.49431699e+00]
[3.20000000e+01 4.39680000e+01 1.53363474e+00]
[3.30000000e+01 4.53420000e+01 1.57171329e+00]
[3.40000000e+01 4.67160000e+01 1.60849049e+00]
[3.50000000e+01 4.80900000e+01 1.64390417e+00]
[3.60000000e+01 4.94640000e+01 1.67789216e+00]
[3.70000000e+01 5.08380000e+01 1.71039230e+00]
[3.80000000e+01 5.22120000e+01 1.74134241e+00]
[3.90000000e+01 5.35860000e+01 1.77068035e+00]
[4.00000000e+01 5.49600000e+01 1.79834394e+00]
[4.10000000e+01 5.63340000e+01 1.82427101e+00]
[4.20000000e+01 5.77080000e+01 1.84839941e+00]
[4.30000000e+01 5.90820000e+01 1.87066696e+00]
[4.40000000e+01 6.04560000e+01 1.89101151e+00]
[4.50000000e+01 6.18300000e+01 1.90937088e+00]
[4.60000000e+01 6.32040000e+01 1.92570604e+00]
[4.70000000e+01 6.45780000e+01 1.94056076e+00]
[4.80000000e+01 6.59520000e+01 1.95421968e+00]
[4.90000000e+01 6.73260000e+01 1.96719695e+00]
[5.00000000e+01 6.87000000e+01 1.97928362e+00]
[5.10000000e+01 7.00740000e+01 1.98942207e+00]
[5.20000000e+01 7.14480000e+01 1.99700320e+00]
[5.30000000e+01 7.28220000e+01 2.00180807e+00]
[5.40000000e+01 7.41960000e+01 2.00361776e+00]
[5.50000000e+01 7.55700000e+01 2.00221333e+00]
[5.60000000e+01 7.69440000e+01 1.99737586e+00]
[5.70000000e+01 7.83180000e+01 1.98888640e+00]
[5.80000000e+01 7.96920000e+01 1.97652604e+00]
[5.90000000e+01 8.10660000e+01 1.96007583e+00]
[6.00000000e+01 8.24400000e+01 1.93931685e+00]
[6.10000000e+01 8.38140000e+01 1.91403017e+00]
[6.20000000e+01 8.51880000e+01 1.88497097e+00]
[6.30000000e+01 8.65620000e+01 1.85740456e+00]
[6.40000000e+01 8.79360000e+01 1.83466390e+00]
[6.50000000e+01 8.93100000e+01 1.81970145e+00]
[6.60000000e+01 9.06840000e+01 1.81546971e+00]
[6.70000000e+01 9.20580000e+01 1.82177337e+00]
[6.80000000e+01 9.34320000e+01 1.82842946e+00]
[6.90000000e+01 9.48060000e+01 1.83439551e+00]
[7.00000000e+01 9.61800000e+01 1.83969621e+00]
[7.10000000e+01 9.75540000e+01 1.84435625e+00]
[7.20000000e+01 9.89280000e+01 1.84840034e+00]
[7.30000000e+01 1.00302000e+02 1.85185316e+00]
[7.40000000e+01 1.01676000e+02 1.85473940e+00]
[7.50000000e+01 1.03050000e+02 1.85708377e+00]
[7.60000000e+01 1.04424000e+02 1.85891096e+00]
[7.70000000e+01 1.05798000e+02 1.86024566e+00]
[7.80000000e+01 1.07172000e+02 1.86111256e+00]
[7.90000000e+01 1.08546000e+02 1.86153636e+00]
[8.00000000e+01 1.09920000e+02 1.86154176e+00]
[8.10000000e+01 1.11294000e+02 1.86115344e+00]
[8.20000000e+01 1.12668000e+02 1.86039610e+00]
[8.30000000e+01 1.14042000e+02 1.85929444e+00]
[8.40000000e+01 1.15416000e+02 1.85787402e+00]
[8.50000000e+01 1.16790000e+02 1.85624017e+00]
[8.60000000e+01 1.18164000e+02 1.85445481e+00]
[8.70000000e+01 1.19538000e+02 1.85252055e+00]
[8.80000000e+01 1.20912000e+02 1.85043999e+00]
[8.90000000e+01 1.22286000e+02 1.84821574e+00]
[9.00000000e+01 1.23660000e+02 1.84585039e+00]
[9.10000000e+01 1.25034000e+02 1.84334656e+00]
[9.20000000e+01 1.26408000e+02 1.84070685e+00]
[9.30000000e+01 1.27782000e+02 1.83793385e+00]
[9.40000000e+01 1.29156000e+02 1.83503019e+00]
[9.50000000e+01 1.30530000e+02 1.83199845e+00]
[9.60000000e+01 1.31904000e+02 1.82884125e+00]
[9.70000000e+01 1.33278000e+02 1.82556119e+00]
[9.80000000e+01 1.34652000e+02 1.82216087e+00]
[9.90000000e+01 1.36026000e+02 1.81864290e+00]
[1.00000000e+02 1.37400000e+02 1.81500988e+00]
[1.01000000e+02 1.38774000e+02 1.81126441e+00]
[1.02000000e+02 1.40148000e+02 1.80740911e+00]
[1.03000000e+02 1.41522000e+02 1.80344657e+00]
[1.04000000e+02 1.42896000e+02 1.79937940e+00]
[1.05000000e+02 1.44270000e+02 1.79521020e+00]
[1.06000000e+02 1.45644000e+02 1.79094157e+00]
[1.07000000e+02 1.47018000e+02 1.78657613e+00]
[1.08000000e+02 1.48392000e+02 1.78211648e+00]
[1.09000000e+02 1.49766000e+02 1.77756521e+00]
[1.10000000e+02 1.51140000e+02 1.77292494e+00]
[1.11000000e+02 1.52514000e+02 1.76819827e+00]
[1.12000000e+02 1.53888000e+02 1.76338780e+00]
[1.13000000e+02 1.55262000e+02 1.75849613e+00]
[1.14000000e+02 1.56636000e+02 1.75352588e+00]
[1.15000000e+02 1.58010000e+02 1.74847964e+00]
[1.16000000e+02 1.59384000e+02 1.74336002e+00]
[1.17000000e+02 1.60758000e+02 1.73816962e+00]
[1.18000000e+02 1.62132000e+02 1.73291105e+00]
[1.19000000e+02 1.63506000e+02 1.72758692e+00]
[1.20000000e+02 1.64880000e+02 1.72219982e+00]
[1.21000000e+02 1.66254000e+02 1.71675236e+00]
[1.22000000e+02 1.67628000e+02 1.71124714e+00]
[1.23000000e+02 1.69002000e+02 1.70568677e+00]
[1.24000000e+02 1.70376000e+02 1.70007386e+00]
[1.25000000e+02 1.71750000e+02 1.69441100e+00]
[1.26000000e+02 1.73124000e+02 1.68870081e+00]
[1.27000000e+02 1.74498000e+02 1.68294588e+00]
[1.28000000e+02 1.75872000e+02 1.67714882e+00]
[1.29000000e+02 1.77246000e+02 1.67131224e+00]
[1.30000000e+02 1.78620000e+02 1.66543873e+00]
[1.31000000e+02 1.79994000e+02 1.65953091e+00]
[1.32000000e+02 1.81368000e+02 1.65359138e+00]
[1.33000000e+02 1.82742000e+02 1.64762273e+00]
[1.34000000e+02 1.84116000e+02 1.64162758e+00]
[1.35000000e+02 1.85490000e+02 1.63560853e+00]
[1.36000000e+02 1.86864000e+02 1.62956819e+00]]
Is there any way to detect the highest peaks using a python library without setting any parameter?. I'm developing a user interface and I want the algorithm to be able to detect highest peaks automatically...
I want it to be able to detect these peaks in picture below:
graph here
Data looks like this:
8.60291e-07
-1.5491e-06
5.64568e-07
-9.51195e-07
1.07203e-06
4.6521e-07
6.43967e-07
-9.86092e-07
-9.82323e-07
6.38977e-07
-1.93884e-06
-2.98309e-08
1.33543e-06
1.05064e-06
1.17332e-06
-1.53549e-07
-8.9357e-07
1.59176e-06
-2.17331e-06
1.46756e-06
5.63301e-07
-8.77556e-07
7.47681e-09
-8.30101e-07
-3.6647e-07
5.27046e-07
-1.94983e-06
1.89018e-07
1.22533e-06
8.00735e-07
-8.51166e-07
1.13437e-06
-2.75787e-07
1.79601e-06
-1.67875e-06
1.13529e-06
-1.29865e-06
9.9688e-07
-9.34486e-07
8.89931e-07
-3.88634e-07
1.15124e-06
-4.23569e-07
-1.8029e-07
1.20537e-07
4.10736e-07
-9.99077e-07
-3.62984e-07
2.97916e-06
-1.95828e-06
-1.07398e-06
2.422e-06
-6.33202e-07
-1.36953e-06
1.6694e-06
-4.71764e-07
3.98849e-07
-1.0071e-06
-9.72984e-07
8.13553e-07
2.64193e-06
-3.12365e-06
1.34049e-06
-1.30419e-06
1.48369e-07
1.26033e-06
-2.59872e-07
4.28284e-07
-6.44356e-07
2.99934e-07
8.34335e-07
3.53226e-07
-7.08252e-07
4.1243e-07
2.41525e-06
-8.92159e-07
8.82339e-08
4.31945e-06
3.75152e-06
1.091e-06
3.8204e-06
-1.21356e-06
3.35564e-06
-1.06234e-06
-5.99808e-07
2.18155e-06
5.90652e-07
-1.36728e-06
-4.97017e-07
-7.77283e-08
8.68263e-07
4.37645e-07
-1.26514e-06
2.26413e-06
-8.52966e-07
-7.35596e-07
4.11911e-07
1.7585e-06
-inf
1.10779e-08
-1.49507e-06
9.87305e-07
-3.85296e-06
4.31265e-06
-9.89227e-07
-1.33537e-06
4.1713e-07
1.89362e-07
3.21968e-07
6.80237e-08
2.31636e-07
-2.98523e-07
7.99133e-07
7.36305e-07
6.39862e-07
-1.11932e-06
-1.57262e-06
1.86305e-06
-3.63716e-07
3.83865e-07
-5.23293e-07
1.31812e-06
-1.23608e-06
2.54684e-06
-3.99796e-06
2.90441e-06
-5.20203e-07
1.36295e-06
-1.89317e-06
1.22366e-06
-1.10373e-06
2.71276e-06
9.48181e-07
7.70881e-06
5.17066e-06
6.21254e-06
1.3513e-05
1.47878e-05
8.78543e-06
1.61819e-05
1.68438e-05
1.16082e-05
5.74059e-06
4.92458e-06
1.11884e-06
-1.07419e-06
-1.28517e-06
-2.70949e-06
1.65662e-06
1.42964e-06
3.40604e-06
-5.82825e-07
1.98288e-06
1.42819e-06
1.65517e-06
4.42749e-07
-1.95609e-06
-2.1756e-07
1.69164e-06
8.7204e-08
-5.35324e-07
7.43546e-07
-1.08687e-06
2.07289e-06
2.18529e-06
-2.8161e-06
1.88821e-06
4.07272e-07
1.063e-06
8.47244e-07
1.53879e-06
-9.0799e-07
-1.26709e-07
2.40044e-06
-9.48166e-07
1.41788e-06
3.67615e-07
-1.29199e-06
3.868e-06
9.54654e-06
2.51951e-05
2.2769e-05
7.21716e-06
1.36545e-06
-1.32681e-06
-3.09641e-06
4.90417e-07
2.99335e-06
1.578e-06
6.0025e-07
2.90656e-06
-2.08258e-06
-1.54214e-06
2.19757e-07
3.74982e-06
-1.76944e-06
2.15018e-06
-1.01935e-06
4.37469e-07
1.39078e-06
6.39587e-07
-1.7807e-06
-6.16455e-09
1.61557e-06
1.59644e-06
-2.35217e-06
5.29449e-07
1.9169e-06
-7.54822e-07
2.00342e-06
-3.28452e-06
3.91663e-06
1.66016e-08
-2.65897e-06
-1.4064e-06
4.67987e-07
1.67786e-06
4.69543e-07
-8.90106e-07
-1.4584e-06
1.37915e-06
1.98483e-06
-2.3735e-06
4.45618e-07
1.91504e-06
1.09653e-06
-8.00873e-07
1.32321e-06
2.04846e-06
-1.50656e-06
7.23816e-07
2.06049e-06
-2.43918e-06
1.64417e-06
2.65411e-07
-2.66107e-06
-8.01788e-07
2.05121e-06
-1.74988e-06
1.83594e-06
-8.14026e-07
-2.69342e-06
1.81152e-06
1.11664e-07
-4.21863e-06
-7.20551e-06
-5.92407e-07
-1.44629e-06
-2.08136e-06
2.86105e-06
3.77911e-06
-1.91898e-06
1.41742e-06
2.67914e-07
-8.55835e-07
-9.8584e-07
-2.74115e-06
3.39044e-06
1.39639e-06
-2.4964e-06
8.2486e-07
2.02432e-06
1.65793e-06
-1.43094e-06
-3.36807e-06
-8.96515e-07
5.31323e-06
-8.27209e-07
-1.39221e-06
-3.3754e-06
2.12372e-06
3.08218e-06
-1.42947e-06
-2.36777e-06
3.86218e-06
2.29327e-06
-3.3941e-06
-1.67291e-06
2.63828e-06
2.21008e-07
7.07794e-07
1.8172e-06
-2.00082e-06
1.80664e-06
6.69739e-07
-3.95395e-06
1.92148e-06
-1.07187e-06
-4.04938e-07
-1.76553e-06
2.7099e-06
1.30768e-06
1.41812e-06
-1.55518e-07
-3.78302e-06
4.00137e-06
-8.38623e-07
4.54651e-07
1.00027e-06
1.32196e-06
-2.62717e-06
1.67865e-06
-6.99249e-07
2.8837e-06
-1.00516e-06
-3.68011e-06
1.61847e-06
1.90887e-06
1.59641e-06
4.16779e-07
-1.35245e-06
1.65717e-06
-2.92667e-06
3.6203e-07
2.53528e-06
-2.0578e-07
-3.41919e-07
-1.42154e-06
-2.33322e-06
3.07175e-06
-2.69165e-08
-8.21045e-07
2.3175e-06
-7.22992e-07
1.49069e-06
8.75488e-07
-2.02676e-06
-2.81158e-07
3.6004e-06
-3.94708e-06
4.72983e-06
-1.38873e-06
-6.92139e-08
-1.4678e-06
1.04251e-06
-2.06625e-06
3.10406e-06
-8.13873e-07
7.23694e-07
-9.78912e-07
-8.65967e-07
7.37335e-07
1.52563e-06
-2.33591e-06
1.78265e-06
9.58435e-07
-5.22064e-07
-2.29736e-07
-4.26996e-06
-6.61411e-06
1.14789e-06
-4.32697e-06
-5.32779e-06
2.12241e-06
-1.40726e-06
1.76086e-07
-3.77194e-06
-2.71326e-06
-9.49402e-08
1.70807e-07
-2.495e-06
4.22324e-06
-3.62476e-06
-9.56055e-07
7.16583e-07
3.01447e-06
-1.41229e-06
-1.67694e-06
7.61627e-07
3.55881e-06
2.31015e-06
-9.50378e-07
4.45251e-08
-1.94791e-06
2.27081e-06
-3.34717e-06
3.05688e-06
4.57062e-07
3.87326e-06
-2.39215e-06
-3.52682e-06
-2.05212e-06
5.26495e-06
-3.28613e-07
-5.76569e-07
-7.46338e-07
5.98795e-06
8.80493e-07
-4.82965e-06
2.56839e-06
-1.58792e-06
-2.2294e-06
1.83841e-06
2.65482e-06
-3.10474e-06
-3.46741e-07
2.45557e-06
2.01328e-06
-3.92606e-06
inf
-8.11737e-07
5.72174e-07
1.57245e-06
8.02612e-09
-2.901e-06
1.22079e-06
-6.31714e-07
3.06241e-06
1.20059e-06
-1.80344e-06
4.90784e-07
3.74243e-06
-2.94342e-07
-3.45764e-08
-3.42099e-06
-1.43695e-06
5.91064e-07
3.47308e-06
3.78232e-06
4.01093e-07
-1.58435e-06
-3.47375e-06
1.34943e-06
1.11768e-06
1.95212e-06
-8.28033e-07
1.53705e-06
6.38031e-07
-1.84702e-06
1.34689e-06
-6.98669e-07
1.81653e-06
-2.42355e-06
-1.35257e-06
3.04367e-06
-1.21976e-06
1.61896e-06
-2.69528e-06
1.84601e-06
6.45447e-08
-4.94263e-07
3.47568e-06
-2.00531e-06
3.56693e-06
-3.19446e-06
2.72141e-06
-1.39059e-06
2.20032e-06
-1.76819e-06
2.32727e-07
-3.47382e-07
2.11823e-07
-5.22614e-07
2.69846e-06
-1.47983e-06
2.14554e-06
-6.27594e-07
-8.8501e-10
7.89124e-07
-2.8653e-07
8.30902e-07
-2.12857e-06
-1.90887e-07
1.07593e-06
1.40781e-06
2.41641e-06
-4.52689e-06
2.37207e-06
-2.19479e-06
1.65131e-06
1.2706e-06
-2.18387e-06
-1.72821e-07
5.41687e-07
7.2879e-07
7.56927e-07
1.57739e-06
-3.79395e-07
-1.02887e-06
-1.20987e-06
1.43066e-06
8.96301e-08
5.09766e-07
-2.8812e-06
-2.35944e-06
2.25912e-06
-2.78967e-06
-4.69913e-06
1.60822e-06
6.9342e-07
4.6225e-07
-1.33276e-06
-3.59033e-06
1.11206e-06
1.83521e-06
2.39163e-06
2.3468e-08
5.91431e-07
-8.80249e-07
-2.77405e-08
-1.13184e-06
-1.28036e-06
1.66229e-06
2.81784e-06
-2.97589e-06
8.73413e-08
1.06439e-06
2.39075e-06
-2.76974e-06
1.20862e-06
-5.12817e-07
-5.19104e-07
4.51324e-07
-4.7168e-07
2.35608e-06
5.46906e-07
-1.66748e-06
5.85236e-07
6.42944e-07
2.43164e-07
4.01031e-07
-1.93646e-06
2.07416e-06
-1.16116e-06
4.27155e-07
5.2951e-07
9.09149e-07
-8.71887e-08
-1.5564e-09
1.07266e-06
-9.49402e-08
2.04016e-06
-6.38123e-07
-1.94241e-06
-5.17294e-06
-2.18622e-06
-8.26703e-06
2.54364e-06
4.32614e-06
8.3847e-07
-2.85309e-06
2.72345e-06
-3.42752e-06
-1.36871e-07
2.23346e-06
5.26825e-07
1.3566e-06
-2.17111e-06
2.1463e-07
2.06479e-06
1.76929e-06
-1.2655e-06
-1.3797e-06
3.10706e-06
-4.72189e-06
4.38138e-06
6.41815e-07
-3.25623e-08
-4.93707e-06
5.05743e-06
5.17578e-07
-5.30524e-06
3.62463e-06
5.68909e-07
1.16226e-06
1.10843e-06
-5.00854e-07
9.48761e-07
-2.18701e-06
-3.57635e-07
4.26709e-06
-1.50836e-06
-5.84412e-06
3.5054e-06
3.94019e-06
-4.7623e-06
2.05856e-06
-2.22992e-07
1.64969e-06
2.64694e-06
-8.49487e-07
-3.63562e-06
1.0386e-06
1.69461e-06
-2.05798e-06
3.60349e-06
3.42651e-07
-1.46686e-06
1.19949e-06
-1.60519e-06
2.37793e-07
6.12366e-07
-1.54669e-06
1.43668e-06
1.87009e-06
-2.22626e-06
2.15155e-06
-3.10571e-06
2.05188e-06
-4.40002e-07
2.06683e-06
-1.11362e-06
5.96924e-07
-2.64471e-06
2.4892e-06
1.13083e-06
-3.23181e-07
5.10651e-07
2.73499e-07
-1.24899e-06
1.40564e-06
-9.3158e-07
1.45947e-06
3.70544e-07
-1.62628e-06
-1.70215e-06
1.72098e-06
8.19031e-07
-5.57709e-07
1.10107e-06
-2.81845e-06
1.57654e-07
3.30716e-06
-9.75403e-07
1.73126e-07
1.30447e-06
7.64771e-08
-6.65344e-07
-1.4346e-06
5.03171e-06
-2.84576e-06
2.3212e-06
-2.73373e-06
2.16675e-08
2.24026e-06
-4.11682e-08
-3.36642e-06
1.78775e-06
1.28174e-08
-9.32068e-07
2.97177e-06
-1.05338e-06
9.42505e-07
2.02362e-07
-1.81326e-06
2.16995e-06
2.83722e-07
-1.2648e-06
9.21814e-07
-8.9447e-07
-1.61597e-06
3.5036e-06
-6.79626e-08
1.52823e-06
-2.98682e-06
5.57404e-07
9.5166e-07
7.10419e-07
-1.28528e-06
-3.76038e-07
-1.03845e-06
2.96631e-06
-1.18356e-06
-2.77313e-07
3.24149e-06
-1.85455e-06
-1.27747e-07
3.6264e-07
4.66431e-07
-1.54443e-06
1.38437e-06
-1.53119e-06
7.4231e-07
-1.2388e-06
1.99774e-06
1.15799e-06
1.39478e-06
-2.93527e-06
-2.03012e-06
2.46667e-06
2.16751e-06
-2.50354e-06
3.95905e-07
5.74371e-07
1.33575e-07
-3.98315e-07
4.93927e-07
-5.23987e-07
-1.74713e-07
6.49384e-07
-7.16766e-07
2.35733e-06
-4.91333e-08
-1.88138e-06
1.74722e-06
4.03503e-07
3.5965e-07
1.44836e-07]
The task you are describing could be treated like anomaly/outlier detection.
One possible solution is to use a Z-score transformation and treat every value with a z score above a certain threshold as an outlier. Because there is no clear definition of an outlier it won't be able to detect such peaks without setting any parameters (threshold).
One possible solution could be:
import numpy as np
def detect_outliers(data):
outliers = []
d_mean = np.mean(data)
d_std = np.std(data)
threshold = 3 # this defines what you would consider a peak (outlier)
for point in data:
z_score = (point - d_mean)/d_std
if np.abs(z_score) > threshold:
outliers.append(point)
return outliers
# create normal data
data = np.random.normal(size=100)
# create outliers
outliers = np.random.normal(100, size=3)
# combine normal data and outliers
full_data = data.tolist() + outliers.tolist()
# print outliers
print(detect_outliers(full_data))
If you only want to detect peaks, remove the np.abs function call from the code.
This code snippet is based on a Medium Post, which also provides another way of detecting outliers.
I am trying to segment 3d tomographs of porous networks in python. I am able to calculate the distance map with ndimage.distance_transform_edt and the peaks with feature.peak_local_max. when I apply the watershed algorithm a get an acceptable result, but the markers of the peaks are not located at the visible peaks, see image, of the distance map
Thanks in advance
Here the code a is the image
D = ndimage.distance_transform_edt(a)
localMax = feature.peak_local_max(D, indices=False, min_distance=50,
labels=a)
localMax2 = feature.peak_local_max(D, indices=True, min_distance=50,
labels=a)
markers = ndimage.label(localMax, structure=np.ones((3,3,3)))[0]
labels = morphology.watershed(-D,markers,mask=a)
I found a way:
i had to exclude the borders and apply a threshold
D = ndimage.distance_transform_edt(a)
localMax = feature.peak_local_max(D, indices=False, min_distance=30,
labels=a,threshold_abs=9,exclude_border=1)
localMax2 = feature.peak_local_max(D, indices=True, min_distance=30,
labels=a,threshold_abs=9,exclude_border=1)
#markers = ndimage.label(localMax, structure=np.ones((3,3,3)))[0]
markers = ndimage.label(localMax, structure=np.ones((3,3,3)))[0]
labels = morphology.watershed(-D,markers,mask=a)
regions=measure.regionprops(labels,intensity_image=a)
I want to plot a simplified heatmap that is not so difficult to edit with the scalar vector graphics program I am using (inkscape). The original heatmap as produced below contains lots of rectangles, and I wonder if they could be merged together in the different sectors to simplify the output pdf file:
nentries=100000
ci=rainbow(nentries)
set.seed=1
mean=10
## Generate some data (4 factors)
i = data.frame(
a=round(abs(rnorm(nentries,mean-2))),
b=round(abs(rnorm(nentries,mean-1))),
c=round(abs(rnorm(nentries,mean+1))),
d=round(abs(rnorm(nentries,mean+2)))
)
minvalue = 10
# Discretise values to 1 or 0
m0 = matrix(as.numeric(i>minvalue),nrow=nrow(i))
# Remove rows with all zeros
m = m0[rowSums(m0)>0,]
# Reorder with 1,1,1,1 on top
ms =m[order(as.vector(m %*% matrix(2^((ncol(m)-1):0),ncol=1)), decreasing=TRUE),]
rowci = rainbow(nrow(ms))
colci = rainbow(ncol(ms))
colnames(ms)=LETTERS[1:4]
limits=c(which(!duplicated(ms)),nrow(ms))
l=length(limits)
toname=round((limits[-l]+ limits[-1])/2)
freq=(limits[-1]-limits[-l])/nrow(ms)
rn=rep("", nrow(ms))
for(i in toname) rn[i]=paste(colnames(ms)[which(ms[i,]==1)],collapse="")
rn[toname]=paste(rn[toname], ": ", sprintf( "%.5f", freq ), "%")
heatmap(ms,
Rowv=NA,
labRow=rn,
keep.dendro = FALSE,
col=c("black","red"),
RowSideColors=rowci,
ColSideColors=colci,
)
dev.copy2pdf(file="/tmp/file.pdf")
Why don't you try RSvgDevice? Using it you could save your image as svg file, which is much convenient to Inkscape than pdf
I use the Cairo package for producing svg. It's incredibly easy. Here is a much simpler plot than the one you have in your example:
require(Cairo)
CairoSVG(file = "tmp.svg", width = 6, height = 6)
plot(1:10)
dev.off()
Upon opening in Inkscape, you can ungroup the elements and edit as you like.
Example (point moved, swirl added):
I don't think we (the internet) are being clear enough on this one.
Let me just start off with a successful export example
png("heatmap.png") #Ruby dev's think of this as kind of like opening a `File.open("asdfsd") do |f|` block
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=terrain.colors(256), scale="column", margins=c(5,10))
dev.off()
The dev.off() bit, in my mind, reminds me of an end call to a ruby block or method, in that, the last line of the "nested" or enclosed (between png() and dev.off()) code's output is what gets dumped into the png file.
For example, if you ran this code:
png("heatmap4.png")
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=terrain.colors(32), scale="column", margins=c(5,15))
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=greenred(32), scale="column", margins=c(5,15))
dev.off()
it would output the 2nd (greenred color scheme, I just tested it) heatmap to the heatmap4.png file, just like how a ruby method returns its last line by default
I need to plot a 3D bar graph in matlab or excel. I am going to use some dates in x-axis, time in y-axis and some amount on the z-axis. Each record in csv file looks like ...
18-Apr, 21, 139.45
I am not sure how to do this right. can anyone help me please. I tried using pivort chart of excel. however, i could not manipulate the axis and use appropriate space between each tick.
thanks
kaisar
Since the question is lacking details, let me illustrate with an example.
Consider the following code:
%# read file contents: date,time,value
fid = fopen('data.csv','rt');
C = textscan(fid, '%s %s %f', 'Delimiter',',');
fclose(fid);
%# correctly reshape the data, and extract x/y labels
num = 5;
d = reshape(C{1},num,[]); d = d(1,:);
t = reshape(C{2},num,[]); t = t(:,1);
Z = reshape(C{3},num,[]);
%# plot 3D bars
bar3(Z)
xlabel('date'), ylabel('time'), zlabel('value')
set(gca, 'XTickLabel',d, 'YTickLabel',t)
I ran on the following data file:
data.csv
18-Apr,00:00,0.85535
18-Apr,03:00,0.38287
18-Apr,06:00,0.084649
18-Apr,09:00,0.73387
18-Apr,12:00,0.33199
19-Apr,00:00,0.83975
19-Apr,03:00,0.37172
19-Apr,06:00,0.82822
19-Apr,09:00,0.17652
19-Apr,12:00,0.12952
20-Apr,00:00,0.87988
20-Apr,03:00,0.044079
20-Apr,06:00,0.68672
20-Apr,09:00,0.73377
20-Apr,12:00,0.43717
21-Apr,00:00,0.37984
21-Apr,03:00,0.97966
21-Apr,06:00,0.39899
21-Apr,09:00,0.44019
21-Apr,12:00,0.15681
22-Apr,00:00,0.32603
22-Apr,03:00,0.31406
22-Apr,06:00,0.8945
22-Apr,09:00,0.24702
22-Apr,12:00,0.31068
23-Apr,00:00,0.40887
23-Apr,03:00,0.70801
23-Apr,06:00,0.14364
23-Apr,09:00,0.87132
23-Apr,12:00,0.083156
24-Apr,00:00,0.46174
24-Apr,03:00,0.030389
24-Apr,06:00,0.7532
24-Apr,09:00,0.70004
24-Apr,12:00,0.21451
25-Apr,00:00,0.6799
25-Apr,03:00,0.55729
25-Apr,06:00,0.85068
25-Apr,09:00,0.55857
25-Apr,12:00,0.90177
26-Apr,00:00,0.41952
26-Apr,03:00,0.35813
26-Apr,06:00,0.48899
26-Apr,09:00,0.25596
26-Apr,12:00,0.92917
27-Apr,00:00,0.46676
27-Apr,03:00,0.25401
27-Apr,06:00,0.43122
27-Apr,09:00,0.70253
27-Apr,12:00,0.40233
Use MATLAB's CSV reading functions (or write your own) and then use bar3 to display the data.