コード例 #1
0
    def _getExpectedCaseWithDistCriteria(self):
        edgesA, edgesB = [
            self.aziEdgesA, self.pitchEdgesA, self.oxyDistEdgesA
        ], [self.aziEdgesB, self.pitchEdgesB, self.oxyDistEdgesB]
        expBinObjA, expBinObjB = binResHelp.NDimensionalBinnedResults(
            edgesA), binResHelp.NDimensionalBinnedResults(edgesB)
        expBinObjA.initialiseCountsMatrix()
        expBinObjB.initialiseCountsMatrix()

        #Sort unnormalised counts
        expBinObjA.binVals["counts"][0][0][1] = 2
        expBinObjA.binVals["counts"][1][1][0] = 1

        expBinObjB.binVals["counts"][0][1][0] = 1
        expBinObjB.binVals["counts"][0][0][0] = 2

        #Sort the normalised counts (same as unnormalised for the simple case with 1 step)
        expBinObjA.initialiseCountsMatrix(countKey="normalised_counts")
        expBinObjB.initialiseCountsMatrix(countKey="normalised_counts")
        np.copyto(expBinObjA.binVals["normalised_counts"],
                  expBinObjA.binVals["counts"])
        np.copyto(expBinObjB.binVals["normalised_counts"],
                  expBinObjB.binVals["counts"])

        return [expBinObjA, expBinObjB]
コード例 #2
0
	def createTestObjs(self):
		self.binValsA = {self.countKey:self.countsA, self.normCountKey: self.countsA/self.nStepsA}
		self.binValsB = {self.countKey:self.countsB, self.normCountKey: self.countsB/self.nStepsB}

		self.binObjA = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals=self.binValsA)
		self.binObjB = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals=self.binValsB)

		self.binObjsToAdd = [self.binObjA, self.binObjB]
コード例 #3
0
	def testBinEdgesArray_3dim(self):
		self.edgesC = [7,8,9]
		edges = [self.edgesA, self.edgesB, self.edgesC]
		self.testObj = tCode.NDimensionalBinnedResults(edges)

		#2,3,2 are number of bins along first 3 dimensions.
		# Then we need 3 slots to hold EACH of the bin edge pairs
		# THEN we need another 2 slots to hold upper and lower values of the bin
		expArray = np.zeros( [2,3,2,len(edges),2] )

		expArray[0][0][0] = [ np.array([1,2]), np.array([6,5]), np.array([7,8]) ] 
		expArray[0][0][1] = [ np.array([1,2]), np.array([6,5]), np.array([8,9]) ]
		expArray[0][1][0] = [ np.array([1,2]), np.array([5,4]), np.array([7,8]) ]
		expArray[0][1][1] = [ np.array([1,2]), np.array([5,4]), np.array([8,9]) ]
		expArray[0][2][0] = [ np.array([1,2]), np.array([4,3]), np.array([7,8]) ]
		expArray[0][2][1] = [ np.array([1,2]), np.array([4,3]), np.array([8,9]) ]

		expArray[1][0][0] = [ np.array([2,3]), np.array([6,5]), np.array([7,8]) ]
		expArray[1][0][1] = [ np.array([2,3]), np.array([6,5]), np.array([8,9]) ]
		expArray[1][1][0] = [ np.array([2,3]), np.array([5,4]), np.array([7,8]) ]
		expArray[1][1][1] = [ np.array([2,3]), np.array([5,4]), np.array([8,9]) ]
		expArray[1][2][0] = [ np.array([2,3]), np.array([4,3]), np.array([7,8]) ]
		expArray[1][2][1] = [ np.array([2,3]), np.array([4,3]), np.array([8,9]) ]

		actArray = self.testObj.binEdgesArray

		self.assertTrue( np.allclose(expArray, actArray) )
コード例 #4
0
	def _loadExpObj_2d(self):
		outObj = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals={"normalised_counts":self.normCounts})
		outObj.binVals["circular_rdf"] = np.array( [ [48.6341681483221, 22.9661349589299],
		                                             [12.1585420370805, 5.74153373973247],
		                                             [2.70189823046234, 1.27589638660722] ] )
		outObj.binVals["circular_rdf"] *= (1/(self.numbFromA*self.numbFromB))
		return outObj
