Commit dd2e9a8c authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Make sourcename non-optional

parent 407e44f6
...@@ -21,7 +21,7 @@ try: ...@@ -21,7 +21,7 @@ try:
except: except:
print("Could not connect to console, no RA/DEC recorded") print("Could not connect to console, no RA/DEC recorded")
def create_filterbank(outfile, infile=None, date=None, source=None, create=False): def create_filterbank(outfile, source, infile=None, date=None, create=False):
""" """
Create a filterbank file from the CAMRAS-format, which is generated Create a filterbank file from the CAMRAS-format, which is generated
by pulsar_record. by pulsar_record.
...@@ -33,14 +33,7 @@ def create_filterbank(outfile, infile=None, date=None, source=None, create=False ...@@ -33,14 +33,7 @@ def create_filterbank(outfile, infile=None, date=None, source=None, create=False
source: name of the source to be used; default is guessed from filename source: name of the source to be used; default is guessed from filename
""" """
if not source: source = "PSR " + source
if not infile:
raise RuntimeError("If no input file is given, you must specify source")
match = re.match("[BJ][0-9]*[+-][0-9]*", infile)
if match:
source = "PSR " + match.group(0)
else:
raise ValueError("Could not guess source name from filename")
if not date: if not date:
if infile: if infile:
...@@ -134,9 +127,9 @@ def create_filterbank(outfile, infile=None, date=None, source=None, create=False ...@@ -134,9 +127,9 @@ def create_filterbank(outfile, infile=None, date=None, source=None, create=False
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert a camras pulsar file (output of pulsar_record) to filterbank format") 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("outfile", help="Name of output file, e.g. 'B0329.fil'")
parser.add_argument("sourcename", help="Name of the source, e.g. 'B0329+54'")
parser.add_argument("-i", "--infile", help="Input CAMRAS pulsar file. If empty, create just the header.") parser.add_argument("-i", "--infile", help="Input CAMRAS pulsar file. If empty, create just the header.")
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("-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") parser.add_argument("-c", "--create", help="Create new observation by calling pulsar_filterbank", default=False, action="store_true")
args = parser.parse_args() args = parser.parse_args()
...@@ -146,4 +139,4 @@ if __name__ == "__main__": ...@@ -146,4 +139,4 @@ if __name__ == "__main__":
if args.infile is None and args.source is None: if args.infile is None and args.source is None:
parser.error("Without infile, --source must be specified") parser.error("Without infile, --source must be specified")
create_filterbank(args.outfile, infile=args.infile, date=args.date, source=args.source, create=args.create) create_filterbank(args.outfile, args.sourcename, infile=args.infile, date=args.date, 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