Exemple #1
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)
Exemple #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))
Exemple #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')
Exemple #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)
Exemple #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')
Exemple #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)
           (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)
Exemple #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)
Exemple #9
0
    def run(self):
        """
        Calculate GMPEs, create bias plot comparisons
        """
        print("GMPE Comparison".center(80, '-'))

        # Initialize basic variables
        install = InstallCfg.getInstance()
        sim_id = self.sim_id
        sta_base = os.path.basename(os.path.splitext(self.r_stations)[0])

        # Input, tmp, and output directories
        a_tmpdir = os.path.join(install.A_TMP_DATA_DIR, str(sim_id))
        a_outdir = os.path.join(install.A_OUT_DATA_DIR, str(sim_id))
        a_tmpdir_seis = os.path.join(install.A_TMP_DATA_DIR, str(sim_id),
                                     "obs_seis_%s" % (sta_base))
        a_outdir_gmpe = os.path.join(install.A_OUT_DATA_DIR, str(sim_id),
                                     "gmpe_data_%s" % (sta_base))
        a_logdir = os.path.join(install.A_OUT_LOG_DIR, str(sim_id))

        self.log = os.path.join(a_logdir, "%d.gmpe_compare.log" % (sim_id))

        #
        # Make sure the output and tmp directories exist
        #
        dirs = [a_tmpdir, a_tmpdir_seis, a_outdir_gmpe, a_outdir, a_logdir]
        bband_utils.mkdirs(dirs, print_cmd=False)

        # Source file, parse it!
        a_srcfile = os.path.join(install.A_IN_DATA_DIR, str(sim_id),
                                 self.r_src_file)
        self.src_keys = bband_utils.parse_src_file(a_srcfile)

        # Station file
        a_statfile = os.path.join(install.A_IN_DATA_DIR, str(sim_id),
                                  self.r_stations)

        slo = StationList(a_statfile)
        site_list = slo.getStationList()

        # Go through each station, and print comparison headers for
        # the first station we process
        print_headers = True
        gmpe_models = []
        for site in site_list:
            stat = site.scode
            obs_file = os.path.join(a_tmpdir_seis, "%s.rd50" % (stat))
            gmpe_file = os.path.join(a_outdir_gmpe, "%s-gmpe.ri50" % (stat))
            # Skip station if we don't have observation file
            if not os.access(obs_file, os.R_OK):
                continue
            gmpe_data, gmpe_models[:] = self.read_gmpe(gmpe_file)
            obs_periods, obs_data = self.read_rotd50(obs_file)

            # Loop through the NGA methods
            for gmpe_model in gmpe_models:
                resid_file = os.path.join(
                    a_outdir_gmpe,
                    "%s-%d.resid.txt" % (gmpe_model.lower(), sim_id))
                period_set = self.calculate_residuals(site, gmpe_model,
                                                      gmpe_data, obs_periods,
                                                      obs_data, resid_file,
                                                      print_headers)
            print_headers = False

        for gmpe_model in gmpe_models:
            # Now call the resid2uncer_varN program to summarize the
            # residuals and create the files needed for the GOF plot
            resid_file = os.path.join(
                a_outdir_gmpe,
                "%s-%d.resid.txt" % (gmpe_model.lower(), sim_id))
            fileroot = os.path.join(
                a_outdir, "%s-GMPE-%d_r%d-all-rd50-%s" %
                (self.comp_label, sim_id, 0, gmpe_model.lower()))
            cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
                   "residfile=%s fileroot=%s " % (resid_file, fileroot) +
                   "comp=%s nstat=%d nper=%d " %
                   (gmpe_model.lower(), len(site_list), len(period_set)) +
                   "min_cdst=%d >> %s 2>&1" % (0, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Plot GOF plot
        gmpe_group = gmpe_config.GMPES[self.gmpe_group_name]
        gmpe_labels = gmpe_group["labels"]
        plotter = PlotGoF()
        plottitle = "Comparison between GMPEs and %s" % (self.comp_label)
        fileroot = "%s-GMPE-%d_r%d-all-rd50-" % (self.comp_label, sim_id, 0)
        dataroot = [
            "%s%s" % (fileroot, model.lower()) for model in gmpe_models
        ]
        plotter.multi_plot(plottitle, dataroot, a_outdir, a_outdir,
                           gmpe_labels, len(site_list))

        print("GMPE Comparison Completed".center(80, '-'))
Exemple #10
0
    def run(self):
        """
        Calculate GMPEs, create bias plot comparisons
        """
        print("GMPE Comparison".center(80, '-'))

        # Initialize basic variables
        install = InstallCfg.getInstance()
        sim_id = self.sim_id
        sta_base = os.path.basename(os.path.splitext(self.r_stations)[0])

        # Input, tmp, and output directories
        a_tmpdir = os.path.join(install.A_TMP_DATA_DIR, str(sim_id))
        a_outdir = os.path.join(install.A_OUT_DATA_DIR, str(sim_id))
        a_tmpdir_seis = os.path.join(install.A_TMP_DATA_DIR, str(sim_id),
                                     "obs_seis_%s" % (sta_base))
        a_outdir_gmpe = os.path.join(install.A_OUT_DATA_DIR, str(sim_id),
                                     "gmpe_data_%s" % (sta_base))
        a_logdir = os.path.join(install.A_OUT_LOG_DIR, str(sim_id))

        self.log = os.path.join(a_logdir, "%d.gmpe_compare.log" % (sim_id))

        #
        # Make sure the output and tmp directories exist
        #
        dirs = [a_tmpdir, a_tmpdir_seis, a_outdir_gmpe, a_outdir, a_logdir]
        bband_utils.mkdirs(dirs, print_cmd=False)

        # Source file, parse it!
        a_srcfile = os.path.join(install.A_IN_DATA_DIR,
                                 str(sim_id),
                                 self.r_src_file)
        self.src_keys = bband_utils.parse_src_file(a_srcfile)

        # Station file
        a_statfile = os.path.join(install.A_IN_DATA_DIR,
                                  str(sim_id),
                                  self.r_stations)

        slo = StationList(a_statfile)
        site_list = slo.getStationList()

        # Go through each station, and print comparison headers for
        # the first station we process
        print_headers = True
        gmpe_models = []
        for site in site_list:
            stat = site.scode
            obs_file = os.path.join(a_tmpdir_seis, "%s.rd50" % (stat))
            gmpe_file = os.path.join(a_outdir_gmpe, "%s-gmpe.ri50" % (stat))
            # Skip station if we don't have observation file
            if not os.access(obs_file, os.R_OK):
                continue
            gmpe_data, gmpe_models[:] = self.read_gmpe(gmpe_file)
            obs_periods, obs_data = self.read_rotd50(obs_file)

            # Loop through the NGA methods
            for gmpe_model in gmpe_models:
                resid_file = os.path.join(a_outdir_gmpe, "%s-%d.resid.txt" %
                                          (gmpe_model.lower(), sim_id))
                period_set = self.calculate_residuals(site, gmpe_model,
                                                      gmpe_data, obs_periods,
                                                      obs_data, resid_file,
                                                      print_headers)
            print_headers = False

        for gmpe_model in gmpe_models:
            # Now call the resid2uncer_varN program to summarize the
            # residuals and create the files needed for the GOF plot
            resid_file = os.path.join(a_outdir_gmpe, "%s-%d.resid.txt" %
                                      (gmpe_model.lower(), sim_id))
            fileroot = os.path.join(a_outdir, "%s-GMPE-%d_r%d-all-rd50-%s" %
                                    (self.comp_label, sim_id,
                                     0, gmpe_model.lower()))
            cmd = ("%s/resid2uncer_varN " % (install.A_GP_BIN_DIR) +
                   "residfile=%s fileroot=%s " % (resid_file, fileroot) +
                   "comp=%s nstat=%d nper=%d " % (gmpe_model.lower(),
                                                  len(site_list),
                                                  len(period_set)) +
                   "min_cdst=%d >> %s 2>&1" %
                   (0, self.log))
            bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False)

        # Plot GOF plot
        gmpe_group = gmpe_config.GMPES[self.gmpe_group_name]
        gmpe_labels = gmpe_group["labels"]
        plotter = PlotGoF()
        plottitle = "Comparison between GMPEs and %s" % (self.comp_label)
        fileroot = "%s-GMPE-%d_r%d-all-rd50-" % (self.comp_label, sim_id, 0)
        dataroot = ["%s%s" % (fileroot, model.lower()) for model in gmpe_models]
        plotter.multi_plot(plottitle, dataroot, a_outdir,
                           a_outdir, gmpe_labels, len(site_list))

        print("GMPE Comparison Completed".center(80, '-'))