コード例 #1
0
 def load(self, ioneqName=None):
     """
     Read temperature and ion fractions from a CHIANTI ".ioneq" file.
     """
     if ioneqName is None:
         ioneqName = chdata.Defaults['ioneqfile']
     ioneqAll = io.ioneqRead(ioneqName)
     self.Temperature = ioneqAll['ioneqTemperature']
     self.Ioneq = ioneqAll['ioneqAll'][self.Z - 1]
コード例 #2
0
ファイル: Ioneq.py プロジェクト: wtbarnes/ChiantiPy
 def load(self, ioneqName=None):
     """
     Read temperature and ion fractions from a CHIANTI ".ioneq" file.
     """
     if ioneqName is None:
         ioneqName = chdata.Defaults['ioneqfile']
     ioneqAll = io.ioneqRead(ioneqName)
     self.Temperature = ioneqAll['ioneqTemperature']
     self.Ioneq = ioneqAll['ioneqAll'][self.Z - 1]
コード例 #3
0
    def ioneqOne(self):
        '''
        Provide the ionization equilibrium for the selected ion as a function of temperature.

        returned in self.IoneqOne
        '''
        #
        if hasattr(self, 'Temperature'):
            temperature = self.Temperature
        else:
            return
        #
        if hasattr(self, 'IoneqAll'):
            ioneqAll = self.IoneqAll
        else:
            ioneqAll = io.ioneqRead(ioneqname=self.Defaults['ioneqfile'])
            self.ioneqAll = self.IoneqAll
        #
        ioneqTemperature = ioneqAll['ioneqTemperature']
        Z = self.Z
        stage = self.Ion
        Dielectronic = self.Dielectronic
        ioneqOne = np.zeros_like(temperature)
        #
        thisIoneq = ioneqAll['ioneqAll'][Z - 1,
                                         stage - 1 + Dielectronic].squeeze()
        gioneq = thisIoneq > 0.
        goodt1 = self.Temperature >= ioneqTemperature[gioneq].min()
        goodt2 = self.Temperature <= ioneqTemperature[gioneq].max()
        goodt = np.logical_and(goodt1, goodt2)
        y2 = splrep(np.log(ioneqTemperature[gioneq]),
                    np.log(thisIoneq[gioneq]),
                    s=0)
        #
        if goodt.sum() > 0:
            if self.Temperature.size > 1:
                gIoneq = splev(np.log(self.Temperature[goodt]), y2)  #,der=0)
                ioneqOne[goodt] = np.exp(gIoneq)
            else:
                gIoneq = splev(np.log(self.Temperature), y2)
                ioneqOne = np.exp(gIoneq) * np.ones(self.NTempDen, 'float64')
            self.IoneqOne = ioneqOne
        else:
            self.IoneqOne = np.zeros_like(self.Temperature)
コード例 #4
0
ファイル: Continuum.py プロジェクト: rstoneback/ChiantiPy
 def ioneqOne(self):
     '''
     Provide the ionization equilibrium for the selected ion as a function of temperature.
     Similar to but not identical to ion.ioneqOne()
     returned in self.IoneqOne
     '''
     #
     if hasattr(self, 'Temperature'):
         temperature = self.Temperature
     else:
         return
     #
     if hasattr(self, 'IoneqAll'):
         ioneqAll = self.IoneqAll
     else:
         self.IoneqAll = ch_io.ioneqRead(
             ioneqname=self.Defaults['ioneqfile'])
         ioneqAll = self.IoneqAll
     #
     ioneqTemperature = ioneqAll['ioneqTemperature']
     Z = self.Z
     stage = self.stage
     ioneqOne = np.zeros_like(temperature)
     #
     thisIoneq = ioneqAll['ioneqAll'][Z - 1, stage - 1].squeeze()
     gioneq = thisIoneq > 0.
     goodt1 = self.Temperature >= ioneqTemperature[gioneq].min()
     goodt2 = self.Temperature <= ioneqTemperature[gioneq].max()
     goodt = np.logical_and(goodt1, goodt2)
     y2 = splrep(np.log(ioneqTemperature[gioneq]),
                 np.log(thisIoneq[gioneq]),
                 s=0)
     #
     if goodt.sum() > 0:
         if self.Temperature.size > 1:
             gIoneq = splev(np.log(self.Temperature[goodt]), y2)  #,der=0)
             ioneqOne[goodt] = np.exp(gIoneq)
         else:
             gIoneq = splev(np.log(self.Temperature), y2)
             ioneqOne = np.exp(gIoneq)
             ioneqOne = np.atleast_1d(ioneqOne)
         self.IoneqOne = ioneqOne
     else:
         self.IoneqOne = np.zeros_like(self.Temperature)
コード例 #5
0
ファイル: Continuum.py プロジェクト: wtbarnes/ChiantiPy
 def ioneqOne(self):
     '''
     Provide the ionization equilibrium for the selected ion as a function of temperature.
     Similar to but not identical to ion.ioneqOne()
     returned in self.IoneqOne
     '''
     #
     if hasattr(self, 'Temperature'):
         temperature = self.Temperature
     else:
         return
     #
     if hasattr(self, 'IoneqAll'):
         ioneqAll = self.IoneqAll
     else:
         self.IoneqAll = ch_io.ioneqRead(ioneqname = self.Defaults['ioneqfile'])
         ioneqAll = self.IoneqAll
     #
     ioneqTemperature = ioneqAll['ioneqTemperature']
     Z = self.Z
     stage = self.stage
     ioneqOne = np.zeros_like(temperature)
     #
     thisIoneq = ioneqAll['ioneqAll'][Z-1,stage-1].squeeze()
     gioneq = thisIoneq > 0.
     goodt1 = self.Temperature >= ioneqTemperature[gioneq].min()
     goodt2 = self.Temperature <= ioneqTemperature[gioneq].max()
     goodt = np.logical_and(goodt1,goodt2)
     y2 = splrep(np.log(ioneqTemperature[gioneq]),np.log(thisIoneq[gioneq]),s=0)
     #
     if goodt.sum() > 0:
         if self.Temperature.size > 1:
             gIoneq = splev(np.log(self.Temperature[goodt]),y2)   #,der=0)
             ioneqOne[goodt] = np.exp(gIoneq)
         else:
             gIoneq = splev(np.log(self.Temperature),y2)
             ioneqOne = np.exp(gIoneq)
             ioneqOne = np.atleast_1d(ioneqOne)
         self.IoneqOne = ioneqOne
     else:
         self.IoneqOne = np.zeros_like(self.Temperature)
コード例 #6
0
ファイル: Continuum.py プロジェクト: Cadair/ChiantiPy
    def ioneqOne(self):
        '''Provide the ionization equilibrium for the selected ion as a function of temperature.
        returned in self.IoneqOne
        this is a duplicate of the method ion.ioneqOne '''
        #
        try:
            temperature = self.Temperature
        except:
            return
        #
        try:
            ioneqAll = self.IoneqAll
        except:
            self.IoneqAll = chio.ioneqRead(ioneqname = self.Defaults['ioneqfile'])
            ioneqAll=self.IoneqAll
        #
        ioneqTemperature = ioneqAll['ioneqTemperature']
        Z=self.Z
        Ion=self.Ion
        Dielectronic=self.Dielectronic
        ioneqOne = np.zeros_like(temperature)
        #
        thisIoneq=ioneqAll['ioneqAll'][Z-1,Ion-1-Dielectronic].squeeze()
#        thisIoneq = self.Ioneq
        gioneq=thisIoneq > 0.
        goodt1=self.Temperature >= ioneqTemperature[gioneq].min()
        goodt2=self.Temperature <= ioneqTemperature[gioneq].max()
        goodt=np.logical_and(goodt1,goodt2)
        y2=interpolate.splrep(np.log(ioneqTemperature[gioneq]),np.log(thisIoneq[gioneq]),s=0)
        #
        if goodt.sum() > 0:
            if self.Temperature.size > 1:
                gIoneq=interpolate.splev(np.log(self.Temperature[goodt]),y2)   #,der=0)
                ioneqOne[goodt] = np.exp(gIoneq)
            else:
                gIoneq=interpolate.splev(np.log(self.Temperature),y2)
                ioneqOne = np.exp(gIoneq)
        else:
            ioneqOne = 0.
        #
        self.IoneqOne = ioneqOne
コード例 #7
0
    def plot(self, stages=0, tRange=0, yr=0, oplot=False, label=1, title=1,  bw=False, semilogx = 0, verbose=0):
        '''
        Plots the ionization equilibria.

        self.plot(tRange=None, yr=None, oplot=False)
        stages = sequence of ions to be plotted, neutral == 1, fully stripped == Z+1
        tRange = temperature range, yr = ion fraction range

        for overplotting:
        oplot="ioneqfilename" such as 'mazzotta'
        or if oplot=True or oplot=1 and a widget will come up so that a file can be selected.
        bw, if True, the plot is made in black and white
        '''
        if hasattr(self, 'Ioneq'):
            ioneq = getattr(self, 'Ioneq')
        else:
            print(' must first load or calculate and ionization equilibrium')
            return

        if bw:
            linestyle = ['k-','k--', 'k-.', 'k:']
            plt.rcParams['font.size'] = 16.
            lw = 2
        else:
            linestyle = ['b-','r--', 'g-.', 'm:']
            plt.rcParams['font.size'] = 14.
            lw = 2
        #
        if not stages:
            stages = range(1, self.Z+2)
        elif min(stages) < 1 or max(stages) > self.Z+1:
            stages = range(1, self.Z+2)  #  spectroscopic notation
        if not tRange:
            tRange = [self.Temperature.min(), self.Temperature.max()]
        if not yr:
            yr = [0.01, 1.1]
        xyr = list(tRange)
        xyr.extend(list(yr))
        #
        iz = stages[0]
        if semilogx:
            plt.semilogx(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
        else:
            plt.loglog(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
        if label:
            idx = self.Ioneq[iz-1] == self.Ioneq[iz-1].max()
            if idx.sum() > 1:
                jdx = np.arange(len(idx))
                idx = int(jdx[idx].max())
            ann = const.Ionstage[iz-1]
            plt.annotate(ann, [self.Temperature[idx], 0.7*ioneq[iz-1, idx]], ha='center')
        for iz in stages[1:]:
            if semilogx:
                plt.semilogx(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
            else:
                plt.loglog(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
            if label:
                idx = ioneq[iz-1] == ioneq[iz-1].max()
                if idx.sum() > 1:
                    jdx = np.arange(len(idx))
                    idx = int(jdx[idx].mean())
                ann = const.Ionstage[iz-1]
                plt.annotate(ann, [self.Temperature[idx], 0.7*ioneq[iz-1, idx]], ha='center')
        plt.xlabel('Temperature (K)')
        plt.ylabel('Ion Fraction')
        atitle = 'Chianti Ionization Equilibrium for '+const.El[self.Z-1].capitalize()
        #
        if oplot:
            if isinstance(oplot,int):
                result = io.ioneqRead(ioneqName='')
#                print('keys = ', result.keys()
                if result != False:
                    atitle += '  & '+ result['ioneqname'].replace('.ioneq', '')
                    atitle += ' '+linestyle[0]
                    for iz in stages:
                        plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            elif type(oplot) == type('string'):
                atitle += '  & ' + oplot
                result = io.ioneqRead(ioneqName=oplot)
                if result != False:
                    for iz in stages:
                        plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            elif type(oplot) == type([]):
                for iplot in range(len(oplot)):
                    result = io.ioneqRead(ioneqName=oplot[iplot])
#                    print 'keys = ', result.keys()
                    if result != False:
                        atitle += '  & '+oplot[iplot]+' '+linestyle[iplot%3]
                        for iz in stages:
                            plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            else:
                print(' oplot file not understood %s'%(oplot))
        if title:
            plt.title(atitle)
        plt.tight_layout()
        plt.axis(xyr)
コード例 #8
0
ファイル: data.py プロジェクト: svenhuldt/ChiantiPy
- `rStar` : distance of the plasma from the source (in units of the source's radius)
- `distance` : distance from the central source
'''
import os
import glob
import traceback
import warnings

import ChiantiPy.tools.io as chio

try:
    xuvtop = os.environ['XUVTOP']
    Defaults = chio.defaultsRead()
    Ip = chio.ipRead()
    MasterList = chio.masterListRead()
    IoneqAll = chio.ioneqRead(ioneqname=Defaults['ioneqfile'])
    ChiantiVersion = chio.versionRead()
    keywordArgs = [
        'temperature', 'eDensity', 'hDensity', 'pDensity', 'radTemperature',
        'rStar', 'distance'
    ]
    AbundanceDefault = chio.abundanceRead(abundancename=Defaults['abundfile'])

    AbundanceList = []
    for fname in glob.glob(os.path.join(xuvtop, 'abundance', '*.abund')):
        AbundanceList.append(os.path.splitext(os.path.basename(fname))[0])
    Abundance = {
        abundance: chio.abundanceRead(abundancename=abundance)
        for abundance in AbundanceList
    }
except (KeyError, IOError) as e:
コード例 #9
0
ファイル: data.py プロジェクト: wtbarnes/ChiantiPy
- `rStar` : distance of the plasma from the source (in units of the source's radius)
- `distance` : distance from the central source
'''
import os
import glob
import traceback
import warnings

import ChiantiPy.tools.io as chio

try:
    xuvtop = os.environ['XUVTOP']
    Defaults = chio.defaultsRead()
    Ip = chio.ipRead()
    MasterList = chio.masterListRead()
    IoneqAll = chio.ioneqRead(ioneqname=Defaults['ioneqfile'])
    ChiantiVersion = chio.versionRead()
    keywordArgs = ['temperature', 'eDensity', 'hDensity', 'pDensity', 'radTemperature',
                   'rStar', 'distance']
    AbundanceDefault = chio.abundanceRead(abundancename=Defaults['abundfile'])

    AbundanceList = []
    for fname in glob.glob(os.path.join(xuvtop, 'abundance', '*.abund')):
        AbundanceList.append(os.path.splitext(os.path.basename(fname))[0])
    Abundance = {abundance: chio.abundanceRead(abundancename=abundance)
                 for abundance in AbundanceList}
except (KeyError, IOError) as e:
    print(traceback.format_exc())
    if isinstance(e, KeyError):
        warnings.warn(
            'XUVTOP environment variable not set. You will not be able to access any data from the CHIANTI database.')
コード例 #10
0
ファイル: Ioneq.py プロジェクト: wtbarnes/ChiantiPy
    def plot(self, stages=0, xr=0, yr=0, oplot=0, label=1, title=1,  bw=0, semilogx = 0):
        '''
        Plots the ionization equilibria.

        self.plot(xr=None, yr=None, oplot=False)
        stages = sequence of ions to be plotted, neutral == 1, fully stripped == Z+1
        xr = temperature range, yr = ion fraction range

        for overplotting:
        oplot="ioneqfilename" such as 'mazzotta'
        or if oplot=True or oplot=1 and a widget will come up so that a file can be selected.
        '''
        if hasattr(self, 'Ioneq'):
            ioneq = getattr(self, 'Ioneq')
        else:
            print(' must first load or calculate and ionization equilibrium')
            return

        if bw:
            linestyle = ['k-','k--', 'k-.', 'k:']
            plt.rcParams['font.size'] = 16.
            lw = 2
        else:
            linestyle = ['b-','r--', 'g-.', 'm:']
            plt.rcParams['font.size'] = 14.
            lw = 2
        #
        if not stages:
            stages = range(1, self.Z+2)
        elif min(stages) < 1 or max(stages) > self.Z+1:
            stages = range(1, self.Z+2)  #  spectroscopic notation
        if not xr:
            xr = [self.Temperature.min(), self.Temperature.max()]
        if not yr:
            yr = [0.01, 1.1]
        xyr = list(xr)
        xyr.extend(list(yr))
        #
        iz = stages[0]
        if semilogx:
            plt.semilogx(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
        else:
            plt.loglog(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
        if label:
            idx = self.Ioneq[iz-1] == self.Ioneq[iz-1].max()
            if idx.sum() > 1:
                jdx = np.arange(len(idx))
                idx = int(jdx[idx].max())
            ann = const.Ionstage[iz-1]
            plt.annotate(ann, [self.Temperature[idx], 0.7*ioneq[iz-1, idx]], ha='center')
        for iz in stages[1:]:
            if semilogx:
                plt.semilogx(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
            else:
                plt.loglog(self.Temperature, ioneq[iz-1], linestyle[0], lw=lw)
            if label:
                idx = ioneq[iz-1] == ioneq[iz-1].max()
                if idx.sum() > 1:
                    jdx = np.arange(len(idx))
                    idx = int(jdx[idx].mean())
                ann = const.Ionstage[iz-1]
                plt.annotate(ann, [self.Temperature[idx], 0.7*ioneq[iz-1, idx]], ha='center')
        plt.xlabel('Temperature (K)')
        plt.ylabel('Ion Fraction')
        atitle = 'Chianti Ionization Equilibrium for '+const.El[self.Z-1].capitalize()
        #
        if oplot:
            if oplot == 0:
                result = io.ioneqRead(ioneqname='')
#                print 'keys = ', result.keys()
                if result != False:
                    atitle += '  & '+result['ioneqname'].replace('.ioneq', '')
                    atitle += ' '+linestyle[0]
                    for iz in stages:
                        plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            elif type(oplot) == type('string'):
                atitle += '  & ' + oplot
                result = io.ioneqRead(ioneqname=oplot)
                if result != False:
                    for iz in stages:
                        plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            elif type(oplot) == type([]):
                for iplot in range(len(oplot)):
                    result = io.ioneqRead(ioneqname=oplot[iplot])
#                    print 'keys = ', result.keys()
                    if result != False:
                        atitle += '  & '+oplot[iplot]+' '+linestyle[iplot%3]
                        for iz in stages:
                            plt.plot(result['ioneqTemperature'], result['ioneqAll'][self.Z-1, iz-1],linestyle[1], lw=lw)
            else:
                print(' oplot file not understood %s'%(oplot))
        if title:
            plt.title(atitle)
        plt.tight_layout()
        plt.axis(xyr)