lib/App/SeismicUnixGui/misc/su_xtract_waveform.pm untested

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 151 CC 9 SCAR 18.4
CC
9
Cov
0%
file_out
20.0
inbound
6.0
absclip
6.0
CRAP 6.3
1 package App::SeismicUnixGui::misc::su_xtract_waveform;
2  
3 use Moose;
4 our $VERSION = '0.0.1';
5  
6 =head1 DOCUMENTATION
7  
8 =head2 SYNOPSIS
9  
10 PERL PROGRAM NAME: xract_waveform.pl
11 Purpose: Simple viewing of an su file
12 to extract waveforms
13 AUTHOR: Juan M. Lorenzo
14 DEPENDS: Seismic Unix modules from CSM
15 DATE: July 7 2016 V0.1
16 DESCRIPTION: based upon non-oop Xtract.pl
17  
18 =head2 USES
19  
20 (for subroutines)
21 manage_files_by
22 System_Variables (for subroutines)
23  
24 (for variable definitions)
25 SeismicUnix (Seismic Unix modules)
26  
27  
28 =head2 NOTES
29  
30 We are using moose
31 moose already declares that you need debuggers turned on
32 so you don't need a line like the following:
33  
34 use warnings;
35
36 =head2 USES
37  
38 (for subroutines)
39 manage_files_by
40 System_Variables (for subroutines)
41  
42 (for variable definitions)
43 SeismicUnix (Seismic Unix modules)
44  
45  
46 use App::SeismicUnixGui::misc::SeismicUnix qw($in $out $on $go $to $suffix_ascii $off $suffix_su) ;
47
48 =head2 STEPS IN THE PROGRAM
49  
50 =cut
51  
52 =head2 Create
53  
54 hash of shared variables and
55 subroutine to clear them
56  
57 Do not clear: absclip
58  
59 =cut
60  
61 my $xtract = {
62 _inbound => '',
63 _outbound => '',
64 _ref_picks_file => '',
65 _ref_indices => '',
66 _file_out => '',
67 _header_word => 'tracf',
68 _absclip => 1,
69 _waveform_tmin => '',
70 _waveform_tmax => '',
71 _waveform_key_max => '',
72 _waveform_key_min => '',
73 _window_title => ''
74 };
75  
76 sub clear {
77 $xtract->{_key} = '';
78 $xtract->{_inbound} = '';
79 $xtract->{_ref_indices} = '';
80 $xtract->{_outbound} = '';
81 $xtract->{_ref_picks_file} = '';
82 $xtract->{_file_out} = '';
83 $xtract->{_header_word} = '';
84 $xtract->{_window_title} = '';
85 $xtract->{_waveform_tmin} = '';
86 $xtract->{_waveform_tmax} = '';
87 $xtract->{_waveform_key_max} = '';
88 $xtract->{_waveform_key_min} = '';
89 }
90  
91 =head2 sub inbound
92  
93 set inbound seismic-unix
94 -formatted file name
95  
96 =cut
97  
98 sub inbound {
99 my ( $variable, $inbound ) = @_;
100 if ($inbound) {
101 $xtract->{_inbound} = $inbound;
102  
103 #print("inbound is $xtract->{_inbound}\n\n");
104 }
105 }
106  
107 =head2 sub absclip
108  
109 set absclip for suxwigb
110
111  
112 =cut
113  
114 sub absclip {
115 my ( $variable, $absclip ) = @_;
116 if ($absclip) {
117 $xtract->{_absclip} = $absclip;
118 }
119 }
120  
121 =head2 sub sorted_indices
122  
123 for sorting indices
124  
125 =cut
126  
127 sub sorted_indices {
128 my (@unsorted) = @_;
129 my @idx = sort { $unsorted[$a] <=> $unsorted[$b] } 0 .. $#unsorted;
130 $xtract->{_ref_indices} = \@idx;
131  
132 #print ("indices are @idx\n\n");
133 #print("unsorted is @unsorted\n\n");
134 }
135  
136 =head2 sub file_out
137  
138 set name of output file
139 using both ref_picks_file that
140 is used to select a single waveform
141 and the seismic unix file containing all the data
142  
143 =cut
144  
145 sub file_out {
146 my ( $variable, $ref_picks_file, $inbound ) = @_;
147  
148 =head2 Read
149
150 the picked 'waveform' file
151 assume local directory
152  
153 =cut
154  
155 if ( $ref_picks_file && $inbound ) {
156  
157 use App::SeismicUnixGui::misc::SeismicUnix qw($suffix_su);
158 use aliased 'App::SeismicUnixGui::misc::readfiles';
159  
160 my $read = readfiles->new();
161 my ( $ref_time, $ref_key, $max_index ) =
162 $read->cols_2p($ref_picks_file);
163  
164 =head2 Sort
165
166 the picked 'waveform' file
167  
168 =cut
169  
170 #print("keys are @$ref_key\n");
171 #print("times are @$ref_time\n");
172 my $idx = sorted_indices(@$ref_key);
173 my @sorted_key = @$ref_key[@$idx];
174 my @sorted_time = @$ref_time[@$idx];
175  
176 print("sorted keys are @sorted_key\n\n");
177 print("sorted times are @sorted_time\n\n");
178  
179 $xtract->{_waveform_tmin} = $sorted_time[0];
180 $xtract->{_waveform_tmax} = $sorted_time[$max_index];
181 $xtract->{_waveform_key_max} = $sorted_key[$max_index];
182 $xtract->{_waveform_key_min} = $sorted_key[0];
183  
184 $xtract->{_file_out} =
185 $$ref_picks_file . '_'
186 . $xtract->{_waveform_tmin} . 's_'
187 . $xtract->{_waveform_tmax} . 's'
188 . $suffix_su;
189 print("su_xtract_waveform,file out: $xtract->{_file_out}\n\n");
190  
191 =head2 Error
192  
193 Message
194  
195 =cut
196  
197 if ( $xtract->{_waveform_key_min} <= 1 ) {
198 # print("su_xtract_waveform,file outsmallest key is $xtract->{_waveform_key_min}\n");
199 # print("su_xtract_waveform,file outupdated to 1 \n");
200 $xtract->{_waveform_key_min} = 1;
201 }
202  
203 if ( $xtract->{_waveform_key_max} <= 1 ) {
204 # print("su_xtract_waveform,file outlsu_xtract_waveform,file outargest key is $xtract->{_waveform_key_max}\n");
205 # print("su_xtract_waveform,file outupdated to 1 \n");
206 $xtract->{_waveform_key_max} = 1;
207  
208 #$xtract->{_file_out} = ${$xtract->{_ref_picks_file}}.'_'.$waveform_tmin.'s_'.$waveform_tmax.'s'.$suffix_su; #print("picks file is ${$xtract->{_file_out}} \n\n");
209 }
210  
211 return $xtract->{_file_out};
212 }
213  
214 } # end of sub file_out
215  
216 =head2 sub
217  
218 set ref_picks_file
219 waveform file
220  
221 =cut
222  
223 sub ref_picks_file {
224 my ( $variable, $ref_picks_file ) = @_;
225 if ($ref_picks_file) {
226 $xtract->{_ref_picks_file} = $ref_picks_file;
227  
228 #print("picks file is ${$xtract->{_ref_picks_file}} \n\n");
229 }
230 }
231  
232 =head2 sub header_word
233  
234 set header_word for suwind
235
236 =cut
237  
238 sub header_word {
239 my ( $variable, $header_word ) = @_;
240 if ($header_word) {
241 $xtract->{_header_word} = $header_word;
242 }
243 }
244  
245 =head2 sub window_title
246  
247 set window_title for suxwigb
248  
249 =cut
250  
251 sub window_title {
252 my ( $variable, $window_title ) = @_;
253 if ($window_title) {
254 $xtract->{_window_title} = $window_title;
255 }
256 }
257  
258 =head2 sub Step
259
260 Extraction of waveform
261  
262 =cut
263  
264 sub Step {
265  
266 use App::SeismicUnixGui::misc::SeismicUnix qw($in $out $on $go $to $suffix_ascii $off $suffix_su);
267 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
268 use aliased 'App::SeismicUnixGui::misc::message';
269 use aliased 'App::SeismicUnixGui::misc::flow';
270 use aliased 'App::SeismicUnixGui::sunix::plot::suxwigb';
271 use aliased 'App::SeismicUnixGui::sunix::shapeNcut::suwind';
272  
273 =head2 Instantiate classes
274  
275 1. Instantiate classes
276 Create a new version of the package
277 Personalize to give it a new name if you wish
278 Use classes:
279 flow
280 log
281 message
282 suxwigb
283 suwind
284  
285 =cut
286  
287 my $Project = Project_config->new();
288 my $log = message->new();
289 my $run = flow->new();
290 my $suxwigb = suxwigb->new();
291 my $suwind = suwind->new();
292  
293 =head2 Declare
294  
295 local variables
296  
297 =cut
298  
299 my ( @flow, @sufile_out );
300 my (@suxwigb);
301 my ( @suwind, @items );
302 my (@read);
303  
304 my ($DATA_SEISMIC_SU) = $Project->DATA_SEISMIC_SU();
305  
306 =head2 Set
307
308 Only for debugging
309 set suxwigb parameters
310 In the perl module for suxwigb we should
311 have (but we do not yet) an explanation of each of these parameters
312  
313 $suxwigb-> clear();
314 $suxwigb-> d1(1);
315 $suxwigb-> d2(1);
316 $suxwigb-> f1(1);
317 $suxwigb-> f2(1);
318 $suxwigb-> xcur(1);
319 $suxwigb-> n2tic(1);
320 $suxwigb-> d2num(20);
321 $suxwigb-> windowtitle($xtract->{_window_title});
322 #$suxwigb-> title($xtract->{_window_title});
323 $suxwigb-> xlabel($xtract->{_header_word});
324 suxwigb-> ylabel('TWTT\ s');
325 $suxwigb-> box_width(300);
326 $suxwigb-> box_height(500);
327 $suxwigb-> box_X0(0);
328 $suxwigb-> box_Y0(0);
329 $suxwigb-> absclip($xtract->{_absclip});
330 $suxwigb[1] = $suxwigb->Step();
331  
332 @items = ($suwind[1],$in,$xtract->{_inbound},$to,
333 $suwind[2],$to,$suxwigb[1],$go);
334 $flow[1] = $run->modules(\@items);
335  
336 =cut
337  
338 =head2 QC-Extract
339  
340 the selected waveform
341 to a file
342 =cut
343  
344 $xtract->{_outbound} = $DATA_SEISMIC_SU . '/' . $xtract->{_file_out};
345  
346 =head2 Window by
347  
348 trace
349  
350 =cut
351  
352 $suwind->clear();
353 $suwind->key( $xtract->{_header_word} );
354 $suwind->min( $xtract->{_waveform_key_min} );
355 $suwind->max( $xtract->{_waveform_key_max} );
356 $suwind[1] = $suwind->Step();
357  
358 =head2 Window by
359  
360 time
361  
362 =cut
363  
364 $suwind->clear();
365 $suwind->tmin( $xtract->{_waveform_tmin} );
366 $suwind->tmax( $xtract->{_waveform_tmax} );
367 $suwind[2] = $suwind->Step();
368  
369 =head2 DEFINE FLOW(S)
370
371 Save a copy of extracted file
372  
373 =cut
374  
375 @items = (
376 $suwind[1], $in, $xtract->{_inbound}, $to,
377 $suwind[2], $out, $xtract->{_outbound}, $go
378 );
379 $flow[1] = $run->modules( \@items );
380  
381 #print ("flow is $flow[1]\n\n");
382 #print ("flow is $flow[2]\n\n");
383  
384 return \@flow;
385  
386 } # end of sub Step
387  
388  
389 1;