コード例 #5
0
	def _loadExpectedBinsCasesB_3d_to_1d(self):
		outEdges = [self.edgesB]
		outBinObj = tCode.NDimensionalBinnedResults(outEdges)

		outBinObj.initialiseCountsMatrix(countKey="fake_counts")
		outBinObj.binVals["fake_counts"][0] = 1+2+5+6
		outBinObj.binVals["fake_counts"][1] = 3+4+7+8

		return outBinObj	
コード例 #6
0
	def testExpectedCase_2d_singleVol(self):
		self.volumes = 25
		expObj = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals={"normalised_counts":self.normCounts})
		expObj.binVals["rdf"] = np.array( [ [15.1981775463507, 2.39230572488853],
		                                    [1.26651479552922, 0.199358810407378],
		                                    [0.140723866169914, 0.022150978934153] ] )
		expObj.binVals["rdf"] *= (1/(self.numbFromA*self.numbFromB))
		self._runTestFunct()
		actObj = self.binObjA
		self.assertEqual(expObj, actObj)
コード例 #7
0
	def testExpectedCase_2d_defaultVolumes(self):
		self.volumes = None
		expObj = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals={"normalised_counts":self.normCounts})
		expObj.binVals["rdf"] = np.array( [ [38.88, 6.12],
		                                       [3.24, 0.51],
		                                       [0.36, 0.056666666666667] ] )
		expObj.binVals["rdf"] *= (1/(self.numbFromA*self.numbFromB))
		self._runTestFunct()
		actObj = self.binObjA
		self.assertEqual(expObj, actObj)
コード例 #8
0
	def testExpectedValsA(self):
		#Create the expected output bin object
		expBinObj = tCode.NDimensionalBinnedResults([self.edgesA])
		expBinObj.initialiseCountsMatrix(countKey="fake_counts")
		expBinObj.binVals["fake_counts"][0] = self.binObjA.binVals["fake_counts"][0][0] + self.binObjA.binVals["fake_counts"][0][1] + self.binObjA.binVals["fake_counts"][0][2]
		expBinObj.binVals["fake_counts"][1] = self.binObjA.binVals["fake_counts"][1][0] + self.binObjA.binVals["fake_counts"][1][1]
		expBinObj.binVals["weighted_average"] = np.array( [sum([ (2/8)*0.5, (5/8)*1.5, (1/8)*2.5 ]),
		                                                  sum([ (8/9)*0.5, (1/9)*1.5 ])] )   

		actBinObj = self._runTestFunct()
		self.assertEqual(expBinObj,actBinObj)
コード例 #9
0
	def testExpectedCaseA(self):
		#Manually get the exp counts and norm-counts matrices
		expCounts = self._loadExpCountsA()
		expNormCounts = self._loadExpNormCountsA()
		expBinVals = {self.countKey: expCounts, self.normCountKey: expNormCounts}

		#Get the expected bin obj
		expBinObj = tCode.NDimensionalBinnedResults( [self.edgesA,self.edgesB], binVals=expBinVals)
		actBinObj = self._runTestFunct()

		self.assertEqual(expBinObj,actBinObj)
コード例 #10
0
	def createTestObjs(self):
		self.comboEdges = [self.edgesA, self.edgesB, self.edgesC]
		self.binObjA = tCode.NDimensionalBinnedResults(self.comboEdges)

		#Put various values there
		#Use a weird key to make sure we dont rely on it being defualt val
		self.binObjA.initialiseCountsMatrix(countKey="fake_counts") 
		self.binObjA.binVals["fake_counts"][0][0][0] = 2
		self.binObjA.binVals["fake_counts"][0][1][1] = 3
		self.binObjA.binVals["fake_counts"][0][1][0] = 5
		self.binObjA.binVals["fake_counts"][1][0][1] = 7
コード例 #11
0
	def _loadExpObj_2d(self):
		outObj = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesB], binVals={"normalised_counts":self.normCounts})
		outObj.binVals["rdf"] = np.array( [ [48.6341681483221, 7.6553783196433],
		                                    [4.05284734569351, 0.637948193303608],
		                                    [0.450316371743724, 0.07088313258929] ] )

#		outObj.binVals["rdf"] = np.array( [ [113.98633159763, 32.5675233136086],
#		                                    [12.2128212426032, 3.48937749788663],
#		                                    [2.54433775887567, 0.218086093617915] ] )

		outObj.binVals["rdf"] *= (1/(self.numbFromA*self.numbFromB))
		return outObj
コード例 #12
0
	def testExpected_normCountsMissing(self):
		self.binObjA.binVals.pop(self.normCountKey)
		self.binObjB.binVals.pop(self.normCountKey)

		#Load expected bin values
		expCounts = self._loadExpCountsA()
		expBinVals = {self.countKey:expCounts}

		#
		expBinObj = tCode.NDimensionalBinnedResults( [self.edgesA,self.edgesB],binVals=expBinVals )
		actBinObj = self._runTestFunct()

		self.assertEqual(expBinObj,actBinObj)
コード例 #13
0
	def testExpectedCaseB_3dim_to_1dim(self):
		#Setup
		self.keepDims = [0]
		self.useIdxOther = [0,0]

		#Figure out what we expect
		expBinEdges = [self.edgesA]
		expBinCounts = np.array( [[2,0]] )
		expBinObj = tCode.NDimensionalBinnedResults( expBinEdges, binVals={"fake_counts":expBinCounts} )

		#Run and test
		actBinObj = self._runTestFunct()
		self.assertEqual(expBinObj, actBinObj)
コード例 #14
0
	def _loadExpectedBinsCaseA_3d_to_2d(self):
		outEdges = [self.edgesA, self.edgesC]
		outBinObj = tCode.NDimensionalBinnedResults(outEdges)

		#
		outBinObj.initialiseCountsMatrix(countKey="fake_counts")

		outBinObj.binVals["fake_counts"][0][0] = 1+3
		outBinObj.binVals["fake_counts"][0][1] = 2+4
		outBinObj.binVals["fake_counts"][1][0] = 5+7
		outBinObj.binVals["fake_counts"][1][1] = 6+8

		return outBinObj
コード例 #15
0
	def testExpected_threeBinsAdded(self):
		self.binObjsToAdd = [self.binObjA, self.binObjB, self.binObjA]

		#Generate expected
		expCounts = np.array(  [ [12,8,0],[0,18,12] ] )
		totalSteps = (2*self.nStepsA) + self.nStepsB
		expNormCounts = np.array( [ [12/totalSteps, 8/totalSteps,0],
		                            [0, 18/totalSteps, 12/totalSteps] ] )
		expBinVals = {self.countKey: expCounts, self.normCountKey: expNormCounts}

		#Get the expected bin object
		expBinObj = tCode.NDimensionalBinnedResults( [self.edgesA,self.edgesB], binVals=expBinVals)
		actBinObj = self._runTestFunct()

		self.assertEqual(expBinObj,actBinObj)
コード例 #16
0
	def testExpected_diffCountKey(self):
		self.countKey = "new_count_key"
		self.createTestObjs()

		#Manually get the exp counts and norm-counts matrices
		expCounts = self._loadExpCountsA()
		expNormCounts = self._loadExpNormCountsA()
		expBinVals = {self.countKey: expCounts, self.normCountKey: expNormCounts}

		#Get the expected bin obj
		expBinObj = tCode.NDimensionalBinnedResults( [self.edgesA,self.edgesB], binVals=expBinVals)
		actBinObj = self._runTestFunct()

		self.assertTrue( "new_count_key" in expBinObj.binVals.keys() )
		self.assertEqual(expBinObj,actBinObj)
コード例 #17
0
    def _getExpectedBinObjCaseA(self):
        edges = [self.aziEdges, self.pitchEdges]
        expBinObj = binResHelp.NDimensionalBinnedResults(edges)
        expBinObj.initialiseCountsMatrix()

        #Sort the unnormalised counts
        expBinObj.binVals["counts"][0][0] = 2
        expBinObj.binVals["counts"][0][1] = 1
        expBinObj.binVals["counts"][1][1] = 1

        #Sort the normalised counts (same as unnormalised for the simple case)
        expBinObj.initialiseCountsMatrix(countKey="normalised_counts")
        np.copyto(expBinObj.binVals["normalised_counts"],
                  expBinObj.binVals["counts"])

        return expBinObj
コード例 #18
0
	def testExpectedCase_1d(self):
		#Create expected
		expObj = tCode.NDimensionalBinnedResults([self.edgesA], binVals={"normalised_counts":np.array([ 12, 9,8 ]) })
		expObj.binVals["rdf"] = [ 5.72957795130823, 0.613883351925882, 0.068209261325098 ]

		#Create actual + run
		self.normCounts = [ 12, 9,8 ]
		self.volumes = self.volumeA
		self.edgesTot = [self.edgesA]
		self.numbAtomsTo = [self.numbToA]
		self.numbAtomsFrom = [self.numbFromA]
		self.createTestObjs()
		self._runTestFunct()
		actObj = self.binObjA

		self.assertEqual(expObj,actObj)
コード例 #19
0
	def testExpectedBinCentresArray_3dim(self):
		self.edgesC = [7,8,10] #Putting in a diff width one
		edges = [self.edgesA, self.edgesB, self.edgesC]
		self.testObj = tCode.NDimensionalBinnedResults(edges)

		expArray = np.zeros( [2,3,2,len(edges)] )

		#Only [X][X][1] are different from theyd be if using the matrix above to calculate
		expArray[0][0][0] = [ 1.5, 5.5, 7.5 ] 
		expArray[0][0][1] = [ 1.5, 5.5, 9 ]
		expArray[0][1][0] = [ 1.5, 4.5, 7.5 ]
		expArray[0][1][1] = [ 1.5, 4.5, 9 ]
		expArray[0][2][0] = [ 1.5, 3.5, 7.5 ]
		expArray[0][2][1] = [ 1.5, 3.5, 9 ]

		expArray[1][0][0] = [ 2.5, 5.5, 7.5 ]
		expArray[1][0][1] = [ 2.5, 5.5, 9 ]
		expArray[1][1][0] = [ 2.5, 4.5, 7.5 ]
		expArray[1][1][1] = [ 2.5, 4.5, 9 ]
		expArray[1][2][0] = [ 2.5, 3.5, 7.5 ]
		expArray[1][2][1] = [ 2.5, 3.5, 9 ]

		actArray = self.testObj.binCentresArray
		self.assertTrue( np.allclose(expArray,actArray) )
コード例 #20
0
	def createTestObjs(self):
		edges = [ self.edgesA, self.edgesB ]
		self.testObj = tCode.NDimensionalBinnedResults(edges)
		self.testObj.initialiseCountsMatrix()
コード例 #21
0
	def createTestObjs(self):
		binVals = {self.countKey: self.counts}
		edges = [self.edgesA, self.edgesB]
		self.testObjA = tCode.NDimensionalBinnedResults(edges, binVals=binVals) 
コード例 #22
0
	def testRaisesWhenEdgesDontMatch(self):
		self.binObjB = tCode.NDimensionalBinnedResults([self.edgesA,self.edgesC], binVals=self.binValsB)
		self.binObjsToAdd = [self.binObjA, self.binObjB]

		with self.assertRaises(ValueError):
			self._runTestFunct()
コード例 #23
0
	def createTestObjs(self):
		self.binObjA = tCode.NDimensionalBinnedResults(self.edgesTot, binVals={"normalised_counts":np.array(self.normCounts)})
コード例 #24
0
	def _loadExpectedBinsCaseA(self):
		outObj = tCode.NDimensionalBinnedResults( [self.edgesA, self.edgesC] )
		outObj.initialiseCountsMatrix(countKey="fake_counts")
		outObj.binVals["fake_counts"][0][0] = 5
		outObj.binVals["fake_counts"][0][1] = 3
		return outObj
コード例 #25
0
	def createTestObjs(self):
		self.testObj = tCode.NDimensionalBinnedResults(self.edges, binVals=self.binVals)
		self.testObj.initialiseCountsMatrix()
コード例 #26
0
	def testRaisesForMoreThanTwoDims(self):
		""" Not sure what to do for >2 dims at the moment (likely it'd be pointless anyway though) """
		self.binObjA = tCode.NDimensionalBinnedResults( self.comboEdges + [[6,7]] )
		with self.assertRaises(NotImplementedError):
			self._runTestFunct()