Exemple #1
0
def find_edge_traces(tops, bots, order, slit_name):  
    
    if order.topMeas is not None:
        logger.debug('tracing top of order')
        order.topTrace = nirspec_lib.trace_order_edge(tops, order.topMeas, slit_name)
        
    if order.botMeas is not None:
        logger.debug('tracing bottom of order')
        order.botTrace = nirspec_lib.trace_order_edge(bots, order.botMeas, slit_name)
        
    if order.topTrace is None and order.botTrace is None:
        return

    if order.topTrace is not None and order.botTrace is not None:
        logger.info('using top and bottom trace')
        order.avgTrace = (order.topTrace + order.botTrace) / 2.0

    elif order.botTrace is None:
        logger.info('using top trace only')
        order.avgTrace = order.topTrace - ((order.topMeas - order.botCalc) / 2.0) + 1.0
        
    else:
        logger.info('using bottom trace only')
        order.avgTrace = order.botTrace + ((order.topCalc - order.botMeas) / 2.0) + 1.0
        
    return
Exemple #2
0
def find_edge_traces(tops, bots, order, slit_name):

    if order.topMeas is not None:
        logger.debug('tracing top of order')
        order.topTrace = nirspec_lib.trace_order_edge(tops, order.topMeas,
                                                      slit_name)

    if order.botMeas is not None:
        logger.debug('tracing bottom of order')
        order.botTrace = nirspec_lib.trace_order_edge(bots, order.botMeas,
                                                      slit_name)

    if order.topTrace is None and order.botTrace is None:
        return

    if order.topTrace is not None and order.botTrace is not None:
        logger.info('using top and bottom trace')
        order.avgTrace = (order.topTrace + order.botTrace) / 2.0

    elif order.botTrace is None:
        logger.info('using top trace only')
        order.avgTrace = order.topTrace - (
            (order.topMeas - order.botCalc) / 2.0) + 1.0

    else:
        logger.info('using bottom trace only')
        order.avgTrace = order.botTrace + (
            (order.topCalc - order.botMeas) / 2.0) + 1.0

    return
Exemple #3
0
    def findSpatialTrace(self, flatOrder):

        if flatOrder.topMeas is not None:
            self.logger.debug('tracing top of order')
            flatOrder.topEdgeTrace = nirspec_lib.trace_order_edge(
                self.topEdgeImg, flatOrder.topMeas)

        if flatOrder.botMeas is not None:
            self.logger.debug('tracing bottom of order')
            flatOrder.botEdgeTrace = nirspec_lib.trace_order_edge(
                self.botEdgeImg, flatOrder.botMeas)

        if flatOrder.topEdgeTrace is None and flatOrder.botEdgeTrace is None:
            raise DrpException('could not trace top or bottom edge')

        if flatOrder.topEdgeTrace is not None and flatOrder.botEdgeTrace is not None:
            self.logger.info('using top and bottom trace')
            flatOrder.avgEdgeTrace = (
                flatOrder.topEdgeTrace + flatOrder.botEdgeTrace) / 2.0

        elif flatOrder.botEdgeTrace is None:
            self.logger.info('using top trace only')
            flatOrder.avgEdgeTrace = flatOrder.topEdgeTrace - \
                ((flatOrder.topMeas - flatOrder.botCalc) / 2.0) + 1.0

        else:
            self.logger.info('using bottom trace only')
            flatOrder.avgEdgeTrace = flatOrder.botEdgeTrace + \
                ((flatOrder.topCalc - flatOrder.botMeas) / 2.0) + 1.0

        # apply long slit edge margin correction to raw traces
        if '24' in self.slit:
            self.logger.info('applying long slit edge margins of {} pixels'.format(
                config.params['long_slit_edge_margin']))
            if flatOrder.topEdgeTrace is not None:
                flatOrder.topEdgeTrace -= config.params['long_slit_edge_margin']
            if flatOrder.botEdgeTrace is not None:
                flatOrder.botEdgeTrace += config.params['long_slit_edge_margin']

        # if bottom edge trace successful, use to refine LHS bottom location
        if flatOrder.botEdgeTrace is not None:
            flatOrder.botMeas = flatOrder.botEdgeTrace[1]

        # smooth spatial trace
        flatOrder.smoothedSpatialTrace, flatOrder.spatialTraceMask = \
            nirspec_lib.smooth_spatial_trace(flatOrder.avgEdgeTrace)

        self.logger.info('spatial trace smoothed, ' +
                         str(self.flatImg.shape[1] - np.count_nonzero(flatOrder.spatialTraceMask)) +
                         ' points ignored')

        flatOrder.spatialTraceFitResidual = np.sqrt(
            np.mean(np.square(flatOrder.avgEdgeTrace - flatOrder.smoothedSpatialTrace)))
        self.logger.info('spatial trace smoothing rms fit residual = {:.2f}'.format(
            flatOrder.spatialTraceFitResidual))

        return
Exemple #4
0
 def findSpatialTrace(self, flatOrder):   
      
     if flatOrder.topMeas is not None:
         self.logger.debug('tracing top of order')
         flatOrder.topEdgeTrace = nirspec_lib.trace_order_edge(self.topEdgeImg, flatOrder.topMeas)
     
     if flatOrder.botMeas is not None:
         self.logger.debug('tracing bottom of order')
         flatOrder.botEdgeTrace = nirspec_lib.trace_order_edge(self.botEdgeImg, flatOrder.botMeas)
         
     if flatOrder.topEdgeTrace is None and flatOrder.botEdgeTrace is None:
         raise DrpException('could not trace top or bottom edge')
 
     if flatOrder.topEdgeTrace is not None and flatOrder.botEdgeTrace is not None:
         self.logger.info('using top and bottom trace')
         flatOrder.avgEdgeTrace = (flatOrder.topEdgeTrace + flatOrder.botEdgeTrace) / 2.0
 
     elif flatOrder.botEdgeTrace is None:
         self.logger.info('using top trace only')
         flatOrder.avgEdgeTrace = flatOrder.topEdgeTrace - \
                 ((flatOrder.topMeas - flatOrder.botCalc) / 2.0) + 1.0
         
     else:
         self.logger.info('using bottom trace only')
         flatOrder.avgEdgeTrace = flatOrder.botEdgeTrace + \
                 ((flatOrder.topCalc - flatOrder.botMeas) / 2.0) + 1.0
                 
     # apply long slit edge margin correction to raw traces
     if '24' in self.slit:
         self.logger.info('applying long slit edge margins of {} pixels'.format(
             config.params['long_slit_edge_margin']))
         if flatOrder.topEdgeTrace is not None:
             flatOrder.topEdgeTrace -= config.params['long_slit_edge_margin']
         if flatOrder.botEdgeTrace is not None:
             flatOrder.botEdgeTrace += config.params['long_slit_edge_margin']   
         
     # if bottom edge trace successful, use to refine LHS bottom location
     if flatOrder.botEdgeTrace is not None:
         flatOrder.botMeas = flatOrder.botEdgeTrace[1]
                 
     # smooth spatial trace
     flatOrder.smoothedSpatialTrace, flatOrder.spatialTraceMask = \
             nirspec_lib.smooth_spatial_trace(flatOrder.avgEdgeTrace)
             
     self.logger.info('spatial trace smoothed, ' + \
             str(self.flatImg.shape[1] - np.count_nonzero(flatOrder.spatialTraceMask)) + 
             ' points ignored')
 
     flatOrder.spatialTraceFitResidual = np.sqrt(
             np.mean(np.square(flatOrder.avgEdgeTrace - flatOrder.smoothedSpatialTrace)))
     self.logger.info('spatial trace smoothing rms fit residual = {:.2f}'.format(
             flatOrder.spatialTraceFitResidual))
         
     return