Beispiel #1
0
 def test_occupation_temperature(self):
     q = 'occupation'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [[11., 12., 13.]])
Beispiel #2
0
 def test_mode_kappa_temperature(self):
     q = 'mode_kappa'
     d = {q: self.four, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [[[11., 12., 13.]]])
Beispiel #3
0
 def test_mode_kappa_both(self):
     q = 'mode_kappa'
     d = {q: self.four, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23., direction='z')
     self.assertEqual(d[q], [[[13.]]])
Beispiel #4
0
 def test_group_velocity_temperature(self):
     q = 'group_velocity'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], self.three)
Beispiel #5
0
 def test_mode_kappa_direction(self):
     q = 'mode_kappa'
     d = {q: self.four, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertTrue((d[q] == [[[[3.]], [[13.]], [[23.]]]]).all())
Beispiel #6
0
 def test_qpoint_direction(self):
     q = 'qpoint'
     d = {q: self.two, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertTrue((d[q] == [3., 13., 23.]).all())
Beispiel #7
0
 def test_velocities_product_temperature(self):
     q = 'velocities_product'
     d = {q: self.two_m, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q],
                      [[11., 12., 13.], [14., 15., 16.], [17., 18., 19.]])
Beispiel #8
0
 def test_lattice_thermal_conductivity_both(self):
     q = 'lattice_thermal_conductivity'
     d = {q: self.two, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23., direction='z')
     self.assertEqual(d[q], 13.)
Beispiel #9
0
 def test_lifetime_temperature(self):
     q = 'lifetime'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [[11., 12., 13.]])
Beispiel #10
0
 def test_lattice_thermal_conductivity_direction(self):
     q = 'lattice_thermal_conductivity'
     d = {q: self.two, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertTrue((d[q] == [3., 13., 23.]).all())
Beispiel #11
0
 def test_lattice_thermal_conductivity_temperature(self):
     q = 'lattice_thermal_conductivity'
     d = {q: self.two, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [11., 12., 13.])
Beispiel #12
0
 def test_heat_capacity_temperature(self):
     q = 'heat_capacity'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [[11., 12., 13.]])
Beispiel #13
0
 def test_heat_capacity_direction(self):
     q = 'heat_capacity'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertEqual(d[q], self.three)
Beispiel #14
0
 def test_gv_by_gv_direction(self):
     q = 'gv_by_gv'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertTrue((d[q] == [[[3.], [13.], [23.]]]).all())
Beispiel #15
0
 def test_power_factor_temperature(self):
     q = 'power_factor'
     d = {q: self.three_m, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q],
                      [[[11., 12., 13.], [14., 15., 16.], [17., 18., 19.]]])
Beispiel #16
0
 def test_mean_free_path_temperature(self):
     q = 'mean_free_path'
     d = {q: self.four, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], [[[11., 12., 13.]]])
Beispiel #17
0
 def test_power_factor_both(self):
     q = 'power_factor'
     d = {q: self.three_m, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z', temperature=23.)
     self.assertTrue((d[q] == [[19.]]).all())
Beispiel #18
0
 def test_mesh_direction(self):
     q = 'mesh'
     d = {q: self.one, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z')
     self.assertEqual(d[q], 3)
Beispiel #19
0
 def test_qpoint_temperature(self):
     q = 'qpoint'
     d = {q: self.three, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], self.three)
Beispiel #20
0
 def test_mesh_temperature(self):
     q = 'mesh'
     d = {q: self.one, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, temperature=23.)
     self.assertEqual(d[q], self.one)
Beispiel #21
0
 def test_velocities_product_both(self):
     q = 'velocities_product'
     d = {q: self.two_m, 'temperature': self.t, 'meta': {}}
     d = resolve.resolve(d, q, direction='z', temperature=23.)
     self.assertTrue((d[q] == [19.]).all())
Beispiel #22
0
def add_cum_kappa(ax, data, kmin=1, temperature=300, direction='avg',
                  xmarkers=None, ymarkers=None, legend='\kappa_l', main=True,
                  scale=False, colour='#000000', fill=False, fillcolour=20,
                  line=True, markerkwargs={}, **kwargs):
    """Cumulates and plots kappa against mean free path.

    Arguments:
        ax : axes
            axes to plot on.
        data : dict
            Phono3py-like data including:
                mode_kappa: array-like
                    frequency and q-point decomposed lattice thermal
                    conductivity.
                mean_free_path : array-like
                    mean free paths.
                temperature : array-like
                    temperature.
        kmin : float or int, optional
            minimum kappa to plot in percent. Default: 1.

        temperature : float, optional
            temperature in K (finds nearest). Default: 300.
        direction : str, optional
            direction from anisotropic data, accepts x-z/ a-c or
            average/ avg. Default: average

        xmarkers : array-like, optional
            mark kappa at certain mean free paths.
        ymarkers : array-like, optional
            mark mean free path at certain kappas.

        main : bool, optional
            set ticks, labels, limits. Default: True.
        scale : bool, optional
            if main, scale to percent. If not main, scale to axis
            limits. Default: False.

        colour : str, optional
            #RRGGBB line colour. Default: #000000.
        fill : bool, optional
            fill below lines. Default: False.
        fillcolour : int or str, optional
            if an integer from 0-99, and colour in #RRGGBB format,
            applies alpha in % to colour. Otherwise treats it as a
            colour. Default: 20.
        line : bool, optional
            plot lines. Default: True.

        markerkwargs : dict, optional
            keyword arguments for the markers, passed to
            matplotlib.pyplot.plot.
            Defaults: {'color':      'black',
                       'rasterized': False}.
        **kwargs : dict, optional
            keyword arguments passed to matplotlib.pyplot.fill_between
            if filled or matplotlib.pyplot.plot otherwise.
            Defaults: {'label':      '$\mathregular{\kappa_l}$',
                       'rasterized': False}
    """

    from tp.calculate import cumulate

    # defaults

    defkwargs = {'label':      '$\mathregular{\kappa_l}$',
                 'rasterized': False}
    for key in defkwargs:
        if key not in kwargs:
            kwargs[key] = defkwargs[key]

    # data formatting and calculation

    data = resolve.resolve(data, ['mode_kappa', 'mean_free_path'],
                           temperature=temperature, direction=direction)
    k = np.ravel(data['mode_kappa'])
    mfp = np.abs(np.ravel(data['mean_free_path']))

    mfp, k = cumulate(mfp, k)
    np.savetxt('cumkappa-mfp-{:.0f}K-{}.dat'.format(temperature, direction),
               np.transpose([mfp, k]), header='mfp(m) k_l(Wm-1K-1)')
    mfp = np.append(mfp, 100*mfp[-1])
    k = np.append(k, k[-1])

    # percentage output

    if scale:
        axscale = [0, 100] if main else None
        k, _ = tp.plot.frequency.scale_to_axes(ax, k, scale=axscale)

    # colour

    if fill:
        if colour.startswith('#') and isinstance(fillcolour, int) and \
           len(colour) == 7:
            if fillcolour >= 0 and fillcolour <= 9:
                fillcolour = colour + '0' + str(fillcolour)
            elif fillcolour >= 10 and fillcolour <= 99:
                fillcolour = colour + str(fillcolour)
            else:
                raise Exception('Expected alpha value between 0 and 99')
        elif isinstance(fillcolour, int):
            warnings.warn('integer fill colours ignored when colour format is '
                          'not #RRGGBB.')
            fillcolour = colour
        if not line: colour = fillcolour

        # plotting

        ax.fill_between(mfp, k, facecolor=fillcolour, edgecolor=colour,
                        **kwargs)
    else:
        ax.plot(mfp, k, color=colour, **kwargs)

    # axes formatting

    if main:
        mindex = next(x[0] for x in enumerate(k) if x[1] > kmin*k[-2]/100)
        axlabels = tp.settings.labels()
        ax.set_ylabel(axlabels['cumulative_kappa'])
        ax.set_xlabel(axlabels['mean_free_path'])
        ax.set_ylim(0, k[-2])
        ax.set_xlim(mfp[mindex], mfp[-2])
        tp.settings.set_locators(ax, x='log', y='linear')

    if xmarkers is not None or ymarkers is not None:
        add_markers(ax, mfp, k, xmarkers, ymarkers, **markerkwargs)

    return