44 #define NOISYMIZE_VERSION \ 45 "NOISYMIZE V1.6 program reads a set of SFF traces,\n" \ 46 " convolves them with white noise and stacks" 52 #include <tfxx/commandline.h> 53 #include <tfxx/error.h> 54 #include <aff/series.h> 55 #include <aff/seriesoperators.h> 56 #include <tsxx/tsxx.h> 57 #include <tsxx/convolve.h> 58 #include <tsioxx/tsioxx.h> 59 #include <tsxx/random.h> 60 #include <datrwxx/readany.h> 61 #include <datrwxx/sff.h> 91 typedef ts::sff::File<Tseries>
Tfile;
93 int main(
int iargc,
char* argv[])
100 "usage: noisymize Zin Rin Zout Rout" "\n" 101 " [-v] [-type t] [-n n] [-o] [-rf] [-s e]" "\n" 103 " or: noisymize --help|-h" "\n" 109 "Zin vertical component input data" "\n" 110 "Rin radial component input data" "\n" 111 "Zout vertical component output data" "\n" 112 "Rout radial component output data" "\n" 115 "-type t input file type" "\n" 116 "-n n number of noise samples to use" "\n" 117 "-o overwrite output" "\n" 118 "-rf report factors" "\n" 119 "-s e scale seismograms with offset" "\n" 120 " the scaling factor is r**e, where r is the offset" "\n" 121 "-fixed do not scale each offset with a randomly" "\n" 122 " chosen amplitude" "\n" 124 "This program was specifically created to test procedures for\n" 125 "MHVSR (microseismic H/V spectral ratio) analysis by application\n" 126 "to synthetic data. Synthetic seismograms for vertical and radial\n" 127 "component of the receiver calculated for a transient source signal\n" 128 "have to be convolved with the same random noise in this case\n" 130 "Description of the procedure:" "\n" 131 "- the program reads pairs of seismograms from Zin and Rin" "\n" 132 "- each of the input files may contain multiple traces" "\n" 133 "- for each trace in Zin there must be a corresponding trace" "\n" 134 " in Rin at the same offset" "\n" 135 "- for each offset the program does the following:" "\n" 136 " 1. the Z-trace and the R-trace are convolved with the same" "\n" 137 " stochastic time series (random normaly distributed white noise)" "\n" 138 " a new stochastic time series is calculated for each offset" "\n" 139 " through the libgsl random number generator" "\n" 140 " 2. the Z-trace and the R-trace are scaled by a random value" "\n" 141 " (this function can be switched off through option -fixed)" "\n" 142 " 3. the Z-trace and the R-trace are scaled by an offset" "\n" 143 " dependend value (selected through option -s e)" "\n" 144 " 4. the R-trace is scaled by 0.707 to simulate a uniform" "\n" 145 " distribution of sources of all azimuths; as a consequence" "\n" 146 " the R result my be used as N- and E-component as well" "\n" 147 "- the results for all offsets are stacked; the resulting Z-" "\n" 148 " and R-series are written to files Zout and Rout," "\n" 153 using namespace tfxx::cmdline;
154 static Declare options[]=
161 {
"type",arg_yes,
"sff"},
171 {
"fixed",arg_no,
"-"},
178 cerr << usage_text << endl;
183 Commandline cmdline(iargc, argv, options);
186 if (cmdline.optset(0))
188 cerr << usage_text << endl;
189 cerr << help_text << endl;
204 opt.
offexp=cmdline.double_arg(6);
208 TFXX_assert(cmdline.extra(),
"ERROR: missing filename Zin!");
209 filename.
Zin=cmdline.next();
210 TFXX_assert(cmdline.extra(),
"ERROR: missing filename Rin!");
211 filename.
Rin=cmdline.next();
212 TFXX_assert(cmdline.extra(),
"ERROR: missing filename Zout!");
213 filename.
Zout=cmdline.next();
214 TFXX_assert(cmdline.extra(),
"ERROR: missing filename Rout!");
215 filename.
Rout=cmdline.next();
220 { cout <<
"read input file " << filename.
Zin << endl; }
223 std::ifstream ifs(filename.
Zin.c_str());
225 Zindata.read(is.idatstream(), opt.
verbose);
229 { cout <<
"read input file " << filename.
Rin << endl; }
232 std::ifstream ifs(filename.
Rin.c_str());
234 Rindata.read(is.idatstream(), opt.
verbose);
241 if (opt.
verbose) { cout <<
"consistency checks:" << endl; }
244 TFXX_assert(Zindata.size()==Rindata.size(),
245 "ERROR: inconsitent number of traces");
247 { cout <<
"input files both have " << Zindata.size() <<
" traces." << endl; }
250 Tfile::Tbase::const_iterator Zit=Zindata.begin();
251 Tfile::Tbase::const_iterator Rit=Rindata.begin();
252 sff::WID2compare compare(sff::Fnsamples | sff::Fdt);
253 while((Zit!=Zindata.end()) && (Rit!=Rindata.end()))
255 TFXX_assert(compare(Zit->header.wid2(), Rit->header.wid2()),
256 "ERROR: inconsitent trace headers");
257 if (Zit->header.hasinfo())
259 sff::INFO Zinfo=Zit->header.info();
260 sff::INFO Rinfo=Rit->header.info();
261 TFXX_assert(Zinfo==Rinfo,
262 "ERROR: inconsitent coordinates");
268 { cout <<
"trace headers and coordinates are consistent" << endl; }
277 sff::SRCE Zsrce=Zindata.fileheader.srce();
278 sff::SRCE Rsrce=Rindata.fileheader.srce();
282 Tseries fac=ts::rnd::dugauss(Zindata.size());
284 Tseries offfac(Zindata.size());
285 Tseries traceoffset(Zindata.size());
293 cout <<
"convolve " << Zit->size()
294 <<
" data samples (each trace) with" << endl
295 << opt.
noiselength <<
" samples of uniform gaussian noise" 296 <<
" and stack." << endl;
298 bool initialize_result=
true;
299 unsigned int itrace=0;
300 while((Zit!=Zindata.end()) && (Rit!=Rindata.end()))
303 sff::INFO Zinfo=Zit->header.info();
304 sff::INFO Rinfo=Rit->header.info();
305 double Zoffset=sff::offset(Zsrce, Zinfo);
306 double Roffset=sff::offset(Rsrce, Rinfo);
307 double offerr=(Zoffset/Roffset)-1.;
308 if (offerr < 0.) { offerr=-offerr; }
309 TFXX_assert((offerr < 1.e-4),
310 "ERROR: offset of R- and Z-component are inconsistent!");
311 traceoffset(itrace)=Zoffset;
312 offfac(itrace)=std::pow(Zoffset, opt.
offexp);
320 const double Hfactor=0.707;
322 double scalefac=fac(itrace)*offfac(itrace);
323 if (opt.
verbose) { cout <<
"*"; cout.flush(); }
325 if (opt.
verbose) { cout <<
"+"; cout.flush(); }
326 if (initialize_result)
327 { Zseries = scalefac*ts::convolve(*Zit, noise); }
329 { Zseries += scalefac*ts::convolve(*Zit, noise); }
330 if (opt.
verbose) { cout <<
"+"; cout.flush(); }
331 if (initialize_result)
332 { Rseries = Hfactor*scalefac*ts::convolve(*Rit, noise); }
334 { Rseries += Hfactor*scalefac*ts::convolve(*Rit, noise); }
335 initialize_result=
false;
340 if (opt.
verbose) { cout << endl; }
343 cout <<
"factors used for scaling:" << endl;
351 cout <<
"offset" << endl;
352 for (itrace=0; itrace<Zindata.size(); itrace++)
354 cout.width(5); cout.precision(3);
356 cout.width(12); cout.precision(4);
358 cout.width(12); cout.precision(4);
359 cout << offfac(itrace);
360 cout.width(12); cout.precision(4);
361 cout << traceoffset(itrace)*1.e-3 <<
"km";
364 cout <<
"traces are scale by f1*f2" << endl;
370 { cout <<
"prepare output data" << endl; }
371 typedef ts::sff::SFFTimeSeries<Tseries> Tsffseries;
372 Tsffseries::Theader Zheader(Zindata[0].header);
373 Tsffseries::Theader Rheader(Rindata[0].header);
375 sff::WID2 wid2line=Zheader.wid2();
376 wid2line.nsamples=Zseries.size();
377 wid2line.channel=
"Z";
378 Zheader.wid2(wid2line);
379 Tsffseries Zoutdata(Zseries, Zheader);;
381 wid2line=Rheader.wid2();
382 wid2line.nsamples=Rseries.size();
383 wid2line.channel=
"R";
384 Rheader.wid2(wid2line);
385 Tsffseries Routdata(Rseries, Rheader);;
388 if (opt.
verbose) { cout <<
"open output file " << filename.
Zout << endl; }
392 std::ifstream file(filename.
Zout.c_str(),std::ios_base::in);
393 TFXX_assert((!file.good()),
"ERROR: output file exists!");
395 std::ofstream ofs(filename.
Zout.c_str());
396 datrw::osffstream os(ofs);
406 if (opt.
verbose) { cout <<
"open output file " << filename.
Rout << endl; }
410 std::ifstream file(filename.
Rout.c_str(),std::ios_base::in);
411 TFXX_assert((!file.good()),
"ERROR: output file exists!");
413 std::ofstream ofs(filename.
Rout.c_str());
414 datrw::osffstream os(ofs);
#define NOISYMIZE_VERSION
aff::Series< Tvalue > Tseries
ts::sff::File< Tseries > Tfile
int main(int iargc, char *argv[])
aff::Series< double > Tseries
ts::sff::File< Tseries > Tfile