def match_frames_old(slf, frames, frametype='<None>'): """ Parameters ---------- slf frames frametype Returns ------- """ from pypit import arcyutils msgs.info("Matching {0:d} {1:s} frames".format(frames.shape[2],frametype)) srtframes = [np.zeros((frames.shape[0],frames.shape[1],1))] srtframes[0][:,:,0] = frames[:,:,0] prob = arutils.erf(slf._argflag['reduce']['flatmatch']/np.sqrt(2.0))[0] # chisqv = chisq.ppf(prob,frames.shape[0]*frames.shape[1]) chisqv = frames.shape[0]*frames.shape[1] for fr in range(1,frames.shape[2]): fm = None for st in range(len(srtframes)): chisqc = arcyutils.checkmatch(srtframes[st][:,:,0],frames[:,:,fr],1048577.0) if chisqc < chisqv*10.0: fm = st break if fm is None: srtframes.append(np.zeros((frames.shape[0],frames.shape[1],1))) srtframes[-1][:,:,0] = frames[:,:,fr] else: srtframes[fm] = np.append(srtframes[fm],np.zeros((frames.shape[0],frames.shape[1],1)),axis=2) srtframes[fm][:,:,-1] = frames[:,:,fr] msgs.info("Found {0:d} different sets of {1:s} frames".format(len(srtframes),frametype)) return srtframes
def match_frames_old(slf, frames, frametype='<None>'): """ Parameters ---------- slf frames frametype Returns ------- """ from pypit import arcyutils msgs.info("Matching {0:d} {1:s} frames".format(frames.shape[2],frametype)) srtframes = [np.zeros((frames.shape[0],frames.shape[1],1))] srtframes[0][:,:,0] = frames[:,:,0] prob = arutils.erf(slf._argflag['reduce']['flatmatch']/np.sqrt(2.0))[0] # chisqv = chisq.ppf(prob,frames.shape[0]*frames.shape[1]) chisqv = frames.shape[0]*frames.shape[1] for fr in xrange(1,frames.shape[2]): fm = None for st in xrange(len(srtframes)): chisqc = arcyutils.checkmatch(srtframes[st][:,:,0],frames[:,:,fr],1048577.0) if chisqc < chisqv*10.0: fm = st break if fm is None: srtframes.append(np.zeros((frames.shape[0],frames.shape[1],1))) srtframes[-1][:,:,0] = frames[:,:,fr] else: srtframes[fm] = np.append(srtframes[fm],np.zeros((frames.shape[0],frames.shape[1],1)),axis=2) srtframes[fm][:,:,-1] = frames[:,:,fr] msgs.info("Found {0:d} different sets of {1:s} frames".format(len(srtframes),frametype)) return srtframes
def match_frames(frames, criteria, frametype='<None>', satlevel=None): """ identify frames with a similar appearance (i.e. one frame appears to be a scaled version of another). """ prob = arutils.erf(criteria/np.sqrt(2.0))[0] frsh0, frsh1, frsh2 = frames.shape msgs.info("Matching {:d} {:s} frames with confidence interval {:5.3%}".format(frsh2, frametype, prob)) srtframes = [np.zeros((frsh0, frsh1, 1))] srtframes[0][:,:,0] = frames[:,:,0] tsrta = [frames[frsh0/2,:,0]] tsrtb = [frames[:,frsh1/2,0]] msgs.bug("Throughout this routine, you should probably search for the mean of the non-saturated pixels") tsrta[0] /= np.mean(tsrta[0]) tsrtb[0] /= np.mean(tsrtb[0]) for fr in range(1, frames.shape[2]): fm = None for st in range(len(srtframes)): tmata = frames[frsh0/2,:,fr] tmatb = frames[:,frsh1/2,fr] tmata /= np.mean(tmata) tmatb /= np.mean(tmatb) if satlevel is None: wa = np.where(tmata>0.0) wb = np.where(tmatb>0.0) else: wa = np.where((tmata>0.0)&(tmata<satlevel)) wb = np.where((tmatb>0.0)&(tmatb<satlevel)) testa, testb = np.mean(tsrta[st][wa]/tmata[wa]), np.mean(tsrtb[st][wb]/tmatb[wb]) if np.size(wa[0]) == 0 or np.size(wb[0]) == 0: msgs.bug("I didn't expect to find a row of zeros in the middle of the chip!") sys.exit() if (testa >= prob) and (testa <= (2.0-prob)) and (testb >= prob) and (testb <= (2.0-prob)): fm = st break if fm is None: srtframes.append(np.zeros((frames.shape[0], frames.shape[1], 1))) srtframes[-1][:,:,0] = frames[:,:,fr] tsrta.append(tmata) tsrtb.append(tmatb) else: srtframes[fm] = np.append(srtframes[fm],np.zeros((frames.shape[0], frames.shape[1], 1)), axis=2) srtframes[fm][:,:,-1] = frames[:,:,fr] if len(srtframes) > 1: msgs.info("Found {0:d} different sets of {1:s} frames".format(len(srtframes), frametype)) else: msgs.info("Found {0:d} set of {1:s} frames".format(len(srtframes), frametype)) if frames.shape[2] > 1: del tsrta, tsrtb, tmata, tmatb, testa, testb return srtframes
def match_frames(frames, criteria, frametype='<None>', satlevel=None): """ identify frames with a similar appearance (i.e. one frame appears to be a scaled version of another). """ prob = arutils.erf(criteria/np.sqrt(2.0))[0] frsh0, frsh1, frsh2 = frames.shape msgs.info("Matching {:d} {:s} frames with confidence interval {:5.3%}".format(frsh2, frametype, prob)) srtframes = [np.zeros((frsh0, frsh1, 1))] srtframes[0][:,:,0] = frames[:,:,0] tsrta = [frames[frsh0/2,:,0]] tsrtb = [frames[:,frsh1/2,0]] msgs.bug("Throughout this routine, you should probably search for the mean of the non-saturated pixels") tsrta[0] /= np.mean(tsrta[0]) tsrtb[0] /= np.mean(tsrtb[0]) for fr in xrange(1, frames.shape[2]): fm = None for st in xrange(len(srtframes)): tmata = frames[frsh0/2,:,fr] tmatb = frames[:,frsh1/2,fr] tmata /= np.mean(tmata) tmatb /= np.mean(tmatb) if satlevel is None: wa = np.where(tmata>0.0) wb = np.where(tmatb>0.0) else: wa = np.where((tmata>0.0)&(tmata<satlevel)) wb = np.where((tmatb>0.0)&(tmatb<satlevel)) testa, testb = np.mean(tsrta[st][wa]/tmata[wa]), np.mean(tsrtb[st][wb]/tmatb[wb]) if np.size(wa[0]) == 0 or np.size(wb[0]) == 0: msgs.bug("I didn't expect to find a row of zeros in the middle of the chip!") sys.exit() if (testa >= prob) and (testa <= (2.0-prob)) and (testb >= prob) and (testb <= (2.0-prob)): fm = st break if fm is None: srtframes.append(np.zeros((frames.shape[0], frames.shape[1], 1))) srtframes[-1][:,:,0] = frames[:,:,fr] tsrta.append(tmata) tsrtb.append(tmatb) else: srtframes[fm] = np.append(srtframes[fm],np.zeros((frames.shape[0], frames.shape[1], 1)), axis=2) srtframes[fm][:,:,-1] = frames[:,:,fr] if len(srtframes) > 1: msgs.info("Found {0:d} different sets of {1:s} frames".format(len(srtframes), frametype)) else: msgs.info("Found {0:d} set of {1:s} frames".format(len(srtframes), frametype)) if frames.shape[2] > 1: del tsrta, tsrtb, tmata, tmatb, testa, testb return srtframes