lib/App/SeismicUnixGui/sunix/statsMath/suop.pm untested

filter: Statementstmt 0.0% 0 / 124 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 172 CC 12 SCAR 25.4
CC
12
Cov
0%
Step
42.0
_get_file_names
6.0
_get_inbound
6.0
CRAP 12.7
1 package App::SeismicUnixGui::sunix::statsMath::suop;
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 SUOP - do unary arithmetic operation on segys
25  
26  
27  
28 suop <stdin >stdout op=abs
29  
30  
31  
32 Required parameters:
33  
34 none
35  
36  
37  
38 Optional parameter:
39  
40 op=abs operation flag
41  
42 abs : absolute value
43  
44 avg : remove average value
45  
46 ssqrt : signed square root
47  
48 sqr : square
49  
50 ssqr : signed square
51  
52 sgn : signum function
53  
54 exp : exponentiate
55  
56 sexp : signed exponentiate
57  
58 slog : signed natural log
59  
60 slog2 : signed log base 2
61  
62 slog10: signed common log
63  
64 cos : cosine
65  
66 sin : sine
67  
68 tan : tangent
69  
70 cosh : hyperbolic cosine
71  
72 sinh : hyperbolic sine
73  
74 tanh : hyperbolic tangent
75  
76 cnorm : norm complex samples by modulus ",
77  
78 norm : divide trace by Max. Value
79  
80 db : 20 * slog10 (data)
81  
82 neg : negate value
83  
84 posonly : pass only positive values
85  
86 negonly : pass only negative values
87  
88 sum : running sum trace integration
89  
90 diff : running diff trace differentiation
91  
92 refl : (v[i+1] - v[i])/(v[i+1] + v[i])
93  
94 mod2pi : modulo 2 pi
95  
96 inv : inverse
97  
98 rmsamp : rms amplitude
99  
100 s2v : sonic to velocity (ft/s) conversion
101  
102 s2vm : sonic to velocity (m/s) conversion
103  
104 d2m : density (g/cc) to metric (kg/m^3) conversion
105  
106 drv2 : 2nd order vertical derivative
107  
108 drv4 : 4th order vertical derivative
109  
110 integ : top-down integration
111  
112 spike : local extrema to spikes
113  
114 saf : spike and fill to next spike
115  
116 freq : local dominant freqeuncy
117  
118 lnza : preserve least non-zero amps
119  
120 --------- window operations -----------
121  
122 mean : arithmetic mean
123  
124 despike : despiking based on median filter
125  
126 std : standard deviation
127  
128 var : variance
129  
130 nw=21 number of time samples in window
131  
132 ---------------------------------------
133  
134 nop : no operation
135  
136  
137  
138 Note: Binary ops are provided by suop2.
139  
140 Operations inv, slog, slog2, and slog10 are "punctuated", ",
141  
142 meaning that if, the input contains 0 values,
143  
144 0 values are returned. ",
145  
146  
147  
148 For file operations on non-SU format binary files use: farith
149  
150  
151  
152 Credits:
153  
154  
155  
156 CWP: Shuki Ronen, Jack K Cohen (c. 1987)
157  
158 Toralf Foerster: norm and db operations, 10/95.
159  
160 Additions by Reg Beardsley, Chris Liner, and others.
161  
162  
163  
164 Notes:
165  
166 If efficiency becomes important consider inverting main loop
167  
168 and repeating operation code within the branches of the switch.
169  
170  
171  
172 Note on db option. The following are equivalent:
173  
174 ... | sufft | suamp | suop op=norm | suop op=slog10 |\
175  
176 sugain scale equals 20| suxgraph style=normal
177  
178  
179  
180 ... | sufft | suamp | suop op=db | suxgraph style=normal
181  
182  
183  
184 =head2 User's notes (Juan Lorenzo)
185  
186 An additional parameter called "list" allows the operation
187 to be repeated among multiple files.
188  
189 The base file names of the su files are in the list, which
190 means that they are missing their suffix or extension,
191
192 e.g., file1_neg
193  
194 The list is found in $DATA_SEISMIC_TXT.
195 Output file names carry a suffix equal to the operation
196 variable. For example,
197  
198 file1_neg.su
199  
200 =cut
201  
202 =head2 CHANGES and their DATES
203  
204 =cut
205  
206 use Moose;
207 our $VERSION = '0.0.1';
208  
209 =head2 Import packages
210  
211 =cut
212  
213 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
214  
215 use App::SeismicUnixGui::misc::SeismicUnix
216 qw($go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su);
217 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
218 use aliased 'App::SeismicUnixGui::misc::control';
219 use aliased 'App::SeismicUnixGui::misc::readfiles';
220  
221 =head2 instantiation of packages
222  
223 =cut
224  
225 my $get = L_SU_global_constants->new();
226 my $Project = Project_config->new();
227 my $control = control->new();
228 my $readfiles = readfiles->new();
229 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
230 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
231 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
232  
233 my $PS_SEISMIC = $Project->PS_SEISMIC();
234  
235 my $var = $get->var();
236 my $on = $var->{_on};
237 my $off = $var->{_off};
238 my $true = $var->{_true};
239 my $false = $var->{_false};
240 my $empty_string = $var->{_empty_string};
241  
242 =head2 Encapsulated
243 hash of private variables
244  
245 =cut
246  
247 my $suop = {
248 _inbound_list => '',
249 _nw => '',
250 _op => '',
251 _Step => '',
252 _note => '',
253  
254 };
255  
256 =head2 sub Step
257  
258 collects switches and assembles bash instructions
259 by adding the program name
260  
261 =cut
262  
263 sub Step {
264  
265 my ($self) = @_;
266  
267 if ( length $suop->{_inbound_list} ) {
268 my $file_num;
269 my @Step;
270  
271 my ( $file_name_aref, $num_files ) = _get_file_names();
272 my ($inbound_aref) = _get_inbound();
273 my @inbound = @$inbound_aref;
274 my @file_name = @$file_name_aref;
275 my $num_of_files = scalar @file_name;
276  
277 # print("_get_inbound: @inbound\n");
278 my $outbound;
279 my $step;
280  
281 my $last_idx = $num_of_files - 1;
282  
283 # All cases when num_traces >=0
284 # for first file
285 $outbound = $DATA_SEISMIC_SU.'/'.$file_name[0] . '_' . $suop->{_op} . $suffix_su;
286 $step = " suop $suop->{_Step} < $inbound[0] > $outbound ";
287 # print ("outbound=$outbound\n");
288  
289 if ( $last_idx >= 2 ) {
290  
291 # CASE: >= 3 operations
292 for ( my $i = 1 ; $i < $last_idx ; $i++ ) {
293  
294 $outbound =
295 $DATA_SEISMIC_SU . '/'
296 . $file_name[$i] . '_'
297 . $suop->{_op}
298 . $suffix_su;
299 $step =
300 $step . "& suop $suop->{_Step} < $inbound[$i] > $outbound ";
301  
302 }
303  
304 # for last file
305 $outbound = $DATA_SEISMIC_SU.'/'.$file_name[$last_idx] . '_' . $suop->{_op} . $suffix_su;
306 $suop->{_Step} =
307 $step . "& suop $suop->{_Step} < $inbound[$last_idx] > $outbound ";
308  
309 }
310 elsif ( $last_idx == 1 ) {
311  
312 # for last file
313 $outbound = $DATA_SEISMIC_SU.'/'.$file_name[$last_idx] . '_' . $suop->{_op} . $suffix_su;
314 $suop->{_Step} =
315 $step . "& suop $suop->{_Step} < $inbound[$last_idx] > $outbound ";
316  
317 }
318 elsif ( $last_idx == 0 ) {
319  
320 $suop->{_Step} = $step;
321  
322 }
323 else {
324 print("suop,Step,unexpected case\n");
325 return();
326 }
327  
328 return ($suop->{_Step});
329 }
330 elsif ( not length $suop->{_inbound_list} ) {
331  
332 $suop->{_Step} = 'suop' . $suop->{_Step};
333 return ( $suop->{_Step} );
334  
335 }
336 else {
337 print("suop, Step, incorrect parameters\n");
338 }
339  
340 }
341  
342 =head2 sub note
343  
344 collects switches and assembles bash instructions
345 by adding the program name
346  
347 =cut
348  
349 sub note {
350  
351 $suop->{_note} = 'suop' . $suop->{_note};
352 return ( $suop->{_note} );
353  
354 }
355  
356 =head2 sub clear
357  
358 =cut
359  
360 sub clear {
361 $suop->{_inbound_list} = '';
362 $suop->{_nw} = '';
363 $suop->{_op} = '';
364 $suop->{_Step} = '';
365 $suop->{_note} = '';
366 }
367  
368 =head2 sub _get_file_names
369  
370 =cut
371  
372 sub _get_file_names {
373 my ($self) = @_;
374  
375 if ( length $suop->{_inbound_list} ) {
376  
377 # _set_inbound_list();
378  
379 my $inbound_list = $suop->{_inbound_list};
380  
381 my ( $file_names_ref, $num_files ) = $readfiles->cols_1p($inbound_list);
382 my $result_a = $file_names_ref;
383 my $result_b = $num_files;
384  
385 # print("_get_file_names, values=@$file_names_ref\n");
386 return ( $result_a, $result_b );
387  
388 }
389 else {
390 print("_get_file_names, missing inbound\n");
391 return ();
392 }
393  
394 }
395  
396 =head2 sub _get_inbound
397  
398 =cut
399  
400 sub _get_inbound {
401 my ($self) = @_;
402  
403 my ( $array_ref, $num_files ) = _get_file_names();
404  
405 if ( length $array_ref ) {
406  
407 my @file_name = @$array_ref;
408 my @inbound;
409  
410 for ( my $i = 0 ; $i < $num_files ; $i++ ) {
411  
412 $inbound[$i] = $DATA_SEISMIC_SU . '/' . $file_name[$i] . $suffix_su;
413  
414 }
415  
416 return ( \@inbound );
417  
418 }
419 else {
420 print("suop,_get_inbound, missing file names\n");
421 return ();
422 }
423  
424 }
425  
426 =head2 sub _set_inbound_list
427  
428 =cut
429  
430 sub _set_inbound_list {
431 my ($self) = @_;
432  
433 if ( length $suop->{_inbound_list} ) {
434  
435 my $inbound_list = $suop->{_inbound_list};
436 $control->set_back_slashBgone($inbound_list);
437 $inbound_list = $control->get_back_slashBgone();
438 $suop->{_inbound_list} = $inbound_list;
439  
440 }
441 else {
442 print("_set_inbound_list, missing list\n");
443 return ();
444 }
445  
446 }
447  
448 =head2 sub list
449  
450 list array
451  
452 =cut
453  
454 sub list {
455 my ( $self, $list ) = @_;
456  
457 if ( length $list ) {
458  
459 $suop->{_inbound_list} = $list;
460 _set_inbound_list();
461  
462 # print("suop,list is $suop->{_inbound_list}\n\n");
463  
464 }
465 else {
466 print("suop, list, missing list,\n");
467 }
468 return ();
469 }
470  
471 #=head2 sub neg
472 #
473 #
474 #=cut
475 #
476 #sub neg {
477 #
478 # my ( $self, $neg ) = @_;
479 # if ( $neg ne $empty_string ) {
480 #
481 # $suop->{_neg} = $neg;
482 # $suop->{_note} = $suop->{_note} . ' neg=' . $suop->{_neg};
483 # $suop->{_Step} = $suop->{_Step} . ' neg=' . $suop->{_neg};
484 #
485 # }
486 # else {
487 # print("suop, neg, missing neg,\n");
488 # }
489 #}
490  
491 =head2 sub nw
492  
493  
494 =cut
495  
496 sub nw {
497  
498 my ( $self, $nw ) = @_;
499 if ( $nw ne $empty_string ) {
500  
501 $suop->{_nw} = $nw;
502 $suop->{_note} = $suop->{_note} . ' nw=' . $suop->{_nw};
503 $suop->{_Step} = $suop->{_Step} . ' nw=' . $suop->{_nw};
504  
505 }
506 else {
507 print("suop, nw, missing nw,\n");
508 }
509 }
510  
511 =head2 sub op
512  
513  
514 =cut
515  
516 sub op {
517  
518 my ( $self, $op ) = @_;
519 if ( $op ne $empty_string ) {
520  
521 $suop->{_op} = $op;
522 $suop->{_note} = $suop->{_note} . ' op=' . $suop->{_op};
523 $suop->{_Step} = $suop->{_Step} . ' op=' . $suop->{_op};
524  
525 }
526 else {
527 print("suop, op, missing op,\n");
528 }
529 }
530  
531 =head2 sub get_max_index
532  
533 max index = number of input variables -1
534
535 =cut
536  
537 sub get_max_index {
538 my ($self) = @_;
539 my $max_index = 2;
540  
541 return ($max_index);
542 }
543  
544 1;