[cig-commits] r13108 - in seismo/3D/ADJOINT_TOMO/iterate_adj/pangu: . scripts

carltape at geodynamics.org carltape at geodynamics.org
Mon Oct 20 19:56:11 PDT 2008


Author: carltape
Date: 2008-10-20 19:56:11 -0700 (Mon, 20 Oct 2008)
New Revision: 13108

Added:
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/README
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_SEM_dir.pl
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_kernel_dir.pl
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_forward_dir.pl
   seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_kernel_dir.pl
Log:
Added setup scripts for launching numerous forward simulations and kernel simulations on pangu.  These have several safety checks to prevent from launching simulations that will crash due to missing files.


Added: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/README
===================================================================
--- seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/README	                        (rev 0)
+++ seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/README	2008-10-21 02:56:11 UTC (rev 13108)
@@ -0,0 +1,26 @@
+Carl Tape, 20-Oct-2008
+
+/ADJOINT_TOMO/iterate_adj/pangu/scripts/README
+
+These scripts are used in setting up the forward simulations and the kernel simulations.
+
+setup_forward_dir.pl
+setup_kernel_dir.pl
+copy_kernel_dir.pl
+copy_SEM_dir.pl
+
+In both cases, they require the directory Master_Dir, which is used to link run directories for all the requested event IDs.  The organization is as follows:
+
+BASIN_KERNEL/
+   setup_kernel_dir.pl
+   Master_Dir/
+   done_dirs/
+       copy_kernel_dir.pl
+
+BASIN_FORWARD/
+   setup_forward_dir.pl
+   Master_Dir/
+   done_dirs/
+       copy_SEM_dir.pl
+
+-----------------------

Added: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_SEM_dir.pl
===================================================================
--- seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_SEM_dir.pl	                        (rev 0)
+++ seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_SEM_dir.pl	2008-10-21 02:56:11 UTC (rev 13108)
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+if (@ARGV < 1) {die("Usage: copy_SEM_dir.pl smodel\n")}
+($smodel) = @ARGV;
+
+#$smodel = "m1";
+
+$basedir = "/net/sierra/raid1/carltape/socal/socal_3D/SYN";
+$mdir = "$basedir/model_${smodel}";
+if (not -e $mdir) {die("check if mdir $mdir exist or not\n")}
+
+ at dirs = `ls -1 -d [1-9]*`;
+$neid = @dirs;
+
+#print "\n @dirs\n";
+
+#$neid = 1;
+
+# loop over all directories
+for ($i = 1; $i <= $neid; $i++) {
+
+  $eid = $dirs[$i-1]; chomp($eid);
+  print "==== $eid =====\n";
+
+  $odir = "$mdir/$eid";
+  if (-e $odir) {
+     die("--> $odir already exists\n");
+  } else {
+     `mkdir $odir`;
+     `cp $eid/SEM/* $odir`;
+  }
+}
+
+#=================================================================


Property changes on: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_SEM_dir.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_kernel_dir.pl
===================================================================
--- seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_kernel_dir.pl	                        (rev 0)
+++ seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_kernel_dir.pl	2008-10-21 02:56:11 UTC (rev 13108)
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+
+#-------------------------
+# copies kernel output files from cluster to disk
+#
+# EXAMPLE: copy_kernel_dir.pl m04 all
+#-------------------------
+
+if (@ARGV < 2) {die("Usage: copy_kernel_dir.pl smodel ftag\n")}
+($smodel,$ftag) = @ARGV;
+
+$basedir = "/net/sierra/raid1/carltape/socal/socal_3D/RUNS";
+if (not -e $basedir) {die("check if basedir $basedir exist or not\n")}
+
+ at dirs = `ls -1 -d [1-9]*`;
+$neid = @dirs;
+
+#print "\n -- @dirs --\n";
+
+#$neid = 1;
+
+# loop over all directories
+for ($i = 1; $i <= $neid; $i++) {
+
+  $eid = $dirs[$i-1]; chomp($eid);
+  print "==== $eid =====\n";
+
+  $odir = "$basedir/$eid/$smodel";
+  if (not -e $odir) {die("odir $odir does not exist\n")}
+
+  # make sure not to overwrite any directories
+  $dir_output = "$odir/OUTPUT_${ftag}";
+  $dir_sem = "$odir/SEM_${ftag}";
+  $dir_mesh = "$odir/MESH_${ftag}";
+  if (-e ${dir_output}) {die("dir_output ${dir_output} already exists\n")}
+  if (-e ${dir_sem}) {die("dir_sem ${dir_sem} already exists\n")}
+  if (-e ${dir_mesh}) {die("dir_mesh ${dir_mesh} already exists\n")}
+
+  # copy files over
+  `cp -r $eid/OUTPUT_FILES ${dir_output}`;
+  `sleep 5s`;
+  `cp -r $eid/SEM/MESH_${ftag} ${dir_mesh}`;
+  `sleep 5s`;
+  `cp -r $eid/SEM/SEM_${ftag} ${dir_sem}`;
+  `sleep 5s`;
+
+}
+
+#=================================================================


