Advertisement
Guest User

RFI Signals

a guest
Jul 20th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. #Takes a UV object and injects randomly distributed RFI signals into the data array of object
  2.  
  3. #applyRFI should take in a dict with keys narrowband,scatter,burst
  4. #scatter: mu,sigma, max_times, max_freq, points
  5. #narrowband: mu, sigma, times, freq
  6. #burst: mu, sigma, ???
  7.  
  8. RFIdict = {
  9.  
  10. 'narrowband' : {
  11.  
  12. 'mu' : 1e6,
  13. 'sigma' : 1e9,
  14. 'freq' : 900,
  15. 'max_times' : 60
  16.  
  17. },
  18. 'scatter' : {
  19.  
  20. 'mu' : 1e6,
  21. 'sigma' : 1e9,
  22. 'max_times' : 60,
  23. 'max_freqs' : 1024,
  24. 'points' : 30
  25.  
  26. },
  27. 'burst' : {
  28.  
  29. 'mu' : 1e6,
  30. 'sigma' : 1e9,
  31. 'freq' : 500,
  32. 'max_times' : 30
  33.  
  34. }
  35. }
  36.  
  37.  
  38. def scatterRFI(baseline_data, RFIdict):
  39.  
  40. max_times = RFIdict.get('scatter').get('max_times')
  41. max_freq = RFIdict.get('scatter').get('max_freqs')
  42. mu = RFIdict.get('scatter').get('mu')
  43. sigma = RFIdict.get('scatter').get('sigma')
  44. points = RFIdict.get('scatter').get('points')
  45.  
  46. #Defines range of baseline timestamps an frequencies
  47. times = np.random.randint(0,max_times,size=points)
  48. freq = np.random.randint(0,max_freq,size=points)
  49.  
  50. #Loops for each point to be adjusted
  51. #print times
  52. for i in range(points):
  53.  
  54. #Increasing randomly distributed RFI signals
  55. baseline_data[times[i],freq[i]] += np.random.normal(loc=mu,scale=sigma)
  56.  
  57. return baseline_data
  58.  
  59. def narrowbandRFI(baseline_data, RFIdict):
  60.  
  61. #get freq of narrowband signal
  62. freq = RFIdict.get('narrowband').get('freq')
  63. max_times = RFIdict.get('narrowband').get('max_times')
  64. mu = RFIdict.get('narrowband').get('mu')
  65. sigma = RFIdict.get('narrowband').get('sigma')
  66.  
  67. #iterate through ALL times and apply narrowband RFI to baseline
  68. for i in range(max_times):
  69.  
  70. #Increasing randomly distributed RFI signals
  71. baseline_data[i,freq] += np.random.normal(loc=mu,scale=sigma)
  72.  
  73. return baseline_data
  74.  
  75. def burstRFI(baseline_data, RFIdict):
  76.  
  77. freq = RFIdict.get('burst').get('freq')
  78. max_times = RFIdict.get('burst').get('max_times')
  79. mu = RFIdict.get('burst').get('mu')
  80. sigma = RFIdict.get('burst').get('sigma')
  81. times = np.random.randint(0,max_times)
  82. time_offset = np.random.randint(0,max_times)
  83. max_taper = (times/2) if (times >= 2) else (1)
  84. taper_length = np.random.randint(0,max_taper)
  85. center_strength = np.random.randint(1e0,1e2)
  86.  
  87. #iterate through ALL times and apply burst RFI to baseline
  88. for i in range(times):
  89. if(i < taper_length):
  90.  
  91. baseline_data[i + time_offset,freq] = (center_strength * ((i+1) / float(taper_length +1)))
  92. #print (i+1), (taper_length), baseline_data[i + time_offset,freq]
  93. #print center_strength, (i+1), (taper_length+1), (center_strength * ((i+1) / (taper_length+1)))
  94. elif(times - i <= taper_length):
  95. baseline_data[i + time_offset,freq] = (center_strength * ((times - i+1) / float(taper_length+1)))
  96. else:
  97. baseline_data[i + time_offset,freq] = center_strength
  98.  
  99. return baseline_data
  100.  
  101. def applyRFI(uv_object, RFIdict):
  102.  
  103. #Looping through all antenna pairs
  104. for cur_pair in uv_object.get_antpairs():
  105. #Getting baseline data for antenna pair
  106. baseline_data = uv_object.get_data(cur_pair, force_copy = 'true')
  107. #Zero
  108. baseline_data = np.zeros_like(baseline_data)
  109.  
  110. if RFIdict.has_key('scatter'):
  111. baseline_data = scatterRFI(baseline_data, RFIdict)
  112.  
  113. if RFIdict.has_key('narrowband'):
  114. baseline_data = narrowbandRFI(baseline_data, RFIdict)
  115.  
  116. if RFIdict.has_key('burst'):
  117. baseline_data = burstRFI(baseline_data, RFIdict)
  118.  
  119. antpair_indices = uv_object.antpair2ind(cur_pair[0],cur_pair[1])
  120. uv_object.data_array[antpair_indices,0,:,0] = copy.copy(baseline_data)
  121.  
  122. return uv_object
  123.  
  124. new_RFI1 = applyRFI(UV1, RFIdict)
  125.  
  126. #new_RFI1.write_miriad('RFIrandom20')
  127.  
  128. plt.figure(figsize=(20,20))
  129. plt.imshow(
  130. np.abs(
  131. new_RFI1.data_array[np.where(
  132. new_RFI1.baseline_array == new_RFI1.antnums_to_baseline(0,2)
  133. ),0,:,0][0]), aspect='auto', norm = matplotlib.colors.LogNorm(1e0,1e2))
  134. plt.colorbar()
  135. plt.xlabel('Frequency')
  136. plt.ylabel('Time (Integrations)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement