From 490ec53785cec63135cee3b08e5dbce776f26ba3 Mon Sep 17 00:00:00 2001 From: "Kieran B. Spooner" Date: Wed, 30 Aug 2023 08:58:17 +0100 Subject: [PATCH 1/3] can now add contours to heatmaps easily also cli bug fix --- tp/cli/cli.py | 2 +- tp/plot/heatmap.py | 106 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 96 insertions(+), 12 deletions(-) diff --git a/tp/cli/cli.py b/tp/cli/cli.py index a550ae8..b934a77 100644 --- a/tp/cli/cli.py +++ b/tp/cli/cli.py @@ -272,7 +272,7 @@ def get_amset(amset_file, quantity, dtype, doping, direction, temperature, spin, @get.command('occupation') @inputs_function('amset_mesh_file', nargs=1) @doping_type_option -@doping_option +@doping_function() @temperature_option @click.option('--spin', help='Spin direction.', diff --git a/tp/plot/heatmap.py b/tp/plot/heatmap.py index 2b20a73..b3abe01 100644 --- a/tp/plot/heatmap.py +++ b/tp/plot/heatmap.py @@ -46,7 +46,9 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', xscale='linear', yscale='linear', cscale='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, - colour='viridis', undercolour=None, overcolour=None, **kwargs): + colour='viridis', undercolour=None, overcolour=None, + contours=None, contourcolours='black', contourkwargs=None, + **kwargs): """Adds a heatmap to a set of axes. Formats limits, parses extra colourmap options, makes sure data @@ -101,6 +103,15 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', overcolour : str or array-like, optional colour for values over cmax. Default: None. + contours : int or float or array-like, optional + contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -233,6 +244,21 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', else: cbar = plt.colorbar(heat, ax=ax, extend=extend) + # contours + if contours is not None: + if contourkwargs == None: + contourkwargs = {} + if not isinstance(contours, (list, np.ndarray)): + contours = list(contours) + if not isinstance(contourcolours, (list, np.ndarray)): + contourcolours = list(contourcolours) + while len(contourcolours) < len(contours): + contourcolours += contourcolours + plt.contour(x[:-1], y[:-1], c, contours, colors=contourcolours, + **contourkwargs) + for i, c in enumerate(contours): + cbar.ax.axhline(c, color=contourcolours[i], **contourkwargs) + # axes formatting tp.plot.utilities.set_locators(ax, x=xscale, y=yscale) tp.plot.utilities.set_locators(cbar.ax, y=cscale) @@ -244,7 +270,8 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, - cmin=None, cmax=None, colour='viridis', **kwargs): + cmin=None, cmax=None, colour='viridis', contours=None, + contourcolours='black', contourkwargs=None, **kwargs): """Convenience wrapper for plotting power factor heatmaps. Calculates power factor, plots and formats labels etc. @@ -287,6 +314,15 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, hex or rgb (array) or a named colour recognised by matplotlib. Default: viridis. + contours : int or float or array-like, optional + PF contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the PF contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -329,7 +365,9 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, data['power_factor'], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, - colour=colour, **kwargs) + colour=colour, contours=contours, + countourcolours=contourcolours, + contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -343,7 +381,9 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, colour1='#800080', colour2='#FF8000', - midcolour='#FFFFFF', label1=None, label2=None, **kwargs): + midcolour='#FFFFFF', label1=None, label2=None, + contours=None, contourcolours='black', contourkwargs=None, + **kwargs): """Plots a difference of two power factors heatmap. Calculates power factor, plots and formats labels etc. @@ -390,6 +430,15 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, label(1,2) : str, optional labels for data(1,2) to go in a legend. Default: None. + contours : int or float or array-like, optional + PF contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the PF contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -467,7 +516,8 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, diff, xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - **kwargs) + contours=contours, contourcolours=contourcolours, + contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -480,7 +530,8 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, - ymax=None, cmin=None, cmax=None, colour='viridis', **kwargs): + ymax=None, cmin=None, cmax=None, colour='viridis', contours=None, + contourcolours='black', contourkwargs=None, **kwargs): """Convenience wrapper for plotting ZT heatmaps. Calculates ZT, plots and formats labels etc. @@ -527,6 +578,15 @@ def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, or rgb (array) or a named colour recognised by matplotlib. Default: viridis. + contours : int or float or array-like, optional + ZT contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the ZT contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -588,7 +648,8 @@ def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, data['zt'], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - **kwargs) + contours=contours, contourcolours=contourcolours, + contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -603,7 +664,8 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, colour1='#800080', colour2='#FF8000', midcolour='#FFFFFF', label1=None, - label2=None, **kwargs): + label2=None, contours=None, contourcolours='black', + contourkwargs=None, **kwargs): """Plots a difference of two ZTs heatmap. Calculates ZT, plots and formats labels etc. @@ -654,6 +716,15 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', label(1,2) : str, optional labels for data(1,2) to go in a legend. Default: None. + contours : int or float or array-like, optional + ZT contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the ZT contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -751,7 +822,8 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', diff, xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - **kwargs) + contours=contours, contourcolours=contourcolours, + contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -765,7 +837,8 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=0, cmax=None, colour='viridis', - negativecolour='grey', **kwargs): + negativecolour='grey', contours=None, + contourcolours='black', contourkwargs=None, **kwargs): """Plots a heatmap of k_latt required for a target ZT Calculates lattice thermal conductivity, plots and formats labels @@ -813,6 +886,15 @@ def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, negativecolour : str or array-like, optional colour for values under cmin. Default: grey. + contours : int or float or array-like, optional + kappa contours to plot. Default: None. + contourcolours : string or array-like, optional + colours of the kappa contours. If fewer are supplied, they + repeat. Default: black. + + contourkwargs : dict, optional + keyword arguments passed to matplotlib.pyplot.contour. + Default: None kwargs keyword arguments passed to matplotlib.pyplot.pcolormesh. Defaults are defined below, which are overridden by those in @@ -854,7 +936,9 @@ def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, data[ltc], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - undercolour=negativecolour, **kwargs) + undercolour=negativecolour, contours=contours, + contourcolours=contourcolours, + contourkwargs=contourkwargs, **kwargs) # axes formatting From 188f2b8024cb24f9c1232358df5ee8c0f2b99932 Mon Sep 17 00:00:00 2001 From: "Kieran B. Spooner" Date: Fri, 16 Feb 2024 15:22:10 +0000 Subject: [PATCH 2/3] added contour and contourf to heatmaps heatmap functions now can add contours or discretise the colourmap with contour(f) --- examples/heatmaps/README.rst | 6 +- tp/cli/cli.py | 63 +++++++----- tp/cli/options.py | 27 +++++ tp/plot/heatmap.py | 193 +++++++++++++++++++++++++---------- 4 files changed, 211 insertions(+), 78 deletions(-) diff --git a/examples/heatmaps/README.rst b/examples/heatmaps/README.rst index b0bf04d..b8fb9ae 100644 --- a/examples/heatmaps/README.rst +++ b/examples/heatmaps/README.rst @@ -84,4 +84,8 @@ using an axes template with multiple sets of axes, the ``custom`` argument must be used in ``add_legend`` to enable manual manipulation of the handles and labels. ``add_ztdiff`` and its power factor equivalent, ``add_pfdiff``, also make sure the colour scale is centred -on zero (i.e. where both are equal). \ No newline at end of file +on zero (i.e. where both are equal). + +Some users may find adding contours with the ``contours`` argument or making +the colour scale discrete with the ``discrete`` argument more legible or +informative. \ No newline at end of file diff --git a/tp/cli/cli.py b/tp/cli/cli.py index b934a77..04f3ab7 100644 --- a/tp/cli/cli.py +++ b/tp/cli/cli.py @@ -956,16 +956,17 @@ def avg_rates(mesh_h5, mfp, total, x, crt, exclude, doping, direction, elif ymax is not None: ax.set_ylim(top=ymax) - if ymin is not None: - if ymax is not None: - for a in ax: - a.set_ylim(ymin, ymax) - else: + else: + if ymin is not None: + if ymax is not None: + for a in ax: + a.set_ylim(ymin, ymax) + else: + for a in ax: + a.set_ylim(bottom=ymin) + elif ymax is not None: for a in ax: - a.set_ylim(bottom=ymin) - elif ymax is not None: - for a in ax: - a.set_ylim(top=ymax) + a.set_ylim(top=ymax) if save: for ext in extension: @@ -1434,12 +1435,14 @@ def kappa(kfile, efile, component, direction, tmin, tmax, dtype, doping, help='Colour for values below --cmin.', default='grey', show_default=True) +@heatmap_options @axes_limit_function(c=True) @plot_io_function('tp-kappa-target') def kappa_target(transport_file, zt, direction, interpolate, kind, colour, - negativecolour, xmin, xmax, ymin, ymax, cmin, cmax, style, + negativecolour, discrete, levels, contours, contourcolours, + xmin, xmax, ymin, ymax, cmin, cmax, style, large, save, show, extension, output): """Plots lattice thermal conductivity to reach a target ZT. @@ -1466,6 +1469,9 @@ def kappa_target(transport_file, zt, direction, interpolate, kind, colour, xinterp=interpolate, yinterp=interpolate, kind=kind, colour=colour, + discrete=discrete, levels=levels, + contours=contours, + contourcolours=contourcolours, negativecolour=negativecolour, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax) @@ -2219,11 +2225,13 @@ def wideband(band_yaml, kappa_hdf5, temperature, poscar, colour, smoothing, styl multiple=True, default=['viridis'], show_default=True) +@heatmap_options @axes_limit_function(c=True) @plot_io_function('tp-ztmap') -def ztmap(transport_file, pf, kappa, direction, dtype, interpolate, kind, colour, +def ztmap(transport_file, pf, kappa, direction, dtype, interpolate, kind, + colour, discrete, levels, contours, contourcolours, xmin, xmax, ymin, ymax, cmin, cmax, style, large, save, show, extension, output): """Plots ZT or PF against temperature and carrier concentration.""" @@ -2242,7 +2250,9 @@ def ztmap(transport_file, pf, kappa, direction, dtype, interpolate, kind, colour if pf: tp.plot.heatmap.add_pfmap(ax, edata, direction=direction, xinterp=interpolate, yinterp=interpolate, - kind=kind, colour=colour, xmin=xmin, + kind=kind, colour=colour, discrete=discrete, + levels=levels, contours=contours, + contourcolours=contourcolours, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax) else: @@ -2253,7 +2263,9 @@ def ztmap(transport_file, pf, kappa, direction, dtype, interpolate, kind, colour tp.plot.heatmap.add_ztmap(ax, edata, kdata=kdata, direction=direction, xinterp=interpolate, yinterp=interpolate, - kind=kind, colour=colour, xmin=xmin, + kind=kind, colour=colour, discrete=discrete, + levels=levels, contours=contours, + contourcolours=contourcolours, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax) @@ -2292,15 +2304,16 @@ def ztmap(transport_file, pf, kappa, direction, dtype, interpolate, kind, colour 'colour recognised by matplotlib.', default='white', show_default=True) +@heatmap_options @axes_limit_function(c=True) @legend_function() @plot_io_function('tp-ztdiff') def ztdiff(transport_files, pf, kappa, direction, dtype, interpolate, kind, - colour, midcolour, xmin, xmax, ymin, ymax, cmin, cmax, legend, - label, legend_title, location, style, large, save, show, extension, - output): + colour, midcolour, discrete, levels, contours, contourcolours, + xmin, xmax, ymin, ymax, cmin, cmax, legend, label, legend_title, + location, style, large, save, show, extension, output): """Plots ZT or PF difference against temperature and carrier concentration. Requires two input datasets. --kappa and --colour take exactly two values @@ -2328,7 +2341,9 @@ def ztdiff(transport_files, pf, kappa, direction, dtype, interpolate, kind, _, h, l = tp.plot.heatmap.add_pfdiff(ax, *edata, direction=direction, xinterp=interpolate, yinterp=interpolate, kind=kind, colour1=colour[0], colour2=colour[1], midcolour=midcolour, - label1=label[0], label2=label[1], xmin=xmin, xmax=xmax, + label1=label[0], label2=label[1], discrete=discrete, + levels=levels, contours=contours, + contourcolours=contourcolours, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax) else: kdata = [] @@ -2343,12 +2358,14 @@ def ztdiff(transport_files, pf, kappa, direction, dtype, interpolate, kind, except OSError: raise Exception( "--kappa must be valid filepaths or floats.") - _, h, l = tp.plot.heatmap.add_ztdiff(ax, edata[0], edata[1], kdata1=kdata[0], - kdata2=kdata[1], direction=direction, xinterp=interpolate, - yinterp=interpolate, kind=kind, colour1=colour[0], - colour2=colour[1], midcolour=midcolour, label1=label[0], - label2=label[1], xmin=xmin, xmax=xmax, ymin=ymin, - ymax=ymax, cmin=cmin, cmax=cmax) + _, h, l = tp.plot.heatmap.add_ztdiff(ax, edata[0], edata[1], + kdata1=kdata[0], kdata2=kdata[1], direction=direction, + xinterp=interpolate, yinterp=interpolate, kind=kind, + colour1=colour[0], colour2=colour[1], midcolour=midcolour, + label1=label[0], label2=label[1], discrete=discrete, + levels=levels, contours=contours, + contourcolours=contourcolours, xmin=xmin, xmax=xmax, + ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax) if legend and label != [None, None]: if location is None: diff --git a/tp/cli/options.py b/tp/cli/options.py index e8ef126..4a9fc16 100644 --- a/tp/cli/options.py +++ b/tp/cli/options.py @@ -11,6 +11,8 @@ dos_function + heatmap_options + input_argument inputs_function @@ -81,6 +83,31 @@ def doping_option(f): return f return doping_option +def heatmap_options(f): + """Options for heatmaps.""" + + f = click.option('--discrete/--continuous', + help='Discretise colourmap. [default: continuous]', + default=False, + show_default=False)(f) + f = click.option('-l', '--levels', + help='Levels for discrete plots. Lists directly ' + 'specify the contour levels, while integers ' + 'specify the maximum-1 number of "nice" ' + 'levels to plot.', + multiple=True, + default=None)(f) + f = click.option('--contours', + help='Contours to plot.', + multiple=True, + type=float, + default=None)(f) + f = click.option('--contourcolours', + help='contour colours', + multiple=True, + default='black')(f) + return f + def dos_function(dosargs=['-c', '--colour']): if isinstance(dosargs, str): dosargs = [dosargs] diff --git a/tp/plot/heatmap.py b/tp/plot/heatmap.py index b3abe01..9f091be 100644 --- a/tp/plot/heatmap.py +++ b/tp/plot/heatmap.py @@ -47,8 +47,8 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', xscale='linear', yscale='linear', cscale='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, colour='viridis', undercolour=None, overcolour=None, - contours=None, contourcolours='black', contourkwargs=None, - **kwargs): + discrete=False, levels=None, contours=None, + contourcolours='black', contourkwargs=None, **kwargs): """Adds a heatmap to a set of axes. Formats limits, parses extra colourmap options, makes sure data @@ -98,6 +98,13 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', with mid and min and/or max keys. Colour format must be hex or rgb (array) or a named colour recognised by matplotlib. Default: Blues. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. undercolour : str or array-like, optional colour for values under cmin. Default: None. overcolour : str or array-like, optional @@ -113,11 +120,11 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -236,7 +243,21 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', y.append(y[-1] ** 2 / y[-2]) # plotting - heat = ax.pcolormesh(x, y, c, cmap=colours, norm=cnorm, **kwargs) + if discrete: + kwargs.pop('rasterized') + if levels is None or levels == (): + heat = ax.contourf(x[:-1], y[:-1], c, cmap=colours, norm=cnorm, + **kwargs) + else: + if isinstance(levels, (list, np.ndarray, tuple)) and len(levels) == 1: + levels = int(levels[0]) + elif isinstance(levels, float): + raise TypeError('levels must be an int or array-like, not float') + if levels is not None and levels != (): + heat = ax.contourf(x[:-1], y[:-1], c, cmap=colours, norm=cnorm, + levels=levels, **kwargs) + else: + heat = ax.pcolormesh(x, y, c, cmap=colours, norm=cnorm, **kwargs) fig = ax.get_figure() if 'dos' in fig.__dict__ and fig.__dict__['dos']: # place colourbar outside dos @@ -245,17 +266,39 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', cbar = plt.colorbar(heat, ax=ax, extend=extend) # contours - if contours is not None: + if contours is not None and contours != (): if contourkwargs == None: contourkwargs = {} if not isinstance(contours, (list, np.ndarray)): contours = list(contours) if not isinstance(contourcolours, (list, np.ndarray)): contourcolours = list(contourcolours) - while len(contourcolours) < len(contours): - contourcolours += contourcolours - plt.contour(x[:-1], y[:-1], c, contours, colors=contourcolours, - **contourkwargs) + if len(contours) > 1: + ctnorm = [(ct-np.amin(contours))/ + (np.amax(contours)-np.amin(contours)) + for ct in contours] + else: + ctnorm = 0 + cmap = None + try: + cmap = contourcolours + contourcolours = mpl.cm.get_cmap(contourcolours)(ctnorm) + plt.contour(x[:-1], y[:-1], c, contours, cmap=cmap, + **contourkwargs) + except ValueError: + cmap = None + if isinstance(contourcolours, mpl.colors.ListedColormap): + cmap = contourcolours + contourcolours = contourcolours(ctnorm) + plt.contour(x[:-1], y[:-1], c, contours, cmap=cmap, + **contourkwargs) + elif not isinstance(contourcolours, (list, np.ndarray)): + contourcolours = [contourcolours] + while len(contourcolours) < len(contours): + contourcolours += contourcolours + if cmap is None: + plt.contour(x[:-1], y[:-1], c, contours, colors=contourcolours, + **contourkwargs) for i, c in enumerate(contours): cbar.ax.axhline(c, color=contourcolours[i], **contourkwargs) @@ -270,8 +313,9 @@ def add_heatmap(ax, x, y, c, xinterp=None, yinterp=None, kind='linear', def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, - cmin=None, cmax=None, colour='viridis', contours=None, - contourcolours='black', contourkwargs=None, **kwargs): + cmin=None, cmax=None, colour='viridis', discrete=False, + levels=None, contours=None, contourcolours='black', + contourkwargs=None, **kwargs): """Convenience wrapper for plotting power factor heatmaps. Calculates power factor, plots and formats labels etc. @@ -313,6 +357,13 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, RGB colours to generate a colour map. Colour format must be hex or rgb (array) or a named colour recognised by matplotlib. Default: viridis. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. contours : int or float or array-like, optional PF contours to plot. Default: None. @@ -324,11 +375,11 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -365,8 +416,8 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, data['power_factor'], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, - colour=colour, contours=contours, - countourcolours=contourcolours, + colour=colour, discrete=discrete, levels=levels, + contours=contours, countourcolours=contourcolours, contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -381,9 +432,9 @@ def add_pfmap(ax, data, direction='avg', xinterp=200, yinterp=200, def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, colour1='#800080', colour2='#FF8000', - midcolour='#FFFFFF', label1=None, label2=None, - contours=None, contourcolours='black', contourkwargs=None, - **kwargs): + midcolour='#FFFFFF', label1=None, label2=None, discrete=False, + levels=None, contours=None, contourcolours='black', + contourkwargs=None, **kwargs): """Plots a difference of two power factors heatmap. Calculates power factor, plots and formats labels etc. @@ -429,6 +480,13 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, colour at 0 difference. Default: #FFFFFF. label(1,2) : str, optional labels for data(1,2) to go in a legend. Default: None. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. contours : int or float or array-like, optional PF contours to plot. Default: None. @@ -440,11 +498,11 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -516,7 +574,8 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, diff, xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - contours=contours, contourcolours=contourcolours, + discrete=discrete, levels=levels, contours=contours, + contourcolours=contourcolours, contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -530,7 +589,8 @@ def add_pfdiff(ax, data1, data2, direction='avg', xinterp=200, yinterp=200, def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, - ymax=None, cmin=None, cmax=None, colour='viridis', contours=None, + ymax=None, cmin=None, cmax=None, colour='viridis', + discrete=False, levels=None, contours=None, contourcolours='black', contourkwargs=None, **kwargs): """Convenience wrapper for plotting ZT heatmaps. @@ -577,6 +637,13 @@ def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, colours to generate a colour map. Colour format must be hex or rgb (array) or a named colour recognised by matplotlib. Default: viridis. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. contours : int or float or array-like, optional ZT contours to plot. Default: None. @@ -588,11 +655,11 @@ def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -648,7 +715,8 @@ def add_ztmap(ax, data, kdata=1., direction='avg', xinterp=200, data['zt'], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - contours=contours, contourcolours=contourcolours, + discrete=discrete, levels=levels, contours=contours, + contourcolours=contourcolours, contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -664,8 +732,8 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=None, cmax=None, colour1='#800080', colour2='#FF8000', midcolour='#FFFFFF', label1=None, - label2=None, contours=None, contourcolours='black', - contourkwargs=None, **kwargs): + label2=None, discrete=False, levels=None, contours=None, + contourcolours='black', contourkwargs=None, **kwargs): """Plots a difference of two ZTs heatmap. Calculates ZT, plots and formats labels etc. @@ -715,6 +783,13 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', colour at 0 difference. Default: #FFFFFF. label(1,2) : str, optional labels for data(1,2) to go in a legend. Default: None. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. contours : int or float or array-like, optional ZT contours to plot. Default: None. @@ -726,11 +801,11 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -822,7 +897,8 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', diff, xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - contours=contours, contourcolours=contourcolours, + discrete=discrete, levels=levels, contours=contours, + contourcolours=contourcolours, contourkwargs=contourkwargs, **kwargs) # axes formatting @@ -837,8 +913,9 @@ def add_ztdiff(ax, data1, data2, kdata1=1., kdata2=1., direction='avg', def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, yinterp=200, kind='linear', xmin=None, xmax=None, ymin=None, ymax=None, cmin=0, cmax=None, colour='viridis', - negativecolour='grey', contours=None, - contourcolours='black', contourkwargs=None, **kwargs): + negativecolour='grey', discrete=False, levels=None, + contours=None, contourcolours='black', contourkwargs=None, + **kwargs): """Plots a heatmap of k_latt required for a target ZT Calculates lattice thermal conductivity, plots and formats labels @@ -885,6 +962,13 @@ def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, matplotlib. Default: viridis. negativecolour : str or array-like, optional colour for values under cmin. Default: grey. + discrete : bool, optional + use colour bands rather than a continuously shifting colour + sequence. Default: False. + levels : int or array-like, optional + sets levels for discrete plots. Lists directly specify the + contour levels while integers specify the maximum-1 number + of "nice" levels to plot. Default: None. contours : int or float or array-like, optional kappa contours to plot. Default: None. @@ -896,11 +980,11 @@ def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, keyword arguments passed to matplotlib.pyplot.contour. Default: None kwargs - keyword arguments passed to matplotlib.pyplot.pcolormesh. - Defaults are defined below, which are overridden by those in - ``~/.config/tprc.yaml``, both of which are overridden by - arguments passed to this function. - Defaults: + keyword arguments passed to matplotlib.pyplot.pcolormesh or + matplotlib.pyplot.contourf. Defaults are defined below, + which are overridden by those in ``~/.config/tprc.yaml``, + both of which are overridden by arguments passed to this + function. Defaults: rasterized: True @@ -936,7 +1020,8 @@ def add_kappa_target(ax, data, zt=2, direction='avg', xinterp=200, data[ltc], xinterp=xinterp, yinterp=yinterp, kind=kind, yscale='log', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, cmin=cmin, cmax=cmax, colour=colour, - undercolour=negativecolour, contours=contours, + undercolour=negativecolour, discrete=discrete, + levels=levels, contours=contours, contourcolours=contourcolours, contourkwargs=contourkwargs, **kwargs) From 071e37e0849203febb88052e5367ecf97b1bf297 Mon Sep 17 00:00:00 2001 From: "Kieran B. Spooner" Date: Wed, 28 Feb 2024 14:54:09 +0000 Subject: [PATCH 3/3] bug squashing and warning quashing fixed a bug where both n- and p-type data in a file would cause the amset loaders to break fixed some regex-related warnings --- tp/data/load.py | 10 +--- tp/plot/frequency.py | 2 +- tp/plot/mfp.py | 2 +- tp/settings.py | 132 +++++++++++++++++++++---------------------- 4 files changed, 70 insertions(+), 76 deletions(-) diff --git a/tp/data/load.py b/tp/data/load.py index 755eabc..6a66e9a 100644 --- a/tp/data/load.py +++ b/tp/data/load.py @@ -159,9 +159,6 @@ def amset(filename, quantities='all', doping='n'): if q2 in dimensions: data2['meta']['dimensions'][q2] = dimensions[q2] - if 'doping' in data2: - data2['doping'] = np.array(data2['doping'])[di] - for c in aconversions: if c in data2: data2[c] = np.multiply(data2[c], float(aconversions[c])) @@ -405,9 +402,6 @@ def resolve_spin(data, q, spin): if q2 in dimensions: data['meta']['dimensions'][q2] = dimensions[q2] - if 'doping' in data: - data['doping'] = np.array(data['doping'])[di] - if 'stype' in data: data['stype'] = [l.decode('UTF-8') for l in data['stype']] data['stype'].append('Total') @@ -897,8 +891,8 @@ def get_path(yamldata): ticks.append(yamldata['labels'][-1][1]) except: # new phonopy/ sumo ticks = [yamldata['phonon'][i - 1]['label'] for i in tickindex] - ticks = ['$\mathregular{\Gamma}$' if i == 'G' or 'gamma' in i.lower() else - '$\mathregular{{{}}}$'.format(i.strip('$')) for i in ticks] + ticks = [r'$\mathregular{\Gamma}$' if i == 'G' or 'gamma' in i.lower() else + r'$\mathregular{{{}}}$'.format(i.strip('$')) for i in ticks] return tickpos, ticks diff --git a/tp/plot/frequency.py b/tp/plot/frequency.py index aae7f07..e1a0381 100644 --- a/tp/plot/frequency.py +++ b/tp/plot/frequency.py @@ -472,7 +472,7 @@ def add_cum_kappa(ax, data, temperature=300, direction='avg', label=None, marker = [marker] if label is None: if len(data) == 1 and len(direction) == 1: - label = ['$\mathregular{\kappa_l}$'] + label = [r'$\mathregular{\kappa_l}$'] else: label = direction elif isinstance(label, str): diff --git a/tp/plot/mfp.py b/tp/plot/mfp.py index 436154f..c6da667 100644 --- a/tp/plot/mfp.py +++ b/tp/plot/mfp.py @@ -183,7 +183,7 @@ def add_cum_kappa(ax, data, kmin=1, temperature=300, direction='avg', if label is None: if len(data) == 1 and len(direction) == 1: - label = ['$\mathregular{\kappa_l}$'] + label = [r'$\mathregular{\kappa_l}$'] else: label = direction elif isinstance(label, str): diff --git a/tp/settings.py b/tp/settings.py index b757478..9d4161f 100644 --- a/tp/settings.py +++ b/tp/settings.py @@ -373,7 +373,7 @@ def dimensions(): 'seebeck_effective_mass': [], 'temperature': ['temperature'], 'thermal_conductivity': ['temperature', 'doping', 3, 3], - 'total_weights': ['stype', 'temperature', 'doping'], + 'total_weights': ['temperature', 'doping'], 'velocities': ['band', 'kpoint', 3], 'weighted_mfp': ['stype', 'temperature', 'doping', 3], 'weighted_rates': ['stype', 'temperature', 'doping'], @@ -447,23 +447,23 @@ def long_labels(): 'complexity_factor': 'Complexity Factor', 'conductivity': - 'Conductivity (S m$\mathregular{^{-1}}$)', + r'Conductivity (S m$\mathregular{^{-1}}$)', 'cumulative_kappa': - 'Cumulative Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Cumulative Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', 'cumulative_percent': 'Cumulative Lattice Thermal Conductivity (%)', 'doping': - 'Carrier Concentration (cm$\mathregular{^{-3}}$)', + r'Carrier Concentration (cm$\mathregular{^{-3}}$)', 'dos': 'Density of States', 'efermi': 'Fermi Energy (eV)', 'effective_mass': - 'Effective Mass (m$\mathregular{_e}$)', + r'Effective Mass (m$\mathregular{_e}$)', 'energy': 'Energy (eV)', 'electronic_thermal_conductivity': - 'Electronic Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Electronic Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', 'fermi_level': 'Fermi Level (eV)', 'frequency': @@ -471,45 +471,45 @@ def long_labels(): 'gamma': 'Imaginary Self Energy (THz)', 'group_velocity': - 'Group Velocity (m s$\mathregular{^{-1}}$)', + r'Group Velocity (m s$\mathregular{^{-1}}$)', 'gruneisen': 'Gruneisen Parameter', 'gv_by_gv': - 'Group Velocity Outer Product (m$\mathregular{^2\ s^{-2}}$)', + r'Group Velocity Outer Product (m$\mathregular{^2\ s^{-2}}$)', 'heat_capacity': - 'Heat Capacity (J K$\mathregular{^{-1}}$)', + r'Heat Capacity (J K$\mathregular{^{-1}}$)', 'lattice_thermal_conductivity': - 'Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', 'lifetime': 'Lifetime (s)', 'mean_free_path': 'Mean Free Path (m)', 'mobility': - 'Mobility (cm$\mathregular{^2\ V^{-1}\ s^{-1}}$)', + r'Mobility (cm$\mathregular{^2\ V^{-1}\ s^{-1}}$)', 'mode_kappa': - 'Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Lattice Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', 'ph_ph_strength': - 'Average Phonon-Phonon Interaction Strengths (eV$\mathregular{^2}$)', + r'Average Phonon-Phonon Interaction Strengths (eV$\mathregular{^2}$)', 'power_factor': - 'Power Factor (W m$\mathregular{^{-1}\ K^{-2}}$)', + r'Power Factor (W m$\mathregular{^{-1}\ K^{-2}}$)', 'occupation': 'Occupation', 'scattering_rates': - 'Scattering Rates (s$\mathregular{^{-1}}$)', + r'Scattering Rates (s$\mathregular{^{-1}}$)', 'seebeck': - 'Seebeck Coefficient ($\mathregular{\mu V\ K^{-1}}$)', + r'Seebeck Coefficient ($\mathregular{\mu V\ K^{-1}}$)', 'temperature': 'Temperature (K)', 'thermal_conductivity': - 'Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Thermal Conductivity (W m$\mathregular{^{-1}\ K^{-1}}$)', 'velocities': - 'Velocity (m s$\mathregular{^{-1}})', + r'Velocity (m s$\mathregular{^{-1}})', 'wavevector': 'Wavevector', 'weighted_mfp': 'Mean Free Path (m)', 'weighted_rates': - 'Scattering Rates (s$\mathregular{^{-1}}$)', + r'Scattering Rates (s$\mathregular{^{-1}}$)', 'zt': 'ZT'} @@ -527,23 +527,23 @@ def medium_labels(): 'complexity_factor': 'Complexity Factor', 'conductivity': - 'Conductivity (S m$\mathregular{^{-1}}$)', + r'Conductivity (S m$\mathregular{^{-1}}$)', 'cumulative_kappa': - 'Cum. LTC (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Cum. LTC (W m$\mathregular{^{-1}\ K^{-1}}$)', 'cumulative_percent': 'Cum. LTC (%)', 'doping': - 'Carrier Concentration (cm$\mathregular{^{-3}}$)', + r'Carrier Concentration (cm$\mathregular{^{-3}}$)', 'dos': 'Density of States', 'efermi': 'Fermi Energy (eV)', 'effective_mass': - 'Effective Mass (m$\mathregular{_e}$)', + r'Effective Mass (m$\mathregular{_e}$)', 'energy': 'Energy (eV)', 'electronic_thermal_conductivity': - 'Elec. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Elec. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', 'fermi_level': 'Fermi Level (eV)', 'frequency': @@ -551,45 +551,45 @@ def medium_labels(): 'gamma': 'Imaginary Self Energy (THz)', 'group_velocity': - 'Group Velocity (m s$\mathregular{^{-1}}$)', + r'Group Velocity (m s$\mathregular{^{-1}}$)', 'gruneisen': 'Gruneisen Parameter', 'gv_by_gv': - 'Group Vel. Outer Prod. (m$\mathregular{^2\ s^{-2}}$)', + r'Group Vel. Outer Prod. (m$\mathregular{^2\ s^{-2}}$)', 'heat_capacity': - 'Heat Capacity (J K$\mathregular{^{-1}}$)', + r'Heat Capacity (J K$\mathregular{^{-1}}$)', 'lattice_thermal_conductivity': - 'Lat. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Lat. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', 'lifetime': 'Lifetime (s)', 'mean_free_path': 'Mean Free Path (m)', 'mobility': - 'Mobility (cm$\mathregular{^2\ V^{-1}\ s^{-1}}$)', + r'Mobility (cm$\mathregular{^2\ V^{-1}\ s^{-1}}$)', 'mode_kappa': - 'Lat. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Lat. Therm. Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', 'ph_ph_strength': - 'Avg. Ph-Ph Strengths (eV$\mathregular{^2}$)', + r'Avg. Ph-Ph Strengths (eV$\mathregular{^2}$)', 'power_factor': - 'Power Factor (W m$\mathregular{^{-1}\ K^{-2}}$)', + r'Power Factor (W m$\mathregular{^{-1}\ K^{-2}}$)', 'occupation': 'Occupation', 'scattering_rates': - 'Scattering Rates (s$\mathregular{^{-1}}$)', + r'Scattering Rates (s$\mathregular{^{-1}}$)', 'seebeck': - 'Seebeck Coefficient ($\mathregular{\mu V\ K^{-1}}$)', + r'Seebeck Coefficient ($\mathregular{\mu V\ K^{-1}}$)', 'temperature': 'Temperature (K)', 'thermal_conductivity': - 'Thermal Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', + r'Thermal Cond. (W m$\mathregular{^{-1}\ K^{-1}}$)', 'velocities': - 'Velocity (m s$\mathregular{^{-1}})', + r'Velocity (m s$\mathregular{^{-1}})', 'wavevector': 'Wavevector', 'weighted_mfp': 'Mean Free Path (m)', 'weighted_rates': - 'Scattering Rates (s$\mathregular{^{-1}}$)', + r'Scattering Rates (s$\mathregular{^{-1}}$)', 'zt': 'ZT'} @@ -603,73 +603,73 @@ def short_labels(): """Get dictionary of short-form axis labels.""" labels = {'chemical_potential': - '$\mathregular{\mu}$ (eV)', + r'$\mathregular{\mu}$ (eV)', 'complexity_factor': - '$\mathregular{N_v*K*}$', + r'$\mathregular{N_v*K*}$', 'conductivity': - '$\mathregular{\sigma\ (S\ m^{-1})}$', + r'$\mathregular{\sigma\ (S\ m^{-1})}$', 'cumulative_kappa': - '$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', + r'$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', 'cumulative_percent': - '$\mathregular{\kappa_l}$ (%)', + r'$\mathregular{\kappa_l}$ (%)', 'doping': - 'n (cm$\mathregular{^{-3}}$)', + r'n (cm$\mathregular{^{-3}}$)', 'dos': 'DoS', 'efermi': - 'E$\mathregular{_{F}}$ (eV)', + r'E$\mathregular{_{F}}$ (eV)', 'effective_mass': - '$\mathregular{m*\ (m_e})$', + r'$\mathregular{m*\ (m_e})$', 'energy': 'E (eV)', 'electronic_thermal_conductivity': - '$\mathregular{\kappa_e\ (W\ m^{-1}\ K^{-1})}$', + r'$\mathregular{\kappa_e\ (W\ m^{-1}\ K^{-1})}$', 'fermi_level': - 'E$\mathregular{_{F}}$ (eV)', + r'E$\mathregular{_{F}}$ (eV)', 'frequency': - '$\mathregular{\\nu}$ (THz)', + r'$\mathregular{\\nu}$ (THz)', 'gamma': - '$\mathregular{\Gamma}$ (THz)', + r'$\mathregular{\Gamma}$ (THz)', 'group_velocity': - '$\mathregular{g_v\ (m\ s^{-1})}$', + r'$\mathregular{g_v\ (m\ s^{-1})}$', 'gruneisen': - '$\gamma$', + r'$\gamma$', 'gv_by_gv': - '$\mathregular{g_v \otimes g_v\ (m^2\ s^{-2})}$', + r'$\mathregular{g_v \otimes g_v\ (m^2\ s^{-2})}$', 'heat_capacity': - 'C (J K$\mathregular{^{-1}}$)', + r'C (J K$\mathregular{^{-1}}$)', 'lattice_thermal_conductivity': - '$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', + r'$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', 'lifetime': - '$\mathregular{\\tau}$ (s)', + r'$\mathregular{\\tau}$ (s)', 'mean_free_path': - '$\mathregular{\Lambda}$ (m)', + r'$\mathregular{\Lambda}$ (m)', 'mobility': - '$\mathregular{\mu\ (cm^2\ V^{-1}\ s^{-1})}$', + r'$\mathregular{\mu\ (cm^2\ V^{-1}\ s^{-1})}$', 'mode_kappa': - '$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', + r'$\mathregular{\kappa_l\ (W\ m^{-1}\ K^{-1})}$', 'ph_ph_strength': - '$\mathregular{P_\lambda\ (eV^2)}$', + r'$\mathregular{P_\lambda\ (eV^2)}$', 'power_factor': - 'PF (W m$\mathregular{^{-1}\ K^{-2}}$)', + r'PF (W m$\mathregular{^{-1}\ K^{-2}}$)', 'occupation': 'Occupation', 'scattering_rates': - '$\mathregular{\\tau^{-1}\ (s^{-1})}$', + r'$\mathregular{\\tau^{-1}\ (s^{-1})}$', 'seebeck': - '$\mathregular{\\alpha\ (\mu V\ K^{-1})}$', + r'$\mathregular{\\alpha\ (\mu V\ K^{-1})}$', 'temperature': 'T (K)', 'thermal_conductivity': - '$\mathregular{\kappa\ (W\ m^{-1}\ K^{-1}}$)', + r'$\mathregular{\kappa\ (W\ m^{-1}\ K^{-1}}$)', 'velocities': - 'v (m s$\mathregular{^{-1}})', + r'v (m s$\mathregular{^{-1}})', 'wavevector': 'q', 'weighted_mfp': - '$\mathregular{\Lambda}$ (m)', + r'$\mathregular{\Lambda}$ (m)', 'weighted_rates': - '$\mathregular{\\tau^{-1}\ (s^{-1})}$', + r'$\mathregular{\\tau^{-1}\ (s^{-1})}$', 'zt': 'ZT'}