In [25]:
%matplotlib inline

In [63]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from SpecificHeat import spec_heat_apiezon_n
sns.set_context('talk', font_scale=1.25, rc={'lines.linewidth':3})
sns.set_style('whitegrid')

In [27]:
#%%writefile -a SpecificHeat.py
#import numpy as np
#
def spec_heat_copper(T, echo=False):
    """Return the specific heat for Copper at temperature 'T' in Kelvin
    
    Parameters
    ----------
    T : float, int, list, numpy.ndarray
        Temperature in Kelvin at which the specific heat should be calculated.
    echo : boolean, optional
        When true, the function prints a sentence with the values to the command line.
        
    Returns
    -------
    C : numpy.ndarray
        The specific heat of Apiezon N at tempterature T in uTg^(-1)K^(-1)
        
    Reference
    ---------
    [1] D. L. Martin, Review of Scientific Instruments 58, 639 (1987)
    [2] cygenics.nist.gov/Papers/Cryo_Materials
    
    """
    # Convert whatever the input is into a numpy array.
    if isinstance(T, (float, int)):
        T = np.asarray([T])
    elif isinstance(T, list):
        T = np.asarray(T)
    elif isinstance(T, np.ndarray):
        pass
    else:
        raise TypeError('Invalid temperature type. Type a float, int, list or numpy array.')

    C = np.ndarray(T.shape)
    
    # MArtin 87
    A1 = np.array([-0.8209550462989,
                   +0.1877774093791,
                   -0.1572548380193E-1,
                   +0.5828318431167E-3,
                   -0.1420296394933E-5,
                   -0.3466012703872E-6,
                   +0.1030643882976E-7,
                   -0.1621415050746E-9,
                   +0.1678243825986E-11,
                   -0.1225826347399E-13,
                   +0.6497335630403E-16,
                   -0.2516918128676E-18,
                   +0.7065147741950E-21,
                   -0.1400307720276E-23,
                   +0.1858984964834E-26,
                   -0.1483657580275E-29,
                   +0.5382629833814E-33])
                    
    # Matin 68
    gamma = 165.2
    Omega = 345.8
    
    # NIST
    A2 = np.array([-1.91844,
                   -0.15973,
                   +8.61013,
                   -18.99640,
                   +21.96610,
                   -12.73280,
                   +3.54322,
                   -0.37970,
                   +0])
          
    for i, t in enumerate(T):
        #print(i, t)
        # Martin87
        #if t >= 20 and t <= 320:
        #    for n, a in enumerate(A1):
        #        #print(n, a)
        #        C[i] += a/63.546*T**(n)
        
        # Martin68
        #if t <= 3.0:
        #    C[i] = gamma * (1/63.546) * t +(464.34/(Omega**(3)))*t**(3)
        #else:
        #    C[i] = np.NaN
        
        # NIST
        for n, a in enumerate(A2):
            c = a*np.log10(t)**n
            #print('10^({:.3}*log({})^{}) = {:.3}'.format(a, t, n, 10**c))
            C[i] += c
            
    C = (10**C)
    
    # Print the results to the commant line
    if echo:
        try:
            for i, t in enumerate(T):
                # print(i, t)
                print('The specific heat of Apiezon N at {} K is {:.3f} J g^(-1) K^(-1)'.format(t, C[i]))
        except IndexError:
            print('The specific heat of Apiezon N at {} K is {:.3f} J g^(-1) K^(-1)'.format(T, C))
    
    # Return the resutling array
    return C

In [18]:
def therm_cond_copper(T):
    log_kappa = ((2.2154 - 0.88068*T**(0.5) + 0.29505*T - 0.048310*T**(1.5) + 0.003207*T**2)/
                 (1 - 0.47461*T**(0.5) + 0.13871*T - 0.020430*T**(1.5) + 0.001281*T**2))
    
    kappa = 10**log_kappa
    
    return kappa

In [59]:
x = np.linspace(0.0, 270.0)
print(x)


[   0.            5.51020408   11.02040816   16.53061224   22.04081633
   27.55102041   33.06122449   38.57142857   44.08163265   49.59183673
   55.10204082   60.6122449    66.12244898   71.63265306   77.14285714
   82.65306122   88.16326531   93.67346939   99.18367347  104.69387755
  110.20408163  115.71428571  121.2244898   126.73469388  132.24489796
  137.75510204  143.26530612  148.7755102   154.28571429  159.79591837
  165.30612245  170.81632653  176.32653061  181.83673469  187.34693878
  192.85714286  198.36734694  203.87755102  209.3877551   214.89795918
  220.40816327  225.91836735  231.42857143  236.93877551  242.44897959
  247.95918367  253.46938776  258.97959184  264.48979592  270.        ]

In [60]:
copper = pd.DataFrame({r'C_p' : spec_heat_copper(x),
                       r'\kappa' : therm_cond_copper(x)},
                      index=x)

In [61]:
copper


