1 #!/usr/bin/perl |
1 #!/usr/bin/perl |
2 #====================================================================== |
2 #====================================================================== |
3 # L A D C P _ W |
3 # L A D C P _ W |
4 # doc: Fri Dec 17 18:11:13 2010 |
4 # doc: Fri Dec 17 18:11:13 2010 |
5 # dlm: Thu Sep 5 16:23:16 2013 |
5 # dlm: Mon May 19 22:21:35 2014 |
6 # (c) 2010 A.M. Thurnherr |
6 # (c) 2010 A.M. Thurnherr |
7 # uE-Info: 495 0 NIL 0 0 72 2 2 4 NIL ofnI |
7 # uE-Info: 932 27 NIL 0 0 72 2 2 4 NIL ofnI |
8 #====================================================================== |
8 #====================================================================== |
9 |
9 |
10 # TODO: |
10 # TODO: |
11 # detection so that editing stats make sense |
11 # detection so that editing stats make sense |
12 # - own seabed detection (P403) |
12 # - own seabed detection (P403) |
134 # - added re-gridding of full profile after ping-coherent error removal |
134 # - added re-gridding of full profile after ping-coherent error removal |
135 # Jun 5, 2013: - renamed $discard_velocities_from_beam to $bad_beam |
135 # Jun 5, 2013: - renamed $discard_velocities_from_beam to $bad_beam |
136 # - BUG: $bad_beam did not discard BT_VELOCITY data |
136 # - BUG: $bad_beam did not discard BT_VELOCITY data |
137 # Jun 6, 2013: - BUG: error message had -a instead of -d |
137 # Jun 6, 2013: - BUG: error message had -a instead of -d |
138 # Sep 5, 2013: - BUG: w12/w34 do not work for earth-coordinate data, of course |
138 # Sep 5, 2013: - BUG: w12/w34 do not work for earth-coordinate data, of course |
|
139 # Apr 17, 2014: - BUG: edit_tilt was never called when all recorded bins are valid |
|
140 # Apr 21, 2014: - updated comments |
139 |
141 |
140 # CTD REQUIREMENTS |
142 # CTD REQUIREMENTS |
141 # - elapsed elapsed seconds; see note below |
143 # - elapsed elapsed seconds; see note below |
142 # - depth |
144 # - depth |
143 # - ss sound speed |
145 # - ss sound speed |
587 next unless ($per_bin_nsamp[$bin]/($lastGoodEns-$firstGoodEns) < $per_bin_valid_frac_lim); |
589 next unless ($per_bin_nsamp[$bin]/($lastGoodEns-$firstGoodEns) < $per_bin_valid_frac_lim); |
588 $first_bad_bin = $bin; |
590 $first_bad_bin = $bin; |
589 last; |
591 last; |
590 } |
592 } |
591 |
593 |
592 if (defined($first_bad_bin)) { |
594 $fprm = $pte = 0; |
593 $fprm = $pte = 0; |
595 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
594 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
596 $pte += editTilt($ens,$opt_t); |
595 $pte += editTilt($ens,$opt_t); |
597 $fprm += editFarBins($ens,$first_bad_bin) if defined($first_bad_bin); |
596 $fprm += editFarBins($ens,$first_bad_bin) if defined($first_bad_bin); |
598 } |
597 } |
599 progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n", |
598 progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n", |
600 $opt_t,$pte,round(100*$pte/$nvv)); |
599 $opt_t,$pte,round(100*$pte/$nvv)); |
601 progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n", |
600 progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n", |
602 round(100*$per_bin_valid_frac_lim),$fprm,round(100*$fprm/$nvw)); |
601 round(100*$per_bin_valid_frac_lim),$fprm,round(100*$fprm/$nvw)); |
|
602 } |
|
603 |
603 |
604 #-------------- |
604 #-------------- |
605 # Read CTD data |
605 # Read CTD data |
606 #-------------- |
606 #-------------- |
607 |
607 |
656 |
656 |
657 #-------------------------------------------------------------------- |
657 #-------------------------------------------------------------------- |
658 # Construct sound-speed correction profile from CTD 1Hz downcast data |
658 # Construct sound-speed correction profile from CTD 1Hz downcast data |
659 # very simple algorithm that stores the last value found |
659 # very simple algorithm that stores the last value found |
660 # in each 1m bin |
660 # in each 1m bin |
|
661 # For PPI filtering, a sound speed profile to the surface is required. |
|
662 # This is ensured by extrapolating the first value up to zero |
661 #-------------------------------------------------------------------- |
663 #-------------------------------------------------------------------- |
662 |
664 |
663 progress("Constructing sound-speed correction profile\n"); |
665 progress("Constructing sound-speed correction profile\n"); |
664 |
666 |
665 my($scans_per_sec) = int(1/$CTD{DT}+0.5); |
667 my($scans_per_sec) = int(1/$CTD{DT}+0.5); |
|
668 my($min_depth) = 9e99; |
666 for (my($s)=0; $s<=$CTD_atbottom; $s+=$scans_per_sec) { |
669 for (my($s)=0; $s<=$CTD_atbottom; $s+=$scans_per_sec) { |
667 next unless ($CTD{DEPTH}[$s] >= 0 && numberp($CTD{SVEL}[$s])); |
670 next unless ($CTD{DEPTH}[$s] >= 0 && numberp($CTD{SVEL}[$s])); |
|
671 $min_depth = $s if ($s < $min_depth); |
668 $sVelProf[int($CTD{DEPTH}[$s])] = $CTD{SVEL}[$s]; |
672 $sVelProf[int($CTD{DEPTH}[$s])] = $CTD{SVEL}[$s]; |
|
673 } |
|
674 while ($min_depth > 0) { |
|
675 $sVelProf[$min_depth-1] = $sVelProf[$min_depth]; |
|
676 $min_depth--; |
669 } |
677 } |
670 |
678 |
671 #------------------- |
679 #------------------- |
672 # Determine time lag |
680 # Determine time lag |
673 #------------------- |
681 #------------------- |
853 |
861 |
854 progress("Calculating volume-scattering coefficients...\n"); |
862 progress("Calculating volume-scattering coefficients...\n"); |
855 calc_backscatter_profs($firstGoodEns,$lastGoodEns); |
863 calc_backscatter_profs($firstGoodEns,$lastGoodEns); |
856 |
864 |
857 #---------------------------------------------------------------------------- |
865 #---------------------------------------------------------------------------- |
858 # Remove data contaminated by sidelobe reflection from seabed and sea surface |
866 # Edit data |
|
867 # 1) contaminated by sidelobe reflection from seabed and sea surface |
|
868 # 2) PPI |
859 #---------------------------------------------------------------------------- |
869 #---------------------------------------------------------------------------- |
860 |
870 |
861 if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN}) { |
871 if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN}) { |
862 &antsAddParams('ADCP_orientation','downlooker'); |
872 &antsAddParams('ADCP_orientation','downlooker'); |
863 |
873 |
892 |
902 |
893 progress("Editing data to remove sidelobe interference from seabed...\n"); |
903 progress("Editing data to remove sidelobe interference from seabed...\n"); |
894 ($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth); |
904 ($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth); |
895 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
905 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
896 |
906 |
|
907 progress("Editing data to remove PPI from seabed...\n"); |
|
908 progress("\tConstructing travel-time profile...\n"); |
|
909 my($tt) = ($water_depth - $#sVelProf) / $sVelProf[$#sVelProf]; # $#sVelProf = max_depth(profile) in meters |
|
910 $ttProf[$#sVelProf] = $tt; |
|
911 for (my($d)=$#sVelProf-1; $d>=0; $d--) { |
|
912 $tt += 1 / $sVelProf[$d]; |
|
913 $ttProf[$d] = $tt; |
|
914 } |
|
915 ($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth); |
|
916 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
897 } else { |
917 } else { |
898 info("no seabed found in backscatter profiles --- no sidelobe editing done\n"); |
918 info("no seabed found in backscatter profiles --- cannot edit sidelobe or PPI\n"); |
899 } |
919 } |
900 |
920 |
901 } else { |
921 } else { |
902 &antsAddParams('ADCP_orientation','uplooker'); |
922 &antsAddParams('ADCP_orientation','uplooker'); |
|
923 |
903 progress("Editing data to remove sidelobe interference from sea surface...\n"); |
924 progress("Editing data to remove sidelobe interference from sea surface...\n"); |
904 ($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef); |
925 ($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef); |
|
926 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
|
927 |
|
928 progress("Editing data to remove PPI from sea surface...\n"); |
|
929 progress("\tConstructing travel-time profile...\n"); |
|
930 my($tt) = 0; |
|
931 $ttProf[0] = $tt; |
|
932 for (my($d)=1; $d<=$#sVelProf; $d++) { |
|
933 $tt += 1 / $sVelProf[$d]; |
|
934 $ttProf[$d] = $tt; |
|
935 } |
|
936 ($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,undef); |
905 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
937 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
906 } |
938 } |
907 |
939 |
908 #---------------------------------------------------------------------- |
940 #---------------------------------------------------------------------- |
909 # Data Editing after LADCP and CTD data have been merged |
941 # Data Editing after LADCP and CTD data have been merged |