Esempio n. 1
0
    'omega_lambda_0': 0.714,
    'omega_k_0': 0.0,
    'h': 0.696
}

VCV = pd.read_csv('VCV_z03.dat', sep='|', skiprows=4)
distance = []
RA_AGN = []
DEC_AGN = []
name = []
flux = []
j = 0
for i in range(len(VCV)):
    if VCV.values[i][2] > 0 and VCV.values[i][2] < .03:
        RA, DEC = np.rad2deg(
            astroconvert.gal2eq(np.deg2rad(VCV.values[i][4]),
                                np.deg2rad(VCV.values[i][5])))
        RA2 = float("{0:.2f}".format(float(RA)))
        DEC2 = float("{0:.2f}".format(float(DEC)))
        RA_AGN.append(RA2)
        DEC_AGN.append(DEC2)
        D = cd.comoving_distance(VCV.values[i][2], **cosmo)
        D2 = float("{0:.2f}".format(float(D)))
        distance.append(D2)
        name.append(VCV.values[i][1])
        flux.append(100.0)
        j += 1
sorted_index, sorted_d = zip(
    *sorted([(i, e) for i, e in enumerate(distance)], key=lambda x: x[1]))
RA_AGN_sorted = [RA_AGN[i] for i in sorted_index]
DEC_AGN_sorted = [DEC_AGN[i] for i in sorted_index]
distance_sorted = [distance[i] for i in sorted_index]
Esempio n. 2
0
    l_Obs=l_Obs[l_Obs!=0]
    b_Obs=Data[:,8]*((Data[:,2]>=E_min) & (Data[:,2]<E_max) & (Data[:,1]<theta_max_deg ) & (Data[:,1]>=theta_min_deg ))*1; 
    b_Obs=b_Obs[b_Obs!=0]

E_Obs=Data[:,2]*((Data[:,2]>=E_min) & (Data[:,2]<E_max) & (Data[:,1]<theta_max_deg ) & (Data[:,1]>=theta_min_deg ))*1; 
E_Obs=E_Obs[E_Obs!=0]
Zenith_Obs=Data[:,1]*((Data[:,2]>=E_min) & (Data[:,2]<E_max) & (Data[:,1]<theta_max_deg ) & (Data[:,1]>=theta_min_deg ))*1; 
Zenith_Obs=Zenith_Obs[Zenith_Obs!=0]

RA_Obs=np.zeros(l_Obs.size)
DEC_Obs=np.zeros(l_Obs.size)

for k in range(l_Obs.size):
    l=l_Obs[k]
    b=b_Obs[k]
    x2,y2=astroconvert.gal2eq(np.deg2rad(l),np.deg2rad(b))
    RA_Obs[k]=np.rad2deg(x2)
    DEC_Obs[k]=np.rad2deg(y2)
Zenith_Datos=Zenith_Obs
E_Datos=E_Obs
RA_Datos=RA_Obs
DEC_Datos=DEC_Obs
print DEC_Datos.size, "events with for E>=", E_min, "EeV and zenith <", theta_max_deg, "degree"
np.savetxt("Zenith_Datos", Zenith_Datos,fmt='%.2f')
np.savetxt("E_Datos", E_Datos,fmt='%.2f')    
np.savetxt("RA_Datos", RA_Datos,fmt='%.2f')
np.savetxt("DEC_Datos", DEC_Datos,fmt='%.2f')