Out[61]:
C_p \kappa
0.000000 NaN 164.210151
5.510204 0.190613 858.207427
11.020408 1.137101 1684.062598
16.530612 4.043631 2264.763407
22.040816 10.232978 2441.966710
27.551020 20.498312 2281.460866
33.061224 34.836776 1942.642820
38.571429 52.587631 1573.786990
44.081633 72.740365 1258.410881
49.591837 94.218862 1019.622792
55.102041 116.065200 849.122678
60.612245 137.524365 729.999091
66.122449 158.059867 646.845112
71.632653 177.331279 588.222010
77.142857 195.156248 546.274771
82.653061 211.470342 515.755806
88.163265 226.291345 493.173103
93.673469 239.690380 476.185522
99.183673 251.770031 463.203517
104.693878 262.648564 453.131878
110.204082 272.449068 445.204524
115.714286 281.292337 438.877663
121.224490 289.292479 433.759882
126.734694 296.554456 429.565761
132.244898 303.172934 426.084641
137.755102 309.232003 423.159292
143.265306 314.805444 420.671146
148.775510 319.957321 418.529925
154.285714 324.742737 416.666278
159.795918 329.208676 415.026483
165.306122 333.394844 413.568605
170.816327 337.334479 412.259671
176.326531 341.055120 411.073573
181.836735 344.579296 409.989509
187.346939 347.925162 408.990801
192.857143 351.107060 408.064000
198.367347 354.136023 407.198200
203.877551 357.020221 406.384509
209.387755 359.765347 405.615642
214.897959 362.374969 404.885598
220.408163 364.850830 404.189410
225.918367 367.193120 403.522950
231.428571 369.400710 402.882766
236.938776 371.471365 402.265965
242.448980 373.401932 401.670103
247.959184 375.188500 401.093115
253.469388 376.826557 400.533239
258.979592 378.311120 399.988972
264.489796 379.636853 399.459024
270.000000 380.798182 398.942280

In [64]:
fig, axes = plt.subplots();

copper.plot(ax=axes,
            secondary_y=r'\kappa'
            );
axes.set_title('Uh...');
axes.set_xlabel('Temperature [K]');
axes.set_ylabel('Specific Heat [J/kg*K]');


Out[64]:
<matplotlib.text.Text at 0x7f0c0ec39710>

In [32]:
plt.loglog(x, spec_heat_copper(x), x, therm_cond_copper(x), basex=10, basey=10);
plt.xlabel('Temperature [K]');
plt.ylabel('Specific Heat [J/kg*K]');



In [42]:
therm_cond_copper(x)


Out[42]:
array([  164.21015083,   397.7016206 ,   653.44774552,   950.24635191,
        1264.13727694,  1569.39353356,  1844.54678832,  2074.4655562 ,
        2250.32355323,  2368.70211061,  2430.50801876,  2439.958015  ,
        2403.65968682,  2329.75414153,  2227.10315978,  2104.54378021,
        1970.26065387,  1831.32704189,  1693.44224199,  1560.85966781,
        1436.47020591,  1321.98901877,  1218.1923956 ,  1125.16069891,
        1042.49791774,   969.51264556,   905.35644772,   849.12267813,
         799.91231892,   756.87438965,   719.22795524,   686.27156657,
         657.38461257,   632.02382426,   609.71715927,   590.05652929,
         572.69028126,   557.31596529,   543.67367158,   531.54006009,
         520.72311042,   511.05756402,   502.40100285,   494.63049606,
         487.63974407,   481.33665259,   475.64127463,   470.48406575,
         465.80440468,   461.54933807])

In [58]:
spec_heat_copper(x)


Out[58]:
array([             nan,   2.90170490e-02,   1.03356495e-01,
         2.41099187e-01,   4.89174727e-01,   9.07163372e-01,
         1.56371945e+00,   2.53210088e+00,   3.88462903e+00,
         5.68725147e+00,   7.99501460e+00,   1.08488815e+01,
         1.42740165e+01,   1.82794307e+01,   2.28587468e+01,
         2.79917847e+01,   3.36466675e+01,   3.97821841e+01,
         4.63501951e+01,   5.32979259e+01,   6.05700416e+01,
         6.81104448e+01,   7.58637710e+01,   8.37765810e+01,
         9.17982687e+01,   9.98817135e+01,   1.07983708e+02,
         1.16065200e+02,   1.24091380e+02,   1.32031650e+02,
         1.39859496e+02,   1.47552295e+02,   1.55091078e+02,
         1.62460253e+02,   1.69647324e+02,   1.76642597e+02,
         1.83438890e+02,   1.90031252e+02,   1.96416701e+02,
         2.02593966e+02,   2.08563263e+02,   2.14326073e+02,
         2.19884954e+02,   2.25243362e+02,   2.30405494e+02,
         2.35376150e+02,   2.40160605e+02,   2.44764505e+02,
         2.49193766e+02,   2.53454496e+02])