@@ -1478,64 +1478,75 @@ def determineDistortion(self, adinputs=None, **params):
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-
1493- # Straight slits, such as in longslit, can have all the lines
1494- # traced simultaneously since they all have the same starting
1495- # point. "Curved" slits need to be handled one-by-one. This is
1496- # quite a bit slower, so this block of code does the line
1497- # tracing based on the slit involved.
1498- if constant_slit :
1499- traces = tracing .trace_lines (
1500- # Only need a single `start` value for all lines.
1501- ext , axis = 1 - dispaxis ,
1502- start = start , initial = initial_peaks ,
1503- rwidth = rwidth , cwidth = max (int (fwidth ), 5 ), step = step ,
1504- nsum = nsum , max_missed = max_missed ,
1505- max_shift = max_shift * ybin / xbin ,
1506- viewer = self .viewer if debug else None ,
1507- min_line_length = min_line_length * slit_length_frac )
1508-
1509- else :
1510- traces = []
1511- for peak in initial_peaks :
1512- # Need to start midway along the slit, which varies
1513- # along the dispersion axis. `extract_info` here is the
1514- # polynomial describing that midway line.
1515- start = extract_info (peak )
1516- print ("peak, start:" , peak , start )
1517- traces .extend (tracing .trace_lines (
1481+ if len (initial_peaks ):
1482+ # The slit length may be smaller than the width of the slice,
1483+ # so we need to estimate the slit length and
1484+ # "min_line_length" is the fraction of that, not the fraction
1485+ # of the slice width.
1486+ if ext .mask is not None :
1487+ loc = int (np .median (initial_peaks ))
1488+ if dispaxis == 0 :
1489+ _slice = ext .mask [loc ] & DQ .unilluminated
1490+ else :
1491+ _slice = ext .mask [:, loc ] & DQ .unilluminated
1492+ slit_length_frac = 1 - ((_slice .argmin () +
1493+ _slice [::- 1 ].argmin ()) / _slice .size )
1494+ else :
1495+ try :
1496+ slit_length_frac = ad .MDF ['slitlength_pixels' ] / ext .shape [1 - dispaxis ]
1497+ except (AttributeError , KeyError ):
1498+ slit_length_frac = 1
1499+
1500+ # Straight slits, such as in longslit, can have all the lines
1501+ # traced simultaneously since they all have the same starting
1502+ # point. "Curved" slits need to be handled one-by-one. This is
1503+ # quite a bit slower, so this block of code does the line
1504+ # tracing based on the slit involved.
1505+ if constant_slit :
1506+ traces = tracing .trace_lines (
1507+ # Only need a single `start` value for all lines.
15181508 ext , axis = 1 - dispaxis ,
1519- start = start , initial = [ peak ] ,
1509+ start = start , initial = initial_peaks ,
15201510 rwidth = rwidth , cwidth = max (int (fwidth ), 5 ), step = step ,
15211511 nsum = nsum , max_missed = max_missed ,
15221512 max_shift = max_shift * ybin / xbin ,
15231513 viewer = self .viewer if debug else None ,
1524- min_line_length = min_line_length * slit_length_frac ))
1514+ min_line_length = min_line_length * slit_length_frac )
15251515
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 ())
1530-
1531- # List of traced peak positions
1532- in_coords = np .array ([coord for trace in traces for
1533- coord in trace .input_coordinates ()]).T
1516+ else :
1517+ traces = []
1518+ for peak in initial_peaks :
1519+ # Need to start midway along the slit, which varies
1520+ # along the dispersion axis. `extract_info` here is the
1521+ # polynomial describing that midway line.
1522+ start = extract_info (peak )
1523+ traces .extend (tracing .trace_lines (
1524+ ext , axis = 1 - dispaxis ,
1525+ start = start , initial = [peak ],
1526+ rwidth = rwidth , cwidth = max (int (fwidth ), 5 ), step = step ,
1527+ nsum = nsum , max_missed = max_missed ,
1528+ max_shift = max_shift * ybin / xbin ,
1529+ viewer = self .viewer if debug else None ,
1530+ min_line_length = min_line_length * slit_length_frac ))
1531+
1532+ log .stdinfo (f"Traced { len (traces )} lines" )
1533+ if ext .id == 6 and ad .filename .startswith ("S20060311S0321" ):
1534+ for trace in traces :
1535+ print (trace .input_coordinates ())
1536+
1537+ # List of traced peak positions
1538+ in_coords = np .array ([coord for trace in traces for
1539+ coord in trace .input_coordinates ()]).T
1540+
1541+ # We can't do anything if we have no coordinates
1542+ if in_coords .size == 0 :
1543+ log .warning ("Failed to trace any lines for "
1544+ f"{ ad .filename } :{ ext .id } " )
1545+ continue
15341546
1535- # We can't do anything if we have no coordinates
1536- if in_coords .size == 0 :
1537- log .warning ("Failed to trace any lines for "
1538- f"{ ad .filename } :{ ext .id } " )
1547+ else :
1548+ log .warning ("Failed to find any peaks in "
1549+ "f{ad.filename}:{ext.id}" )
15391550 continue
15401551
15411552 # List of "reference" positions (i.e., the coordinate
0 commit comments