Related
when i try to run the code below i get this graph
my code:
from numpy import nan
import json
import os
import numpy as np
import subprocess
import math
import matplotlib.pyplot as plt
from statistics import mean, stdev
def smooth(t):
new_t = []
for i, x in enumerate(t):
neighbourhood = t[max(i-2,0): i+3]
m = mean(neighbourhood)
s = stdev(neighbourhood, xbar=m)
if abs(x - m) > s:
x = ( t[i - 1 + (i==0)*2] + t[i + 1 - (i+1==len(t))*2] ) / 2
new_t.append(x)
return new_t
def outLiersFN(*U):
outliers=[] # after preprocessing list
#preprocessing Fc =| 2*LF1 prev by 1 - LF2 prev by 2 |
c0 = -2 #(previous) by 2 #from original
c1 =-1 #(previous) #from original
c2 =0 #(current) #from original
c3 = 1 #(next) #from original
preP = U[0] # original list
if c2 == 0:
outliers.append(preP[0])
c1+=1
c2+=1
c0+=1
c3+=1
oldlen = len(preP)
M_RangeOfMotion = 90
while oldlen > c2 :
if c3 == oldlen:
outliers.insert(c2, preP[c2]) #preP[c2] >> last element in old list
break
if (preP[c2] > M_RangeOfMotion and preP[c2] < (preP[c1] + preP[c3])/2) or (preP[c2] < M_RangeOfMotion and preP[c2] > (preP[c1] + preP[c3])/2): #Check Paper 3.3.1
Equ = (preP[c1] + preP[c3])/2 #fn of preprocessing # From third index # ==== inserting current frame
formatted_float = "{:.2f}".format(Equ) #with .2 number only
equu = float(formatted_float) #from string float to float
outliers.insert(c2,equu) # insert the preprocessed value to the List
c1+=1
c2+=1
c0+=1
c3+=1
else :
Equ = preP[c2] # fn of preprocessing #put same element (do nothing)
formatted_float = "{:.2f}".format(Equ) # with .2 number only
equu = float(formatted_float) # from string float to float
outliers.insert(c2, equu) # insert the preprocessed value to the List
c1 += 1
c2 += 1
c0 += 1
c3 += 1
return outliers
def remove_nan(list):
newlist = [x for x in list if math.isnan(x) == False]
return newlist
the_angel = [176.04, 173.82, 170.09, 165.3, 171.8, 178.3, 178.77, 179.24, 179.93, 180.0, 173.39, 166.78, 166.03, 165.28, 165.72, 166.17, 166.71, 167.26, 168.04, 167.22, 166.68, 166.13, 161.53, 165.81, 170.1, 170.05, 170.5, 173.01, 176.02, 174.53, 160.09, 146.33, 146.38, 146.71, 150.33, 153.95, 154.32, 154.69, 134.52, 114.34, 115.6, 116.86, 134.99, 153.12, 152.28, 151.43, 151.36, 152.32, 158.9, 166.52, 177.74, 178.61, 179.47, 167.44, 155.4, 161.54, 167.68, 163.96, 160.24, 137.45, 114.66, 117.78, 120.89, 139.95, 139.62, 125.51, 111.79, 112.07, 112.74, 110.22, 107.7, 107.3, 106.52, 105.73, 103.07, 101.35, 102.5, 104.59, 104.6, 104.49, 104.38, 102.81, 101.25, 100.62, 100.25, 100.15, 100.32, 99.84, 99.36, 100.04, 100.31, 99.14, 98.3, 97.92, 97.41, 96.9, 96.39, 95.88, 95.9, 95.9, 96.02, 96.14, 96.39, 95.2, 94.56, 94.02, 93.88, 93.8, 93.77, 93.88, 94.04, 93.77, 93.65, 93.53, 94.2, 94.88, 92.59, 90.29, 27.01, 32.9, 38.78, 50.19, 61.59, 61.95, 62.31, 97.46, 97.38, 97.04, 96.46, 96.02, 96.1, 96.33, 95.61, 89.47, 89.34, 89.22, 89.48, 89.75, 90.02, 90.28, 88.16, 88.22, 88.29, 88.17, 88.17, 94.98, 94.84, 94.69, 94.94, 94.74, 94.54, 94.69, 94.71, 94.64, 94.58, 94.19, 94.52, 94.85, 87.7, 87.54, 87.38, 95.71, 96.57, 97.11, 97.05, 96.56, 96.07, 95.76, 95.56, 95.35, 95.28, 95.74, 96.2, 96.32, 96.33, 96.2, 96.14, 96.07, 96.07, 96.12, 96.17, 96.28, 96.31, 96.33, 96.16, 96.05, 95.94, 95.33, 88.96, 95.0, 95.78, 88.19, 88.19, 88.19, 87.92, 87.93, 88.03, 87.94, 87.86, 87.85, 87.89, 88.08, 88.01, 87.88, 88.02, 88.15, 88.15, 88.66, 88.73, 88.81, 88.41, 88.55, 88.68, 88.69, 88.02, 87.35, 95.19, 95.39, 95.38, 95.37, 95.27, 95.17, 95.33, 95.32, 95.31, 95.37, 95.42, 95.34, 95.44, 95.53, 95.47, 95.41, 95.13, 94.15, 94.78, 97.64, 97.1, 96.87, 97.03, 96.76, 35.44, 23.63, 23.27, 24.71, 26.16, 96.36, 113.13, 129.9, 96.82, 63.74, 34.25, 33.42, 32.6, 30.69, 31.06, 31.43, 97.14, 97.51, 97.23, 98.54, 100.13, 100.95, 28.82, 33.81, 66.81, 99.82, 102.63, 101.9, 101.44, 102.19, 103.22, 103.67, 104.13, 104.07, 104.73, 105.46, 103.74, 102.02, 103.32, 102.59, 29.54, 28.08, 28.76, 29.79, 30.82, 113.51, 129.34, 145.16, 143.18, 148.29, 153.67, 166.14, 161.16, 151.64, 149.27, 146.9, 151.67, 153.02, 149.28, 145.53, 149.1, 152.67, 158.78, 164.89, 164.84, 164.8, 162.11, 159.42, 156.73, 156.28, 155.83, 156.4, 161.0, 165.59, 164.44, 159.73, 155.76, 156.97, 158.92, 159.15, 159.39, 159.99, 160.44, 160.88, 163.89, 166.9, 167.71, 167.11, 167.0, 167.44, 168.38, 153.16, 137.94, 137.65, 152.09, 169.49, 171.36, 173.22, 174.01, 174.0, 174.2, 174.41, 157.74, 141.09, 149.32, 157.57, 156.4, 148.4, 140.78, 141.06, 141.73, 143.05, 143.91, 156.59, 169.29, 172.17, 175.05, 175.29, 175.27, 175.15, 175.02, 174.81, 174.59, 174.76, 174.94, 175.18, 175.41, 175.23, 174.51, 174.64, 174.77, 174.56, 173.25, 172.38, 174.17, 176.4, 177.27, 177.29, 177.33, 178.64, 179.98, 179.99, 176.0, 172.88, 173.77, 173.8, 173.97, 174.72, 175.24, 176.89, 179.07, 179.27, 178.78, 178.29, 175.61, 174.21, 172.8, 173.05, 173.41, 173.77, 174.65, 175.52, 175.58, 176.15, 176.71, 159.12, 141.54, 141.12, 155.62, 170.53, 165.54, 160.71, 158.22, 156.35, 156.82, 158.55, 160.27, 161.33, 162.39, 162.37, 159.48, 156.59, 156.77, 158.05, 159.32, 158.49, 157.66, 157.7, 157.74, 158.44, 159.14, 150.13, 143.06, 136.0, 125.7, 115.41, 111.19, 106.97, 107.1, 107.24, 107.45, 107.67, 113.34, 119.01, 144.87, 170.73, 174.31, 177.89, 174.78, 171.67, 163.26, 134.58, 105.9, 102.98, 100.77, 101.05, 101.39, 101.73, 99.79, 98.71, 97.64, 97.8, 97.89, 96.67, 95.45, 94.33, 93.38, 92.44, 48.53, 91.4, 91.35, 91.34, 91.33, 90.92, 90.51, 88.63, 87.0, 86.74, 86.48, 96.79, 96.09, 95.46, 95.39, 94.32, 93.25, 93.31, 93.37, 93.11, 92.57, 93.41, 94.25, 96.48, 92.71, 88.94, 90.07, 90.43, 78.06, 77.69, 77.32, 90.1, 89.15, 89.14, 88.85, 88.38, 87.63, 121.2, 120.66, 86.89, 86.42, 85.69, 84.86, 84.86, 85.34, 85.82, 86.07, 86.32, 85.82, 85.32, 86.23, 86.69, 87.15, 87.04, 86.87, 86.58, 86.0, 85.41, 85.41, 85.53, 85.66, 85.7, 85.72, 85.75, 85.92, 86.09, 85.77, 85.45, 84.94, 85.55, 86.16, 86.21, 86.1, 85.77, 85.27, 84.56, 84.99, 85.38, 85.42, 85.98, 86.54, 86.5, 86.45, 86.56, 86.63, 86.35, 86.08, 85.82, 85.51, 85.21, 84.6, 84.84, 84.97, 85.1, 86.12, 86.88, 86.8, 86.46, 86.47, 87.23, 87.8, 88.0, 88.08, 88.16, 87.72, 87.63, 87.37, 86.42, 86.48, 87.24, 87.97, 88.09, 88.19, 88.32, 88.44, 87.82, 87.2, 86.03, 85.78, 91.5, 93.0, 88.2, 88.52, 88.42, 87.28, 85.73, 85.62, 85.5, 85.5, 87.06, 87.6, 88.1, 88.31, 88.53, 88.77, 89.14, 89.52, 89.46, 89.4, 90.28, 89.74, 91.28, 92.17, 92.16, 92.15, 93.08, 94.0, 94.66, 95.32, 94.13, 93.7, 93.32, 93.69, 94.58, 95.47, 97.25, 99.03, 99.63, 99.67, 99.71, 100.33, 101.58, 103.36, 103.49, 103.41, 106.31, 109.34, 109.28, 109.21, 107.76, 106.31, 105.43, 104.94, 104.44, 111.19, 117.93, 115.59, 113.24, 116.15, 119.06, 125.43, 140.72, 156.0, 161.7, 143.52, 135.33, 127.13, 127.68, 148.68, 169.68, 172.2, 174.72, 174.75, 174.66, 158.57, 142.63, 145.13, 153.29, 161.45, 163.34, 165.24, 162.25, 159.89, 159.07, 156.39, 155.21, 156.04, 159.29, 160.07, 160.85, 163.45, 162.93, 161.71, 160.06, 158.4, 144.74, 132.64, 134.57, 150.22, 165.86, 172.95, 174.12, 175.3, 175.5, 176.31, 177.71, 179.72, 168.13, 156.55, 146.24, 155.75, 176.0, 175.99, 175.98, 176.0, 176.02, 176.25, 175.13, 174.26, 173.38, 173.37, 173.46, 176.34, 174.55, 172.77, 168.45, 166.35, 166.47, 168.81, 167.43, 166.79, 167.35, 168.65, 168.51, 168.37, 168.88, 169.74, 171.19, 171.33, 169.91, 168.49, 167.11, 166.83, 167.01, 168.68, 170.34, 170.43, 172.15, 173.86, 177.62, 177.61, 175.34, 173.06, 176.47, 179.87, 179.9, 177.67, 175.67, 175.39, 175.36, 177.03, 176.0, 174.98, 174.96, 174.94, 175.76, 176.57, 169.05, 162.99, 164.97, 168.74, 172.51, 167.38, 165.08, 163.03, 163.81, 164.83, 164.81, 164.8, 165.88, 165.36, 159.61, 153.86, 153.57, 153.61, 153.65, 154.62, 155.58, 157.97, 156.35, 155.66, 154.98, 156.11, 157.24, 159.25, 159.6, 160.43, 161.26, 164.71, 168.17, 147.46, 126.92, 106.38, 105.23, 104.4, 105.37, 106.65, 109.21, 107.44, 104.65, 101.86, 102.35, 102.84, 102.79, 102.19, 101.59, 100.98, 100.38, 98.72, 97.73, 97.32, 96.9, 95.11, 93.97, 94.12, 94.12, 93.1, 92.08, 89.29, 90.35, 90.35, 90.35, 90.35, 86.95, 86.37, 86.06, 85.74, 94.56, 93.16, 92.46, 91.76, 88.55, 85.33, 87.52, 92.18, 93.68, 95.18, 94.4, 92.17, 89.94, 89.4, 89.37, 99.44, 100.98, 102.52, 103.18, 88.96, 88.23, 87.5, 85.2, 85.19, 86.87, 121.42, 155.96, 155.97, 155.97, 86.2, 86.5, 86.8, 87.22, 87.36, 87.34, 87.03, 87.04, 87.05, 86.36, 85.68, 85.71, 85.84, 85.93, 86.01, 86.04, 86.08, 85.92, 86.05, 86.18, 86.17, 86.19, 86.23, 86.22, 86.09, 85.92, 85.66, 85.69, 85.69, 85.31, 84.91, 84.93, 84.95, 84.93, 84.91, 84.9, 84.9, 84.9, 84.9, 85.38, 85.52, 85.66, 85.66, 85.4, 85.14, 85.47, 85.8, 85.72, 85.64, 86.09, 85.84, 85.27, 85.47, 85.66, 85.59, 85.52, 85.38, 85.39, 85.28, 85.17, 85.39, 85.7, 85.98, 86.26, 86.61, 92.97, 93.15, 86.58, 86.58, 86.53, 86.47, 98.55, 99.41, 100.16, 100.9, 89.19, 90.28, 91.38, 91.39, 91.4, 91.44, 92.05, 131.05, 170.63, 170.13, 162.43, 125.64, 88.85, 88.85, 99.08, 100.38, 101.69, 100.74, 99.79, 96.33, 93.31, 93.73, 94.87, 96.01, 96.93, 97.85, 98.97, 97.85, 98.14, 99.37, 102.01, 103.8, 105.58, 108.52, 108.12, 107.72, 106.75, 106.82, 109.08, 112.37, 112.52, 112.66, 112.97, 114.12, 115.64, 117.1, 118.57, 126.13, 133.69, 149.27, 163.96, 166.62, 169.27, 164.94, 160.61, 149.35, 141.18, 143.41, 143.57, 149.26, 157.49, 159.94, 151.93, 147.47, 145.97, 145.56, 145.15, 143.85, 142.54, 142.18, 142.43, 143.12, 144.41, 144.38, 151.99, 159.59, 174.81, 174.94, 175.84, 176.87, 162.41, 152.94, 151.59, 155.24, 155.22, 155.19, 155.04]
p0 = outLiersFN(smooth(remove_nan(the_angel)))
the_angel = p0
plt.plot(the_angel) #list(filter(fun, L1))
plt.show()
print((the_angel))
how can i smooth the values in (the_angel) to get graph like this (red line)
i mean ignoring all unnecessary and noisy values and get only main line instead
you can edit my code or suggest me new filter or algorithm
pandas has a rolling() method for dataframes that you can use to calculate the mean over a window of values, e.g. the 70 closest ones:
import pandas as pd
import matplotlib.pyplot as plt
WINDOW_SIZE = 70
the_angel = [176.04, 173.82, 170.09, 165.3, 171.8, # ...
]
df = pd.DataFrame({'the angel': the_angel})
df[f'mean of {WINDOW_SIZE}'] = df['the angel'].rolling(
window=WINDOW_SIZE, center=True).mean()
df.plot(color=['blue', 'red']);
When trying to calculate a transformation matrix between two systems with the library transformations and the function superimposition_matrix, I get the following error :
File "D:\Travail\Dev\projet Jarvis\collisions\Test dans
Jarvis\JarvisRobotics_20180717_1937\JarvisRobotics\outils_matrices.py",
line 839, in set_frame_passageV000
M = transformations.superimposition_matrix(list_base, list_ext, scale=True, usesvd=True) ValueError: eigenvector_of_symmetric_44()
failed
The data in entry are two list of ten vector(x,y,z):
<class 'list'>: [[2443.9128, -501.7427, -630.8925], [2126.8356, -703.2691, -678.1219], [1534.3236, -757.3283, -678.0219], [1532.8918, -339.4951, -682.6528], [2103.9974, -226.6539, -472.8035], [2297.246, 47.3245, -475.6743], [2429.3814, 88.5478, -476.0224], [2353.675, 614.8282, -447.7145], [1931.7996, 651.5278, -448.4745], [1604.6555, 664.6893, -448.8943]]
<class 'list'>: [[406.93, -373.8, 2559.99], [612.81, -65.74, 2566.76], [679.68, 520.63, 2542.36], [271.24, 532.19, 2612.08], [114.43, -31.73, 2439.24], [-157.93, -220.7, 2490.9], [-200.13, -350.38, 2501.29], [-722.9, -260.64, 2556.52], [-750.43, 160.15, 2551.35], [-759.14, 488.8, 2545.55]]
is anybody here to help me or to guide me to go further?
def set_frame_passage_(list_pt_ref_base, list_pt_ref_ext):
str_erreur = ''
if len(list_pt_ref_base) == len(list_pt_ref_ext):
nb_pts = len(list_pt_ref_base)
array_base = np.zeros((nb_pts, 3))
array_ext = np.zeros((nb_pts, 3))
lg_array = 0
for index in range(0, nb_pts):
array_base[lg_array] = list_pt_ref_base[index][:3]
array_ext[lg_array] = list_pt_ref_ext[index][:3]
lg_array += 1
M = superimposition_matrix(array_base, array_ext, scale=True)
# valeurs de sortie
xyzrpw = set_mat4x4_2_xyzrpw(M)
mat_rdk = mat4x4_numpy_2_rdk(M)
if not (not np.all(M) and xyzrpw and mat_rdk):
return False
return RetVal([True, dt.now, 'matrice de passage calculée avec succès !', M, xyzrpw, mat_rdk])
else:
str_erreur = 'Les tailles du tableau du référentiel base('
str_erreur += str(len(list_pt_ref_base))
str_erreur += ') et du référentiel extérieur('
str_erreur += str(len(list_pt_ref_ext))
str_erreur += ') ne sont pas de la même taille !'
print(str_erreur)
RetVal([False, dt.now, str_erreur])
list_ext_brute = [[406.93, -373.8, 2559.99, 0.0, -0.0, 0.0],
[612.81, -65.74, 2566.76, 0.0, -0.0, 0.0],
[679.68, 520.63, 2542.36, 0.0, -0.0, 0.0],
[271.24, 532.19, 2612.08, 0.0, -0.0, 0.0],
[114.43, -31.73, 2439.24, 0.0, -0.0, 0.0],
[-157.93, -220.7, 2490.9, 0.0, -0.0, 0.0],
[-200.13, -350.38, 2501.29, 0.0, -0.0, 0.0],
[-722.9, -260.64, 2556.52, 0.0, -0.0, 0.0],
[-750.43, 160.15, 2551.35, 0.0, -0.0, 0.0],
[-759.14, 488.8, 2545.55, 0.0, -0.0, 0.0],
[-358.39, 151.63, 2416.5, 0.0, -0.0, 0.0],
[-289.58, -60.31, 2410.38, 0.0, -0.0, 0.0],
[-86.04, 153.06, 2369.19, 0.0, -0.0, 0.0],
[-9.05, -92.79, 2361.71, 0.0, -0.0, 0.0]]
list_base_brute = [[2443.9128, -501.7427, -630.8925, -179.0604, 0.4017, 145.2487],
[2126.8356, -703.2691, -678.1219, -179.6825, 0.552, 124.2606],
[1534.3236, -757.3283, -678.0219, 179.9398, 0.6337, 88.9192],
[1532.8918, -339.4951, -682.6528, 179.7809, 0.5975, 74.2169],
[2103.9974, -226.6539, -472.8035, -179.4523, 0.3239, 153.7627],
[2297.246, 47.3245, -475.6743, -179.4523, 0.3237, 153.7627],
[2429.3814, 88.5478, -476.0224, -179.7454, -0.5832, -109.2463],
[2353.675, 614.8282, -447.7145, -179.7454, -0.5833, -109.2462],
[1931.7996, 651.5278, -448.4745, -179.7454, -0.5835, -109.2461],
[1604.6555, 664.6893, -448.8943, -179.7455, -0.5835, -109.2461],
[1925.4354, 246.4732, -379.1885, -179.7455, -0.5836, -109.2458],
[2137.8614, 172.319, -378.1896, -179.7455, -0.5836, -109.2459],
[1919.7934, -31.8006, -376.11, -179.7455, -0.5837, -109.2459],
[2164.5074, -117.227, -374.9585, -179.7455, -0.5837, -109.2459]]
mat_ = set_frame_passage_(list_base_brute, list_ext_brute)
if mat_.b_done:
print('-------------------------------------------------------------------------------------------------------')
print('xyzrpw = ' + str(mat_.res2))
print('-------------------------------------------------------------------------------------------------------')
print('vecteur translation : x=' + str(mat_.res2[0]) + ', y=' + str(mat_.res2[1]) + ', z=' + str(mat_.res2[2]))
print('angles de rotation : r=' + str(mat_.res2[3]) + ', p=' + str(mat_.res2[4]) + ', w=' + str(mat_.res2[5]))
print('----------------------------------------------------------------------------')
print('Matrice de rotation numpy 4x4:')
print(mat_.res1)
print('----------------------------------------------------------------------------')
print('Matrice de rotation roboDK 4x4:')
print(mat_.res3)
else:
print(mat_.str_msg)
For information, I have found why I got this error:
The module transformation.py that i get is not complete and some functions are missing (in particular the one that raise an error) and due to the instruction "from transformation import *", there was apparently a default... I just use import the function that I need (superimposition_matrix) and I just test.
So now, the calculation passed but Now the result is not OK.
By an another software that we use for the robots ABB (Robotstudio), we have a function dedicated to the calculation of the Transformation Frames which is "DefAccFrame - Definition of an Accurate Frame between two systems". When we use it, we obtains the correct value (tested in real) and for now, this code does not work.
The issue is that this instruction is accessible only on ABB robots and I would to find a way to use it in any controller.
That's where I am today.
Really Thanks to everybody for all the help.
I have a data set of points, logR, logT, and logX, where X is a function of R and T. It's only a data set, I have no defined function for X. The data is listed in a table, where logR corresponds to columns and logT corresponds to logT. I am attempting to use an interpolation function to evaluate this grid at two inputs of logR and logT. I found my situation most related to this post:
How to pass arrays into Scipy Interpolate RectBivariateSpline?
But I could not arrange things so my function could be evaluated at my inputs. Here are my attempts:
import numpy as np
from scipy.interpolate import RectBivariateSpline, interp2d
op_r = np.array([1e-8, 3.1622e-8, 1e-7, 3.1622e-7, 1e-6, 3.1622e-6, 1e-5,
3.1622e-5, 1e-4, 3.1622e-4, 1e-3, 3.1622e-3, 1e-2, 3.1622e-2, 0.1, .31622, 1,
3.1622, 10])
op_T = np.array([17782.794, 19952.623, 22387.211, 25118.864, 28183.829,
31622.777, 35481.339, 39810.717, 44668.359, 50118.723, 56234.133, 63095.734,
79432.823, 89125.094])
log_op_val = np.array([[-0.598, -0.593, -0.583, -0.568, -0.539, -0.477,
-0.353, -0.142, 0.168, 0.558, 0.990, 1.443, 1.915, 2.407, 2.866, 3.239, 3.517,
3.725, 3.896], [-0.597, -0.592, -0.580, -0.561, -0.532, -0.474, -0.362,
-0.165, 0.138, 0.539, 1.001, 1.476, 1.942, 2.426, 2.912, 3.352, 3.702, 3.968,
4.175], [-0.588, -0.588, -0.578, -0.555, -0.520, -0.462, -0.357, -0.171,
0.124, 0.529, 1.009, 1.507, 2.001, 2.487, 2.979, 3.453, 3.856, 4.176, 4.422],
[-0.545, -0.559, -0.563, -0.546, -0.506, -0.442, -0.338, -0.159, 0.132, 0.538,
1.015, 1.525, 2.051, 2.565, 3.072, 3.563, 3.996, 4.356, 4.634], [-0.520,
-0.521, -0.519, -0.509, -0.475, -0.409, -0.301, -0.122, 0.167, 0.571, 1.052,
1.570, 2.106, 2.642, 3.176, 3.684, 4.136, 4.517, 4.822], [-0.518, -0.514,
-0.504, -0.478, -0.425, -0.344, -0.232, -0.056, 0.226, 0.629, 1.111, 1.631,
2.169, 2.719, 3.276, 3.804, 4.275, 4.672, 4.990], [-0.517, -0.513, -0.504,
-0.479, -0.417, -0.297, -0.129, 0.074, 0.353, 0.734, 1.202, 1.715, 2.250,
2.800, 3.364, 3.907, 4.394, 4.802, 5.127], [-0.518, -0.514, -0.505, -0.484,
-0.429, -0.311, -0.104, 0.185, 0.521, 0.894, 1.329, 1.818, 2.341, 2.883,
3.441, 3.986, 4.481, 4.894, 5.218], [-0.517, -0.514, -0.507, -0.490, -0.443,
-0.337, -0.142, 0.169, 0.588, 1.039, 1.480, 1.936, 2.431, 2.955, 3.496, 4.031,
4.521, 4.934, 5.253], [-0.516, -0.513, -0.507, -0.492, -0.453, -0.361, -0.184,
0.103, 0.510, 1.009, 1.531, 2.022, 2.502, 3.002, 3.519, 4.035, 4.513, 4.920,
5.235], [-0.515, -0.511, -0.506, -0.493, -0.460, -0.381, -0.225, 0.036, 0.409,
0.877, 1.415, 1.973, 2.502, 3.005, 3.505, 4.002, 4.468, 4.868, 5.183],
[-0.515, -0.511, -0.503, -0.490, -0.462, -0.394, -0.257, -0.022, 0.321, 0.759,
1.269, 1.827, 2.403, 2.949, 3.458, 3.948, 4.405, 4.802, 5.113], [-0.516,
-0.512, -0.502, -0.487, -0.460, -0.400, -0.279, -0.066, 0.254, 0.672, 1.164,
1.701, 2.278, 2.851, 3.388, 3.889, 4.347, 4.741, 5.047], [-0.517, -0.512,
-0.503, -0.485, -0.454, -0.397, -0.287, -0.092, 0.211, 0.620, 1.101, 1.628,
2.190, 2.762, 3.322, 3.841, 4.305, 4.695, 4.989], [-0.516, -0.512, -0.503,
-0.484, -0.449, -0.388, -0.283, -0.099, 0.192, 0.596, 1.071, 1.596, 2.148,
2.714, 3.281, 3.811, 4.280, 4.661, 4.937]])
T_1a = 22100.
R_a = rho_ta /(((T_1a)/(1e6))**3)
gri_chi_a = RectBivariateSpline(op_r, op_T, op_val)
chi_a = RectBivariateSpline(R_a, T_1a)
print chi_a
And this is the error I get:
Traceback (most recent call last):
File "model.py", line 279, in <module>
gri_chi_a = RectBivariateSpline(op_r, op_T, op_val)
"/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/interpolate/fitpack2.py", line 882, in __init__
raise TypeError('x dimension of z must have same number of '
TypeError: x dimension of z must have same number of elements as x
It is the same as if I use the interp2d function. Any help would be appreciated.
Copy-n-pasting your arrays I get:
In [391]: op_r.shape
Out[391]: (19,)
In [393]: op_T.shape
Out[393]: (14,)
In [395]: log_op_val.shape
Out[395]: (15, 19)
15 does not equal 14 or 19!
I am having a very weird and frustrating error.
The problem is very simple:
>>> mylist
[70.71, 67.23, 60.1, 62.52, 64.14, 65.4, 68.84, 61.04, 66.95, 62.22, 63.73, 62.04, 57.12, 61.3, 65.48, 61.49, 66.94, 62.68, 60.31, 64.38, 62.84, 63.03, 67.12, 60.65, 61.68, 64.0, 62.91, 61.36, 60.65, 62.45, 64.22, 66.4, 59.96, 57.03, 66.4, 60.43, 64.05, 64.09, 50.94, 39.84, 45.12, 63.39, 55.62, 55.58, 58.04, 59.91, 60.05, 57.3, 61.83, 63.87, 50.58, 62.56, 60.75, 58.9, 62.99, 61.65, 59.09, 59.91, 64.66, 61.1, 61.31, 59.62, 56.65, 60.1, 66.04, 60.57, 59.77, 53.0, 60.84, 61.75, 64.53, 52.0, 62.08, 67.69, 60.62, 55.04, 54.49, 30.82, 48.32, 59.66, 62.56, 66.71, 70.4, 55.13, 59.32, 63.06, 56.0, 56.19, 65.9, 61.01, 62.03, 59.43, 62.82, 56.83, 62.91, 76.44, 68.01, 61.0, 63.51, 58.12, 65.77, 56.88, 63.18, 69.03, 63.34, 54.91, 60.25, 64.79, 64.17, 61.86, 53.05, 63.42, 57.08, 60.36, 59.62, 64.69, 59.78, 58.34, 65.19, 55.49, 73.53, 56.25, 61.09, 53.35, 63.45, 64.34, 29.79, 59.75, 67.7, 59.74, 52.17, 61.29, 58.88, 55.68, 55.81, 57.52, 62.0, 62.49, 60.47, 61.86, 56.94, 56.31, 61.82, 62.01, 59.99, 59.4, 57.9, 63.08, 64.56, 60.77, 63.95, 60.1, 66.22, 58.05, 66.25, 62.34, 61.17, 64.04, 64.08, 61.1, 56.19, 61.04, 53.13, 64.58, 60.96, 58.97, 59.43, 66.22, 58.4, 55.68, 35.47, 42.6, 57.57, 58.3, 60.84, 62.52, 54.86, 60.9, 60.99, 60.47, 61.45, 58.34, 62.17, 63.68, 62.4, 64.62, 56.78, 59.14, 61.47, 54.7, 55.3, 58.09, 62.95, 61.47, 57.69, 62.45, 54.86, 58.51, 60.52, 54.56]
An now I try to get the min value:
>>> min(mylist)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
Why?
Most probably you have a variable named min that shadowed the built in min function. If you are using the interactive console just do:
del min
Also consider using numpy, as it can be faster on bigger lists:
>>> import numpy
>>> numpy.min(mylist)
I can not reproduce this. min(mylist) returns 29.79.
You are probably using a variable called min in your code. Don't do this.
I'm trying to input a csv file that I can then use to do calculations:
import csv
data=[]
file=input ("Enter file name: ")
with open(file,"r") as f:
reader=csv.reader(f)
for row in reader:
data.append([x.strip(";") for x in row])
print(data)
print("Calculate COV")
lst= data
spl= [x.split(";") for y in lst for x in y]
flattened = [float(x) for y in spl for x in y if x]
print (flattened)
But I keep getting this when I use decimal numbers:
[['13', '25;12', '97;13', '12;13', '47;13', '44;13', '09;12', '86;12', '78;12', '91;12', '93;12', '91;13', '11'], ['12', '92;13', '42;13', '58;13', '7;13', '62;13', '7;13', '31;12', '86;12', '59;12', '81;13', '46;12', '9'], ['13', '39;13', '5;13', '29;13', '26;13', '38;13', '45;13', '46;11', '95;12;12', '57;13', '22;12', '88'], ['12', '48;13', '76;13', '7;13', '77;13', '08;13', '48;13', '25;12', '31;12', '56;12', '56;12', '95;13', '38'], ['12', '52;14', '07;14', '46;14', '13;13', '98;14', '07;13', '92;12', '7;13', '01;12', '79;13;13', '13']]
When I should have this:
[13.25, 12.97, 13.12, 13.47, 13.44, 13.09, 12.86, 12.78, 12.91, 12.93, 12.91, 13.11, 12.92, 13.42, 13.58, 13.7, 13.62, 13.7, 13.31, 12.86, 12.59, 12.81, 13.46, 12.9, 13.39, 13.5, 13.29, 13.26, 13.38, 13.45, 13.46, 11.95, 12.57, 13.22, 12.88, 12.48, 13.76, 13.7, 13.77, 13.08, 13.48, 13.25, 12.31, 12.56, 12.56, 12.95, 13.38, 12.52, 14.07, 14.46, 14.13, 13.98, 14.07, 13.92, 12.7, 13.01, 12.79, 13.0, 13.13]
It's really not clear how you are trying to use the CSV module. First, by default, the csv module is going to use comma separated values, not semicolon separated values.
But either way, let's try writing some code:
import csv
class MyDialect(csv.excel):
delimiter = ';'
with open('in.csv', 'r') as f:
reader = csv.reader(f, MyDialect())
data = list(reader)
data = [[float(elem.replace(',', '.')) for elem in line] for line in data]
for line in data:
print line
in.csv
13,25;12,97;13,12;13,47;13,44;13,09;12,86;12,78;12,91;12,93;12,91;13,11
12,92;13,42;13,58;13,7;13,62;13,7;13,31;12,86;12,59;12,81;13,46;12,9
13,39;13,5;13,29;13,26;13,38;13,45;13,46;11,95;12;12,57;13,22;12,88
12,48;13,76;13,7;13,77;13,08;13,48;13,25;12,31;12,56;12,56;12,95;13,38
12,52;14,07;14,46;14,13;13,98;14,07;13,92;12,7;13,01;12,79;13;13,13
stdout
[13.25, 12.97, 13.12, 13.47, 13.44, 13.09, 12.86, 12.78, 12.91, 12.93, 12.91, 13.11]
[12.92, 13.42, 13.58, 13.7, 13.62, 13.7, 13.31, 12.86, 12.59, 12.81, 13.46, 12.9]
[13.39, 13.5, 13.29, 13.26, 13.38, 13.45, 13.46, 11.95, 12.0, 12.57, 13.22, 12.88]
[12.48, 13.76, 13.7, 13.77, 13.08, 13.48, 13.25, 12.31, 12.56, 12.56, 12.95, 13.38]
[12.52, 14.07, 14.46, 14.13, 13.98, 14.07, 13.92, 12.7, 13.01, 12.79, 13.0, 13.13]
Try this:
import csv
data=[]
import re
with open("out.csv","r") as f:
reader=csv.reader(f,delimiter=";")
for row in reader:
print row
data+=[x.split(",") for x in row]
print(data)
print("Calculate COV")
flattened = [float(x) for y in data for x in y]