def plotcurv2D(xg: dict[str, T.Any], parm: xarray.DataArray, lalt: int = 512, llat: int = 512): # grid data alti, loni, lati, parmi = model2magcoords(xg, parm, lalt, 1, llat) # define slices indices, for 2D there is only one longitude index ilon = 0 # plot the meridional slice fg = figure() ax = fg.gca() h = ax.pcolormesh(lati, alti / 1e3, parmi[:, ilon, :], shading="nearest") ax.set_xlabel("mlat") ax.set_ylabel("alt") fg.colorbar(h, ax=ax)
# setup output directories direc = "/Users/zettergm/simulations/raid/EIAwinds_reverse_large/" plotdir = direc + "/customplots/" if not os.path.isdir(plotdir): os.mkdir(plotdir) # load config and grid cfg = gemini3d.read.config(direc) xg = gemini3d.read.grid(direc) inds = np.arange(0, len(cfg["time"])) # set resolution of plot grid lalt = 1024 llat = 1024 llon = 1 parmlbl = "ne" # plots for k in inds: print(cfg["time"][k]) data = gemini3d.read.frame(direc, cfg["time"][k]) # read the data parm = data[parmlbl] alti, mloni, mlati, parmi = model2magcoords(xg, parm, lalt, llon, llat) # grid the data timelbl = str(cfg["time"][k]) plotdata(alti, mlati, parmi, timelbl, parmlbl) simtime = (cfg["time"][k] - cfg["time"][0]).total_seconds() plt.savefig(plotdir + "/" + parmlbl + str(simtime) + "s.png") #wait=input("Press a button to continue...")
# parameters to plot params = ["ne", "Ti", "Te", "v3"] paramslbl = ["$n_e$ (m$^{-3})$", "$T_i$ (K)", "$T_e (K)$", "$v_E$ (m/s)"] lp = len(params) dati = np.zeros((lp, len(direcs), lalt, llon, llat)) # loop over simulations and times for simtime in cfg["time"]: plt.subplots(4, 1, dpi=100, figsize=(8.5, 8.5)) timelbl = str(simtime) for i, direc in enumerate(direcs): print(" Loading: " + timelbl) dat = gemini3d.read.frame(direc, simtime) for j, param in enumerate(params): alti, mloni, mlati, parami = model2magcoords( xg, dat[param], lalt, llon, llat) # grid the data dati[j, i, :, :, :] = parami ialt = np.argmin(np.abs(alti - 500e3)) ilon = llon // 2 plt.subplot(lp, 1, j + 1) plt.plot(mlati, parami[ialt, ilon, :]) plt.xlabel("mag. lat. (deg.)") plt.ylabel(paramslbl[j]) if j == 0: plt.title(timelbl) plt.legend(("Q=0.02 mW/m$^2$", "Q=0.04 mW/m$^2$", "Q=0.06 mW/m$^2$")) plt.savefig(plotdir + "/" + timelbl + ".png") plt.close("all")
lalt = 256 llon = 128 llat = 256 # regrid data in geographic print("Sampling in geographic coords...") galti, gloni, glati, parmgi = model2geogcoords(xg, dat[parm], lalt, llon, llat, wraplon=True) # regrid in geomagnetic print("Sampling in geomagnetic coords...") malti, mloni, mlati, parmmi = model2magcoords(xg, dat[parm], lalt, llon, llat) ############################################################################### # read in a vector quantity, rotate into geographic components and then grid ############################################################################### v1 = dat["v1"] v2 = dat["v2"] v3 = dat["v3"] [egalt, eglon, eglat] = unitvecs_geographic(xg) #^ returns a set of geographic unit vectors on xg; these are in ECEF geomag comps # like all other unit vectors in xg # each of the components in models basis projected onto geographic unit vectors vgalt = (np.sum(xg["e1"] * egalt, 3) * dat["v1"] + np.sum(xg["e2"] * egalt, 3) * dat["v2"] + np.sum(xg["e3"] * egalt, 3) * dat["v3"])
def plotcurv3D(xg: dict[str, T.Any], parm: xarray.DataArray, cfg: dict[str, T.Any], lalt: int = 256, llon: int = 256, llat: int = 256, coord: str = "geomagnetic"): """plot dipole grid data vs. alt,lon,lat""" # grid data; wasteful and should only do a slice at a time??? if coord == "geomagnetic": alti, loni, lati, parmi = model2magcoords(xg, parm, lalt, llon, llat) lonlbl = "mlon" latlbl = "mlat" elif coord == "geographic": alti, loni, lati, parmi = model2geogcoords(xg, parm, lalt, llon, llat, wraplon=True) lonlbl = "glon" latlbl = "glat" else: print("WARNING: defaulting to geomagnetic sampling...") alti, loni, lati, parmi = model2magcoords(xg, parm, lalt, llon, llat) lonlbl = "mlon" latlbl = "mlat" # define slices indices altref = 300e3 ialt = abs(alti - altref).argmin() lonavg = loni.mean() ilon = abs(loni - lonavg).argmin() latavg = lati.mean() ilat = abs(lati - latavg).argmin() # plot various slices through the 3D domain fg = figure() axs = fg.subplots(1, 3) ax = axs[0] h = ax.pcolormesh(loni, alti / 1e3, parmi[:, :, ilat], shading="nearest") ax.set_xlabel(lonlbl) ax.set_ylabel("alt") fg.colorbar(h, ax=ax) ax = axs[1] h = ax.pcolormesh(loni, lati, parmi[ialt, :, :].transpose(), shading="nearest") ax.set_xlabel(lonlbl) ax.set_ylabel(latlbl) fg.colorbar(h, ax=ax) ax = axs[2] ax.pcolormesh(lati, alti / 1e3, parmi[:, ilon, :], shading="nearest") ax.set_xlabel(latlbl) ax.set_ylabel("alt") fg.colorbar(h, ax=ax)