Skip to content

Commit

Permalink
Merge pull request #1170 from wright-group/refactor_quicknd
Browse files Browse the repository at this point in the history
refactor quicknd
  • Loading branch information
kameyer226 authored Apr 29, 2024
2 parents 1f71638 + 1e644dc commit 6745f3e
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 252 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
## [Unreleased]

### Added
- `Data.ichop`, an interation-based version of `Data.chop`
- `Data.ichop`, an iteration-based version of `Data.chop`
- new artist helper function: `norm_from_channel`
- new artist helper function: `ticks_from_norm`
- new artist iterator `ChopHandler`

### Fixed
- fixed Quick2D/Quick1D issues where collapsing unused dims did not work
- wt5 explore : fixed bug where data will not load interactively if directory is not cwd
- constants in chopped data will inherit the units of the original data

## Changed
- refactor of artists.quick1D and artists.quick2D
- quick2D and quick1D will not force `autosave=True` if the number of figures is large. Instead, interactive plotting will be truncated if the number of figures is large.
- artists now gets turbo colormap straight from matplotlib
- artists.interact2D now returns a `types.SimpleNamespace` object (rather than a tuple)

Expand Down
38 changes: 38 additions & 0 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.patheffects as PathEffects

from matplotlib.colors import Normalize, CenteredNorm, TwoSlopeNorm
from mpl_toolkits.axes_grid1 import make_axes_locatable

import imageio.v3 as iio
Expand All @@ -33,6 +35,7 @@
"create_figure",
"diagonal_line",
"get_scaled_bounds",
"norm_from_channel",
"pcolor_helper",
"plot_colorbar",
"plot_margins",
Expand All @@ -43,6 +46,7 @@
"set_fig_labels",
"subplots_adjust",
"stitch_to_animation",
"ticks_from_norm",
]


Expand Down Expand Up @@ -1116,3 +1120,37 @@ def stitch_to_animation(paths, outpath=None, *, duration=0.5, palettesize=256, v
interval = np.round(t.interval, 2)
print("gif generated in {0} seconds - saved at {1}".format(interval, outpath))
return outpath


def norm_from_channel(channel, dynamic_range=False):
if channel.signed:
if dynamic_range:
norm = TwoSlopeNorm(vcenter=channel.null, vmin=channel.min(), vmax=channel.max())
else:
norm = CenteredNorm(vcenter=channel.null, halfrange=channel.mag())
if norm.halfrange == 0:
norm.halfrange = 1
else:
norm = Normalize(vmin=channel.null, vmax=np.nanmax(channel[:]))
if norm.vmax == norm.vmin:
norm.vmax += 1
return norm


def ticks_from_norm(norm, n=11) -> np.array:
if type(norm) == CenteredNorm:
vmin = norm.vcenter - norm.halfrange
vmax = norm.vcenter + norm.halfrange
elif type(norm) == Normalize:
vmin = norm.vmin
vmax = norm.vmax
elif type(norm) == TwoSlopeNorm:
mag = max(norm.vcenter - norm.vmin, norm.vmax - norm.vcenter)
in_range = lambda x: x >= norm.vmin and x <= norm.vmax
temp = [x for x in filter(in_range, np.linspace(-mag, mag, n))]
temp[0] = norm.vmin
temp[-1] = norm.vmax
return np.array(temp)
else:
raise TypeError(f"ticks for norm of type {type(norm)} is not supported at this time")
return np.linspace(vmin, vmax, n)
Loading

0 comments on commit 6745f3e

Please sign in to comment.