In [1]:
import sys
import os
import time
import numpy as np
# For module testing, include path to module here
modPath = r'D:\code\github\ePSproc'
# modPath = r'/home/femtolab/github/ePSproc/'
sys.path.append(modPath)
import epsproc as ep
In [2]:
# Load data from modPath\data
dataPath = os.path.join(modPath, 'data', 'photoionization')
dataFile = os.path.join(dataPath, 'n2_3sg_0.1-50.1eV_A2.inp.out') # Set for sample N2 data for testing
# Scan data file
dataSet = ep.readMatEle(fileIn = dataFile)
dataXS = ep.readMatEle(fileIn = dataFile, recordType = 'CrossSection') # XS info currently not set in NO2 sample file.
In [3]:
jobInfo = ep.headerFileParse(dataFile)
molInfo = ep.molInfoParse(dataFile)
In [4]:
ep.jobSummary(jobInfo, molInfo);
As shown in the basic demo notebook, basic plotting with Xarray functionality is a quick and easy way to plot matrix elements.
In [5]:
# Plot matrix elements using Xarray functionality
daPlot = dataSet[0].sum('mu').sum('Sym').sel({'Type':'L'}).squeeze()
daPlot.pipe(np.abs).plot.line(x='Eke');
For more control, additional preprocessing with thresholding & selection can be used.
In [6]:
selDims = {'Type':'L','Cont':'PU'}
daPlot = ep.matEleSelector(dataSet[0], thres=1e-2, inds = selDims, sq = True)
daPlot.pipe(np.abs).sum('mu').plot.line(x='Eke');
... or faceting ...
In [7]:
# Plot with faceting on symmetry
daPlot = ep.matEleSelector(dataSet[0], thres=1e-2, dims = 'Eke', sq = True).sum('mu').squeeze()
daPlot.pipe(np.abs).plot.line(x='Eke', col='Sym', row='Type');
For complex multidimensional cases line plots get busy, quickly. A nice alternative is provided by Seaborn's Clustermap, which produces a 2D map of values (i.e. a heatmap or image), with additional dimensional information as a side-bar. This is now implemented in ep.lmPlot().
In [8]:
# Plot with sensible defaults - all dims
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0])
In order to use Seaborn, the data is converted from a multidimensional Xarray to a 2D Pandas array. This displays nicely in Jupyter, so is also handy for inspecting values.
In [9]:
daPlotpd
Out[9]:
In [10]:
# With slicing by index (dims, energy)
daPlotpd.iloc[0:6, 0:6]
Out[10]:
Various settings can be passed for more control over the plot.
Example with
In [11]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'},
plotDims = ('l','m','mu','Cont','Targ','Total'),
thresType='pc', thres = 0.01, figsize = (15,10), logFlag = True)
Example with
In [12]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'}, sumDims = ['mu'],
plotDims = ('l','m','Cont','Targ','Total'),
thresType='pc', thres = 0.01, figsize = (15,10), logFlag = True)
Example with
In [13]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'}, sumDims = ['mu', 'Sym'],
plotDims = ('l','m'),
thresType='pc', thres = 0.01, figsize = (15,10), logFlag = True)
Example with
In [14]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'}, sumDims = ['Sym'],
plotDims = ('m','l','mu'),
thresType='pc', thres = 0.01, figsize = (15,10))
Example with
In [15]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'},
plotDims = ('Total','Cont','Targ','l','m','mu'),
thresType='pc', thres = 0.01, figsize = (15,10), logFlag = True)
Example with
In [16]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'},
plotDims = ('l','m','mu','Cont','Targ','Total'),
thres = 0.5, figsize = (15,10),
pType = 'phaseUW')
In [17]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'}, xDim = 'LM', sumDims = 'Eke',
plotDims = ('Total','Cont','Targ','m','mu'),
thresType='pc', thres = 0.01, figsize = (15,10),
cmap = 'Greens')
In [18]:
daPlotpd
Out[18]:
pandas.corr(). This defaults to a Pearson correlation coefficient, but other types of correlation functions can be used. Work in progress!
In [19]:
ep.snsMatMod.clustermap(daPlotpd.corr())
Out[19]:
In [20]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'}, sumDims = ['mu', 'Sym'],
plotDims = ('l','m'),
thresType='pc', thres = 0.01, figsize = (15,10))
In [21]:
# Display values for first 10 Ekes
daPlotpd.iloc[:,0:11]
Out[21]:
In [22]:
# Eke correlations
ep.snsMatMod.clustermap(daPlotpd.iloc[:,0:11].corr())
Out[22]:
In [23]:
# (l,m) correlations
ep.snsMatMod.clustermap(daPlotpd.iloc[:,0:11].T.corr())
Out[23]:
In [24]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(dataSet[0], selDims = {'Type':'L'},
plotDims = ('l','m','mu','Cont','Targ','Total'),
thres = 0.5, figsize = (15,10),
pType = 'phase')
In [25]:
# ep.snsMatMod.clustermap(daPlotpd.iloc[:,0:11].corr())
ep.snsMatMod.clustermap(daPlotpd.corr())
Out[25]:
In [26]:
# ep.snsMatMod.clustermap(daPlotpd.iloc[:,0:11].T.corr())
ep.snsMatMod.clustermap(daPlotpd.T.corr())
Out[26]:
The same functionality can be applied to plotting $\beta_{L,M}$ paramters...
(For calculation details, see $\beta_{L,M}$ calculations demo notebook.)
In [27]:
daIn = dataSet[0].copy()
BLMXeN2 = ep.mfblm(daIn, selDims = {'Type':'L'}, thres = 1e-2, verbose = 0) # Run for all Eke
In [28]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(BLMXeN2, SFflag = True,
plotDims = ('l','m'),
figsize = (15,10))
In [29]:
ep.snsMatMod.clustermap(daPlotpd.corr())
Out[29]:
For the $\beta_{L,M}$ case, the SFflag controls whether normalised or unnormalised values are plotted. In the former case, the cross-section ($\beta_{0,0}$) is divided out, hence $\beta_{0,0}$ = 1.
In [30]:
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(BLMXeN2, SFflag = False,
plotDims = ('l','m'),
figsize = (15,10))
In [31]:
ep.snsMatMod.clustermap(daPlotpd.T.corr())
Out[31]:
As a function of Euler angle...
In [32]:
# Set pol geoms - these correspond to (z,x,y) in molecular frame (relative to principle/symmetry axis)
pRot = [0, 0, np.pi/2]
tRot = [0, np.pi/2, np.pi/2]
cRot = [0, 0, 0]
eAngs = np.array([pRot, tRot, cRot]).T # List form to use later, rows per set of angles
In [33]:
thres = 1e-2
# Calculate for each pol geom
# Run for all Eke, selected gauge only; round angles for display purposes only (to be fixed!)
BLMeuler = ep.mfblmEuler(daIn, selDims = {'Type':'L'}, eAngs = np.round(eAngs,3), thres = thres, verbose = 0)
Cross-sections...
In [35]:
# Check XS values
BLMeuler.XS.real.plot.line(x='Eke');
BLMeuler.XS.sum('Euler').real.plot.line(x='Eke'); # Add sum over Euler angles sets
In [36]:
# Check XS from ePS file GetCRO outputs
# This is for each symmetry group, averaged over all angles (i.e. unaligned LF) - see ePS manaul, https://www.chem.tamu.edu/rgroup/lucchese/ePolyScat.E3.manual/GetCro.html
# Hence should be similar to (x,y,z) MF orientations, but not identical
dataXS[0].sel({'XC':'SIGMA', 'Type':'L'}).plot.line(x='Eke');
$\beta_{L,M}$ parameters...
In [37]:
# Plot (normalised) BLM results - basic with Xarray (note Seaborn style may now be applied, since lmPlot() sets this globally)
BLMplot = ep.matEleSelector(BLMeuler, thres=thres, dims = 'Eke')
BLMplot.real.squeeze().plot.line(x='Eke', col='Euler');
In [38]:
# Plot resutls - 2D maps with Xarray, faceted on Euler angle sets
# Set BLM index for y-axis
BLMplot['BLMind'] = ('BLM',np.arange(0, BLMplot.BLM.size))
# Plot
BLMplot.real.squeeze().plot(x='Eke', y='BLMind', col='Euler', size = 5);
In [39]:
# Plot results with lmPlot()
# NOTE - this currently plots with unstacked Euler angles (P,T,C) - should change to treat these as a stacked set.
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(BLMeuler, SFflag = False,
plotDims = ('l','m','P','T','C'),
figsize = (15,10))
In [40]:
daPlotpd
Out[40]:
In [41]:
ep.snsMatMod.clustermap(daPlotpd.T.corr())
Out[41]:
In [42]:
# Plot results with lmPlot(), ordering by Euler sets
# NOTE - this currently plots with unstacked Euler angles (P,T,C) - should change to treat these as a stacked set.
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(BLMeuler, SFflag = False,
plotDims = ('P','T','C','l','m'),
figsize = (15,10))
... and including cross-section ...
In [43]:
# Plot results with lmPlot(), ordering by Euler sets + use XS
# NOTE - this currently plots with unstacked Euler angles (P,T,C) - should change to treat these as a stacked set.
daPlot, daPlotpd, legendList, gFig = ep.lmPlot(BLMeuler, SFflag = True,
plotDims = ('P','T','C','l','m'),
figsize = (15,10))
In [44]:
daPlotpd
Out[44]: