lib/App/SeismicUnixGui/sunix/model/suaddnoise.pm untested

filter: Statementstmt 0.0% 0 / 111 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 167 CC 12 SCAR 16.0
CC
12
Cov
0%
N
6.0
Output
6.0
amps
6.0
CRAP 4.9
1 package App::SeismicUnixGui::sunix::model::suaddnoise;
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 SUADDNOISE - add noise to traces
25  
26  
27  
28 suaddnoise <stdin >stdout sn=20 noise=gauss seed=from_clock
29  
30  
31  
32 Required parameters:
33  
34 if any of f=f1,f2,... and amp=a1,a2,... are specified by the user
35  
36 and if dt is not set in header, then dt is mandatory
37  
38  
39  
40 Optional parameters:
41  
42 sn=20 signal to noise ratio
43  
44 noise=gauss noise probability distribution
45  
46 =flat for uniform; default Gaussian
47  
48 seed=from_clock random number seed (integer)
49  
50 f=f1,f2,... array of filter frequencies (as in sufilter)
51  
52 amps=a1,a2,... array of filter amplitudes
53  
54 dt= (from header) time sampling interval (sec)
55  
56 verbose=0 =1 for echoing useful information
57  
58  
59  
60 tmpdir= if non-empty, use the value as a directory path
61  
62 prefix for storing temporary files; else if the
63  
64 the CWP_TMPDIR environment variable is set use
65  
66 its value for the path; else use tmpfile()
67  
68  
69  
70 Notes:
71  
72 Output = Signal + scale * Noise
73  
74  
75  
76 scale = (1/sn) * (absmax_signal/sqrt(2))/sqrt(energy_per_sample)
77  
78  
79  
80 If the signal is already band-limited, f=f1,f2,... and amps=a1,a2,...
81  
82 can be used, as in sufilter, to bandlimit the noise traces to match
83  
84 the signal band prior to computing the scale defined above.
85  
86  
87  
88 Examples of noise bandlimiting:
89  
90 low freqency: suaddnoise < data f=40,50 amps=1,0 | ...
91  
92 high freqency: suaddnoise < data f=40,50 amps=0,1 | ...
93  
94 near monochromatic: suaddnoise < data f=30,40,50 amps=0,1,0 | ...
95  
96 with a notch: suaddnoise < data f=30,40,50 amps=1,0,1 | ...
97  
98 bandlimited: suaddnoise < data f=20,30,40,50 amps=0,1,1,0 | ...
99  
100  
101  
102  
103  
104 Credits:
105  
106 CWP: Jack Cohen, Brian Sumner, Ken Larner
107  
108 John Stockwell (fixed filtered noise option)
109  
110  
111  
112 Notes:
113  
114 At S/N = 2, the strongest reflector is well delineated, so to
115  
116 see something 1/nth as strong as this dominant reflector
117  
118 requires S/N = 2*n.
119  
120  
121  
122 Trace header field accessed: ns
123  
124  
125  
126  
127  
128 =head2 User's notes (Juan Lorenzo)
129 untested
130  
131 =cut
132  
133  
134 =head2 CHANGES and their DATES
135  
136 =cut
137  
138 use Moose;
139 our $VERSION = '0.0.1';
140  
141  
142 =head2 Import packages
143  
144 =cut
145  
146 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
147  
148 use App::SeismicUnixGui::misc::SeismicUnix qw($in $out $on $go $to $suffix_ascii $off $suffix_su $suffix_bin);
149 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
150  
151  
152 =head2 instantiation of packages
153  
154 =cut
155  
156 my $get = L_SU_global_constants->new();
157 my $Project = Project_config->new();
158 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
159 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
160 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
161  
162 my $var = $get->var();
163 my $on = $var->{_on};
164 my $off = $var->{_off};
165 my $true = $var->{_true};
166 my $false = $var->{_false};
167 my $empty_string = $var->{_empty_string};
168  
169 =head2 Encapsulated
170 hash of private variables
171  
172 =cut
173  
174 my $suaddnoise = {
175 _N => '',
176 _Output => '',
177 _amps => '',
178 _dt => '',
179 _f => '',
180 _noise => '',
181 _scale => '',
182 _seed => '',
183 _sn => '',
184 _tmpdir => '',
185 _verbose => '',
186 _Step => '',
187 _note => '',
188  
189 };
190  
191 =head2 sub Step
192  
193 collects switches and assembles bash instructions
194 by adding the program name
195  
196 =cut
197  
198 sub Step {
199  
200 $suaddnoise->{_Step} = 'suaddnoise'.$suaddnoise->{_Step};
201 return ( $suaddnoise->{_Step} );
202  
203 }
204  
205  
206 =head2 sub note
207  
208 collects switches and assembles bash instructions
209 by adding the program name
210  
211 =cut
212  
213 sub note {
214  
215 $suaddnoise->{_note} = 'suaddnoise'.$suaddnoise->{_note};
216 return ( $suaddnoise->{_note} );
217  
218 }
219  
220  
221  
222 =head2 sub clear
223  
224 =cut
225  
226 sub clear {
227  
228 $suaddnoise->{_N} = '';
229 $suaddnoise->{_Output} = '';
230 $suaddnoise->{_amps} = '';
231 $suaddnoise->{_dt} = '';
232 $suaddnoise->{_f} = '';
233 $suaddnoise->{_noise} = '';
234 $suaddnoise->{_scale} = '';
235 $suaddnoise->{_seed} = '';
236 $suaddnoise->{_sn} = '';
237 $suaddnoise->{_tmpdir} = '';
238 $suaddnoise->{_verbose} = '';
239 $suaddnoise->{_Step} = '';
240 $suaddnoise->{_note} = '';
241 }
242  
243  
244 =head2 sub N
245  
246  
247 =cut
248  
249 sub N {
250  
251 my ( $self,$N ) = @_;
252 if ( $N ne $empty_string ) {
253  
254 $suaddnoise->{_N} = $N;
255 $suaddnoise->{_note} = $suaddnoise->{_note}.' N='.$suaddnoise->{_N};
256 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' N='.$suaddnoise->{_N};
257  
258 } else {
259 print("suaddnoise, N, missing N,\n");
260 }
261 }
262  
263  
264 =head2 sub Output
265  
266  
267 =cut
268  
269 sub Output {
270  
271 my ( $self,$Output ) = @_;
272 if ( $Output ne $empty_string ) {
273  
274 $suaddnoise->{_Output} = $Output;
275 $suaddnoise->{_note} = $suaddnoise->{_note}.' Output='.$suaddnoise->{_Output};
276 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' Output='.$suaddnoise->{_Output};
277  
278 } else {
279 print("suaddnoise, Output, missing Output,\n");
280 }
281 }
282  
283  
284 =head2 sub amps
285  
286  
287 =cut
288  
289 sub amps {
290  
291 my ( $self,$amps ) = @_;
292 if ( $amps ne $empty_string ) {
293  
294 $suaddnoise->{_amps} = $amps;
295 $suaddnoise->{_note} = $suaddnoise->{_note}.' amps='.$suaddnoise->{_amps};
296 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' amps='.$suaddnoise->{_amps};
297  
298 } else {
299 print("suaddnoise, amps, missing amps,\n");
300 }
301 }
302  
303  
304 =head2 sub dt
305  
306  
307 =cut
308  
309 sub dt {
310  
311 my ( $self,$dt ) = @_;
312 if ( $dt ne $empty_string ) {
313  
314 $suaddnoise->{_dt} = $dt;
315 $suaddnoise->{_note} = $suaddnoise->{_note}.' dt='.$suaddnoise->{_dt};
316 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' dt='.$suaddnoise->{_dt};
317  
318 } else {
319 print("suaddnoise, dt, missing dt,\n");
320 }
321 }
322  
323  
324 =head2 sub f
325  
326  
327 =cut
328  
329 sub f {
330  
331 my ( $self,$f ) = @_;
332 if ( $f ne $empty_string ) {
333  
334 $suaddnoise->{_f} = $f;
335 $suaddnoise->{_note} = $suaddnoise->{_note}.' f='.$suaddnoise->{_f};
336 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' f='.$suaddnoise->{_f};
337  
338 } else {
339 print("suaddnoise, f, missing f,\n");
340 }
341 }
342  
343  
344 =head2 sub noise
345  
346  
347 =cut
348  
349 sub noise {
350  
351 my ( $self,$noise ) = @_;
352 if ( $noise ne $empty_string ) {
353  
354 $suaddnoise->{_noise} = $noise;
355 $suaddnoise->{_note} = $suaddnoise->{_note}.' noise='.$suaddnoise->{_noise};
356 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' noise='.$suaddnoise->{_noise};
357  
358 } else {
359 print("suaddnoise, noise, missing noise,\n");
360 }
361 }
362  
363  
364 =head2 sub scale
365  
366  
367 =cut
368  
369 sub scale {
370  
371 my ( $self,$scale ) = @_;
372 if ( $scale ne $empty_string ) {
373  
374 $suaddnoise->{_scale} = $scale;
375 $suaddnoise->{_note} = $suaddnoise->{_note}.' scale='.$suaddnoise->{_scale};
376 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' scale='.$suaddnoise->{_scale};
377  
378 } else {
379 print("suaddnoise, scale, missing scale,\n");
380 }
381 }
382  
383  
384 =head2 sub seed
385  
386  
387 =cut
388  
389 sub seed {
390  
391 my ( $self,$seed ) = @_;
392 if ( $seed ne $empty_string ) {
393  
394 $suaddnoise->{_seed} = $seed;
395 $suaddnoise->{_note} = $suaddnoise->{_note}.' seed='.$suaddnoise->{_seed};
396 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' seed='.$suaddnoise->{_seed};
397  
398 } else {
399 print("suaddnoise, seed, missing seed,\n");
400 }
401 }
402  
403  
404 =head2 sub sn
405  
406  
407 =cut
408  
409 sub sn {
410  
411 my ( $self,$sn ) = @_;
412 if ( $sn ne $empty_string ) {
413  
414 $suaddnoise->{_sn} = $sn;
415 $suaddnoise->{_note} = $suaddnoise->{_note}.' sn='.$suaddnoise->{_sn};
416 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' sn='.$suaddnoise->{_sn};
417  
418 } else {
419 print("suaddnoise, sn, missing sn,\n");
420 }
421 }
422  
423  
424 =head2 sub tmpdir
425  
426  
427 =cut
428  
429 sub tmpdir {
430  
431 my ( $self,$tmpdir ) = @_;
432 if ( $tmpdir ne $empty_string ) {
433  
434 $suaddnoise->{_tmpdir} = $tmpdir;
435 $suaddnoise->{_note} = $suaddnoise->{_note}.' tmpdir='.$suaddnoise->{_tmpdir};
436 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' tmpdir='.$suaddnoise->{_tmpdir};
437  
438 } else {
439 print("suaddnoise, tmpdir, missing tmpdir,\n");
440 }
441 }
442  
443  
444 =head2 sub verbose
445  
446  
447 =cut
448  
449 sub verbose {
450  
451 my ( $self,$verbose ) = @_;
452 if ( $verbose ne $empty_string ) {
453  
454 $suaddnoise->{_verbose} = $verbose;
455 $suaddnoise->{_note} = $suaddnoise->{_note}.' verbose='.$suaddnoise->{_verbose};
456 $suaddnoise->{_Step} = $suaddnoise->{_Step}.' verbose='.$suaddnoise->{_verbose};
457  
458 } else {
459 print("suaddnoise, verbose, missing verbose,\n");
460 }
461 }
462  
463  
464 =head2 sub get_max_index
465  
466 max index = number of input variables -1
467
468 =cut
469
470 sub get_max_index {
471 my ($self) = @_;
472 my $max_index = 7;
473  
474 return($max_index);
475 }
476
477
478 1;