Skip to content
Snippets Groups Projects

Plot horizon distance from ranking statistics

Merged ChiWai Chan requested to merge plot_psd_horizon into master
1 unresolved thread
2 files
+ 35
8
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -16,31 +16,58 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Plot horizon history from ranking statistics
"""Plot horizon history from ranking statistics.
"""
from itertools import groupby
from optparse import OptionParser
from pathlib import Path
from gstlal.plots import horizon
from lal.utils import CacheEntry
def parse_command_line():
parser = OptionParser(description = __doc__)
parser.add_option("-o", "--output", help = "Set plot filename.")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose")
parser.add_option("-o", "--outdir", default = ".", help = "Set the output directory. By default, current directory will be used.")
parser.add_option("-f", "--format", default = "png", help = "Set the output format. By default, the output will be a png file.")
parser.add_option("-s", "--fig-size", default = "12,4", help = "Set the output figure size in inch. By default, the figure size will be 12,4. (Optional)")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose. (Optional)")
options, args = parser.parse_args()
options.format = options.format.strip(".")
try:
figsize = options.fig_size.split(",")
w, h = float(figsize[0]), float(figsize[1])
except:
raise ValueError("Please provide valid --fig-size, expecting a format of 'width,height', got '%s'." % options.fig_size)
else:
options.fig_size = (w, h)
if len(args) == 0:
raise ValueError("Must provide at least one ranking statistics file.")
if options.output is None:
raise ValueError("Must provide --output (output filename).")
return options, args
options, files = parse_command_line()
horizon_distance = horizon.HorizonDistance.from_rankingstats(files, verbose = options.verbose)
horizon_distance.savefig(options.output)
urls = []
for f in files:
if f.endswith(".cache"):
urls.extend([CacheEntry(line).url for line in open(f)])
elif f.endswith(".gz"):
urls.append(f)
outdir = Path(options.outdir)
for key, group in groupby(sorted(urls, key = lambda x: CacheEntry.from_T050017(x).description), lambda x: CacheEntry.from_T050017(x).description):
rankfiles = list(group)
ce = CacheEntry.from_T050017(rankfiles[0])
desc = ce.description.replace('MARG_DIST_STATS', 'HORIZON')
start = ce.segment[0]
duration = ce.segment[1] - ce.segment[0]
output = outdir / f"{ce.observatory}-{desc}-{start}-{duration}.{options.format}"
horizon_distance = horizon.HorizonDistance.from_rankingstats(rankfiles, verbose = options.verbose)
horizon_distance.savefig(output, options.fig_size)
Loading