Skip to content
Merged
6 changes: 0 additions & 6 deletions py4DSTEM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from py4DSTEM import io
from py4DSTEM.io import import_file, read, save


### basic data classes

# data
Expand All @@ -40,7 +39,6 @@
# datacube
from py4DSTEM.datacube import DataCube, VirtualImage, VirtualDiffraction


### visualization

from py4DSTEM import visualize
Expand All @@ -64,15 +62,12 @@
# diffraction
from py4DSTEM.process.diffraction import Crystal, Orientation


# ptycho
from py4DSTEM.process import phase


# polar
from py4DSTEM.process.polar import PolarDatacube


# strain
from py4DSTEM.process.strain.strain import StrainMap

Expand All @@ -89,7 +84,6 @@
from py4DSTEM import preprocess
from py4DSTEM import process


### utilities

# config
Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/braggvectors/diskdetection_parallel_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from emdfile import PointListArray, PointList
from py4DSTEM.braggvectors.diskdetection import _find_Bragg_disks_single_DP_FK


#### SERIALISERS ####
# Define Serialiser
# these are functions which allow the hdf5 objects to be passed. May not be required anymore
Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/data/propagating_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import warnings


# This is the abstract pattern:


Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/datacube/virtualimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from py4DSTEM.preprocess import get_shifted_ar
from py4DSTEM.visualize import show


# Virtual image container class


Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
from py4DSTEM.io.read import read
from py4DSTEM.io.save import save


# google downloader
from py4DSTEM.io.google_drive_downloader import gdrive_download, get_sample_file_ids
1 change: 0 additions & 1 deletion py4DSTEM/io/google_drive_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import warnings


### File IDs

# single files
Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/io/legacy/legacy13/v13_emd_classes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from numbers import Number
from emdfile import tqdmnd


# Define the EMD group types

EMD_group_types = {
Expand Down
1 change: 0 additions & 1 deletion py4DSTEM/io/legacy/legacy13/v13_py4dstem_classes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
_read_metadata,
)


# Calibration


Expand Down
2 changes: 0 additions & 2 deletions py4DSTEM/io/legacy/legacy13/v13_to_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
from emdfile import tqdmnd


# v13 imports

from py4DSTEM.io.legacy.legacy13.v13_emd_classes import (
Expand All @@ -25,7 +24,6 @@
BraggVectors as BraggVectors13,
)


# v14 imports

from emdfile import Root, Metadata, Array, PointList, PointListArray
Expand Down
132 changes: 69 additions & 63 deletions py4DSTEM/process/diffraction/crystal_ACOM.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def orientation_plan(
)
self.orientation_zone_axis_steps = (
np.round(step / self.orientation_refine_ratio) * self.orientation_refine_ratio
).astype(np.integer)
).astype(np.int32)
# ).astype(np.integer)

