Commit e170d806 authored by Antoine Laudrain's avatar Antoine Laudrain
Browse files

Add helper function to get plot ext list. Duplicated in MSO and T&D.

parent 8043ad3b
......@@ -49,3 +49,32 @@ def cut_array(data, every=None, average=None):
data = data[:max_len].reshape((-1, average)).mean(-1)
return data
def get_exts_list(exts, default=None):
"""Ensure the provided extension(s) are iterable.
@param[in] exts: None or string or list of string
If None, return the default list.
If a string, make it the only element of a list.
If a list, do nothing.
@param[in] default: None or string or list of string
The default list of extension if `exts` is None.
If None, make it ["pdf", "png"]
If a single string, make it the only element of a list.
If a list, take this as default extensions.
@return: list of string
List of plot extensions.
"""
if not default: # None or empty list
default = ["pdf", "png"]
if isinstance(default, str):
default = [default]
if not exts:
exts = default
if isinstance(exts, str):
exts = [exts]
return exts
......@@ -20,7 +20,7 @@ if "--display" not in sys.argv:
# pylint: disable=wrong-import-position
import matplotlib.pyplot as plt
from helpers import cut_array
from helpers import cut_array, get_exts_list
from helpers_wav import process_data_file
from logger_cfg import getLogger, setup_logging
logger = getLogger(__name__)
......@@ -38,7 +38,7 @@ def main(data, outfile_name, exts=None,
this file.
@param[in] outfile_name: string
Path to output plot file, without extension.
@param[in] exts: None or list of string
@param[in] exts: string or list of string or None
List of plot extension.
If None is provided (default), assumed to be ['pdf', 'png'].
@param[in] xmin, xmax, ymin, ymax: None (default) or float
......@@ -111,9 +111,7 @@ def main(data, outfile_name, exts=None,
ax.legend(loc="center right")
plt.subplots_adjust(bottom=0.13, top=0.93, left=0.15, right=0.95)
if not exts: # None or empty list of extensions
exts = ["png", "pdf"]
for ext in exts:
for ext in get_exts_list(exts, default=["pdf", "png"]):
outfile_path = outfile_name + "." + ext
logger.info("Writting plot file %s", outfile_path)
fig.savefig(outfile_path)
......
......@@ -52,6 +52,35 @@ def cut_array(data, every=None, average=None):
return data
def get_exts_list(exts, default=None):
"""Ensure the provided extension(s) are iterable.
@param[in] exts: None or string or list of string
If None, return the default list.
If a string, make it the only element of a list.
If a list, do nothing.
@param[in] default: None or string or list of string
The default list of extension if `exts` is None.
If None, make it ["pdf", "png"]
If a single string, make it the only element of a list.
If a list, take this as default extensions.
@return: list of string
List of plot extensions.
"""
if not default: # None or empty list
default = ["pdf", "png"]
if isinstance(default, str):
default = [default]
if not exts:
exts = default
if isinstance(exts, str):
exts = [exts]
return exts
def main(infiles, outfile_name, exts=None,
after=None, before=None, every=None, average=None,
display=False, debug=False):
......@@ -60,7 +89,7 @@ def main(infiles, outfile_name, exts=None,
@param[in] infiles: list of .tgz of .xml files paths to get data from.
@param[in] outfile_name: str
Full output plot file name without extension.
@param[in] exts: list of str or None
@param[in] exts: string or list of string or None
List of plot format to output.
If None, assumes it is png + pdf.
@param[in] after, before: str or None (default)
......@@ -118,9 +147,7 @@ def main(infiles, outfile_name, exts=None,
ax.grid()
plt.subplots_adjust(bottom=0.15, top=0.95, left=0.15, right=0.95)
if not exts: # None or empty list of extensions
exts = ["png", "pdf"]
for ext in exts:
for ext in get_exts_list(exts, ["png", "pdf"]):
outfile_path = outfile_name + "." + ext
logger.info("Writting plot file %s", outfile_path)
fig.savefig(outfile_path)
......
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