Skip to content

Commit

Permalink
updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsavitzky committed Dec 12, 2024
1 parent 921eb3a commit f1db35a
Show file tree
Hide file tree
Showing 11 changed files with 1,514 additions and 1,021 deletions.
48 changes: 11 additions & 37 deletions py4DSTEM/__init__.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,34 @@
from py4DSTEM.version import __version__
from emdfile import tqdmnd


### Utility functions
# Utilities
from emdfile import tqdmnd
from py4DSTEM.utils import *

### IO substructure
from emdfile import (
Node,
Root,
Metadata,
Array,
PointList,
PointListArray,
Custom,
print_h5_tree,
)
# IO
from emdfile import (Node,Root,Metadata,Array,PointList,PointListArray,Custom,
print_h5_tree,)
_emd_hook = True

# IO structure
from py4DSTEM import io
from py4DSTEM.io import import_file, read, save

### Basic data classes
from py4DSTEM.data import (
Data,
Calibration,
DiffractionSlice,
RealSlice,
QPoints,
)

### Visualization
### CLASSES
# Data
from py4DSTEM.data import (Data,Calibration,DiffractionSlice,RealSlice,QPoints,)
# Visualization
from py4DSTEM import visualize
from py4DSTEM.visualize import show, show_complex

# Analysis classes
from py4DSTEM.datacube import DataCube
from py4DSTEM.datacube import VirtualImage, VirtualDiffraction
from py4DSTEM.datacube import DataCube,VirtualImage,VirtualDiffraction
from py4DSTEM.datacube.diskdetection import Probe
from py4DSTEM.braggvectors import BraggVectors, BraggVectorMap
from py4DSTEM.process import classification
from py4DSTEM.clustering import ACCHOO, VoronoiClustering
from py4DSTEM.process.diffraction import Crystal, Orientation
from py4DSTEM.process import phase
from py4DSTEM.process.polar import PolarDatacube
from py4DSTEM.process.strain.strain import StrainMap
from py4DSTEM.process import wholepatternfit
from py4DSTEM.acchoo import ACCHOO


### Config
from py4DSTEM.utils.configuration_checker import check_config
# TODO - config .toml

# testing
from os.path import dirname, join

_TESTPATH = join(dirname(__file__), "../test/unit_test_data")

2 changes: 0 additions & 2 deletions py4DSTEM/acchoo/__init__.py

This file was deleted.

5 changes: 5 additions & 0 deletions py4DSTEM/clustering/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from py4DSTEM.clustering.acchoo import ACCHOO
from py4DSTEM.clustering.voronoiclustering import *
from py4DSTEM.clustering.classutils import *
from py4DSTEM.clustering.featurization import *

57 changes: 30 additions & 27 deletions py4DSTEM/acchoo/acchoo.py → py4DSTEM/clustering/acchoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ def __init__(
threshold intensity for data points to be counted as 'empty' or not
min_inten : bool
data inclusion intensity threshold
#dist_frac_tol : number
# data points which are just over a voronoi ridge from a masked to an
# unmasked channel may be ignored if the distance fraction
# (dist_to_masked_vor_point / dis_to_unmasked_vor_point) is under this
# threshold tolerance. 1 (default) is no tolerance; 1.05 means if the
# distance to the closest masked seed is within 5% of the closest
# unmasked seed distance, the point is disregarded
#numb_frac_tol : number
# unmasked data points will be ignored unless their fraction of the total
# number of points is greater than numb_frac_tol
seed_picker : str in 'max' or 'most' or 'random' or 'front' or 'back'
strategy for choosing crystal seed points
num_lowq : int
Expand Down Expand Up @@ -225,7 +215,7 @@ def get_kpoints(self, p, vp={}, show=True):
self._voronoi_vertices = get_voronoi_vertices(
self._voronoi, self.d.Qshape[0], self.d.Qshape[1])
# show
print(f"Identified {len(ans)} points")
print(f"Identified {len(ans)} diffraction maxima; setting up voronoi channel data basis.")
if show:
show_points(
self.bvm,
Expand Down Expand Up @@ -280,6 +270,17 @@ def _seedloop(self):
print(f'Setting out at seed {seed}!')
self._new_path(seed)
return True
# pick a seed from a seeded pixel
elif np.sum(self.labels==3)>0:
loop = np.sum(self.labels==3)>0
while loop:
seed = self._pick_seeded_seed(seed_picker=self.seed_picker)
if self._verbose:
print(f'setting out at a merged seed path at seed {seed}')
self._reset_path_vars()
loop = self._seeded_path(seed)
loop = np.sum(self.labels==3)>0
pass
# are we done?
else:
if self._verbose:
Expand Down Expand Up @@ -329,29 +330,31 @@ def _new_path(self,seed):
loop = self._xtal_search_loop(seed)
if self._verbose:
print(f"Found {len(self._crystals_curr)} crystals: {self._crystals_curr}")
if loop:
print("Score still above threshold, continuing search...")
else:
print("Score satisfies threshold, exiting crystal search loop.")
# loop - walk
self._put_on_shoes_and_coat(seed)
# finalize current path
self._finalize_path_and_update_crystals(seed)
# enter seeded path loops
loop = np.sum(self.labels==3)>0
while loop:
seed = self._pick_seeded_seed(seed_picker=self.seed_picker)
if self._verbose:
print(f'setting out at a merged seed path at seed {seed}')
self._reset_path_vars()
loop = self._seeded_path(seed)
loop = np.sum(self.labels==3)>0
pass
# # enter seeded path loops
# loop = np.sum(self.labels==3)>0
# while loop:
# seed = self._pick_seeded_seed(seed_picker=self.seed_picker)
# if self._verbose:
# print(f'setting out at a merged seed path at seed {seed}')
# self._reset_path_vars()
# loop = self._seeded_path(seed)
# loop = np.sum(self.labels==3)>0
# pass
if self._verbose:
print("Exiting _new_path...")
pass

def _xtal_search_loop(self,seed):
""" Find a crystal set and mask, then _put_on_shoes_and_coat
"""
if self._vv:
print('Commencing crystal search...')
x,y,inten = self._data_curr
channels = self._data_channels_curr
# prepare boolean mask
Expand All @@ -372,7 +375,8 @@ def _xtal_search_loop(self,seed):
for idx,channel in enumerate(channels):
if channels[idx] in self._b_opts_curr:
m[idx] = 0 # don't pick current opts
self._get_b_next_opts(m)
if len(x[m])>0:
self._get_b_next_opts(m)
crystal_opts, mask_opts = self._get_crystal_opts_curr()
self._score_crystal_options_and_update(crystal_opts,mask_opts)
# are we done?
Expand Down Expand Up @@ -512,7 +516,8 @@ def _xtal_search_seeded_internalloop(self,seed):
# first get basis vector options & new crystal options
# then compute permutation scores and update vars
self._crystals_n_opts += 1
self._get_b_next_opts(m)
if len(x[m])>0:
self._get_b_next_opts(m)
crystal_opts, mask_opts = self._get_crystal_opts_curr()
# merge new and existing xtal masks
self._score_crystal_options_and_update_addxtal(crystal_opts,mask_opts)
Expand Down Expand Up @@ -891,8 +896,6 @@ def _get_crystal_opts_curr(self):
# return
return crystals_opts, masks_opts

### Misc. Utilities ###

# data
def _get_data(self,seed):
data = self.d.cal[seed[0],seed[1]]
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f1db35a

Please sign in to comment.