Skip to content

Dead fiber ids when making RSS files #59

@joaquinhernandezg

Description

@joaquinhernandezg

Hi!

I noticed dead fibers are not being handled properly, and it messes up the fiber indexing when constructing the extraction files and RSS files, and it is noticeable when constructing the cubes, as some spaxels appear in positions they shouldn't.

For example, 2A has dead fibers 270 and 299. When examining an RSS file, they appear in the table as alive fibers, and the last two fibers (298 and 299) are not present. All the indices are therefore shifted due to not considering these dead fibers.

I noticed in ExtractLlamas.py, there is a catch for dead fibers

However, the dead fibers are not inserted; this modification adds the dead fibers

index_trace = 0

for ifiber in range(expected_nfibers):
    extracted = np.zeros(self.trace.naxis1)
    # print fiber, and list of dead fibers, print also bench and color
    logger.info(self.dead_fibers)
    logger.info(f'Extracting fiber # {ifiber} of {trace.nfibers} for bench {benchside} channel {self.channel}')
    if ifiber in self.dead_fibers:
        logger.info(f"Skipping dead fiber # {ifiber}")
        self.counts[ifiber,:] = extracted
        continue

    if (optimal == True):
        # Optimally weighted extraction (a la Horne et al ~1986)
        #logger.info("..Optimally Extracting fiber #{}".format(ifiber))
        x_spec,f_spec,weights = self.isolateProfile(index_trace)
        if x_spec is None:
            continue

        extracted = np.zeros(self.trace.naxis1)
        for i in range(self.trace.naxis1):
            thisx = (x_spec == i)
            if np.nansum(thisx) > 0:
                extracted[i] = np.nansum(f_spec[thisx]*weights[thisx])/np.nansum(weights[thisx])
            #handles case where there are no elements
            else:
                extracted[i] = 0.0

        self.counts[ifiber,:] = extracted

    elif optimal == False:
        # Boxcar Extraction - fast!
        logger.info("..Boxcar extracting fiber #{}".format(ifiber))
        x_spec,f_spec,weights = self.isolateProfile(index_trace, boxcar=True)

        if x_spec is None:
            continue

        extracted = np.zeros(self.trace.naxis1)
        tracey = self.trace.traces[index_trace,:]
        for i in range(self.trace.naxis1):
            thisx = (x_spec == i)
            if np.nansum(thisx) > 0:
                extracted[i] = np.nansum(f_spec[thisx])
            #handles case where there are no elements
            else:
                extracted[i] = 0.0
            extracted[i] = np.nansum(self.frame[round(tracey[i])-4:round(tracey[i])+5,i])

        self.counts[ifiber,:] = extracted
    index_trace += 1
self.old_count_shape = self.counts.shape
if i in dead_set:
    # Leave zeros for dead fiber positions
    new_counts[i] = np.zeros(trace.naxis1)
    logger.info(f"Inserting dead fiber at index {i}")
    continue
else:
      # Copy data from original array if position exists
      #if current_idx < len(self.counts):
      new_counts[i] = self.counts[current_idx]
      current_idx += 1

Then the dead fibers have to be taken into account when constructing the indices of the fibers in the RSS files here

fiber_ids.extend(np.arange(n_fibers))

This small code constructs the fiber ids, taking into account the dead fibers

  fibers =[]
  counter = 0
  while len(fibers) < n_fibers:
      if counter in dead_fibers:
          counter+=1
      else:
          fibers.append(counter)
          counter+=1

  fiber_ids.extend(fibers)

Doing these two small changes fixes the fiber positioning in the final cube. Although I think only the last step is needed, as the fibers with zeros are removed anyway when making the RSS files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions