Example #1
0
File: gp_gof.py Project: somu15/bbp
    def summarize_rotd50(self, site_list, a_outdir, a_outdir_gmpe):
        """
        Summarizes all rotd50 data and creates the rotd50 GOF plot
        """
        sim_id = self.sim_id
        install = self.install
        config = self.config

        rd50_residfile = os.path.join(
            a_outdir, "%s-%d.rd50-resid.txt" % (self.comp_label, sim_id))
        for comp in config.COMPS_PSA5:
            # Build paths and check lengths
            fileroot = os.path.join(
                a_outdir, "%s-%d_r%d-%d-rd50-%s" %
                (self.comp_label, sim_id, config.MIN_CDST, self.max_cutoff,
                 comp))
            bband_utils.check_path_lengths([rd50_residfile, fileroot],
                                           bband_utils.GP_MAX_FILENAME)

            cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
                   "residfile=%s fileroot=%s " % (rd50_residfile, fileroot) +
                   "comp=%s nstat=%d nper=63 " % (comp, len(site_list)) +
                   "min_cdst=%d max_cdst=%d >> %s 2>&1" %
                   (config.MIN_CDST, self.max_cutoff, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Plot GOF for psa5/rotd50 data
        if self.single_component:
            plot_mode = 'rd50-single'
        else:
            plot_mode = 'rd50'
        fileroot = '%s-%d_r0-%d-rd50' % (self.comp_label, sim_id,
                                         self.max_cutoff)
        plottitle = ("GOF Comparison between %s and simulation %d" %
                     (self.comp_label, sim_id))
        plotter = PlotGoF()
        plotter.plot(plottitle,
                     fileroot,
                     a_outdir,
                     a_outdir,
                     cutoff=self.max_cutoff,
                     mode=plot_mode,
                     colorset='single')

        # Finally, plot the distance and map GOFs
        plot_dist_gof(rd50_residfile,
                      self.comp_label,
                      a_outdir_gmpe,
                      sim_id=self.sim_id)
        plot_map_gof(self.r_srcfile,
                     self.r_stations,
                     rd50_residfile,
                     self.comp_label,
                     sim_id=self.sim_id)
Example #2
0
def summarize_rotd50(tmpdir, outdir, combined_resid_file, comp_label,
                     num_stations, num_realization, codebase):
    """
    This function summarizes all rotd50 data and creates the combined
    rotd50 GOF plot
    """
    config = GPGofCfg()

    # Figure out where out binaries are
    if "BBP_DIR" in os.environ:
        install_root = os.path.normpath(os.environ["BBP_DIR"])
    else:
        raise bband_utils.ProcessingError("BBP_DIR is not set!")
    gp_bin_dir = os.path.join(install_root, "src", "gp", "bin")

    logfile = os.path.join(tmpdir, "log.txt")

    for comp in config.COMPS_PSA5:
        # Build paths and check lengths
        fileroot = os.path.join(
            tmpdir, "%s-%s-combined-rd50-%s" % (codebase, comp_label, comp))
        bband_utils.check_path_lengths([combined_resid_file, fileroot],
                                       bband_utils.GP_MAX_FILENAME)

        cmd = ("%s " % (os.path.join(gp_bin_dir, "resid2uncer_varN")) +
               "residfile=%s fileroot=%s " % (combined_resid_file, fileroot) +
               "comp=%s nstat=%d nper=63 " % (comp, num_stations) +
               " >> %s 2>&1" % (logfile))
        bband_utils.runprog(cmd, abort_on_error=True)

    plottitle = ("Combined GOF Plot for %s\n%d Realizations - %s Method" %
                 (comp_label, num_realization, codebase.upper()))
    fileroot = "%s-%s-combined-rd50" % (codebase, comp_label)
    plotter = PlotGoF()
    plotter.plot(plottitle,
                 fileroot,
                 tmpdir,
                 outdir,
                 cutoff=0,
                 mode="rd50-single",
                 colorset="combined")

    print("Stations used: %s" % (num_stations))
Example #3
0
    def generate_plot(self, a_statfile, a_dstdir):
        """
        This function generates the bias plot with ratio of maximum to
        median response across orientations (RotD100/RotD50)
        """
        install = install_cfg.InstallCfg.getInstance()
        sim_id = self.sim_id
        slo = StationList(a_statfile)
        site_list = slo.getStationList()

        rd100_resid_output = os.path.join(
            a_dstdir, "%s-%d-resid-rd100.txt" % (self.comp_label, sim_id))
        for comp in ['rotd50', 'rotd100', 'ratio']:
            # Build paths and check lengths
            fileroot = os.path.join(
                a_dstdir, "%s-%d_r0-%d-rd100-%s" %
                (self.comp_label, sim_id, self.max_cutoff, comp))
            bband_utils.check_path_lengths([rd100_resid_output, fileroot],
                                           bband_utils.GP_MAX_FILENAME)

            cmd = ("%s " %
                   (os.path.join(install.A_GP_BIN_DIR, "resid2uncer_varN")) +
                   "residfile=%s fileroot=%s " %
                   (rd100_resid_output, fileroot) +
                   "comp=%s nstat=%d nper=63 " % (comp, len(site_list)) +
                   "min_cdst=%d max_cdst=%d >> %s 2>&1" %
                   (0, self.max_cutoff, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Generate bias plot
        plot_mode = 'rd100'
        fileroot = ("%s-%d_r0-%d-rd100" %
                    (self.comp_label, sim_id, self.max_cutoff))
        plottitle = ("GOF Comparison between %s and simulation %d" %
                     (self.comp_label, sim_id))
        plotter = PlotGoF()
        plotter.plot(plottitle,
                     fileroot,
                     a_dstdir,
                     a_dstdir,
                     cutoff=self.max_cutoff,
                     mode=plot_mode,
                     colorset='single')
Example #4
0
    def summarize_rotd50(self, site_list, a_outdir, a_outdir_gmpe):
        """
        Summarizes all rotd50 data and creates the rotd50 GOF plot
        """
        sim_id = self.sim_id
        install = self.install
        config = self.config

        rd50_residfile = os.path.join(a_outdir, "%s-%d.rd50-resid.txt" %
                                      (self.comp_label, sim_id))
        for comp in config.COMPS_PSA5:
            # Build paths and check lengths
            fileroot = os.path.join(a_outdir, "%s-%d_r%d-%d-rd50-%s" %
                                    (self.comp_label, sim_id, config.MIN_CDST,
                                     self.max_cutoff, comp))
            bband_utils.check_path_lengths([rd50_residfile, fileroot],
                                           bband_utils.GP_MAX_FILENAME)

            cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
                   "residfile=%s fileroot=%s " % (rd50_residfile, fileroot) +
                   "comp=%s nstat=%d nper=63 " % (comp, len(site_list)) +
                   "min_cdst=%d max_cdst=%d >> %s 2>&1" %
                   (config.MIN_CDST, self.max_cutoff, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Plot GOF for psa5/rotd50 data
        if self.single_component:
            plot_mode = 'rd50-single'
        else:
            plot_mode = 'rd50'
        fileroot = '%s-%d_r0-%d-rd50' % (self.comp_label, sim_id, self.max_cutoff)
        plottitle = ("GOF Comparison between %s and simulation %d" %
                     (self.comp_label, sim_id))
        plotter = PlotGoF()
        plotter.plot(plottitle, fileroot, a_outdir, a_outdir,
                     cutoff=self.max_cutoff, mode=plot_mode, colorset='single')

        # Finally, plot the distance and map GOFs
        plot_dist_gof(rd50_residfile, self.comp_label,
                      a_outdir_gmpe, sim_id=self.sim_id)
        plot_map_gof(self.r_srcfile, self.r_stations, rd50_residfile,
                     self.comp_label, sim_id=self.sim_id)
Example #5
0
    def generate_plot(self, a_statfile, a_dstdir):
        """
        This function generates the bias plot with ratio of maximum to
        median response across orientations (RotD100/RotD50)
        """
        install = install_cfg.InstallCfg.getInstance()
        sim_id = self.sim_id
        slo = StationList(a_statfile)
        site_list = slo.getStationList()

        rd100_resid_output = os.path.join(a_dstdir, "%s-%d-resid-rd100.txt" %
                                          (self.comp_label, sim_id))
        for comp in ['rotd50', 'rotd100', 'ratio']:
            # Build paths and check lengths
            fileroot = os.path.join(a_dstdir, "%s-%d_r0-%d-rd100-%s" %
                                    (self.comp_label, sim_id,
                                     self.max_cutoff, comp))
            bband_utils.check_path_lengths([rd100_resid_output, fileroot],
                                           bband_utils.GP_MAX_FILENAME)

            cmd = ("%s " % (os.path.join(install.A_GP_BIN_DIR,
                                         "resid2uncer_varN")) +
                   "residfile=%s fileroot=%s " %
                   (rd100_resid_output, fileroot) +
                   "comp=%s nstat=%d nper=63 " %
                   (comp, len(site_list)) +
                   "min_cdst=%d max_cdst=%d >> %s 2>&1" %
                   (0, self.max_cutoff, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Generate bias plot
        plot_mode = 'rd100'
        fileroot = ("%s-%d_r0-%d-rd100" %
                    (self.comp_label, sim_id,
                     self.max_cutoff))
        plottitle = ("GOF Comparison between %s and simulation %d" %
                     (self.comp_label, sim_id))
        plotter = PlotGoF()
        plotter.plot(plottitle, fileroot, a_dstdir, a_dstdir,
                     cutoff=self.max_cutoff, mode=plot_mode, colorset='single')
Example #6
0
def summarize_rotd50(tmpdir, outdir, combined_resid_file,
                     comp_label, num_stations, num_realization,
                     codebase):
    """
    This function summarizes all rotd50 data and creates the combined
    rotd50 GOF plot
    """
    config = GPGofCfg()

    # Figure out where out binaries are
    if "BBP_DIR" in os.environ:
        install_root = os.path.normpath(os.environ["BBP_DIR"])
    else:
        raise bband_utils.ProcessingError("BBP_DIR is not set!")
    gp_bin_dir = os.path.join(install_root, "src", "gp", "bin")

    logfile = os.path.join(tmpdir, "log.txt")

    for comp in config.COMPS_PSA5:
        # Build paths and check lengths
        fileroot = os.path.join(tmpdir, "%s-%s-combined-rd50-%s" %
                                (codebase, comp_label, comp))
        bband_utils.check_path_lengths([combined_resid_file, fileroot],
                                       bband_utils.GP_MAX_FILENAME)

        cmd = ("%s/resid2uncer_varN " % (gp_bin_dir) + 
               "residfile=%s fileroot=%s " % (combined_resid_file, fileroot) +
               "comp=%s nstat=%d nper=63 " % (comp, num_stations) +
               " >> %s 2>&1" % (logfile))
        bband_utils.runprog(cmd, abort_on_error=True)

    plottitle = ("Combined GOF Plot for %s\n%d Realizations\n%s Method" %
                 (comp_label, num_realization, codebase.upper()))
    fileroot = "%s-%s-combined-rd50" % (codebase, comp_label)
    plotter = PlotGoF()
    plotter.plot(plottitle, fileroot, tmpdir, outdir,
                 cutoff=0, mode="rd50-single", colorset="combined")

    print "Stations used: %s" % (num_stations)
Example #7
0
           (print_header_rd50, resid_file, log_file))
    bband_utils.runprog(cmd, abort_on_error=True)

    # Only need to print header the first time
    if print_header_rd50 == 1:
        print_header_rd50 = 0

for comp in config.COMPS_PSA5:
    # Build paths and check lengths
    fileroot = os.path.join(
        TMPDIR, "%s-%d_r%d-all-rd50-%s" %
        (event_label, sim_id_1, config.MIN_CDST, comp))
    bband_utils.check_path_lengths([fileroot], bband_utils.GP_MAX_FILENAME)

    cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
           "residfile=%s fileroot=%s " % (resid_file, fileroot) +
           "comp=%s nstat=%d nper=63 " % (comp, len(site_list)) +
           "min_cdst=%d >> %s 2>&1" % (config.MIN_CDST, log_file))
    bband_utils.runprog(cmd, abort_on_error=True)

plottitle = ("GOF Comparison between simulation %d and simulation %d" %
             (sim_id_1, sim_id_2))
plot_mode = 'rd50-single'
fileroot = '%s-%d_r0-all-rd50' % (event_label, sim_id_1)
plotter = PlotGoF()
plotter.plot(plottitle, fileroot, TMPDIR, output_dir, 0, plot_mode, 'single')

print "All Done!"
# Clean-up, all done!
shutil.rmtree(TMPDIR)
Example #8
0
    # Only need to print header the first time
    if print_header_rd50 == 1:
        print_header_rd50 = 0

for comp in config.COMPS_PSA5:
    # Build paths and check lengths
    fileroot = os.path.join(TMPDIR, "%s-%d_r%d-all-rd50-%s" %
                            (event_label, sim_id_1, config.MIN_CDST,
                             comp))
    bband_utils.check_path_lengths([fileroot],
                                   bband_utils.GP_MAX_FILENAME)

    cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
           "residfile=%s fileroot=%s " % (resid_file, fileroot) + 
           "comp=%s nstat=%d nper=63 " % (comp, len(site_list)) +
           "min_cdst=%d >> %s 2>&1" %
           (config.MIN_CDST, log_file))
    bband_utils.runprog(cmd, abort_on_error=True)

plottitle = ("GOF Comparison between simulation %d and simulation %d" %
             (sim_id_1, sim_id_2))
plot_mode = 'rd50-single'
fileroot = '%s-%d_r0-all-rd50' % (event_label, sim_id_1)
plotter = PlotGoF()
plotter.plot(plottitle, fileroot, TMPDIR, output_dir,
             0, plot_mode, 'single')
   
print "All Done!"
# Clean-up, all done!
shutil.rmtree(TMPDIR)