Property changes on: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/copy_kernel_dir.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_forward_dir.pl
===================================================================
--- seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_forward_dir.pl	                        (rev 0)
+++ seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_forward_dir.pl	2008-10-21 02:56:11 UTC (rev 13108)
@@ -0,0 +1,122 @@
+#!/usr/bin/perl -w
+
+#
+# EXAMPLE: setup_forward_dir.pl m12 1 300
+#
+
+if (@ARGV < 3) {die("Usage: setup_forward_dir.pl smodel imin imax\n")}
+($smodel,$imin,$imax) = @ARGV;
+
+#-----------------------------------
+# USER INPUT
+
+$master_dir = "/ibrixfs1/home/carltape/BASIN_FORWARD/Master_Dir";
+$scripts_dir = "/ibrixfs1/home/carltape/BASIN_FORWARD/Scripts";
+
+# directory containing CMTSOLUTION files for all events
+$cmt_dir = "/ibrixfs1/home/carltape/CMT/CMT_files_pre_inverted";
+
+# directory containing finished synthetics
+$done_dir = "/net/sierra/raid1/carltape/socal/socal_3D/SYN/model_${smodel}";
+
+# list of ALL event IDs and simulation durations
+$event_list = "/ibrixfs1/home/carltape/CMT/EIDs_simulation_duration";
+
+# list of EIDs of events for which you want synthetics
+$eid_list = "/net/sierra/raid1/carltape/results/EID_LISTS/syn_run_${smodel}";
+
+#-----------------------------------
+
+# read in the list of ALL event IDs and simulation durations
+$event_list = "/ibrixfs1/home/carltape/CMT/EIDs_simulation_duration";
+open(IN,"${event_list}"); @lines = <IN>; close(IN);
+$neid = @lines;
+
+# read in list of synthetics for which you want synthetics
+if (not -f ${eid_list}) {print "\n check if eid_list ${eid_list} exists\n";}
+open(IN,"${eid_list}"); @keids = <IN>; close(IN);
+$nrun = @keids;
+
+# half-duration for the simulation
+$hdur = 0;
+
+if ($imax > $neid) {$imax = $neid;}
+
+# loop over all events
+for ($i = $imin; $i <= $imax; $i++) {
+
+  ($index,$eid,$sdur_round,$dur) = split(" ",$lines[$i-1]);
+  print "\n $i : $eid";
+
+  # find the matching EID in the subset list
+  $imatch = 0;
+  for ($j = 1; $j <= $nrun; $j++) {
+    $keid = $keids[$j-1];
+    if ($eid == $keid) {
+      $imatch = $imatch+1;
+    }
+  }
+
+  if ($imatch == 0) {
+    print "\n --> no match in EID list";
+
+  } else {
+
+    $dir1 = $eid;
+    $dir2 = "done_dirs/${eid}";
+
+    if ( (-e "${done_dir}/$eid") || (-e $dir1 || -e $dir2 ) ) {
+      print "\n --> event has already been setup or done";
+
+    } else {
+
+      $cmtfile = "${cmt_dir}/CMTSOLUTION_$eid";
+      if (not -f $cmtfile) {
+	print "\n --> cmtfile does not exist";
+
+      } else {
+
+	# copy in a new CMTSOLUTION
+	$cmtfile1 = "$eid/DATA/CMTSOLUTION";
+	`${scripts_dir}/copy_basin_sem_dir.bash ${master_dir} $eid`;
+	`cp $cmtfile $cmtfile1`;
+      
+	# change the half-duration
+	$hdur_st = sprintf("%8.4f",$hdur);
+	$ctemp   = "${cmtfile}_temp";
+	`sed '/^half duration:/s/^.*\$/half duration: ${hdur_st}/' $cmtfile1 > $ctemp`;
+	`mv $ctemp $cmtfile1`;
+
+	# change the simulation time in the Par_file
+	$sdur = sprintf("%.1f",$sdur_round);
+	$parfile = "$eid/DATA/Par_file";
+	$ptemp   = "$eid/DATA/Par_file_temp";
+	`sed '/^RECORD_LENGTH_IN_SECONDS        =/s/^.*\$/RECORD_LENGTH_IN_SECONDS        = $sdur/' $parfile > $ptemp`;
+	`mv $ptemp $parfile`;
+
+	# change the label for the run
+	`sed "/socal_earthquakes/s/socal_earthquakes/${eid}_earthquake/" $eid/go_mesher_solver_lsf_basin.bash > $eid/run.tmp`;
+	`mv -f $eid/run.tmp $eid/go_mesher_solver_lsf_basin.bash`;
+      }
+    }
+  }
+}
+
+
+#--------------------
+#Master_dir=/ibrixfs1/home/carltape/BASIN_FORWARD/Master_Dir
+#Scripts_dir=/ibrixfs1/home/carltape/BASIN_FORWARD/Scripts
+#
+#for eid in `cat /ibrixfs1/home/carltape/CMT/test_events`; do
+#
+# mkdir -p $eid
+#
+# echo "==== $eid ====="
+#
+# ${Scripts_dir}/copy_basin_sem_dir.bash ${Master_dir} $eid
+# cp /ibrixfs1/home/carltape/CMT/CMT_files/CMTSOLUTION_$eid $eid/DATA/CMTSOLUTION
+#
+#done
+#--------------------
+
+#=================================================================


