Skip to content

Commit

Permalink
Merge branch 'dev' into g1_g2_indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-rakowski authored Nov 21, 2023
2 parents 3bb6f0a + 244f360 commit e0c7b82
Show file tree
Hide file tree
Showing 43 changed files with 214 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_install_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
allow_failure: [false]
runs-on: [ubuntu-latest]
architecture: [x86_64]
python-version: ["3.9", "3.10", "3.11",]
python-version: ["3.9", "3.10", "3.11", "3.12"]
# include:
# - python-version: "3.12.0-beta.4"
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_install_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
allow_failure: [false]
runs-on: [ubuntu-latest, windows-latest, macos-latest]
architecture: [x86_64]
python-version: ["3.9", "3.10", "3.11",]
python-version: ["3.9", "3.10", "3.11", "3.12"]
#include:
# - python-version: "3.12.0-beta.4"
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_install_quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
allow_failure: [false]
runs-on: [ubuntu-latest]
architecture: [x86_64]
python-version: ["3.10"]
python-version: ["3.9", "3.12"]
# Currently no public runners available for this but this or arm64 should work next time
# include:
# - python-version: "3.10"
Expand Down
24 changes: 16 additions & 8 deletions py4DSTEM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,25 @@
BraggVectorMap,
)

from py4DSTEM.process import classification


# 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

# TODO - crystal
# TODO - ptycho
# TODO - others

# TODO - where
from py4DSTEM.process import (
PolarDatacube,
)
from py4DSTEM.process import wholepatternfit


