From dc4e703d8f109876884e0ab80001f919d145baad Mon Sep 17 00:00:00 2001 From: Jiao Lin Date: Tue, 16 Apr 2019 16:04:35 -0400 Subject: [PATCH] Refs #16. refactor: move violini model to its own module --- dgsres/singlextal/plot.py | 50 ++++-------------------------------- dgsres/singlextal/violini.py | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 45 deletions(-) create mode 100644 dgsres/singlextal/violini.py diff --git a/dgsres/singlextal/plot.py b/dgsres/singlextal/plot.py index 358ddf6..df6295f 100644 --- a/dgsres/singlextal/plot.py +++ b/dgsres/singlextal/plot.py @@ -2,7 +2,11 @@ from . import use_covmat from .pointcloud import PointCloud from .simdata import McvineResolutionData +from .violini import VioliniModel +# backward compatible +AnalyticalModel = VioliniModel +# obsolete def createARCSAnalyticalModel( tau_P, tau_M, pix_r, pix_h, sample_thickness, @@ -26,56 +30,12 @@ def createARCSAnalyticalModel( height = "meter*%s" % pix_h, pressure = "10*atm", ) - return AnalyticalModel( + return VioliniModel( instrument, pixel, tofwidths, beamdivs, sample_yml, samplethickness, Ei, psi_scan) -class AnalyticalModel: - - """analytical resolution model based on paper by Violini et al. - The main calculation is done in module .use_covmat. - """ - - def __init__( - self, instrument, pixel, tofwidths, beamdivs, - sample_yml, samplethickness, - Ei, psi_scan): - self.instrument = instrument - self.pixel = pixel - self.tofwidths = tofwidths - self.beamdivs = beamdivs - self.sample_yml = sample_yml - self.samplethickness = samplethickness - self.Ei = Ei - self.psi_scan = psi_scan - return - - def computePointCloud(self, hkl, E, N=int(1e6)): - covmat = self.computeCovMat(hkl, E) - events = np.random.multivariate_normal(np.zeros(4), covmat, size=N) - dhs, dks, dls, dEs = events.T - ws = np.ones(dhs.shape) - return PointCloud(dhs, dks, dls, dEs, ws) - - def computeCovMat(self, hkl, E): - class dynamics: - hkl_dir = np.array([1.,0.,0.]) - dq = 0 - dynamics.hkl0 = hkl - dynamics.E = E - cm_res = use_covmat.compute( - self.sample_yml, self.Ei, - dynamics, - self.psi_scan, - self.instrument, self.pixel, - self.tofwidths, self.beamdivs, self.samplethickness, - plot=False) - # ellipsoid_trace = cm_res['u'] - InvCov4D = cm_res['hklE_inv_cov'] - return np.linalg.inv(InvCov4D)/2.355 - def plotEllipsoid(covmat, q, symbol='.'): """plot 2d ellipsoid along a particular hkl direction, given the cov matrix. """ diff --git a/dgsres/singlextal/violini.py b/dgsres/singlextal/violini.py new file mode 100644 index 0000000..5fad115 --- /dev/null +++ b/dgsres/singlextal/violini.py @@ -0,0 +1,48 @@ +import os, numpy as np +from . import use_covmat +from .pointcloud import PointCloud + +class VioliniModel: + + """analytical resolution model based on paper by Violini et al. + The main calculation is done in module .use_covmat. + """ + + def __init__( + self, instrument, pixel, tofwidths, beamdivs, + sample_yml, samplethickness, + Ei, psi_scan): + self.instrument = instrument + self.pixel = pixel + self.tofwidths = tofwidths + self.beamdivs = beamdivs + self.sample_yml = sample_yml + self.samplethickness = samplethickness + self.Ei = Ei + self.psi_scan = psi_scan + return + + def computePointCloud(self, hkl, E, N=int(1e6)): + covmat = self.computeCovMat(hkl, E) + events = np.random.multivariate_normal(np.zeros(4), covmat, size=N) + dhs, dks, dls, dEs = events.T + ws = np.ones(dhs.shape) + return PointCloud(dhs, dks, dls, dEs, ws) + + def computeCovMat(self, hkl, E): + class dynamics: + hkl_dir = np.array([1.,0.,0.]) + dq = 0 + dynamics.hkl0 = hkl + dynamics.E = E + cm_res = use_covmat.compute( + self.sample_yml, self.Ei, + dynamics, + self.psi_scan, + self.instrument, self.pixel, + self.tofwidths, self.beamdivs, self.samplethickness, + plot=False) + # ellipsoid_trace = cm_res['u'] + InvCov4D = cm_res['hklE_inv_cov'] + return np.linalg.inv(InvCov4D)/2.355 +