Adding an option to change the output file format. The available formats...

Adding an option to change the output file format. The available formats depends of the host, but usually png, pdf, ps, eps and svg is supported.

Example:
--format svg
parent c36ec79f
...@@ -53,16 +53,19 @@ def main(): ...@@ -53,16 +53,19 @@ def main():
subparsers = parser.add_subparsers(help="List of commands") subparsers = parser.add_subparsers(help="List of commands")
pdf_parser = subparsers.add_parser('pdf', help=pdf_action.__doc__) pdf_parser = subparsers.add_parser('pdf', help=pdf_action.__doc__)
pdf_parser.add_argument('--format', dest='format', default='pdf')
pdf_parser.add_argument('--outdir', dest='outdir', default='out') pdf_parser.add_argument('--outdir', dest='outdir', default='out')
pdf_parser.set_defaults(parser='pdf') pdf_parser.set_defaults(parser='pdf')
chi2_parser = subparsers.add_parser('chi2', help=chi2_action.__doc__) chi2_parser = subparsers.add_parser('chi2', help=chi2_action.__doc__)
chi2_parser.add_argument('--format', dest='format', default='pdf')
chi2_parser.add_argument('--outdir', dest='outdir', default='out') chi2_parser.add_argument('--outdir', dest='outdir', default='out')
chi2_parser.set_defaults(parser='chi2') chi2_parser.set_defaults(parser='chi2')
sed_parser = subparsers.add_parser('sed', help=sed_action.__doc__) sed_parser = subparsers.add_parser('sed', help=sed_action.__doc__)
sed_parser.add_argument('--type', default='mJy') sed_parser.add_argument('--type', default='mJy')
sed_parser.add_argument('--nologo', action='store_true') sed_parser.add_argument('--nologo', action='store_true')
sed_parser.add_argument('--format', dest='format', default='pdf')
sed_parser.add_argument('--outdir', dest='outdir', default='out') sed_parser.add_argument('--outdir', dest='outdir', default='out')
sed_parser.add_argument('--xrange', dest='xrange', default=':', sed_parser.add_argument('--xrange', dest='xrange', default=':',
type=parser_range, type=parser_range,
...@@ -76,6 +79,7 @@ def main(): ...@@ -76,6 +79,7 @@ def main():
mock_parser = subparsers.add_parser('mock', help=mock_action.__doc__) mock_parser = subparsers.add_parser('mock', help=mock_action.__doc__)
mock_parser.add_argument('--nologo', action='store_true') mock_parser.add_argument('--nologo', action='store_true')
mock_parser.add_argument('--format', dest='format', default='pdf')
mock_parser.add_argument('--outdir', dest='outdir', default='out') mock_parser.add_argument('--outdir', dest='outdir', default='out')
mock_parser.set_defaults(parser='mock') mock_parser.set_defaults(parser='mock')
...@@ -91,9 +95,9 @@ def main(): ...@@ -91,9 +95,9 @@ def main():
parser.print_usage() parser.print_usage()
else: else:
if args.parser == 'chi2': if args.parser == 'chi2':
chi2_action(config, outdir) chi2_action(config, args.format, outdir)
elif args.parser == 'pdf': elif args.parser == 'pdf':
pdf_action(config, outdir) pdf_action(config, args.format, outdir)
elif args.parser == 'sed': elif args.parser == 'sed':
if not args.series: if not args.series:
series = AVAILABLE_SERIES series = AVAILABLE_SERIES
...@@ -103,6 +107,6 @@ def main(): ...@@ -103,6 +107,6 @@ def main():
else: else:
series = args.series series = args.series
sed_action(config, args.type, args.nologo, args.xrange, args.yrange, sed_action(config, args.type, args.nologo, args.xrange, args.yrange,
series, outdir) series, args.format, outdir)
elif args.parser == 'mock': elif args.parser == 'mock':
mock_action(config, args.nologo, outdir) mock_action(config, args.nologo, outdir)
...@@ -33,7 +33,7 @@ def pool_initializer(counter): ...@@ -33,7 +33,7 @@ def pool_initializer(counter):
gbl_counter = counter gbl_counter = counter
def chi2(config, outdir): def chi2(config, format, outdir):
"""Plot the χ² values of analysed variables. """Plot the χ² values of analysed variables.
""" """
file = path.join(path.dirname(outdir), config.configuration['data_file']) file = path.join(path.dirname(outdir), config.configuration['data_file'])
...@@ -42,7 +42,7 @@ def chi2(config, outdir): ...@@ -42,7 +42,7 @@ def chi2(config, outdir):
chi2_vars += [band for band in config.configuration['bands'] chi2_vars += [band for band in config.configuration['bands']
if band.endswith('_err') is False] if band.endswith('_err') is False]
items = list(product(input_data['id'], chi2_vars, [outdir])) items = list(product(input_data['id'], chi2_vars, [format], [outdir]))
counter = Counter(len(items)) counter = Counter(len(items))
with mp.Pool(processes=config.configuration['cores'], initializer=pool_initializer, with mp.Pool(processes=config.configuration['cores'], initializer=pool_initializer,
initargs=(counter,)) as pool: initargs=(counter,)) as pool:
...@@ -51,7 +51,7 @@ def chi2(config, outdir): ...@@ -51,7 +51,7 @@ def chi2(config, outdir):
pool.join() pool.join()
def _chi2_worker(obj_name, var_name, outdir): def _chi2_worker(obj_name, var_name, format, outdir):
"""Plot the reduced χ² associated with a given analysed variable """Plot the reduced χ² associated with a given analysed variable
Parameters Parameters
...@@ -80,5 +80,5 @@ def _chi2_worker(obj_name, var_name, outdir): ...@@ -80,5 +80,5 @@ def _chi2_worker(obj_name, var_name, outdir):
ax.minorticks_on() ax.minorticks_on()
figure.suptitle("Reduced $\chi^2$ distribution of {} for {}." figure.suptitle("Reduced $\chi^2$ distribution of {} for {}."
.format(var_name, obj_name)) .format(var_name, obj_name))
figure.savefig("{}/{}_{}_chi2.pdf".format(outdir, obj_name, var_name)) figure.savefig("{}/{}_{}_chi2.{}".format(outdir, obj_name, var_name, format))
plt.close(figure) plt.close(figure)
...@@ -32,7 +32,7 @@ def pool_initializer(counter): ...@@ -32,7 +32,7 @@ def pool_initializer(counter):
gbl_counter = counter gbl_counter = counter
def pdf(config, outdir): def pdf(config, format, outdir):
"""Plot the PDF of analysed variables. """Plot the PDF of analysed variables.
""" """
input_data = read_table(path.join(path.dirname(outdir), config.configuration['data_file'])) input_data = read_table(path.join(path.dirname(outdir), config.configuration['data_file']))
...@@ -40,7 +40,7 @@ def pdf(config, outdir): ...@@ -40,7 +40,7 @@ def pdf(config, outdir):
pdf_vars += [band for band in config.configuration['bands'] pdf_vars += [band for band in config.configuration['bands']
if band.endswith('_err') is False] if band.endswith('_err') is False]
items = list(product(input_data['id'], pdf_vars, [outdir])) items = list(product(input_data['id'], pdf_vars, [format], [outdir]))
counter = Counter(len(items)) counter = Counter(len(items))
with mp.Pool(processes=config.configuration['cores'], initializer=pool_initializer, with mp.Pool(processes=config.configuration['cores'], initializer=pool_initializer,
initargs=(counter,)) as pool: initargs=(counter,)) as pool:
...@@ -49,7 +49,7 @@ def pdf(config, outdir): ...@@ -49,7 +49,7 @@ def pdf(config, outdir):
pool.join() pool.join()
def _pdf_worker(obj_name, var_name, outdir): def _pdf_worker(obj_name, var_name, format, outdir):
"""Plot the PDF associated with a given analysed variable """Plot the PDF associated with a given analysed variable
Parameters Parameters
...@@ -113,5 +113,5 @@ def _pdf_worker(obj_name, var_name, outdir): ...@@ -113,5 +113,5 @@ def _pdf_worker(obj_name, var_name, outdir):
ax.minorticks_on() ax.minorticks_on()
figure.suptitle("Probability distribution function of {} for {}" figure.suptitle("Probability distribution function of {} for {}"
.format(var_name, obj_name)) .format(var_name, obj_name))
figure.savefig("{}/{}_{}_pdf.pdf".format(outdir, obj_name, var_name)) figure.savefig("{}/{}_{}_pdf.{}".format(outdir, obj_name, var_name, format))
plt.close(figure) plt.close(figure)
...@@ -56,7 +56,7 @@ def pool_initializer(counter): ...@@ -56,7 +56,7 @@ def pool_initializer(counter):
gbl_counter = counter gbl_counter = counter
def sed(config, sed_type, nologo, xrange, yrange, series, outdir): def sed(config, sed_type, nologo, xrange, yrange, series, format, outdir):
"""Plot the best SED with associated observed and modelled fluxes. """Plot the best SED with associated observed and modelled fluxes.
""" """
obs = read_table(path.join(path.dirname(outdir), config.configuration['data_file'])) obs = read_table(path.join(path.dirname(outdir), config.configuration['data_file']))
...@@ -75,12 +75,12 @@ def sed(config, sed_type, nologo, xrange, yrange, series, outdir): ...@@ -75,12 +75,12 @@ def sed(config, sed_type, nologo, xrange, yrange, series, outdir):
initargs=(counter,)) as pool: initargs=(counter,)) as pool:
pool.starmap(_sed_worker, zip( pool.starmap(_sed_worker, zip(
obs, mod, repeat(filters), repeat(sed_type), repeat(logo), obs, mod, repeat(filters), repeat(sed_type), repeat(logo),
repeat(xrange), repeat(yrange), repeat(series), repeat(outdir))) repeat(xrange), repeat(yrange), repeat(series), repeat(format), repeat(outdir)))
pool.close() pool.close()
pool.join() pool.join()
def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdir): def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, format, outdir):
"""Plot the best SED with the associated fluxes in bands """Plot the best SED with the associated fluxes in bands
Parameters Parameters
...@@ -103,6 +103,8 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdi ...@@ -103,6 +103,8 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdi
xrange: tuple(float|boolean, float|boolean) xrange: tuple(float|boolean, float|boolean)
yrange: tuple(float|boolean, float|boolean) yrange: tuple(float|boolean, float|boolean)
series: list series: list
format: string
One of png, pdf, ps, eps or svg.
outdir: string outdir: string
The absolute path to outdir The absolute path to outdir
...@@ -332,7 +334,7 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdi ...@@ -332,7 +334,7 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series, outdi
figure.figimage(logo, 12, figure_height - 67, origin='upper', zorder=0, figure.figimage(logo, 12, figure_height - 67, origin='upper', zorder=0,
alpha=1) alpha=1)
figure.savefig(path.join(outdir, '{}_best_model.pdf'.format(obs['id']))) figure.savefig(path.join(outdir, '{}_best_model.{}'.format(obs['id'], format)))
plt.close(figure) plt.close(figure)
else: else:
print("No valid best SED found for {}. No plot created.".format(obs['id'])) print("No valid best SED found for {}. No plot created.".format(obs['id']))
......
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