Skip to content

Commit

Permalink
lite refactor commits from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Jul 4, 2024
1 parent c2f6ea3 commit 307f27d
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 20 deletions.
10 changes: 8 additions & 2 deletions py4DSTEM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
BraggVectorMap,
)

from py4DSTEM.process import classification
try:
from py4DSTEM.process import classification
except (ImportError, ModuleNotFoundError):
pass


# diffraction
Expand All @@ -70,7 +73,10 @@
# strain
from py4DSTEM.process.strain.strain import StrainMap

from py4DSTEM.process import wholepatternfit
try:
from py4DSTEM.process import wholepatternfit
except (ImportError, ModuleNotFoundError):
pass


### more submodules
Expand Down
5 changes: 4 additions & 1 deletion py4DSTEM/braggvectors/diskdetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from py4DSTEM.datacube import DataCube
from py4DSTEM.preprocess.utils import get_maxima_2D
from py4DSTEM.process.utils.cross_correlate import get_cross_correlation_FT
from py4DSTEM.braggvectors.diskdetection_aiml import find_Bragg_disks_aiml
try:
from py4DSTEM.braggvectors.diskdetection_aiml import find_Bragg_disks_aiml
except (ImportError, ModuleNotFoundError):
pass


def find_Bragg_disks(
Expand Down
5 changes: 3 additions & 2 deletions py4DSTEM/datacube/virtualimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# for bragg virtual imaging methods, goto diskdetection.virtualimage.py

import numpy as np
import dask.array as da
from typing import Optional
import inspect

Expand Down Expand Up @@ -220,7 +219,9 @@ def get_virtual_image(
virtual_image[rx, ry] = np.sum(self.data[rx, ry] * mask)

# dask
if dask is True:
if dask:
import dask.array as da

# set up a generalized universal function for dask distribution
def _apply_mask_dask(self, mask):
virtual_image = np.sum(
Expand Down
5 changes: 4 additions & 1 deletion py4DSTEM/io/filereaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
from py4DSTEM.io.filereaders.read_K2 import read_gatan_K2_bin
from py4DSTEM.io.filereaders.empad import read_empad
from py4DSTEM.io.filereaders.read_mib import load_mib
from py4DSTEM.io.filereaders.read_arina import read_arina
try:
from py4DSTEM.io.filereaders.read_arina import read_arina
except (ImportError, ModuleNotFoundError):
pass
from py4DSTEM.io.filereaders.read_abTEM import read_abTEM
2 changes: 1 addition & 1 deletion py4DSTEM/io/importfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from py4DSTEM.io.filereaders import (
load_mib,
read_abTEM,
read_arina,
read_dm,
read_empad,
read_gatan_K2_bin,
Expand Down Expand Up @@ -90,6 +89,7 @@ def import_file(
elif filetype == "mib":
data = load_mib(filepath, mem=mem, binfactor=binfactor, **kwargs)
elif filetype == "arina":
from py4DSTEM.io.filereaders import read_arina
data = read_arina(filepath, mem=mem, binfactor=binfactor, **kwargs)
elif filetype == "abTEM":
data = read_abTEM(filepath, mem=mem, binfactor=binfactor, **kwargs)
Expand Down
10 changes: 8 additions & 2 deletions py4DSTEM/process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from py4DSTEM.process import phase
from py4DSTEM.process import calibration
from py4DSTEM.process import utils
from py4DSTEM.process import classification
try:
from py4DSTEM.process import classification
except (ImportError, ModuleNotFoundError):
pass
from py4DSTEM.process import diffraction
from py4DSTEM.process import wholepatternfit
try:
from py4DSTEM.process import wholepatternfit
except (ImportError, ModuleNotFoundError):
pass
4 changes: 3 additions & 1 deletion py4DSTEM/process/diffraction/crystal_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from scipy.signal import medfilt
from scipy.ndimage import gaussian_filter
from scipy.ndimage import distance_transform_edt
from skimage.morphology import dilation, erosion

import warnings
import numpy as np
Expand Down Expand Up @@ -1884,7 +1883,10 @@ def plot_clusters(

for a0 in range(self.cluster_sizes.shape[0]):
if self.cluster_sizes[a0] >= area_min:

if outline_grains:
from skimage.morphology import erosion

im_grain[:] = False
im_grain[
self.cluster_inds[a0][0, :],
Expand Down
5 changes: 4 additions & 1 deletion py4DSTEM/process/phase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from py4DSTEM.process.phase.parallax import Parallax
from py4DSTEM.process.phase.ptychographic_tomography import PtychographicTomography
from py4DSTEM.process.phase.singleslice_ptychography import SingleslicePtychography
from py4DSTEM.process.phase.parameter_optimize import OptimizationParameter, PtychographyOptimizer
try:
from py4DSTEM.process.phase.parameter_optimize import OptimizationParameter, PtychographyOptimizer
except (ImportError, ModuleNotFoundError):
pass

# fmt: on
2 changes: 1 addition & 1 deletion py4DSTEM/process/phase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def get_array_module(*args):
from py4DSTEM.process.utils import get_CoM
from py4DSTEM.process.utils.cross_correlate import align_and_shift_images
from py4DSTEM.process.utils.utils import electron_wavelength_angstrom
from skimage.restoration import unwrap_phase

# fmt: off

Expand Down Expand Up @@ -1755,6 +1754,7 @@ def unwrap_phase_2d(array, weights=None, gauge=None, corner_centered=True, xp=np


def unwrap_phase_2d_skimage(array, corner_centered=True, xp=np):
from skimage.restoration import unwrap_phase
if xp is np:
array = array.astype(np.float64)
unwrapped_array = unwrap_phase(array, wrap_around=corner_centered).astype(
Expand Down
3 changes: 2 additions & 1 deletion py4DSTEM/process/polar/polar_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from scipy.ndimage import gaussian_filter
from sklearn.decomposition import PCA

from emdfile import tqdmnd

Expand Down Expand Up @@ -980,6 +979,8 @@ def background_pca(
radial PCA component selected
"""

from sklearn.decomposition import PCA

# PCA decomposition
shape = self.radial_all.shape
A = np.reshape(self.radial_all, (shape[0] * shape[1], shape[2]))
Expand Down
3 changes: 2 additions & 1 deletion py4DSTEM/process/polar/polar_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from scipy.ndimage import gaussian_filter, gaussian_filter1d
from scipy.signal import peak_prominences
from skimage.feature import peak_local_max
from scipy.optimize import curve_fit, leastsq
import warnings

Expand Down Expand Up @@ -105,6 +104,8 @@ def find_peaks_single_pattern(
"""

from skimage.feature import peak_local_max

# if needed, generate mask from Bragg peaks
if bragg_peaks is not None:
mask_bragg = self._datacube.get_braggmask(
Expand Down
8 changes: 2 additions & 6 deletions py4DSTEM/utils/configuration_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

# need a mapping of pypi/conda names to import names
import_mapping_dict = {
"scikit-image": "skimage",
"scikit-learn": "sklearn",
"scikit-optimize": "skopt",
"mp-api": "mp_api",
}


Expand Down Expand Up @@ -88,7 +84,8 @@ def get_modules_dict():


# module_depenencies = get_modules_dict()
modules = get_modules_list()
# modules = get_modules_list()
modules = []


#### Class and Functions to Create Coloured Strings ####
Expand Down Expand Up @@ -527,7 +524,6 @@ def print_no_extra_checks(m: str):

# dict of extra check functions
funcs_dict = {
"cupy": check_cupy_gpu,
}


Expand Down

0 comments on commit 307f27d

Please sign in to comment.