In [11]:
import numpy as np
import pandas as pd
xls = pd.ExcelFile('HAAG.xls')
DATA = xls.parse('PerpExtrusion')
T = DATA['Temperature(C)']
F = DATA['Fluence(dpa)']
Y = DATA['DV/V0(%)']
E0 = DATA['Pre-Irrad.Eo(GPa)']
EpE0 = DATA['Rel.ChangeE/EoPre-Irrad.']

In [20]:
%matplotlib notebook
import matplotlib.pylab as plt

TEMPS = pd.unique(DATA['IrradiationTemperature(°C)'])

for temperature in TEMPS:
    SUBSET = DATA.loc[DATA['IrradiationTemperature(°C)']==temperature]
    FS = SUBSET['FastNeutronFluence(dpa)']
    YS = SUBSET['Rel.VolumeChangesΔV/V0(%)']
    E0S = SUBSET['Pre-Irrad.Eo(GPa)']
    EpE0S = SUBSET['Rel.ChangeE/EoPre-Irrad.']
    
    plt.figure(1);ax = plt.gca();color = ax._get_lines.get_next_color();plt.plot(FS,YS,'*',color=color);    
    plt.figure(2);ax = plt.gca();color = ax._get_lines.get_next_color();plt.plot(FS,E0S*EpE0S,'*',color=color)


    plt.figure(1);plt.show()
    plt.figure(2);plt.show()



In [9]:
import numpy as np
import pandas as pd
xls = pd.ExcelFile('HAAG.xls')
DATA = xls.parse('WithGrain')
T = DATA['Temperature(°C)']
F = DATA['FastNeutronFluence(dpa)']
Y = DATA['CreepStrain(%) Tensile']
#E0 = DATA['Pre-Irrad.Eo(GPa)']
#EpE0 = DATA['Rel.ChangeE/EoPre-Irrad.']

def form_2Dfunc(X1,X2,PARAMETERS):
    T = X1
    F = X2
    a0,a1,a2,a3,a4,a5,a6,a7,a8,a9 = PARAMETERS
    return  a0 + a1*T + a2*F + a3*T*F + a4*T**2 + a5*F**2 + a6*T**3+ a7*F**3 + a8*T**2*F + a9*T*F**2

def residual(PARAMETERS,XDATA,YDATA):
    X1 = XDATA[0]
    X2 = XDATA[1]
    return form_2Dfunc(X1,X2,PARAMETERS) - YDATA

def normalize(X):
    Xmin = X.min()
    Xmax = X.max()
    return (X-Xmin)/(Xmax-Xmin),Xmin,Xmax

def original(X,Xmin,Xmax):
    return X*(Xmax-Xmin)+Xmin

def normalize1(X):
    Xmin = X.min()
    Xmax = X.max()
    return (X-Xmin)/(Xmax-Xmin)+1,Xmin,Xmax



import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

T,Tmin,Tmax = normalize(T)
F,Fmin,Fmax = normalize(F)

#Y = E0

ax.plot3D(T,F,Y,'k*')
plt.show()

%matplotlib notebook
from scipy.optimize import least_squares
res_lsq = least_squares(residual, [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1],loss='soft_l1', f_scale=0.1, args=([T,F],Y))
print(res_lsq['x'])

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

NT = 11
NF = 11
TT,FF = np.meshgrid(np.linspace(T.min(),T.max(),NT),np.linspace(F.min(),F.max(),NF))

X1 = np.reshape(TT,(NT*NF))
X2 = np.reshape(FF,(NT*NF))
YFUNC = np.reshape(form_2Dfunc(X1,X2,res_lsq['x']),(NT,NF))

ax.plot3D(T,F,Y,'k*')
ax.plot_surface(TT,FF,YFUNC)
plt.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-1c1425cc8620> in <module>()
     50 get_ipython().magic('matplotlib notebook')
     51 from scipy.optimize import least_squares
---> 52 res_lsq = least_squares(residual, [0.1,0.1,0.1],loss='soft_l1', f_scale=0.1, args=([T,F],Y))
     53 print(res_lsq['x'])
     54 

/home/nico/anaconda3/lib/python3.5/site-packages/scipy/optimize/_lsq/least_squares.py in least_squares(fun, x0, jac, bounds, method, ftol, xtol, gtol, x_scale, loss, f_scale, diff_step, tr_solver, tr_options, jac_sparsity, max_nfev, verbose, args, kwargs)
    773 
    774     if not np.all(np.isfinite(f0)):
--> 775         raise ValueError("Residuals are not finite in the initial point.")
    776 
    777     n = x0.size

ValueError: Residuals are not finite in the initial point.

In [10]:
DATA


Out[10]:
IrradiationTemperature(°C) FastNeutronFluence(dpa) Rel.LinearDimensionalChangesΔl/l0(%) Pre-Irrad.BulkDensity(g/cm3) Rel.VolumeChangesΔV/V0(%) Pre-Irrad.Eo(GPa) Rel.ChangeE/EoPre-Irrad. R0(Ω⋅μm) Rel.ChangeΔR/R0(%) Pre-Irrad.α0(10-6/K) Rel.ChangeΔα/α0(%)
0 300 8.92 -1.10 1.830 -3.94 9.39 1.91 7.19 246 4.86 21.2
1 300 16.99 -1.92 1.830 -7.42 9.39 3.07 7.19 205 4.86 6.2
2 300 25.39 -1.75 1.830 -7.17 9.39 4.20 7.19 204 4.86 -16.5
3 299 33.92 -0.05 1.830 -3.17 NaN NaN 7.19 229 NaN NaN
4 310 16.80 -1.60 1.835 -6.87 8.66 3.13 7.50 199 4.72 5.3
5 308 27.56 -1.43 1.835 -7.02 8.66 3.79 7.50 181 4.72 -24.4
6 309 38.45 0.35 1.835 -3.31 8.66 4.14 7.50 222 4.72 -35.8
7 305 47.52 3.13 1.835 2.66 8.66 2.63 7.50 303 NaN NaN
8 305 17.06 -1.83 1.778 -7.00 8.08 3.26 7.89 194 NaN NaN
9 303 27.76 -1.43 1.778 -6.79 8.08 4.62 7.89 180 NaN NaN
10 300 13.91 -1.59 1.820 -5.90 8.69 2.57 7.56 219 NaN NaN
11 302 23.88 -1.95 1.820 -7.95 8.69 3.65 7.56 176 NaN NaN
12 303 34.65 -0.42 1.820 -5.49 8.69 4.42 7.56 204 NaN NaN
13 303 45.80 2.22 1.820 2.33 8.69 3.17 7.56 285 NaN NaN
14 305 16.93 -2.04 1.828 -7.17 9.41 3.28 7.18 198 NaN NaN
15 301 27.03 -1.71 1.828 -6.95 9.41 3.47 7.18 192 NaN NaN
16 302 36.48 -0.45 1.828 -4.57 9.41 4.24 7.18 212 NaN NaN
17 301 46.18 2.20 1.828 2.29 9.41 2.66 7.18 301 NaN NaN
18 300 11.68 -1.46 1.797 -5.20 8.76 2.20 7.57 227 NaN NaN
19 302 21.65 -2.15 1.797 -7.99 8.76 3.36 7.57 181 NaN NaN
20 303 32.28 -0.82 1.797 -5.79 8.76 4.45 7.57 201 NaN NaN
21 301 41.98 1.73 1.797 1.04 8.76 2.79 7.57 282 NaN NaN
22 305 16.14 -2.00 1.857 -6.39 9.81 3.03 6.90 210 NaN NaN
23 301 25.59 -1.91 1.857 -7.10 NaN NaN 6.90 240 NaN NaN
24 302 34.91 -0.65 1.857 -4.59 9.81 4.39 6.90 211 NaN NaN
25 301 44.61 1.86 1.857 1.87 9.81 2.76 6.90 282 NaN NaN
26 395 6.46 -1.03 1.839 -3.42 8.76 2.49 7.44 211 4.73 28.3
27 392 14.07 -2.05 1.839 -7.44 8.76 3.35 7.44 195 4.73 3.2
28 392 19.69 -1.90 1.839 -7.33 8.76 4.25 7.44 191 4.73 -21.8
29 392 20.87 -1.64 1.839 -6.91 8.76 4.00 7.44 193 4.73 -27.2
... ... ... ... ... ... ... ... ... ... ... ...
138 570 2.17 -0.33 1.834 -0.97 9.02 1.83 7.37 218 5.06 16.5
139 600 3.67 -0.51 1.841 -2.58 9.13 1.85 7.32 239 5.05 17.8
140 593 11.55 -1.53 1.841 -5.21 9.13 2.28 7.32 212 5.05 -1.6
141 595 15.29 -1.66 1.841 -6.34 9.13 2.27 7.32 204 5.05 -23.2
142 596 21.68 -0.32 1.841 -3.90 9.13 2.69 7.32 214 5.05 -35.6
143 595 5.88 -0.83 1.801 -2.70 8.38 1.99 7.77 217 5.05 19.2
144 607 11.13 -1.69 1.801 -5.92 8.38 2.63 7.77 206 5.05 -15.4
145 602 15.52 -1.41 1.801 -6.43 8.38 2.70 7.77 195 5.05 -29.3
146 601 23.01 1.12 1.801 -1.02 8.38 2.79 7.77 261 5.05 -41.8
147 600 5.77 -0.82 1.831 -2.48 9.42 1.95 7.20 214 5.05 17.0
148 606 12.86 -1.90 1.831 -5.87 9.42 2.63 7.20 205 5.05 -19.0
149 604 17.32 -1.74 1.831 -5.74 9.42 2.30 7.20 196 5.05 -32.3
150 603 24.80 0.19 1.831 -0.25 9.42 2.20 7.20 270 5.05 -35.8
151 565 1.51 -0.21 1.797 -0.74 8.66 1.75 7.54 210 NaN NaN
152 555 2.76 -0.45 1.793 -1.45 8.90 1.92 7.36 224 NaN NaN
153 600 6.09 -0.87 1.702 -2.76 8.18 1.96 7.86 222 NaN NaN
154 605 12.78 -2.05 1.702 -6.35 8.18 2.74 7.86 209 NaN NaN
155 602 17.51 -1.86 1.702 -6.71 8.18 2.57 7.86 200 NaN NaN
156 602 24.99 0.67 1.702 -0.10 8.18 2.70 7.86 278 NaN NaN
157 605 4.67 -0.71 1.774 -2.25 8.75 1.95 7.62 218 NaN NaN
158 614 11.63 -1.85 1.774 -6.21 8.75 2.49 7.62 205 NaN NaN
159 608 14.78 -2.05 1.774 -6.17 8.75 2.38 7.62 198 NaN NaN
160 606 20.22 -1.23 1.774 -5.19 8.75 2.71 7.62 221 NaN NaN
161 600 6.13 -0.89 1.786 -2.82 8.94 1.99 7.60 217 NaN NaN
162 605 11.77 -1.87 1.786 -6.37 8.94 2.56 7.60 202 NaN NaN
163 601 16.10 -1.83 1.786 -6.25 8.94 2.57 7.60 194 NaN NaN
164 600 5.33 -0.81 1.796 -2.48 9.04 1.97 7.33 218 NaN NaN
165 596 9.27 -1.70 1.796 -4.93 9.04 2.23 7.33 215 NaN NaN
166 597 12.74 -2.07 1.796 -6.78 9.04 2.25 7.33 210 NaN NaN
167 598 18.78 -1.42 1.796 -5.21 9.04 2.68 7.33 219 NaN NaN

168 rows × 11 columns


In [12]:
a = {'a':1}

In [13]:
a


Out[13]:
{'a': 1}

In [14]:
type(a)


Out[14]:
dict

In [ ]: