Revert "CygnusRFI.py py 2to3"

This reverts commit 9205acf142.
spacecruft
Jeff Moe 2023-01-17 09:07:30 -07:00
parent 9205acf142
commit 04ab43b1be
1 changed files with 98 additions and 57 deletions

View File

@ -1,57 +1,98 @@
--- CygnusRFI.py.orig (original) #!/usr/bin/env python
+++ CygnusRFI.py.orig (refactored) import os
@@ -51,20 +51,20 @@ import sys
sleep(0.5) import argparse
print('\n\033[1;33;48m\033[4;33;48mRFI Measurement Parameters:\033[0;32;48m') from time import sleep
sleep(0.15)
-print('\033[1;32;48mFrequency range to scan: \033[1;36;48m'+str(float(fmin)/1000000)+'-'+str(float(fmax)/1000000)+' MHz') # Define argparse arguments
+print(('\033[1;32;48mFrequency range to scan: \033[1;36;48m'+str(float(fmin)/1000000)+'-'+str(float(fmax)/1000000)+' MHz')) parser = argparse.ArgumentParser()
sleep(0.15)
-print('\033[1;32;48mBandwidth per spectrum: \033[1;36;48m'+str(float(bandwidth)/1000000)+' MHz') parser.add_argument("-b", "--bandwidth", type=str, required=True)
+print(('\033[1;32;48mBandwidth per spectrum: \033[1;36;48m'+str(float(bandwidth)/1000000)+' MHz')) parser.add_argument("-c", "--channels", type=str, default=1024)
sleep(0.15) parser.add_argument("-t", "--t_int", type=str, default=0.1)
-print('\033[1;32;48mIntegration time per spectrum: \033[1;36;48m'+duration+' sec') parser.add_argument("-d", "--duration", type=str, required=True)
+print(('\033[1;32;48mIntegration time per spectrum: \033[1;36;48m'+duration+' sec')) parser.add_argument("-f", "--fmin", type=float, required=True)
sleep(0.15) parser.add_argument("-F", "--fmax", type=float, required=True)
-print('\033[1;32;48mNumber of channels per spectrum (FFT Size should be a power of 2): \033[1;36;48m'+str(channels))
+print(('\033[1;32;48mNumber of channels per spectrum (FFT Size should be a power of 2): \033[1;36;48m'+str(channels))) args = parser.parse_args()
sleep(0.15)
-print('\033[1;32;48mIntegration time per FFT sample: \033[1;36;48m'+t_int+' sec') bandwidth=args.bandwidth
+print(('\033[1;32;48mIntegration time per FFT sample: \033[1;36;48m'+t_int+' sec')) channels=args.channels
sleep(0.5) t_int=args.t_int
-print("\n\033[1;32;48mEstimated completion time: \033[1;36;48m"+str(float(duration)*float(fmax-fmin)/float(bandwidth))+" sec") duration=args.duration
+print(("\n\033[1;32;48mEstimated completion time: \033[1;36;48m"+str(float(duration)*float(fmax-fmin)/float(bandwidth))+" sec")) fmin=args.fmin
fmax=args.fmax
sleep(0.5)
-proceed = input("\n\033[1;36;48mProceed to measurement? [Y/n]: \033[1;33;48m") #Define GRC observation parameters
+proceed = eval(input("\n\033[1;36;48mProceed to measurement? [Y/n]: \033[1;33;48m")) bandwidth = str(bandwidth)
channels = str(channels)
if proceed.lower() != 'n' and proceed.lower() != 'no': t_int = str(t_int)
print('\n\033[1;33;48m+=================================================================+') duration = str(duration)
@@ -73,7 +73,7 @@ fmin = float(fmin)
fmax = float(fmax)
q=0
for freq in range(int(fmin), int(fmax), int(float(bandwidth))): nbins = str(int(float(t_int) * float(bandwidth)/float(channels)))
- print("\033[1;33;48m\n---------------------------------------------------------------------------\n \033[1;33;48m[*] \033[1;32;48mCurrently monitoring f_center = "+str(0.000001*freq)+" +/- "+str(float(float(bandwidth)*0.000001)/2)+" MHz (iteration: "+str(q)+")...\n\033[1;33;48m---------------------------------------------------------------------------")
+ print(("\033[1;33;48m\n---------------------------------------------------------------------------\n \033[1;33;48m[*] \033[1;32;48mCurrently monitoring f_center = "+str(0.000001*freq)+" +/- "+str(float(float(bandwidth)*0.000001)/2)+" MHz (iteration: "+str(q)+")...\n\033[1;33;48m---------------------------------------------------------------------------")) #Delete pre-existing observation.dat file
for file_name in os.listdir('.'):
#Define observation frequency if file_name.endswith('.dat'):
f_center = str(freq) try:
@@ -81,7 +81,7 @@ os.remove(file_name)
#Execute top_block.py with parameters except OSError:
print('\033[0m') pass
sys.argv = ['top_block.py', '--c-freq='+f_center, '--samp-rate='+bandwidth, '--nchan='+channels, '--nbin='+nbins, '--obs-time='+duration] try:
- execfile('top_block.py') os.remove('rfi_plot.png')
+ exec(compile(open('top_block.py', "rb").read(), 'top_block.py', 'exec')) except OSError:
os.rename('observation.dat', str(q)+'.dat') pass
q = q+1 print('\n\033[1;33;48m+=================================================================+')
@@ -91,7 +91,7 @@ print('\033[1;33;48m| \033[1;36;48mCygnusRFI\033[1;33;48m:\033[1;32;48m An open-source Radio Frequency Interference analyzer\033[1;33;48m |')
print('\033[1;33;48m+=================================================================+')
f_center = str(fmin) sleep(0.5)
sys.argv = ['rfi_plotter.py', 'freq='+f_center, 'samp_rate='+bandwidth, 'nchan='+channels, 'nbin='+nbins, 'n='+str(q), 'dur='+duration, 'fminimum='+str(fmin), 'fmaximum='+str(fmax)] print('\n\033[1;33;48m\033[4;33;48mRFI Measurement Parameters:\033[0;32;48m')
- execfile('rfi_plotter.py') sleep(0.15)
+ exec(compile(open('rfi_plotter.py', "rb").read(), 'rfi_plotter.py', 'exec')) print('\033[1;32;48mFrequency range to scan: \033[1;36;48m'+str(float(fmin)/1000000)+'-'+str(float(fmax)/1000000)+' MHz')
sleep(0.15)
print('\033[1;32;48mYour data has been saved as \033[1;36;48mrfi_plot.png\033[1;32;48m.') print('\033[1;32;48mBandwidth per spectrum: \033[1;36;48m'+str(float(bandwidth)/1000000)+' MHz')
else: sleep(0.15)
print('\033[1;32;48mIntegration time per spectrum: \033[1;36;48m'+duration+' sec')
sleep(0.15)
print('\033[1;32;48mNumber of channels per spectrum (FFT Size should be a power of 2): \033[1;36;48m'+str(channels))
sleep(0.15)
print('\033[1;32;48mIntegration time per FFT sample: \033[1;36;48m'+t_int+' sec')
sleep(0.5)
print("\n\033[1;32;48mEstimated completion time: \033[1;36;48m"+str(float(duration)*float(fmax-fmin)/float(bandwidth))+" sec")
sleep(0.5)
proceed = input("\n\033[1;36;48mProceed to measurement? [Y/n]: \033[1;33;48m")
if proceed.lower() != 'n' and proceed.lower() != 'no':
print('\n\033[1;33;48m+=================================================================+')
print('\033[1;33;48m| [+] \033[1;32;48m Starting measurement...\033[1;33;48m |')
print('\033[1;33;48m+=================================================================+\n')
q=0
for freq in range(int(fmin), int(fmax), int(float(bandwidth))):
print("\033[1;33;48m\n---------------------------------------------------------------------------\n \033[1;33;48m[*] \033[1;32;48mCurrently monitoring f_center = "+str(0.000001*freq)+" +/- "+str(float(float(bandwidth)*0.000001)/2)+" MHz (iteration: "+str(q)+")...\n\033[1;33;48m---------------------------------------------------------------------------")
#Define observation frequency
f_center = str(freq)
#Execute top_block.py with parameters
print('\033[0m')
sys.argv = ['top_block.py', '--c-freq='+f_center, '--samp-rate='+bandwidth, '--nchan='+channels, '--nbin='+nbins, '--obs-time='+duration]
execfile('top_block.py')
os.rename('observation.dat', str(q)+'.dat')
q = q+1
print('\n\033[1;33;48m+=================================================================+')
print('\033[1;33;48m| \033[1;32;48mMeasurement finished!\033[1;33;48m |')
print('\033[1;33;48m+=================================================================+\n')
f_center = str(fmin)
sys.argv = ['rfi_plotter.py', 'freq='+f_center, 'samp_rate='+bandwidth, 'nchan='+channels, 'nbin='+nbins, 'n='+str(q), 'dur='+duration, 'fminimum='+str(fmin), 'fmaximum='+str(fmax)]
execfile('rfi_plotter.py')
print('\033[1;32;48mYour data has been saved as \033[1;36;48mrfi_plot.png\033[1;32;48m.')
else:
print('\n\033[1;31;48m[!] Exiting...\n')