Commit b97cd2b8 authored by Mukherjee, Debangshu's avatar Mukherjee, Debangshu
Browse files

New strain plotting functions

parent 117795a2
......@@ -594,7 +594,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.5"
}
},
"nbformat": 4,
......@@ -1903,3 +1903,58 @@ def strain_figure(
ax5.set_title("Strain (%)", fontsize=25, fontweight="bold")
plt.tight_layout()
def get_strain_plot(volume, roi, precision=(2, 3), upsampling=6):
"""
Get strain maps from the volume calculation and region of
interest
Parameters
----------
volume: ndarray, float
Calculated volume from strain
roi: ndarray, bool
Region where the particle lies
precision: tuple
The number of significant digits in each axes
upsampling: int
Upsampling factor for the region before calculation
Returns
-------
rawvals: ndarray, float
The raw calculated strain values from the region of interest
strain: ndarray, float
Strain (second column) as a function of distance from particle
surface (first column), with standard error (third column) and
standard deviation (fourth column)
maxdist: float
Maximum distance from surface
Notes
-----
The ROI is upsampled by the upsampled by the upsampling factor, and the
cartesian distances inside that ROI from the nearest edge point are
calculated. That's your x values, which is the distance from the surface,
while the y values are the calculated volume strain at that position
"""
roi_ups = st.util.resizer2D(roi, 1 / upsampling)
roi_edge, _ = st.util.sobel(roi_ups, 5)
ups_map = st.util.resizer2D(volume, 1 / upsampling)
roi_dists = st.util.euclidean_dist(roi_edge)
xvals = (np.max(roi_dists) - roi_dists[roi_dists > 1 / upsampling]) / upsampling
yvals = ups_map[roi_dists > 1 / upsampling]
maxdist = np.amax(np.round(xvals, 1))
xvals = maxdist - xvals
rawvals = np.transpose(np.asarray((xvals, yvals)))
rawvals = st.util.reduce_precision_xy(rawvals, precision)
strain = np.zeros((len(np.unique(rawvals[:, 0])), 4))
strain[:, 0] = np.unique(rawvals[:, 0])
yvals = rawvals[:, 1]
for ii in np.arange(strain.shape[0]):
strain[ii, 1] = np.median(yvals[rawvals[:, 0] == strain[ii, 0]])
nn = len(yvals[rawvals[:, 0] == strain[ii, 0]])
strain[ii, 2] = np.std(yvals[rawvals[:, 0] == strain[ii, 0]])
strain[ii, 3] = (np.std(yvals[rawvals[:, 0] == strain[ii, 0]])) / (nn ** 0.5)
return rawvals, strain, maxdist
......@@ -728,3 +728,38 @@ def euclidean_dist(binary_image):
dist_map = np.zeros_like(binary_image, dtype=np.float)
dist_map[bi_ones] = dist_vals ** 0.5
return dist_map
def reduce_precision_xy(xy, reducer):
"""
Reduce the precison of an xy array along both
the x and y axes.
Parameters
----------
xy: ndarray
The first column is the x dimension, while
the second column is the y dimension
reducer: tuple
The precison reducers along the individual
dimensions
Returns
-------
xyprec: ndarray
Reduced precision array
"""
reducer = np.asarray(reducer, dtype=np.int)
xy_red = np.zeros_like(xy)
xy_red[:, 0] = np.round(xy[:, 0], reducer[0])
xy_red[:, 1] = np.round(xy[:, 1], reducer[1])
x_unique = np.unique(xy_red[:, 0])
y_all = xy_red[:, 1]
xy_prec = np.zeros((1, 2))
for ii in np.arange(len(x_unique)):
y_ii = np.unique(y_all[xy_red[:, 0] == x_unique[ii]])
x_ii = np.ones_like(y_ii) * x_unique[ii]
arr_ii = np.transpose(np.asarray((x_ii, y_ii)))
xy_prec = np.concatenate((xy_prec, arr_ii), axis=0)
return xy_prec[1 : len(xy_prec), 0:2]
......@@ -512,7 +512,7 @@ def remove_dark_ref(data3D, dark_ref):
return data_fin
def generate4D_frms6(data_dir, bin_factor=2):
def generate4D_frms6(data_dir, bin_factor=2, workers=0):
current_dir = os.getcwd()
os.chdir(data_dir)
data_class = st.util.Frms6Reader()
......@@ -533,7 +533,10 @@ def generate4D_frms6(data_dir, bin_factor=2):
ii += 1
os.chdir(current_dir)
cluster = dd.LocalCluster(n_workers=int(1 + tot_files))
if workers == 0:
workers = int(1 + tot_files)
cluster = dd.LocalCluster(n_workers=workers)
client = dd.Client(cluster)
draw_shape = (np.mean(filesizes[filesizes[:, -1] != 0, 0:3], axis=0)).astype(int)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment