SOLPSxport.py
def modify_ti(self, sol_points = None, max_psin = 1.1, decay_length = 0.015,
                  rad_loc_for_exp_decay = 1.0, reduce_ti = True, ti_min = 1, plotit = False):
        """
        Manually modify the Ti profile to be more realistic

        CER measures C+6, the temperature of which can differ significantly from
        the main ion species in the edge.

        Inputs:
          sol_points   Number of extra points to add in the SOL
          max_psi      sol_points will be evenly distributed between rad_loc_for_exp_decay
                       and max_psi
          decay_length Decay length for exponential falloff imposed into SOL (in units of psin)
          reduce_ti    Use a profile from a single comparison case of T_D vs T_C+6
                       to reduce the "measured" value of T_D to be more realistic
          ti_min       Ti decays exponentially to this value (in eV)
        """

        tiexp = self.data['pedData']['fitVals']['tisplpsi']['y']
        tiexppsi = self.data['pedData']['fitVals']['tisplpsi']['x']

        ti_mod = tiexp.copy()
        xrad = tiexppsi.copy()

        if reduce_ti:
            saved_ratio_file_loc = \
                '/fusion/projects/results/solps-iter-results/wilcoxr/T_D_C_ratio.txt'

            print('Reducing T_D according to ratio of T_D / T_C from ' + saved_ratio_file_loc)

            try:
                with open(saved_ratio_file_loc, 'r') as f:
                    lines = f.readlines()

                psin_ratio = []
                T_DC_ratio = []  # The ratio T_D / T_C from 171558

                for line in lines:
                    elements = line.split()
                    if elements[0] != '#':
                        psin_ratio.append(np.float(elements[0]))
                        T_DC_ratio.append(np.float(elements[1]))

                T_ratio_fit = np.interp(tiexppsi, np.array(psin_ratio),
                                        np.array(T_DC_ratio), left=1)
                # if > given range, chooses endpoint
                ti_reduced = tiexp * T_ratio_fit

            except FileNotFoundError:
                print("Can't retrieve T_D/T_C ratio file, not reducing Ti")
                ti_reduced = tiexp

            ti_mod = ti_reduced


        # Modify Ti profile to decay exponentially outside separatrix
        if decay_length is not None:
            outer_inds = np.where(tiexppsi >= rad_loc_for_exp_decay)[0]
            val_at_exp_decay_start = np.interp(rad_loc_for_exp_decay, tiexppsi, ti_mod)

            if sol_points is not None:
                xrad = np.delete(xrad, outer_inds)
                ti_mod = np.delete(ti_mod, outer_inds)

                extra_points = np.linspace(rad_loc_for_exp_decay, max_psin, sol_points + 1)
                xrad = np.append(xrad, extra_points)
                outer_inds = np.where(xrad >= rad_loc_for_exp_decay)[0]
                ti_mod = np.append(ti_mod, np.ones(sol_points + 1))

            ti_mod[outer_inds] = (val_at_exp_decay_start - ti_min * 1e-3) * \
                np.exp(-(xrad[outer_inds]-rad_loc_for_exp_decay) / decay_length) + ti_min * 1e-3

        if plotit:
            psi_TS = self.data['pedData']['fitPsiProf']
            teexp = self.data['pedData']['fitProfs']['teprof']

            plt.figure()
            plt.plot(psi_TS, teexp, 'g', lw=1, label = 'T$_e$ (TS)')
            plt.plot(tiexppsi, tiexp, '--sk', lw=2, label='T$_{C+6}$ (CER)')
            if reduce_ti:
                plt.plot(tiexppsi, ti_reduced, '-xr', ms=8, mew=2, lw=2,
                         label='T$_D$ (inferred)')
            plt.plot(xrad, ti_mod, '-ob', lw=3, label = 'Final T$_D$')
            plt.xlabel('$\psi_n$')
            plt.ylabel('T$_i$ (keV)')
            plt.legend(loc='best')
            plt.grid('on')
            plt.show(block=False)

        self.data['pedData']['fitVals']['ti_mod'] = {'x':xrad, 'y':ti_mod}

        Manually modify the Ti profile to be more realistic

        CER measures C+6, the temperature of which can differ significantly from
        the main ion species in the edge.

        Inputs:
          sol_points   Number of extra points to add in the SOL
          max_psi      sol_points will be evenly distributed between rad_loc_for_exp_decay
                       and max_psi
          decay_length Decay length for exponential falloff imposed into SOL (in units of psin)
          reduce_ti    Use a profile from a single comparison case of T_D vs T_C+6
                       to reduce the "measured" value of T_D to be more realistic
          ti_min       Ti decays exponentially to this value (in eV)
        
Manually modify the Ti profile to be more realistic
CER measures C+6, the temperature of which can differ significantly from
the main ion species in the edge.

sol_points   Number of extra points to add in the SOL
max_psi      sol_points will be evenly distributed between rad_loc_for_exp_decay
and max_psi
decay_length Decay length for exponential falloff imposed into SOL (in units of psin)
reduce_ti    Use a profile from a single comparison case of T_D vs T_C+6
to reduce the "measured" value of T_D to be more realistic
ti_min       Ti decays exponentially to this value (in eV)
Manually modify the Ti profile to be more realistic CER measures C + 6 the temperature of which can differ significantly from the main ion species in the edge . sol_points Number of extra points to add in the SOL max_psi sol_points will be evenly distributed between rad_loc_for_exp_decay and max_psi decay_length Decay length for exponential falloff imposed into SOL ( in units of psin ) reduce_ti Use a profile from a single comparison case of T_D vs T_C + 6 to reduce the " measured " value of T_D to be more realistic ti_min Ti decays exponentially to this value ( in eV )
def modify_ti(self, sol_points = None, max_psin = 1.1, decay_length = 0.015,
                  rad_loc_for_exp_decay = 1.0, reduce_ti = True, ti_min = 1, plotit = False):
        tiexp = self.data['pedData']['fitVals']['tisplpsi']['y']
        tiexppsi = self.data['pedData']['fitVals']['tisplpsi']['x']
        ti_mod = tiexp.copy()
        xrad = tiexppsi.copy()
        if reduce_ti:
            saved_ratio_file_loc = \
                '/fusion/projects/results/solps-iter-results/wilcoxr/T_D_C_ratio.txt'
            print('Reducing T_D according to ratio of T_D / T_C from ' + saved_ratio_file_loc)
            try:
                with open(saved_ratio_file_loc, 'r') as f:
                    lines = f.readlines()
                psin_ratio = []
                T_DC_ratio = []  
                for line in lines:
                    elements = line.split()
                    if elements[0] != '#':
                        psin_ratio.append(np.float(elements[0]))
                        T_DC_ratio.append(np.float(elements[1]))
                T_ratio_fit = np.interp(tiexppsi, np.array(psin_ratio),
                                        np.array(T_DC_ratio), left=1)
                ti_reduced = tiexp * T_ratio_fit
            except FileNotFoundError:
                print("Can't retrieve T_D/T_C ratio file, not reducing Ti")
                ti_reduced = tiexp
            ti_mod = ti_reduced
        if decay_length is not None:
            outer_inds = np.where(tiexppsi >= rad_loc_for_exp_decay)[0]
            val_at_exp_decay_start = np.interp(rad_loc_for_exp_decay, tiexppsi, ti_mod)
            if sol_points is not None:
                xrad = np.delete(xrad, outer_inds)
                ti_mod = np.delete(ti_mod, outer_inds)
                extra_points = np.linspace(rad_loc_for_exp_decay, max_psin, sol_points + 1)
                xrad = np.append(xrad, extra_points)
                outer_inds = np.where(xrad >= rad_loc_for_exp_decay)[0]
                ti_mod = np.append(ti_mod, np.ones(sol_points + 1))
            ti_mod[outer_inds] = (val_at_exp_decay_start - ti_min * 1e-3) * \
                np.exp(-(xrad[outer_inds]-rad_loc_for_exp_decay) / decay_length) + ti_min * 1e-3
        if plotit:
            psi_TS = self.data['pedData']['fitPsiProf']
            teexp = self.data['pedData']['fitProfs']['teprof']
            plt.figure()
            plt.plot(psi_TS, teexp, 'g', lw=1, label = 'T$_e$ (TS)')
            plt.plot(tiexppsi, tiexp, '--sk', lw=2, label='T$_{C+6}$ (CER)')
            if reduce_ti:
                plt.plot(tiexppsi, ti_reduced, '-xr', ms=8, mew=2, lw=2,
                         label='T$_D$ (inferred)')
            plt.plot(xrad, ti_mod, '-ob', lw=3, label = 'Final T$_D$')
            plt.xlabel('$\psi_n$')
            plt.ylabel('T$_i$ (keV)')
            plt.legend(loc='best')
            plt.grid('on')
            plt.show(block=False)
        self.data['pedData']['fitVals']['ti_mod'] = {'x':xrad, 'y':ti_mod}
