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

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

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