### more submodules
Expand Down
8 changes: 4 additions & 4 deletions py4DSTEM/braggvectors/braggvector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def histogram(
# then scale by the sampling factor
else:
# get pixel calibration
if self.calstate["pixel"] == True:
if self.calstate["pixel"] is True:
qpix = self.calibration.get_Q_pixel_size()
qx /= qpix
qy /= qpix
# origin calibration
if self.calstate["center"] == True:
if self.calstate["center"] is True:
origin = self.calibration.get_origin_mean()
qx += origin[0]
qy += origin[1]
Expand Down Expand Up @@ -153,12 +153,12 @@ def histogram(
).reshape(Q_Nx, Q_Ny)

# determine the resampled grid center and pixel size
if mode == "cal" and self.calstate["center"] == True:
if mode == "cal" and self.calstate["center"] is True:
x0 = sampling * origin[0]
y0 = sampling * origin[1]
else:
x0, y0 = 0, 0
if mode == "cal" and self.calstate["pixel"] == True:
if mode == "cal" and self.calstate["pixel"] is True:
pixelsize = qpix / sampling
else:
pixelsize = 1 / sampling
Expand Down
3 changes: 2 additions & 1 deletion py4DSTEM/braggvectors/braggvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def copy(self, name=None):
braggvector_copy.set_raw_vectors(self._v_uncal.copy())
for k in self.metadata.keys():
braggvector_copy.metadata = self.metadata[k].copy()
braggvector_copy.setcal()
return braggvector_copy

# write
Expand Down Expand Up @@ -384,7 +385,7 @@ def __getitem__(self, pos):
def __repr__(self):
space = " " * len(self.__class__.__name__) + " "
string = f"{self.__class__.__name__}( "
string += f"Retrieves raw bragg vectors. Get vectors for scan position x,y with [x,y]. )"
string += "Retrieves raw bragg vectors. Get vectors for scan position x,y with [x,y]. )"
return string


Expand Down
14 changes: 7 additions & 7 deletions py4DSTEM/braggvectors/diskdetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ def find_Bragg_disks(
mode = "dc_ml"

elif mode == "datacube":
if distributed is None and CUDA == False:
if distributed is None and CUDA is False:
mode = "dc_CPU"
elif distributed is None and CUDA == True:
if CUDA_batched == False:
elif distributed is None and CUDA is True:
if CUDA_batched is False:
mode = "dc_GPU"
else:
mode = "dc_GPU_batched"
Expand Down Expand Up @@ -271,7 +271,7 @@ def find_Bragg_disks(
kws["data_file"] = data_file
kws["cluster_path"] = cluster_path
# ML arguments
if ML == True:
if ML is True:
kws["CUDA"] = CUDA
kws["model_path"] = ml_model_path
kws["num_attempts"] = ml_num_attempts
Expand Down Expand Up @@ -759,7 +759,7 @@ def _parse_distributed(distributed):
data_file = distributed["data_file"]

if not isinstance(data_file, str):
er = f"Expected string for distributed key 'data_file', "
er = "Expected string for distributed key 'data_file', "
er += f"received {type(data_file)}"
raise TypeError(er)
if len(data_file.strip()) == 0:
Expand All @@ -773,7 +773,7 @@ def _parse_distributed(distributed):
cluster_path = distributed["cluster_path"]

if not isinstance(cluster_path, str):
er = f"distributed key 'cluster_path' must be of type str, "
er = "distributed key 'cluster_path' must be of type str, "
er += f"received {type(cluster_path)}"
raise TypeError(er)

Expand All @@ -784,7 +784,7 @@ def _parse_distributed(distributed):
er = f"distributed key 'cluster_path' does not exist: {cluster_path}"
raise FileNotFoundError(er)
elif not os.path.isdir(cluster_path):
er = f"distributed key 'cluster_path' is not a directory: "
er = "distributed key 'cluster_path' is not a directory: "
er += f"{cluster_path}"
raise NotADirectoryError(er)
else:
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/braggvectors/diskdetection_aiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def find_Bragg_disks_aiml_serial(
)
)

if global_threshold == True:
if global_threshold is True:
from py4DSTEM.braggvectors import universal_threshold

peaks = universal_threshold(
Expand Down Expand Up @@ -559,7 +559,7 @@ def find_Bragg_disks_aiml(
model_path=None,
distributed=None,
CUDA=True,
**kwargs
**kwargs,
):
"""
Finds the Bragg disks in all diffraction patterns of datacube by AI/ML method. This method
Expand Down
6 changes: 3 additions & 3 deletions py4DSTEM/braggvectors/diskdetection_aiml_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def find_Bragg_disks_aiml_CUDA(
datacube.R_N, int(t2 / 3600), int(t2 / 60), int(t2 % 60)
)
)
if global_threshold == True:
if global_threshold is True:
from py4DSTEM.braggvectors import universal_threshold

peaks = universal_threshold(
Expand Down Expand Up @@ -265,7 +265,7 @@ def _find_Bragg_disks_aiml_single_DP_CUDA(
blocks=None,
threads=None,
model_path=None,
**kwargs
**kwargs,
):
"""
Finds the Bragg disks in single DP by AI/ML method. This method utilizes FCU-Net
Expand Down Expand Up @@ -496,7 +496,7 @@ def get_maxima_2D_cp(
if minSpacing > 0:
deletemask = np.zeros(len(maxima), dtype=bool)
for i in range(len(maxima)):
if deletemask[i] == False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(maxima["x"] - maxima["x"][i]) ** 2
+ (maxima["y"] - maxima["y"][i]) ** 2
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/braggvectors/diskdetection_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def get_maxima_2D(
if minSpacing > 0:
deletemask = np.zeros(len(maxima), dtype=bool)
for i in range(len(maxima)):
if deletemask[i] == False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(maxima["x"] - maxima["x"][i]) ** 2
+ (maxima["y"] - maxima["y"][i]) ** 2
Expand Down
14 changes: 7 additions & 7 deletions py4DSTEM/braggvectors/diskdetection_parallel_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def beta_parallel_disk_detection(
close_dask_client=False,
return_dask_client=True,
*args,
**kwargs
**kwargs,
):
"""
This is not fully validated currently so may not work, please report bugs on the py4DSTEM github page.
Expand Down Expand Up @@ -137,8 +137,8 @@ def beta_parallel_disk_detection(
# ... dask stuff.
# TODO add assert statements and other checks. Think about reordering opperations

if dask_client == None:
if dask_client_params != None:
if dask_client is None:
if dask_client_params is not None:
dask.config.set(
{
"distributed.worker.memory.spill": False,
Expand Down Expand Up @@ -201,7 +201,7 @@ def beta_parallel_disk_detection(
dask_data = da.from_array(
dataset.data, chunks=(1, 1, dataset.Q_Nx, dataset.Q_Ny)
)
elif dataset.stack_pointer != None:
elif dataset.stack_pointer is not None:
dask_data = da.from_array(
dataset.stack_pointer, chunks=(1, 1, dataset.Q_Nx, dataset.Q_Ny)
)
Expand All @@ -225,7 +225,7 @@ def beta_parallel_disk_detection(
probe_kernel_FT=dask_probe_delayed[0, 0],
# probe_kernel_FT=delayed_probe_kernel_FT,
*args,
**kwargs
**kwargs,
) # passing through args from earlier or should I use
# corrPower=corrPower,
# sigma=sigma_gaussianFilter,
Expand Down Expand Up @@ -261,9 +261,9 @@ def beta_parallel_disk_detection(
if close_dask_client:
dask_client.close()
return peaks
elif close_dask_client == False and return_dask_client == True:
elif close_dask_client is False and return_dask_client is True:
return peaks, dask_client
elif close_dask_client and return_dask_client == False:
elif close_dask_client and return_dask_client is False:
return peaks
else:
print(
Expand Down
5 changes: 2 additions & 3 deletions py4DSTEM/braggvectors/threshold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Bragg peaks thresholding fns

import numpy as np

from emdfile import tqdmnd, PointListArray


Expand Down Expand Up @@ -52,7 +51,7 @@ def threshold_Braggpeaks(
r2 = minPeakSpacing**2
deletemask = np.zeros(pointlist.length, dtype=bool)
for i in range(pointlist.length):
if deletemask[i] == False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(pointlist.data["qx"] - pointlist.data["qx"][i]) ** 2
+ (pointlist.data["qy"] - pointlist.data["qy"][i]) ** 2
Expand Down Expand Up @@ -160,7 +159,7 @@ def universal_threshold(
r2 = minPeakSpacing**2
deletemask = np.zeros(pointlist.length, dtype=bool)
for i in range(pointlist.length):
if deletemask[i] == False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(pointlist.data["qx"] - pointlist.data["qx"][i]) ** 2
+ (pointlist.data["qy"] - pointlist.data["qy"][i]) ** 2
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/data/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def attach(self, data):
"""
from py4DSTEM.data import Data

assert isinstance(data, Data), f"data must be a Data instance"
assert isinstance(data, Data), "data must be a Data instance"
self.root.attach(data)

# Register for auto-calibration
Expand Down Expand Up @@ -316,7 +316,7 @@ def set_Q_pixel_units(self, x):
"pixels",
"A^-1",
"mrad",
), f"Q pixel units must be 'A^-1', 'mrad' or 'pixels'."
), "Q pixel units must be 'A^-1', 'mrad' or 'pixels'."
self._params["Q_pixel_units"] = x

def get_Q_pixel_units(self):
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/datacube/virtualdiffraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_virtual_diffraction(
# Calculate

# ...with no center shifting
if shift_center == False:
if shift_center is False:
# ...for the whole pattern
if mask is None:
if method == "mean":
Expand Down
12 changes: 6 additions & 6 deletions py4DSTEM/datacube/virtualimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ def get_virtual_image(
# Get mask
mask = self.make_detector(self.Qshape, mode, g)
# if return_mask is True, skip computation
if return_mask == True and shift_center == False:
if return_mask is True and shift_center is False:
return mask

# Calculate virtual image

# no center shifting
if shift_center == False:
if shift_center is False:
# single CPU
if not dask:
# allocate space
Expand All @@ -220,7 +220,7 @@ def get_virtual_image(
virtual_image[rx, ry] = np.sum(self.data[rx, ry] * mask)

# dask
if dask == True:
if dask is True:
# set up a generalized universal function for dask distribution
def _apply_mask_dask(self, mask):
virtual_image = np.sum(
Expand Down Expand Up @@ -444,7 +444,7 @@ def position_detector(
# shift center
if shift_center is None:
shift_center = False
elif shift_center == True:
elif shift_center is True:
assert isinstance(
data, tuple
), "If shift_center is set to True, `data` should be a 2-tuple (rx,ry). \
Expand Down Expand Up @@ -552,7 +552,7 @@ def get_calibrated_detector_geometry(
# Convert units into detector pixels

# Shift center
if centered == True:
if centered is True:
if mode == "point":
g = (g[0] + x0_mean, g[1] + y0_mean)
if mode in ("circle", "circular", "annulus", "annular"):
Expand All @@ -561,7 +561,7 @@ def get_calibrated_detector_geometry(
g = (g[0] + x0_mean, g[1] + x0_mean, g[2] + y0_mean, g[3] + y0_mean)

# Scale by the detector pixel size
if calibrated == True:
if calibrated is True:
if mode == "point":
g = (g[0] / unit_conversion, g[1] / unit_conversion)
if mode in ("circle", "circular"):
Expand Down
Loading

0 comments on commit e0c7b82

Please sign in to comment.