def modify_ti ( self , sol_points = None , max_psin = 1.1 , decay_length = 0.015 , rad_loc_for_exp_decay = 1.0 , reduce_ti = True , ti_min = 1 , plotit = False ) : tiexp = self . data [ 'pedData' ] [ 'fitVals' ] [ 'tisplpsi' ] [ 'y' ] tiexppsi = self . data [ 'pedData' ] [ 'fitVals' ] [ 'tisplpsi' ] [ 'x' ] ti_mod = tiexp . copy ( ) xrad = tiexppsi . copy ( ) if reduce_ti : saved_ratio_file_loc = '/fusion/projects/results/solps-iter-results/wilcoxr/T_D_C_ratio.txt' print ( 'Reducing T_D according to ratio of T_D / T_C from ' + saved_ratio_file_loc ) try : with open ( saved_ratio_file_loc , 'r' ) as f : lines = f . readlines ( ) psin_ratio = [ ] T_DC_ratio = [ ] for line in lines : elements = line . split ( ) if elements [ 0 ] != '#' : psin_ratio . append ( np . float ( elements [ 0 ] ) ) T_DC_ratio . append ( np . float ( elements [ 1 ] ) ) T_ratio_fit = np . interp ( tiexppsi , np . array ( psin_ratio ) , np . array ( T_DC_ratio ) , left = 1 ) ti_reduced = tiexp * T_ratio_fit except FileNotFoundError : print ( "Can't retrieve T_D/T_C ratio file, not reducing Ti" ) ti_reduced = tiexp ti_mod = ti_reduced if decay_length is not None : outer_inds = np . where ( tiexppsi >= rad_loc_for_exp_decay ) [ 0 ] val_at_exp_decay_start = np . interp ( rad_loc_for_exp_decay , tiexppsi , ti_mod ) if sol_points is not None : xrad = np . delete ( xrad , outer_inds ) ti_mod = np . delete ( ti_mod , outer_inds ) extra_points = np . linspace ( rad_loc_for_exp_decay , max_psin , sol_points + 1 ) xrad = np . append ( xrad , extra_points ) outer_inds = np . where ( xrad >= rad_loc_for_exp_decay ) [ 0 ] ti_mod = np . append ( ti_mod , np . ones ( sol_points + 1 ) ) ti_mod [ outer_inds ] = ( val_at_exp_decay_start - ti_min * 1e-3 ) * np . exp ( - ( xrad [ outer_inds ] - rad_loc_for_exp_decay ) / decay_length ) + ti_min * 1e-3 if plotit : psi_TS = self . data [ 'pedData' ] [ 'fitPsiProf' ] teexp = self . data [ 'pedData' ] [ 'fitProfs' ] [ 'teprof' ] plt . figure ( ) plt . plot ( psi_TS , teexp , 'g' , lw = 1 , label = 'T$_e$ (TS)' ) plt . plot ( tiexppsi , tiexp , '--sk' , lw = 2 , label = 'T$_{C+6}$ (CER)' ) if reduce_ti : plt . plot ( tiexppsi , ti_reduced , '-xr' , ms = 8 , mew = 2 , lw = 2 , label = 'T$_D$ (inferred)' ) plt . plot ( xrad , ti_mod , '-ob' , lw = 3 , label = 'Final T$_D$' ) plt . xlabel ( '$\psi_n$' ) plt . ylabel ( 'T$_i$ (keV)' ) plt . legend ( loc = 'best' ) plt . grid ( 'on' ) plt . show ( block = False ) self . data [ 'pedData' ] [ 'fitVals' ] [ 'ti_mod' ] = { 'x' : xrad , 'y' : ti_mod }
Manually modify the Ti profile to be more realistic
CER measures C+6, the temperature of which can differ significantly from
the main ion species in the edge.
Manually modify the Ti profile to be more realistic CER measures C + 6 the temperature of which can differ significantly from the main ion species in the edge .
"""
        Manually modify the Ti profile to be more realistic

        CER measures C+6, the temperature of which can differ significantly from
        the main ion species in the edge.

        Inputs:
          sol_points   Number of extra points to add in the SOL
          max_psi      sol_points will be evenly distributed between rad_loc_for_exp_decay
                       and max_psi
          decay_length Decay length for exponential falloff imposed into SOL (in units of psin)
          reduce_ti    Use a profile from a single comparison case of T_D vs T_C+6
                       to reduce the "measured" value of T_D to be more realistic
          ti_min       Ti decays exponentially to this value (in eV)
        """ # The ratio T_D / T_C from 171558 # if > given range, chooses endpoint # Modify Ti profile to decay exponentially outside separatrix
self
sol_points
max_psin
decay_length
rad_loc_for_exp_decay
reduce_ti
ti_min
plotit