#!/usr/bin/env python # # Copyright (C) 2019 Gino Contestabile, Francesco Pannarale # # 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 the # Free Software Foundation; either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ============================================================================= # Preamble # ============================================================================= from __future__ import division import sys import glob import os import copy import logging from glue.ligolw import lsctables import pycbc.version from pycbc.results.pygrb_plotting_utils import * plt.switch_backend('Agg') __author__ = "Francesco Pannarale " __version__ = pycbc.version.git_verbose_msg __date__ = pycbc.version.date __program__ = "pycbc_pygrb_plot_skygrid" # ============================================================================= # Main script starts here # ============================================================================= description = 'pycbc_pygrb_plot_skygrid will produce the sky grid plot.' usage = __program__ + ' [--options]' opts = pygrb_plot_opts_parser(usage=usage, description=description, version=__version__) if opts.verbose: level = logging.INFO else: level = logging.WARNING logging.basicConfig(format="%(asctime)s:%(levelname)s : %(message)s", level=level) trig_file = os.path.abspath(opts.trig_file) inj_file = None if opts.inj_file: inj_file = os.path.abspath(opts.inj_file) outfile = opts.output_file seg_dir = opts.segment_dir veto_files = [] if opts.veto_directory: veto_string = ','.join([str(i) for i in range(2,opts.veto_category+1)]) veto_files = glob.glob(opts.veto_directory +'/*CAT[%s]*.xml' %(veto_string)) if opts.plot_title is None: opts.plot_title = 'PyGRB sky grid' logging.info("Imported and ready to go.") # Set output directories outdirs = [os.path.split(os.path.abspath(outfile))[0]] for outdir in outdirs: if not os.path.isdir(outdir): os.makedirs(outdir) # Extract IFOs and vetoes ifos = extract_ifos(trig_file) # Extract IFOs and vetoes vetoes = extract_vetoes(trig_file, ifos) # Load triggers trigs = load_triggers(trig_file, vetoes, ifos) # Extract trigger data trig_data = PygrbFilterOutput(trigs, ifos, lsctables.MultiInspiralTable.loadcolumns, "triggers", opts) # # Generate sky grid plot # xlabel = "Longitude (Degrees)" ylabel = "Latitude (Degrees)" if opts.verbose: sys.stdout.write("\nPlotting...\n") fig_name = os.path.split(os.path.abspath(outfile))[1] sys.stdout.write(" * %s (%s vs %s)...\n" % (fig_name, xlabel, ylabel)) pygrb_shared_plot_setups() fig = plt.figure() ax = fig.gca() ax.set_xlabel(xlabel)#, fontsize=16) ax.set_ylabel(ylabel)#, fontsize=16) ax.plot(trig_data.longitude, trig_data.latitude, 'ko', markerfacecolor='blue') # Wrap up save_fig_with_metadata(fig, outfile, cmd=' '.join(sys.argv), title=opts.plot_title, caption=opts.plot_caption) #fig_kwds=fig_kwds, plt.close()