Skip to content

Commit 2b7cf99

Browse files
committed
small bug fixes
1 parent be5cbe1 commit 2b7cf99

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

hexrd/cli/findorientations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def execute(args, parser):
8181

8282
# prepare the analysis directory
8383
quats_f = os.path.join(cfg.working_dir, 'accepted_orientations.dat')
84-
if os.path.exists(quats_f) and not args.force:
84+
if os.path.exists(quats_f) and not (args.force or args.clean):
8585
logger.error(
8686
'%s already exists. Change yml file or specify "force"', quats_f
8787
)
@@ -111,7 +111,7 @@ def execute(args, parser):
111111
pr.enable()
112112

113113
# process the data
114-
find_orientations(cfg, hkls=args.hkls, profile=args.profile)
114+
find_orientations(cfg, hkls=args.hkls, clean=args.clean, profile=args.profile)
115115

116116
if args.profile:
117117
pr.disable()

hexrd/findorientations.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ def quat_distance(x, y):
203203
min_samples=min_samples,
204204
metric='precomputed'
205205
)
206+
cl = np.array(labels, dtype=int) # convert to array
206207
noise_points = cl == -1 # index for marking noise
207-
cl = np.array(labels, dtype=int) + 1 # move index to 1
208-
cl[noise_points] = -1 # re-mark noise
208+
cl += 1 # move index to 1-based instead of 0
209+
cl[noise_points] = -1 # re-mark noise as -1
209210
logger.info("dbscan found %d noise points", sum(noise_points))
210211
elif algorithm == 'fclusterdata':
211212
cl = cluster.hierarchy.fclusterdata(
@@ -242,24 +243,28 @@ def quat_distance(x, y):
242243
return np.atleast_2d(qbar), cl
243244

244245

245-
def load_eta_ome_maps(cfg, pd, reader, detector, hkls=None):
246+
def load_eta_ome_maps(cfg, pd, reader, detector, hkls=None, clean=False):
246247
fn = os.path.join(
247248
cfg.working_dir,
248249
cfg.find_orientations.orientation_maps.file
249250
)
250-
try:
251-
res = cPickle.load(open(fn, 'r'))
252-
pd = res.planeData
253-
available_hkls = pd.hkls.T
254-
logger.info('loaded eta/ome orientation maps from %s', fn)
255-
hkls = [str(i) for i in available_hkls[res.iHKLList]]
256-
logger.info(
257-
'hkls used to generate orientation maps: %s', hkls)
258-
return res
259-
except (AttributeError, IOError):
251+
252+
if not clean:
253+
try:
254+
res = cPickle.load(open(fn, 'r'))
255+
pd = res.planeData
256+
available_hkls = pd.hkls.T
257+
logger.info('loaded eta/ome orientation maps from %s', fn)
258+
hkls = [str(i) for i in available_hkls[res.iHKLList]]
259+
logger.info(
260+
'hkls used to generate orientation maps: %s', hkls)
261+
return res
262+
except (AttributeError, IOError):
263+
return generate_eta_ome_maps(cfg, pd, reader, detector, hkls)
264+
else:
265+
logger.info('clean option specified; recomputing eta/ome orientation maps')
260266
return generate_eta_ome_maps(cfg, pd, reader, detector, hkls)
261267

262-
263268
def generate_eta_ome_maps(cfg, pd, reader, detector, hkls=None):
264269

265270
available_hkls = pd.hkls.T
@@ -303,7 +308,7 @@ def generate_eta_ome_maps(cfg, pd, reader, detector, hkls=None):
303308
return eta_ome
304309

305310

306-
def find_orientations(cfg, hkls=None, profile=False):
311+
def find_orientations(cfg, hkls=None, clean=False, profile=False):
307312
"""
308313
Takes a config dict as input, generally a yml document
309314
@@ -338,7 +343,7 @@ def find_orientations(cfg, hkls=None, profile=False):
338343
logger.info("beginning analysis '%s'", cfg.analysis_name)
339344

340345
# load the eta_ome orientation maps
341-
eta_ome = load_eta_ome_maps(cfg, pd, reader, detector, hkls)
346+
eta_ome = load_eta_ome_maps(cfg, pd, reader, detector, hkls=hkls, clean=clean)
342347

343348
ome_range = (np.min(eta_ome.omeEdges),
344349
np.max(eta_ome.omeEdges)

0 commit comments

Comments
 (0)