##################### Plot events
Esempio n. 3
0
def makeplot(ra,dec,specid,where='',figtype='cart',ellipses='no',saveplot=''):
  """ Makes a plot of RA and DEC.

  where is a string specifying which data from mysql to grab. 
  ONLY include columns from table 'config'. do not include 
  the word 'where' at the beginning or the semicolon at the 
  end. all other common mysql syntax rules apply.

  figtype is the figure type. default is 'cart' for cartesian 
  coordinates. 'sky' plots the ra and dec as a Mollweide
  projection

  if ellipses='yes', the spectra are plotted as individual ellipses
  of fixed size corresponding to ALFA beam width (only for Cartesian
  coordinate axis)

  saveplot allows you to save the figure by specifying the 
  file name as a string. if left empty, the figure is not 
  saved.

  returns a figure"""

  import jd2gd, command

  #Determine values to include in figure
  var1 = min(specid)
  var2 = max(specid)
  var3 = len(specid)

  #Get time info from database
  cmd = command.generate('obstime','config',where=where)
  data = MySQLFunction.mysqlcommand(cmd)

  #Create list
  day = numpy.asarray([data[x][0] for x in xrange(len(data))])

  #Determine start and end dates
  start = min(day)
  end = max(day)
 
  #Create Gregorian date from obstime
  start = jd2gd.caldate(start)
  end = jd2gd.caldate(end)
  dates = ['January','February','March','April','May','June','July',
  'August','September','October','November','December']
  start = [str(start[x]) for x in range(len(start))]
  end = [str(end[x]) for x in range(len(end))]

  #Insert zeros to make formatting nice
  if float(start[2])<10:
    start[2] = '0' + start[2]
  if float(start[3])<10:
    start[3] = '0' + start[3]
  if float(start[4])<10:
    start[4] = '0' + start[4]
  if float(start[5])<10:
    start[5] = '0' + start[5]
  if float(end[2])<10:
    end[2] = '0' + end[2]
  if float(end[3])<10:
    end[3] = '0' + end[3]
  if float(end[4])<10:
    end[4] = '0' + end[4]
  if float(end[5])<10:
    end[5] = '0' + end[5]

  #Compile date strings
  date1 = start[0]+' '+dates[int(start[1])-1]+' '+start[2]+' '+start[3]+':'+start[4]+':'+start[5][:4]
  date2 = end[0]+' '+dates[int(end[1])-1]+' '+end[2]+' '+end[3]+':'+end[4]+':'+end[5][:4]

  #Which fig type?
  patches=[]
  if figtype=='cart':

    #Initialize figure
    fig=pylab.figure(figsize=(12,7))
    ax1 = fig.add_axes([0.1, 0.12, 0.85, 0.75])

    #Plot data
    if ellipses=='yes':
      for x,y in zip(ra,dec):
       circle=matplotlib.patches.Ellipse((x,y),width=.0038888,height=.058333,facecolor='b',edgecolor='b')
       patches.append(circle)
      p=matplotlib.collections.PatchCollection(patches)
      ax1.add_collection(p)
    else: ax1.scatter(ra,dec,s=.1,label='spectra')
   
  else:
    #Convert RA to degrees
    length = len(ra)
    ra = [ra[x]*15 for x in range(length)]
    
    #Convert arrays to radians
    ra = [math.radians(ra[x]) for x in range(length)]
    dec = [math.radians(dec[x]) for x in range(length)]

    #Adjust ra scale
    ra = [ra[x]-numpy.pi for x in range(length)]
    
    #Create figure
    fig = pylab.figure(figsize=(12,7))
    ax1 = fig.add_axes([.1,.12,.70,.85],projection='mollweide')
    
    #Plot data
    ax1.scatter(ra,dec,label='spectra',marker='+',c='b')
    
    #Set xtick labels
    ax1.set_xticklabels(['2','4','6','8','10','12','14','16','18','20','22'])

  #Create galactic plane lines
  #Create l,b arrays
  b = [math.radians(5)]*360 + [math.radians(-5)]*360
  l = list(numpy.linspace(0,2*numpy.pi,360))*2
  
  #Pass l,b pairs to gal2eq
  bounds = []
  for x in range(720):
    bounds.append(astroconvert.gal2eq(l[x],b[x]))

  #Separate into component arrays
  ra_bounds = [bounds[x][0] for x in range(720)]
  dec_bounds = [bounds[x][1] for x in range(720)]

  #Convert to deg if necessary, and plot
  if figtype=='sky':
    ra_bounds = [ra_bounds[x]-numpy.pi for x in range(720)]
    ax1.scatter(ra_bounds,dec_bounds,edgecolor='none',c='r',label='galactic plane')
  else:
    ra_bounds = [math.degrees(ra_bounds[x])/15 for x in range(720)]
    dec_bounds = [math.degrees(dec_bounds[x]) for x in range(720)]
    ax1.plot(ra_bounds,dec_bounds,'r',label='galactic plane')

    #Set axis limits
    ax1.set_xlim(0, 24)
    ax1.set_ylim(0, 40)

  #Set axis labels and title
  pylab.xlabel('RA (hours)')
  pylab.ylabel('Dec (degrees)')
  pylab.title('Right Ascension and Declination')

  #Add legend
  ax1.legend(bbox_to_anchor=(0,0,1,1),loc=0)

  #Add text to figure
  pylab.figtext(0.1,.97,'First Specid: %d' %var1)
  pylab.figtext(0.1,.945,'Last Specid: %d' %var2)
  pylab.figtext(0.1,.92,'Count: %d spectra' %var3)
  pylab.figtext(0.95,.97,' Start: %s' %date1, ha='right')
  pylab.figtext(0.95,.945,'End: %s' %date2, ha='right')

  #Include grid
  pylab.grid(True)
 
  #Save figure?
  if saveplot!='':
    pylab.savefig('%s'%saveplot)

  return fig
