def test_dstrainfit(self): #create some fake strains d0=2.34 e1=0.002 e2=-0.0012 e12=0.0008 #the azimuthal angle phi = np.linspace(-np.pi/2,np.pi/2,23) #distort the lattice as function of phi edata = d0 + d0*(e1*np.cos(phi)**2 + e2*np.sin(phi)**2 + e12*np.sin(2*phi)) edata += np.random.uniform(-0.00002,0.00002,edata.size) edata = unumpy.uarray((edata,np.sqrt(edata))) #fit result = strain.strain_from_d(edata,phi,d0) #check the results self.assertAlmostEqual(e1,result['strain_x'].nominal_value,4) self.assertAlmostEqual(e2,result['strain_y'].nominal_value,4) self.assertAlmostEqual(e12,result['strain_xy'].nominal_value,4)
def test_dstrain_2calc(self): #create some fake strains d0=2.34 e1=0.002 e2=-0.0012 e12=0.000 #the azimuthal angle phi = np.array([0,np.pi/2]) edata = d0 + d0*(e1*np.cos(phi)**2 + e2*np.sin(phi)**2 + e12*np.sin(2*phi)) edata += np.random.uniform(-0.00002,0.00002,edata.size) edata = unumpy.uarray((edata,np.sqrt(edata))) #fit result = strain.strain_from_d(edata,phi,d0) #check the results self.assertAlmostEqual(e1,result['strain_x'].nominal_value,4) self.assertAlmostEqual(e2,result['strain_y'].nominal_value,4) self.assertAlmostEqual(0,result['strain_xy'].nominal_value,4) #check this fails if too many phi badphi = np.array([0.1,np.pi/3]) self.assertRaises(ValueError,strain.strain_from_d,edata,badphi,d0)