Skip to content

Commit

Permalink
Merge pull request #766 from DougBurke/xspec-initial-mdefine-support
Browse files Browse the repository at this point in the history
convert_xspec_script: initial support for MDEFINE
  • Loading branch information
DougBurke authored Jun 6, 2023
2 parents 97a17f0 + b938979 commit d49c0d0
Show file tree
Hide file tree
Showing 3 changed files with 2,071 additions and 881 deletions.
15 changes: 10 additions & 5 deletions bin/convert_xspec_script
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Copyright (C) 2020, 2021, 2023
# Smithsonian Astrophysical Observatory
# Smithsonian Astrophysical Observatory
#
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -27,6 +27,7 @@ Usage:
convert_xspec_script infile outfile
--models modname (can be repeated)
--clean
--clobber
--verbose n or -v n where n is 0, 1, 2, 3, 4, 5
Expand All @@ -52,7 +53,7 @@ from sherpa_contrib.xspec import xcm


TOOLNAME = "convert_xspec_script"
TOOLVER = "12 January 2023"
TOOLVER = "15 May 2023"

lw.initialize_logger(TOOLNAME, verbose=1)
V1 = lw.make_verbose_level(TOOLNAME, 1)
Expand All @@ -68,7 +69,7 @@ The conversion is not guaranteed to match XSPEC perfectly.

COPYRIGHT_STR = """
Copyright (C) 2020, 2021, 2023
Smithsonian Astrophysical Observatory
Smithsonian Astrophysical Observatory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -95,7 +96,7 @@ def check_clobber(fname):


@lw.handle_ciao_errors(TOOLNAME, TOOLVER)
def convert(infile, outfile, clean=False, clobber=False):
def convert(infile, outfile, models=None, clean=False, clobber=False):

if outfile != '-' and not clobber:
check_clobber(outfile)
Expand All @@ -108,7 +109,7 @@ def convert(infile, outfile, clean=False, clobber=False):
except OSError as oe:
raise OSError(f"Unable to read from '{infile}'") from oe

out = xcm.convert(cts, clean=clean)
out = xcm.convert(cts, models=models, clean=clean)
if outfile == '-':
sys.stdout.write(out)
else:
Expand All @@ -124,6 +125,9 @@ if __name__ == "__main__":
parser.add_argument("infile", help="XCM file to convert (- for stdin)")
parser.add_argument("outfile", help="Sherpa file to create (- for stdout)")

parser.add_argument("--models", action="append",
help="Add models created by convert_xspec_user_model: modulename")

parser.add_argument("--clean", dest="clean", action="store_true",
default=False,
help="Should the script start with a call to clean?")
Expand Down Expand Up @@ -161,5 +165,6 @@ if __name__ == "__main__":
sys.exit(0)

convert(args.infile, args.outfile,
models=args.models,
clean=args.clean,
clobber=args.clobber)
Loading

0 comments on commit d49c0d0

Please sign in to comment.