def to_strain_and_angs(s_tilde, cell, nelm): fun_val = [] ubs = s_tilde.reshape(nelm, 3, 3) for i in range(nelm): ubi = np.linalg.inv(ubs[i]) u, eps = tools.ubi_to_u_and_eps(ubi, cell) euler = tools.u_to_euler(u) fun_val.extend(eps) fun_val.extend(list(euler)) return np.asarray(fun_val)
def _check_angles(self, angles): '''Check consistency for euler_to_u() and u_to_euler(). I.e check that the orientation matrix constructed for some set of angles is recovered again when passing between the two functions. ''' for phi1 in angles: for PHI in angles: for phi2 in angles: U = tools.euler_to_u(phi1, PHI, phi2) phi1_new, PHI_new, phi2_new = tools.u_to_euler(U) U_new = tools.euler_to_u(phi1_new, PHI_new, phi2_new) maxdiff = n.max(n.abs(U - U_new)) self.assertTrue(maxdiff < 1e-8) self.assertTrue(0 <= phi1_new <= 2 * n.pi) self.assertTrue(0 <= PHI_new <= 2 * n.pi) self.assertTrue(0 <= phi2_new <= 2 * n.pi)
def run_pcr(self, cif_file, grain_mask, flt, gr, number_y_scans, ymin, ystep): no_voxels = sum(grain_mask[grain_mask == 1]) unit_cell = self.field_converter.extract_cell(self.params) UBI = gr.ubi.copy() cell = tools.ubi_to_cell(UBI) U, strain = tools.ubi_to_u_and_eps(UBI, unit_cell) euler = tools.u_to_euler(U) average = np.concatenate((strain, euler), axis=None) initial_guess = np.concatenate((average, average), axis=None) for i in range(no_voxels - 2): initial_guess = np.concatenate((initial_guess, average), axis=None) th_min, th_max = setup_grain.get_theta_bounds(flt, gr) param = setup_grain.setup_experiment(self.params, cif_file, no_voxels, ystep, th_min, th_max) measured_data = setup_grain.get_measured_data(gr, flt, number_y_scans, ymin, ystep, param) hkl = setup_grain.get_hkls(param, flt, gr) voxel_positions, C, constraint = setup_grain.get_positions( grain_mask, ystep) voxel_data = find_refl_func.find_refl_func(param, hkl, voxel_positions, measured_data, unit_cell, initial_guess, ymin, number_y_scans, C, constraint) bounds_low, bounds_high = setup_grain.get_bounds_strain(initial_guess) solution = voxel_data.steepest_descent(bounds_low, bounds_high, initial_guess) voxels_as_grain_objects = setup_grain.map_solution_to_voxels( solution, grain_mask, no_voxels, voxel_data, var_choice='strain') return voxels_as_grain_objects
def write_grains(param): # Save the generated grain parameters, pos, U and eps # # INPUT: The parameter set from the input file and the grain generator # OUTPUT: grainno x y z phi1 PHI phi2 U11 U12 U13 U21 U22 U23 U31 U32 U33 eps11 eps12 eps13 eps22 eps23 eps33 # # Jette Oddershede, Risoe DTU, March 31 2008 # filename = '%s/%s.gff' % (param['direc'], param['stem']) f = open(filename, 'w') # format = "%d "*1 + "%f "*1 + "%e"*1 + "%f"*18 + "\n" format = "%d " * 1 + "%d " * 1 + "%f " * 1 + "%e " * 1 + "%f " * 6 + "%0.12f " * 9 + "%0.12f " * 9 + "%e " * 6 + "\n" out = "# grain_id phase_id grainsize grainvolume x y z phi1 PHI phi2 U11 U12 U13 U21 U22 U23 U31 U32 U33 UBI11 UBI12 UBI13 UBI21 UBI22 UBI23 UBI31 UBI32 UBI33 eps11 eps12 eps13 eps22 eps23 eps33 \n" f.write(out) for i in range(param['no_grains']): euler = 180 / n.pi * tools.u_to_euler(param['U_grains_%s' % (param['grain_list'][i])]) if len(param['phase_list']) == 1: phase = param['phase_list'][0] else: phase = param['phase_grains_%s' % (param['grain_list'][i])] b = tools.epsilon_to_b( param['eps_grains_%s' % (param['grain_list'][i])], param['unit_cell_phase_%i' % phase]) u = param['U_grains_%s' % (param['grain_list'][i])] ubi = n.linalg.inv(n.dot(u, b)) * 2 * n.pi out = format % ( param['grain_list'][i], phase, param['size_grains_%s' % (param['grain_list'][i])], n.pi / 6 * (param['size_grains_%s' % (param['grain_list'][i])])**3., param['pos_grains_%s' % (param['grain_list'][i])][0], param['pos_grains_%s' % (param['grain_list'][i])][1], param['pos_grains_%s' % (param['grain_list'][i])][2], euler[0], euler[1], euler[2], param['U_grains_%s' % (param['grain_list'][i])][0, 0], param['U_grains_%s' % (param['grain_list'][i])][0, 1], param['U_grains_%s' % (param['grain_list'][i])][0, 2], param['U_grains_%s' % (param['grain_list'][i])][1, 0], param['U_grains_%s' % (param['grain_list'][i])][1, 1], param['U_grains_%s' % (param['grain_list'][i])][1, 2], param['U_grains_%s' % (param['grain_list'][i])][2, 0], param['U_grains_%s' % (param['grain_list'][i])][2, 1], param['U_grains_%s' % (param['grain_list'][i])][2, 2], ubi[0, 0], ubi[0, 1], ubi[0, 2], ubi[1, 0], ubi[1, 1], ubi[1, 2], ubi[2, 0], ubi[2, 1], ubi[2, 2], param['eps_grains_%s' % (param['grain_list'][i])][0], param['eps_grains_%s' % (param['grain_list'][i])][1], param['eps_grains_%s' % (param['grain_list'][i])][2], param['eps_grains_%s' % (param['grain_list'][i])][3], param['eps_grains_%s' % (param['grain_list'][i])][4], param['eps_grains_%s' % (param['grain_list'][i])][5], ) f.write(out) f.close()
def write_voxels(param): ''' Save the generated voxel parameters, pos, U and eps INPUT: The parameter set from the input file and the voxel generator OUTPUT: voxelno x y z phi1 PHI phi2 U11 U12 U13 U21 U22 U23 U31 U32 U33 eps11 eps12 eps13 eps22 eps23 eps33 ''' filename = '%s/%s.gff' %(param['direc'],param['stem']) with open(filename,'w') as f: # format = "%d "*1 + "%f "*1 + "%e"*1 + "%f"*18 + "\n" format = "%d "*1 + "%d "*1 + "%f "*1 + "%e "*1 + "%f "*6 + "%0.12f "*9 + "%0.12f "*9 + "%e "*6 +"\n" out = "# voxel_id phase_id voxelsize voxelvolume x y z phi1 PHI phi2 U11 U12 U13 U21 U22 U23 U31 U32 U33 UBI11 UBI12 UBI13 UBI21 UBI22 UBI23 UBI31 UBI32 UBI33 eps11 eps12 eps13 eps22 eps23 eps33 \n" f.write(out) for i in range(param['no_voxels']): euler = 180/n.pi*tools.u_to_euler(param['U_voxels_%s' %(param['voxel_list'][i])]) if len(param['phase_list']) == 1: phase = param['phase_list'][0] else: phase = param['phase_voxels_%s' %(param['voxel_list'][i])] b = tools.epsilon_to_b(param['eps_voxels_%s' %(param['voxel_list'][i])], param['unit_cell_phase_%i' %phase ]) u = param['U_voxels_%s' %(param['voxel_list'][i])] ubi = n.linalg.inv(n.dot(u,b))*2*n.pi out = format %(param['voxel_list'][i], phase, param['size_voxels_%s' %(param['voxel_list'][i])], n.pi/6*(param['size_voxels_%s' %(param['voxel_list'][i])])**3., param['pos_voxels_%s' %(param['voxel_list'][i])][0], param['pos_voxels_%s' %(param['voxel_list'][i])][1], param['pos_voxels_%s' %(param['voxel_list'][i])][2], euler[0], euler[1], euler[2], param['U_voxels_%s' %(param['voxel_list'][i])][0,0], param['U_voxels_%s' %(param['voxel_list'][i])][0,1], param['U_voxels_%s' %(param['voxel_list'][i])][0,2], param['U_voxels_%s' %(param['voxel_list'][i])][1,0], param['U_voxels_%s' %(param['voxel_list'][i])][1,1], param['U_voxels_%s' %(param['voxel_list'][i])][1,2], param['U_voxels_%s' %(param['voxel_list'][i])][2,0], param['U_voxels_%s' %(param['voxel_list'][i])][2,1], param['U_voxels_%s' %(param['voxel_list'][i])][2,2], ubi[0,0], ubi[0,1], ubi[0,2], ubi[1,0], ubi[1,1], ubi[1,2], ubi[2,0], ubi[2,1], ubi[2,2], param['eps_voxels_%s' %(param['voxel_list'][i])][0], param['eps_voxels_%s' %(param['voxel_list'][i])][1], param['eps_voxels_%s' %(param['voxel_list'][i])][2], param['eps_voxels_%s' %(param['voxel_list'][i])][3], param['eps_voxels_%s' %(param['voxel_list'][i])][4], param['eps_voxels_%s' %(param['voxel_list'][i])][5], ) f.write(out)