Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2. if True:
  3. import matplotlib
  4. matplotlib.use('Agg')
  5.  
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. import argparse
  9. from matplotlib.gridspec import GridSpec
  10.  
  11. parser = argparse.ArgumentParser()
  12. parser.add_argument('freq')
  13. parser.add_argument('samp_rate')
  14. parser.add_argument('nchan')
  15. parser.add_argument('nbin')
  16. args = parser.parse_args()
  17.  
  18. def decibel(x):
  19. #return 10.0*np.log10(x)
  20. return x
  21.  
  22. def shift_col_up(chan_num,n_rows):
  23. z[:,chan_num] = np.roll(z[:,chan_num], -n_rows)
  24. print(1)
  25. if __name__ == "__main__":
  26. print(2)
  27. #Observation parameters
  28. exec(args.freq)
  29. exec(args.samp_rate)
  30. exec(args.nchan)
  31. exec(args.nbin)
  32. fname = "/home/pictor/Desktop/pictortelescope/sim_pulsar.dat"
  33.  
  34. #Load data
  35. z = np.fromfile(fname, dtype="float32").reshape(-1, nchan)/nbin
  36. #z = z*10000
  37. #z[z > 35000] = 30000
  38.  
  39. #Dedisperse
  40. nchan = z.shape[1]
  41. DM = 100 #2.96927 #pc/cm^3
  42. bandwidth_mhz = 16
  43. bandwidth = 16000000
  44. f_center=freq
  45. f_center_mhz=0.000001*f_center
  46. nbins=nbin
  47. deltaF = float(bandwidth_mhz)/nchan #bandwidth in MHz
  48. print(deltaF)
  49. f_max = f_center_mhz+(float(bandwidth_mhz)/2)
  50. f_max_mhz = f_max #*0.000001
  51. t_int = float(nbins*nchan)/bandwidth
  52. for chan_num in range(nchan):
  53. f_start = f_center_mhz-(float(bandwidth_mhz)/2)
  54. f_chan = f_start+(chan_num)*deltaF
  55. print(f_chan)
  56. deltaT = 4149*DM*((1/(f_chan**2))-(1/(f_max_mhz**2)))
  57. print('deltaT:',deltaT)
  58. print('f_chan:',f_chan)
  59. print('f_max_mhz:',f_max_mhz)
  60. n = int(round(float(100*deltaT)/t_int))
  61. print('n:',n)
  62. print('t_int:',t_int)
  63. shift_col_up(chan_num,n)
  64.  
  65. #Define numpy array for Power vs Time plot
  66. w = np.mean(a=z, axis=1)
  67.  
  68. #Number of sub-integrations
  69. nsub = z.shape[0]
  70.  
  71. #Compute average spectrum
  72. zmean = np.mean(z, axis=0)
  73.  
  74. #Compute time axis
  75. tint = float(nbin*nchan)/samp_rate
  76. t = tint*np.arange(nsub)
  77.  
  78. v = np.arange(0, np.max(t)+tint, tint)
  79.  
  80. #Compute frequency axis (convert to MHz)
  81. freq = np.linspace(freq-0.5*samp_rate, freq+0.5*samp_rate, nchan, endpoint=False)*1e-6
  82.  
  83. #Initialize plot
  84. fig = plt.figure(figsize=(25,20))
  85. gs = GridSpec(2,2)
  86.  
  87. #Plot average spectrum
  88. ax1 = fig.add_subplot(gs[0,0])
  89. ax1.plot(freq, decibel(zmean))
  90. ax1.set_xlim(np.min(freq), np.max(freq))
  91. ax1.ticklabel_format(useOffset=False)
  92. ax1.set_xlabel("Frequency (MHz)")
  93. ax1.set_ylabel("Relative Power")
  94. ax1.set_title("Averaged Spectrum")
  95.  
  96. #Plot dynamic spectrum
  97. ax2 = fig.add_subplot(gs[0,1])
  98. ax2.imshow(decibel(z), origin="lower", interpolation="None", aspect="auto",
  99. extent=[np.min(freq), np.max(freq), np.min(t), np.max(t)])
  100. ax2.ticklabel_format(useOffset=False)
  101. ax2.set_xlabel("Frequency (MHz)")
  102. ax2.set_ylabel("Time (s)")
  103. ax2.set_title("Dynamic Spectrum (Waterfall)")
  104.  
  105. #Plot Power vs Time
  106. ax3 = fig.add_subplot(gs[1,:])
  107. ax3.plot(v,w)
  108. ax3.set_xlim(0,np.max(t)+tint)
  109. ax3.set_xlabel("Time (s)")
  110. ax3.set_ylabel("Relative Power")
  111. ax3.set_title("Power vs Time")
  112.  
  113. plt.tight_layout()
  114. plt.savefig("/home/pictor/Desktop/pictortelescope/plot.png")
  115. else:
  116. print(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement