Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BM32ESRF committed Nov 15, 2022
1 parent 4ee5483 commit 797dbf0
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 150 deletions.
211 changes: 193 additions & 18 deletions lauetoolsnn/end_to_end_scripts/LaueNN_pyScript_3_or_more_phase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 1,
"id": "e2ad7bb0",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -149,10 +149,10 @@
" # =============================================================================\n",
" # # [PEAKSEARCH]\n",
" # =============================================================================\n",
" \"intensity_threshold\" : 2,## for skimage this is of image standard deviation\n",
" \"intensity_threshold\" : 1,## for skimage this is of image standard deviation\n",
" \"boxsize\" : 10,## for skimage this is box size to fit\n",
" \"fit_peaks_gaussian\" : 1,## for skimage this is of no sense\n",
" \"FitPixelDev\" : 15, ## for skimage this is distance between peaks to avoid\n",
" \"FitPixelDev\" : 3, ## for skimage this is distance between peaks to avoid\n",
" \"NumberMaxofFits\" : 3000,## for skimage this is maximum leastquare attempts before giving up\n",
" \"mode\": \"skimage\",\n",
"\n",
Expand Down Expand Up @@ -189,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 2,
"id": "ebdbbba9",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -328,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 3,
"id": "9dda2478-2ff0-4d2a-87d1-f06a7d330446",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -498,14 +498,15 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 4,
"id": "59988fb3-5ecf-45d1-ada2-9671dec9e30f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"adjustText library not installed\n",
"Writing settings file in /home/esrf/purushot/anaconda3/envs/lauenn/lib/python3.7/site-packages/lauetoolsnn/settings.ini\n",
"Directory where trained model is stored : /home/esrf/purushot/Desktop/LaueNN_tutorial/LaueNN_script/GaN_Si_MultiMaterial\n",
"expected 2 files based on the XY grid (1,2) defined by user\n",
Expand All @@ -523,21 +524,21 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Predicting for /home/esrf/purushot/Desktop/LaueNN_tutorial/LaueNN_script/nw1_0000.tif\n"
"Predicting for /home/esrf/purushot/Desktop/LaueNN_tutorial/LaueNN_script/nw1_0000.tif\n",
"Skimage mode (strict constraints) of PeakSearch is used for the PeakSearch\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:00<00:00, 41.70it/s]"
"100%|██████████| 2/2 [00:00<00:00, 31.69it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Skimage mode (strict constraints) of PeakSearch is used for the PeakSearch\n",
"Predicting for /home/esrf/purushot/Desktop/LaueNN_tutorial/LaueNN_script/nw1_0001.tif\n",
"Skimage mode (strict constraints) of PeakSearch is used for the PeakSearch\n"
]
Expand Down Expand Up @@ -880,15 +881,19 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 5,
"id": "f6cde8a9-5b87-4216-8b12-39e911fd658b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"data saved in /home/esrf/purushot/Desktop/LaueNN_tutorial/LaueNN_script/GaN_Si_MultiMaterial//results_GaN_Si_2022-11-15_00-45-42\n"
"ename": "ImportError",
"evalue": "cannot import name 'write_average_orientationMM' from 'lauetoolsnn.utils_lauenn' (/home/esrf/purushot/anaconda3/envs/lauenn/lib/python3.7/site-packages/lauetoolsnn/utils_lauenn.py)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-6308e5f0047e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlauetoolsnn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils_lauenn\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mglobal_plots_MM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwrite_average_orientationMM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconvert_pickle_to_hdf5MM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwrite_prediction_statsMM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwrite_MTEXdataMM\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;31m#% Save results\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0msave_directory_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel_direc\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"//results_\"\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mprefix_mat\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"_\"\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mc_time\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msave_directory_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmakedirs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msave_directory_\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mImportError\u001b[0m: cannot import name 'write_average_orientationMM' from 'lauetoolsnn.utils_lauenn' (/home/esrf/purushot/anaconda3/envs/lauenn/lib/python3.7/site-packages/lauetoolsnn/utils_lauenn.py)"
]
}
],
Expand Down Expand Up @@ -937,10 +942,12 @@
"except:\n",
" print(\"Error in the Prediction statistic module\")\n",
" \n",
"## Need to rewrite the function for write_prediction_stats in MultiMaterial case\n",
"#write_MTEXdata(save_directory_, material_, material1_, rotation_matrix,\\\n",
"# lattice_material, lattice_material1, lim_x, lim_y, mat_global,\\\n",
"# input_params[\"symmetry\"][0], input_params[\"symmetry\"][1])\n",
"try:\n",
" write_MTEXdataMM(save_directory_, material_, rotation_matrix,\\\n",
" lattice_material, lim_x, lim_y, mat_global,\\\n",
" input_params[\"symmetry\"])\n",
"except:\n",
" print(\"Error in the Prediction statistic module\")\n",
"\n",
"try:\n",
" global_plots_MM(lim_x, lim_y, rotation_matrix, strain_matrix, strain_matrixs, \n",
Expand All @@ -951,6 +958,174 @@
" print(\"Error in the global plots module\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "79507b4d-c7de-493b-aa6c-15749a89894c",
"metadata": {},
"outputs": [],
"source": [
"from lauetoolsnn.utils_lauenn import OrientationMatrix2Euler\n",
"save_directory_ = model_direc+\"//results_\"+prefix_mat+\"_\"+c_time\n",
"if not os.path.exists(save_directory_):\n",
" os.makedirs(save_directory_)\n",
" \n",
"def write_MTEXdataMM(save_directory_, material_, rotation_matrix1,\\\n",
" lattice_, lim_x, lim_y, mat_global,\\\n",
" symmetry_global_):\n",
" print(\"To be rewritten the function\")\n",
" ## write MTEX file\n",
" rotation_matrix = [[] for i in range(len(rotation_matrix1))]\n",
" for i in range(len(rotation_matrix)):\n",
" rotation_matrix[i].append(np.zeros((lim_x*lim_y,3,3)))\n",
"\n",
" for i in range(len(rotation_matrix1)):\n",
" temp_mat = rotation_matrix1[i][0] \n",
" for j in range(len(temp_mat)):\n",
" orientation_matrix = temp_mat[j,:,:] \n",
" ## rotate orientation by 40degrees to bring in Sample RF\n",
" omega = np.deg2rad(-40)\n",
" # # rotation de -omega autour de l'axe x (or Y?) pour repasser dans Rsample\n",
" cw = np.cos(omega)\n",
" sw = np.sin(omega)\n",
" mat_from_lab_to_sample_frame = np.array([[cw, 0.0, sw], [0.0, 1.0, 0.0], [-sw, 0, cw]]) #Y\n",
" # mat_from_lab_to_sample_frame = np.array([[1.0, 0.0, 0.0], [0.0, cw, -sw], [0.0, sw, cw]]) #X\n",
" # mat_from_lab_to_sample_frame = np.array([[cw, -sw, 0.0], [sw, cw, 0.0], [0.0, 0.0, 1.0]]) #Z\n",
" orientation_matrix = np.dot(mat_from_lab_to_sample_frame.T, orientation_matrix)\n",
"\n",
" if np.linalg.det(orientation_matrix) < 0:\n",
" orientation_matrix = -orientation_matrix\n",
" rotation_matrix[i][0][j,:,:] = orientation_matrix\n",
" \n",
" header = [\n",
" \"Channel Text File\",\n",
" \"Prj lauetoolsnn\",\n",
" \"Author [Ravi raj purohit]\",\n",
" \"JobMode Grid\",\n",
" \"XCells \"+str(lim_x),\n",
" \"YCells \"+str(lim_y),\n",
" \"XStep 1.0\",\n",
" \"YStep 1.0\",\n",
" \"AcqE1 0\",\n",
" \"AcqE2 0\",\n",
" \"AcqE3 0\",\n",
" \"Euler angles refer to Sample Coordinate system (CS0)! Mag 100 Coverage 100 Device 0 KV 15 TiltAngle 40 TiltAxis 0\",\n",
" \"Phases 2\",\n",
" ]\n",
" \n",
" if len(material_) > 1:\n",
" for ino, imat in enumerate(material_):\n",
" lattice = lattice_[ino]\n",
" symmetry_global = symmetry_global_[ino]\n",
" if symmetry_global ==\"cubic\":\n",
" material0_lauegroup = \"11\"\n",
" elif symmetry_global ==\"monoclinic\":\n",
" material0_lauegroup = \"2\"\n",
" elif symmetry_global == \"hexagonal\":\n",
" material0_lauegroup = \"9\"\n",
" elif symmetry_global == \"orthorhombic\":\n",
" material0_lauegroup = \"3\"\n",
" elif symmetry_global == \"tetragonal\":\n",
" material0_lauegroup = \"5\"\n",
" elif symmetry_global == \"trigonal\":\n",
" material0_lauegroup = \"7\"\n",
" elif symmetry_global == \"triclinic\":\n",
" material0_lauegroup = \"1\"\n",
" \n",
" mat_string = str(round(lattice._lengths[0]*10,5))+\";\"+str(round(lattice._lengths[1]*10,5))+\";\"+\\\n",
" str(round(lattice._lengths[2]*10,5))+\"\\t\"+str(round(lattice._angles[0],5))+\";\"+\\\n",
" str(round(lattice._angles[1],5))+\";\"+str(round(lattice._angles[2],5))+\"\\t\"+\"Material\"+str(int(ino+1))+ \"\\t\"+material0_lauegroup+ \"\\t\"+\"????\"+\"\\t\"+\"????\"\n",
" header.append(mat_string)\n",
"\n",
" else:\n",
" lattice = lattice_[0]\n",
" symmetry_global = symmetry_global_[0]\n",
" if symmetry_global ==\"cubic\":\n",
" material0_lauegroup = \"11\"\n",
" elif symmetry_global ==\"monoclinic\":\n",
" material0_lauegroup = \"2\"\n",
" elif symmetry_global == \"hexagonal\":\n",
" material0_lauegroup = \"9\"\n",
" elif symmetry_global == \"orthorhombic\":\n",
" material0_lauegroup = \"3\"\n",
" elif symmetry_global == \"tetragonal\":\n",
" material0_lauegroup = \"5\"\n",
" elif symmetry_global == \"trigonal\":\n",
" material0_lauegroup = \"7\"\n",
" elif symmetry_global == \"triclinic\":\n",
" material0_lauegroup = \"1\"\n",
" \n",
" mat_string = str(round(lattice._lengths[0]*10,5))+\";\"+str(round(lattice._lengths[1]*10,5))+\";\"+\\\n",
" str(round(lattice._lengths[2]*10,5))+\"\\t\"+str(round(lattice._angles[0],5))+\";\"+\\\n",
" str(round(lattice._angles[1],5))+\";\"+str(round(lattice._angles[2],5))+\"\\t\"+\"Material1\"+ \"\\t\"+material0_lauegroup+ \"\\t\"+\"????\"+\"\\t\"+\"????\"\n",
" header.append(mat_string)\n",
"\n",
" final_line = \"Phase X Y Bands Error Euler1 Euler2 Euler3 MAD BC BS\"\n",
" header.append(final_line)\n",
" \n",
" # =================CALCULATION OF POSITION=====================================\n",
" for index in range(len(rotation_matrix)):\n",
" euler_angles = np.zeros((len(rotation_matrix[index][0]),3))\n",
" phase_euler_angles = np.zeros(len(rotation_matrix[index][0]))\n",
" for i in range(len(rotation_matrix[index][0])):\n",
" if np.all(rotation_matrix[index][0][i,:,:] == 0):\n",
" continue\n",
" euler_angles[i,:] = OrientationMatrix2Euler(rotation_matrix[index][0][i,:,:])\n",
" phase_euler_angles[i] = mat_global[index][0][i] \n",
" \n",
" euler_angles = euler_angles.reshape((lim_x,lim_y,3))\n",
" phase_euler_angles = phase_euler_angles.reshape((lim_x,lim_y,1))\n",
" \n",
" a = euler_angles\n",
" \n",
" if len(material_) > 1:\n",
" prefix_mat = material_[0]\n",
" for ino, imat in enumerate(material_):\n",
" if ino == 0:\n",
" continue\n",
" prefix_mat = prefix_mat + \"_\" + imat\n",
" else:\n",
" prefix_mat = material_[0]\n",
"\n",
" filename125 = save_directory_+ \"//\"+prefix_mat+\"_MTEX_UBmat_\"+str(index)+\"_LT.ctf\"\n",
" \n",
" f = open(filename125, \"w\")\n",
" for ij in range(len(header)):\n",
" f.write(header[ij]+\" \\n\")\n",
" \n",
" for i123 in range(euler_angles.shape[1]):\n",
" y_step = 1 * i123\n",
" for j123 in range(euler_angles.shape[0]):\n",
" x_step = 1 * j123\n",
" phase_id = int(phase_euler_angles[j123,i123,0])\n",
" eul = str(phase_id)+'\\t' + \"%0.4f\" % x_step +'\\t'+\"%0.4f\" % y_step+'\\t8\\t0\\t'+ \\\n",
" \"%0.4f\" % a[j123,i123,0]+'\\t'+\"%0.4f\" % a[j123,i123,1]+ \\\n",
" '\\t'+\"%0.4f\" % a[j123,i123,2]+'\\t0.0001\\t180\\t0\\n'\n",
" string = eul\n",
" f.write(string)\n",
" f.close()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "6964b722-5674-4465-a840-929f1c7d52ad",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To be rewritten the function\n"
]
}
],
"source": [
"write_MTEXdataMM(save_directory_, material_, rotation_matrix,\\\n",
" lattice_material, lim_x, lim_y, mat_global,\\\n",
" input_params[\"symmetry\"])\n"
]
},
{
"cell_type": "markdown",
"id": "b489c1a5-1301-4f4d-ac16-cbb79d876dd3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
from itertools import accumulate
## if LaueToolsNN is properly installed
from lauetoolsnn.utils_lauenn import get_multimaterial_detail, new_MP_multimat_function, resource_path, global_plots_MM,\
write_average_orientation, convert_pickle_to_hdf5, write_prediction_stats, write_MTEXdata
write_average_orientationMM, convert_pickle_to_hdf5MM, write_prediction_statsMM, write_MTEXdataMM
from lauetoolsnn.lauetools import dict_LaueTools as dictLT
from lauetoolsnn.NNmodels import read_hdf5

Expand Down Expand Up @@ -819,31 +819,31 @@

## Lets save also a set of average UB matrix in text file to be used with user_OM setting
try:
write_average_orientation(save_directory_, mat_global, rotation_matrix,
match_rate, lim_x, lim_y, crystal, crystal1,
write_average_orientationMM(save_directory_, mat_global, rotation_matrix,
match_rate, lim_x, lim_y, crystal,
radius=10, grain_ang=5, pixel_grain_definition=3)
except:
print("Error with Average orientation and grain index calculation")

try:
convert_pickle_to_hdf5(save_directory_, files_treated, rotation_matrix, strain_matrix,
convert_pickle_to_hdf5MM(save_directory_, files_treated, rotation_matrix, strain_matrix,
strain_matrixs, match_rate, spots_len, iR_pix,
fR_pix, colx, coly, col, mat_global,
material_, material1_, lim_x, lim_y)
material_, lim_x, lim_y)
except:
print("Error writting H5 file")

try:
write_prediction_stats(save_directory_, material_, material1_, files_treated,\
write_prediction_statsMM(save_directory_, material_, files_treated,\
lim_x, lim_y, best_match, strain_matrixs, strain_matrix, iR_pix,\
fR_pix, mat_global)
except:
print("Error writting prediction statistics file")

try:
write_MTEXdata(save_directory_, material_, material1_, rotation_matrix,\
lattice_material, lattice_material1, lim_x, lim_y, mat_global,\
input_params["symmetry"][0], input_params["symmetry"][1])
write_MTEXdataMM(save_directory_, material_, rotation_matrix,\
lattice_material, lim_x, lim_y, mat_global,\
input_params["symmetry"])
except:
print("Error writting MTEX orientation file")

Expand Down
Loading

0 comments on commit 797dbf0

Please sign in to comment.