Skip to content

Commit

Permalink
Version 3.1.1
Browse files Browse the repository at this point in the history
3.1.1
  • Loading branch information
ksunden committed Aug 3, 2018
2 parents c34013f + deda738 commit 316646d
Show file tree
Hide file tree
Showing 41 changed files with 6,352 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
__pycache__/
*.py[cod]

# direnv
*.envrc

# distribution / packaging
.Python
env/
Expand Down
4 changes: 4 additions & 0 deletions readthedocs.yml → .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
requirements_file: requirements.txt

build:
image: latest

python:
version: 3.6
pip_install: true
extra_requirements: [docs]

Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ addons:
apt:
packages:
- libfreetype6-dev
- hdf5-tools
- libhdf5-dev
- libopenblas-dev
install:
- python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion WrightTools/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.1.1
29 changes: 29 additions & 0 deletions WrightTools/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# --- import --------------------------------------------------------------------------------------


import WrightTools as wt
import argparse


# --- define --------------------------------------------------------------------------------------


def wt_tree():
parser = argparse.ArgumentParser(description="Print a given data tree.")

# Add arguments
parser.add_argument("path", type=str)
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose? False by default")
parser.add_argument("--depth", "-d", "-L", type=int, default=9, help="depth to print (int)")
parser.add_argument("internal_path", nargs="?", default="/")
args = parser.parse_args()

# Create the data/collection object
obj = wt.open(args.path, edit_local=True)[args.internal_path]

# Print the tree
# If the object is a data object, it doesn't take depth as a parameter
if isinstance(obj, wt.Data):
obj.print_tree(verbose=args.verbose)
else:
obj.print_tree(verbose=args.verbose, depth=args.depth)
1 change: 1 addition & 0 deletions WrightTools/artists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from ._colors import *
from ._helpers import *
from ._quick import *
from ._interact import *
144 changes: 94 additions & 50 deletions WrightTools/artists/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,67 @@ def _parse_limits(self, zi=None, data=None, channel_index=None, dynamic_range=Fa
else:
vmin = data.channels[channel_index].null
vmax = data.channels[channel_index].max()
# don't overwrite
if "vmin" not in kwargs.keys():
kwargs["vmin"] = vmin
if "vmax" not in kwargs.keys():
kwargs["vmax"] = vmax
# don't overwrite
if "vmin" not in kwargs.keys():
kwargs["vmin"] = vmin
if "vmax" not in kwargs.keys():
kwargs["vmax"] = vmax
return kwargs

def _parse_plot_args(self, *args, **kwargs):
plot_type = kwargs.pop("plot_type")
if plot_type not in ["pcolor", "pcolormesh"]:
raise NotImplementedError
args = list(args) # offer pop, append etc
dynamic_range = kwargs.pop("dynamic_range", False)
if isinstance(args[0], Data):
data = args.pop(0)
if plot_type in ["pcolor", "pcolormesh"]:
ndim = 2
if not data.ndim == ndim:
raise wt_exceptions.DimensionalityError(ndim, data.ndim)
# arrays
channel = kwargs.pop("channel", 0)
channel_index = wt_kit.get_index(data.channel_names, channel)
zi = data.channels[channel_index][:]
xi = data.axes[0].full
yi = data.axes[1].full
if plot_type in ["pcolor", "pcolormesh"]:
X, Y = pcolor_helper(xi, yi)
else:
X, Y = xi, yi
args = [X, Y, zi] + args
# limits
kwargs = self._parse_limits(
data=data, channel_index=channel_index, dynamic_range=dynamic_range, **kwargs
)
# cmap
kwargs = self._parse_cmap(data=data, channel_index=channel_index, **kwargs)
else:
xi, yi, zi = args[:3]
if plot_type in ["pcolor", "pcolormesh"]:
# only apply pcolor_helper if it looks like it hasn't been applied
if (xi.ndim == 1 and xi.size == zi.shape[1]) or (
xi.ndim == 2 and xi.shape == zi.shape
):
xi, yi = pcolor_helper(xi, yi)
args[:3] = [xi.T.copy(), yi.T.copy(), zi]
data = None
channel_index = 0
kwargs = self._parse_limits(zi=args[2], **kwargs)
kwargs = self._parse_cmap(**kwargs)
# labels
self._apply_labels(
autolabel=kwargs.pop("autolabel", False),
xlabel=kwargs.pop("xlabel", None),
ylabel=kwargs.pop("ylabel", None),
data=data,
channel_index=channel_index,
)
# decoration
self.set_facecolor([0.75] * 3)
return args, kwargs

def add_sideplot(self, along, pad=0, height=0.75, ymin=0, ymax=1.1):
"""Add a side axis.
Expand Down Expand Up @@ -210,9 +264,6 @@ def contour(self, *args, **kwargs):
channel_index=channel_index,
)
else:
data = None
channel_index = 0
signed = False
kwargs = self._parse_limits(zi=args[2], dynamic_range=dynamic_range, **kwargs)
# call parent
return super().contour(*args, **kwargs)
Expand Down Expand Up @@ -362,50 +413,43 @@ def pcolor(self, *args, **kwargs):
-------
matplotlib.collections.PolyCollection
"""
args = list(args) # offer pop, append etc
channel = kwargs.pop("channel", 0)
dynamic_range = kwargs.pop("dynamic_range", False)
# unpack data object, if given
if isinstance(args[0], Data):
data = args.pop(0)
if not data.ndim == 2:
raise wt_exceptions.DimensionalityError(2, data.ndim)
# arrays
channel_index = wt_kit.get_index(data.channel_names, channel)
xi = data.axes[0].full
yi = data.axes[1].full
zi = data.channels[channel_index][:]
X, Y, Z = pcolor_helper(xi, yi, zi)
args = [X, Y, Z] + args
# limits
kwargs = self._parse_limits(
data=data, channel_index=channel_index, dynamic_range=dynamic_range, **kwargs
)
# cmap
kwargs = self._parse_cmap(data=data, channel_index=channel_index, **kwargs)
else:
xi, yi, zi = args[:3]
if xi.ndim == 1 and xi.size == zi.shape[1]:
xi, yi, zi = pcolor_helper(xi, yi, zi)
elif xi.ndim == 2 and xi.shape == zi.shape:
xi, yi, zi = pcolor_helper(xi, yi, zi)
data = None
channel_index = 0
kwargs = self._parse_limits(zi=args[2], **kwargs)
kwargs = self._parse_cmap(**kwargs)
# labels
self._apply_labels(
autolabel=kwargs.pop("autolabel", False),
xlabel=kwargs.pop("xlabel", None),
ylabel=kwargs.pop("ylabel", None),
data=data,
channel_index=channel_index,
)
# decoration
self.set_facecolor([0.75] * 3)
# call parent
args, kwargs = self._parse_plot_args(*args, **kwargs, plot_type="pcolor")
return super().pcolor(*args, **kwargs)

def pcolormesh(self, *args, **kwargs):
"""Create a pseudocolor plot of a 2-D array.
Uses pcolor_helper to ensure that color boundaries are drawn
bisecting point positions, when possible.
Quicker than pcolor
Parameters
----------
data : 2D WrightTools.data.Data object
Data to plot.
channel : int or string (optional)
Channel index or name. Default is 0.
dynamic_range : boolean (optional)
Force plotting of all contours, overloading for major extent. Only applies to signed
data. Default is False.
autolabel : {'none', 'both', 'x', 'y'} (optional)
Parameterize application of labels directly from data object. Default is none.
xlabel : string (optional)
xlabel. Default is None.
ylabel : string (optional)
ylabel. Default is None.
**kwargs
matplotlib.axes.Axes.pcolormesh__ optional keyword arguments.
__ https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html
Returns
-------
matplotlib.collections.QuadMesh
"""
args, kwargs = self._parse_plot_args(*args, **kwargs, plot_type="pcolormesh")
return super().pcolormesh(*args, **kwargs)

def plot(self, *args, **kwargs):
"""Plot lines and/or markers.
Expand Down
2 changes: 1 addition & 1 deletion WrightTools/artists/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def make_colormap(seq, name="CustomMap", plot=False):
name : string (optional)
A name for the colormap
plot : boolean (optional)
Use to generate a plot of the colormap (Defalut is False).
Use to generate a plot of the colormap (Default is False).
Returns
-------
Expand Down
47 changes: 27 additions & 20 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


import os
import sys

import numpy as np

Expand All @@ -17,7 +16,9 @@
from mpl_toolkits.axes_grid1 import make_axes_locatable

import imageio
import warnings

from .. import exceptions as wt_exceptions
from .. import kit as wt_kit
from ._base import Figure, GridSpec
from ._colors import colormaps
Expand Down Expand Up @@ -147,8 +148,10 @@ def add_sideplot(
# beautify
if along == "x":
axCorr.set_ylim(ymin, ymax)
axCorr.tick_params(axis="x", which="both", length=0)
elif along == "y":
axCorr.set_xlim(ymin, ymax)
axCorr.tick_params(axis="y", which="both", length=0)
plt.grid(grid)
if zero_line:
if along == "x":
Expand Down Expand Up @@ -485,7 +488,7 @@ def get_scaled_bounds(ax, position, *, distance=0.1, factor=200):
return [h_scaled, v_scaled], [va, ha]


def pcolor_helper(xi, yi, zi):
def pcolor_helper(xi, yi, zi=None):
"""Prepare a set of arrays for plotting using `pcolor`.
The return values are suitable for feeding directly into ``matplotlib.pcolor``
Expand All @@ -497,28 +500,27 @@ def pcolor_helper(xi, yi, zi):
Array of X-coordinates.
yi : 1D or 2D array-like
Array of Y-coordinates.
zi : 2D array-like
Rectangular array of Z-coordinates.
zi : 2D array (optional, deprecated)
If zi is not None, it is returned unchanged in the output.
Returns
-------
X : 2D ndarray
X dimension for pcolor
Y : 2D ndarray
Y dimension for pcolor
Z : 2D ndarray
Z dimension for pcolor
zi : 2D ndarray
if zi parameter is not None, returns zi parameter unchanged
"""
xi = xi.copy()
yi = yi.copy()
zi = zi.copy()
if xi.ndim == 1:
xi.shape = (xi.size, 1)
if yi.ndim == 1:
yi.shape = (1, yi.size)
shape = wt_kit.joint_shape(xi, yi)
# full

# full
def full(arr):
for i in range(arr.ndim):
if arr.shape[i] == 1:
Expand Down Expand Up @@ -546,7 +548,14 @@ def full(arr):
ll = orig[idx[0] + 0, idx[1] + 0]
lr = orig[idx[0] + 0, idx[1] + 1]
out[idx] = np.mean([ul, ur, ll, lr])
return X, Y, zi
if zi is not None:
warnings.warn(
"zi argument is not used in pcolor_helper and is not required",
wt_exceptions.VisibleDeprecationWarning,
)
return X, Y, zi.copy()
else:
return X, Y


def plot_colorbar(
Expand Down Expand Up @@ -634,6 +643,8 @@ def plot_colorbar(
# parse clim
if vlim is None:
vlim = clim
if max(vlim) == min(vlim):
vlim[-1] += 1e-1
# parse format
if isinstance(decimals, int):
format = "%.{0}f".format(decimals)
Expand Down Expand Up @@ -1011,17 +1022,13 @@ def stitch_to_animation(images, outpath=None, *, duration=0.5, palettesize=256,
if outpath is None:
outpath = os.path.splitext(images[0])[0] + ".gif"
# write
try:
t = wt_kit.Timer(verbose=False)
with t, imageio.get_writer(
outpath, mode="I", duration=duration, palettesize=palettesize
) as writer:
for p in images:
image = imageio.imread(p)
writer.append_data(image)
except BaseException:
print("Error: {0}".format(sys.exc_info()[0]))
return None
t = wt_kit.Timer(verbose=False)
with t, imageio.get_writer(
outpath, mode="I", duration=duration, palettesize=palettesize
) as writer:
for p in images:
image = imageio.imread(p)
writer.append_data(image)
# finish
if verbose:
interval = np.round(t.interval, 2)
Expand Down

0 comments on commit 316646d

Please sign in to comment.