Skip to content

Commit

Permalink
Merge pull request #239 from wright-group/development
Browse files Browse the repository at this point in the history
2.13.7
  • Loading branch information
untzag committed Sep 6, 2017
2 parents 039507d + 200eff7 commit 1eae4ed
Show file tree
Hide file tree
Showing 37 changed files with 10,481 additions and 195 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -0,0 +1,3 @@
# Require review from one maintainer for pushes to Development and Master

* @untzag @ksunden
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -23,4 +23,8 @@ install:
- conda create -n wrighttools --file requirements.txt
- source activate wrighttools
- python setup.py install
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script: python setup.py test
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.13.6
2.13.7
11 changes: 1 addition & 10 deletions WrightTools/__init__.py
Expand Up @@ -10,16 +10,6 @@
import matplotlib as _matplotlib


# --- temp directory ------------------------------------------------------------------------------


_here = _os.path.abspath(_os.path.dirname(__file__))

_temp_dir = _os.path.join(_here, 'temp')
if not _os.path.isdir(_temp_dir):
_os.mkdir(_temp_dir)


# --- import --------------------------------------------------------------------------------------


Expand All @@ -38,6 +28,7 @@


# read from VERSION file
_here = _os.path.abspath(_os.path.dirname(__file__))
with open(_os.path.join(_os.path.dirname(_here), 'VERSION')) as _version_file:
__version__ = _version_file.read().strip()

Expand Down
121 changes: 50 additions & 71 deletions WrightTools/artists.py
Expand Up @@ -30,6 +30,8 @@
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.patheffects as PathEffects

import imageio

from . import kit as wt_kit


Expand Down Expand Up @@ -121,7 +123,8 @@ def contourf(self, *args, **kwargs):
contours = matplotlib.axes.Axes.contourf(self, *args, **kwargs) # why can't I use super?
# fill lines
zorder = contours.collections[0].zorder - 0.1
matplotlib.axes.Axes.contour(self, *(args[:3] + [len(contours.levels)]),
levels = (contours.levels[1:] + contours.levels[:-1]) / 2
matplotlib.axes.Axes.contour(self, *args[:3], levels=levels,
cmap=contours.cmap,
zorder=zorder)
# PathCollection modifications
Expand Down Expand Up @@ -198,10 +201,10 @@ def plot_data(self, data, channel=0, interpolate=False, coloring=None,
xaxis = data.axes[0]
# get min
if min is None:
min = channel.min
min = channel.min()
# get max
if max is None:
max = channel.max
max = channel.max()
# 1D --------------------------------------------------------------------------------------
if data.dimensionality == 1:
# get list of all datas
Expand Down Expand Up @@ -1311,14 +1314,13 @@ def plot_gridlines(ax=None, c='grey', lw=1, diagonal=False, zorder=2,
# grid
# ax.grid(True)
lines = ax.xaxis.get_gridlines() + ax.yaxis.get_gridlines()
for l in lines.copy():
l = l
l.set_linestyle(':')
l.set_color(c)
l.set_linewidth(lw)
l.set_zorder(zorder)
l.set_dashes(dashes)
ax.add_line(l)
for line in lines.copy():
line.set_linestyle(':')
line.set_color(c)
line.set_linewidth(lw)
line.set_zorder(zorder)
line.set_dashes(dashes)
ax.add_line(line)
# diagonal
if diagonal:
min_xi, max_xi = ax.get_xlim()
Expand Down Expand Up @@ -1421,12 +1423,6 @@ def stitch_to_animation(images, outpath=None, duration=0.5, palettesize=256,
verbose : bool (optional)
Toggle talkback. Default is True.
"""
# import imageio
try:
import imageio
except ImportError:
raise ImportError(
'WrightTools.artists.stitch_to_animation requires imageio - https://imageio.github.io/')
# parse filename
if outpath is None:
outpath = os.path.splitext(images[0])[0] + '.gif'
Expand Down Expand Up @@ -1707,7 +1703,7 @@ def plot(self, channel=0, local=False, autosave=False, output_folder=None,
if local:
pass
else:
plt.ylim(channels[channel_index].min, channels[channel_index].max)
plt.ylim(channels[channel_index].min(), channels[channel_index].max())
# label axes
plt.xlabel(axes[0].get_label(), fontsize=18)
plt.ylabel(channels[channel_index].name, fontsize=18)
Expand Down Expand Up @@ -1905,7 +1901,7 @@ def plot(self, channel=0,
output_folder : str (optional)
Output folder.
fname : str (optional)
File name.
File name. If None, data name is used. Default is None.
verbose : bool (optional)
Toggle talkback. Default is True.
"""
Expand All @@ -1916,6 +1912,11 @@ def plot(self, channel=0,
channel_index = self.chopped[0].channel_names.index(channel)
else:
print('channel type not recognized in mpl_2D!')
# get fname
if fname:
pass
else:
fname = self.data.name
# prepare figure
fig = None
if len(self.chopped) > 10:
Expand All @@ -1929,10 +1930,6 @@ def plot(self, channel=0,
else:
if len(self.chopped) == 1:
output_folder = os.getcwd()
if fname:
pass
else:
fname = self.data.name
else:
folder_name = 'mpl_2D ' + wt_kit.get_timestamp(style='short')
os.mkdir(folder_name)
Expand All @@ -1954,24 +1951,22 @@ def plot(self, channel=0,
if normalize_slices == 'both':
pass
elif normalize_slices == 'horizontal':
nmin = channel.null
nmin = channel.null()
# normalize all x traces to a common value
maxes = zi.max(axis=1)
numerator = (zi - nmin)
denominator = (maxes - nmin)
for j in range(zi.shape[0]):
zi[j] = numerator[j] / denominator[j]
channel.max = zi.max()
channel.min = zi.min()
channel.null = 0
channel._null = 0
elif normalize_slices == 'vertical':
nmin = channel.null
nmin = channel.null()
maxes = zi.max(axis=0)
numerator = (zi - nmin)
denominator = (maxes - nmin)
for j in range(zi.shape[1]):
zi[:, j] = numerator[:, j] / denominator[j]
channel.null = 0
channel._null = 0
# create figure -----------------------------------------------------------------------
if fig and autosave:
plt.close(fig)
Expand Down Expand Up @@ -2003,27 +1998,27 @@ def plot(self, channel=0,
if channel.signed:
if local:
print('signed local')
limit = max(abs(channel.null - np.nanmin(zi)),
abs(channel.null - np.nanmax(zi)))
limit = max(abs(channel.null() - np.nanmin(zi)),
abs(channel.null() - np.nanmax(zi)))
else:
if dynamic_range:
limit = min(abs(channel.null - channel.min),
abs(channel.null - channel.max))
limit = min(abs(channel.null() - channel.min()),
abs(channel.null() - channel.max()))
else:
limit = channel.mag
limit = channel.mag()
if np.isnan(limit):
limit = 1.
if limit is np.ma.masked:
limit = 1.
levels = np.linspace(-limit + channel.null, limit + channel.null, 200)
levels = np.linspace(-limit + channel.null(), limit + channel.null(), 200)
else:
if local:
levels = np.linspace(channel.null, np.nanmax(zi), 200)
levels = np.linspace(channel.null(), np.nanmax(zi), 200)
else:
if channel.max < channel.null:
levels = np.linspace(channel.min, channel.null, 200)
if channel.max() < channel.null():
levels = np.linspace(channel.min(), channel.null(), 200)
else:
levels = np.linspace(channel.null, channel.max, 200)
levels = np.linspace(channel.null(), channel.max(), 200)
# main plot ---------------------------------------------------------------------------
# get colormap
if cmap == 'automatic':
Expand Down Expand Up @@ -2099,7 +2094,7 @@ def plot(self, channel=0,
# force top and bottom contour to be just outside of data range
# add two contours
contours_levels = np.linspace(
channel.null - 1e-10, np.nanmax(zi) + 1e-10, contours + 2)
channel.null() - 1e-10, np.nanmax(zi) + 1e-10, contours + 2)
else:
contours_levels = contours
if contour_thickness is None:
Expand Down Expand Up @@ -2131,7 +2126,7 @@ def plot(self, channel=0,
axCorrx.set_ylim([0, 1.1])
# bin
if xbin:
x_ax_int = np.nansum(zi, axis=0) - channel.null * len(self.yaxis.points)
x_ax_int = np.nansum(zi, axis=0) - channel.null() * len(self.yaxis.points)
x_ax_int[x_ax_int == 0] = np.nan
# normalize (min is a pixel)
xmax = max(np.abs(x_ax_int))
Expand Down Expand Up @@ -2170,7 +2165,7 @@ def plot(self, channel=0,
axCorry.set_xlim([0, 1.1])
# bin
if ybin:
y_ax_int = np.nansum(zi, axis=1) - channel.null * len(self.xaxis.points)
y_ax_int = np.nansum(zi, axis=1) - channel.null() * len(self.xaxis.points)
y_ax_int[y_ax_int == 0] = np.nan
# normalize (min is a pixel)
ymax = max(np.abs(y_ax_int))
Expand Down Expand Up @@ -2443,22 +2438,6 @@ def plot(self, channel_index=0,
subplot_main = plt.subplot(gs[0])
subplot_main.patch.set_facecolor(facecolor)
# levels ------------------------------------------------------------------------------
"""
if channel.signed:
if dynamic_range:
limit = min(abs(channel.null - channel.min), abs(channel.null - channel.max))
else:
limit = max(abs(channel.null - channel.min), abs(channel.null - channel.max))
levels = np.linspace(-limit + channel.null, limit + channel.null, 200)
else:
if local:
levels = np.linspace(channel.null, zi.max(), 200)
else:
levels = np.linspace(channel.null, channel.max, 200)
"""
levels = np.linspace(0, 1, 200)
# main plot ---------------------------------------------------------------------------
# get colormap
Expand Down Expand Up @@ -2513,7 +2492,7 @@ def plot(self, channel_index=0,
# force top and bottom contour to be just outside of data range
# add two contours
contours_levels = np.linspace(
channel.null - 1e-10, np.nanmax(zi) + 1e-10, contours + 2)
channel.null() - 1e-10, np.nanmax(zi) + 1e-10, contours + 2)
else:
contours_levels = contours
plt.contour(xaxis.points, yaxis.points, zi,
Expand Down Expand Up @@ -2735,11 +2714,11 @@ def plot(self, channel=0, output_path=None, w1w2=True, w1_wigner=True,
for data_index in range(len(self.datas)):
data = self.chopped_datas[data_index][slice_index]
if self.data_signed:
global_limits = [self.datas[data_index].channels[channel_index].min,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].min(),
self.datas[data_index].channels[channel_index].max()]
else:
global_limits = [self.datas[data_index].channels[channel_index].null,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].null(),
self.datas[data_index].channels[channel_index].max()]
axs, spss = self._fill_row(
data, channel_index, gs, data_index, global_limits)
if not data_index == len(self.datas) - 1:
Expand All @@ -2761,11 +2740,11 @@ def plot(self, channel=0, output_path=None, w1w2=True, w1_wigner=True,
for data_index in range(len(self.datas)):
data = self.chopped_datas[data_index][slice_index]
if self.data_signed:
global_limits = [self.datas[data_index].channels[channel_index].min,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].min(),
self.datas[data_index].channels[channel_index].max()]
else:
global_limits = [self.datas[data_index].channels[channel_index].null,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].null(),
self.datas[data_index].channels[channel_index].max()]
axs, spss = self._fill_row(
data, channel_index, gs, data_index, global_limits)
if not data_index == len(self.datas) - 1:
Expand All @@ -2792,11 +2771,11 @@ def plot(self, channel=0, output_path=None, w1w2=True, w1_wigner=True,
for data_index in range(len(self.datas)):
data = self.chopped_datas[data_index][slice_index]
if self.data_signed:
global_limits = [self.datas[data_index].channels[channel_index].min,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].min(),
self.datas[data_index].channels[channel_index].max()]
else:
global_limits = [self.datas[data_index].channels[channel_index].null,
self.datas[data_index].channels[channel_index].max]
global_limits = [self.datas[data_index].channels[channel_index].null(),
self.datas[data_index].channels[channel_index].max()]
axs, spss = self._fill_row(
data, channel_index, gs, data_index, global_limits)
if not data_index == len(self.datas) - 1:
Expand Down
2 changes: 1 addition & 1 deletion WrightTools/calibration.py
Expand Up @@ -200,7 +200,7 @@ def map_points(self, points, units='same'):
# convert new points to local units
if units == 'same':
units = self.control_units
new_points = sorted(wt_units.converter(new_points, units, self.control_units))
new_points = np.sort(wt_units.converter(new_points, units, self.control_units))
new_values = self.get_offset(new_points)
# finish
self.points = new_points
Expand Down

0 comments on commit 1eae4ed

Please sign in to comment.