def run_mag_test(fld, title="", show=False): vx, vy, vz = fld.component_views() # pylint: disable=W0612 vx, vy, vz = fld.component_fields() try: t0 = time() mag_ne = viscid.magnitude(fld, preferred="numexpr", only=False) t1 = time() logger.info("numexpr mag runtime: %g", t1 - t0) except viscid.verror.BackendNotFound: xfail("Numexpr is not installed") planes = ["z=0", "y=0"] nrows = 4 ncols = len(planes) _, axes = plt.subplots(nrows, ncols, sharex=True, sharey=True, squeeze=False) for ind, p in enumerate(planes): vlt.plot(vx, p, ax=axes[0, ind], show=False) vlt.plot(vy, p, ax=axes[1, ind], show=False) vlt.plot(vz, p, ax=axes[2, ind], show=False) vlt.plot(mag_ne, p, ax=axes[3, ind], show=False) plt.suptitle(title) vlt.auto_adjust_subplots(subplot_params=dict(top=0.9, right=0.9)) plt.gcf().set_size_inches(6, 7) plt.savefig(next_plot_fname(__file__)) if show: vlt.mplshow()
def run_mag_test(fld, title="", show=False): vx, vy, vz = fld.component_views() # pylint: disable=W0612 vx, vy, vz = fld.component_fields() try: t0 = time() mag_ne = viscid.magnitude(fld, preferred="numexpr", only=False) t1 = time() logger.info("numexpr mag runtime: %g", t1 - t0) except viscid.verror.BackendNotFound: xfail("Numexpr is not installed") planes = ["z=0", "y=0"] nrows = 4 ncols = len(planes) ax = plt.subplot2grid((nrows, ncols), (0, 0)) ax.axis("equal") for ind, p in enumerate(planes): plt.subplot2grid((nrows, ncols), (0, ind), sharex=ax, sharey=ax) mpl.plot(vx, p, show=False) plt.subplot2grid((nrows, ncols), (1, ind), sharex=ax, sharey=ax) mpl.plot(vy, p, show=False) plt.subplot2grid((nrows, ncols), (2, ind), sharex=ax, sharey=ax) mpl.plot(vz, p, show=False) plt.subplot2grid((nrows, ncols), (3, ind), sharex=ax, sharey=ax) mpl.plot(mag_ne, p, show=False) mpl.plt.suptitle(title) mpl.auto_adjust_subplots(subplot_params=dict(top=0.9)) mpl.plt.gcf().set_size_inches(6, 7) mpl.plt.savefig(next_plot_fname(__file__)) if show: mpl.mplshow()
def main(): parser = argparse.ArgumentParser(description="Test quasi potential") parser.add_argument("--show", "--plot", action="store_true") args = vutil.common_argparse(parser) b, e = make_arcade(8.0, N=[64, 64, 64]) epar = viscid.project(e, b) epar.pretty_name = "E parallel" ############### # Calculate Xi seeds = viscid.Volume(xl=[-10, 0.0, -10], xh=[10, 0.0, 10], n=[64, 1, 64]) b_lines, _ = viscid.calc_streamlines(b, seeds) xi_dat = viscid.integrate_along_lines(b_lines, e, reduction='dot') xi = seeds.wrap_field(xi_dat, name='xi', pretty_name=r"$\Xi$") ################################ # Make 2D Matplotlib plot of Xi mpl.plot(xi, x=(-10, 10), y=(-10, 10), style='contourf', levels=256, lin=(2e-4, 1.5718)) mpl.plot(xi, x=(-10, 10), y=(-10, 10), style='contour', colors='grey', levels=[0.5, 1.0]) mpl.savefig(next_plot_fname(__file__)) if args.show: mpl.show() ############################################################ # Make 3D mayavi plot of Xi and the 'brightest' field lines # as well as some other field lines for context try: from viscid.plot import mvi except ImportError: xfail("Mayavi not installed") mvi.figure(size=[1200, 800], offscreen=not args.show) inds = np.argsort(xi_dat)[-64:] inds = np.concatenate([inds, np.arange(len(xi_dat))[::71]]) s = mvi.plot_lines(b_lines[inds], scalars=epar, cmap='viridis') mvi.mesh_from_seeds(seeds, scalars=xi, cmap='inferno') mvi.colorbar(s, orientation='horizontal', title=epar.pretty_name) # mvi.streamline(b, scalars=e, seedtype='sphere', seed_resolution=4, # integration_direction='both') oa = mvi.orientation_axes() oa.marker.set_viewport(0.75, 0.75, 1.0, 1.0) mvi.view(roll=0, azimuth=90, elevation=25, distance=30.0, focalpoint=[0, 2, 0]) mvi.savefig(next_plot_fname(__file__)) if args.show: mvi.show()
def _main(): parser = argparse.ArgumentParser(description=__doc__) _ = vutil.common_argparse(parser) if _HAS_SCIPY: warnings.filterwarnings("ignore", category=OptimizeWarning) f = viscid.load_file(os.path.join(sample_dir, 'sample_xdmf.3d.[0].xdmf')) mp = viscid.get_mp_info(f['pp'], f['b'], f['j'], f['e_cc'], fit='mp_xloc', slc="x=7f:12.0f, y=-6f:6f, z=-6f:6f", cache=False) Y, Z = mp['pp_max_xloc'].meshgrid(prune=True) # # get normals from paraboloid surface if isinstance(mp['paraboloid'], viscid.DeferredImportError): xfail("Scipy not installed; paraboloid curve fitting not tested") else: parab_n = viscid.paraboloid_normal(Y, Z, *mp['paraboloid'][0]) parab_n = parab_n.reshape(3, -1) # get normals from minvar minvar_y = Y.reshape(-1) minvar_z = Z.reshape(-1) minvar_n = np.zeros([3, len(minvar_y)]) for i in range(minvar_n.shape[1]): p0 = [0.0, minvar_y[i], minvar_z[i]] p0[0] = mp['pp_max_xloc']['y={0[0]}f, z={0[1]}f'.format(p0)] lmn = viscid.find_minvar_lmn_around(f['b'], p0, l=2.0, n=64) minvar_n[:, i] = lmn[2, :] theta = (180 / np.pi) * np.arccos(np.sum(parab_n * minvar_n, axis=0)) # make sure paraboloid normals and minvar normals are closeish # this is a poor check, but at least it's something assert np.min(theta) < 3.0 assert np.average(theta) < 20.0 assert np.median(theta) < 20.0 assert np.max(theta) < 70.0 return 0
def _main(): parser = argparse.ArgumentParser(description=__doc__) _ = vutil.common_argparse(parser) if _HAS_SCIPY: warnings.filterwarnings("ignore", category=OptimizeWarning) f = viscid.load_file(os.path.join(sample_dir, 'sample_xdmf.3d.[0].xdmf')) mp = viscid.get_mp_info(f['pp'], f['b'], f['j'], f['e_cc'], fit='mp_xloc', slc="x=7j:12.0j, y=-6j:6j, z=-6j:6j", cache=False) Y, Z = mp['pp_max_xloc'].meshgrid(prune=True) # # get normals from paraboloid surface if isinstance(mp['paraboloid'], viscid.DeferredImportError): xfail("Scipy not installed; paraboloid curve fitting not tested") else: parab_n = viscid.paraboloid_normal(Y, Z, *mp['paraboloid'][0]) parab_n = parab_n.reshape(3, -1) # get normals from minvar minvar_y = Y.reshape(-1) minvar_z = Z.reshape(-1) minvar_n = np.zeros([3, len(minvar_y)]) for i in range(minvar_n.shape[1]): p0 = [0.0, minvar_y[i], minvar_z[i]] p0[0] = mp['pp_max_xloc']['y={0[0]}f, z={0[1]}f'.format(p0)] lmn = viscid.find_minvar_lmn_around(f['b'], p0, l=2.0, n=64) minvar_n[:, i] = lmn[2, :] theta = (180 / np.pi) * np.arccos(np.sum(parab_n * minvar_n, axis=0)) # make sure paraboloid normals and minvar normals are closeish # this is a poor check, but at least it's something assert np.min(theta) < 3.0 assert np.average(theta) < 20.0 assert np.median(theta) < 20.0 assert np.max(theta) < 70.0 return 0
from __future__ import print_function import argparse import os import sys from viscid_test_common import next_plot_fname, xfail import numpy as np import viscid from viscid import sample_dir from viscid import vutil try: from viscid.plot import vlab except ImportError: xfail("Mayavi not installed") # In this test, the OpenGGCM reader needs to read the log file # in order to determine the crds when doing the cotr transformation. # In general, this flag is useful to put in your viscidrc file, see # the corresponding page in the tutorial for more information. viscid.readers.openggcm.GGCMFile.read_log_file = True viscid.readers.openggcm.GGCMGrid.mhd_to_gse_on_read = "auto" def _main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--show", "--plot", action="store_true") parser.add_argument("--interact", "-i", action="store_true") args = vutil.common_argparse(parser)
def _main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--show", "--plot", action="store_true") args = vutil.common_argparse(parser) b, e = make_arcade(8.0, N=[64, 64, 64]) epar = viscid.project(e, b) epar.pretty_name = "E parallel" ############### # Calculate Xi seeds = viscid.Volume(xl=[-10, 0.0, -10], xh=[10, 0.0, 10], n=[64, 1, 64]) b_lines, _ = viscid.calc_streamlines(b, seeds) xi_dat = viscid.integrate_along_lines(b_lines, e, reduction='dot') xi = seeds.wrap_field(xi_dat, name='xi', pretty_name=r"$\Xi$") ################################ # Make 2D Matplotlib plot of Xi vlt.plot(xi, x=(-10, 10), y=(-10, 10), style='contourf', levels=256, lin=(2e-4, 1.5718)) vlt.plot(xi, x=(-10, 10), y=(-10, 10), style='contour', colors='grey', levels=[0.5, 1.0]) vlt.savefig(next_plot_fname(__file__)) if args.show: vlt.show() ############################################################ # Make 3D mayavi plot of Xi and the 'brightest' field lines # as well as some other field lines for context try: from viscid.plot import vlab except ImportError: xfail("Mayavi not installed") vlab.figure(size=[1200, 800], offscreen=not args.show) inds = np.argsort(xi_dat)[-64:] inds = np.concatenate([inds, np.arange(len(xi_dat))[::71]]) s = vlab.plot_lines(b_lines[inds], scalars=epar, cmap='viridis') vlab.mesh_from_seeds(seeds, scalars=xi, cmap='inferno') vlab.colorbar(s, orientation='horizontal', title=epar.pretty_name) # vlab.streamline(b, scalars=e, seedtype='sphere', seed_resolution=4, # integration_direction='both') oa = vlab.orientation_axes() oa.marker.set_viewport(0.75, 0.75, 1.0, 1.0) vlab.view(roll=0, azimuth=90, elevation=25, distance=30.0, focalpoint=[0, 2, 0]) vlab.savefig(next_plot_fname(__file__)) if args.show: vlab.show() try: vlab.mlab.close() except AttributeError: pass return 0