36 #define FIDASEXX_VERSION \ 37 "FIDASEXX V1.2 FIt DAtaSEts - a C++ successor of fidase" 51 #include <tfxx/commandline.h> 52 #include <tfxx/xcmdline.h> 55 #include <tfxx/error.h> 56 #include <tfxx/misc.h> 59 #include <tfxx/seitosh.h> 62 #include <tfxx/rangestring.h> 63 #include <tfxx/rangelist.h> 66 #include <aff/series.h> 69 #include <datrwxx/readany.h> 70 #include <datrwxx/writeany.h> 73 #include <linearxx/matrix.h> 74 #include <linearxx/lapackxx.h> 75 #include <linearxx/operators.h> 78 #include <aff/functions/rms.h> 79 #include <aff/functions/max.h> 80 #include <aff/functions/min.h> 82 #include <aff/seriesoperators.h> 85 #include <pgplotxx/affpgplot.h> 187 int main(
int iargc,
char* argv[])
194 "usage: fidasexx [-v] [-DEBUG] [-type f] [-plot[=dev]]" "\n" 195 " [-overwrite] [-write[=prefix]] [-rmin r] [-rmax r]" "\n" 196 " file [t:l] [f:t] file [t:l] [f:t] [file [t:l] [f:t]...]" "\n" 197 " or: fidasexx --help|-h" "\n" 198 " or: fidasexx --xhelp" "\n" 205 "-DEBUG produce debug output\n" 206 "-type f read and write files of file type \"f\"\n" 207 "-plot[=dev] produce graphical display on PGPLOT device \"dev\"\n" 208 " the specification of \"dev\" is optional\n" 209 "-overwrite overwrite output files in case they already exist\n" 211 " write scaled files; prepend \"prefix\" to file names\n" 212 " to distinguish scaled files and original files\n" 213 "-rmin r use only traces with offset equal or larger than \"r\"\n" 214 "-rmax r use only traces with offset equal or less than \"r\"\n" 216 "The program expects at least two input files containing seismic data.\n" 217 "Each of the input files is understood to contain data from one single\n" 218 "and unique shot. File specific parameters:\n" 220 "t:l use only traces from list \"l\" for evaluation\n" 221 " \"l\" may be somtehing like \"2-4,5,7,11\"\n" 222 " all traces are read, tapered and written to the\n" 223 " output; but only traces in range indicated by\n" 224 " \"l\" are used to infer the scaling factor\n" 225 "f:t file has data file type \"t\" instead of the\n" 226 " global format specified by the argument to\n" 229 "The program is used to scale data from independent shots to make the\n" 230 "apparent shot amplitude comparable. fidasexx uses a different strategy.\n" 231 "While fidase tries to find optimal scaling factors such that the amplitude\n" 232 "decay with offset is smooth as measured by second differences of rms\n" 233 "values, fidasexx fits the rms values to an explicit amplitude decay with\n" 234 "offset. The underlying model is that rms-values depend on offset r\n" 236 " rms(r) = A0 * r**(K),\n" 237 "where r**(K) means \"r to the power of K\".\n" 239 "If d_(j,k) is the rms value of trace k in file j and r_(j,k) are the\n" 240 "offset of trace k in file j, we search for factors f_j and K such that\n" 241 "the residuals r_(j,k) = log d_(j,k) - (log f_j + K * log r_(j,k))\n" 242 "are minimized in a least squares sense.\n" 246 using namespace tfxx::cmdline;
247 static Declare options[]=
252 {
"xhelp",arg_no,
"-"},
256 {
"DEBUG",arg_no,
"-"},
258 {
"type",arg_yes,
"sff"},
260 {
"plot",arg_opt,
"/xserve"},
262 {
"overwrite",arg_no,
"-"},
264 {
"write",arg_opt,
"scaled_"},
266 {
"rmin",arg_yes,
"0."},
268 {
"rmax",arg_yes,
"1.e15"},
275 cerr << usage_text << endl;
276 cerr << tfxx::seitosh::repository_reference << endl;
285 Commandline cmdline(iargc, argv, options);
288 if (cmdline.optset(0))
290 cerr << usage_text << endl;
291 cerr << help_text << endl;
292 datrw::supported_data_types(cerr);
293 pgplot::basic_device::ldev();
294 cerr << endl << tfxx::seitosh::repository_reference << endl;
299 if (cmdline.optset(1))
301 cerr << usage_text << endl;
303 datrw::online_help(cerr);
304 cerr << endl << tfxx::seitosh::repository_reference << endl;
311 opt.
debug=cmdline.optset(3);
313 opt.
doplot=cmdline.optset(5);
318 opt.
rrange.min=cmdline.float_arg(8);
319 opt.
rrange.max=cmdline.float_arg(9);
328 TFXX_assert(cmdline.extra(),
"missing input file");
329 tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline,
cmdlinekeys);
340 tfxx::cmdline::Tparsed::const_iterator infilearg=arguments.begin();
341 while (infilearg != arguments.end())
350 if (opt.
verbose) { cout <<
"open input file " << infile.
filename << endl; }
360 std::ios_base::openmode iopenmode
361 =datrw::ianystream::openmode(inputformat);
363 std::ifstream ifs(infile.
filename.c_str(), iopenmode);
365 datrw::ianystream is(ifs, inputformat);
377 bool doselect=infilearg->haskey(
tracekey);
380 typedef tfxx::RangeList<int> Trangelist;
381 Trangelist traceranges=
382 tfxx::string::rangelist<Trangelist::Tvalue>(infilearg->value(
tracekey));
406 trace.
selected=(((!doselect) || traceranges.contains(itrace))
407 && opt.
rrange.contains(sff::offset(infile.
srce,
411 infile.
traces.push_back(trace);
418 files.push_back(infile);
430 cout <<
"input files are read..." << endl;
431 cout <<
"next: count traces" << endl;
446 Tvecoffiles::const_iterator F=files.begin();
447 while (F!=files.end())
455 Tvecoftraces::const_iterator T=F->traces.begin();
456 while (T != F->traces.end())
459 if (T->selected) { ++ntraces; ++ninthisfile; }
465 TFXX_assert(ninthisfile>0,
466 "ERROR: at least one trace per file has to be selected");
473 TFXX_assert(nfiles>1,
"ERROR: we require at least two files!");
479 cout <<
"number of files: " << nfiles << endl;
480 cout <<
"total number of traces to be used: " << ntraces << endl;
481 cout <<
"next: set up system of linear equations" << endl;
511 linear::TDmatrix m(nfiles+1);
515 linear::TDmatrix d(ntraces);
519 linear::TDmatrix r(ntraces);
523 typedef std::vector<int> Tvecofint;
524 Tvecofint fileindex(ntraces);
527 linear::TDmatrix D(ntraces, nfiles+1);
532 int itrace=d.first(0);
536 for (
unsigned int i=0; i<files.size(); ++i)
539 const File& currentfile=files[i];
541 for (
unsigned int j=0; j<currentfile.
traces.size(); ++j)
549 TFXX_assert(itrace<=d.last(0),
550 "ERROR: illegal vector index - inconsistency in program");
552 d(itrace)=std::log(aff::func::rms(currenttrace.
series));
553 r(itrace)=sff::offset(currentfile.
srce,currenttrace.
info);
555 TFXX_assert(r(itrace)>1.e-6,
556 "ERROR: offset is unreasonably small (possibly zero)");
557 D(itrace,i+D.first(1))=1.;
558 D(itrace,D.last(1))=std::log(r(itrace));
559 fileindex[itrace-d.first(0)]=i;
569 cout <<
"system of linear equations is ready" << endl;
574 linear::TDmatrix M=linear::op::dotNxM(linear::op::transposeNxM(D),D);
575 linear::TDmatrix R=linear::op::dotNxM(linear::op::transposeNxM(D),d);
579 m=linear::lapack::dposv(M,R);
583 Tvalue firstamp=std::exp(m(m.first(0)));
584 for (
int i=0; i<=factor.last(); ++i)
586 factor(i)=firstamp/std::exp(m(m.first(0)+i));
588 Tvalue attenuation=m(m.last(0));
592 cout <<
"system of linear equations is solved" << endl;
593 cout <<
"power-law attentuation exponent is " << attenuation << endl;
599 pgplot::Trange offsetrange(0.,0.), rmsrange(0.,0.);
603 for (
unsigned int i=0; i<files.size(); ++i)
605 File& currentfile=files[i];
610 cout <<
"scale file #" <<i+1 <<
" " 611 << currentfile.
filename <<
" by " << factor(i) << endl;
613 for (
unsigned int j=0; j<currentfile.
traces.size(); ++j)
615 currentfile.
traces[j].series *= factor(i);
616 currentfile.
offset(j)=std::log10(sff::offset(currentfile.
srce,
617 currentfile.
traces[j].info));
618 currentfile.
rms(j)=std::log10(aff::func::rms(currentfile.
traces[j].series));
624 offsetrange=pgplot::pgaff::series_value_range(currentfile.
offset);
625 rmsrange=pgplot::pgaff::series_value_range(currentfile.
rms);
629 offsetrange.extend(pgplot::pgaff::series_value_range(currentfile.
offset));
630 rmsrange.extend(pgplot::pgaff::series_value_range(currentfile.
rms));
642 dev.env(pgplot::Trect(offsetrange,rmsrange), 0, 30);
643 dev.lab(
"offset / m",
"rms value",
"rms amplitude of scaled traces");
644 for (
unsigned int i=0; i<files.size(); ++i)
646 File& currentfile=files[i];
647 pgplot::pgaff::pt(dev, currentfile.
offset, currentfile.
rms, 2+i);
652 for (
int i=0; i<npts; ++i)
654 x(i)=offsetrange.min+i*offsetrange.fullrange()/(npts-1);
655 y(i)=std::log10(firstamp)+attenuation*x(i);
657 pgplot::pgaff::line(dev, x, y);
667 if (opt.
verbose) { cout <<
"write scaled files" << endl; }
669 for (
unsigned int i=0; i<files.size(); ++i)
671 File& currentfile=files[i];
675 cout <<
"write file " << ofilename << endl;
679 std::ostringstream oss;
680 oss <<
"scaled by factor " << factor(i)
681 <<
"; decay constant is " << attenuation;
685 currentfile.
free.append(oss.str());
688 std::ios_base::openmode oopenmode
690 std::ofstream ofs(ofilename.c_str(), oopenmode);
694 if (os.handlessrce()) { os << currentfile.
srce; }
695 if (os.handlesfilefree()) { os << currentfile.
free; }
698 for (
unsigned int j=0; j<currentfile.
traces.size(); ++j)
702 cout <<
" write trace #" << j+1 << endl;
707 currenttrace.
free.append(oss.str());
709 os << currenttrace.
wid2;
710 if (os.handlesinfo()) { os << currenttrace.
info; }
711 if (os.handlesfilefree()) { os << currenttrace.
free; }
712 os << currenttrace.
series;
aff::Series< Tvalue > Tseries
static const char tracekey[]
int main(int iargc, char *argv[])
static const char * cmdlinekeys[]
static const char formatkey[]
std::vector< File > Tvecoffiles
pgplot::pgaff::Tseries rms
std::vector< Trace > Tvecoftraces
aff::Series< double > Tseries
pgplot::pgaff::Tseries offset