Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tutorialised examples, bug fixes #37

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/01-python-foundations/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Every function returns three things:
2. axes: Where the data goes, used in step 3.
3. add_legend: Adds a legend. We don't use it here, so we've thrown it
away by assigning it to ``_``. Giving it any name and not using it
has the same effect. Legends will be discussed in example 03.
has the same effect. Legends will be discussed in ``03-compound-axes``.

This command can easily be replaced with ``matplotlib.pyplot`` commands
such as ``figure`` and ``subfigs``.
Expand All @@ -50,7 +50,7 @@ file to read from, and return a dictionary of the data.
While you can load your own data, ThermoPlotter takes several steps to
ensure consistent format and units between codes and also with some
old versions of these codes; and with the plotting functions. It also
consistently applies cutom unit conversions and provides metadata
consistently applies custom unit conversions and provides metadata
including array shapes, units and data sources, so care should be
taken if this step is done manually.

Expand All @@ -66,7 +66,7 @@ customisation option, including all the ``kwargs`` from the underlying

This stage can be replaced with ordinary ``matplotlib`` functions such
as ``ax.plot``, which can be assisted by a number of ancillary
ThermoPlotter functions discussed later.
ThermoPlotter functions discussed in ``05-helper-functions``.

----
Save
Expand Down
2 changes: 1 addition & 1 deletion examples/02-individual-customisation/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. image:: wideband.png
:alt: Finite bandwidth phonon dispersion of ZnO.

In most cases, plotting scripts will be more complex than example 01.
In most cases, plotting scripts will be more complex than ``01-python-foundations``.
Many functions require more inputs, and most users will want to
customise plots with colours and stuff.

Expand Down
2 changes: 1 addition & 1 deletion examples/03-compound-axes/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ into one legend, with duplicates removed, which uses up the ``handles``
and ``labels`` arguments, so in order to specify your own, you must set
``custom=True`` (not necessary for single-axes figures).
``tp.axes.legend.consolidate`` may also be useful for non-ThermoPlotter
endaevors, as will be discussed in example 05
endaevors, as will be discussed in ``05-helper-functions``.
4 changes: 2 additions & 2 deletions examples/04-layered-plots/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Axes

Here we use ``two_h``. h stands for horizontal, and there is a
corresponding vertical set of axes, ``two_v``. They also come with
colourbars, by adding ``_colourbars`` to their names.
space for colourbars, by adding ``_colourbars`` to their names.

----
Load
Expand Down Expand Up @@ -61,4 +61,4 @@ reversed with some helper functions: ``set_locators`` sets the axis
scales and tick locators for each axis, and also has a DoS argument,
which removes the ticks and tick labels and the y axis label, while all
the default labels can be accessed with ``settings.labels``. These will
be covered more in example 05.
be covered more in ``05-helper-functions``.
7 changes: 4 additions & 3 deletions examples/05-helper-functions/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ Locators, Ticks and Labels
There are several functions to aid in formatting axes.
``tp.settings.labels``, and its variations ``large_``, ``long_``,
``medium_`` and ``short_labels`` return a dictionary of axes labels
(more on these in example 06). ``tp.plot.utilities.set_locators`` sets
the locators, if you provide a set of axes and set ``x`` and ``y`` to
either ``'linear'`` or ``'log'`` as appropriate.
(more on these in ``06-package-customisation``).
``tp.plot.utilities.set_locators`` sets the locators, if you provide a
set of axes and set ``x`` and ``y`` to either ``'linear'`` or ``'log'``
as appropriate.

-------
Legends
Expand Down
2 changes: 1 addition & 1 deletion examples/05-helper-functions/plot-transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
tp.axes.legend.alphabetise(ax, preset='roman', suffix=')', x=-0.12)

# Save
fig.savefig('transport.pdf')
fig.savefig('transport.png')
Binary file removed examples/05-helper-functions/transport.pdf
Binary file not shown.
Binary file added examples/05-helper-functions/transport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions examples/06-package-customisation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ dictionaries like the locators. The aliases are listed as:
alias: xxx_name

If you add unit conversions, remember to update the units and labels
too! There are six labels dictionaries. ``long_``, ``medium_`` and
``short_labels`` contain the actual labels of those lengths, while
``labels``, ``inverted_labels`` and ``large_labels`` point to which
of those you' would liek to default to for small, inverted and large
axes, respectively. For example, if you prefer to put a inverted DoSs
in a separate axes rather than a DoS axes, you may want to set
``inverted_labels: long``. Finally, there are the default ``kwargs``
for each function, which are passed to the matplotlib plotting
function, such as ``plt.plot``. These override defaults set in the
ThermoPlotter plotting function, but are overridden by arguments
specified by the user.
too! An example has been provided for converting from
S m<super>-1</super> to S cm<super>-1</super>. There are six labels
dictionaries. ``long_``, ``medium_`` and ``short_labels`` contain the
actual labels of those lengths, while ``labels``, ``inverted_labels``
and ``large_labels`` point to which of those you would like to default
to for small, inverted and large axes, respectively. For example, if
you prefer to put a inverted DoSs in a separate axes rather than a DoS
axes, you may want to set ``inverted_labels: long``. Finally, there are
the default ``kwargs`` for each function, which are passed to the
matplotlib plotting function, such as ``plt.plot``. These override
defaults set in the ThermoPlotter plotting function, but are overridden
by arguments specified by the user.

-----------------------
Extending ThermoPlotter
Expand Down
77 changes: 77 additions & 0 deletions examples/06-package-customisation/tprc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This is a counterpart to the ThermoPlotter/tp/settings.py module for
# saving cutom values. If you want to edit ThermoPlotter, save a copy of
# this file as ``~/.config/tprc.yaml``, and edit it there. Only that
# file will be checked and any changes made in the ThermoPlotter
# directory will be overwritten on upgrading.

# style sheet names or lists of names
style: null # default style sheet
large_style: null # large style sheet

# Locator settings
locator:
# Unlike other parts of this file, rather than whole arguments, this
# should give integers to pass to MaxNLocator and AutoMinorLocator,
# respectively.
major: null
minor: null

# The to_xxx, conversions, units and long_, medium_ and short_labels
# functions should contain dictionaries, e.g.
# to_xxx:
# energies: 'energy'
# and if you change a conversion, remember to change the units and
# labels as well and vice versa!

# aliases for quantities
to_tp: null
to_amset: null
to_boltztrap: null
to_phono3py: null

# unit conversions from the tp standards (see settings.py for reference)
conversions:
conductivity: 1.e-2

# updated units
units:
conductivity: 'S cm-1'

# updated axis labels`
long_labels:
conductivity: 'Conductivity (S cm$\mathregular{^{-1}}$)'
medium_labels:
conductivity: 'Conductivity (S cm$\mathregular{^{-1}}$)'
short_labels:
conductivity: '$\mathregular{\sigma\ (S\ cm^{-1}}$)'

# The following should contain either long, medium or short, to point to
# the dictionaries of long_, medium_ or short_labels.
labels: null # for paper-style (small) axes
inverted_labels: null # for dos-style axes
large_labels: null # for presentation-style (large) axes

# The following are default kwargs for each plot type. These will
# override those specified in the module, but will be overridden by
# those specified when the function is called.
# Frequency:
dos_kwargs: null
frequency_cum_kappa_kwargs: null
waterfall_kwargs: null
projected_waterfall_kwargs: null
density_kwargs: null
# Heatmap:
heatmap_kwargs: null
ztmap_kwargs: null
kappa_target_kwargs: null
# MFP:
mfp_cum_kappa_kwargs: null
marker_kwargs: null
# Phonons:
dispersion_kwargs: null
multi_kwargs: null
alt_dispersion_kwargs: null
projected_dispersion_kwargs: null
alt_projected_dispersion_kwargs: null
wideband_kwargs: null
xmarkkwargs: null
2 changes: 1 addition & 1 deletion examples/cumkappa/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to add markers has been included, e.g. here you can see nanostructuring
to 10 nanometers may reduce the lattice thermal conductivity by nearly
50 %.

This also demonstrates use of the add_legend function supplied with
This also demonstrates use of the ``add_legend`` function supplied with
``tp.axes`` functions, which combines the legends of all plots and
places itself in one of several pre-programmed position, which you can
select with the ``location`` argument. Numbers will place the legend
Expand Down
2 changes: 1 addition & 1 deletion examples/kappa-target/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This is also available as a command-line script, ``tp plot kappa-target``.
This also demonstrates the ``tp.plot.heatmap.add_heatmap`` function
which ``add_ztmap`` wraps around, which enhances pcolourmesh in ways
such as automatic rescaling of axes to represent all data, automatic
extension of colourbars if applicable and custom colourmaps These
extension of colourbars if applicable and custom colourmaps. These
colourmaps are generated dynamically with the input of a single
``#RRGGBB`` colour code. In this case, the ``tp.plot.colour.uniform``
colourmap generator has been used, which calculates a uniform colourmap
Expand Down
4 changes: 2 additions & 2 deletions examples/phonons/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This shows a phonon dispersion and density of states (DoS). All plot-
types in ``tp.plot.frequency`` have an invert argument to plot them
side-on by a phonon dispersion, which also shortens their x-axis labels
and removes their y-axis labels and tick labels. Currently the axes of
the two plots have to be aligned manually, but this is simple (see
script).
the two plots have to be aligned manually, but this is simple
(``plot-phonons.py`` line 24).

.. image:: multiphon.png
:alt: Phonon dispersions for different supercell sizes.
Expand Down
4 changes: 2 additions & 2 deletions tp/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def to_tp(name, value):

conversions = tp.settings.conversions()
if name in conversions and conversions[name] is not None:
value = np.divide(value, conversions[name])
value = np.divide(value, float(conversions[name]))

return value

Expand All @@ -578,7 +578,7 @@ def from_tp(name, value):

conversions = tp.settings.conversions()
if name in conversions and conversions[name] is not None:
value = np.multiply(value, conversions[name])
value = np.multiply(value, float(conversions[name]))

return value

Expand Down
22 changes: 11 additions & 11 deletions tp/data/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def amset(filename, quantities=['seebeck', 'conductivity',

for c in aconversions:
if c in data2:
data2[c] = np.multiply(data2[c], aconversions[c])
data2[c] = np.multiply(data2[c], float(aconversions[c]))

if 'power_factor' in quantities:
data2 = tp.calculate.power_factor_fromdict(data2)
Expand Down Expand Up @@ -360,11 +360,11 @@ def resolve_spin(data, q, spin):

for c in aconversions:
if c in data:
data[c] = np.multiply(data[c], aconversions[c])
data[c] = np.multiply(data[c], float(aconversions[c]))

for c in conversions:
if c in data:
data[c] = np.multiply(data[c], conversions[c])
data[c] = np.multiply(data[c], float(conversions[c]))

return data

Expand Down Expand Up @@ -445,11 +445,11 @@ def boltztrap(filename, quantities=['temperature', 'doping', 'seebeck',

for c in bconversions:
if c in data:
data[c] = np.multiply(data[c], bconversions[c])
data[c] = np.multiply(data[c], float(bconversions[c]))

for c in conversions:
if c in data:
data[c] = np.multiply(data[c], conversions[c])
data[c] = np.multiply(data[c], float(conversions[c]))

return data

Expand Down Expand Up @@ -581,7 +581,7 @@ def phono3py(filename, quantities=['kappa', 'temperature']):

for c in pconversions:
if c in data:
data[c] = np.multiply(data[c], pconversions[c])
data[c] = np.multiply(data[c], float(pconversions[c]))

if 'lifetime' in quantities or 'mean_free_path' in quantities:
data['lifetime'] = tp.calculate.lifetime(data['gamma'], use_tprc=False)
Expand All @@ -596,7 +596,7 @@ def phono3py(filename, quantities=['kappa', 'temperature']):

for c in conversions:
if c in data:
data[c] = np.multiply(data[c], conversions[c])
data[c] = np.multiply(data[c], float(conversions[c]))

return data

Expand Down Expand Up @@ -666,11 +666,11 @@ def phonopy_dispersion(filename, xdata=None):

for c in pconversions:
if c in data2:
data2[c] = np.multiply(data2[c], pconversions[c])
data2[c] = np.multiply(data2[c], float(pconversions[c]))

for c in conversions:
if c in data2:
data2[c] = np.multiply(data2[c], conversions[c])
data2[c] = np.multiply(data2[c], float(conversions[c]))

return data2

Expand Down Expand Up @@ -748,11 +748,11 @@ def phonopy_dos(filename, poscar='POSCAR', atoms=None):

for c in pconversions:
if c in data2:
data2[c] = np.multiply(data2[c], pconversions[c])
data2[c] = np.multiply(data2[c], float(pconversions[c]))

for c in conversions:
if c in data2:
data2[c] = np.multiply(data2[c], conversions[c])
data2[c] = np.multiply(data2[c], float(conversions[c]))

return data2

Expand Down