From 69ad6ea3726e3601c8b1048292b84a03f5f3cac9 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:35:25 -0500 Subject: [PATCH 01/22] soft deprecate plot_colorbar remove from examples, docs --- WrightTools/artists/_base.py | 3 ++- WrightTools/artists/_helpers.py | 4 ++++ WrightTools/artists/_interact.py | 2 +- docs/api/WrightTools.artists.rst | 1 - docs/artists.rst | 3 +-- examples/DOVE_transform.py | 5 +++-- examples/colormaps.py | 4 ++-- examples/custom_fig.py | 6 ++++-- examples/fill_types.py | 15 ++++++++------- examples/fringes_transform.py | 4 ++-- examples/label_delay_space.py | 10 +++++----- examples/level.py | 4 ++-- examples/moment_sideplot.py | 5 +++-- examples/tune_test.py | 4 ++-- 14 files changed, 39 insertions(+), 31 deletions(-) diff --git a/WrightTools/artists/_base.py b/WrightTools/artists/_base.py index cddc6a269..9714fe206 100644 --- a/WrightTools/artists/_base.py +++ b/WrightTools/artists/_base.py @@ -154,7 +154,8 @@ def _parse_plot_args(self, *args, **kwargs): data=data, channel_index=channel_index, dynamic_range=dynamic_range, **kwargs ) if plot_type == "contourf": - if "levels" not in kwargs.keys(): + if ("levels" not in kwargs.keys()) and ("norm" not in kwargs): + # because of _parse_limits, we ensur we always have vmin and vmax to use kwargs["levels"] = np.linspace(kwargs["vmin"], kwargs["vmax"], 256) elif plot_type == "contour": if "levels" not in kwargs.keys(): diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py index ceeabdac2..1a7d96dd6 100644 --- a/WrightTools/artists/_helpers.py +++ b/WrightTools/artists/_helpers.py @@ -657,6 +657,10 @@ def plot_colorbar( matplotlib.colorbar.ColorbarBase object The created colorbar. """ + warnings.warn( + "`plot_colorbar` is planned for deprecation. " + +"Use `matplotlib.pyplot.colorbar` instead.", + wt_exceptions.VisibleDeprecationWarning) # parse cax if cax is None: cax = plt.gca() diff --git a/WrightTools/artists/_interact.py b/WrightTools/artists/_interact.py index 071ab5548..05625363e 100644 --- a/WrightTools/artists/_interact.py +++ b/WrightTools/artists/_interact.py @@ -299,7 +299,7 @@ def interact2D( # colorbar ticks = current_state.norm.ticks ticklabels = gen_ticklabels(ticks, channel.signed) - colorbar = plot_colorbar(cax, cmap=cmap, label=channel.natural_name, ticks=ticks) + colorbar = fig.colorbar(mappable=obj2D, cax=cax, cmap=cmap, label=channel.natural_name, ticks=ticks) colorbar.set_ticklabels(ticklabels) fig.canvas.draw_idle() diff --git a/docs/api/WrightTools.artists.rst b/docs/api/WrightTools.artists.rst index 25ddce56e..a0d49d511 100644 --- a/docs/api/WrightTools.artists.rst +++ b/docs/api/WrightTools.artists.rst @@ -23,7 +23,6 @@ WrightTools\.artists module interact2D overline_colors pcolor_helper - plot_colorbar plot_colormap_components plot_gridlines plot_margins diff --git a/docs/artists.rst b/docs/artists.rst index 343e63129..19859107e 100644 --- a/docs/artists.rst +++ b/docs/artists.rst @@ -277,7 +277,6 @@ In addition, ``WrightTools`` defines some small helper functions for common task - Pairs well with :attr:`WrightTools.data.Constant.label` -- :meth:`~WrightTools.artists.plot_colorbar` Add a colorbar in a single function call - :meth:`~WrightTools.artists.set_fig_labels` Label axes in a whole row/column of a figure - Allows the use of slice objects to limit range affected @@ -311,7 +310,7 @@ In addition, ``WrightTools`` defines some small helper functions for common task # plot colormap cax = plt.subplot(gs[1:3, -1]) ticks = np.linspace(data.ai0.min(), data.ai0.max(), 11) - wt.artists.plot_colorbar(cax=cax, label="amplitude", cmap="default", ticks=ticks) + plt.colorbar(cax=cax, label="amplitude", cmap="default", ticks=ticks) # set axis labels wt.artists.set_fig_labels(xlabel=data.w1__e__wm.label, ylabel=data.d2.label, col=slice(0, 1)) diff --git a/examples/DOVE_transform.py b/examples/DOVE_transform.py index 7bc213164..8346081e4 100644 --- a/examples/DOVE_transform.py +++ b/examples/DOVE_transform.py @@ -13,6 +13,7 @@ p = datasets.KENT.LDS821_DOVE data = wt.data.from_KENT(p, ignore=["d1", "d2", "wm"], verbose=False) +data.channels[0].normalize() fig, gs = wt.artists.create_figure(width="double", cols=[1, 1, "cbar"], wspace=0.7) @@ -27,11 +28,11 @@ # transformed ax = plt.subplot(gs[0, 1]) data.transform("w2", "w1-w2") -ax.pcolor(data) +art = ax.pcolor(data) wt.artists.set_ax_labels(xlabel=data.w2.label) ax.grid() ax.set_title("transformed", fontsize=20) # colorbar cax = plt.subplot(gs[0, -1]) -wt.artists.plot_colorbar(cax, label="Intensity") +fig.colorbar(art, cax=cax, label="Intensity") diff --git a/examples/colormaps.py b/examples/colormaps.py index b7e25964d..166a74c91 100644 --- a/examples/colormaps.py +++ b/examples/colormaps.py @@ -30,10 +30,10 @@ def fill_row(row, cmap): ax.pcolor(data, cmap=wt.artists.grayify_cmap(cmap)) # color ax = plt.subplot(gs[row, 1]) - ax.pcolor(data, cmap=cmap) + art = ax.pcolor(data, cmap=cmap) # cbar cax = plt.subplot(gs[row, 2]) - wt.artists.plot_colorbar(cax=cax, label=cmap.name, cmap=cmap) + fig.colorbar(art, cax=cax, label=cmap.name) wt.artists.set_ax_labels(cax, yticks=False) diff --git a/examples/custom_fig.py b/examples/custom_fig.py index e5074125c..73ef6c8dd 100644 --- a/examples/custom_fig.py +++ b/examples/custom_fig.py @@ -8,6 +8,7 @@ """ import matplotlib.pyplot as plt +from matplotlib.colors import Normalize import numpy as np @@ -23,6 +24,7 @@ data.smooth([2, 2, 2]) data.ai0.symmetric_root(2) data.ai0.normalize() +norm = Normalize(vmin=0, vmax=1) data.ai0.clip(min=0, replace="value") # chop out data of interest d2_vals = [-50, -500] @@ -48,7 +50,7 @@ indxs = [(row, col) for row in range(1, 3) for col in range(2)] for indx, wigner, color in zip(indxs, wigners, wigner_colors): ax = plt.subplot(gs[indx]) - ax.pcolor(wigner, vmin=0, vmax=1) # global colormpa + art = ax.pcolormesh(wigner, norm=norm) # global colormpa ax.contour(wigner) # local contours ax.grid() wt.artists.set_ax_spines(ax=ax, c=color) @@ -73,7 +75,7 @@ # plot colormap cax = plt.subplot(gs[1:3, -1]) ticks = np.linspace(data.ai0.min(), data.ai0.max(), 11) -wt.artists.plot_colorbar(cax=cax, label="amplitude", cmap="default", ticks=ticks) +fig.colorbar(art, cax=cax, label="amplitude", cmap="default", ticks=ticks) # set axis labels wt.artists.set_fig_labels(xlabel=data.w1__e__wm.label, ylabel=data.d2.label, col=slice(0, 1)) # ylabel of zeroth row diff --git a/examples/fill_types.py b/examples/fill_types.py index 85b228e82..42ce36142 100644 --- a/examples/fill_types.py +++ b/examples/fill_types.py @@ -15,6 +15,7 @@ from WrightTools import datasets cmap = wt.artists.colormaps["default"] +norm = matplotlib.colors.Normalize(vmin=0, vmax=1) fig, gs = wt.artists.create_figure(width="double", nrows=2, cols=[1, 1, 1, 1, "cbar"]) @@ -39,11 +40,11 @@ def decorate(ax): # pcolor ax = plt.subplot(gs[0, 0]) -ax.pcolor(data, cmap=cmap) +ax.pcolor(data, cmap=cmap, norm=norm) ax.set_title("pcolor", fontsize=20) decorate(ax) ax = plt.subplot(gs[1, 0]) -ax.pcolor(data, cmap=cmap, edgecolors="k") +art = ax.pcolor(data, cmap=cmap, edgecolors="k", norm=norm) dot_pixel_centers(ax, data.d1.points, data.d2.points) decorate(ax) @@ -54,11 +55,11 @@ def decorate(ax): ax = plt.subplot(gs[0, 1]) points = [xi, yi] x, y = tuple(np.meshgrid(*points, indexing="ij")) -ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), cmap=cmap, vmin=0, vmax=1) +ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), cmap=cmap, norm=norm) decorate(ax) ax.set_title("tripcolor", fontsize=20) ax = plt.subplot(gs[1, 1]) -ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), edgecolor="k", cmap=cmap, vmin=0, vmax=1) +ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), edgecolor="k", cmap=cmap, norm=norm) decorate(ax) dot_pixel_centers(ax, xi, yi) @@ -76,11 +77,11 @@ def plot_delaunay_edges(ax, xi, yi, zi): # contourf ax = plt.subplot(gs[0, 2]) -ax.contourf(data, vmin=-1e-3) +ax.contourf(data, norm=norm, levels=265) decorate(ax) ax.set_title("contourf", fontsize=20) ax = plt.subplot(gs[1, 2]) -ax.contourf(data, vmin=-1e-3) +ax.contourf(data, norm=norm, levels=256) plot_delaunay_edges(ax, xi, yi, zi) dot_pixel_centers(ax, xi, yi) decorate(ax) @@ -102,4 +103,4 @@ def plot_delaunay_edges(ax, xi, yi, zi): # colorbar cax = plt.subplot(gs[:, -1]) -wt.artists.plot_colorbar(cax=cax, label="amplitude") +fig.colorbar(art, cax=cax, label="amplitude") diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index dce93d45b..b423ce7ac 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -30,11 +30,11 @@ ax = plt.subplot(gs[0, 1]) data.transform("wm", "w1") data.convert("wn") -ax.pcolor(data) +art = ax.pcolor(data) wt.artists.set_ax_labels(xlabel=data.wm.label, yticks=False) ax.grid() ax.set_title("transformed", fontsize=20) # colorbar cax = plt.subplot(gs[0, -1]) -wt.artists.plot_colorbar(cax, label="amplitude") +fig.colorbar(art, cax, label="amplitude") \ No newline at end of file diff --git a/examples/label_delay_space.py b/examples/label_delay_space.py index 2b4ade831..722da0208 100644 --- a/examples/label_delay_space.py +++ b/examples/label_delay_space.py @@ -7,6 +7,7 @@ """ import matplotlib.pyplot as plt +from matplotlib.colors import Normalize import WrightTools as wt from WrightTools import datasets @@ -18,6 +19,7 @@ def set_lim(ax): ax.set_xlim(-175, 175) ax.set_ylim(-175, 175) +norm = Normalize(vmin=0, vmax=1, clip=True) # traditional delay space ax = plt.subplot(gs[0, 0]) @@ -26,8 +28,7 @@ def set_lim(ax): data.convert("fs") data.channels[0].symmetric_root(2) data.channels[0].normalize() -data.channels[0].clip(min=0, replace="value") -ax.pcolor(data) +ax.pcolor(data, norm=norm) wt.diagrams.delay.label_sectors(ax=ax) # using default labels set_lim(ax) ax.set_title(r"$\mathsf{\vec{k}_1 - \vec{k}_2 + \vec{k}_{2^\prime}}$", fontsize=20) @@ -39,8 +40,7 @@ def set_lim(ax): data.convert("fs") data.channels[0].symmetric_root(2) data.channels[0].normalize() -data.channels[0].clip(min=0, replace="value") -ax.pcolor(data) +art = ax.pcolor(data, norm=norm) labels = ["II", "I", "III", "V", "VI", "IV"] wt.diagrams.delay.label_sectors(ax=ax, labels=labels) set_lim(ax) @@ -51,4 +51,4 @@ def set_lim(ax): # colorbar cax = plt.subplot(gs[:, -1]) -wt.artists.plot_colorbar(cax=cax, label="amplitude") +fig.colorbar(art, cax=cax, label="amplitude") diff --git a/examples/level.py b/examples/level.py index 4e4a4adf5..9e89e8fc3 100644 --- a/examples/level.py +++ b/examples/level.py @@ -22,7 +22,7 @@ ax = plt.subplot(gs[0, 0]) chop = data.chop("w1=wm", "d2", at={"w2": [1.7, "eV"]})[0] chop.ai0.null = chop.ai0.min() # only for example -ax.pcolor(chop) +art = ax.pcolor(chop) ax.contour(chop) # leveled @@ -38,5 +38,5 @@ # colorbar cax = plt.subplot(gs[0, -1]) -wt.artists.plot_colorbar(cax=cax, label="amplitude") +fig.colorbar(art, cax=cax, label="amplitude") wt.artists.set_ax_labels(cax, yticks=False) diff --git a/examples/moment_sideplot.py b/examples/moment_sideplot.py index 99b93c5db..7d6c662ba 100644 --- a/examples/moment_sideplot.py +++ b/examples/moment_sideplot.py @@ -22,6 +22,7 @@ def S(x): d.create_variable("d1", values=d1, units="ps", label="1") d.create_variable("d2", values=d2, units="ps", label="2") d.create_channel("z", values=arr) +d.z.normalize() d.transform("d1", "d2") # calculate moments @@ -38,7 +39,7 @@ def S(x): axcorrx = ax.add_sideplot(along="x", pad=0.1, ymin=-0.1, ymax=1.1) axcorry = ax.add_sideplot(along="y", pad=0.1, ymin=-0.1, ymax=1.1) # plot data -ax.pcolor(d, autolabel="both") +art = ax.pcolor(d, autolabel="both") # plot integral moments in sideplot axcorrx.plot(d, channel="z_d2_moment_0", color="k", linewidth=3) # this sideplot is uncouth. @@ -55,4 +56,4 @@ def S(x): ax_.grid() # plot colorbar cax = plt.subplot(gs[-1]) -wt.artists.plot_colorbar(cax=cax, label="amplitude") +fig.colorbar(art, cax=cax, label="amplitude") diff --git a/examples/tune_test.py b/examples/tune_test.py index e9a9bd15d..5d1581e41 100644 --- a/examples/tune_test.py +++ b/examples/tune_test.py @@ -26,11 +26,11 @@ # transformed ax = plt.subplot(gs[0, 2]) data.transform("w1", "wa-w1") -ax.pcolor(data) +art = ax.pcolor(data) wt.artists.set_ax_labels(xlabel=data.w1.label, ylabel=data.wa__m__w1.label) ax.grid() ax.set_title("transformed", fontsize=20) # colorbar cax = plt.subplot(gs[0, -1]) -wt.artists.plot_colorbar(cax, label="intensity") +fig.colorbar(art, cax=cax, label="intensity") From daa1e46eef87b149b30ce0564b4a7b159573bc5c Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:44:34 -0500 Subject: [PATCH 02/22] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15a1f8009..392b12fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## Changed - artists now gets turbo colormap straight from matplotlib +- deprecating `artists.plot_colorbar`: instead use matplotlib's `colorbar` implementations directly ## [3.5.2] From 5c9eaa08722bcb7155f1f4f867131c008ed3d4a7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:44:49 +0000 Subject: [PATCH 03/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- WrightTools/artists/_helpers.py | 5 +++-- WrightTools/artists/_interact.py | 4 +++- examples/fringes_transform.py | 2 +- examples/label_delay_space.py | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py index 1a7d96dd6..73fd60e18 100644 --- a/WrightTools/artists/_helpers.py +++ b/WrightTools/artists/_helpers.py @@ -659,8 +659,9 @@ def plot_colorbar( """ warnings.warn( "`plot_colorbar` is planned for deprecation. " - +"Use `matplotlib.pyplot.colorbar` instead.", - wt_exceptions.VisibleDeprecationWarning) + + "Use `matplotlib.pyplot.colorbar` instead.", + wt_exceptions.VisibleDeprecationWarning, + ) # parse cax if cax is None: cax = plt.gca() diff --git a/WrightTools/artists/_interact.py b/WrightTools/artists/_interact.py index 05625363e..80bbd9470 100644 --- a/WrightTools/artists/_interact.py +++ b/WrightTools/artists/_interact.py @@ -299,7 +299,9 @@ def interact2D( # colorbar ticks = current_state.norm.ticks ticklabels = gen_ticklabels(ticks, channel.signed) - colorbar = fig.colorbar(mappable=obj2D, cax=cax, cmap=cmap, label=channel.natural_name, ticks=ticks) + colorbar = fig.colorbar( + mappable=obj2D, cax=cax, cmap=cmap, label=channel.natural_name, ticks=ticks + ) colorbar.set_ticklabels(ticklabels) fig.canvas.draw_idle() diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index b423ce7ac..3bf1a54e5 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -37,4 +37,4 @@ # colorbar cax = plt.subplot(gs[0, -1]) -fig.colorbar(art, cax, label="amplitude") \ No newline at end of file +fig.colorbar(art, cax, label="amplitude") diff --git a/examples/label_delay_space.py b/examples/label_delay_space.py index 722da0208..94dab2097 100644 --- a/examples/label_delay_space.py +++ b/examples/label_delay_space.py @@ -19,6 +19,7 @@ def set_lim(ax): ax.set_xlim(-175, 175) ax.set_ylim(-175, 175) + norm = Normalize(vmin=0, vmax=1, clip=True) # traditional delay space From 81229516c8c1269b6c50af49542d50112b00aca2 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:51:42 -0500 Subject: [PATCH 04/22] fix 2 warnings --- WrightTools/__citation__.py | 4 ++-- docs/quickstart.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WrightTools/__citation__.py b/WrightTools/__citation__.py index d8ff1c611..7ca3a50d0 100644 --- a/WrightTools/__citation__.py +++ b/WrightTools/__citation__.py @@ -6,6 +6,6 @@ here = pathlib.Path(__file__).parent -with here / "CITATION" as f: +with open(here / "CITATION") as f: # remove extra whitespace - __citation__ = " ".join(f.read_text().split()) + __citation__ = " ".join(f.read().split()) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 0832a3916..9087db340 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -360,7 +360,7 @@ To choose a specific time point, you can of course just make the chopping more s data = wt.open(p) data.transform('w1=wm', 'w2-wm', 'd2') data.convert('eV') - data1 = data.chop('w2', at={'w1=wm':[1.5, 'eV'], 'd2':[0, 'fs']})[0] + data1 = data.chop('w2-wm', at={'w1=wm':[1.5, 'eV'], 'd2':[0, 'fs']})[0] wt.artists.quick1D(data1) plt.show() From 7ab3ab7d2a893802d705f9c70ba38fd6c8418461 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:38:43 -0500 Subject: [PATCH 05/22] test build --- WrightTools/artists/_helpers.py | 7 +++++-- WrightTools/data/_join.py | 3 ++- examples/fringes_transform.py | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py index 73fd60e18..2544e1dc6 100644 --- a/WrightTools/artists/_helpers.py +++ b/WrightTools/artists/_helpers.py @@ -1052,8 +1052,11 @@ def set_fig_labels( def subplots_adjust(fig=None, inches=1): - """Enforce margins for generated figure, starting at subplots. - .. note:: + """ + Enforce margins for generated figure, starting at subplots. + + Note + ---- You probably should be using wt.artists.create_figure instead. Parameters diff --git a/WrightTools/data/_join.py b/WrightTools/data/_join.py index dc0a7fc55..9b272d372 100644 --- a/WrightTools/data/_join.py +++ b/WrightTools/data/_join.py @@ -26,7 +26,8 @@ def join( datas, *, atol=None, rtol=None, name="join", parent=None, method="first", verbose=True ) -> Data: - """Join a list of data objects into one data object. + """ + Join a list of data objects into one data object. The underlying dataset arrays are merged. Joined datas must have the same axes and axes order. diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index 3bf1a54e5..7aa08380a 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -11,30 +11,30 @@ import WrightTools as wt from WrightTools import datasets -p = datasets.PyCMDS.w2_w1_000 -data = wt.data.from_PyCMDS(p) +# p = datasets.PyCMDS.w2_w1_000 +# data = wt.data.from_PyCMDS(p) -data.signal_mean.symmetric_root(2) # to amplitude level -data.convert("wn") +# data.signal_mean.symmetric_root(2) # to amplitude level +# data.convert("wn") fig, gs = wt.artists.create_figure(width="double", cols=[1, 1, "cbar"]) # as taken ax = plt.subplot(gs[0, 0]) -ax.pcolor(data) -wt.artists.set_ax_labels(xlabel=data.w2.label, ylabel=data.w1.label) +# ax.pcolor(data) +# wt.artists.set_ax_labels(xlabel=data.w2.label, ylabel=data.w1.label) ax.grid() ax.set_title("as taken", fontsize=20) # transformed ax = plt.subplot(gs[0, 1]) -data.transform("wm", "w1") -data.convert("wn") -art = ax.pcolor(data) -wt.artists.set_ax_labels(xlabel=data.wm.label, yticks=False) +# data.transform("wm", "w1") +# data.convert("wn") +# art = ax.pcolor(data) +# wt.artists.set_ax_labels(xlabel=data.wm.label, yticks=False) ax.grid() ax.set_title("transformed", fontsize=20) # colorbar cax = plt.subplot(gs[0, -1]) -fig.colorbar(art, cax, label="amplitude") +# fig.colorbar(art, cax, label="amplitude") From 1509e85f0df37d0976f1b63abd4f18d1a94da749 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:30:44 -0500 Subject: [PATCH 06/22] Update fringes_transform.py try alternative path to make fringes work --- examples/fringes_transform.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index 7aa08380a..0a41ef563 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -12,29 +12,30 @@ from WrightTools import datasets # p = datasets.PyCMDS.w2_w1_000 -# data = wt.data.from_PyCMDS(p) +p = datasets.here / "PyCMDS" / "w2 w1 000.data" +data = wt.data.from_PyCMDS(p) -# data.signal_mean.symmetric_root(2) # to amplitude level -# data.convert("wn") +data.signal_mean.symmetric_root(2) # to amplitude level +data.convert("wn") fig, gs = wt.artists.create_figure(width="double", cols=[1, 1, "cbar"]) # as taken ax = plt.subplot(gs[0, 0]) -# ax.pcolor(data) -# wt.artists.set_ax_labels(xlabel=data.w2.label, ylabel=data.w1.label) +ax.pcolor(data) +wt.artists.set_ax_labels(xlabel=data.w2.label, ylabel=data.w1.label) ax.grid() ax.set_title("as taken", fontsize=20) # transformed ax = plt.subplot(gs[0, 1]) -# data.transform("wm", "w1") -# data.convert("wn") -# art = ax.pcolor(data) -# wt.artists.set_ax_labels(xlabel=data.wm.label, yticks=False) +data.transform("wm", "w1") +data.convert("wn") +art = ax.pcolor(data) +wt.artists.set_ax_labels(xlabel=data.wm.label, yticks=False) ax.grid() ax.set_title("transformed", fontsize=20) # colorbar cax = plt.subplot(gs[0, -1]) -# fig.colorbar(art, cax, label="amplitude") +fig.colorbar(art, cax, label="amplitude") From 82424664d8888ce15f0c950d022e9bc1ef106bbf Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 23 Mar 2024 02:55:44 -0500 Subject: [PATCH 07/22] test node20 --- .github/workflows/python-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 6ca1b514a..6a3127804 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -15,9 +15,9 @@ jobs: python-version: [3.8, 3.9, '3.10', 3.11] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 1834767635a540d9c9a3b63642cb629c8569602b Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 23 Mar 2024 03:13:54 -0500 Subject: [PATCH 08/22] Update fringes_transform.py try to get feedback from error --- examples/fringes_transform.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index 0a41ef563..9c20633d6 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -11,7 +11,13 @@ import WrightTools as wt from WrightTools import datasets -# p = datasets.PyCMDS.w2_w1_000 +try: + p = datasets.PyCMDS.w2_w1_000 +except AttributeError as e: + e.add_note(f"valid attrs are {datasets.PyCMDS.__dict__.items()}") + e.add_note(f"KENT has other attrs: {datasets.KENT.__dict__.items()}") + raise + p = datasets.here / "PyCMDS" / "w2 w1 000.data" data = wt.data.from_PyCMDS(p) From 13386fd5afe897e4a8a0f4202ecee2eb753ae51f Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 23 Mar 2024 03:59:23 -0500 Subject: [PATCH 09/22] try more for sphinx --- docs/cli.rst | 1 + docs/conf.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/cli.rst b/docs/cli.rst index a88e8202d..22cc72a4b 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -14,6 +14,7 @@ wt-convert Use ``wt-convert`` to explore the WrightTools units system and the conversions of units. .. code-block:: shell + > wt-units 1330 nm wn 7692.3 wn 0.95372 eV diff --git a/docs/conf.py b/docs/conf.py index eb57526a0..252054d3d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -246,7 +246,7 @@ def reset_wt(gallery_conf, fname): "filename_pattern": "/*.py", "gallery_dirs": "auto_examples", "backreferences_dir": os.path.join("gen_modules", "backreferences"), - "reset_modules": ["matplotlib", reset_wt], + "reset_modules": ["matplotlib"] # , reset_wt], } From 06e32b7267f755cccb170683669fff07764ab21e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:59:37 +0000 Subject: [PATCH 10/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 252054d3d..1e81d0829 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -246,7 +246,7 @@ def reset_wt(gallery_conf, fname): "filename_pattern": "/*.py", "gallery_dirs": "auto_examples", "backreferences_dir": os.path.join("gen_modules", "backreferences"), - "reset_modules": ["matplotlib"] # , reset_wt], + "reset_modules": ["matplotlib"], # , reset_wt], } From 31fa0bddaa7e5d17c3381fd10bf91adad5be2fe0 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:07:20 -0500 Subject: [PATCH 11/22] Update split.py --- examples/split.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/split.py b/examples/split.py index db704335a..04ace4245 100644 --- a/examples/split.py +++ b/examples/split.py @@ -9,7 +9,9 @@ import WrightTools as wt from WrightTools import datasets -d = wt.data.from_PyCMDS(datasets.PyCMDS.w2_w1_000) + +p = datasets.PyCMDS.w2_w1_000 +d = wt.data.from_PyCMDS(p) d.convert("wn", convert_variables=True) From fdf358cb6852ce89741dec54247ecc143625d6fd Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:51:30 -0500 Subject: [PATCH 12/22] re-implement module reset (#1175) * re-implement module reset * Update split.py * Update split.py * Update conf.py * Update split.py * Update fringes_transform.py * Update __init__.py * Update fringes_transform.py * Revert "Update fringes_transform.py" This reverts commit 7911367c43847449c908f30e3f68b3ee43d3a7f9. * node 20 --- .github/workflows/python-publish.yml | 4 ++-- .github/workflows/python-test.yml | 2 +- WrightTools/datasets/__init__.py | 3 +++ docs/conf.py | 3 ++- examples/fringes_transform.py | 11 +++-------- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bea1a5b60..a4be18122 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,9 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install dependencies diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 6a3127804..9e2a8c70b 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/WrightTools/datasets/__init__.py b/WrightTools/datasets/__init__.py index b29bd2f38..c6168a932 100644 --- a/WrightTools/datasets/__init__.py +++ b/WrightTools/datasets/__init__.py @@ -103,9 +103,12 @@ def _from_directory(self, dirname, prefix=""): "COLORS", "JASCO", "KENT", + "LabRAM", "ocean_optics", "PyCMDS", + "Shimadzu", "Solis", + "spcm", "Tensor27", "wt5", ] diff --git a/docs/conf.py b/docs/conf.py index 1e81d0829..eb236c4cd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -246,7 +246,8 @@ def reset_wt(gallery_conf, fname): "filename_pattern": "/*.py", "gallery_dirs": "auto_examples", "backreferences_dir": os.path.join("gen_modules", "backreferences"), - "reset_modules": ["matplotlib"], # , reset_wt], + "reset_modules": ["matplotlib", reset_wt], + "reset_module_order": "both", } diff --git a/examples/fringes_transform.py b/examples/fringes_transform.py index 9c20633d6..3c57fda8c 100644 --- a/examples/fringes_transform.py +++ b/examples/fringes_transform.py @@ -11,14 +11,9 @@ import WrightTools as wt from WrightTools import datasets -try: - p = datasets.PyCMDS.w2_w1_000 -except AttributeError as e: - e.add_note(f"valid attrs are {datasets.PyCMDS.__dict__.items()}") - e.add_note(f"KENT has other attrs: {datasets.KENT.__dict__.items()}") - raise - -p = datasets.here / "PyCMDS" / "w2 w1 000.data" +p = datasets.PyCMDS.w2_w1_000 + +# p = datasets.here / "PyCMDS" / "w2 w1 000.data" data = wt.data.from_PyCMDS(p) data.signal_mean.symmetric_root(2) # to amplitude level From ddf2db89fffbec790c1cdea02cf81ffae8103810 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sun, 31 Mar 2024 11:51:36 -0500 Subject: [PATCH 13/22] new example for norms, cbar --- examples/norms.py | 149 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 examples/norms.py diff --git a/examples/norms.py b/examples/norms.py new file mode 100644 index 000000000..92c06af72 --- /dev/null +++ b/examples/norms.py @@ -0,0 +1,149 @@ +""" +use the right combination of colorbar and matplotlib norms +to communicate your data! +""" + +import WrightTools as wt +from WrightTools import datasets +import matplotlib.colors as mpl_colors +import matplotlib.pyplot as plt +import numpy as np +from matplotlib import colormaps as colormaps + + +# --- colormaps ----------------------------------------------------------------------------------- +unsigned_cmap = [ + wt.artists.colormaps["default"].copy(), + colormaps["cubehelix_r"], + colormaps["magma_r"], + colormaps["viridis_r"], +][0] +unsigned_cmap.set_under([0.9, 0.9, 0.9, 1]) + +cyclic_cmap = "twilight" + +signed_cmap = [ + "twilight_shifted", + "RdBu", + "coolwarm", + "seismic" +][1] + + +# --- data ---------------------------------------------------------------------------------------- +signed = wt.open(datasets.wt5.v1p0p0_perovskite_TA).at(d2=[-15, "fs"]).split("w1", [1.6])[1] +signed.bring_to_front("signal_diff") + +unsigned = wt.data.from_PyCMDS(r"https://osf.io/75vny/download") +unsigned.bring_to_front("signal_diff") +unsigned.convert("eV") +unsigned.signal_diff.normalize() + + +# --- plot ---------------------------------------------------------------------------------------- +label_kwargs=dict(fontsize=14, corner="LR", background_alpha=0.6) +fig, gs = wt.artists.create_figure(width=8, cols=[1,1], nrows=4, wspace=1.3) + + +# --- unsigned data ------------------------------------------------------------------------------- +# --- --- linear ---------------------------------------------------------------------------------- +ax00 = fig.add_subplot(gs[0,0], label="00 - unsigned linear") +wt.artists.corner_text("linear", **label_kwargs) +art = ax00.pcolormesh(unsigned, cmap=unsigned_cmap, autolabel="y") +fig.colorbar(art, ax=ax00, extend="min") + +ax00.set_title("unsigned data") + +# --- --- sqrt ------------------------------------------------------------------------------------ +ax10 = fig.add_subplot(gs[1,0], label="10 - unsigned sqrt") +wt.artists.corner_text("sqrt", **label_kwargs) +norm = mpl_colors.PowerNorm(gamma=0.5, vmin=0) +""" +NOTE: a bug with PowerNorm makes the colorbar extend arrow incorrect color +as recently as mpl 3.8.3. +a fix has been applied upstream; we just have to wait for it +https://github.com/matplotlib/matplotlib/pull/27589 +in the meantime, we can define a custom norm to get past the issue +""" +_forward = lambda x: np.sign(x) * np.sqrt(np.abs(x)) +_inverse = lambda x: np.sign(x) * x**2 +norm = mpl_colors.FuncNorm((_forward, _inverse), vmin=0, clip=False) +art = ax10.pcolormesh(unsigned, norm=norm, cmap=unsigned_cmap, autolabel="y") +cb = fig.colorbar(art, ax=ax10, extend="min") + +# --- --- log10 ----------------------------------------------------------------------------------- +ax20 = fig.add_subplot(gs[2, 0], label="20 - unsigned log") +wt.artists.corner_text("log10", **label_kwargs) +norm = mpl_colors.LogNorm(vmin=5e-4, clip=False) +art = ax20.pcolormesh(unsigned, norm=norm, cmap=unsigned_cmap, autolabel="y") +cblog = fig.colorbar(art, ax=ax20, extend="min") + +# --- --- log10, decadic cycles ------------------------------------------------------------------- +# currently a bit hackish, but works. We could make tools for this +ax30 = fig.add_subplot(gs[3, 0], label="30 - unsigned log cyclic") +wt.artists.corner_text("log10, cyclic", **label_kwargs) +mantissa = lambda x: np.mod(np.log10(x), -1) +unsigned.create_channel("mantissa", values=10**mantissa(unsigned.signal_diff[:])) +norm = mpl_colors.LogNorm() +art = ax30.pcolormesh( + unsigned, channel="mantissa", norm=norm, cmap=cyclic_cmap, autolabel="both" +) +cb = fig.colorbar(art, ax=ax30) +cb.ax.yaxis.set_minor_formatter("{x:0.1f}") +cb.ax.set_yticks([0.1, 0.2, 0.5], minor=True) # , labels=["0.2", "0.5"], minor=True) + +# --- plot signed data --------------------------------------------------------------------------- +# --- --- linear norm ---------------------------------------------------------------------------- +ax01 = fig.add_subplot(gs[0, 1], label="01 - signed linear") +ax01.set_title("signed data") +wt.artists.corner_text("linear", **label_kwargs) +art = ax01.pcolormesh(signed, cmap=signed_cmap, autolabel="y") +fig.colorbar(art, ax=ax01) + +# --- --- bilinear norm -------------------------------------------------------------------------- +ax11 = fig.add_subplot(gs[1, 1], label="11 - signed bilinear") +wt.artists.corner_text("bilinear", **label_kwargs) +norm = mpl_colors.TwoSlopeNorm(vcenter=signed.signal_diff.null) +art = ax11.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="y") +cb = fig.colorbar(art, ax=ax11) +cb.ax.set_yscale('linear') + +# --- --- asinh norm ------------------------------------------------------------------------------ +ax21 = fig.add_subplot(gs[2, 1], label="21 - signed asinh") +wt.artists.corner_text("asinh", **label_kwargs) +norm = mpl_colors.AsinhNorm( + linear_width=1e-3, + vmin=-signed.signal_diff.mag(), + vmax=signed.signal_diff.mag() +) +art = ax21.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="y") +fig.colorbar(art, ax=ax21) + +# --- --- symlog norm ----------------------------------------------------------------------------- +ax31 = fig.add_subplot(gs[3, 1], label="31 - signed symlog") +wt.artists.corner_text("symLog", **label_kwargs) +norm = mpl_colors.SymLogNorm( + linthresh=1e-3, + vmin=-signed.signal_diff.mag(), + vmax=signed.signal_diff.mag() +) +art = ax31.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="both") +fig.colorbar(art, ax=ax31) + + +# --- final decorations --------------------------------------------------------------------------- + +for ax in fig.axes: + label = ax.get_label() + if label == "": + continue + ax.grid(c="k", lw=1, ls="-.", alpha=0.5) + if label[0] != "3": # not bottom row + ax.set_xticks(ax.get_xticks(), ax.get_xticklabels(), visible=False) + ax.set_xticks(ax.get_yticks()) + if label[1] == "0": # unsigned + ax.set_xlim(unsigned.w2.min(), unsigned.w2.max()) + else: + ax.set_xlim(signed.w1.min(), signed.w1.max()) + +plt.show() \ No newline at end of file From 39c36bf9aae828d8f8d72ed213f3920fd1bb39bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:54:26 +0000 Subject: [PATCH 14/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/norms.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/examples/norms.py b/examples/norms.py index 92c06af72..30752d2eb 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -22,12 +22,7 @@ cyclic_cmap = "twilight" -signed_cmap = [ - "twilight_shifted", - "RdBu", - "coolwarm", - "seismic" -][1] +signed_cmap = ["twilight_shifted", "RdBu", "coolwarm", "seismic"][1] # --- data ---------------------------------------------------------------------------------------- @@ -40,14 +35,14 @@ unsigned.signal_diff.normalize() -# --- plot ---------------------------------------------------------------------------------------- -label_kwargs=dict(fontsize=14, corner="LR", background_alpha=0.6) -fig, gs = wt.artists.create_figure(width=8, cols=[1,1], nrows=4, wspace=1.3) +# --- plot ---------------------------------------------------------------------------------------- +label_kwargs = dict(fontsize=14, corner="LR", background_alpha=0.6) +fig, gs = wt.artists.create_figure(width=8, cols=[1, 1], nrows=4, wspace=1.3) # --- unsigned data ------------------------------------------------------------------------------- # --- --- linear ---------------------------------------------------------------------------------- -ax00 = fig.add_subplot(gs[0,0], label="00 - unsigned linear") +ax00 = fig.add_subplot(gs[0, 0], label="00 - unsigned linear") wt.artists.corner_text("linear", **label_kwargs) art = ax00.pcolormesh(unsigned, cmap=unsigned_cmap, autolabel="y") fig.colorbar(art, ax=ax00, extend="min") @@ -55,7 +50,7 @@ ax00.set_title("unsigned data") # --- --- sqrt ------------------------------------------------------------------------------------ -ax10 = fig.add_subplot(gs[1,0], label="10 - unsigned sqrt") +ax10 = fig.add_subplot(gs[1, 0], label="10 - unsigned sqrt") wt.artists.corner_text("sqrt", **label_kwargs) norm = mpl_colors.PowerNorm(gamma=0.5, vmin=0) """ @@ -83,11 +78,9 @@ ax30 = fig.add_subplot(gs[3, 0], label="30 - unsigned log cyclic") wt.artists.corner_text("log10, cyclic", **label_kwargs) mantissa = lambda x: np.mod(np.log10(x), -1) -unsigned.create_channel("mantissa", values=10**mantissa(unsigned.signal_diff[:])) +unsigned.create_channel("mantissa", values=10 ** mantissa(unsigned.signal_diff[:])) norm = mpl_colors.LogNorm() -art = ax30.pcolormesh( - unsigned, channel="mantissa", norm=norm, cmap=cyclic_cmap, autolabel="both" -) +art = ax30.pcolormesh(unsigned, channel="mantissa", norm=norm, cmap=cyclic_cmap, autolabel="both") cb = fig.colorbar(art, ax=ax30) cb.ax.yaxis.set_minor_formatter("{x:0.1f}") cb.ax.set_yticks([0.1, 0.2, 0.5], minor=True) # , labels=["0.2", "0.5"], minor=True) @@ -106,15 +99,13 @@ norm = mpl_colors.TwoSlopeNorm(vcenter=signed.signal_diff.null) art = ax11.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="y") cb = fig.colorbar(art, ax=ax11) -cb.ax.set_yscale('linear') +cb.ax.set_yscale("linear") # --- --- asinh norm ------------------------------------------------------------------------------ ax21 = fig.add_subplot(gs[2, 1], label="21 - signed asinh") wt.artists.corner_text("asinh", **label_kwargs) norm = mpl_colors.AsinhNorm( - linear_width=1e-3, - vmin=-signed.signal_diff.mag(), - vmax=signed.signal_diff.mag() + linear_width=1e-3, vmin=-signed.signal_diff.mag(), vmax=signed.signal_diff.mag() ) art = ax21.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="y") fig.colorbar(art, ax=ax21) @@ -123,9 +114,7 @@ ax31 = fig.add_subplot(gs[3, 1], label="31 - signed symlog") wt.artists.corner_text("symLog", **label_kwargs) norm = mpl_colors.SymLogNorm( - linthresh=1e-3, - vmin=-signed.signal_diff.mag(), - vmax=signed.signal_diff.mag() + linthresh=1e-3, vmin=-signed.signal_diff.mag(), vmax=signed.signal_diff.mag() ) art = ax31.pcolormesh(signed, norm=norm, cmap=signed_cmap, autolabel="both") fig.colorbar(art, ax=ax31) @@ -146,4 +135,4 @@ else: ax.set_xlim(signed.w1.min(), signed.w1.max()) -plt.show() \ No newline at end of file +plt.show() From 1622cd9739234d50797d592c02695530d3b9191b Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Sun, 31 Mar 2024 13:54:06 -0500 Subject: [PATCH 15/22] abandon using datasets as module --- docs/conf.py | 2 +- examples/norms.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index eb236c4cd..f36ad6cd2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -105,7 +105,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/examples/norms.py b/examples/norms.py index 30752d2eb..0f756d4e5 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -5,11 +5,14 @@ import WrightTools as wt from WrightTools import datasets + import matplotlib.colors as mpl_colors import matplotlib.pyplot as plt -import numpy as np from matplotlib import colormaps as colormaps +import numpy as np +import pathlib + # --- colormaps ----------------------------------------------------------------------------------- unsigned_cmap = [ @@ -26,7 +29,8 @@ # --- data ---------------------------------------------------------------------------------------- -signed = wt.open(datasets.wt5.v1p0p0_perovskite_TA).at(d2=[-15, "fs"]).split("w1", [1.6])[1] +p = pathlib.Path(datasets.__file__).parent / "wt5" / "v1.0.0" / "perovskite_TA.wt5" +signed = wt.open(p).at(d2=[-15, "fs"]).split("w1", [1.6])[1] signed.bring_to_front("signal_diff") unsigned = wt.data.from_PyCMDS(r"https://osf.io/75vny/download") From 5cd0cf5cf01f6198561b5f3be2b3516ad8eac7eb Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:57:00 -0500 Subject: [PATCH 16/22] try new load method --- WrightTools/datasets/__init__.py | 65 +++++++++++++++++--------------- docs/conf.py | 10 +++-- examples/norms.py | 3 +- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/WrightTools/datasets/__init__.py b/WrightTools/datasets/__init__.py index c6168a932..68c7fa03c 100644 --- a/WrightTools/datasets/__init__.py +++ b/WrightTools/datasets/__init__.py @@ -47,52 +47,57 @@ def _from_directory(self, dirname, prefix=""): setattr(self, n, ps) +BrunoldrRaman = DatasetContainer() +Cary = DatasetContainer() +COLORS = DatasetContainer() +JASCO = DatasetContainer() +KENT = DatasetContainer() +LabRAM = DatasetContainer() +ocean_optics = DatasetContainer() +PyCMDS = DatasetContainer() +Shimadzu = DatasetContainer() +Solis = DatasetContainer() +spcm = DatasetContainer() +Tensor27 = DatasetContainer() +wt5 = DatasetContainer() + + # --- fill ---------------------------------------------------------------------------------------- -BrunoldrRaman = DatasetContainer() -BrunoldrRaman._from_files(here / "BrunoldrRaman") +def _populate_containers(): + BrunoldrRaman._from_files(here / "BrunoldrRaman") -Cary = DatasetContainer() -Cary._from_files("Cary") + Cary._from_files("Cary") -COLORS = DatasetContainer() -COLORS._from_files(here / "COLORS" / "v0.2", prefix="v0p2_") -COLORS._from_files(here / "COLORS" / "v2.2", prefix="v2p2_") + COLORS._from_files(here / "COLORS" / "v0.2", prefix="v0p2_") + COLORS._from_files(here / "COLORS" / "v2.2", prefix="v2p2_") -JASCO = DatasetContainer() -JASCO._from_files("JASCO") + JASCO._from_files("JASCO") -KENT = DatasetContainer() -KENT._from_directory(here / "KENT" / "LDS821 TRSF") -KENT._from_directory(here / "KENT" / "LDS821 DOVE") -KENT._from_directory(here / "KENT" / "PbSe 2D delay B") + KENT._from_directory(here / "KENT" / "LDS821 TRSF") + KENT._from_directory(here / "KENT" / "LDS821 DOVE") + KENT._from_directory(here / "KENT" / "PbSe 2D delay B") -LabRAM = DatasetContainer() -LabRAM._from_files(here / "LabRAM") + LabRAM._from_files(here / "LabRAM") -ocean_optics = DatasetContainer() -ocean_optics._from_files("ocean_optics") + ocean_optics._from_files("ocean_optics") -PyCMDS = DatasetContainer() -PyCMDS._from_files("PyCMDS") + PyCMDS._from_files("PyCMDS") -Shimadzu = DatasetContainer() -Shimadzu._from_files("Shimadzu") + Shimadzu._from_files("Shimadzu") -Solis = DatasetContainer() -Solis._from_files("Solis") + Solis._from_files("Solis") -spcm = DatasetContainer() -spcm._from_files("spcm") + spcm._from_files("spcm") -Tensor27 = DatasetContainer() -Tensor27._from_files("Tensor27") + Tensor27._from_files("Tensor27") + + wt5._from_files(here / "wt5" / "v1.0.0", prefix="v1p0p0_") + wt5._from_files(here / "wt5" / "v1.0.1", prefix="v1p0p1_") -wt5 = DatasetContainer() -wt5._from_files(here / "wt5" / "v1.0.0", prefix="v1p0p0_") -wt5._from_files(here / "wt5" / "v1.0.1", prefix="v1p0p1_") +_populate_containers() # --- pretty namespace ---------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index f36ad6cd2..3747fa6ef 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,6 +24,7 @@ # import sphinx_gallery import math import pathlib +import importlib # --- define ------------------------------------------------------------------------------------- @@ -236,9 +237,10 @@ def reset_wt(gallery_conf, fname): # This is an awful hack because python does not allow unloading modules # This is, however, the same thing upstream sphinx-gallery does for # seaborn, so it's not _so_ bad I guess. 2019-04-07 KFS - for module in list(sys.modules.keys()): - if module.startswith("WrightTools.datasets"): - del sys.modules[module] + from WrightTools import datasets + datasets_module = sys.modules.get("WrightTools.datasets") + if datasets_module is not None: + datasets._populate_containers() sphinx_gallery_conf = { @@ -247,7 +249,7 @@ def reset_wt(gallery_conf, fname): "gallery_dirs": "auto_examples", "backreferences_dir": os.path.join("gen_modules", "backreferences"), "reset_modules": ["matplotlib", reset_wt], - "reset_module_order": "both", + "reset_module_order": "before", } diff --git a/examples/norms.py b/examples/norms.py index 0f756d4e5..ac56254ca 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -29,7 +29,8 @@ # --- data ---------------------------------------------------------------------------------------- -p = pathlib.Path(datasets.__file__).parent / "wt5" / "v1.0.0" / "perovskite_TA.wt5" +# p = pathlib.Path(datasets.__file__).parent / "wt5" / "v1.0.0" / "perovskite_TA.wt5" +p = datasets.wt5.v1p0p0_perovskite_TA signed = wt.open(p).at(d2=[-15, "fs"]).split("w1", [1.6])[1] signed.bring_to_front("signal_diff") From 0be6b2e5b6c42c7331b9e989215fc4336bba4329 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:23:18 -0500 Subject: [PATCH 17/22] datasets us SimpleNamespace still trying to fix sphinx build test --- WrightTools/datasets/__init__.py | 83 ++++++++++++++++---------------- examples/norms.py | 2 - 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/WrightTools/datasets/__init__.py b/WrightTools/datasets/__init__.py index 68c7fa03c..7119593b7 100644 --- a/WrightTools/datasets/__init__.py +++ b/WrightTools/datasets/__init__.py @@ -4,6 +4,7 @@ import pathlib +from types import SimpleNamespace from .. import kit as wt_kit @@ -17,8 +18,27 @@ # --- container class ----------------------------------------------------------------------------- -class DatasetContainer(object): - def _from_files(self, dirname, prefix=""): +BrunoldrRaman = SimpleNamespace() +Cary = SimpleNamespace() +COLORS = SimpleNamespace() +JASCO = SimpleNamespace() +KENT = SimpleNamespace() +LabRAM = SimpleNamespace() +ocean_optics = SimpleNamespace() +PyCMDS = SimpleNamespace() +Shimadzu = SimpleNamespace() +Solis = SimpleNamespace() +spcm = SimpleNamespace() +Tensor27 = SimpleNamespace() +wt5 = SimpleNamespace() + + +# --- fill ---------------------------------------------------------------------------------------- + + +def _populate_containers(): + + def _from_files(obj, dirname, prefix=""): """Add datasets from files in a directory. Parameters @@ -30,9 +50,9 @@ def _from_files(self, dirname, prefix=""): """ for p in (here / dirname).iterdir(): n = prefix + wt_kit.string2identifier(p.name.split(".")[0]) - setattr(self, n, p) + setattr(obj, n, p) - def _from_directory(self, dirname, prefix=""): + def _from_directory(obj, dirname, prefix=""): """Add dataset from files in a directory. Parameters @@ -44,57 +64,38 @@ def _from_directory(self, dirname, prefix=""): """ ps = list((here / dirname).iterdir()) n = prefix + wt_kit.string2identifier(dirname.name) - setattr(self, n, ps) + setattr(obj, n, ps) -BrunoldrRaman = DatasetContainer() -Cary = DatasetContainer() -COLORS = DatasetContainer() -JASCO = DatasetContainer() -KENT = DatasetContainer() -LabRAM = DatasetContainer() -ocean_optics = DatasetContainer() -PyCMDS = DatasetContainer() -Shimadzu = DatasetContainer() -Solis = DatasetContainer() -spcm = DatasetContainer() -Tensor27 = DatasetContainer() -wt5 = DatasetContainer() - - -# --- fill ---------------------------------------------------------------------------------------- - - -def _populate_containers(): - BrunoldrRaman._from_files(here / "BrunoldrRaman") + _from_files(BrunoldrRaman, here / "BrunoldrRaman") - Cary._from_files("Cary") + _from_files(Cary, "Cary") - COLORS._from_files(here / "COLORS" / "v0.2", prefix="v0p2_") - COLORS._from_files(here / "COLORS" / "v2.2", prefix="v2p2_") + _from_files(COLORS, here / "COLORS" / "v0.2", prefix="v0p2_") + _from_files(COLORS, here / "COLORS" / "v2.2", prefix="v2p2_") - JASCO._from_files("JASCO") + _from_files(JASCO, "JASCO") - KENT._from_directory(here / "KENT" / "LDS821 TRSF") - KENT._from_directory(here / "KENT" / "LDS821 DOVE") - KENT._from_directory(here / "KENT" / "PbSe 2D delay B") + _from_directory(KENT, here / "KENT" / "LDS821 TRSF") + _from_directory(KENT, here / "KENT" / "LDS821 DOVE") + _from_directory(KENT, here / "KENT" / "PbSe 2D delay B") - LabRAM._from_files(here / "LabRAM") + _from_files(LabRAM, here / "LabRAM") - ocean_optics._from_files("ocean_optics") + _from_files(ocean_optics, "ocean_optics") - PyCMDS._from_files("PyCMDS") + _from_files(PyCMDS, "PyCMDS") - Shimadzu._from_files("Shimadzu") + _from_files(Shimadzu, "Shimadzu") - Solis._from_files("Solis") + _from_files(Solis, "Solis") - spcm._from_files("spcm") + _from_files(spcm, "spcm") - Tensor27._from_files("Tensor27") + _from_files(Tensor27, "Tensor27") - wt5._from_files(here / "wt5" / "v1.0.0", prefix="v1p0p0_") - wt5._from_files(here / "wt5" / "v1.0.1", prefix="v1p0p1_") + _from_files(wt5, here / "wt5" / "v1.0.0", prefix="v1p0p0_") + _from_files(wt5, here / "wt5" / "v1.0.1", prefix="v1p0p1_") _populate_containers() diff --git a/examples/norms.py b/examples/norms.py index ac56254ca..10ccf5365 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -139,5 +139,3 @@ ax.set_xlim(unsigned.w2.min(), unsigned.w2.max()) else: ax.set_xlim(signed.w1.min(), signed.w1.max()) - -plt.show() From 813228a8a58ddff797f31f9960536c3560c84463 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:40:56 -0500 Subject: [PATCH 18/22] Update norms.py --- examples/norms.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/norms.py b/examples/norms.py index 10ccf5365..694edeb43 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -11,7 +11,6 @@ from matplotlib import colormaps as colormaps import numpy as np -import pathlib # --- colormaps ----------------------------------------------------------------------------------- @@ -29,7 +28,6 @@ # --- data ---------------------------------------------------------------------------------------- -# p = pathlib.Path(datasets.__file__).parent / "wt5" / "v1.0.0" / "perovskite_TA.wt5" p = datasets.wt5.v1p0p0_perovskite_TA signed = wt.open(p).at(d2=[-15, "fs"]).split("w1", [1.6])[1] signed.bring_to_front("signal_diff") From 274f78954ecf47359f0abbeb9232b2423d6d2ac3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:41:11 +0000 Subject: [PATCH 19/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- WrightTools/datasets/__init__.py | 1 - docs/conf.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/WrightTools/datasets/__init__.py b/WrightTools/datasets/__init__.py index 7119593b7..9fc587898 100644 --- a/WrightTools/datasets/__init__.py +++ b/WrightTools/datasets/__init__.py @@ -66,7 +66,6 @@ def _from_directory(obj, dirname, prefix=""): n = prefix + wt_kit.string2identifier(dirname.name) setattr(obj, n, ps) - _from_files(BrunoldrRaman, here / "BrunoldrRaman") _from_files(Cary, "Cary") diff --git a/docs/conf.py b/docs/conf.py index 3747fa6ef..2daeb09a2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -238,6 +238,7 @@ def reset_wt(gallery_conf, fname): # This is, however, the same thing upstream sphinx-gallery does for # seaborn, so it's not _so_ bad I guess. 2019-04-07 KFS from WrightTools import datasets + datasets_module = sys.modules.get("WrightTools.datasets") if datasets_module is not None: datasets._populate_containers() From 35fc3a25ce7585292f28a452c516f5071a132343 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:10:40 -0500 Subject: [PATCH 20/22] codeql --- docs/conf.py | 1 - examples/norms.py | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 2daeb09a2..7efb43230 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,6 @@ # import sphinx_gallery import math import pathlib -import importlib # --- define ------------------------------------------------------------------------------------- diff --git a/examples/norms.py b/examples/norms.py index 694edeb43..9026b1773 100644 --- a/examples/norms.py +++ b/examples/norms.py @@ -7,7 +7,6 @@ from WrightTools import datasets import matplotlib.colors as mpl_colors -import matplotlib.pyplot as plt from matplotlib import colormaps as colormaps import numpy as np @@ -55,7 +54,7 @@ # --- --- sqrt ------------------------------------------------------------------------------------ ax10 = fig.add_subplot(gs[1, 0], label="10 - unsigned sqrt") wt.artists.corner_text("sqrt", **label_kwargs) -norm = mpl_colors.PowerNorm(gamma=0.5, vmin=0) +# norm = mpl_colors.PowerNorm(gamma=0.5, vmin=0) """ NOTE: a bug with PowerNorm makes the colorbar extend arrow incorrect color as recently as mpl 3.8.3. @@ -67,7 +66,7 @@ _inverse = lambda x: np.sign(x) * x**2 norm = mpl_colors.FuncNorm((_forward, _inverse), vmin=0, clip=False) art = ax10.pcolormesh(unsigned, norm=norm, cmap=unsigned_cmap, autolabel="y") -cb = fig.colorbar(art, ax=ax10, extend="min") +fig.colorbar(art, ax=ax10, extend="min") # --- --- log10 ----------------------------------------------------------------------------------- ax20 = fig.add_subplot(gs[2, 0], label="20 - unsigned log") From fa536edde1cbcb7b478ff8f6cae4b3b30f3278d6 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 3 May 2024 10:34:20 -0500 Subject: [PATCH 21/22] axis_label_from_data, deprecation warnings --- WrightTools/artists/_helpers.py | 59 ++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py index 4f12e2047..4f07a16af 100644 --- a/WrightTools/artists/_helpers.py +++ b/WrightTools/artists/_helpers.py @@ -30,18 +30,19 @@ __all__ = [ "_title", + "axis_label_from_data", "add_sideplot", "corner_text", "create_figure", "diagonal_line", "get_scaled_bounds", "norm_from_channel", - "pcolor_helper", - "plot_colorbar", + "pcolor_helper", # deprecation imminent + "plot_colorbar", # to be deprecated (use mpl methods) "plot_margins", - "plot_gridlines", + "plot_gridlines", # to be deprecated (use mpl methods, styles) "savefig", - "set_ax_labels", + "set_ax_labels", # to be deprecated (use mpl methods, styles) "set_ax_spines", "set_fig_labels", "subplots_adjust", @@ -53,6 +54,34 @@ # --- functions ----------------------------------------------------------------------------------- +def axis_label_from_data(data, ax=None, cax=None, which="both", channel_index=0): + """Apply x and/or y labels to axes. + Parameters + ---------- + data : WrightTools.Data + data from which to extract the label(s) + ax : Axis object (optional) + Default is current axis + autolabel : {'none', 'both', 'x', 'y'} (optional) + Label(s) to apply from data. Default is none. + channel_index : integer (optional) + Channel index. Default is 0. Only important for 2D data + """ + if ax is None: + ax = plt.gca() + if which in ["both", "x"]: + xlabel = data.axes[0].label + ax.set_xlabel(xlabel) + if which in ["both", "y"]: + if data.ndim == 1: + ylabel = data.channels[channel_index].label + elif data.ndim == 2: + ylabel = data.axes[1].label + else: + raise wt_exceptions.DimensionalityError("<=3", data.ndim) + ax.set_ylabel(ylabel) + + def _title(fig, title, subtitle="", *, margin=1, fontsize=20, subfontsize=18): """Add a title to a figure. @@ -812,6 +841,13 @@ def plot_gridlines(ax=None, c="grey", lw=1, diagonal=False, zorder=2, makegrid=T zorder : number (optional) zorder of plotted grid. Default is 2. """ + warnings.warn( + "``plot_gridlines`` is deprecated and will be removed in a future version. " + + "Use matplotlib's ``grid`` methods instead", + wt_exceptions.VisibleDeprecationWarning, + ) + + # get ax if ax is None: ax = plt.gca() @@ -918,6 +954,11 @@ def set_ax_labels(ax=None, xlabel=None, ylabel=None, xticks=None, yticks=None, l -------- set_fig_labels """ + warnings.warn( + "``set_ax_labels`` is deprecated and will be removed in a future version. " + + "Use matplotlib's ``set_xlabel`` and ``set_ylabel`` methods instead", + wt_exceptions.VisibleDeprecationWarning, + ) # get ax if ax is None: ax = plt.gca() @@ -1029,14 +1070,8 @@ def set_fig_labels( for ax in fig.axes: if ax.is_sideplot: continue - try: - # [row|col]span were introduced in matplotlib 3.2 - # this try/except can be removed when supprot for mpl < 3.2 is dropped - rowNum = ax.get_subplotspec().rowspan.start - colNum = ax.get_subplotspec().colspan.start - except AttributeError: - rowNum = ax.rowNum - colNum = ax.colNum + rowNum = ax.get_subplotspec().rowspan.start + colNum = ax.get_subplotspec().colspan.start if row_start <= rowNum <= row_stop and col_start <= colNum <= col_stop: if colNum == col_start: set_ax_labels(ax=ax, ylabel=ylabel, yticks=yticks, label_fontsize=label_fontsize) From 537c93fa9a0c53a5244d5b569019159331ccb446 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 15:34:38 +0000 Subject: [PATCH 22/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- WrightTools/artists/_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/WrightTools/artists/_helpers.py b/WrightTools/artists/_helpers.py index 4f07a16af..1d019681e 100644 --- a/WrightTools/artists/_helpers.py +++ b/WrightTools/artists/_helpers.py @@ -847,7 +847,6 @@ def plot_gridlines(ax=None, c="grey", lw=1, diagonal=False, zorder=2, makegrid=T wt_exceptions.VisibleDeprecationWarning, ) - # get ax if ax is None: ax = plt.gca()