Commit b8207fbf authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema

Add progress bar (tqdm)

parent fb7a6678
......@@ -22,7 +22,7 @@ try:
except:
print("Could not connect to console, no RA/DEC recorded")
def create_filterbank(source, infile=None, outfile=None, date=None, headeronly=False, centerfrequency=420., duration=30):
def create_filterbank(source, infile=None, outfile=None, date=None, headeronly=False, centerfrequency=420., duration=30, showprogressbar=False):
"""
Create a filterbank file from the CAMRAS-format, which is generated
by pulsar_record.
......@@ -52,6 +52,7 @@ def create_filterbank(source, infile=None, outfile=None, date=None, headeronly=F
date = Time(os.path.getctime(infile), format='unix')
else:
date = Time.now()
print("Waiting for a time multiple of 10 seconds...")
while date.datetime.second % 10 != 0:
date = Time.now()
else:
......@@ -104,10 +105,26 @@ def create_filterbank(source, infile=None, outfile=None, date=None, headeronly=F
if not infile:
out.close()
cmd = "/home/dijkema/pulsar/pulsar_filterbank " + str(duration) + " " + outfile
cmd = "sleep "+str(duration)
#cmd = "sleep "+str(duration)
print("Running "+cmd)
#subprocess.Popen(cmd.split())
os.system(cmd)
measure_process = subprocess.Popen(cmd.split())
if showprogressbar:
from tqdm import tqdm
import time
time.sleep(1) # Give measure process time to print something on the screen
with tqdm(total=duration) as pbar:
for time_chunk in range(duration):
pbar.update(1)
if measure_process.poll() is not None:
break
time.sleep(1)
measure_process.wait()
if measure_process.returncode != 0:
raise RuntimeError("Measure process exited abnormally")
print("\a")
return
......@@ -145,8 +162,8 @@ if __name__ == "__main__":
parser.add_argument("-d", "--date", help="Start date/time of observation, in 'isot' format (defaults to now, or creation date of infile)", default=None)
parser.add_argument("--header", help="Only record a header", default=False, action="store_true")
parser.add_argument("-f", "--frequency", help="Center frequency in MHz, default: 420.", default=420., type=float)
parser.add_argument("-t", "--time", help="Duration for observing in seconds, default: 300s (5min)", default=300)
parser.add_argument("-t", "--time", help="Duration for observing in seconds, default: 300s (5min)", default=300, type=int)
args = parser.parse_args()
create_filterbank(args.sourcename, infile=args.infile, outfile=args.outfile, date=args.date, headeronly=args.header, centerfrequency=args.frequency, duration=args.time)
create_filterbank(args.sourcename, infile=args.infile, outfile=args.outfile, date=args.date, headeronly=args.header, centerfrequency=args.frequency, duration=args.time, showprogressbar=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment