Commit 407e44f6 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema

Make outfile fixed argument, add call to pulsar_filterbank

parent 4ae7b89a
......@@ -21,24 +21,18 @@ try:
except:
print("Could not connect to console, no RA/DEC recorded")
def create_filterbank(infile=None, outfile=None, date=None, source=None):
def create_filterbank(outfile, infile=None, date=None, source=None, create=False):
"""
Create a filterbank file from the CAMRAS-format, which is generated
by pulsar_record.
outfile: name of the filterbank file to be created
infile: name of the file generated by pulsar_record
outfile: name of the filterbank file to be created; if not given, a name
will be created from the infile
date: the date to be used; default is the file creation date of infile
if given, the date must be in a format the astropy.time understands
source: name of the source to be used; default is guessed from filename
"""
if not outfile:
if not infile:
raise RuntimeError("Specify at least one of inputfile or outputfile")
outfile = re.split('[+-\.]', infile)[0] + ".fil"
if not source:
if not infile:
raise RuntimeError("If no input file is given, you must specify source")
......@@ -63,7 +57,6 @@ def create_filterbank(infile=None, outfile=None, date=None, source=None):
if telescope_found:
dt = telescope(consoleHost='console')
az_start = (180*u.deg + dt.getAzEl(waitForUpdate=True)[0]).to(u.deg).value
print(az_start)
za_start = (90*u.deg - dt.getAzEl()[1]).to(u.deg).value
src_raj = dt.getRaDec().ra.to_string(unit=u.hour, sep='')
src_dej = dt.getRaDec().dec.to_string(unit=u.degree, sep='')
......@@ -104,6 +97,10 @@ def create_filterbank(infile=None, outfile=None, date=None, source=None):
# Write header
out = filterbank.create_filterbank_file(outfile, fil_header, nbits=16)
if create:
os.system("./pulsar_filterbank 3600 "+outfile)
return
if not infile:
out.close()
return
......@@ -136,16 +133,17 @@ def create_filterbank(infile=None, outfile=None, date=None, source=None):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert a camras pulsar file (output of pulsar_record) to filterbank format")
parser.add_argument("outfile", help="Name of output file, e.g. 'B0329.fil'")
parser.add_argument("-i", "--infile", help="Input CAMRAS pulsar file. If empty, create just the header.")
parser.add_argument("-o", "--outfile", help="Name of output file, e.g. 'B0329.fil' (default: guessed from input filename)", default=None)
parser.add_argument("-d", "--date", help="Start date/time of observation, in 'isot' format (defaults to creation date of file, or now if no infile given)", default=None)
parser.add_argument("-s", "--source", help="Name of the source, e.g. 'PSR B0329+54' (default: guessed from input filename)", default=None)
parser.add_argument("-c", "--create", help="Create new observation by calling pulsar_filterbank", default=False, action="store_true")
args = parser.parse_args()
if args.infile is None and args.outfile is None:
parser.error("One of --infile or --outfile is required")
if args.infile is None and not(args.create):
parser.error("One of --infile or --create is required")
if args.infile is None and args.source is None:
parser.error("Without infile, --source must be specified")
create_filterbank(infile=args.infile, outfile=args.outfile, date=args.date, source=args.source)
create_filterbank(args.outfile, infile=args.infile, date=args.date, source=args.source, create=args.create)
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