Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| recherche:methodes:ebsd:edax_conv [27/10/2020 09:47] – créée simon.breumier | recherche:methodes:ebsd:edax_conv [27/10/2020 10:16] (Version actuelle) – simon.breumier | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ==== Convert Oxford EBSD patterns in HDF5 for EMSOFT ==== | ==== Convert Oxford EBSD patterns in HDF5 for EMSOFT ==== | ||
| + | |||
| + | The following python script converts a list of pattern in the //picRep// folder with naming conventions " | ||
| + | |||
| + | To use it, change the values of the variables in the PARAMETERS section to the one that fits to you. | ||
| + | |||
| + | Note that you will need an HDF5 template file, I usually use one of the HDF5 provided for the [[https:// | ||
| + | |||
| + | < | ||
| + | ########################################################################## | ||
| + | # Converts a set of Kikuchi pattern to a readable EDAX HDF5 format | ||
| + | # Kikuchi pattern must all be in the same folder (defined by ' | ||
| + | # Pattern names must be of the form ' | ||
| + | # As all the patterns are stored in RAM for writing, it is possible to make an HDF5 | ||
| + | # of a subdomain of the map | ||
| + | # | ||
| + | # Note: for now, the scrip just fills the Patterns and their coordinates on the map | ||
| + | # All other fields contain dummy values. | ||
| + | # | ||
| + | # 31/ | ||
| + | ########################################################################## | ||
| + | import h5py | ||
| + | import matplotlib.pyplot as plt | ||
| + | import matplotlib.image as mpimg | ||
| + | from PIL import Image | ||
| + | import numpy as np | ||
| + | import os | ||
| + | from scipy import ndimage | ||
| + | import math | ||
| + | from get_tiff_param import get_pat_pc | ||
| + | from progress.bar import Bar | ||
| + | |||
| + | print(' | ||
| + | #################### | ||
| + | |||
| + | out = ' | ||
| + | picRep = ' | ||
| + | template_file=' | ||
| + | # Carto parameters | ||
| + | Xsize=201 #Map width in px | ||
| + | Ysize=164 #Map height in px | ||
| + | X0 = 1 #X position to start the writing (usefull to make an HDF5 file with a partition of your map) | ||
| + | Y0 = 1 #Y position to start the writing | ||
| + | Xmax = 201 #X position to stop the writting | ||
| + | Ymax = 164 #Y position to stop the writting | ||
| + | step=0.003 #Step size in mm | ||
| + | |||
| + | #Pattern dimensions (after binning) | ||
| + | pattHeight = 512 | ||
| + | pattWidth = 672 | ||
| + | |||
| + | ##################################### | ||
| + | tmp = h5py.File(template_file,' | ||
| + | |||
| + | f = h5py.File(out+' | ||
| + | for elem in tmp.keys(): | ||
| + | tmp.copy(elem, | ||
| + | tmp.close() | ||
| + | |||
| + | ############# | ||
| + | del(f[' | ||
| + | f.create_dataset(' | ||
| + | head = f[' | ||
| + | print(' | ||
| + | tmp = f[' | ||
| + | tmp[...] = pattHeight | ||
| + | tmp = f[' | ||
| + | tmp[...] = pattWidth | ||
| + | tmp = f[' | ||
| + | tmp[...] = 70. | ||
| + | tmp = f[' | ||
| + | tmp[...] = step*1000 | ||
| + | tmp = f[' | ||
| + | tmp[...] = step*1000 | ||
| + | tmp = f[' | ||
| + | tmp[...] = 16022. | ||
| + | tmp = f[' | ||
| + | tmp[...] = Xmax - X0+1 | ||
| + | tmp = f[' | ||
| + | tmp[...] = Ymax - Y0+1 | ||
| + | |||
| + | ############# | ||
| + | if 'Scan 4' in f.keys(): | ||
| + | del(f[' | ||
| + | if 'Scan 6' in f.keys(): | ||
| + | del(f[' | ||
| + | |||
| + | ebsdDat =f[' | ||
| + | print(' | ||
| + | print(' | ||
| + | listPat = os.listdir(picRep) | ||
| + | if ' | ||
| + | lenPat = len(listPat) | ||
| + | print(' | ||
| + | dum = np.ones((Xsize-X0)*(Ysize-Y0)+1) | ||
| + | i =0 | ||
| + | if 'X Position' | ||
| + | del(f[' | ||
| + | |||
| + | if 'Y Position' | ||
| + | del(f[' | ||
| + | |||
| + | if ' | ||
| + | del(f[' | ||
| + | |||
| + | dumList = [' | ||
| + | |||
| + | for elem in dumList: | ||
| + | if elem in f[' | ||
| + | del(f[' | ||
| + | # | ||
| + | |||
| + | ############# | ||
| + | lenTot = (Xmax-X0+1)*(Ymax-Y0+1) | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | |||
| + | Patval = [] | ||
| + | DDs = [] | ||
| + | PCXs = [] | ||
| + | PCYs = [] | ||
| + | i = 0 | ||
| + | last = 0 | ||
| + | j = 0 | ||
| + | limAct = [Ysize/ | ||
| + | tmp, | ||
| + | tmp = tmp+' | ||
| + | numZeros = len(picId.split(' | ||
| + | print(' | ||
| + | |||
| + | bar = Bar(' | ||
| + | |||
| + | for Yact in range(Y0, | ||
| + | for Xact in range(X0, | ||
| + | picId = (Yact-1)*Xsize+Xact | ||
| + | picId_str = (numZeros-math.floor(math.log10(picId)))*' | ||
| + | PCX, PCY, lfov, Xbeam, Ybeam, DD = get_pat_pc(picRep+'/' | ||
| + | tabID = (Yact-Y0)*(Xmax-X0+1)+Xact-X0 | ||
| + | f[' | ||
| + | f[' | ||
| + | DDs.append(DD*pattWidth/ | ||
| + | PCXs.append(PCX) | ||
| + | PCYs.append(PCY) | ||
| + | imActu = mpimg.imread(picRep+'/' | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | i+=1 | ||
| + | bar.next() | ||
| + | |||
| + | bar.finish() | ||
| + | print(' | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | f[' | ||
| + | f.close() | ||
| + | print(' | ||
| + | print(' | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | </ | ||