Skip to content

Commit

Permalink
Merge pull request #58 from JuDFTteam/release-0.4.10
Browse files Browse the repository at this point in the history
Release 0.4.10
  • Loading branch information
janssenhenning authored Jul 5, 2021
2 parents 1334d48 + c3e5971 commit 3083e19
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.9
current_version = 0.4.10
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion masci_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
'''
import logging

__version__ = '0.4.9'
__version__ = '0.4.10'

logging.getLogger(__name__).addHandler(logging.NullHandler())
3 changes: 2 additions & 1 deletion masci_tools/tools/greensfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def _read_element_header(hdffile, index):
onsite = element.attrs['l_onsite'][0] == 1
contour = element.attrs['iContour'][0]
atomDiff = np.array(element.attrs['atomDiff'])
atomDiff[abs(atomDiff) < 1e-12] = 0.0
nLO = element.attrs['numLOs'][0]

return GreensfElement(l, lp, atomType, atomTypep, sphavg, onsite, contour, nLO, atomDiff)
Expand Down Expand Up @@ -431,7 +432,7 @@ def printElements(elements, index=None, mark=None):
atomdiff_str = np.array2string(element.atomDiff,
precision=2,
separator=',',
suppress_small=False,
suppress_small=True,
sign=' ',
floatmode='fixed')
print(
Expand Down
18 changes: 10 additions & 8 deletions masci_tools/vis/bokeh_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,11 @@ def bokeh_dos(dosdata,

if 'limits' in kwargs:
limits = kwargs.pop('limits')
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
if 'x' not in limits and 'y' not in limits:
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
kwargs['limits'] = {k: v for k, v in limits.items() if v is not None}

lines = {'horizontal': 0}
Expand Down Expand Up @@ -475,10 +476,11 @@ def bokeh_spinpol_dos(dosdata,

if 'limits' in kwargs:
limits = kwargs.pop('limits')
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
if 'x' not in limits and 'y' not in limits:
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
kwargs['limits'] = {k: v for k, v in limits.items() if v is not None}

lines = {'horizontal': 0}
Expand Down
11 changes: 9 additions & 2 deletions masci_tools/vis/bokeh_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ def __init__(self, **kwargs):
key_descriptions=self._BOKEH_DESCRIPTIONS,
**kwargs)

def plot_kwargs(self, ignore=None, extra_keys=None, plot_type='default', post_process=True, **kwargs):
def plot_kwargs(self,
ignore=None,
extra_keys=None,
plot_type='default',
post_process=True,
list_of_dicts=True,
**kwargs):
"""
Creates a dict or list of dicts (for multiple plots) with the defined parameters
for the plotting calls fo matplotlib
Expand Down Expand Up @@ -269,7 +275,8 @@ def plot_kwargs(self, ignore=None, extra_keys=None, plot_type='default', post_pr
if 'marker_size' in plot_kwargs:
plot_kwargs['size'] = plot_kwargs.pop('marker_size')

plot_kwargs = self.dict_of_lists_to_list_of_dicts(plot_kwargs, self.single_plot, self.num_plots)
if list_of_dicts:
plot_kwargs = self.dict_of_lists_to_list_of_dicts(plot_kwargs, self.single_plot, self.num_plots)

return plot_kwargs

Expand Down
16 changes: 14 additions & 2 deletions masci_tools/vis/fleur.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def plot_fleur_dos(dosdata,
recipe from :py:mod:`~masci_tools.io.parsers.hdf5.recipes` or something
producing equivalent data
The limits for the axes can be specified either with ``x`` and ``y`` or
``energy`` and ``dos``. Mixing the two options is not possible
:param dosdata: dataset dict produced by the `FleurDOS` recipe
:param attributes: attributes dict produced by the `FleurDOS` recipe
:param spinpol: bool, if True (default) use the plot for spin-polarized dos if the data is spin-polarized
Expand Down Expand Up @@ -363,7 +366,7 @@ def plot_fleur_dos(dosdata,
#Select the keys
legend_labels, keys = np.array(legend_labels)[key_mask].tolist(), np.array(keys)[key_mask].tolist()

kwargs = _process_dos_kwargs(keys, **kwargs)
kwargs = _process_dos_kwargs(keys, bokeh_plot=bokeh_plot, **kwargs)

if bokeh_plot:
if spinpol:
Expand All @@ -385,7 +388,7 @@ def plot_fleur_dos(dosdata,
return fig


def _process_dos_kwargs(ordered_keys, **kwargs):
def _process_dos_kwargs(ordered_keys, bokeh_plot=False, **kwargs):
"""
Convert any kwarg in dict form with str keys to the correct dict with integer index
for the plotting functions.
Expand All @@ -394,8 +397,17 @@ def _process_dos_kwargs(ordered_keys, **kwargs):
:returns: kwargs with the dicts converted to integer indexed dicts
"""
from .matplotlib_plotter import MatplotlibPlotter
from .bokeh_plotter import BokehPlotter

if bokeh_plot:
params = BokehPlotter()
else:
params = MatplotlibPlotter()

for key, value in kwargs.items():
if params.is_general(key):
continue
if isinstance(value, dict):
new_dict = value.copy()
for plot_label, val in value.items():
Expand Down
20 changes: 17 additions & 3 deletions masci_tools/vis/matplotlib_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,13 @@ def __init__(self, **kwargs):
key_descriptions=self._MATPLOTLIB_DESCRIPTIONS,
**kwargs)

def plot_kwargs(self, ignore=None, extra_keys=None, plot_type='default', post_process=True, **kwargs):
def plot_kwargs(self,
ignore=None,
extra_keys=None,
plot_type='default',
post_process=True,
list_of_dicts=True,
**kwargs):
"""
Creates a dict or list of dicts (for multiple plots) with the defined parameters
for the plotting calls fo matplotlib
Expand Down Expand Up @@ -394,9 +400,17 @@ def plot_kwargs(self, ignore=None, extra_keys=None, plot_type='default', post_pr

plot_kwargs['cmap'] = self.truncate_colormap(plot_kwargs['cmap'], *self['sub_colormap'])

plot_kwargs = self.dict_of_lists_to_list_of_dicts(plot_kwargs, self.single_plot, self.num_plots)
if list_of_dicts:
plot_kwargs = self.dict_of_lists_to_list_of_dicts(plot_kwargs, self.single_plot, self.num_plots)

if not self.single_plot:
if not list_of_dicts and 'label' in plot_kwargs:
label = plot_kwargs.pop('label')
if isinstance(label, list):
plot_kwargs['label'] = [value if value is not None else '' for value in label]
else:
plot_kwargs['label'] = label if label is not None else ''

if not self.single_plot and list_of_dicts:
for index, value in enumerate(plot_kwargs):
if self[('area_plot', index)]:
value.pop('marker', None)
Expand Down
28 changes: 25 additions & 3 deletions masci_tools/vis/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,21 @@ def _generate_plot_parameters_table(defaults, descriptions):
value = f'``{value}``'

descr = descriptions.get(key, 'No Description available')
descr = descr.replace('{',' ``{')
descr = descr.replace('}','}`` ')

table.extend([f' * - ``{key}``',
f' - {descr}',
f' - {value}'])
f' - {descr}'])

if not isinstance(value, dict):
table.append(f' - {value}')
else:
string_value = [f"'{key}': {val}," for key, val in value.items()]
string_value[0] = '{' + string_value[0]
string_value[-1] = string_value[-1].rstrip(',') + '}'

table.extend([' - .. code-block::', ''] + \
[f' {string}' for string in string_value])

table.append('')
#yapf: enable
Expand Down Expand Up @@ -387,7 +398,7 @@ def __setitem__(self, key, value):
if key not in self._params:
raise KeyError(f'Unknown parameter: {key}')

if key not in self._GENERAL_KEYS:
if not self.is_general(key):
value = self.convert_to_complete_list(value,
self.single_plot,
self.num_plots,
Expand Down Expand Up @@ -582,6 +593,17 @@ def get_description(self, key):
else:
warnings.warn(f'{key} is not a known parameter')

def is_general(self, key):
"""
Return, whether the key is general
(meaning only related to the whole plots)
:param key: str of the key to check
:returns: bool, whether the key is general
"""
return key in self._GENERAL_KEYS

@property
def _hardcoded_defaults(self):
"""
Expand Down
32 changes: 20 additions & 12 deletions masci_tools/vis/plot_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ def histogram(xdata,
If the arguments are not recognized they are passed on to the matplotlib function `hist`
"""

if not isinstance(xdata[0], (list, np.ndarray, pd.Series)):
xdata = [xdata]

plot_params.single_plot = False
plot_params.num_plots = len(xdata)

if 'label' in kwargs:
warnings.warn('Please use plot_label instead of label', DeprecationWarning)
kwargs['plot_label'] = kwargs.pop('label')
Expand Down Expand Up @@ -804,7 +810,7 @@ def histogram(xdata,

ax = plot_params.prepare_plot(title=title, xlabel=xlabel, ylabel=ylabel, axis=axis, minor=True)

plot_kwargs = plot_params.plot_kwargs(plot_type='histogram')
plot_kwargs = plot_params.plot_kwargs(plot_type='histogram', list_of_dicts=False)
n, bins, patches = ax.hist(xdata,
density=density,
histtype=histtype,
Expand Down Expand Up @@ -1538,9 +1544,9 @@ def plot_lattice_constant(scaling,
with NestedPlotParameters(plot_params):
ax = single_scatterplot(scaling,
fit_y,
xlabel,
ylabel,
title,
xlabel=xlabel,
ylabel=ylabel,
title=title,
axis=ax,
show=False,
save_plots=False,
Expand Down Expand Up @@ -1595,10 +1601,11 @@ def plot_dos(energy_grid,

if 'limits' in kwargs:
limits = kwargs.pop('limits')
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
if 'x' not in limits and 'y' not in limits:
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
kwargs['limits'] = {k: v for k, v in limits.items() if v is not None}

lines = {'horizontal': 0}
Expand Down Expand Up @@ -1668,10 +1675,11 @@ def plot_spinpol_dos(energy_grid,

if 'limits' in kwargs:
limits = kwargs.pop('limits')
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
if 'x' not in limits and 'y' not in limits:
if xyswitch:
limits['x'], limits['y'] = limits.pop('dos', None), limits.pop('energy', None)
else:
limits['x'], limits['y'] = limits.pop('energy', None), limits.pop('dos', None)
kwargs['limits'] = {k: v for k, v in limits.items() if v is not None}

if isinstance(spin_up_data[0], (list, np.ndarray)):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]

[tool.poetry]
name = "masci_tools"
version = "0.4.9"
version = "0.4.10"
description = "Tools for Materials science. Vis contains wrapers of matplotlib functionality to visualalize common material science data. Plus wrapers of visualisation for aiida-fleur workflow nodes"
readme = "README.md"
authors = ["Jens Bröder <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if __name__ == '__main__':
setup(
name='masci_tools',
version='0.4.9',
version='0.4.10',
description='Tools for Materials science. Vis contains wrappers of matplotlib functionality to visualize common material science data. Plus wrappers of visualisation for aiida-fleur workflow nodes',
# add long_description from readme.md:
long_description = long_description, # add contents of README.md
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions tests/test_fleur_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@ def test_plot_dos_param_change_by_label_mpl():
return gcf()


@pytest.mark.mpl_image_compare(baseline_dir='files/fleur_vis/', filename='dos_param_by_label_with_general_params.png')
def test_plot_dos_param_change_by_label_general_dicts_mpl():
from masci_tools.io.parsers.hdf5 import HDF5Reader
from masci_tools.io.parsers.hdf5.recipes import FleurDOS
from masci_tools.vis.fleur import plot_fleur_dos

TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_dos.hdf')

with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
data, attributes = h5reader.read(recipe=FleurDOS)

gcf().clear()

plot_fleur_dos(data,
attributes,
show=False,
color={'MT:1_up': 'red'},
linewidth={'Total_up': 6},
limits={'energy': (-5, 5)},
lines={'vertical': [-1, 0, 1]})

return gcf()


@pytest.mark.mpl_image_compare(baseline_dir='files/fleur_vis/', filename='spinpol_dos_defaults.png')
def test_plot_spinpol_dos_defaults_mpl():
from masci_tools.io.parsers.hdf5 import HDF5Reader
Expand Down
51 changes: 51 additions & 0 deletions tests/test_plot_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,57 @@ def test_param_change(self):
# need to return the figure in order for mpl checks to work
return gcf()

@pytest.mark.mpl_image_compare(baseline_dir='files/plot_methods/matplotlib/histogram/', filename='stacked.png')
def test_defaults_stacked(self):
"""
Test of histogram plot with default values
"""
import numpy as np
from masci_tools.vis.plot_methods import histogram

np.random.seed(19680801)
N_points = 10000

# Generate a normal distribution, center at x=0 and y=5
x = np.random.randn(N_points)
x2 = np.random.randn(N_points)

gcf().clear()

histogram([x, x2], show=False, histtype='barstacked')

# need to return the figure in order for mpl checks to work
return gcf()

@pytest.mark.mpl_image_compare(baseline_dir='files/plot_methods/matplotlib/histogram/',
filename='stacked_param_change.png')
def test_param_changed_stacked(self):
"""
Test of histogram plot with default values
"""
import numpy as np
from masci_tools.vis.plot_methods import histogram

np.random.seed(19680801)
N_points = 10000

# Generate a normal distribution, center at x=0 and y=5
x = np.random.randn(N_points)
x2 = np.random.randn(N_points)

gcf().clear()

histogram([x, x2],
color=['darkblue', 'darkred'],
histtype='barstacked',
linewidth=2,
legend=True,
plot_label={1: 'This is on top'},
show=False)

# need to return the figure in order for mpl checks to work
return gcf()


class TestBarchartPlot(object): #pylint: disable=missing-class-docstring

Expand Down

0 comments on commit 3083e19

Please sign in to comment.