Esempio n. 4
0
if (Type != 'Desviacion_GAL'):
    cb = m.colorbar(im, "right", size="3%", pad='3%')
else:
    cb = m.colorbar(im, "right", size="3%", pad='6%')

#m.contour(XX,YY,Overlap_Datos_Gal)

#main_ax.set_title('Zenithal Acceptance between 55 and 80 deg')
main_ax.title.set_fontsize(15)
# PLANO G
phi_G = np.linspace(0, 2 * np.pi, num=400)
theta_G = np.linspace(0, 0, num=400)
x1 = np.zeros(theta_G.size)
y1 = np.zeros(theta_G.size)
for k in range(theta_G.size):
    x1[k], y1[k] = astroconvert.gal2eq(phi_G[k], theta_G[k])
    x1[k] = np.rad2deg(x1[k])
    y1[k] = np.rad2deg(y1[k])
x2 = np.sort(x1, axis=0)
sort_indices = np.argsort(x1, axis=0)
y2 = y1[sort_indices]
x3, y3 = m(x2, y2)
if (Type != 'Desviacion_GAL'):
    m.plot(x3, y3, color='w', linewidth=3.0, linestyle="--")

# PLANO SG
phi_SG = np.linspace(0, 360, num=400, endpoint=False)
theta_SG = np.linspace(0, 0, num=400, endpoint=False)
x1 = np.zeros(theta_SG.size)
y1 = np.zeros(theta_SG.size)
x2 = np.zeros(theta_SG.size)
Esempio n. 5
0
def allsky_plot(ra,dec,color='False',header='False',saveplot=''):
 """Plots a 2D histogram of pointing data,
 with a color scale giving the relative counts. One ra value
 and one dec value are supplied for each continuous pointing.

 Inputs:
 ra: array of RA values for pointings in db
 dec: array of DEC values for pointings in db
 color: whether or not to generate a color plot, default='False'
 header: whether or not to include header information, default='False'
 saveplot: string to specify name of plot
 
 Output is a figure"""

 #Perform histogramming
 x,y,data=histogram2d(ra,dec,dtype='Equatorial')

 #Create figure/axes
 fig = pylab.figure(figsize=(12,7))
 if header=='False':
  ax1 = fig.add_axes([.1,.12,.90,.85])
 else: ax1=fig.add_axes([.1,.12,.90,.75])

 #Add plot
 
 if color=='False':
  mesh=ax1.pcolormesh(x,y,data,cmap=pylab.get_cmap('gray_r'))
 elif color=='True':
  mesh=ax1.pcolormesh(x,y,data,cmap=pylab.get_cmap('spectral_r'))
 fig.colorbar(mesh)
 ax1.set_ylabel('Declination')
 ax1.set_xlabel('Right Ascension')
 pylab.grid(True)

 #Add galactic plane
  
 #Create l,b arrays
 b = [math.radians(5)]*360 + [math.radians(-5)]*360
 l = list(numpy.linspace(0,2*numpy.pi,360))*2
  
 #Pass l,b pairs to gal2eq
 bounds = []
 for x in range(720):
   bounds.append(astroconvert.gal2eq(l[x],b[x]))

 #Separate into component arrays
 ra_bounds = [bounds[x][0] for x in range(720)]
 dec_bounds = [bounds[x][1] for x in range(720)]

 #Convert to deg if necessary, and plot
 ra_bounds = [math.degrees(ra_bounds[x])/15 for x in range(720)]
 dec_bounds = [math.degrees(dec_bounds[x]) for x in range(720)]
 ax1.plot(ra_bounds,dec_bounds,'k--',label='galactic plane')
 ax1.legend(bbox_to_anchor=(0,0,1,1),loc=0) 

 #Fix axes
 ax1.set_xlim(min(ra),max(ra))
 ax1.set_ylim(min(dec),max(dec))

 #Add more info
 if header!='False':
  pylab.figtext(0.1,.95,'# Spectra: %d' %len(specid))
  pylab.figtext(0.1,.93,'Max Count: %d' %numpy.max(data))
 
 return fig