-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notebook to show how to use python to call matlab mtex to convert pol…
…e figure to texture. with this, users don't have to run mtex gui.
- Loading branch information
Showing
1 changed file
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/SNS/users/lj7/imaging/testmtex\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"workdir = \"/SNS/users/lj7/imaging/testmtex\"\n", | ||
"!mkdir -p {workdir}\n", | ||
"%cd {workdir}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os, numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Modules" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Overwriting startup.m\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%file startup.m\n", | ||
"addpath('/HFIR/CG1D/shared/mtex/mtex-4.5.2/')\n", | ||
"startup_mtex" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 44, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Overwriting odf2VPSC.m\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%file odf2VPSC.m\n", | ||
"function odf2VPSC(odf,filename,varargin)\n", | ||
"% export an ODF to the VPSC format\n", | ||
"%\n", | ||
"%% Syntax\n", | ||
"% export_VPSC(odf,'file.txt','points',points)\n", | ||
"%\n", | ||
"%% Input\n", | ||
"% odf - ODF to be exported\n", | ||
"% filename - name of the ascii file\n", | ||
"%\n", | ||
"%% Options\n", | ||
"% points - number of orientations\n", | ||
"%\n", | ||
"%% See also\n", | ||
"% ODFImportExport\n", | ||
" \n", | ||
"% get number of points\n", | ||
"points = get_option(varargin,'points',5000);\n", | ||
"\n", | ||
"% simulate orientations\n", | ||
"orientations = calcOrientations(odf,points,varargin{:});\n", | ||
"\n", | ||
"% export\n", | ||
"export_VPSC(orientations,filename,varargin{:});\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Writing polfig2VPSC2.m\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%file polfig2VPSC.m\n", | ||
"function polfig2VPSC(polfigpath, hkls, outpath)\n", | ||
"%% Import Script for PoleFigure Data\n", | ||
"\n", | ||
"%% Specify Crystal and Specimen Symmetries\n", | ||
"% crystal symmetry\n", | ||
"CS = crystalSymmetry('1', [1 1 1], [90,90,90]*degree, 'X||a', 'Y||b*', 'Z||c*', 'color', 'light blue');\n", | ||
"\n", | ||
"% specimen symmetry\n", | ||
"SS = specimenSymmetry('1');\n", | ||
"\n", | ||
"% plotting convention\n", | ||
"setMTEXpref('xAxisDirection','north');\n", | ||
"setMTEXpref('zAxisDirection','outOfPlane');\n", | ||
"\n", | ||
"%% Specify File Names\n", | ||
"\n", | ||
"% path to files\n", | ||
"fname = [polfigpath];\n", | ||
"\n", | ||
"%% Specify Miller Indice\n", | ||
"nhkl = size(hkls, 1);\n", | ||
"h = arrayfun( @(IDX) Miller(mat2cell(hkls(IDX,:), 1, ones(1, 3)), CS), (1:nhkl).', 'uniform', 0);\n", | ||
"\n", | ||
"%% Import the Data\n", | ||
"\n", | ||
"% create a Pole Figure variable containing the data\n", | ||
"pf = loadPoleFigure(fname,h,CS,SS,'interface','siemens');\n", | ||
"\n", | ||
"odf = calcODF(pf);\n", | ||
"odf2VPSC(odf, outpath);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Start matlab" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matlab.engine, matlab\n", | ||
"_ml_engine = matlab.engine.start_matlab()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"hkls = matlab.double([[1,1,1], [2,0,0], [2,2,0], [2,2,2] ])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import StringIO\n", | ||
"out = StringIO.StringIO()\n", | ||
"err = StringIO.StringIO()\n", | ||
"\n", | ||
"_ml_engine.polfig2VPSC(\n", | ||
" \"/SNS/users/lj7/dv/imaging/braggedgemodeling/tests/data/VULCAN.rpf\", \n", | ||
" hkls,\n", | ||
" \"tmp.txt\",\n", | ||
" nargout=0, stdout=out, stderr=err\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 35, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"------ MTEX -- PDF to ODF inversion ------------------\n", | ||
"Call c-routine\n", | ||
"initialize solver\n", | ||
"start iteration\n", | ||
"error: 8.9615E-02 2.9824E-02 2.3061E-02 2.0660E-02 1.9165E-02 1.8185E-02 1.7371E-02 1.6778E-02 1.6254E-02 1.5831E-02 1.5434E-02 \n", | ||
"Finished PDF-ODF inversion.\n", | ||
"error: 1.5434E-02\n", | ||
"alpha: 1.0301E+00 9.2333E-01 1.0223E+00 1.0214E+00 \n", | ||
"required time: 5s\n", | ||
"ghost correction\n", | ||
"calculate with fixed background 0.49\n", | ||
"initialize solver\n", | ||
"start iteration\n", | ||
"error: 2.7973E-01 1.0409E-01 8.0557E-02 7.3001E-02 6.7023E-02 6.3385E-02 6.0057E-02 5.7743E-02 5.5601E-02 5.4001E-02 5.2487E-02 \n", | ||
"Finished PDF-ODF inversion.\n", | ||
"error: 5.2487E-02\n", | ||
"alpha: 1.0334E+00 9.2192E-01 1.0099E+00 1.0255E+00 \n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print out.getvalue()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 36, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print err.getvalue()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Exit matlab" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_ml_engine.exit()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "python2-default at jnrk-sns-analysis", | ||
"language": "python", | ||
"name": "jnrk-sns-analysis-python2-default" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.12" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": true, | ||
"toc_window_display": true | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |