From 3fa8df7fc3bcccde78f364862b7533b833d00052 Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Wed, 5 Feb 2020 11:05:57 -0500 Subject: [PATCH 1/2] minor fixes in viz module --- pydrad/visualize/plot.py | 41 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pydrad/visualize/plot.py b/pydrad/visualize/plot.py index 9dc3ecb..959ffb9 100644 --- a/pydrad/visualize/plot.py +++ b/pydrad/visualize/plot.py @@ -60,6 +60,7 @@ def plot_strand(strand, limits=None, cmap='viridis', **kwargs): # Parameters strand (#pydrad.parse.Strand): Loop strand object limits (`dict`): Set axes limits for hydrodynamic quantities, optional + cmap (`str`): The colormap to map the timestep index to plot_kwargs (`dict`): Any keyword arguments used matplotlib.plot, optional figsize (`tuple`): Width and height of figure, optional """ @@ -68,7 +69,6 @@ def plot_strand(strand, limits=None, cmap='viridis', **kwargs): fig, axes = _setup_figure(strand[0], limits, **kwargs) colors = matplotlib.colors.LinearSegmentedColormap.from_list( '', plt.get_cmap(cmap).colors, N=len(strand)) - # NOTE: once strand indexing is fixed, we can index it directly for i, p in enumerate(strand): plot_kwargs['color'] = colors(i) _ = _plot_profile(p, axes, **plot_kwargs) @@ -76,9 +76,16 @@ def plot_strand(strand, limits=None, cmap='viridis', **kwargs): def plot_profile(profile, **kwargs): - limits = kwargs.get('limits', {}) - if 'limits' in kwargs: - del kwargs['limits'] + """ + Plot hydrodynamic quantites at a single timestep + + # Parameters + profile (#pydrad.parse.Strand): Loop profile object + limits (`dict`): Set axes limits for hydrodynamic quantities, optional + plot_kwargs (`dict`): Any keyword arguments used matplotlib.plot, optional + figsize (`tuple`): Width and height of figure, optional + """ + limits = kwargs.pop('limits', {}) plot_kwargs = kwargs.get('plot_kwargs', {}) fig, axes = _setup_figure(profile, limits, **kwargs) _plot_profile(profile, axes, **plot_kwargs) @@ -96,7 +103,7 @@ def _setup_figure(profile, limits, **kwargs): axes[1, 0].set_ylim(limits.get('pressure', (0.1, 1e2))) axes[1, 0].set_yscale('log') axes[1, 1].set_ylim(limits.get('velocity', (-5e7, 5e7))) - axes[1, 1].set_xlim(0, profile.coordinate[-1].to(u.cm).value) + axes[1, 1].set_xlim(profile.coordinate[[0, -1]].to(u.Mm).value) # Labels axes[0, 0].set_ylabel(r'$T$ [MK]') axes[0, 1].set_ylabel(r'$n$ [cm$^{-3}$]') @@ -110,44 +117,44 @@ def _setup_figure(profile, limits, **kwargs): def _plot_profile(profile, axes, **kwargs): line1a, = axes[0, 0].plot( - profile.coordinate.to(u.cm), + profile.coordinate.to(u.Mm), profile.electron_temperature.to(u.MK), **kwargs, ls='-' ) line1b, = axes[0, 0].plot( - profile.coordinate.to(u.cm), + profile.coordinate.to(u.Mm), profile.ion_temperature.to(u.MK), **kwargs, ls='--' ) line2a, = axes[0, 1].plot( - profile.coordinate.to(u.cm), - profile.electron_density, + profile.coordinate.to(u.Mm), + profile.electron_density.to(u.cm**(-3)), **kwargs, ls='-' ) line2b, = axes[0, 1].plot( - profile.coordinate.to(u.cm), - profile.ion_density, + profile.coordinate.to(u.Mm), + profile.ion_density.to(u.cm**(-3)), **kwargs, ls='--' ) line3a, = axes[1, 0].plot( - profile.coordinate.to(u.cm), - profile.electron_pressure, + profile.coordinate.to(u.Mm), + profile.electron_pressure.to(u.dyne / (u.cm**2 * u.s)), **kwargs, ls='-' ) line3b, = axes[1, 0].plot( - profile.coordinate.to(u.cm), - profile.ion_pressure, + profile.coordinate.to(u.Mm), + profile.ion_pressure.to(u.dyne / (u.cm**2 * u.s)), **kwargs, ls='--' ) line4, = axes[1, 1].plot( - profile.coordinate.to(u.cm), - profile.velocity, + profile.coordinate.to(u.Mm), + profile.velocity.to(u.km/u.s), **kwargs ) return line1a, line1b, line2a, line2b, line3a, line3b, line4 From e5c9aa4dd092744231120083b8c9102fb0f321bc Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Wed, 5 Feb 2020 11:19:34 -0500 Subject: [PATCH 2/2] few more lingering unit bugs --- pydrad/visualize/animate.py | 23 ++++++++++++----------- pydrad/visualize/plot.py | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pydrad/visualize/animate.py b/pydrad/visualize/animate.py index ba415fb..80b5740 100644 --- a/pydrad/visualize/animate.py +++ b/pydrad/visualize/animate.py @@ -20,26 +20,27 @@ def animate_strand(strand, **kwargs): limits = kwargs.get('limits', {}) if 'limits' in kwargs: del kwargs['limits'] - # Initialize figure fig, axes = _setup_figure(strand[0], limits, **kwargs) + # Make sure the lines stay the same color if 'color' not in plot_kwargs: plot_kwargs['color'] = 'C0' l1a, l1b, l2a, l2b, l3a, l3b, l4 = _plot_profile(strand[0], axes, **plot_kwargs) - # Update function + def update_plot(i): - profile = strand[i] - l1a.set_data(profile.coordinate.to(u.cm), profile.electron_temperature.to(u.MK)) - l1b.set_data(profile.coordinate.to(u.cm), profile.ion_temperature.to(u.MK)) - l2a.set_data(profile.coordinate.to(u.cm), profile.electron_density) - l2b.set_data(profile.coordinate.to(u.cm), profile.ion_density) - l3a.set_data(profile.coordinate.to(u.cm), profile.electron_pressure) - l3b.set_data(profile.coordinate.to(u.cm), profile.ion_pressure) - l4.set_data(profile.coordinate.to(u.cm), profile.velocity) - fig.suptitle(r'$t={:4.0f}$ {}'.format( + p = strand[i] + l1a.set_data(p.coordinate.to(u.Mm), p.electron_temperature.to(u.MK)) + l1b.set_data(p.coordinate.to(u.Mm), p.ion_temperature.to(u.MK)) + l2a.set_data(p.coordinate.to(u.Mm), p.electron_density.to(u.cm**(-3))) + l2b.set_data(p.coordinate.to(u.Mm), p.ion_density.to(u.cm**(-3))) + l3a.set_data(p.coordinate.to(u.Mm), p.electron_pressure.to(u.dyne/(u.cm**2))) + l3b.set_data(p.coordinate.to(u.Mm), p.ion_pressure.to(u.dyne/(u.cm**2))) + l4.set_data(p.coordinate.to(u.Mm), p.velocity.to(u.km/u.s)) + fig.suptitle(r'$t={:.0f}$ {}'.format( strand.time[i].value, strand.time[i].unit), y=0.905) return l1a, l1b, l2a, l2b, l3a, l3b, l4 + return FuncAnimation( fig, update_plot, blit=kwargs.get('blit', True), frames=len(strand), interval=kwargs.get('interval', 10), repeat=kwargs.get('repeat', True)) diff --git a/pydrad/visualize/plot.py b/pydrad/visualize/plot.py index 959ffb9..b6ae41e 100644 --- a/pydrad/visualize/plot.py +++ b/pydrad/visualize/plot.py @@ -102,13 +102,13 @@ def _setup_figure(profile, limits, **kwargs): axes[0, 1].set_yscale('log') axes[1, 0].set_ylim(limits.get('pressure', (0.1, 1e2))) axes[1, 0].set_yscale('log') - axes[1, 1].set_ylim(limits.get('velocity', (-5e7, 5e7))) + axes[1, 1].set_ylim(limits.get('velocity', (-1e2, 1e2))) axes[1, 1].set_xlim(profile.coordinate[[0, -1]].to(u.Mm).value) # Labels axes[0, 0].set_ylabel(r'$T$ [MK]') axes[0, 1].set_ylabel(r'$n$ [cm$^{-3}$]') axes[1, 0].set_ylabel(r'$P$ [dyne cm$^{-2}$ s$^{-1}$]') - axes[1, 1].set_ylabel(r'$v$ [cm s$^{-1}$]') + axes[1, 1].set_ylabel(r'$v$ [km s$^{-1}$]') axes[1, 0].set_xlabel(r'$s$ [Mm]') axes[1, 1].set_xlabel(r'$s$ [Mm]') @@ -142,13 +142,13 @@ def _plot_profile(profile, axes, **kwargs): ) line3a, = axes[1, 0].plot( profile.coordinate.to(u.Mm), - profile.electron_pressure.to(u.dyne / (u.cm**2 * u.s)), + profile.electron_pressure.to(u.dyne / (u.cm**2)), **kwargs, ls='-' ) line3b, = axes[1, 0].plot( profile.coordinate.to(u.Mm), - profile.ion_pressure.to(u.dyne / (u.cm**2 * u.s)), + profile.ion_pressure.to(u.dyne / (u.cm**2)), **kwargs, ls='--' )