added option for periodic averaging

This commit is contained in:
tiasmaiti 2016-09-10 16:33:28 -04:00
parent 0b4e75c201
commit 2daad7542e
1 changed files with 31 additions and 3 deletions

View File

@ -4,9 +4,18 @@
import os,sys
import math # noqa
import numpy as np
from optparse import OptionParser
from optparse import OptionParser, OptionGroup
import damask
#"https://en.wikipedia.org/wiki/Center_of_mass#Systems_with_periodic_boundary_conditions"
def periodicAverage(Points, Box):
theta = (Points/Box[1]) * (2.0*np.pi)
xi = np.cos(theta)
zeta = np.sin(theta)
theta_avg = np.arctan2(-1.0*zeta.mean(), -1.0*xi.mean()) + np.pi
Pmean = Box[1] * theta_avg/(2.0*np.pi)
return Pmean
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
@ -35,7 +44,23 @@ parser.add_option('-a','--all',
action = 'store_true',
help = 'apply mapping function also to grouping column')
parser.set_defaults(function = 'np.average')
group = OptionGroup(parser, "periodic averaging", "")
group.add_option('-p','--periodic',
dest = 'periodic',
action = 'store_true',
help = 'calculate average in periodic space defined by periodic length [%default]')
group.add_option('--boundary',
dest = 'boundary', metavar = 'MIN MAX',
type = 'float', nargs = 2,
help = 'define periodic box end points %default')
parser.add_option_group(group)
parser.set_defaults(function = 'np.average',
all = False,
periodic = False,
boundary = [0.0, 1.0])
(options,filenames) = parser.parse_args()
@ -92,7 +117,10 @@ for name in filenames:
grpTable = np.empty((len(values), cols)) # initialize output
for i in xrange(len(values)): # iterate over groups (unique values in grpColumn)
grpTable[i] = np.apply_along_axis(mapFunction,0,table.data[index[i]:index[i+1]]) # apply mapping function
if options.periodic :
grpTable[i] = periodicAverage(table.data[index[i]:index[i+1]],options.boundary) # apply periodicAverage mapping function
else :
grpTable[i] = np.apply_along_axis(mapFunction,0,table.data[index[i]:index[i+1]]) # apply mapping function
if not options.all: grpTable[i,grpColumn] = table.data[index[i],grpColumn] # restore grouping column value
table.data = grpTable