def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--show", "--plot", action="store_true") args = vutil.common_argparse(parser) iono_file = viscid.load_file(_viscid_root + '/../sample/jrrle_sample.iof.*') fac_tot = 1e9 * iono_file["fac_tot"] plot_args = dict(projection="polar", lin=[-4e3, 3e3], bounding_lat=35.0, drawcoastlines=True, # for basemap only, probably will never be used title="Total FAC\n", # make a title, or if a string, use the string as title gridec='gray', label_lat=True, label_mlt=True, colorbar=dict(pad=0.1) # pad the colorbar away from the plot ) ax1 = plt.subplot(121, projection='polar') mpl.plot(fac_tot, ax=ax1, hemisphere='north', **plot_args) ax1.annotate('(a)', xy=(0, 0), textcoords="axes fraction", xytext=(-0.1, 1.0), fontsize=18) ax2 = plt.subplot(122, projection='polar') plot_args['gridec'] = False mpl.plot(fac_tot, ax=ax2, hemisphere="south", style="contourf", levels=50, extend="both", **plot_args) ax2.annotate('(b)', xy=(0, 0), textcoords="axes fraction", xytext=(-0.1, 1.0), fontsize=18) if args.show: mpl.mplshow()
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--show", "--plot", action="store_true") args = vutil.common_argparse(parser) f3d = viscid.load_file(_viscid_root + '/../sample/sample.3df.xdmf', grid_type=MyGGCMGrid) pp = f3d['pp'] rr = f3d['rr'] T = f3d['T'] # bmag = timeit(lambda: f3d['bmag']) bmag = f3d["bmag"] plt.subplot(141) mpl.plot(pp, "y=0f,x=-20f:10f", plot_opts="log", earth=True, show=False) plt.subplot(142) mpl.plot(rr, "y=0f,x=-20f:10f", plot_opts="log", earth=True, show=False) plt.subplot(143) mpl.plot(T, "y=0f,x=-20f:10f", plot_opts="log", earth=True, show=False) plt.subplot(144) mpl.plot(bmag, "y=0f,x=-20f:10f", plot_opts="log", earth=True, show=False) if args.show: mpl.mplshow()
def main(): parser = argparse.ArgumentParser(description="Test xdmf") parser.add_argument("--show", "--plot", action="store_true") parser.add_argument("--keep", action="store_true") args = vutil.common_argparse(parser) # setup a simple force free field x = np.linspace(-2, 2, 20) y = np.linspace(-2.5, 2.5, 25) z = np.linspace(-3, 3, 30) psi = viscid.empty([x, y, z], name="psi", center="node") b = viscid.empty([x, y, z], nr_comps=3, name="b", center="cell", layout="interlaced") X, Y, Z = psi.get_crds_nc("xyz", shaped=True) Xcc, Ycc, Zcc = psi.get_crds_cc("xyz", shaped=True) psi[:, :, :] = 0.5 * (X ** 2 + Y ** 2 - Z ** 2) b["x"] = Xcc b["y"] = Ycc b["z"] = -Zcc # save an hdf5 file with companion xdmf file h5_fname = sample_dir + "/test.h5" viscid.save_fields(h5_fname, [psi, b]) # load the companion xdmf file xdmf_fname = h5_fname[:-3] + ".xdmf" f = viscid.load_file(xdmf_fname) plt.subplot(131) mpl.plot(f["psi"], "y=0") plt.subplot(132) mpl.plot(f["b"].component_fields()[0], "y=0") plt.subplot(133) mpl.plot(f["b"].component_fields()[2], "y=0") mpl.plt.savefig(next_plot_fname(__file__)) if args.show: plt.show() if not args.keep: os.remove(h5_fname) os.remove(xdmf_fname)
def main(): parser = argparse.ArgumentParser(description="Test xdmf") parser.add_argument("--show", "--plot", action="store_true") parser.add_argument("--keep", action="store_true") args = vutil.common_argparse(parser) # setup a simple force free field x = np.linspace(-2, 2, 20) y = np.linspace(-2.5, 2.5, 25) z = np.linspace(-3, 3, 30) psi = viscid.empty([x, y, z], name='psi', center='node') b = viscid.empty([x, y, z], nr_comps=3, name='b', center='cell', layout='interlaced') X, Y, Z = psi.get_crds_nc("xyz", shaped=True) Xcc, Ycc, Zcc = psi.get_crds_cc("xyz", shaped=True) psi[:, :, :] = 0.5 * (X**2 + Y**2 - Z**2) b['x'] = Xcc b['y'] = Ycc b['z'] = -Zcc fname = sample_dir + '/test.npz' viscid.save_fields(fname, [psi, b]) f = viscid.load_file(fname) plt.subplot(131) mpl.plot(f['psi'], "y=0") plt.subplot(132) mpl.plot(f['b'].component_fields()[0], "y=0") plt.subplot(133) mpl.plot(f['b'].component_fields()[2], "y=0") mpl.plt.savefig(next_plot_fname(__file__)) if args.show: plt.show() if not args.keep: os.remove(fname)
# run eval fld = eval(salted_eqn, {"__builtins__": {}}, local_dict) # pylint: disable=eval-used try: fld.name = result_name fld.pretty_name = result_name except AttributeError: pass return fld if __name__ == "__main__": import os import viscid from viscid.plot import mpl from viscid.plot.mpl import plt enabled = True _d = os.path.dirname(viscid.__file__) _g = viscid.load_file(_d + "/../sample/sample.py_0.xdmf").get_grid() plt.subplot(211) _fld = evaluate(_g, "speed", "sqrt(vx**2 + vy**2 + sqrt(vz**4))") mpl.plot(_fld, show=False) plt.subplot(212) _fld = evaluate(_g, "speed", "sqrt(vx**2 + vy**2 + sqrt(vz**4))", try_numexpr=False) mpl.plot(_fld, show=True) ## ## EOF ##