def get_corr_map_(coo1, coo2, skypos, skyrange, sec):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len2):
            print(i)
            tmp_co = np.roll(coo2, i, axis=0)[0:len1, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= 0.01, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= 0.01, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    else:
        for i in range(len1):
            print(i)
            tmp_co = coo2 - np.roll(coo1, i, axis=0)[0:len2, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= 0.01, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= 0.01, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    return co_rel[1:]
def get_corr_map_photon(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
  count = np.zeros(imsz)
  print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001)

  if len2<=80 or len1<=80:
    return count, np.array([0.0, 0.0])
  if len2>len1:
    for i in range(len2):
      #print(i)
      tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  else:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  print co_rel.shape
  if co_rel.shape[0]>1000:
    centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
  else:
    return count, np.array([0.0, 0.0])

  return count, centroid
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len2):
            print(i)
            tmp_co = np.roll(coo2, i, axis=0)[0:len1, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            '''
      if (i+1)%200 == 0:
        writer.writerows(co_rel[1:])
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
      '''
    else:
        for i in range(len1):
            print(i)
            tmp_co = coo2 - np.roll(coo1, i, axis=0)[0:len2, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            '''
      if (i+1)%200 == 0:
        writer.writerows(co_rel[1:])
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
      '''
    '''
  if co_rel.shape[0]>1:
    #writer.writerows(co_rel[1:])
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
    count += H
  #csvfile.close()
  '''
    centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)

    return count, centroid
示例#4
0
def get_corr_map(coo1, coo2, skypos, skyrange):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.001)
  count = np.zeros(imsz)
  print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.001)
  if len2>len1:
    for i in range(len2):
      print(i)
      co_rel = np.concatenate((co_rel, np.roll(coo2, i, axis=0)[0:len1,:]-coo1), axis = 0)
      if (i+1)%200 == 0:
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
  else:
    for i in range(len1):
      print(i)
      co_rel = np.concatenate((co_rel, coo2-np.roll(coo1, i, axis=0)[0:len2,:]), axis = 0)
      if (i+1)%200 == 0:
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
  if co_rel.shape[0]>1:
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
    count += H
  return count
def get_corr_map_(coo1, coo2, skypos, skyrange, sec):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
  count = np.zeros(imsz)
  print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len2):
      print(i)
      tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=0.01,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=0.01,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len1):
      print(i)
      tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=0.01,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=0.01,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  return co_rel[1:]
def get_corr_map_fast(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
  count = np.zeros(imsz)
  print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  print co_rel.shape
  if co_rel.shape[0]>50:
    centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
  else:
    return count, np.array([0.0, 0.0])

  return count, centroid
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
  count = np.zeros(imsz)
  print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len2):
      #print(i)
      tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      '''
      if (i+1)%200 == 0:
        writer.writerows(co_rel[1:])
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
      '''
  else:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      '''
      if (i+1)%200 == 0:
        writer.writerows(co_rel[1:])
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
        co_rel = np.array([[0, 0]])
      '''
  '''
  if co_rel.shape[0]>1:
    #writer.writerows(co_rel[1:])
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
    count += H
  #csvfile.close()
  '''
  print co_rel.shape
  if co_rel.shape[0]>50:
    centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
  else:
    return count, np.array([0.0, 0.0])

  return count, centroid
def plot_co(co, pixsz, skypos, skyrange, weights=None):
    bound = skyrange[0] / 2.
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co[:, 0:2], 1), 1)
    if weights is not None:
        H, xedges, yedges = np.histogram2d(foc[:, 1] - 0.5,
                                           foc[:, 0] - 0.5,
                                           bins=imsz,
                                           range=([[0, imsz[0]], [0,
                                                                  imsz[1]]]),
                                           weights=weights)
    else:
        H, xedges, yedges = np.histogram2d(foc[:, 1] - 0.5,
                                           foc[:, 0] - 0.5,
                                           bins=imsz,
                                           range=([[0, imsz[0]], [0,
                                                                  imsz[1]]]))
    h = H.copy()
    #np.flip(h,axis=0)
    '''
    hist_size = [100,100]
    H,xedges,yedges=np.histogram2d(co[:,1], co[:,0],\
                             bins=hist_size, range=([ [-bound,bound],[-bound,bound] ]))
    h = H.copy()
    '''
    plt.imshow(h+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'),\
                 aspect='equal', extent=[bound*3600, -bound*3600, -bound*3600, bound*3600], origin='lower',vmin=0)
    #norm=LogNorm(10**0,np.max(h)))

    plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
    plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
    plt.xlabel(r'$\Delta gl$')
    plt.ylabel(r'$\Delta gb$')
    plt.xlim(-bound * 3600, bound * 3600)
    plt.ylim(-bound * 3600, bound * 3600)
    '''
    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    t=50
    c_data = c3.find_centroid(data, t)
    if c_data is not None:
        cy, cx, max_value, flux = c_data
        c = np.array([-bound+cx*bound*2/hist_size[0], -bound+cy*bound*2/hist_size[0]])
    print c*3600
    '''
    c = centroid(5, H, wcs)
    print(c * 3600)
    plt.plot(c[0] * 3600, c[1] * 3600, '+r', markersize=8, mew=1)
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    print co_rel.shape
    plt.hist2d(co_rel[:, 0], co_rel[:, 1], bins=100)
    #plt.hist2d(co_rel[:,0], co_rel[:,1], bins=200, range=[[-0.06,-0.03],[-0.08,-0.04]])
    plt.show()
    centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
    print centroid
    #plt.hist2d(co_rel[:,0], co_rel[:,1], bins=200)
    '''
  plt.hist(co_rel[:,0],100)
  plt.show()
  plt.hist(co_rel[:,1],100)
  plt.show()
  '''
    '''
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    #print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    cy, cx, max_value = c3.find_centroid(data)
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0]
    if centroid[0] > 1:
        centroid[0] = centroid[0] - 360.

    return centroid, max_value
示例#11
0
def plot_co(co, pixsz, skypos, skyrange, weights=None):
    bound = skyrange[0]/2.
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co[:,0:2],1),1)
    if weights is not None:
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights)
    else:
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
    h = H.copy()
    #np.flip(h,axis=0)
    '''
    hist_size = [100,100]
    H,xedges,yedges=np.histogram2d(co[:,1], co[:,0],\
                             bins=hist_size, range=([ [-bound,bound],[-bound,bound] ]))
    h = H.copy()
    '''
    plt.imshow(h+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'),\
                 aspect='equal', extent=[bound*3600, -bound*3600, -bound*3600, bound*3600], origin='lower',vmin=0)
                 #norm=LogNorm(10**0,np.max(h)))

    plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
    plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
    plt.xlabel(r'$\Delta gl$')
    plt.ylabel(r'$\Delta gb$')
    plt.xlim(-bound*3600,bound*3600)
    plt.ylim(-bound*3600,bound*3600)

    '''
    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    t=50
    c_data = c3.find_centroid(data, t)
    if c_data is not None:
        cy, cx, max_value, flux = c_data
        c = np.array([-bound+cx*bound*2/hist_size[0], -bound+cy*bound*2/hist_size[0]])
    print c*3600
    '''
    c = centroid(5,H,wcs)
    print(c*3600)
    plt.plot(c[0]*3600,c[1]*3600,'+r', markersize=8, mew=1)
示例#12
0
def get_corr_map(coo1, coo2, skypos, skyrange):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.001)
    if len2 > len1:
        for i in range(len2):
            print(i)
            co_rel = np.concatenate(
                (co_rel, np.roll(coo2, i, axis=0)[0:len1, :] - coo1), axis=0)
            if (i + 1) % 200 == 0:
                foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
                H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                           bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
                count += H
                co_rel = np.array([[0, 0]])
    else:
        for i in range(len1):
            print(i)
            co_rel = np.concatenate(
                (co_rel, coo2 - np.roll(coo1, i, axis=0)[0:len2, :]), axis=0)
            if (i + 1) % 200 == 0:
                foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
                H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                           bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
                count += H
                co_rel = np.array([[0, 0]])
    if co_rel.shape[0] > 1:
        foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
        H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                   bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
        count += H
    return count
def get_corr_map_photon(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)

    if len2 <= 80 or len1 <= 80:
        return count, np.array([0.0, 0.0])
    if len2 > len1:
        for i in range(len2):
            #print(i)
            tmp_co = np.roll(coo2, i, axis=0)[0:len1, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    else:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - np.roll(coo1, i, axis=0)[0:len2, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    print co_rel.shape
    if co_rel.shape[0] > 1000:
        centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
    else:
        return count, np.array([0.0, 0.0])

    return count, centroid
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
  imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
  count = np.zeros(imsz)
  #print(imsz)
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))


  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  cy, cx, max_value = c3.find_centroid(data)
  centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.

  return centroid, max_value
def get_corr_map_fast(coo1, coo2, skypos, skyrange, sec, bound, bandwidth):
    imsz = imagetools.deg2pix(skypos, skyrange, 0.0001)
    count = np.zeros(imsz)
    print(imsz)
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=0.0001)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    print co_rel.shape
    if co_rel.shape[0] > 50:
        centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound)
    else:
        return count, np.array([0.0, 0.0])

    return count, centroid
示例#16
0
import imagetools
import numpy as np
from astropy.io import fits as pyfits

if __name__ == '__main__':
    scan_list = ['05', '14', '23', '32', '41', '50', '59', '68']

    tranges = [[0, 0]]
    skypos_f, skyrange_f = ([0, 0], [1.33333336, 1.33333336])
    imsz_f = imagetools.deg2pix(skypos_f, skyrange_f, 0.0016666667)
    count_f = np.zeros(imsz_f)
    wcs_f = imagetools.define_wcs(skypos_f,
                                  skyrange_f,
                                  width=False,
                                  height=False,
                                  verbose=0,
                                  pixsz=0.0016666667)

    for scan_num in scan_list:
        hdu_list = pyfits.open(
            '../fits/count_map_%s_gPr_cata_10_device_r0_nostar.fits' %
            scan_num)
        data = hdu_list[0].data
        #tranges.append(hdulist[0].header)
        count_f += data
    print np.median(count_f) * 0.85, np.median(count_f) * 1.15

    hdu = pyfits.PrimaryHDU(count_f)
    hdu = imagetools.fits_header('NUV',
                                 skypos_f,
                                 tranges,
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix,
                 info_list, d3, outdir):
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    count = np.zeros(imsz)
    #print(imsz)
    bound = skyrange[0] / 0.000554 / 2400. * 36000. * 800 * 0.001666
    co_rel = np.array([[0, 0]])
    infos = np.array([[0, 0, 0]])
    rot = np.array([0])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    '''
  photon_len = coo2.shape[0]
  star_len = coo1.shape[0]
  print 'repeat coo1'
  coo1 = np.repeat(coo1, photon_len, axis=0)
  print coo1.shape
  print 'repeat d3'
  d3 = np.tile(d3, (star_len,1))
  print d3.shape
  print 'convert coo1'
  xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0)
  print 'tile coo2'
  co_rel = np.tile(coo2, (star_len,1)) - np.array([xi,eta]).T
  mask = (np.absolute(co_rel[:,0])<=bound) & (np.absolute(co_rel[:,1])<=bound)
  co_rel = co_rel[mask]
  print 'tile infos'
  infos = np.tile(info_list, (star_len,1))[mask]
  print infos.shape
  '''

    if len2 > len1:
        for i in range(len1):
            ones = np.ones(d3.shape[0])
            xi, eta = gn.gnomfwd_simple(coo1[i, 0] * ones, coo1[i, 1] * ones,
                                        d3[:, 1], d3[:, 2], -d3[:, 3],
                                        1 / 36000., 0)
            tmp_co = coo2 - np.array([xi, eta]).T
            mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute(
                tmp_co[:, 1]) <= bound)
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            infos = np.concatenate((infos, info_list[mask]), axis=0)
            #rot = np.concatenate((rot, d3[mask]), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            infos = np.concatenate(
                (infos, np.repeat(info_list[i], tmp_co.shape[0])), axis=0)
            rot = np.concatenate((rot, np.repeat(d3[i], tmp_co.shape[0])),
                                 axis=0)

    path = os.path.dirname('{0}/test/test'.format(outdir))
    if not os.path.exists(path):
        os.makedirs(path)
    np.save('{0}/test/{1}.npy'.format(outdir, idx), co_rel)
    #np.save('{0}/radec/{1}.npy'.format(outdir, idx), co_radec)
    np.save('{0}/test/info_{1}.npy'.format(outdir, idx), infos)

    return [0, 0], 0, 0
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix,
                 info_list, d3, outdir):
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    count = np.zeros(imsz)
    #print(imsz)
    bound = skyrange[0]
    co_rel = np.array([[0, 0]])
    infos = np.array([[0, 0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute(
                tmp_co[:, 1]) <= bound)
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            infos = np.concatenate((infos, info_list[mask]), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            infos = np.concatenate(
                (infos, np.repeat(info_list[i], tmp_co.shape[0])), axis=0)

    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

    t = np.percentile(H, 90)
    t = 50
    print 'threshold:{0}'.format(t)
    hp = H.copy()

    #plt.colorbar()

    #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05)
    #plt.xlim(-0.005,0.005)
    #plt.ylim(-0.005,0.005)

    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    c_data = c3.find_centroid(data, t)
    if c_data is not None:
        cy, cx, max_value, flux = c_data
        cy += 0.5
        cx += 0.5
        centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0]
    else:
        centroid = [0., 0.]
        max_value = 0
        flux = 500
    if centroid[0] > 1:
        centroid[0] = centroid[0] - 360.
    #print 'max:{0}'.format(max_value)
    print hp.shape

    #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0)

    plt.imshow(hp + 10**-10,
               interpolation='None',
               cmap=plt.get_cmap('Greys'),
               aspect='equal',
               extent=[0.02 * 3600, -0.02 * 3600, 0.02 * 3600, -0.02 * 3600],
               origin='upper',
               norm=LogNorm(10**0, np.max(hp)))
    plt.colorbar()
    plt.xlim(-0.02 * 3600, 0.02 * 3600)
    plt.ylim(-0.02 * 3600, 0.02 * 3600)
    plt.ylabel('gb')
    plt.xlabel('gl')
    plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
    plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
    plt.plot(centroid[0] * 3600, centroid[1] * 3600, '+r', markersize=8)
    #plt.show()
    rot = np.mean(d3) / 180. * np.pi

    l = np.linspace(0, 8., 5)
    x_y = np.sin(-rot) * l
    x_x = np.cos(-rot) * l
    y_y = np.sin(-rot + np.pi / 2.) * l
    y_x = np.cos(-rot + np.pi / 2.) * l

    plt.plot(x_x, x_y, '--g')
    plt.plot(y_x, y_y, '--g')

    co_rel = co_rel * 3600
    mask = (co_rel[1:, 0]**2 + co_rel[1:, 1]**2) <= (2.5**2)
    num = np.sum(mask)
    plt.title('t={0}-{1}s, photons within d=5\" circle:{2}'.format(
        idx / 2 - 50, idx / 2, num))

    plt.savefig('{0}/{1}.pdf'.format(outdir, idx))
    plt.clf()
    np.save('{0}/{1}.npy'.format(outdir, idx), co_rel)

    plt.imshow(hp + 10**-10,
               interpolation='None',
               cmap=plt.get_cmap('Greys'),
               aspect='equal',
               extent=[0.02 * 3600, -0.02 * 3600, 0.02 * 3600, -0.02 * 3600],
               origin='upper',
               norm=LogNorm(10**0, np.max(hp)))
    plt.colorbar()
    plt.xlim(-0.01 * 3600, 0.01 * 3600)
    plt.ylim(-0.01 * 3600, 0.01 * 3600)
    plt.ylabel('gb')
    plt.xlabel('gl')
    plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
    plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
    #plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8)
    #plt.show()
    rot = np.mean(d3) / 180. * np.pi

    l = np.linspace(0, 8., 5)
    x_y = np.sin(-rot) * l
    x_x = np.cos(-rot) * l
    y_y = np.sin(-rot + np.pi / 2.) * l
    y_x = np.cos(-rot + np.pi / 2.) * l

    #plt.plot(x_x, x_y, '--g')
    #plt.plot(y_x, y_y, '--g')

    #mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2)
    #num = np.sum(mask)
    plt.title('t={0}-{1}s'.format(idx / 2 - 50, idx / 2))

    plt.savefig('{0}/zoom_{1}.pdf'.format(outdir, idx))
    plt.clf()
    '''
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,0], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('xa')
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/xa_{0}.png'.format(idx))
  plt.clf()
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,1], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('ya')
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/ya_{0}.png'.format(idx))
  plt.clf()
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,2], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('q')  
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/q_{0}.png'.format(idx), dpi=190)
  plt.clf()
  '''
    '''
  n, bins, patches = plt.hist(infos[1:,1], 30, normed=1, facecolor='green', alpha=0.5)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_{0}.pdf'.format(idx), dpi=190)
  plt.clf()

  mask = (co_rel[:,0]<-25) & (co_rel[:,0]>-45) & (co_rel[:,1]>42) & (co_rel[:,1]<66)
  n, bins, patches = plt.hist(infos[mask,1], 30, normed=1, facecolor='green', alpha=0.5)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_gh_{0}.pdf'.format(idx), dpi=190)
  plt.clf()
  '''

    return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  bound = skyrange[0]
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

  t = np.percentile(H, 90)
  t = 1
  print 'threshold:{0}'.format(t) 
  hp = H.copy()

  #plt.colorbar()
  '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
  #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  if c_data is not None:
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #print 'max:{0}'.format(max_value)
  print hp.shape

  return centroid, max_value, flux
def get_corr_map(pid,
                 coo1,
                 coo2,
                 skypos,
                 skyrange,
                 pixsz,
                 time,
                 suffix,
                 weight,
                 flux=None):
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    count = np.zeros(imsz)
    bound = skyrange[0] / 2.

    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)

    catalog = SkyCoord(coo1, unit='deg', frame='fk5', equinox='J2000.0')
    sky_data = SkyCoord(coo2, unit='deg', frame='fk5', equinox='J2000.0')
    print '{1}:catalog:{0}'.format(catalog.shape[0], pid)
    print '{1}:data:{0}'.format(sky_data.shape[0], pid)
    idxc, idxcatalog, d2d_p, d3d_p = sky_data.search_around_sky(
        catalog, 0.0045 * u.deg)
    print '{1}:match:{0}'.format(idxc.shape[0], pid)

    if idxc.shape[0] < 10:
        centroid = [0., 0.]
        max_value = 0
        flux = 500
        return centroid, max_value, flux, idxc.shape[0]

    co_rel = coo2[idxcatalog] - coo1[idxc]
    if flux is not None:
        weights = weight[idxcatalog] / flux[idxc] * 50.
    else:
        weights = weight[idxcatalog]

    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel, 1), 1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights)

    t = np.percentile(H, 90)
    t = 1
    print '{1}:threshold:{0}'.format(t, pid)
    #hp = H.copy()

    #plt.colorbar()
    '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
    #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    c_data = c3.find_centroid(data, t)
    #print c_data
    if c_data is not None:
        #cy, cx, max_value, flux, x, y = c_data
        cy, cx, max_value, flux = c_data
        cy += 0.5
        cx += 0.5
        centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0]
        #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0]
        #print c_sex
    else:
        centroid = [0., 0.]
        max_value = 0
        flux = 500
    if centroid[0] > 1:
        centroid[0] = centroid[0] - 360.
    #if c_sex[0]>1:
    #  c_sex[0] = c_sex[0]-360.
    #print 'max:{0}'.format(max_value)
    #print cx,cy
    '''
  plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0)
  #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-bound/3, bound/3)
  plt.ylim(-bound/3, bound/3)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0],centroid[1],'+r', markersize=8)
  #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8)
  plt.show()
  #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx))
  #plt.clf()
  '''
    return centroid, max_value, flux, idxc.shape[0]
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, info_list, d3, outdir):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  bound = skyrange[0]/0.000554/2400.*36000.*800*0.001666
  co_rel = np.array([[0,0]])
  infos = np.array([[0,0,0]])
  rot = np.array([0])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  '''
  photon_len = coo2.shape[0]
  star_len = coo1.shape[0]
  print 'repeat coo1'
  coo1 = np.repeat(coo1, photon_len, axis=0)
  print coo1.shape
  print 'repeat d3'
  d3 = np.tile(d3, (star_len,1))
  print d3.shape
  print 'convert coo1'
  xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0)
  print 'tile coo2'
  co_rel = np.tile(coo2, (star_len,1)) - np.array([xi,eta]).T
  mask = (np.absolute(co_rel[:,0])<=bound) & (np.absolute(co_rel[:,1])<=bound)
  co_rel = co_rel[mask]
  print 'tile infos'
  infos = np.tile(info_list, (star_len,1))[mask]
  print infos.shape
  '''

  if len2>len1:
    for i in range(len1):
      ones = np.ones(d3.shape[0])
      xi, eta = gn.gnomfwd_simple(coo1[i,0]*ones, coo1[i,1]*ones, d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0)
      tmp_co = coo2-np.array([xi,eta]).T
      mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound)
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      infos = np.concatenate((infos,info_list[mask]), axis=0)
      #rot = np.concatenate((rot, d3[mask]), axis=0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      infos = np.concatenate((infos,np.repeat(info_list[i], tmp_co.shape[0])), axis=0)
      rot = np.concatenate((rot, np.repeat(d3[i], tmp_co.shape[0])), axis=0)


  path = os.path.dirname('{0}/test/test'.format(outdir))
  if not os.path.exists(path):
    os.makedirs(path)
  np.save('{0}/test/{1}.npy'.format(outdir, idx), co_rel)
  #np.save('{0}/radec/{1}.npy'.format(outdir, idx), co_radec)
  np.save('{0}/test/info_{1}.npy'.format(outdir, idx), infos)


  return [0,0], 0, 0
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  bound = skyrange[0]
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

  t = np.percentile(H, 90)
  t = 1
  print 'threshold:{0}'.format(t) 
  hp = H.copy()

  #plt.colorbar()
  '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
  #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  if c_data is not None:
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #print 'max:{0}'.format(max_value)
  print hp.shape
  fig = plt.gcf()
  fig.set_size_inches(8,8)
  plt.imshow(hp,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02,-0.02, 0.02,-0.02], origin='upper', imlim=[-0.02,0.02, -0.02,0.02])
  #plt.imshow(hp,interpolation='None', cmap=plt.get_cmap('Greys'), extent=[0.02,-0.02,0.02,-0.02])
  plt.xlabel(r'$\Delta RA$')
  plt.ylabel(r'$\Delta Dec$')
  plt.plot(centroid[0],centroid[1],'+r', markersize=8)
  plt.xlim(0.02, -0.02)
  plt.ylim(0.02, -0.02)
  plt.tight_layout()
  #plt.subplots_adjust(left=0.12, bottom=0.07, right=0.95, top=0.97, wspace=0, hspace=0)
  plt.savefig('/home/dw1519/galex/plots/co%s.png'%suffix, dpi=190)
  #plt.show()
  plt.clf()
  return centroid, max_value, flux
        sky_data = SkyCoord(data, unit='deg', frame=FK5, equinox='J2000.0')
        gal = sky_data.transform_to(Galactic)
        data = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) 
        H = hist_g(data, wcs, imsz)
        count += H
        trange[1] = float(time)/1000
  tranges.append(trange)
  #trange = [0, 0]
  return_dict[pid] = (count, tranges)

if __name__ == '__main__':
  if False:
    skypos, skyrange = pos_range.get_pos_range(name_list='../data/name_list')
    tranges = []
    trange = [0, 0]
    imsz = imagetools.deg2pix(skypos, skyrange, 0.002)
    count = np.zeros(imsz)
    wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.002)
    print imsz

    hdulist = pyfits.open('../data/AIS_GAL_SCAN_00005_0001-asprta.fits')
    co_data = hdulist[1].data

    step = 10
    offsets = np.load('../data/new/offsets300-1343_10_new.npy')
    length = offsets.shape[0]
    print length
    for i in range(length-1):
      offsets[i+1] = offsets[i+1] + offsets[i]
    offsets = np.append(offsets, np.array([[0.,0.]]), axis=0)
    print offsets.shape
    if False:
        for i in range(100, 2900, 400):
            data_list = []
            data_list1 = []
            for j in range(4):
                out = '/home/dw1519/dw1519/galex/plots/co239-10'
                data = np.load('{0}/{1}.npy'.format(out, i)) / 3600.
                data1 = np.load('{0}/ya/{1}.npy'.format(out, i)) / 3600.
                data_list.append(data)
                data_list1.append(data1)
                #info = np.load('/home/dw1519/dw1519/galex/plots/co32-10/info_{0}.npy'.format(i))
                #mask = info[:,1]>=2
            skypos = [0, 0]
            skyrange = [0.02, 0.02]
            pixsz = 0.0004
            imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
            wcs = imagetools.define_wcs(skypos,
                                        skyrange,
                                        width=False,
                                        height=False,
                                        verbose=0,
                                        pixsz=pixsz)
            foc = wcs.sip_pix2foc(wcs.wcs_world2pix(data[1:], 1), 1)
            H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                         bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
            #p = radial_profile(H, [99.5,99.5])
            p = radial_profile(H, [24.5, 24.5])

            foc = wcs.sip_pix2foc(wcs.wcs_world2pix(data1[1:], 1), 1)
            H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                         bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
示例#25
0
      print 'exists'

    cata = spi.load_obj('../data/%s_starset_extra_full'%name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

    count_list, imsz_list, wcs_list = [],[],[]
    skypos_list, skyrange_list = [],[]
    for i in range(cata_list.shape[0]):
      skypos, skyrange = ([cata_list[i,1], cata_list[i,2]] , [0.03, 0.03])
      print skypos
      print skyrange
      skypos_list.append(skypos)
      skyrange_list.append(skyrange)
      imsz = imagetools.deg2pix(skypos, skyrange, 0.000416666666666667)
      count = np.zeros(imsz)
      wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.000416666666666667)
      count_list.append(count)
      wcs_list.append(wcs)
      imsz_list.append(imsz)

    step = 10
    tranges = []
    trange = [0, 0]

    hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%name)
    co_data = hdulist[1].data
    offsets = np.load('../data/%s/cata/offsets1_10_new.npy'%name)
    initial = int((co_data[1][0]-0.5)*1000)
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, weight, flux=None):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  weights = np.array([])
  bound = skyrange[0]/2.
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  '''
  sky_data = SkyCoord(coo1, unit='deg', frame=FK5, equinox='J2000.0')
  gal = sky_data.transform_to(Galactic)
  coo1 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1)

  sky_data = SkyCoord(coo2, unit='deg', frame=FK5, equinox='J2000.0')
  gal = sky_data.transform_to(Galactic)
  coo2 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1)
  '''

  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound)
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      if flux is not None:
        f = flux[i]
      else:
        f = 1.
      weights = np.concatenate((weights,weight[mask]/f*50.), axis=0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound)
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      if flux is not None:
        f = flux[mask]
      else:
        f = np.ones(tmp_co.shape[0])
      weights = np.concatenate((weights,np.repeat(weight[i], tmp_co.shape[0])/f), axis=0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights)
  print H.shape

  t = np.percentile(H, 90)
  t = 1
  print 'threshold:{0}'.format(t) 
  #hp = H.copy()

  #plt.colorbar()
  '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
  #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  #print c_data
  if c_data is not None:
    #cy, cx, max_value, flux, x, y = c_data
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
    #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0]
    #print c_sex
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #if c_sex[0]>1:
  #  c_sex[0] = c_sex[0]-360.
  #print 'max:{0}'.format(max_value)
  #print cx,cy
  '''
  plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0)
  #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-bound/3, bound/3)
  plt.ylim(-bound/3, bound/3)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0],centroid[1],'+r', markersize=8)
  #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8)
  plt.show()
  #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx))
  #plt.clf()
  '''

  return centroid, max_value, flux
示例#27
0
        deads = np.array_split(dead, num_t)
        flat_hdu = pyfits.open('../data/cal/NUV_flat.fits')
        flat = flat_hdu[0].data
        size = flat_hdu[0].header['CDELT2']
        hrflat = scipy.ndimage.interpolation.zoom(flat,
                                                  size / 0.002,
                                                  order=1,
                                                  prefilter=False)

        hrflat = np.swapaxes(hrflat, 0, 1)

        skypos = [267.5, -26.0]
        skyrange = [25, 20]
        tranges = []
        trange = [0, 0]
        imsz = imagetools.deg2pix(skypos, skyrange, 0.002)
        wcs = imagetools.define_wcs(skypos,
                                    skyrange,
                                    width=False,
                                    height=False,
                                    verbose=0,
                                    pixsz=0.002)

        thread_list = []
        for i in range(num_t):
            thread = exp_dead(i, imsz, wcs, hrflat, asp_solutions[i], deads[i])
            thread.start()
            thread_list.append(thread)

        for t in thread_list:
            t.join()
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  bound = skyrange[0]
  co_rel = np.array([[0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

  t = np.percentile(H, 90)
  t = 1
  print 'threshold:{0}'.format(t) 
  hp = H.copy()

  #plt.colorbar()
  
  #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05)
  #plt.xlim(-0.005,0.005)
  #plt.ylim(-0.005,0.005)

  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  if c_data is not None:
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #print 'max:{0}'.format(max_value)
  print hp.shape

  #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0)
  plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8)
  #plt.show()
  plt.savefig('/home/dw1519/dw1519/galex/plots/co239_orignal/{0}.pdf'.format(idx))
  plt.clf()

  return centroid, max_value, flux
        cata = spi.load_obj('../data/%s_starset_extra_full' % name)
        cata_a = np.array(list(cata))
        cata_len = len(cata)
        cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

        count_list, imsz_list, wcs_list = [], [], []
        skypos_list, skyrange_list = [], []
        for i in range(cata_list.shape[0]):
            skypos, skyrange = ([cata_list[i, 1], cata_list[i,
                                                            2]], [0.03, 0.03])
            print skypos
            print skyrange
            skypos_list.append(skypos)
            skyrange_list.append(skyrange)
            imsz = imagetools.deg2pix(skypos, skyrange, 0.000416666666666667)
            count = np.zeros(imsz)
            wcs = imagetools.define_wcs(skypos,
                                        skyrange,
                                        width=False,
                                        height=False,
                                        verbose=0,
                                        pixsz=0.000416666666666667)
            count_list.append(count)
            wcs_list.append(wcs)
            imsz_list.append(imsz)

        step = 10
        tranges = []
        trange = [0, 0]
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, info_list, d3, outdir):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  #print(imsz)
  bound = skyrange[0]
  co_rel = np.array([[0,0]])
  infos = np.array([[0,0,0]])
  len1 = coo1.shape[0]
  len2 = coo2.shape[0]
  print(len1,len2)
  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
  #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
  if len2>len1:
    for i in range(len1):
      #print(i)
      tmp_co = coo2-coo1[i,:]
      mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound)
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      infos = np.concatenate((infos,info_list[mask]), axis=0)
  else:
    for i in range(len2):
      #print(i)
      tmp_co = coo2[i,:]-coo1
      tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:]
      tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:]
      co_rel = np.concatenate((co_rel, tmp_co), axis = 0)
      infos = np.concatenate((infos,np.repeat(info_list[i], tmp_co.shape[0])), axis=0)

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

  t = np.percentile(H, 90)
  t = 50
  print 'threshold:{0}'.format(t) 
  hp = H.copy()

  #plt.colorbar()
  
  #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05)
  #plt.xlim(-0.005,0.005)
  #plt.ylim(-0.005,0.005)

  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  if c_data is not None:
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #print 'max:{0}'.format(max_value)
  print hp.shape

  #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0)

  plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8)
  #plt.show()
  rot = np.mean(d3)/180.*np.pi

  l = np.linspace(0, 8., 5)
  x_y = np.sin(-rot)*l
  x_x = np.cos(-rot)*l
  y_y = np.sin(-rot+np.pi/2.)*l
  y_x = np.cos(-rot+np.pi/2.)*l

  plt.plot(x_x, x_y, '--g')
  plt.plot(y_x, y_y, '--g')


  co_rel = co_rel*3600
  mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2)
  num = np.sum(mask)
  plt.title('t={0}-{1}s, photons within d=5\" circle:{2}'.format(idx/2-50, idx/2, num))

  plt.savefig('{0}/{1}.pdf'.format(outdir,idx))
  plt.clf()
  np.save('{0}/{1}.npy'.format(outdir,idx), co_rel)

  plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-0.01*3600, 0.01*3600)
  plt.ylim(-0.01*3600, 0.01*3600)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8)
  #plt.show()
  rot = np.mean(d3)/180.*np.pi

  l = np.linspace(0, 8., 5)
  x_y = np.sin(-rot)*l
  x_x = np.cos(-rot)*l
  y_y = np.sin(-rot+np.pi/2.)*l
  y_x = np.cos(-rot+np.pi/2.)*l

  plt.plot(x_x, x_y, '--g')
  plt.plot(y_x, y_y, '--g')

  mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2)
  num = np.sum(mask)
  plt.title('t={0}-{1}s'.format(idx/2-50, idx/2))

  plt.savefig('{0}/zoom_{1}.pdf'.format(outdir,idx))
  plt.clf()

  '''
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,0], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('xa')
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/xa_{0}.png'.format(idx))
  plt.clf()
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,1], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('ya')
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/ya_{0}.png'.format(idx))
  plt.clf()
  plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,2], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face')
  cb1 = plt.colorbar()
  cb1.set_label('q')  
  plt.xlim(-0.02*3600, 0.02*3600)
  plt.ylim(-0.02*3600, 0.02*3600)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/q_{0}.png'.format(idx), dpi=190)
  plt.clf()
  '''

  '''
  n, bins, patches = plt.hist(infos[1:,1], 30, normed=1, facecolor='green', alpha=0.5)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_{0}.pdf'.format(idx), dpi=190)
  plt.clf()

  mask = (co_rel[:,0]<-25) & (co_rel[:,0]>-45) & (co_rel[:,1]>42) & (co_rel[:,1]<66)
  n, bins, patches = plt.hist(infos[mask,1], 30, normed=1, facecolor='green', alpha=0.5)
  plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_gh_{0}.pdf'.format(idx), dpi=190)
  plt.clf()
  '''

  return centroid, max_value, flux
示例#31
0
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix):
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    count = np.zeros(imsz)
    #print(imsz)
    bound = skyrange[0]
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)

    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))

    t = np.percentile(H, 90)
    t = 1
    print 'threshold:{0}'.format(t)
    hp = H.copy()

    #plt.colorbar()
    '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
    #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    c_data = c3.find_centroid(data, t)
    if c_data is not None:
        cy, cx, max_value, flux = c_data
        cy += 0.5
        cx += 0.5
        centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0]
    else:
        centroid = [0., 0.]
        max_value = 0
        flux = 500
    if centroid[0] > 1:
        centroid[0] = centroid[0] - 360.
    #print 'max:{0}'.format(max_value)
    print hp.shape

    return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix,
                 weight):
    imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
    count = np.zeros(imsz)
    #print(imsz)
    weights = np.array([])
    bound = skyrange[0]
    co_rel = np.array([[0, 0]])
    len1 = coo1.shape[0]
    len2 = coo2.shape[0]
    print(len1, len2)
    wcs = imagetools.define_wcs(skypos,
                                skyrange,
                                width=False,
                                height=False,
                                verbose=0,
                                pixsz=pixsz)
    #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile:
    #writer = csv.writer(csvfile)
    sky_data = SkyCoord(coo1, unit='deg', frame=FK5, equinox='J2000.0')
    gal = sky_data.transform_to(Galactic)
    coo1 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T),
                          axis=1)

    sky_data = SkyCoord(coo2, unit='deg', frame=FK5, equinox='J2000.0')
    gal = sky_data.transform_to(Galactic)
    coo2 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T),
                          axis=1)

    if len2 > len1:
        for i in range(len1):
            #print(i)
            tmp_co = coo2 - coo1[i, :]
            mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute(
                tmp_co[:, 1]) <= bound)
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            weights = np.concatenate((weights, weight[mask]), axis=0)
    else:
        for i in range(len2):
            #print(i)
            tmp_co = coo2[i, :] - coo1
            mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute(
                tmp_co[:, 1]) <= bound)
            tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :]
            tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :]
            co_rel = np.concatenate((co_rel, tmp_co), axis=0)
            weights = np.concatenate(
                (weights, np.repeat(weight[i], tmp_co.shape[0])), axis=0)

    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1)
    H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                               bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))#, weights=weights)

    t = np.percentile(H, 90)
    t = 1
    print 'threshold:{0}'.format(t)
    hp = H.copy()

    #plt.colorbar()
    '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
    #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
    data = H.byteswap(True).newbyteorder()
    data = data.copy(order='C')
    data = data.byteswap(True).newbyteorder()
    c_data = c3.find_centroid(data, t)
    #print c_data
    if c_data is not None:
        #cy, cx, max_value, flux, x, y = c_data
        cy, cx, max_value, flux = c_data
        cy += 0.5
        cx += 0.5
        centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0]
        #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0]
        #print c_sex
    else:
        centroid = [0., 0.]
        max_value = 0
        flux = 500
    if centroid[0] > 1:
        centroid[0] = centroid[0] - 360.
    #if c_sex[0]>1:
    #  c_sex[0] = c_sex[0]-360.
    #print 'max:{0}'.format(max_value)
    '''
  plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', vmin=0)
  #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-0.01*3600/2, 0.01*3600/2)
  plt.ylim(-0.01*3600/2, 0.01*3600/2)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8)
  plt.plot(c_sex[0]*3600,c_sex[1]*3600,'+g', markersize=8)
  plt.show()
  #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx))
  #plt.clf()
  '''

    return centroid, max_value, flux
def get_corr_map(pid, coo1, coo2, skypos, skyrange, pixsz, time, suffix, weight, flux=None):
  imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
  count = np.zeros(imsz)
  bound = skyrange[0]/2.

  wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)

  catalog = SkyCoord(coo1, unit='deg', frame='fk5', equinox='J2000.0')
  sky_data = SkyCoord(coo2, unit='deg', frame='fk5', equinox='J2000.0')
  print '{1}:catalog:{0}'.format(catalog.shape[0], pid)
  print '{1}:data:{0}'.format(sky_data.shape[0], pid)
  idxc, idxcatalog, d2d_p, d3d_p = sky_data.search_around_sky(catalog, 0.0045*u.deg)
  print '{1}:match:{0}'.format(idxc.shape[0], pid)

  if idxc.shape[0]<10:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
    return centroid, max_value, flux, idxc.shape[0]

  co_rel = coo2[idxcatalog] - coo1[idxc]
  if flux is not None:
    weights = weight[idxcatalog]/flux[idxc]*50.
  else:
    weights = weight[idxcatalog]

  foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel,1),1)
  H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights)

  t = np.percentile(H, 90)
  t = 1
  print '{1}:threshold:{0}'.format(t, pid) 
  #hp = H.copy()

  #plt.colorbar()
  '''
  plt.plot(co_rel[:,0],co_rel[:,1], '.k')
  plt.xlim(-0.02,0.02)
  plt.ylim(-0.02,0.02)
  '''
  #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx))
  data = H.byteswap(True).newbyteorder()
  data = data.copy(order='C')
  data = data.byteswap(True).newbyteorder()
  c_data = c3.find_centroid(data, t)
  #print c_data
  if c_data is not None:
    #cy, cx, max_value, flux, x, y = c_data
    cy, cx, max_value, flux = c_data
    cy+=0.5
    cx+=0.5
    centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0]
    #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0]
    #print c_sex
  else:
    centroid = [0.,0.]
    max_value = 0
    flux = 500
  if centroid[0]>1:
    centroid[0] = centroid[0]-360.
  #if c_sex[0]>1:
  #  c_sex[0] = c_sex[0]-360.
  #print 'max:{0}'.format(max_value)
  #print cx,cy
  '''
  plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0)
  #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp)))  
  plt.colorbar()
  plt.xlim(-bound/3, bound/3)
  plt.ylim(-bound/3, bound/3)
  plt.ylabel('gb')
  plt.xlabel('gl')
  plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1)
  plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1)
  plt.plot(centroid[0],centroid[1],'+r', markersize=8)
  #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8)
  plt.show()
  #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx))
  #plt.clf()
  '''
  return centroid, max_value, flux, idxc.shape[0]
def run_one_r_sec(pid, scan_name, step, resolution, asp_cal, start, end, dis_map, return_dict):

    print('run one r sec')

    num_co = int(resolution/step)
    
    #load asp file
    hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name)
    co_data = hdulist[1].data
    length = co_data.shape[0]

    '''
    try:
      asp_cal = np.load('../data/photon_list/%s_asp_new.npy'%scan_name)
    except IOError:
      T = co_data['T']
      ra = co_data['ra']
      dec = co_data['dec']
      roll = co_data['roll']
      t_new = np.arange((T.shape[0]-1)*200)*0.005+T[0]
      ra_new = np.interp(t_new, T, ra)
      dec_new = np.interp(t_new, T, dec)
      roll_new = np.interp(t_new, T, roll)
      asp_cal = np.array([t_new, ra_new, dec_new, roll_new]).T
      np.save('../data/photon_list/%s_asp_new.npy'%scan_name, asp_cal)
    '''

    #cal_initial = int((co_data[1][0]-0.5)*1000)
    #offsets = np.load('../data/%s/cata/offsets_inter_half_sec.npy'%scan_name)

    angle_list = [0.]

    print length
    data1 = []
    data2 = []
    data3 = []
    start = 700
    c_list = []
    for start in range(701, 1500, 50):
      print start
      data1 = []
      data2 = []
      data3 = []
      for initial_sec in range(start, start+50):
        print 'time:%d'%initial_sec
        file_path = '../data/%s/cata/centroids_rot%d.npy'%(scan_name, initial_sec)

        intitial_asp = co_data[initial_sec]
        rot = intitial_asp[3]
        #center = np.array([intitial_asp[1], intitial_asp[2]])
        #use the first order calibrated asp instead of the original one
        #center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) 
        #print(intitial_asp)

        skypos = [0.0, 0.0]
        skyrange = [0.02, 0.02]
        if step == 1:
          skyrange = [0.04, 0.04]#[0.3, 0.3]
        elif step == 0.5:
          skyrange = [0.02, 0.02]

        initial_time = intitial_asp[0]-step/2.

        tranges = []

        for sec in range(num_co):
          tranges.append([initial_time+step*sec, initial_time+step*(sec+1)])
        print tranges
        time_c = np.mean(tranges, axis=1)
        print 'center time:'
        print time_c

        #data = get_data_cal(tranges, scan_name, cal_initial, offsets)
        data = get_data(tranges, scan_name)
        print 'number of the photons:'
        print len(data)

        centroids = []
        center_time = []
        for sec in range(num_co):
          center_time.append(time_c[sec])
          if len(data[sec]) == 0:
            centroid = np.array([0.0, 0.0, 0.0])
            centroids.append(centroid)
            print centroid
            continue
          arg = np.argmin(np.absolute(asp_cal[:,0]-time_c[sec]))
          center = asp_cal[arg, 1:3]

          data_sec = dis_correct(np.array(data[sec], dtype='float64'), dis_map, asp_cal)
          coo1 = np.array(data_sec, dtype='float64')
          aperture = 0.69
          #coo1 = np.array(data[sec], dtype='float64')[:,-3:-1]
          #coo2 = catalog_fits.get_catalog_tycho(center, aperture)
          coo2 = catalog_fits.get_catalog(center, aperture)

          #coo1 = angle_filter(coo1, center, 0.6)
          #coo2 = angle_filter(coo2, center, 0.6)

          '''
          fig = plt.gcf()
          fig.set_size_inches(8,8)
          plt.plot(coo1[:,0], coo1[:,1], '.k', markersize=0.1)
          plt.plot(coo3[:,0], coo3[:,1], '+r', markersize=12)
          plt.plot(coo2[:,0], coo2[:,1], '+b', markersize=8)
          #plt.show()
          plt.ylabel('Dec')
          plt.xlabel('RA')
          plt.xlim(center[0]-0.65, center[0]+0.65)
          plt.ylim(center[1]-0.65, center[1]+0.65)
          plt.tight_layout()
          plt.savefig('/home/dw1519/galex/plots/photons.png', dpi=190)
          plt.clf()
          plt.close()
          '''
          '''
          #plot field
          #plt.plot(asp_cal[:,1],'.b')
          #plt.show()
          print center
          print coo1.shape
          print np.min(coo1[:,0]), np.max(coo1[:,0])
          print np.min(coo1[:,1]), np.max(coo1[:,1])
          wcs = imagetools.define_wcs(center,[1.5,1.5],width=False,height=False,verbose=0,pixsz=0.002)
          imsz = imagetools.deg2pix(center, [1.5,1.5], 0.002)
          foc = wcs.sip_pix2foc(wcs.wcs_world2pix(coo1,1),1)
          H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
                                     bins=imsz, range=([ [0,imsz[0]],[0,imsz[1
	if False:
		for i in range(100, 2900, 400):
			data_list=[]
			data_list1=[]
			for j in range(4):
				out = '/home/dw1519/dw1519/galex/plots/co239-10'
				data = np.load('{0}/{1}.npy'.format(out,i))/3600.
				data1 = np.load('{0}/ya/{1}.npy'.format(out,i))/3600.
				data_list.append(data)
				data_list1.append(data1)
				#info = np.load('/home/dw1519/dw1519/galex/plots/co32-10/info_{0}.npy'.format(i))
				#mask = info[:,1]>=2
			skypos = [0,0]
			skyrange = [0.02,0.02]
			pixsz = 0.0004
			imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int)
			wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz)
			foc = wcs.sip_pix2foc(wcs.wcs_world2pix(data[1:],1),1)
			H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
			                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
			#p = radial_profile(H, [99.5,99.5])
			p = radial_profile(H, [24.5,24.5])

			foc = wcs.sip_pix2foc(wcs.wcs_world2pix(data1[1:],1),1)
			H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\
			                             bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))
			#p1 = radial_profile(H, [99.5,99.5])
			p1 = radial_profile(H, [24.5,24.5])
			x = np.arange(p.shape[0])*0.0004*3600
			p1 = p1/np.sum(p1[:15])
			p = p/np.sum(p[:15])