@@ -1473,11 +1473,23 @@ def determineDistortion(self, adinputs=None, **params):
14731473 initial_peaks , _ = peak_finding .find_wavelet_peaks (
14741474 data , widths = widths , mask = mask & DQ .not_signal ,
14751475 variance = variance , min_snr = min_snr , reject_bad = debug_reject_bad )
1476- log .stdinfo (f"Found { len (initial_peaks )} peaks" )
1477- print ( initial_peaks )
1476+ # log.stdinfo(f"Found {len(initial_peaks)} peaks")
1477+
14781478 # The coordinates are always returned as (x-coords, y-coords)
14791479 rwidth = 0.42466 * fwidth
14801480
1481+ # The slit length may be smaller than the width of the slice,
1482+ # so we need to estimate the slit length and
1483+ # "min_line_length" is the fraction of that, not the fraction
1484+ # of the slice width.
1485+ loc = int (np .median (initial_peaks ))
1486+ if dispaxis == 0 :
1487+ _slice = ext .mask [loc ] & DQ .unilluminated
1488+ else :
1489+ _slice = ext .mask [:, loc ] & DQ .unilluminated
1490+ slit_length_frac = 1 - ((_slice .argmin () +
1491+ _slice [::- 1 ].argmin ()) / _slice .size )
1492+
14811493 # Straight slits, such as in longslit, can have all the lines
14821494 # traced simultaneously since they all have the same starting
14831495 # point. "Curved" slits need to be handled one-by-one. This is
@@ -1492,7 +1504,7 @@ def determineDistortion(self, adinputs=None, **params):
14921504 nsum = nsum , max_missed = max_missed ,
14931505 max_shift = max_shift * ybin / xbin ,
14941506 viewer = self .viewer if debug else None ,
1495- min_line_length = min_line_length )
1507+ min_line_length = min_line_length * slit_length_frac )
14961508
14971509 else :
14981510 traces = []
@@ -1501,14 +1513,20 @@ def determineDistortion(self, adinputs=None, **params):
15011513 # along the dispersion axis. `extract_info` here is the
15021514 # polynomial describing that midway line.
15031515 start = extract_info (peak )
1516+ print ("peak, start:" , peak , start )
15041517 traces .extend (tracing .trace_lines (
15051518 ext , axis = 1 - dispaxis ,
15061519 start = start , initial = [peak ],
15071520 rwidth = rwidth , cwidth = max (int (fwidth ), 5 ), step = step ,
15081521 nsum = nsum , max_missed = max_missed ,
15091522 max_shift = max_shift * ybin / xbin ,
15101523 viewer = self .viewer if debug else None ,
1511- min_line_length = 0.1 ))
1524+ min_line_length = min_line_length * slit_length_frac ))
1525+
1526+ log .stdinfo (f"Traced { len (traces )} lines" )
1527+ if ext .id == 6 and ad .filename .startswith ("S20060311S0321" ):
1528+ for trace in traces :
1529+ print (trace .input_coordinates ())
15121530
15131531 # List of traced peak positions
15141532 in_coords = np .array ([coord for trace in traces for
0 commit comments