def plot_input_1d(to, time, axne, axTe, ls): """ plot 1d input Plots ne,ni,te,ti vol-avgd Parameters: time (arr) : array with the times where to plot the lines Attributes: None Note: """ au.common_style() if axne==0: f = plt.figure(figsize=(8, 8)) axne = f.add_subplot(211) axTe = f.add_subplot(212, sharex=axne) fig_flag = 0 # this means it wasn't initialized #axzf = f.add_subplot(313, sharex=axne) else: f=plt.gcf() fig_flag=1 t=to.t for y, c, l in zip([to.ne_vavg, to.ni_vavg], ['k','r'], [r'e', r'i']): au._plot_1d(t, y, ax=axne, color=c, label=l, ls=ls) for y, c, l in zip([to.Te_vavg, to.Ti_vavg], ['k','r'], [r'e', r'i']): au._plot_1d(t, y, ax=axTe, color=c, label=l, ls=ls) if fig_flag==0: #==================================================== # Correct ticks and xylabels #==================================================== au.limit_labels(axne, r'Time [s]', r'$\langle n \rangle$ [$1/m^3$]','' ) au.limit_labels(axTe, r'Time [s]', r'$\langle T \rangle$ [$eV$]','' ) #==================================================== # Plot vertical lines #==================================================== ind = tu._time_to_ind(to.t, time) for ax in [axne, axTe]:#, axzf]: if len(ind)!=1: for i, el in enumerate(ind): ax.axvline(x=to.t[el], color=col[i], lw=2., linestyle='--') if fig_flag==0: ax.legend(loc='best') f.tight_layout() plt.show()
def _calculate_n0(self, plot=0): """ plot n0 at lcfs plot n0 at lcfs Parameters: None Attributes: None Note: """ v_source = self.file.variables['DN0VD'][:] w_source = self.file.variables['DN0WD'][:] # Drecy = self.file.variables['N0RC_D_D'][:] # Dflow= self.file.variables['N0GF_D_D'][:] # Dsflow= self.file.variables['N0SGF_D'][:] # Dnrecy= self.file.variables['N0SRC_D'][:] # Drec= self.file.variables['N0V0_D'][:] try: CXfastn = self.file.variables['N0BCXD0'][:] first_fastn = self.file.variables['N0BD0'][:] n0fast = first_fastn+CXfast except: # halob = self.file.variables['N0BH_D'][:] n0fast=0. tot_source = v_source+w_source#+Drecy+Dflow+Dsflow+Dnrecy+Drec tot_source += n0fast self.n0_tot = tot_source*1e6 #in m^-3 if plot==1: au.common_style() f=plt.figure(); ax=f.add_subplot(111) ax.plot(self.t, tot_source[:, -1]*1e6, 'k', lw=2.3, label='tot') ax.plot(self.t, v_source[:,-1]*1e6, 'b', lw=2.3, label='Volume') ax.plot(self.t, Drecy[:,-1]*1e6+Dnrecy[:,-1]*1e6+Drec[:,-1]*1e6, 'g', lw=2.3, label='Recy') ax.plot(self.t, w_source[:,-1]*1e6, 'r', lw=2.3, label='wall') ax.plot(self.t, n0fast[:,-1]*1e6, 'm', lw=2.3, label='fast') # ax.plot(self.t, halob[:,-1]*1e6, 'm', lw=2.3, label='halo') # ax.plot(self.t, first_fastn[:,-1]*1e6, 'c', lw=2.3, label='fastn') # ax.plot(self.t, CXfastn[:,-1]*1e6,'y', lw=2.3, label='CX') ax.set_xlabel(r't [s]'); ax.set_ylabel(r'n0 [1/m3]') ax.legend(loc='best'); ax.grid('on') plt.show()
def plot_input_prof(to, time=[0]): """ plot 1d input Plots input quantities, such as ne, ni, Te, Ti profiles Parameters: time (arr) : array with the times where to plot the lines Attributes: None Note: """ au.common_style() f = plt.figure(figsize=(12,10)) axne = f.add_subplot(221) axni = f.add_subplot(222, sharey=axne) axTe = f.add_subplot(223) axTi = f.add_subplot(224, sharey=axTe) ind = tu._time_to_ind(to, time) for i, el in enumerate(ind): lab = r't = {:.2f}'.format(to.t[el]) axne.plot(to.rho[el,:], to.kin_vars['ne'][el,:], col[i], label=lab, lw=2.) axni.plot(to.rho[el,:], to.kin_vars['ni'][el,:], col[i], label=lab, lw=2.) axTe.plot(to.rho[el,:], to.kin_vars['te'][el,:]*1e-3, col[i], label=lab, lw=2.) axTi.plot(to.rho[el,:], to.kin_vars['ti'][el,:]*1e-3, col[i], label=lab, lw =2.) #======================================================== # SET TICK LOCATION #======================================================== au.limit_labels(axne, r'$\rho$', r'$n_e$ [$1/m^3$]','' ) au.limit_labels(axTe, r'$\rho$', r'$T_e$ [$keV$]','' ) au.limit_labels(axni, r'$\rho$', r'$n_i$ [$1/m^3$]','' ) au.limit_labels(axTi, r'$\rho$', r'$T_i$ [$keV$]','' ) axTi.legend(loc='best') f.tight_layout() #f.subplots_adjust(left=0.2) plt.show()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Mar 6 15:33:58 2020 @author: vallar """ import numpy as np import matplotlib.pyplot as plt import scipy.interpolate as interp from utils.plot_utils import common_style import scipy.constants as const import a5py.postprocessing.COM as a5com import sys common_style() def main(fname_a5, run, Ekev=85, debug=0, plot=1): """ COM boundaries w TF ripple Plot COM boundary spaces given eqdsk and Ekev """ c = a5com.COM(fname_a5, run, Ekev) a5obj, a5 = c.a5obj, c.a5 b = a5obj.bfield.read() E = Ekev * 1000 * const.e # Getting psi_2d (Normalized to edge and axis value) and interpolate it # THIS IS WEIRD!!! NEEDS DOUBLE/TRIPLE/QUADRUPLE CHECK!!!! psiw = b['psi1'][0] psia = b['psi0'][0]
import sys sys.path.append('/home/matval/WORK/pythonscripts') import utils.plot_utils as pu import a5py.ascot5io.ascot5 as a5 import numpy as np import matplotlib.pyplot as plt import TFripple as tfr import plot_tips as pt pu.common_style() dir = '/home/matval/WORK/ASCOT/runs/SA_003/ripple/pnb/TFripple_w_plasma/perp/2D' dir = '/home/matval/WORK/ASCOT/runs/SA_003/ripple/nnb/2D/' #dir='/home/vallar/WORK/ASCOT/runs/SA_003/nnb_ripple/runs_2020/TFripple_newascot_20200728/' a = a5.Ascot(f'{dir}/ascot.h5') #run=a.run_1623561441 run = a.active #B field fname_bfield = '/home/matval/WORK/ASCOT/runs/SA_003/ripple/nnb/ascot_TFfield_scen003.h5' fname_bfield = f'{dir}/ascot.h5' #eqd_fname='/home/matval/WORK/JT60SA/JT-60SA_scenario2_highden_eqdsk_chease_cocos02_smoothed.geq' #rippleobj = tfr.TFripple(fname_bfield, '') #R,z, ripple = rippleobj.readfield() #R,z, ripplewell = rippleobj.calculate_ripplewell() #wall (better use 2D) wall = a.wall.wall_2D_3087769866 wall = wall.read() #wall=a.active.wall #particles
def plot_tcv_eq(s, f=0): """ """ au.common_style() flag_leg = 1 ls = '-' if not isinstance(f, matplotlib.figure.Figure): f = plt.figure(figsize=(12, 10)) axj = f.add_subplot(221) axp = f.add_subplot(222) axf = f.add_subplot(223) axc = f.add_subplot(224) axq = axf.twinx( ) # instantiate a second axes that shares the same x-axis axff = axc.twinx() else: axj, axp, axf, axc, axq, axff = f.axes flag_leg = 0 ls = '--' axj.plot(s['jbs']['x'], s['jbs']['y'] * 1e-3, 'r', label=r'BS', lw=2., linestyle=ls) axp.plot(s['p']['x'], s['p']['y'], 'k', label=r'Total exp', lw=2., linestyle=ls) axf.plot(s['torflux']['x'], s['torflux']['y'], 'b', label=r'Tor. Flux', lw=2., linestyle=ls) axf.plot(s['polflux']['x'], s['polflux']['y'] * 10., 'k', label=r'Pol. Flux x 10', lw=2., linestyle=ls) axq.plot(s['q']['x'], s['q']['y'], 'r', label=r'q', lw=2., linestyle=ls) axq.plot([0, 1], [1, 1], 'r--') axq.set_ylim([0, 10]) axf.set_ylim([0, 0.5]) axc.plot(s['i']['x'], s['i']['y'] * 1e-3, 'ko', label=r'EXP CUR', lw=2., linestyle=ls) axff.plot(s['f']['x'], s['f']['y'], 'r^', label=r'EXP F', lw=2., linestyle=ls) axff.legend(loc='lower left') #======================================================== # SET TICK LOCATION #======================================================== if flag_leg == 1: axq.tick_params(axis='y', labelcolor='r') axq.set_ylabel(r'q', color='r') axff.tick_params(axis='y', labelcolor='r') au.limit_labels(axj, r'$\rho_{TOR}$', r'j [kA/m$^2$]', '') au.limit_labels(axp, r'$\rho_{TOR}$', r'p [kPa]', '') axf.set_xlabel(r'$\rho_{TOR}$') axf.set_ylabel(r'Fluxes (Wb/rad)') axj.legend(loc='best') axf.legend(loc='upper left') axf.grid('on') axp.legend(loc='upper right') axp.grid('on') axc.legend(loc='upper right') axc.grid('on') au.limit_labels(axc, r'$t [s]$', r'I [kA]', '') f.tight_layout() f.subplots_adjust(top=0.9) else: axq.set_yticklabels([]) #if titles.get_text() == '': #f.suptitle('{} t={:.2f} s'.format(to.fname[-12:-4], time)) #else: #newtitle = title+' {}'.format(to.fname[-12:-4]) # titles.set_text(newtitle) #except: #f.suptitle('{} t={:.2f} s'.format(to.fname[-12:-4], time)) plt.show()
def plot_eq(to, time=[0], f=0): """ plot equilibrium Plots equilibrium Parameters: time (arr) : array with the times where to plot the lines Attributes: None Note: """ au.common_style() ind = tu._time_to_ind(to.t, time) ind = ind[0] flag_leg = 1 ls = '-' if not isinstance(f, matplotlib.figure.Figure): f = plt.figure(figsize=(12, 10)) axj = f.add_subplot(221) axp = f.add_subplot(222) axf = f.add_subplot(223) axc = f.add_subplot(224) axq = axf.twinx( ) # instantiate a second axes that shares the same x-axis #axff=axc.twinx() else: axj, axp, axf, axc, axq = f.axes flag_leg = 0 ls = '--' axj.plot(to.rho[ind, :], to.eq_vars['j'][ind, :] * 1e-3, 'k', label=r'$j_{TOT}$', lw=2., linestyle=ls) axj.plot(to.rho[ind, :], to.eq_vars['joh'][ind, :] * 1e-3, 'b', label=r'$j_{OH}$', lw=2., linestyle=ls) axj.plot(to.rho[ind, :], to.eq_vars['jbs'][ind, :] * 1e-3, 'r', label=r'$j_{BS}$', lw=2., linestyle=ls) add_curr = to.eq_vars['j'][ind, :] - to.eq_vars['joh'][ ind, :] - to.eq_vars['jbs'][ind, :] axj.plot(to.rho[ind, :], add_curr * 1e-3, 'g', label=r'$j_{Add. heat.}$', lw=2., linestyle=ls) axp.plot(to.rho[ind, :], to.eq_vars['p'][ind, :] * 1e-3, 'k', label=r'Total', lw=2., linestyle=ls) axp.plot(to.rho[ind, :], to.eq_vars['pth'][ind, :] * 1e-3, 'r', label=r'Th.', lw=2., linestyle=ls) axp.plot(to.rho[ind, :], to.eq_vars['pnth'][ind, :] * 1e-3, 'b', label=r'Non th.', lw=2., linestyle=ls) axf.plot(to.rho[ind, :], to.eq_vars['pol_flux'][ind, :] * 10., 'k', label=r'Pol. flux x 10', lw=2., linestyle=ls) axf.plot(to.rho[ind, :], to.eq_vars['tor_flux'][ind, :], 'b', label=r'Tor. Flux', lw=2., linestyle=ls) axq.plot(to.rho[ind, :], to.eq_vars['q'][ind, :], 'r', label=r'q', lw=2., linestyle=ls) axq.plot([0, 1], [1, 1], 'r--') axq.set_ylim([0, 10]) axf.set_ylim([0, 0.5]) axc.plot(to.rho[ind, :], to.file.variables['ETA_USE'][ind, :], 'k', lw=2., linestyle=ls) # axc.plot(to.t[ind], to.file.variables['PCUR'][ind]*1e-3, 'kv', label=r'TRANSP CUR', lw=2., linestyle=ls) # #axc.plot(to.t[ind], to.file.variables['PCURC'][ind]*1e-3, 'kv', label=r'Calc', lw=2., linestyle=ls) # axff.plot(to.t[ind], to.eq_vars['f'][ind], 'rx', label=r'TRANSP F', lw=2., linestyle=ls) #======================================================== # SET TICK LOCATION #======================================================== if flag_leg == 1: axq.tick_params(axis='y', labelcolor='r') axq.set_ylabel(r'q', color='r') axc.set_yscale('log') au.limit_labels(axj, r'$\rho_{TOR}$', r'j [kA/m$^2$]', '') au.limit_labels(axp, r'$\rho_{TOR}$', r'p [kPa]', '') axf.set_xlabel(r'$\rho_{TOR}$') axf.set_ylabel(r'Fluxes (Wb/rad)') axj.legend(loc='best') axf.legend(loc='upper left') axf.grid('on') axp.legend(loc='upper right') axp.grid('on') axc.grid('on') axc.set_xlabel(r'$\rho_{TOR}$') axc.set_ylabel(r'$\eta$') f.tight_layout() f.subplots_adjust(top=0.9) else: axq.set_yticklabels([]) try: titles = f.get_children()[-1] title = titles.get_text() if titles.get_text() == '': f.suptitle('{} t={:.2f} s'.format(to.fname[-12:-4], time)) else: newtitle = title + ' {}'.format(to.fname[-12:-4]) titles.set_text(newtitle) except: f.suptitle('{} t={:.2f} s'.format(to.fname[-12:-4], time)) plt.show()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Dec 4 12:03:45 2019 @author: vallar """ import a5py.ascot5io.ascot5 as a5class from a5py.ascotpy.ascotpy import Ascotpy import a5py.marker.evaluate as eval_mrkr #import a5py.marker.phasespace as ps import numpy as np import matplotlib.pyplot as plt from utils.plot_utils import common_style, limit_labels, define_colors #import plot_tips common_style(labelsize=16) col, _, _, _, _ = define_colors() def evaluate_derived_quant(a5, orb, id_part): # evaluate derived quantities try: mu = orb['mu'] * 1.602e-19 ind, pitch, energy, mu, dE, pphi, psi = evaluate_derived_quant_gc( a5, orb, id_part) except: ind, pitch, energy, mu, dE, pphi, psi = evaluate_derived_quant_go( a5, orb, id_part) return ind, pitch, energy, mu, dE, pphi, psi