lib/App/SeismicUnixGui/sunix/filter/sumedian.pm untested

filter: Statementstmt 0.0% 0 / 126 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 190 CC 14 SCAR 16.2
CC
14
Cov
0%
key
6.0
median
6.0
mix
6.0
CRAP 5.1
1 package App::SeismicUnixGui::sunix::filter::sumedian;
2  
3 =head2 SYNOPSIS
4  
5 PERL PROGRAM NAME:
6  
7 AUTHOR: Juan Lorenzo (Perl module only)
8  
9 DATE:
10  
11 DESCRIPTION:
12  
13 Version:
14  
15 =head2 USE
16  
17 =head3 NOTES
18  
19 =head4 Examples
20  
21 =head2 SYNOPSIS
22  
23 =head3 SEISMIC UNIX NOTES
24 SUMEDIAN - MEDIAN filter about a user-defined polygonal curve with
25  
26 the distance along the curve specified by key header word
27  
28  
29  
30 sumedian <stdin >stdout xshift= tshift= [optional parameters]
31  
32  
33  
34 Required parameters:
35  
36 xshift= array of position values as specified by
37  
38 the `key' parameter
39  
40 tshift= array of corresponding time values (sec)
41  
42 ... or input via files:
43  
44 nshift= number of x,t values defining median times
45  
46 xfile= file containing position values as specified by
47  
48 the `key' parameter
49  
50 tfile= file containing corresponding time values (sec)
51  
52  
53  
54 Optional parameters:
55  
56 key=tracl Key header word specifying trace number
57  
58 =offset use trace offset instead
59  
60  
61  
62 mix=.6,1,1,1,.6 array of weights for mix (weighted moving average)
63  
64 median=0 =0 for mix
65  
66 =1 for median filter
67  
68 nmed=5 odd no. of traces to median filter
69  
70 sign=-1 =-1 for upward shift
71  
72 =+1 for downward shift
73  
74 subtract=1 =1 subtract filtered data from input
75  
76 =0 don't subtract
77  
78 verbose=0 =1 echoes information
79  
80  
81  
82 tmpdir= if non-empty, use the value as a directory path
83  
84 prefix for storing temporary files; else if the
85  
86 the CWP_TMPDIR environment variable is set use
87  
88 its value for the path; else use tmpfile()
89  
90  
91  
92 Notes:
93  
94 ------
95  
96 Median filtering is a process for suppressing a particular moveout on
97  
98 seismic sections. Its advantage over traditional dip filtering is that
99  
100 events with arbitrary moveout may be suppressed. Median filtering is
101  
102 commonly used in up/down wavefield separation of VSP data.
103  
104  
105  
106 The process generally consists of 3 steps:
107  
108 1. A copy of the data panel is shifted such that the polygon in x,t
109  
110 specifying moveout is flattened to horizontal. The x,t pairs are
111  
112 specified either by the vector xshift,tshift or by the values in
113  
114 the datafiles xfile,tfile. For fractional shift, the shifted data
115  
116 is interpolated.
117  
118 2. Then a mix (weighted moving average) is performed over the shifted
119  
120 panel to emphasize events with the specified moveout and suppress
121  
122 events with other moveouts.
123  
124 3. The panel is then shifted back (and interpolated) to its original
125  
126 moveout, and subtracted from the original data. Thus all events
127  
128 with the user-specified moveout are removed.
129  
130  
131  
132 For VSP data the following modifications are provided:
133  
134 1. The moveout polygon in x,t is usually the first break times for
135  
136 each trace. The parameter sign allows for downward shift in order
137  
138 align upgoing events.
139  
140 2. Alternative to a mix, a median filter can be applied by setting
141  
142 the parameter median=1 and nmed= to the number of traces filtered.
143  
144 3. By setting subtract=0 the filtered panel is only shifted back but
145  
146 not subtracted from the original data.
147  
148  
149  
150 The values of tshift are linearly interpolated for traces falling
151  
152 between given xshift values. The tshift interpolant is extrapolated
153  
154 to the left by the smallest time sample on the trace and to the right
155  
156 by the last value given in the tshift array.
157  
158  
159  
160 The files tfile and xfile are files of binary (C-style) floats.
161  
162  
163  
164 The number of values defined by mix=val1,val2,... determines the
165  
166 number of traces to be averaged, the values determine the weights.
167  
168  
169  
170 Caveat:
171  
172 The median filter may perform poorly on the edges of a section.
173  
174 Choosing larger beginning and ending mix values may help, but may
175  
176 also introduce additional artifacts.
177  
178  
179  
180 Examples:
181  
182  
183  
184  
185  
186  
187  
188 Credits:
189  
190  
191  
192 CWP: John Stockwell, based in part on sumute, sureduce, sumix
193  
194 CENPET: Werner M. Heigl - fixed various errors, added VSP functionality
195  
196  
197  
198 U of Durham, UK: Richard Hobbs - fixed the program so it applies the
199  
200 median filter
201  
202 ideas for improvement:
203  
204 a versatile median filter needs to do:
205  
206 shift traces by fractional amounts -> needs sinc interpolation
207  
208 positive and negative shifts similar to SUSTATIC
209  
210 make subtraction of filtered events a user choice
211  
212 provide a median stack as well as a weighted average stack
213  
214 Trace header fields accessed: ns, dt, delrt, key=keyword
215  
216  
217  
218  
219  
220 =head2 User's notes (Juan Lorenzo)
221 untested
222  
223 =cut
224  
225  
226 =head2 CHANGES and their DATES
227  
228 =cut
229  
230 use Moose;
231 our $VERSION = '0.0.1';
232  
233  
234 =head2 Import packages
235  
236 =cut
237  
238 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
239  
240 use App::SeismicUnixGui::misc::SeismicUnix qw($go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su);
241 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
242  
243  
244 =head2 instantiation of packages
245  
246 =cut
247  
248 my $get = L_SU_global_constants->new();
249 my $Project = Project_config->new();
250 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
251 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
252 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
253  
254 my $PS_SEISMIC = $Project->PS_SEISMIC();
255  
256 my $var = $get->var();
257 my $on = $var->{_on};
258 my $off = $var->{_off};
259 my $true = $var->{_true};
260 my $false = $var->{_false};
261 my $empty_string = $var->{_empty_string};
262  
263 =head2 Encapsulated
264 hash of private variables
265  
266 =cut
267  
268 my $sumedian = {
269 _key => '',
270 _median => '',
271 _mix => '',
272 _nmed => '',
273 _nshift => '',
274 _sign => '',
275 _subtract => '',
276 _tfile => '',
277 _tmpdir => '',
278 _tshift => '',
279 _verbose => '',
280 _xfile => '',
281 _xshift => '',
282 _Step => '',
283 _note => '',
284  
285 };
286  
287 =head2 sub Step
288  
289 collects switches and assembles bash instructions
290 by adding the program name
291  
292 =cut
293  
294 sub Step {
295  
296 $sumedian->{_Step} = 'sumedian'.$sumedian->{_Step};
297 return ( $sumedian->{_Step} );
298  
299 }
300  
301  
302 =head2 sub note
303  
304 collects switches and assembles bash instructions
305 by adding the program name
306  
307 =cut
308  
309 sub note {
310  
311 $sumedian->{_note} = 'sumedian'.$sumedian->{_note};
312 return ( $sumedian->{_note} );
313  
314 }
315  
316  
317  
318 =head2 sub clear
319  
320 =cut
321  
322 sub clear {
323  
324 $sumedian->{_key} = '';
325 $sumedian->{_median} = '';
326 $sumedian->{_mix} = '';
327 $sumedian->{_nmed} = '';
328 $sumedian->{_nshift} = '';
329 $sumedian->{_sign} = '';
330 $sumedian->{_subtract} = '';
331 $sumedian->{_tfile} = '';
332 $sumedian->{_tmpdir} = '';
333 $sumedian->{_tshift} = '';
334 $sumedian->{_verbose} = '';
335 $sumedian->{_xfile} = '';
336 $sumedian->{_xshift} = '';
337 $sumedian->{_Step} = '';
338 $sumedian->{_note} = '';
339 }
340  
341  
342 =head2 sub key
343  
344  
345 =cut
346  
347 sub key {
348  
349 my ( $self,$key ) = @_;
350 if ( $key ne $empty_string ) {
351  
352 $sumedian->{_key} = $key;
353 $sumedian->{_note} = $sumedian->{_note}.' key='.$sumedian->{_key};
354 $sumedian->{_Step} = $sumedian->{_Step}.' key='.$sumedian->{_key};
355  
356 } else {
357 print("sumedian, key, missing key,\n");
358 }
359 }
360  
361  
362 =head2 sub median
363  
364  
365 =cut
366  
367 sub median {
368  
369 my ( $self,$median ) = @_;
370 if ( $median ne $empty_string ) {
371  
372 $sumedian->{_median} = $median;
373 $sumedian->{_note} = $sumedian->{_note}.' median='.$sumedian->{_median};
374 $sumedian->{_Step} = $sumedian->{_Step}.' median='.$sumedian->{_median};
375  
376 } else {
377 print("sumedian, median, missing median,\n");
378 }
379 }
380  
381  
382 =head2 sub mix
383  
384  
385 =cut
386  
387 sub mix {
388  
389 my ( $self,$mix ) = @_;
390 if ( $mix ne $empty_string ) {
391  
392 $sumedian->{_mix} = $mix;
393 $sumedian->{_note} = $sumedian->{_note}.' mix='.$sumedian->{_mix};
394 $sumedian->{_Step} = $sumedian->{_Step}.' mix='.$sumedian->{_mix};
395  
396 } else {
397 print("sumedian, mix, missing mix,\n");
398 }
399 }
400  
401  
402 =head2 sub nmed
403  
404  
405 =cut
406  
407 sub nmed {
408  
409 my ( $self,$nmed ) = @_;
410 if ( $nmed ne $empty_string ) {
411  
412 $sumedian->{_nmed} = $nmed;
413 $sumedian->{_note} = $sumedian->{_note}.' nmed='.$sumedian->{_nmed};
414 $sumedian->{_Step} = $sumedian->{_Step}.' nmed='.$sumedian->{_nmed};
415  
416 } else {
417 print("sumedian, nmed, missing nmed,\n");
418 }
419 }
420  
421  
422 =head2 sub nshift
423  
424  
425 =cut
426  
427 sub nshift {
428  
429 my ( $self,$nshift ) = @_;
430 if ( $nshift ne $empty_string ) {
431  
432 $sumedian->{_nshift} = $nshift;
433 $sumedian->{_note} = $sumedian->{_note}.' nshift='.$sumedian->{_nshift};
434 $sumedian->{_Step} = $sumedian->{_Step}.' nshift='.$sumedian->{_nshift};
435  
436 } else {
437 print("sumedian, nshift, missing nshift,\n");
438 }
439 }
440  
441  
442 =head2 sub sign
443  
444  
445 =cut
446  
447 sub sign {
448  
449 my ( $self,$sign ) = @_;
450 if ( $sign ne $empty_string ) {
451  
452 $sumedian->{_sign} = $sign;
453 $sumedian->{_note} = $sumedian->{_note}.' sign='.$sumedian->{_sign};
454 $sumedian->{_Step} = $sumedian->{_Step}.' sign='.$sumedian->{_sign};
455  
456 } else {
457 print("sumedian, sign, missing sign,\n");
458 }
459 }
460  
461  
462 =head2 sub subtract
463  
464  
465 =cut
466  
467 sub subtract {
468  
469 my ( $self,$subtract ) = @_;
470 if ( $subtract ne $empty_string ) {
471  
472 $sumedian->{_subtract} = $subtract;
473 $sumedian->{_note} = $sumedian->{_note}.' subtract='.$sumedian->{_subtract};
474 $sumedian->{_Step} = $sumedian->{_Step}.' subtract='.$sumedian->{_subtract};
475  
476 } else {
477 print("sumedian, subtract, missing subtract,\n");
478 }
479 }
480  
481  
482 =head2 sub tfile
483  
484  
485 =cut
486  
487 sub tfile {
488  
489 my ( $self,$tfile ) = @_;
490 if ( $tfile ne $empty_string ) {
491  
492 $sumedian->{_tfile} = $tfile;
493 $sumedian->{_note} = $sumedian->{_note}.' tfile='.$sumedian->{_tfile};
494 $sumedian->{_Step} = $sumedian->{_Step}.' tfile='.$sumedian->{_tfile};
495  
496 } else {
497 print("sumedian, tfile, missing tfile,\n");
498 }
499 }
500  
501  
502 =head2 sub tmpdir
503  
504  
505 =cut
506  
507 sub tmpdir {
508  
509 my ( $self,$tmpdir ) = @_;
510 if ( $tmpdir ne $empty_string ) {
511  
512 $sumedian->{_tmpdir} = $tmpdir;
513 $sumedian->{_note} = $sumedian->{_note}.' tmpdir='.$sumedian->{_tmpdir};
514 $sumedian->{_Step} = $sumedian->{_Step}.' tmpdir='.$sumedian->{_tmpdir};
515  
516 } else {
517 print("sumedian, tmpdir, missing tmpdir,\n");
518 }
519 }
520  
521  
522 =head2 sub tshift
523  
524  
525 =cut
526  
527 sub tshift {
528  
529 my ( $self,$tshift ) = @_;
530 if ( $tshift ne $empty_string ) {
531  
532 $sumedian->{_tshift} = $tshift;
533 $sumedian->{_note} = $sumedian->{_note}.' tshift='.$sumedian->{_tshift};
534 $sumedian->{_Step} = $sumedian->{_Step}.' tshift='.$sumedian->{_tshift};
535  
536 } else {
537 print("sumedian, tshift, missing tshift,\n");
538 }
539 }
540  
541  
542 =head2 sub verbose
543  
544  
545 =cut
546  
547 sub verbose {
548  
549 my ( $self,$verbose ) = @_;
550 if ( $verbose ne $empty_string ) {
551  
552 $sumedian->{_verbose} = $verbose;
553 $sumedian->{_note} = $sumedian->{_note}.' verbose='.$sumedian->{_verbose};
554 $sumedian->{_Step} = $sumedian->{_Step}.' verbose='.$sumedian->{_verbose};
555  
556 } else {
557 print("sumedian, verbose, missing verbose,\n");
558 }
559 }
560  
561  
562 =head2 sub xfile
563  
564  
565 =cut
566  
567 sub xfile {
568  
569 my ( $self,$xfile ) = @_;
570 if ( $xfile ne $empty_string ) {
571  
572 $sumedian->{_xfile} = $xfile;
573 $sumedian->{_note} = $sumedian->{_note}.' xfile='.$sumedian->{_xfile};
574 $sumedian->{_Step} = $sumedian->{_Step}.' xfile='.$sumedian->{_xfile};
575  
576 } else {
577 print("sumedian, xfile, missing xfile,\n");
578 }
579 }
580  
581  
582 =head2 sub xshift
583  
584  
585 =cut
586  
587 sub xshift {
588  
589 my ( $self,$xshift ) = @_;
590 if ( $xshift ne $empty_string ) {
591  
592 $sumedian->{_xshift} = $xshift;
593 $sumedian->{_note} = $sumedian->{_note}.' xshift='.$sumedian->{_xshift};
594 $sumedian->{_Step} = $sumedian->{_Step}.' xshift='.$sumedian->{_xshift};
595  
596 } else {
597 print("sumedian, xshift, missing xshift,\n");
598 }
599 }
600  
601  
602 =head2 sub get_max_index
603  
604 max index = number of input variables -1
605
606 =cut
607
608 sub get_max_index {
609 my ($self) = @_;
610 my $max_index = 12;
611  
612 return($max_index);
613 }
614
615
616 1;