Skip to content

Commit

Permalink
Merge branch 'master' into adding_signed
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkohler authored Jan 30, 2024
2 parents 89e5b60 + f772f2c commit a08572d
Show file tree
Hide file tree
Showing 122 changed files with 190 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1 # Replace by any tag/version: https://github.com/psf/black/tags
rev: 24.1.1 # Replace by any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
Expand Down
18 changes: 13 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
requirements_file: requirements.txt
version: 2

build:
image: latest
os: ubuntu-22.04
tools:
python: "3.9"

python:
version: 3.8
pip_install: true
extra_requirements: [docs]
install:
- method: pip
path: .
extra_requirements:
- docs

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

formats:
- epub
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Added
- `kit.guess_signed` for empirically guessing channel sign (useful for automated workflows)
- `Data.squeeze`: squeezing the data object to the shape of the axes.

### Fixed
- `interact2D`: fixed bug where use_imshow broke the sliders
- `artists.stitch_to_animation`: use imageio v3 api and declare pillow plugin
- `data.join` ensures valid `method` is selected

### Changed
- `data.join` no longer supports `sum` method

## [3.5.0]

Expand Down
1 change: 1 addition & 0 deletions WrightTools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""WrightTools init."""

# flake8: noqa


Expand Down
1 change: 0 additions & 1 deletion WrightTools/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Define WrightTools version."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/__wt5_version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Define wt5 version."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/_close.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Function to close all open wt5 files."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Dataset base class."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Group base class."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/_open.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Generic open method for wt5 files."""


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


Expand Down
1 change: 1 addition & 0 deletions WrightTools/artists/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Artists."""

# flake8: noqa


Expand Down
1 change: 0 additions & 1 deletion WrightTools/artists/_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Base tools for visualizing data."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/artists/_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Colormaps."""


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

import copy
Expand Down
24 changes: 11 additions & 13 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Functions to help with plotting."""


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


Expand All @@ -15,7 +14,7 @@
import matplotlib.patheffects as PathEffects
from mpl_toolkits.axes_grid1 import make_axes_locatable

import imageio
import imageio.v3 as iio
import warnings

from .. import exceptions as wt_exceptions
Expand Down Expand Up @@ -1082,14 +1081,14 @@ def subplots_adjust(fig=None, inches=1):
fig.subplots_adjust(top=top, right=right, bottom=bottom, left=left)


def stitch_to_animation(images, outpath=None, *, duration=0.5, palettesize=256, verbose=True):
def stitch_to_animation(paths, outpath=None, *, duration=0.5, palettesize=256, verbose=True):
"""Stitch a series of images into an animation.
Currently supports animated gifs, other formats coming as needed.
Parameters
----------
images : list of strings
paths : list of strings
Filepaths to the images to stitch together, in order of apperence.
outpath : string (optional)
Path of output, including extension. If None, bases output path on path
Expand All @@ -1098,22 +1097,21 @@ def stitch_to_animation(images, outpath=None, *, duration=0.5, palettesize=256,
Duration of (each) frame in seconds. Default is 0.5.
palettesize : int (optional)
The number of colors in the resulting animation. Input is rounded to
the nearest power of 2. Default is 1024.
the nearest power of 2. Default is 256.
verbose : bool (optional)
Toggle talkback. Default is True.
"""
# parse filename
if outpath is None:
outpath = os.path.splitext(images[0])[0] + ".gif"
outpath = os.path.splitext(paths[0])[0] + ".gif"
# write
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
with t, iio.imopen(outpath, "w") as gif:
for p in paths:
frame = iio.imread(p)
gif.write(
frame, plugin="pillow", duration=duration * 1e3, loop=0, palettesize=palettesize
)
if verbose:
interval = np.round(t.interval, 2)
print("gif generated in {0} seconds - saved at {1}".format(interval, outpath))
Expand Down
1 change: 0 additions & 1 deletion WrightTools/artists/_quick.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Quick plotting."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/artists/_turbo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Define turbo colormap."""


# Copyright 2019 Google LLC.
# SPDX-License-Identifier: Apache-2.0

Expand Down
1 change: 1 addition & 0 deletions WrightTools/collection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Collection class and associated."""

# flake8: noqa


Expand Down
1 change: 0 additions & 1 deletion WrightTools/collection/_cary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Cary."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/collection/_collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Collection."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/collection/_directory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Cary."""


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


Expand Down
1 change: 1 addition & 0 deletions WrightTools/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data class and associated."""

# flake8: noqa


Expand Down
1 change: 0 additions & 1 deletion WrightTools/data/_aramis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Aramis."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/data/_axis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Axis class and associated."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/data/_brunold.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Brunold."""


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


Expand Down
11 changes: 10 additions & 1 deletion WrightTools/data/_channel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Channel class and associated."""


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


Expand Down Expand Up @@ -225,3 +224,13 @@ def trim(self, neighborhood, method="ztest", factor=3, replace="nan", verbose=Tr
if verbose:
print("%i outliers removed" % len(outliers))
return outliers

def _to_dict(self):
out = {}
out["name"] = self.natural_name
out["values"] = self[:]
out["units"] = self.units
out["label"] = self.label
out["signed"] = self.signed
out.update(self.attrs)
return out
1 change: 0 additions & 1 deletion WrightTools/data/_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""COLORS."""


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


Expand Down
1 change: 0 additions & 1 deletion WrightTools/data/_constant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Constant class and associated."""


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


Expand Down
86 changes: 74 additions & 12 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Central data class and associated."""


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

from __future__ import annotations
Expand Down Expand Up @@ -360,6 +359,78 @@ def at(self, parent=None, name=None, **at) -> Data:
idx = self._at_to_slice(**at)
return self._from_slice(idx, name=name, parent=parent)

def squeeze(self, name=None, parent=None):
"""Reduce the data to the dimensionality of the (non-trivial) span of the axes.
i.e. if the joint shape of the axes has an array dimension with length 1, this
array dimension is squeezed.
channels and variables that span beyond the axes are removed.
Parameters
----------
name : string (optional)
name of the new Data.
parent : WrightTools Collection instance (optional)
Collection to place the new "chop" collection within. Default is
None (new parent).
Returns
-------
out : wt.Data
new data object. The new data object has dimensions of the
(non-trivial) span of the current axes
Examples
--------
>>> ...
See also
--------
Data.chop: Divide the dataset into its lower-dimensionality components.
...
"""
new = Data(name=name, parent=parent)

attrs = {
k: v
for k, v in self.attrs.items()
if k
not in [
"axes",
"channel_names",
"constants",
"name",
"source",
"item_names",
"variable_names",
]
}
new.attrs.update(attrs)

joint_shape = wt_kit.joint_shape(*[ai[:] for ai in self.axes])
cull_dims = [j == 1 for j in joint_shape]
sl = [0 if cull else slice(None) for cull in cull_dims]
matches_broadcast_axes = lambda a: all(
[a.shape[i] == 1 for i in range(self.ndim) if cull_dims[i]]
)

for v in filter(matches_broadcast_axes, self.variables):
kwargs = v._to_dict()
kwargs["values"] = v[sl]
new.create_variable(**kwargs)

for c in filter(matches_broadcast_axes, self.channels):
kwargs = c._to_dict()
kwargs["values"] = c[sl]
new.create_channel(**kwargs)

# inherit constants
for c in self.constants:
new.create_constant(c.expression)

new.transform(*self.axis_expressions)
return new

def chop(self, *args, at=None, parent=None, verbose=True) -> wt_collection.Collection:
"""Divide the dataset into its lower-dimensionality components.
Expand Down Expand Up @@ -509,21 +580,12 @@ def _from_slice(self, idx, name=None, parent=None) -> Data:
out = parent.create_data(name=name)

for v in self.variables:
kwargs = {}
kwargs["name"] = v.natural_name
kwargs = v._to_dict()
kwargs["values"] = v[idx]
kwargs["units"] = v.units
kwargs["label"] = v.label
kwargs.update(v.attrs)
out.create_variable(**kwargs)
for c in self.channels:
kwargs = {}
kwargs["name"] = c.natural_name
kwargs = c._to_dict()
kwargs["values"] = c[idx]
kwargs["units"] = c.units
kwargs["label"] = c.label
kwargs["signed"] = c.signed
kwargs.update(c.attrs)
out.create_channel(**kwargs)

new_axes = [a.expression for a in self.axes if a[idx].size > 1]
Expand Down
Loading

0 comments on commit a08572d

Please sign in to comment.