Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwestfall committed Oct 25, 2023
1 parent 92c4765 commit 750af01
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions pypeit/edgetrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def auto_trace(self, bpm=None, debug=False, show_stages=False):
# like a long-slit observation. At best, that will lead to a lot of
# wasted time in the reductions; at worst, it will just cause the code
# to fault later on.
self.success = self.sync() #debug=True)
self.success = self.sync()
if not self.success:
return
if show_stages:
Expand All @@ -881,7 +881,7 @@ def auto_trace(self, bpm=None, debug=False, show_stages=False):
self.order_refine(debug=debug)
# Check that the edges are still sinked (not overkill if orders are
# missed)
self.success = self.sync() #debug=True)
self.success = self.sync()
if not self.success:
return
if show_stages:
Expand Down Expand Up @@ -2615,8 +2615,6 @@ def check_synced(self, rebuild_pca=False):
for slc in short_slits:
# Remove the edges just before and after this region of short
# slits, if they inserted by the left-right syncing.
# rmtrace[max(0,slc.start-1)] = True
# rmtrace[min(self.ntrace-1, slc.stop)] = True
rmtrace[max(0,slc.start-1)] = sync_inserts[max(0,slc.start-1)]
rmtrace[min(self.ntrace-1, slc.stop)] = sync_inserts[min(self.ntrace-1, slc.stop)]
# Flip the sign of the edges (i.e., turn lefts into rights and
Expand All @@ -2625,13 +2623,9 @@ def check_synced(self, rebuild_pca=False):
# Turn off the masking
self.edge_msk[:,slc] \
= self.bitmask.turn_off(self.edge_msk[:,slc], 'ABNORMALSLIT_SHORT')

# Remove the flagged traces, resort the edges, and rebuild the pca
self.remove_traces(rmtrace, rebuild_pca=_rebuild_pca)
# # This operation should lead to traces that are still synced.
# # There's a bug if they aren't!
# # TODO: We can remove this assert once we're satisfied we've caught
# # all the corner cases.
# assert self.is_synced, 'CODING ERROR: Overlapping slit strategy failed.'

# If this de-synchronizes the traces, we effectively have to start
# the synchronization process over again, with the adjustments for
Expand Down Expand Up @@ -3971,8 +3965,10 @@ def sync(self, rebuild_pca=True, debug=False):
self.insert_traces(side[add_edge], trace_add, loc=add_indx[add_edge], mode='sync')
return True

i = 0
# NOTE: The maximum number of iterations is hard-coded for now. Testing
# is needed to know if we need this to be any larger than 3.
maxiter = 3
i = 0
while i < maxiter:
msgs.info(f'Beginning syncing iteration : {i+1} (of at most {maxiter})')

Expand Down Expand Up @@ -4042,7 +4038,6 @@ def sync(self, rebuild_pca=True, debug=False):

i += 1
if i == maxiter:
# embed(header='sync, hit maximum iterations')
msgs.error('Fatal left-right trace de-synchronization error.')
self.log += [inspect.stack()[0][3]]
return True
Expand Down Expand Up @@ -5100,25 +5095,6 @@ def order_refine(self, debug=False):
msgs.info('No additional orders found to add')
return

# MOVED THIS TO order_refine_free_format, but I assume we need something similar
# for order_refine_fixed_format?
# # Deal with overlapping orders among the ones to be added. The edges
# # are adjusted equally on both sides to avoid changing the order center
# # and exclude the overlap regions from the reduction.
# if np.any(add_left[1:] - add_right[:-1] < 0):
# # Loop sequentially so that each pair is updated as the loop progresses
# for i in range(1, add_left.size):
# # *Negative* of the gap; i.e., positives values means there's
# # overlap
# ngap = add_right[i-1] - add_left[i]
# if ngap > 0:
# # Adjust both order edges to avoid the overlap region but
# # keep the same center coordinate
# add_left[i-1] += ngap
# add_right[i-1] -= ngap
# add_left[i] += ngap
# add_right[i] -= ngap

if rmtraces is not None:
self.remove_traces(rmtraces, rebuild_pca=True)

Expand Down Expand Up @@ -5224,16 +5200,13 @@ def order_refine_free_format(self, reference_row, combined_order_tol=1.8, debug=

# Interpolate any missing orders
# TODO: Expose tolerances to the user?
# order_cen, order_missing = trace.find_missing_orders(cen, width_fit, gap_fit)
individual_orders = np.logical_not(combined_orders)
order_cen, order_missing \
= trace.find_missing_orders(cen[individual_orders], width_fit, gap_fit)

# Extrapolate orders
rng = [0., float(self.nspat)] if self.par['order_spat_range'] is None \
else self.par['order_spat_range']
# lower_order_cen, upper_order_cen \
# = trace.extrapolate_orders(cen, width_fit, gap_fit, rng[0], rng[1])
lower_order_cen, upper_order_cen \
= trace.extrapolate_orders(cen[individual_orders], width_fit, gap_fit,
rng[0], rng[1])
Expand Down

0 comments on commit 750af01

Please sign in to comment.