Property changes on: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_forward_dir.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_kernel_dir.pl
===================================================================
--- seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_kernel_dir.pl	                        (rev 0)
+++ seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_kernel_dir.pl	2008-10-21 02:56:11 UTC (rev 13108)
@@ -0,0 +1,186 @@
+#!/usr/bin/perl -w
+
+#-----------------------------------
+# Carl Tape, 03-Oct-2008
+# setup_kernel_dir.pl
+#
+# This script ...
+#
+# INPUT
+#    smodel    model within the CG iteration (m0, m0t, m1, etc)
+#    hdur_lab  label for the measurements (T02, T06, all)
+#    nstat     minimum number of stations to use
+# 
+# EXAMPLE:
+#    setup_kernel_dir.pl m00 all 10
+#    setup_kernel_dir.pl m01 all 10
+#
+#-----------------------------------
+
+if (@ARGV < 3) {die("Usage: setup_kernel_dir.pl model dir_suffix nstat\n")}
+($smodel,$hdur_lab,$nstat) = @ARGV;
+
+$master_dir = "/ibrixfs1/home/carltape/BASIN_KERNEL/Master_Dir";
+$scripts_dir = "/ibrixfs1/home/carltape/BASIN_KERNEL/Scripts";
+
+# directory containing SEM-inverted CMTSOLUTION files
+$cmt_dir = "/ibrixfs1/home/carltape/CMT/CMT_files_pre_inverted";
+
+# directory containing window files, measurement files, adjoint sources, etc
+$run_dir = "/net/sierra/raid1/carltape/socal/socal_3D/RUNS";
+
+# read in the list of ALL event IDs and simulation durations
+$event_list = "/home/carltape/CMT/EIDs_simulation_duration";
+open(IN,"${event_list}"); @lines = <IN>; close(IN);
+$neid = @lines;
+
+# read in list of kernels that will be used for this model update
+$ker_list = "/net/sierra/raid1/carltape/results/EID_LISTS/kernels_run_${smodel}";
+if (not -f ${ker_list}) {print "\n check if ker_list ${ker_list} exists\n";}
+open(IN,"${ker_list}"); @keids = <IN>; close(IN);
+$nker = @keids;
+
+if (0==1) {
+  print "\n ALL EVENTS \n";
+  for ($i = 1; $i <= $neid; $i++) {
+    ($index,$eid,$sdur_round,$nstep,$hdur,$dur,$mw) = split(" ",$lines[$i-1]);
+    print "\n $i : $eid";
+
+  }
+  die("testing");
+}
+
+$imin = 1; $imax = $neid;    # default
+#$imin = 1; $imax = 10;
+#$imin = 19; $imax = $imin;
+
+#===================================
+
+for ($i = $imin; $i <= $imax; $i++) {
+
+  ($index,$eid,$sdur_round,$nstep,$hdur,$dur,$mw) = split(" ",$lines[$i-1]);
+  print "$i : $eid\n";
+
+  # setup only the EIDs that are in the subset list
+  $imatch = 0;
+  for ($j = 1; $j <= $nker; $j++) {
+    $keid = $keids[$j-1];
+    if ($eid == $keid) {
+      $imatch = $imatch+1;
+    }
+  }
+
+  if ($imatch == 0) {
+    print "--> no match in kernel list\n";
+
+  } else {
+
+    $run_dir_eid = "${run_dir}/${eid}/${smodel}";
+    $cmtfile = "${cmt_dir}/CMTSOLUTION_$eid";
+
+    if (not -f $cmtfile) {
+      print "--> cmtfile does not exist\n";
+    } else {
+
+      if ( -e $eid || -e "done_dirs/${eid}" ) {
+	print "--> kernel simulation has been setup or has been done\n";
+      
+      } else {
+
+	# output directories on denali
+	$output_dir = "${run_dir_eid}/OUTPUT_${hdur_lab}";
+	$adj_dir = "${run_dir_eid}/ADJOINT_${hdur_lab}";
+
+	if (-e $output_dir) {
+	  print "--> kernel simulation has been run\n";
+
+	} else {
+         
+	  if (not -e "${adj_dir}") {
+	    print "--> measurement code has not been run\n";
+
+	  } else {
+	    $nadj = `ls -1 ${adj_dir}/*adj | wc | awk '{print \$1}'`; chomp($nadj);
+	    $nstat_adj = $nadj/3;
+	    print "--> number of adjoint sources/stations : $nadj/$nstat_adj\n";
+
+	    if ($nstat_adj < $nstat) {
+	      print "--> fewer than $nstat stations\n";
+	    } else {
+	      print "--> LET'S RUN THIS EVENT!\n";
+
+	      #----------------------------
+
+	      # replicate the master directory
+	      `${scripts_dir}/copy_basin_sem_dir.bash ${master_dir} $eid`;
+
+	      # copy in a new CMTSOLUTION
+	      $cmtfile0 = "$cmtfile";
+	      $cmtfile1 = "$eid/DATA/CMTSOLUTION";
+	      `cp $cmtfile0 $cmtfile1`; 
+
+	      # change the half-duration
+	      #$hdur_st = sprintf("%8.4f",$hdur);
+	      #$ctemp   = "${cmtfile1}_temp";
+	      #`sed '/^half duration:/s/^.*\$/half duration: ${hdur_st}/' $cmtfile1 > $ctemp`;
+	      #`mv $ctemp $cmtfile1`;
+
+	      # change the simulation TYPE in the Par_file
+	      `change_simulation_type2.pl -F`;
+
+	      # change the simulation TIME in the Par_file
+	      #$sdur_round = 5;   # testing only
+	      $sdur = sprintf("%.1f",$sdur_round);
+	      $parfile = "$eid/DATA/Par_file";
+	      $ptemp   = "$eid/DATA/Par_file_temp";
+	      `sed '/^RECORD_LENGTH_IN_SECONDS        =/s/^.*\$/RECORD_LENGTH_IN_SECONDS        = $sdur/' $parfile > $ptemp`;
+	      `mv $ptemp $parfile`;
+
+	      # make sure attenuation is OFF
+	      `sed '/^ATTENUATION                     =/s/^.*\$/ATTENUATION                     = .false./' $parfile > $ptemp`; 
+	      `mv $ptemp $parfile`;
+
+	      # copy the STATIONS file
+	      $stafile = "${adj_dir}/STATIONS_ADJOINT";
+	      `cp $stafile $eid/DATA/STATIONS`;
+	      `cp $stafile $eid/DATA/STATIONS_ADJOINT`;
+
+	      # number of stations
+	      $ns = `sed -n 1p $eid/DATA/STATIONS`;
+	      $nadj1 = 3*$ns;
+
+	      # copy adjoint sources
+	      `rm $eid/SEM/*adj`;
+	      print "\n copying the adjoint sources onto pangu...\n";
+	      `cp ${adj_dir}/*adj $eid/SEM`;
+
+	      # check that all the adjoint sources are there
+	      $nadj2 = `ls -1 $eid/SEM/*adj | wc | awk '{print \$1}'`; chomp($nadj2);
+	      print "\n NUMBER OF RECORDS -- $nadj1 $nadj2 --";
+	      if ($nadj1 != $nadj2) {
+		die("Check adjoint sources: $nadj1 does not equal $nadj2");
+	      }
+
+	      # make directories (and remove old ones)
+	      $sem_dir = "$eid/SEM/SEM_${hdur_lab}";
+	      $output_dir = "$eid/SEM/OUTPUT_${hdur_lab}";
+	      $mesh_dir = "$eid/SEM/MESH_${hdur_lab}";
+	      `rm -r $eid/SEM/SEM_*    ; mkdir ${sem_dir}`;
+	      `rm -r $eid/SEM/OUTPUT_* ; mkdir ${output_dir}`;
+	      `rm -r $eid/SEM/MESH_*   ; mkdir ${mesh_dir}`;
+
+	      # change the label for the run
+	      `sed "/socal_kernel/s/socal_kernel/${eid}_kernel/" $eid/go_kernel.bash > $eid/run.tmp`;
+	      `mv -f $eid/run.tmp $eid/go_kernel.bash`;
+
+	      #----------------------------
+
+	    }
+	  }
+	}
+      }
+    }
+  }
+}				# for loop
+
+#=================================================================


Property changes on: seismo/3D/ADJOINT_TOMO/iterate_adj/pangu/scripts/setup_kernel_dir.pl
___________________________________________________________________
Name: svn:executable
   + *



More information about the CIG-COMMITS mailing list