if self.orientation_fiber and self.orientation_fiber_angles[0] == 0:
self.orientation_num_zones = int(1)
Expand Down Expand Up @@ -370,7 +371,8 @@ def orientation_plan(
(self.orientation_zone_axis_steps + 1)
* (self.orientation_zone_axis_steps + 2)
/ 2
).astype(np.integer)
).astype(np.int32)
# ).astype(np.integer)
self.orientation_vecs = np.zeros((self.orientation_num_zones, 3))
self.orientation_vecs[0, :] = self.orientation_zone_axis_range[0, :]
self.orientation_inds = np.zeros((self.orientation_num_zones, 3), dtype="int")
Expand All @@ -379,7 +381,8 @@ def orientation_plan(
# or circular arc SLERP for fiber texture
for a0 in np.arange(1, self.orientation_zone_axis_steps + 1):
inds = np.arange(a0 * (a0 + 1) / 2, a0 * (a0 + 1) / 2 + a0 + 1).astype(
np.integer
np.int32
# np.integer
)

p0 = pv[a0, :]
Expand Down Expand Up @@ -617,7 +620,8 @@ def orientation_plan(

# Solve for number of angular steps along in-plane rotation direction
self.orientation_in_plane_steps = np.round(360 / angle_step_in_plane).astype(
np.integer
np.int32
# np.integer
)

# Calculate -z angles (Euler angle 3)
Expand Down Expand Up @@ -2208,8 +2212,6 @@ def calculate_strain(
deformation tensor which transforms the simulated diffraction pattern
into the experimental pattern, for all probe positons.

TODO: add robust fitting?

Parameters
----------
bragg_peaks_array (PointListArray):
Expand Down Expand Up @@ -2330,71 +2332,75 @@ def calculate_strain(
inds_match[a0] = ind_min
keep[a0] = True

# Get all paired peaks
qxy = np.vstack((p.data["qx"][keep], p.data["qy"][keep])).T
qxy_ref = np.vstack(
(p_ref.data["qx"][inds_match[keep]], p_ref.data["qy"][inds_match[keep]])
).T
if np.sum(keep) >= min_num_peaks:
# Get all paired peaks
qxy = np.vstack((p.data["qx"][keep], p.data["qy"][keep])).T
qxy_ref = np.vstack(
(
p_ref.data["qx"][inds_match[keep]],
p_ref.data["qy"][inds_match[keep]],
)
).T

# Fit transformation matrix
# Note - not sure about transpose here
# (though it might not matter if rotation isn't included)
if intensity_weighting:
weights = np.sqrt(p.data["intensity"][keep, None]) * 0 + 1
m = lstsq(
qxy_ref * weights,
qxy * weights,
rcond=None,
)[0].T
else:
m = lstsq(
qxy_ref,
qxy,
rcond=None,
)[0].T

# Robust fitting
if robust:
for a0 in range(5):
# calculate new weights
qxy_fit = qxy_ref @ m
diff2 = np.sum((qxy_fit - qxy) ** 2, axis=1)

weights = np.exp(
diff2 / ((-2 * robust_thresh**2) * np.median(diff2))
)[:, None]
if intensity_weighting:
weights *= np.sqrt(p.data["intensity"][keep, None])

# calculate new fits
# Fit transformation matrix
# Note - not sure about transpose here
# (though it might not matter if rotation isn't included)
if intensity_weighting:
weights = np.sqrt(p.data["intensity"][keep, None]) * 0 + 1
m = lstsq(
qxy_ref * weights,
qxy * weights,
rcond=None,
)[0].T
else:
m = lstsq(
qxy_ref,
qxy,
rcond=None,
)[0].T

# Set values into the infinitesimal strain matrix
strain_map.get_slice("e_xx").data[rx, ry] = 1 - m[0, 0]
strain_map.get_slice("e_yy").data[rx, ry] = 1 - m[1, 1]
strain_map.get_slice("e_xy").data[rx, ry] = -(m[0, 1] + m[1, 0]) / 2.0
strain_map.get_slice("theta").data[rx, ry] = (m[0, 1] - m[1, 0]) / 2.0

# Add finite rotation from ACOM orientation map.
# I am not sure about the relative signs here.
# Also, maybe I need to add in the mirror operator?
if orientation_map.mirror[rx, ry, 0]:
strain_map.get_slice("theta").data[rx, ry] += (
orientation_map.angles[rx, ry, 0, 0]
+ orientation_map.angles[rx, ry, 0, 2]
)
else:
strain_map.get_slice("theta").data[rx, ry] -= (
orientation_map.angles[rx, ry, 0, 0]
+ orientation_map.angles[rx, ry, 0, 2]
)
# Robust fitting
if robust:
for a0 in range(5):
# calculate new weights
qxy_fit = qxy_ref @ m
diff2 = np.sum((qxy_fit - qxy) ** 2, axis=1)

weights = np.exp(
diff2 / ((-2 * robust_thresh**2) * np.median(diff2))
)[:, None]
if intensity_weighting:
weights *= np.sqrt(p.data["intensity"][keep, None])

# calculate new fits
m = lstsq(
qxy_ref * weights,
qxy * weights,
rcond=None,
)[0].T

# Set values into the infinitesimal strain matrix
strain_map.get_slice("e_xx").data[rx, ry] = 1 - m[0, 0]
strain_map.get_slice("e_yy").data[rx, ry] = 1 - m[1, 1]
strain_map.get_slice("e_xy").data[rx, ry] = -(m[0, 1] + m[1, 0]) / 2.0
strain_map.get_slice("theta").data[rx, ry] = (m[0, 1] - m[1, 0]) / 2.0

# Add finite rotation from ACOM orientation map.
# I am not sure about the relative signs here.
# Also, maybe I need to add in the mirror operator?
if orientation_map.mirror[rx, ry, 0]:
strain_map.get_slice("theta").data[rx, ry] += (
orientation_map.angles[rx, ry, 0, 0]
+ orientation_map.angles[rx, ry, 0, 2]
)
else:
strain_map.get_slice("theta").data[rx, ry] -= (
orientation_map.angles[rx, ry, 0, 0]
+ orientation_map.angles[rx, ry, 0, 2]
)

else:
strain_map.get_slice("mask").data[rx, ry] = 0.0
else:
strain_map.get_slice("mask").data[rx, ry] = 0.0

if rotation_range is not None:
strain_map.get_slice("theta").data[:] = np.mod(
Expand Down
Loading
Loading