Skip to content

Commit

Permalink
Refs #16. simdata: added karg "dhkl_ranges"
Browse files Browse the repository at this point in the history
  • Loading branch information
yxqd committed Apr 16, 2019
1 parent 174cb94 commit 3ba2ee6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions dgsres/singlextal/simdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@ def __init__(self, parent_dir, dirname_template='E%s_hkl%s'):
def path(self, hkl, E):
return os.path.join(self.parent_dir, self.dirname_template % (E, '%s,%s,%s' % tuple(hkl)))

def loadData(self, hkl, E):
def loadData(self, hkl, E, dhkl_ranges=None):
p = self.path(hkl, E)
return self._loadData(p)
return self._loadData(p, dhkl_ranges=dhkl_ranges)

def loadPointCloud(self, hkl, E):
dhs, dks, dls, dEs, probs = self.loadData(hkl, E)
return PointCloud(dhs, dks, dls, dEs, probs)

def _loadData(self, outdir1):
def _loadData(self, outdir1, dhkl_ranges=None):
if dhkl_ranges is None:
dhkl_ranges = [ (-2., 2.) ] * 3
dhkls = np.load('%s/dhkls.npy' % outdir1)
dEs = np.load('%s/dEs.npy' % outdir1)
probs = np.load('%s/probs.npy' % outdir1)
dhs,dks,dls = dhkls.T
# there might be unreasonable data points with unreasonable weights
mask = (dhs> -2.)*(dhs<2.) \
* (dks> -2.)*(dks<2.) \
* (dls> -2.)*(dls<2.)
(dh_min, dh_max), (dk_min, dk_max), (dl_min, dl_max) = dhkl_ranges
mask = (dhs>dh_min)*(dhs<dh_max) \
* (dks>dk_min)*(dks<dk_max) \
* (dls>dl_min)*(dls<dl_max)
return np.array([dhs[mask], dks[mask], dls[mask], dEs[mask], probs[mask]])

def computeCovMat(self, hkl, E):
data = self.loadData(hkl, E)
def computeCovMat(self, hkl, E, dhkl_ranges=None):
data = self.loadData(hkl, E, dhkl_ranges=dhkl_ranges)
Data = data[:4]; probs = data[-1]
return np.cov(Data, aweights=probs)

0 comments on commit 3ba2ee6

Please sign in to comment.