Crop data¶
In this notebook, we will see how to crop the aita data.
import xarrayaita.loadData_aita as lda #here are some function to build xarrayaita structure
import xarrayaita.aita as xa
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
%matplotlib widget
Load your data¶
# path to data and microstructure
path_data='orientation_test.dat'
path_micro='micro_test.bmp'
data=lda.aita5col(path_data,path_micro)
data
<xarray.Dataset> Dimensions: (uvecs: 2, x: 1000, y: 2500) Coordinates: * x (x) float64 0.0 0.02 0.04 0.06 0.08 ... 19.92 19.94 19.96 19.98 * y (y) float64 49.98 49.96 49.94 49.92 49.9 ... 0.06 0.04 0.02 0.0 Dimensions without coordinates: uvecs Data variables: orientation (y, x, uvecs) float64 2.395 0.6451 5.377 ... 0.6098 0.6473 quality (y, x) int64 0 90 92 93 92 92 94 94 ... 96 96 96 96 96 97 97 96 micro (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 grainId (y, x) int64 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 Attributes: date: Thursday, 19 Nov 2015, 11:24 am unit: millimeters step_size: 0.02 path_dat: orientation_test.dat
xarray.Dataset
- uvecs: 2
- x: 1000
- y: 2500
- x(x)float640.0 0.02 0.04 ... 19.94 19.96 19.98
array([ 0. , 0.02, 0.04, ..., 19.94, 19.96, 19.98])
- y(y)float6449.98 49.96 49.94 ... 0.04 0.02 0.0
array([4.998e+01, 4.996e+01, 4.994e+01, ..., 4.000e-02, 2.000e-02, 0.000e+00])
- orientation(y, x, uvecs)float642.395 0.6451 ... 0.6098 0.6473
array([[[2.39476627, 0.64507369], [5.37718489, 1.04999008], [5.38905313, 1.05627326], ..., [2.05826679, 0.49654617], [5.65731024, 0.94160513], [5.68523551, 1.03218772]], [[5.35955707, 1.15837502], [5.35885894, 1.12975162], [5.3613024 , 1.11701072], ..., [2.07659274, 0.52063172], [5.64753639, 0.94073247], [5.67912685, 1.04143796]], [[5.36304773, 1.23045712], [5.36165146, 1.23132979], [2.38656322, 0.57246799], ..., ... ..., [0.62378067, 0.625526 ], [0.61784656, 0.61994095], [0.61645029, 0.61400683]], [[0.68085294, 1.12399204], [0.68050388, 1.12730816], [0.67840948, 1.13900187], ..., [0.64123397, 0.62954026], [0.62430427, 0.63529985], [0.61575216, 0.62203535]], [[0.67701322, 1.13236962], [0.67753682, 1.13690747], [0.67840948, 1.13149695], ..., [0.63652158, 0.61418136], [0.61645029, 0.63948864], [0.60981804, 0.64734262]]])
- quality(y, x)int640 90 92 93 92 92 ... 96 96 97 97 96
array([[ 0, 90, 92, ..., 0, 85, 90], [81, 82, 83, ..., 0, 84, 89], [81, 80, 3, ..., 0, 79, 88], ..., [90, 91, 91, ..., 95, 95, 95], [91, 92, 91, ..., 95, 95, 95], [92, 92, 91, ..., 97, 97, 96]])
- micro(y, x)float640.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]])
- grainId(y, x)int641 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
array([[1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], ..., [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1]])
- date :
- Thursday, 19 Nov 2015, 11:24 am
- unit :
- millimeters
- step_size :
- 0.02
- path_dat :
- orientation_test.dat
Use interactive crop for croping¶
Note
The option rebuild_gId
can be use if you want to recompute the grainId labelling. If you use this function it will change the grainId label of every grain. It can be usefull the grain boundary on the border are not close. By default the rebuild_gId=True
.
help(xa.aita.interactive_crop)
Help on function interactive_crop in module xarrayaita.aita:
interactive_crop(self, rebuild_gId=True)
out=data.aita.interactive_crop()
:param rebuild_gId: recompute the grainID
:type rebuild_gId: bool
This function can be use to crop within a jupyter notebook
It will crop the data and export the value of the crop in out.pos
out=data.aita.interactive_crop()
1. click and drag the mouse on the figure to selecte the area
2. you can draw the rectangle using the button "Draw area"
3. if you are unhappy with the selection restart to 1.
4. if you are happy with the selection click on "Export crop" (only the last rectangle is taken into account)
The rectangle coordinate are given in out.crop. In out.crop[0] are the x coordinate of the rectangle corner and in out.crop[1] the y coordinate
print('Corner, x coordinate :',out.crop[0])
print('Corner, y coordinate :',out.crop[1])
Corner, x coordinate : (3.175662382392474, 13.197167758736562, 13.197167758736562, 3.175662382392474)
Corner, y coordinate : (15.667488913267725, 15.667488913267725, 27.139350385129198, 27.139350385129198)
The new data can be found in out.ds
plt.figure()
out.ds.orientation.uvecs.calc_colormap().plot.imshow()
plt.axis('equal')
(-0.5, 500.5, -0.5, 572.5)
out.ds
<xarray.Dataset> Dimensions: (uvecs: 2, x: 501, y: 573) Coordinates: * x (x) float64 3.18 3.2 3.22 3.24 3.26 ... 13.12 13.14 13.16 13.18 * y (y) float64 27.12 27.1 27.08 27.06 ... 15.74 15.72 15.7 15.68 Dimensions without coordinates: uvecs Data variables: orientation (y, x, uvecs) float64 4.024 0.6004 4.045 ... 3.221 0.9186 quality (y, x) float64 94.0 95.0 95.0 95.0 95.0 ... 98.0 98.0 98.0 98.0 micro (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 grainId (y, x) int64 1 1 1 1 1 1 1 1 ... 144 144 144 144 144 144 144 Attributes: date: Thursday, 19 Nov 2015, 11:24 am unit: millimeters step_size: 0.02 path_dat: orientation_test.dat
xarray.Dataset
- uvecs: 2
- x: 501
- y: 573
- x(x)float643.18 3.2 3.22 ... 13.14 13.16 13.18
array([ 3.18, 3.2 , 3.22, ..., 13.14, 13.16, 13.18])
- y(y)float6427.12 27.1 27.08 ... 15.7 15.68
array([27.12, 27.1 , 27.08, ..., 15.72, 15.7 , 15.68])
- orientation(y, x, uvecs)float644.024 0.6004 4.045 ... 3.221 0.9186
array([[[4.02350752, 0.60039326], [4.04497507, 0.59533181], [4.04462601, 0.55676003], ..., [3.47320521, 0.81384703], [3.47268161, 0.81890849], [3.47372881, 0.81786129]], [[4.01704981, 0.56426495], [4.02455472, 0.56531214], [4.02839445, 0.54646259], ..., [3.47303068, 0.81629049], [3.47355428, 0.81803582], [3.47337974, 0.81716316]], [[4.0626029 , 0.57683132], [4.03851736, 0.56129789], [4.02455472, 0.55082591], ..., ... ..., [3.23112804, 0.91629786], [3.23636403, 0.90198616], [3.23269884, 0.89395764]], [[3.7074284 , 1.2398819 ], [3.73709899, 1.30166656], [3.74233498, 1.31772359], ..., [3.22205233, 0.90949107], [3.21908527, 0.89675017], [3.21891074, 0.8847074 ]], [[3.72976861, 1.2833406 ], [3.74076419, 1.29730323], [3.74163685, 1.31109133], ..., [3.22152873, 0.9138544 ], [3.2208306 , 0.93218035], [3.22117967, 0.91856679]]])
- quality(y, x)float6494.0 95.0 95.0 ... 98.0 98.0 98.0
array([[94., 95., 95., ..., 97., 97., 97.], [91., 94., 95., ..., 97., 98., 97.], [95., 96., 95., ..., 98., 97., 97.], ..., [ 0., 94., 93., ..., 98., 97., 97.], [91., 92., 92., ..., 98., 97., 98.], [93., 92., 92., ..., 98., 98., 98.]])
- micro(y, x)float640.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]])
- grainId(y, x)int641 1 1 1 1 1 ... 144 144 144 144 144
array([[ 1, 1, 1, ..., 13, 13, 13], [ 1, 1, 1, ..., 13, 13, 13], [ 1, 1, 1, ..., 13, 13, 13], ..., [156, 156, 156, ..., 144, 144, 144], [156, 156, 156, ..., 144, 144, 144], [156, 156, 156, ..., 144, 144, 144]])
- date :
- Thursday, 19 Nov 2015, 11:24 am
- unit :
- millimeters
- step_size :
- 0.02
- path_dat :
- orientation_test.dat
Overwrite the data¶
If you want to overwrite the variable data
.
data=out.ds
data
<xarray.Dataset> Dimensions: (uvecs: 2, x: 501, y: 573) Coordinates: * x (x) float64 3.18 3.2 3.22 3.24 3.26 ... 13.12 13.14 13.16 13.18 * y (y) float64 27.12 27.1 27.08 27.06 ... 15.74 15.72 15.7 15.68 Dimensions without coordinates: uvecs Data variables: orientation (y, x, uvecs) float64 4.024 0.6004 4.045 ... 3.221 0.9186 quality (y, x) float64 94.0 95.0 95.0 95.0 95.0 ... 98.0 98.0 98.0 98.0 micro (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 grainId (y, x) int64 1 1 1 1 1 1 1 1 ... 144 144 144 144 144 144 144 Attributes: date: Thursday, 19 Nov 2015, 11:24 am unit: millimeters step_size: 0.02 path_dat: orientation_test.dat
xarray.Dataset
- uvecs: 2
- x: 501
- y: 573
- x(x)float643.18 3.2 3.22 ... 13.14 13.16 13.18
array([ 3.18, 3.2 , 3.22, ..., 13.14, 13.16, 13.18])
- y(y)float6427.12 27.1 27.08 ... 15.7 15.68
array([27.12, 27.1 , 27.08, ..., 15.72, 15.7 , 15.68])
- orientation(y, x, uvecs)float644.024 0.6004 4.045 ... 3.221 0.9186
array([[[4.02350752, 0.60039326], [4.04497507, 0.59533181], [4.04462601, 0.55676003], ..., [3.47320521, 0.81384703], [3.47268161, 0.81890849], [3.47372881, 0.81786129]], [[4.01704981, 0.56426495], [4.02455472, 0.56531214], [4.02839445, 0.54646259], ..., [3.47303068, 0.81629049], [3.47355428, 0.81803582], [3.47337974, 0.81716316]], [[4.0626029 , 0.57683132], [4.03851736, 0.56129789], [4.02455472, 0.55082591], ..., ... ..., [3.23112804, 0.91629786], [3.23636403, 0.90198616], [3.23269884, 0.89395764]], [[3.7074284 , 1.2398819 ], [3.73709899, 1.30166656], [3.74233498, 1.31772359], ..., [3.22205233, 0.90949107], [3.21908527, 0.89675017], [3.21891074, 0.8847074 ]], [[3.72976861, 1.2833406 ], [3.74076419, 1.29730323], [3.74163685, 1.31109133], ..., [3.22152873, 0.9138544 ], [3.2208306 , 0.93218035], [3.22117967, 0.91856679]]])
- quality(y, x)float6494.0 95.0 95.0 ... 98.0 98.0 98.0
array([[94., 95., 95., ..., 97., 97., 97.], [91., 94., 95., ..., 97., 98., 97.], [95., 96., 95., ..., 98., 97., 97.], ..., [ 0., 94., 93., ..., 98., 97., 97.], [91., 92., 92., ..., 98., 97., 98.], [93., 92., 92., ..., 98., 98., 98.]])
- micro(y, x)float640.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]])
- grainId(y, x)int641 1 1 1 1 1 ... 144 144 144 144 144
array([[ 1, 1, 1, ..., 13, 13, 13], [ 1, 1, 1, ..., 13, 13, 13], [ 1, 1, 1, ..., 13, 13, 13], ..., [156, 156, 156, ..., 144, 144, 144], [156, 156, 156, ..., 144, 144, 144], [156, 156, 156, ..., 144, 144, 144]])
- date :
- Thursday, 19 Nov 2015, 11:24 am
- unit :
- millimeters
- step_size :
- 0.02
- path_dat :
- orientation_test.dat