def post_process(self): """ Run the standard BBP post-processing tasks """ # Plot seismograms plotter = PlotSeis(os.path.basename(self.station_list), os.path.basename(self.src_files[0]), True, True, self.output_sim_id) plotter.run() # RotD50 process = RotD50(os.path.basename(self.station_list), self.output_sim_id) process.run() # Plot RotD50 # Load station list slo = StationList(self.station_list) site_list = slo.getStationList() for site in site_list: stat = site.scode rd50_file = "%d.%s.rd50" % (self.output_sim_id, stat) rd50_filename1 = os.path.join(self.a_outdir, rd50_file) outfile = os.path.join(self.a_outdir, "%s_%d_%s_rotd50.png" % (self.scenario, self.output_sim_id, stat)) plot_rotd50.plot_rd50(stat, rd50_filename1, "-", self.scenario, "-", outfile, site.low_freq_corner, site.high_freq_corner, quiet=True)
def post_process(station_list, src_files, merged_outdir, realization, scenario): """ Run the standard BBP post-processing tasks """ # Plot seismograms plotter = PlotSeis(os.path.basename(station_list), os.path.basename(src_files[0]), True, True, int(realization)) plotter.run() # RotD50 process = RotD50(os.path.basename(station_list), int(realization)) process.run() # Plot RotD50 # Load station list slo = StationList(station_list) site_list = slo.getStationList() for site in site_list: stat = site.scode rd50_file = "%d.%s.rd50" % (int(realization), stat) rd50_filename1 = os.path.join(merged_outdir, rd50_file) outfile = os.path.join(merged_outdir, "%s_%d_%s_rotd50.png" % (scenario, int(realization), stat)) plot_rotd50.plot_rd50(stat, rd50_filename1, "-", scenario, "-", outfile, site.low_freq_corner, site.high_freq_corner, quiet=True)
def run(self): print("Generating Plots".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]) self.log = os.path.join(install.A_OUT_LOG_DIR, str(sim_id), "%d.gen_plots.log" % (sim_id)) # 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)) # Station file a_statfile = os.path.join(install.A_IN_DATA_DIR, str(sim_id), self.r_stations) # List of observed seismogram files filelist = os.listdir(a_tmpdir_seis) slo = StationList(a_statfile) site_list = slo.getStationList() for site in site_list: stat = site.scode # Look for the files we need bbpfile = os.path.join(a_tmpdir_seis, "%s.bbp" % stat) expected_file = os.path.join(a_outdir, "%d.%s.vel.bbp" % (sim_id, stat)) if (not os.path.exists(expected_file) or not os.path.exists(bbpfile)): # just skip this station continue print("==> Plotting seismogram comparison for station: %s" % (stat)) if self.format == 'vel': # We have velocity, nothing we need to do filename1 = bbpfile elif self.format == 'acc': # We have acceleration, must integrate first # Create path names and check if their sizes are within bounds nsfile = os.path.join(a_tmpdir, "temp.acc.000") ewfile = os.path.join(a_tmpdir, "temp.acc.090") udfile = os.path.join(a_tmpdir, "temp.acc.ver") bband_utils.check_path_lengths([nsfile, ewfile, udfile], bband_utils.GP_MAX_FILENAME) cmd = ("%s/wcc2bbp " % (install.A_GP_BIN_DIR) + "nsfile=%s ewfile=%s udfile=%s " % (nsfile, ewfile, udfile) + "wcc2bbp=0 < %s >> %s 2>&1" % (bbpfile, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) for comp in ['000', '090', 'ver']: # Create path names and check if their sizes are # within bounds filein = os.path.join(a_tmpdir, "temp.acc.%s" % (comp)) fileout = os.path.join(a_tmpdir, "temp.vel.%s" % (comp)) bband_utils.check_path_lengths([filein, fileout], bband_utils.GP_MAX_FILENAME) cmd = ("%s/integ_diff integ=1 " % (install.A_GP_BIN_DIR) + "filein=%s fileout=%s >> %s 2>&1" % (filein, fileout, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) # Create path names and check if their sizes are within bounds nsfile = os.path.join(a_tmpdir, "temp.vel.000") ewfile = os.path.join(a_tmpdir, "temp.vel.090") udfile = os.path.join(a_tmpdir, "temp.vel.ver") vel_bbp_file = os.path.join(a_tmpdir, "temp.%s.vel" % stat) bband_utils.check_path_lengths([nsfile, ewfile, udfile], bband_utils.GP_MAX_FILENAME) cmd = ("%s/wcc2bbp wcc2bbp=1 " % install.A_GP_BIN_DIR + "nsfile=%s ewfile=%s udfile=%s > %s 2>> %s" % (nsfile, ewfile, udfile, vel_bbp_file, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) filename1 = vel_bbp_file # Generate arias duration files for calculated data calc_acc = os.path.join(a_outdir, "%d.%s.acc.bbp" % (sim_id, stat)) calc_peer_n = os.path.join(a_tmpdir, "%d.%s_N.acc" % (sim_id, stat)) calc_peer_e = os.path.join(a_tmpdir, "%d.%s_E.acc" % (sim_id, stat)) calc_peer_z = os.path.join(a_tmpdir, "%d.%s_Z.acc" % (sim_id, stat)) # Convert calculated acc seismogram into peer format bbp_formatter.bbp2peer(calc_acc, calc_peer_n, calc_peer_e, calc_peer_z) # Now calculate arias duration for each component for comp in ["N", "E", "Z"]: file_in = os.path.join(a_tmpdir, "%d.%s_%s.acc" % (sim_id, stat, comp)) file_out = os.path.join( a_tmpdir, "%d.%s_%s.arias" % (sim_id, stat, comp)) arias_duration.ad_from_acc(file_in, file_out) # Generate arias duration files for observed data obs_acc = os.path.join(a_tmpdir_seis, "%s.bbp" % stat) obs_peer_n = os.path.join(a_tmpdir, "obs.%s_N.acc" % (stat)) obs_peer_e = os.path.join(a_tmpdir, "obs.%s_E.acc" % (stat)) obs_peer_z = os.path.join(a_tmpdir, "obs.%s_Z.acc" % (stat)) # Convert observed acc seismogram into peer format bbp_formatter.bbp2peer(obs_acc, obs_peer_n, obs_peer_e, obs_peer_z) # Now calculate arias duration for each component for comp in ["N", "E", "Z"]: file_in = os.path.join(a_tmpdir, "obs.%s_%s.acc" % (stat, comp)) file_out = os.path.join(a_tmpdir, "obs.%s_%s.arias" % (stat, comp)) arias_duration.ad_from_acc(file_in, file_out) # Plot seismograms with arias duration filename2 = os.path.join(a_outdir, "%d.%s.vel.bbp" % (sim_id, stat)) outfile = os.path.join( a_outdir, "%s_%d_%s_overlay.png" % (self.comp_label, sim_id, stat)) obs_arias_n = os.path.join(a_tmpdir, "obs.%s_N.arias" % (stat)) obs_arias_e = os.path.join(a_tmpdir, "obs.%s_E.arias" % (stat)) obs_arias_z = os.path.join(a_tmpdir, "obs.%s_Z.arias" % (stat)) calc_arias_n = os.path.join(a_tmpdir, "%d.%s_N.arias" % (sim_id, stat)) calc_arias_e = os.path.join(a_tmpdir, "%d.%s_E.arias" % (sim_id, stat)) calc_arias_z = os.path.join(a_tmpdir, "%d.%s_Z.arias" % (sim_id, stat)) plot_seismograms.plot_overlay_with_arias( stat, filename1, filename2, obs_arias_n, obs_arias_e, obs_arias_z, calc_arias_n, calc_arias_e, calc_arias_z, self.comp_label, "run %d" % sim_id, outfile) # Now create rd50 comparison plots for site in site_list: stat = site.scode print("==> Plotting RotD50 comparison for station: %s" % (stat)) # Now process rd50 files expected_rd50_file = os.path.join(a_outdir, "%d.%s.rd50" % (sim_id, stat)) if not os.path.exists(expected_rd50_file): # just skip it print("Skipping rotd50/psa5 for station %s..." % (stat)) continue # See if .rd50 file exists for comparison. If it don't # exist, skip it rd50_file = None if ("%s.rd50" % (stat)) in filelist: rd50_file = "%s.rd50" % (stat) else: # Skip this station continue # Plot rotd50 results rd50_filename1 = os.path.join(a_tmpdir_seis, rd50_file) rd50_filename2 = os.path.join(a_outdir, "%d.%s.rd50" % (sim_id, stat)) outfile = os.path.join( a_outdir, "%s_%d_%s_rotd50.png" % (self.comp_label, sim_id, stat)) plot_rotd50.plot_rd50(stat, rd50_filename1, rd50_filename2, self.comp_label, sim_id, outfile, site.low_freq_corner, site.high_freq_corner, quiet=True) print("Generating Plots Completed".center(80, '-'))
def run(self): print("Generating Plots".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]) self.log = os.path.join(install.A_OUT_LOG_DIR, "%d/%d.gen_plots.log" % (sim_id, sim_id)) # 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)) # if self.a_datadir is None: # # When datadir is None, we look for the observation data in # # the tmpdir where the ObsSeismograms module generates them a_tmpdir_seis = os.path.join(install.A_TMP_DATA_DIR, str(sim_id), "obs_seis_%s" % (sta_base)) # Station file a_statfile = os.path.join(install.A_IN_DATA_DIR, str(sim_id), self.r_stations) # List of observed seismogram files filelist = os.listdir(a_tmpdir_seis) slo = StationList(a_statfile) site_list = slo.getStationList() for site in site_list: stat = site.scode # Since we're using the GP station list, make sure the # .bbp for the station exists. It might not if we ran the # validation with a different station list (like UCSB for # Landers) bbpfile = os.path.join(a_tmpdir_seis, "%s.bbp" % stat) expected_file = os.path.join(a_outdir, "%d.%s.vel.bbp" % (sim_id, stat)) if (not os.path.exists(expected_file) or not os.path.exists(bbpfile)): # just skip this station continue print("==> Plotting seismogram comparison for station: %s" % (stat)) if self.format == 'vel': # We have velocity, nothing we need to do filename1 = bbpfile elif self.format == 'acc': # We have acceleration, must integrate first # Create path names and check if their sizes are within bounds nsfile = os.path.join(a_tmpdir, "temp.acc.000") ewfile = os.path.join(a_tmpdir, "temp.acc.090") udfile = os.path.join(a_tmpdir, "temp.acc.ver") bband_utils.check_path_lengths([nsfile, ewfile, udfile], bband_utils.GP_MAX_FILENAME) cmd = ("%s/wcc2bbp " % (install.A_GP_BIN_DIR) + "nsfile=%s ewfile=%s udfile=%s " % (nsfile, ewfile, udfile) + "wcc2bbp=0 < %s >> %s 2>&1" % (bbpfile, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) for comp in ['000', '090', 'ver']: # Create path names and check if their sizes are # within bounds filein = os.path.join(a_tmpdir, "temp.acc.%s" % (comp)) fileout = os.path.join(a_tmpdir, "temp.vel.%s" % (comp)) bband_utils.check_path_lengths([filein, fileout], bband_utils.GP_MAX_FILENAME) cmd = ("%s/integ_diff integ=1 " % (install.A_GP_BIN_DIR) + "filein=%s fileout=%s >> %s 2>&1" % (filein, fileout, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) # Create path names and check if their sizes are within bounds nsfile = os.path.join(a_tmpdir, "temp.vel.000") ewfile = os.path.join(a_tmpdir, "temp.vel.090") udfile = os.path.join(a_tmpdir, "temp.vel.ver") vel_bbp_file = os.path.join(a_tmpdir, "temp.%s.vel" % stat) bband_utils.check_path_lengths([nsfile, ewfile, udfile], bband_utils.GP_MAX_FILENAME) cmd = ("%s/wcc2bbp wcc2bbp=1 " % install.A_GP_BIN_DIR + "nsfile=%s ewfile=%s udfile=%s > %s 2>> %s" % (nsfile, ewfile, udfile, vel_bbp_file, self.log)) bband_utils.runprog(cmd, abort_on_error=True, print_cmd=False) filename1 = vel_bbp_file # Generate arias duration files for calculated data calc_acc = os.path.join(a_outdir, "%d.%s.acc.bbp" % (sim_id, stat)) calc_peer_n = os.path.join(a_tmpdir, "%d.%s_N.acc" % (sim_id, stat)) calc_peer_e = os.path.join(a_tmpdir, "%d.%s_E.acc" % (sim_id, stat)) calc_peer_z = os.path.join(a_tmpdir, "%d.%s_Z.acc" % (sim_id, stat)) # Convert calculated acc seismogram into peer format bbp_formatter.bbp2peer(calc_acc, calc_peer_n, calc_peer_e, calc_peer_z) # Now calculate arias duration for each component for comp in ["N", "E", "Z"]: file_in = os.path.join(a_tmpdir, "%d.%s_%s.acc" % (sim_id, stat, comp)) file_out = os.path.join(a_tmpdir, "%d.%s_%s.arias" % (sim_id, stat, comp)) arias_duration.ad_from_acc(file_in, file_out) # Generate arias duration files for observed data obs_acc = os.path.join(a_tmpdir_seis, "%s.bbp" % stat) obs_peer_n = os.path.join(a_tmpdir, "obs.%s_N.acc" % (stat)) obs_peer_e = os.path.join(a_tmpdir, "obs.%s_E.acc" % (stat)) obs_peer_z = os.path.join(a_tmpdir, "obs.%s_Z.acc" % (stat)) # Convert observed acc seismogram into peer format bbp_formatter.bbp2peer(obs_acc, obs_peer_n, obs_peer_e, obs_peer_z) # Now calculate arias duration for each component for comp in ["N", "E", "Z"]: file_in = os.path.join(a_tmpdir, "obs.%s_%s.acc" % (stat, comp)) file_out = os.path.join(a_tmpdir, "obs.%s_%s.arias" % (stat, comp)) arias_duration.ad_from_acc(file_in, file_out) # Plot seismograms with arias duration filename2 = os.path.join(a_outdir, "%d.%s.vel.bbp" % (sim_id, stat)) outfile = os.path.join(a_outdir, "%s_%d_%s_overlay.png" % (self.comp_label, sim_id, stat)) obs_arias_n = os.path.join(a_tmpdir, "obs.%s_N.arias" % (stat)) obs_arias_e = os.path.join(a_tmpdir, "obs.%s_E.arias" % (stat)) obs_arias_z = os.path.join(a_tmpdir, "obs.%s_Z.arias" % (stat)) calc_arias_n = os.path.join(a_tmpdir, "%d.%s_N.arias" % (sim_id, stat)) calc_arias_e = os.path.join(a_tmpdir, "%d.%s_E.arias" % (sim_id, stat)) calc_arias_z = os.path.join(a_tmpdir, "%d.%s_Z.arias" % (sim_id, stat)) plot_seismograms.plot_overlay_with_arias(stat, filename1, filename2, obs_arias_n, obs_arias_e, obs_arias_z, calc_arias_n, calc_arias_e, calc_arias_z, self.comp_label, "run %d" % sim_id, outfile) # Now create rd50 comparison plots for site in site_list: stat = site.scode print("==> Plotting RotD50 comparison for station: %s" % (stat)) # Now process rd50 files expected_rd50_file = os.path.join(a_outdir, "%d.%s.rd50" % (sim_id, stat)) if not os.path.exists(expected_rd50_file): # just skip it print("Skipping rotd50/psa5 for station %s..." % (stat)) continue # See if .rd50 file exists for comparison. If it don't # exist, skip it rd50_file = None if ("%s.rd50" % (stat)) in filelist: rd50_file = "%s.rd50" % (stat) else: # Skip this station continue # Plot rotd50 results rd50_filename1 = os.path.join(a_tmpdir_seis, rd50_file) rd50_filename2 = os.path.join(a_outdir, "%d.%s.rd50" % (sim_id, stat)) outfile = os.path.join(a_outdir, "%s_%d_%s_rotd50.png" % (self.comp_label, sim_id, stat)) plot_rotd50.plot_rd50(stat, rd50_filename1, rd50_filename2, self.comp_label, sim_id, outfile, site.low_freq_corner, site.high_freq_corner, quiet=True) print("Generating Plots Completed".center(80, '-'))