275 # Jul 31, 2016: - BUG: -d did not work because it was handled in [defaults.pl] |
275 # Jul 31, 2016: - BUG: -d did not work because it was handled in [defaults.pl] |
276 # Oct 16, 2016: - cosmetics |
276 # Oct 16, 2016: - cosmetics |
277 # Dec 22, 2016: - moved $opt_p to [defaults.pl] |
277 # Dec 22, 2016: - moved $opt_p to [defaults.pl] |
278 # Dec 23, 2016: - BUG: -u did not set required variables to proceed |
278 # Dec 23, 2016: - BUG: -u did not set required variables to proceed |
279 # Mar 6, 2017: - BUG: division by zero when water-depth ~ max(CTD_depth) |
279 # Mar 6, 2017: - BUG: division by zero when water-depth ~ max(CTD_depth) |
|
280 # Oct 12, 2017: - BUG: beampair w did not work for earth-coord vels; major re-write |
|
281 # of earthcoord code to unify processing |
|
282 # Nov 26, 2017: - BUG: $bad_beam did not work correctly with bin interpolation |
|
283 # - BUG: ping-coherent residual removal did not respect missing values |
|
284 # Nov 28, 2017: - added $initial_time_lag |
|
285 # - expanded semantics of -q to disable time-lagging and residual filters |
|
286 # Dec 9, 2017: - added $antsSuppressCommonOptions = 1; |
|
287 # Dec 17, 2017: - added dependencies |
|
288 # Apr 24, 2018: - added support for $water_depth_db_cmd |
|
289 # May 1, 2018: - added threshold for reference-layer horizontal speed |
|
290 # - added ambiguity velocity check |
|
291 # May 2, 2018: - BUG: ref-lr threshold did not work |
|
292 # - BUG: BT code was called for UL when -h was used |
|
293 # - replaced $PPI_seabed_editing_required by &PPI_seabed_editing_required |
|
294 # - BUG: surface PPI editing code could not be enabled; added &PPI_surface_editing_required |
|
295 # Nov 2, 2018: - BUG: for 3-beam solutions, residual{12,34} with affected beam was wrong |
280 # HISTORY END |
296 # HISTORY END |
281 |
297 |
282 # CTD REQUIREMENTS |
298 # CTD REQUIREMENTS |
283 # - elapsed elapsed seconds; see note below |
299 # - elapsed elapsed seconds; see note below |
284 # - depth |
300 # - depth |
369 #------ |
385 #------ |
370 |
386 |
371 require "$WCALC/defaults.pl"; # load default/option parameters |
387 require "$WCALC/defaults.pl"; # load default/option parameters |
372 |
388 |
373 $antsParseHeader = 0; |
389 $antsParseHeader = 0; |
|
390 $antsSuppressCommonOptions = 1; |
374 &antsUsage('3:4a:b:c:de:g:h:i:k:lm:n:o:p:qr:s:t:uv:Vw:x:',0, |
391 &antsUsage('3:4a:b:c:de:g:h:i:k:lm:n:o:p:qr:s:t:uv:Vw:x:',0, |
375 "[print software -V)ersion] [-v)erbosity <level[$opt_v]>]", |
392 "[print software -V)ersion] [-v)erbosity <level[$opt_v]>]", |
376 "[-q)uick (no single-ping denoising)]", |
|
377 "[require -4)-beam solutions] [-d)isable bin interpolation] [apply beamvel-m)ask <file> if it exists]", |
393 "[require -4)-beam solutions] [-d)isable bin interpolation] [apply beamvel-m)ask <file> if it exists]", |
378 "[valid LADCP -b)ins <bin,bin[$opt_b]>", |
394 "[valid LADCP -b)ins <bin,bin[$opt_b]>", |
379 "[-c)orrelation <min[$opt_c counts]>] [-t)ilt <max[$opt_t deg]> [-e)rr-vel <max[$opt_e m/s]>]", |
395 "[-c)orrelation <min[$opt_c counts]>] [-t)ilt <max[$opt_t deg]> [-e)rr-vel <max[$opt_e m/s]>]", |
380 "[-r)esidual <rms.max[,delta.max][$opt_r m/s]>]", |
396 "[max -r)esidual <rms.max[,delta.max][$opt_r m/s]>]", |
381 "[-h water <depth|filename>]", |
397 "[-h water <depth|filename>]", |
382 "[max LADCP time-series -g)ap <length[$opt_g s]>]", |
398 "[max LADCP time-series -g)ap <length[$opt_g s]>]", |
383 "[-i)nitial CTD time offset <guestimate> [-u)se as final]]", |
399 "[-i)nitial CTD time offset <guestimate> [-u)se as final]]", |
384 "[calculate -n) <lags,lags[$opt_n]>] [lag -w)indow <sz,sz[$opt_w s]>] [lag-p)iece <CTD_elapsed_min|+[,...]>]", |
400 "[calculate -n) <lags,lags[$opt_n]>] [lag -w)indow <sz,sz[$opt_w s]>] [lag-p)iece <CTD_elapsed_min|+[,...]>]", |
385 "[require top-3) lags to account for <frac[$opt_3]> of all]", |
401 "[require top-3) lags to account for <frac[$opt_3]> of all]", |
386 "[disable time-l)ag filtering]", |
402 "[disable time-l)ag filtering]", |
387 "[pressure-sensor -a)cceleration-derivative correction <residual/CTD_w_tt>]", |
403 "[pressure-sensor -a)cceleration-derivative correction <residual/CTD_w_tt>]", |
388 "[-o)utput bin <resolution[$opt_o m]>] [-k) require <min[$opt_k]> samples]", |
404 "[-o)utput bin <resolution[$opt_o m]>] [-k) require <min[$opt_k]> samples]", |
389 "[e-x)ecute <perl-expr>]", |
405 "[e-x)ecute <perl-expr>]", |
|
406 "[-q)uick-and-dirty (no single-ping denoising, residual and time-lagging filters)]", |
390 "<profile-id> [run-label]"); |
407 "<profile-id> [run-label]"); |
391 |
408 |
392 if ($opt_V) { |
409 if ($opt_V) { |
393 printf(STDERR "+-------------------------+\n"); |
410 printf(STDERR "+------------------------------+\n"); |
394 printf(STDERR "| LADCP_w Software V%s |\n",$VERSION); |
411 printf(STDERR "| LADCP_w Software V%s |\n",$VERSION); |
395 printf(STDERR "|(c) 2015- A.M. Thurnherr |\n"); |
412 printf(STDERR "| (c) 2015-2017 A.M. Thurnherr |\n"); |
396 printf(STDERR "+-------------------------+\n"); |
413 printf(STDERR "+------------------------------+\n"); |
397 exit(0); |
414 exit(0); |
398 } |
415 } |
399 |
416 |
400 &antsUsageError() if ($opt_u && !defined($opt_i)); |
417 &antsUsageError() if ($opt_u && !defined($opt_i)); |
401 &antsUsageError() unless (@ARGV==1 || @ARGV==2); |
418 &antsUsageError() unless (@ARGV==1 || @ARGV==2); |
549 # - low transmit power |
574 # - low transmit power |
550 #--------------------------- |
575 #--------------------------- |
551 |
576 |
552 progress("Reading LADCP data from <$LADCP_file>...\n"); |
577 progress("Reading LADCP data from <$LADCP_file>...\n"); |
553 readData($LADCP_file,\%LADCP); |
578 readData($LADCP_file,\%LADCP); |
|
579 &antsAddDeps($LADCP_file); |
554 if ($LADCP{BEAM_COORDINATES}) { |
580 if ($LADCP{BEAM_COORDINATES}) { |
555 progress("\t%d ensembles (beam coordinates)\n",scalar(@{$LADCP{ENSEMBLE}})); |
581 progress("\t%d ensembles (beam coordinates)\n",scalar(@{$LADCP{ENSEMBLE}})); |
556 } else { |
582 } else { |
557 progress("\t%d ensembles (Earth coordinates)\n",scalar(@{$LADCP{ENSEMBLE}})); |
583 progress("\t%d ensembles (Earth coordinates)\n",scalar(@{$LADCP{ENSEMBLE}})); |
558 } |
584 } |
559 |
585 |
|
586 if ($valid_ensemble_range[0] > 0) { # remove leading invalid records |
|
587 my($ens) = 0; |
|
588 while ($ens < @{$LADCP{ENSEMBLE}} && $LADCP{ENSEMBLE}[$ens]->{NUMBER}<$valid_ensemble_range[0]) { $ens++ } |
|
589 splice(@{$LADCP{ENSEMBLE}},0,$ens); |
|
590 progress("\t%d invalid leading ensembles removed\n",$ens) |
|
591 } |
|
592 if ($valid_ensemble_range[1] > 0) { # remove trailing invalid records |
|
593 my($ens) = 0; |
|
594 while ($ens < @{$LADCP{ENSEMBLE}} && $LADCP{ENSEMBLE}[$ens]->{NUMBER}<$valid_ensemble_range[1]) { $ens++ } |
|
595 splice(@{$LADCP{ENSEMBLE}},$ens); |
|
596 progress("\t%d invalid trailing ensembles removed\n",@{$LADCP{ENSEMBLE}}-$ens) |
|
597 } |
|
598 |
560 error("$LADCP_file: cannot process multi-ping ensembles\n") |
599 error("$LADCP_file: cannot process multi-ping ensembles\n") |
561 unless ($LADCP{PINGS_PER_ENSEMBLE} == 1); |
600 unless ($LADCP{PINGS_PER_ENSEMBLE} == 1); |
562 warning(2,"$LADCP_file: wide-bandwidth setting\n") |
601 warning(2,"$LADCP_file: wide-bandwidth setting\n") |
563 if ($LADCP{WIDE_BANDWIDTH}); |
602 if ($LADCP{WIDE_BANDWIDTH}); |
564 warning(2,"$LADCP_file: low transmit-power setting\n") |
603 warning(2,"$LADCP_file: low transmit-power setting\n") |
661 } |
704 } |
662 error("$LADCP_file: no valid data\n") unless ($nvv > 0); |
705 error("$LADCP_file: no valid data\n") unless ($nvv > 0); |
663 progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv)); |
706 progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv)); |
664 } |
707 } |
665 |
708 |
|
709 #------------------------------------------------------------ |
|
710 # Create beam coordinate velocities for Earth-velocity data |
|
711 # - velocities are replaced "in place" |
|
712 # - BT velocities are treated separately in [find_seabed.pl] |
|
713 # - this transformation will remove all 3-beam solutions |
|
714 # - disable bin mapping because Earth coords are typically bin-remapped |
|
715 #------------------------------------------------------------ |
|
716 |
|
717 unless ($LADCP{BEAM_COORDINATES}) { |
|
718 progress("Replacing earth- with beam-velocities...\n"); |
|
719 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
|
720 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
721 @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]} = |
|
722 &velEarthToBeam(\%LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}); |
|
723 } |
|
724 } |
|
725 $RDI_Coords::binMapping = 'none'; |
|
726 } |
|
727 |
|
728 &antsAddParams('RDI_Coords::binMapping',$RDI_Coords::binMapping); # finally, bin mapping is known |
|
729 |
666 #------------------------------------------------------------------- |
730 #------------------------------------------------------------------- |
667 # Calculate earth velocities |
731 # Calculate earth velocities |
668 # - this is done for all bins (not just valid ones), to allow |
732 # - this is done for all bins (not just valid ones), to allow |
669 # useless possibility that invalid bins are used for reflr calcs |
733 # useless possibility that invalid bins are used for reflr calcs |
670 # - also calculate separate beam-pair velocities |
734 # - also calculate separate beam-pair velocities |
671 # - the UNEDITED velocities are saved for the BT calculations |
735 # - the UNEDITED velocities are saved for the BT calculations |
672 # (W is required, U & V are only used for stats that have not |
736 # (W is required, U & V are only used for stats that have not |
673 # been very useful so far) |
737 # been very useful so far) |
674 #------------------------------------------------------------------- |
738 #------------------------------------------------------------------- |
675 |
739 |
676 if ($LADCP{BEAM_COORDINATES}) { |
740 my($dummy); |
677 my($dummy); |
741 progress("Calculating earth-coordinate velocities...\n"); |
678 progress("Calculating earth-coordinate velocities...\n"); |
742 if ($bad_beam) { |
|
743 progress("\tdiscarding velocities from beam $bad_beam\n"); |
|
744 &antsAddParams('bad_beam_discarded',$bad_beam); |
|
745 } |
|
746 $nvw = 0; |
|
747 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
|
748 $LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH} = |
|
749 gimbal_pitch($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL}); |
|
750 |
679 if ($bad_beam) { |
751 if ($bad_beam) { |
680 progress("\tdiscarding velocities from beam $bad_beam\n"); |
752 for (my($bin)=0; $bin<=$LADCP{N_BINS}-1; $bin++) { |
681 &antsAddParams('bad_beam_discarded',$bad_beam); |
753 undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$bad_beam-1]); |
682 } |
754 undef($LADCP{ENSEMBLE}[$ens]->{BT_VELOCITY}[$bin][$bad_beam-1]); |
683 $nvw = 0; |
755 } |
684 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
756 } |
685 $LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH} = |
757 |
686 gimbal_pitch($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL}); |
758 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
687 |
759 ($LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin], |
688 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
760 $LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin], |
689 if ($bad_beam) { |
761 $LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin], |
690 undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$bad_beam-1]); |
762 $LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]) = earthVels(\%LADCP,$ens,$bin); |
691 undef($LADCP{ENSEMBLE}[$ens]->{BT_VELOCITY}[$bin][$bad_beam-1]); |
763 ($LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{W12}[$bin], |
692 } |
764 $LADCP{ENSEMBLE}[$ens]->{V34}[$bin],$LADCP{ENSEMBLE}[$ens]->{W34}[$bin]) = BPEarthVels(\%LADCP,$ens,$bin); |
693 ($LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin], |
765 } |
694 $LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin], |
766 |
695 $LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin], |
767 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
696 $LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]) = earthVels(\%LADCP,$ens,$bin); |
768 $LADCP{ENSEMBLE}[$ens]->{U}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin]; |
697 ($LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{W12}[$bin], |
769 $LADCP{ENSEMBLE}[$ens]->{V}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin]; |
698 $LADCP{ENSEMBLE}[$ens]->{V34}[$bin],$LADCP{ENSEMBLE}[$ens]->{W34}[$bin]) = BPEarthVels(\%LADCP,$ens,$bin); |
770 $LADCP{ENSEMBLE}[$ens]->{W}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin]; |
699 } |
771 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]; |
700 |
772 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin]); |
701 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
773 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin]); |
702 $LADCP{ENSEMBLE}[$ens]->{U}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin]; |
774 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin]); |
703 $LADCP{ENSEMBLE}[$ens]->{V}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin]; |
775 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]); |
704 $LADCP{ENSEMBLE}[$ens]->{W}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin]; |
776 |
705 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin] = $LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]; |
777 if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) { |
706 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_U}[$bin]); |
778 $per_bin_nsamp[$bin]++; |
707 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_V}[$bin]); |
779 $nvw++; |
708 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_W}[$bin]); |
780 } |
709 undef($LADCP{ENSEMBLE}[$ens]->{INTERP_ERRVEL}[$bin]); |
781 |
710 |
782 $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{U}[$bin]; |
711 if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) { |
783 $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V}[$bin]; |
712 $per_bin_nsamp[$bin]++; |
784 $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin]; |
713 $nvw++; |
785 } |
714 } |
786 } |
715 |
787 progress("\t$nvw valid velocities in bins $LADCP_firstBin-$LADCP_lastBin\n"); |
716 $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{U}[$bin]; |
788 progress("\t3-beam solutions : $RDI_Coords::threeBeam_1 " . |
717 $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V}[$bin]; |
789 "$RDI_Coords::threeBeam_2 " . |
718 $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin]; |
790 "$RDI_Coords::threeBeam_3 " . |
719 } |
791 "$RDI_Coords::threeBeam_4\n") |
720 } |
792 unless ($opt_4); |
721 progress("\t$nvw valid velocities in bins $LADCP_firstBin-$LADCP_lastBin\n"); |
|
722 progress("\t3-beam solutions : $RDI_Coords::threeBeam_1 " . |
|
723 "$RDI_Coords::threeBeam_2 " . |
|
724 "$RDI_Coords::threeBeam_3 " . |
|
725 "$RDI_Coords::threeBeam_4\n") |
|
726 unless ($opt_4); |
|
727 } else { # Earth Coordinates |
|
728 progress("Counting valid vertical velocities...\n"); |
|
729 $nvw = 0; |
|
730 for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) { |
|
731 $LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH} = |
|
732 gimbal_pitch($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL}); |
|
733 for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
734 ($LADCP{ENSEMBLE}[$ens]->{U}[$bin], |
|
735 $LADCP{ENSEMBLE}[$ens]->{V}[$bin], |
|
736 $LADCP{ENSEMBLE}[$ens]->{W}[$bin], |
|
737 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) = @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}; |
|
738 if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) { |
|
739 $per_bin_nsamp[$bin]++; |
|
740 $nvw++; |
|
741 } |
|
742 $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{U}[$bin]; |
|
743 $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V}[$bin]; |
|
744 $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin]; |
|
745 |
|
746 $LADCP{ENSEMBLE}[$ens]->{V12}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V34}[$bin] = nan; |
|
747 |
|
748 # for 3-beam solutions, w12 = w34 = w (I think) |
|
749 ($LADCP{ENSEMBLE}[$ens]->{W12}[$bin],$LADCP{ENSEMBLE}[$ens]->{W34}[$bin]) = |
|
750 velEarthToBPw($LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}); |
|
751 } |
|
752 } |
|
753 progress("\t$nvw valid velocities in bins $LADCP_firstBin-$LADCP_lastBin\n"); |
|
754 } |
|
755 |
793 |
756 error("$LADCP_file: insufficient valid velocities\n") unless ($nvw >= $min_valid_vels); |
794 error("$LADCP_file: insufficient valid velocities\n") unless ($nvw >= $min_valid_vels); |
757 |
795 |
758 #---------------------------------------------- |
796 #---------------------------------------------- |
759 # STEP: Edit earth-coordinate -velocity data |
797 # STEP: Edit earth-coordinate -velocity data |
894 progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n", |
934 progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n", |
895 $opt_t,$pte,round(100*$pte/$nvv)); |
935 $opt_t,$pte,round(100*$pte/$nvv)); |
896 progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n", |
936 progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n", |
897 round(100*$per_bin_valid_frac_lim),$fprm,round(100*$fprm/$nvw)); |
937 round(100*$per_bin_valid_frac_lim),$fprm,round(100*$fprm/$nvw)); |
898 |
938 |
899 #-------------- |
939 #---------------------------------------------------------------------- |
900 # Read CTD data |
940 # Read CTD data |
901 #-------------- |
941 #---------------------------------------------------------------------- |
902 |
942 |
903 progress("Reading CTD data from <$CTD_file>...\n"); |
943 progress("Reading CTD data from <$CTD_file>...\n"); |
904 open(STDIN,$CTD_file) || error("$CTD_file: $!\n"); |
944 open(STDIN,$CTD_file) || error("$CTD_file: $!\n"); |
905 error("$CTD_file: no data\n") unless (&antsIn()); |
945 error("$CTD_file: no data\n") unless (&antsIn()); |
906 undef($antsOldHeaders); |
946 undef($antsOldHeaders); |
907 |
947 |
|
948 &antsAddDeps($CTD_file); |
908 &antsAddParams('lat',$P{lat}) if defined($P{lat}); |
949 &antsAddParams('lat',$P{lat}) if defined($P{lat}); |
909 &antsAddParams('lon',$P{lon}) if defined($P{lon}); |
950 &antsAddParams('lon',$P{lon}) if defined($P{lon}); |
910 |
951 |
911 ($CTD_elapsed,$CTD_depth,$CTD_svel) = &fnr('elapsed','depth','ss'); |
952 ($CTD_elapsed,$CTD_depth,$CTD_svel) = &fnr('elapsed','depth','ss'); |
912 $CTD_w = &fnrNoErr('w_CTD'); |
953 $CTD_w = &fnrNoErr('w_CTD'); |
1339 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
1385 progress("\t$nvrm velocities from $nerm ensembles removed\n"); |
1340 } |
1386 } |
1341 } |
1387 } |
1342 |
1388 |
1343 #---------------------------------------------------------------------- |
1389 #---------------------------------------------------------------------- |
|
1390 # Check For Ambiguity Velocity Problems |
|
1391 #---------------------------------------------------------------------- |
|
1392 |
|
1393 progress("Checking for ambiguity velocity violations...\n"); |
|
1394 |
|
1395 my($ambiguity_velocity) = ambiguity_velocity($LADCP{BEAM_FREQUENCY}, |
|
1396 $LADCP{BEAM_ANGLE}, |
|
1397 $LADCP{SPEED_OF_SOUND}, |
|
1398 $LADCP{TRANSMIT_LAG_DISTANCE}); |
|
1399 &antsAddParams('ambiguity_velocity',$ambiguity_velocity); |
|
1400 my($nbad) = 0; |
|
1401 for (my($ens)=$firstGoodEns; $ens<=$lastGoodEns; $ens++) { |
|
1402 next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}); |
|
1403 next unless ($CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}] > $ambiguity_velocity); |
|
1404 $nbad++; |
|
1405 } |
|
1406 |
|
1407 my($badf) = $nbad / ($lastGoodEns - $firstGoodEns + 1); # fraction of bad values |
|
1408 if ($bad > 0.01) { # allow 1% violations before warning is triggered |
|
1409 warning(2,"%d ensembles (%d%% of total) have CTD_w > ambiguity velocity of %.1 m/s\n", |
|
1410 $nbad,round(100*$badf),$ambiguity_velocity); |
|
1411 } elsif ($nbad > 0) { |
|
1412 info("\t%d ensembles (%d%% of total) have CTD_w > ambiguity velocity of %.1 m/s", |
|
1413 $nbad,round(100*$badf),$ambiguity_velocity); |
|
1414 } else { |
|
1415 info("\tnone found\n"); |
|
1416 } |
|
1417 |
|
1418 #---------------------------------------------------------------------- |
1344 # Data Editing after LADCP and CTD data have been merged |
1419 # Data Editing after LADCP and CTD data have been merged |
1345 # 1) surface layer editing |
1420 # 1) surface layer editing |
1346 # 2) Execute user-supplied $edit_data_hook |
1421 # 2) reference-layer horizontal velocity threshold |
|
1422 # 3) Execute user-supplied $edit_data_hook |
1347 #---------------------------------------------------------------------- |
1423 #---------------------------------------------------------------------- |
1348 |
1424 |
1349 progress("Removing data from instrument at surface...\n"); |
1425 progress("Removing data from instrument at surface...\n"); |
1350 &antsAddParams('surface_layer_depth',$surface_layer_depth); |
1426 &antsAddParams('surface_layer_depth',$surface_layer_depth); |
1351 $nerm = editSurfLayer($firstGoodEns,$lastGoodEns,$surface_layer_depth); |
1427 $nerm = editSurfLayer($firstGoodEns,$lastGoodEns,$surface_layer_depth); |
1352 progress("\t$nerm ensembles removed\n"); |
1428 progress("\t$nerm ensembles removed\n"); |
|
1429 |
|
1430 progress("Removing data collected at large horizontal package speeds...\n"); |
|
1431 $max_hspeed = &max_hspeed(); # defined in [defaults.h] |
|
1432 &antsAddParams('max_hspeed',$max_hspeed); |
|
1433 $nerm = editLargeHSpeeds($firstGoodEns,$lastGoodEns,$max_hspeed); |
|
1434 my($nermf) = $nerm / ($lastGoodEns - $firstGoodEns + 1); |
|
1435 info("\treference-layer horizontal speed threshold (max_hspeed = %g m/s): %d ensembles removed (%d%% of total)\n", |
|
1436 $max_hspeed,$nerm,round(100*$nermf)); |
|
1437 warning(2,"large fraction (%d%%) of samples exceed reference-layer horizontal speed threshold\n",round(100*$nermf)) |
|
1438 if ($nermf > 0.05); |
1353 |
1439 |
1354 if (defined($post_merge_hook)) { |
1440 if (defined($post_merge_hook)) { |
1355 progress("Executing user-supplied \$post_merge_hook...\n"); |
1441 progress("Executing user-supplied \$post_merge_hook...\n"); |
1356 &{$post_merge_hook}($firstGoodEns,$lastGoodEns); |
1442 &{$post_merge_hook}($firstGoodEns,$lastGoodEns); |
1357 } |
1443 } |
1585 |
1674 |
1586 progress("\tre-binning profile data...\n"); |
1675 progress("\tre-binning profile data...\n"); |
1587 |
1676 |
1588 for (my($bi)=0; $bi<=$#{$DNCAST{ENSEMBLE}}; $bi++) { # bin data |
1677 for (my($bi)=0; $bi<=$#{$DNCAST{ENSEMBLE}}; $bi++) { # bin data |
1589 for (my($i)=0; $i<@{$DNCAST{W}[$bi]}; $i++) { # code works if MEDIAN_RESIDUAL_W is nan (possible?) |
1678 for (my($i)=0; $i<@{$DNCAST{W}[$bi]}; $i++) { # code works if MEDIAN_RESIDUAL_W is nan (possible?) |
1590 $DNCAST{W} [$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1679 $DNCAST{W} [$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1591 $DNCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1680 if numberp($DNCAST{W}[$bi][$i]); |
1592 $DNCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1681 $DNCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1593 } |
1682 if numberp($DNCAST{W12}[$bi][$i]); |
1594 $DNCAST{MEDIAN_W} [$bi] = median(@{$DNCAST{W}[$bi]}); |
1683 $DNCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1595 $DNCAST{MEDIAN_W12}[$bi] = median(@{$DNCAST{W12}[$bi]}); |
1684 if numberp($DNCAST{W34}[$bi][$i]); |
1596 $DNCAST{MEDIAN_W34}[$bi] = median(@{$DNCAST{W34}[$bi]}); |
1685 } |
|
1686 $DNCAST{MEDIAN_W} [$bi] = median(@{$DNCAST{W}[$bi]}) if numberp($DNCAST{MEDIAN_W} [$bi]); |
|
1687 $DNCAST{MEDIAN_W12}[$bi] = median(@{$DNCAST{W12}[$bi]}) if numberp($DNCAST{MEDIAN_W12}[$bi]); |
|
1688 $DNCAST{MEDIAN_W34}[$bi] = median(@{$DNCAST{W34}[$bi]}) if numberp($DNCAST{MEDIAN_W34}[$bi]); |
1597 $DNCAST{MAD_W} [$bi] = mad2($DNCAST{MEDIAN_W}[$bi],@{$DNCAST{W}[$bi]}); |
1689 $DNCAST{MAD_W} [$bi] = mad2($DNCAST{MEDIAN_W}[$bi],@{$DNCAST{W}[$bi]}); |
1598 } |
1690 } |
1599 for (my($bi)=0; $bi<=$#{$UPCAST{ENSEMBLE}}; $bi++) { |
1691 for (my($bi)=0; $bi<=$#{$UPCAST{ENSEMBLE}}; $bi++) { |
1600 for (my($i)=0; $i<@{$UPCAST{W}[$bi]}; $i++) { |
1692 for (my($i)=0; $i<@{$UPCAST{W}[$bi]}; $i++) { |
1601 $UPCAST{W} [$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1693 $UPCAST{W} [$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1602 $UPCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1694 if numberp($UPCAST{W}[$bi][$i]); |
1603 $UPCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W}; |
1695 $UPCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1604 } |
1696 if numberp($UPCAST{W12}[$bi][$i]); |
1605 $UPCAST{MEDIAN_W} [$bi] = median(@{$UPCAST{W}[$bi]}); |
1697 $UPCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W} |
1606 $UPCAST{MEDIAN_W12}[$bi] = median(@{$UPCAST{W12}[$bi]}); |
1698 if numberp($UPCAST{W34}[$bi][$i]); |
1607 $UPCAST{MEDIAN_W34}[$bi] = median(@{$UPCAST{W34}[$bi]}); |
1699 } |
|
1700 $UPCAST{MEDIAN_W} [$bi] = median(@{$UPCAST{W}[$bi]}) if numberp($UPCAST{MEDIAN_W} [$bi]); |
|
1701 $UPCAST{MEDIAN_W12}[$bi] = median(@{$UPCAST{W12}[$bi]}) if numberp($UPCAST{MEDIAN_W12}[$bi]); |
|
1702 $UPCAST{MEDIAN_W34}[$bi] = median(@{$UPCAST{W34}[$bi]}) if numberp($UPCAST{MEDIAN_W34}[$bi]); |
1608 $UPCAST{MAD_W} [$bi] = mad2($UPCAST{MEDIAN_W}[$bi],@{$UPCAST{W}[$bi]}); |
1703 $UPCAST{MAD_W} [$bi] = mad2($UPCAST{MEDIAN_W}[$bi],@{$UPCAST{W}[$bi]}); |
1609 } |
1704 } |
1610 |
1705 |
1611 } # unless ($opt_q); |
1706 } # unless ($opt_q); |
1612 |
1707 |
1613 #---------------------------------------------------------------------- |
1708 #---------------------------------------------------------------------- |
1614 # remove ensembles with large rms residuals |
1709 # remove ensembles with large rms residuals |
1615 #---------------------------------------------------------------------- |
1710 #---------------------------------------------------------------------- |
1616 |
1711 |
1617 if (defined($opt_r)) { |
1712 if (defined($opt_r) && !$opt_q) { |
1618 progress("Applying residuals filters...\n"); |
1713 progress("Applying residuals filters...\n"); |
1619 |
1714 |
1620 progress("\trms residuals > $residuals_rms_max: "); |
1715 progress("\trms residuals > $residuals_rms_max: "); |
1621 my($nerm) = editResiduals_rmsMax($firstGoodEns,$lastGoodEns,$residuals_rms_max); |
1716 my($nerm) = editResiduals_rmsMax($firstGoodEns,$lastGoodEns,$residuals_rms_max); |
1622 progress("$nerm ensembles removed (%d%% of total)\n",round(100*$nerm/($lastGoodEns-$firstGoodEns+1))); |
1717 progress("$nerm ensembles removed (%d%% of total)\n",round(100*$nerm/($lastGoodEns-$firstGoodEns+1))); |
1900 $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},1, |
2006 $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},1, |
1901 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin], |
2007 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin], |
1902 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin], |
2008 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin], |
1903 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin], |
2009 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin], |
1904 $LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{V34}[$bin], |
2010 $LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{V34}[$bin], |
1905 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi], |
2011 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],$DNCAST{MEDIAN_W}[$bi]), |
1906 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] - $DNCAST{MEDIAN_W}[$bi], |
2012 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin],$DNCAST{MEDIAN_W}[$bi]), |
1907 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] - $DNCAST{MEDIAN_W}[$bi], |
2013 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin],$DNCAST{MEDIAN_W}[$bi]), |
1908 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2014 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1909 $CTD{W_t}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2015 $CTD{W_t}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1910 $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2016 $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1911 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin], |
2017 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin], |
1912 $LADCP{ENSEMBLE}[$ens]->{REFLR_W}, |
2018 $LADCP{ENSEMBLE}[$ens]->{REFLR_W}, |
1940 $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},0, |
2046 $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},0, |
1941 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin], |
2047 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin], |
1942 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin], |
2048 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin], |
1943 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin], |
2049 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin], |
1944 $LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{V34}[$bin], |
2050 $LADCP{ENSEMBLE}[$ens]->{V12}[$bin],$LADCP{ENSEMBLE}[$ens]->{V34}[$bin], |
1945 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi], |
2051 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],$UPCAST{MEDIAN_W}[$bi]), |
1946 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] - $UPCAST{MEDIAN_W}[$bi], |
2052 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin],$UPCAST{MEDIAN_W}[$bi]), |
1947 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] - $UPCAST{MEDIAN_W}[$bi], |
2053 res($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin],$UPCAST{MEDIAN_W}[$bi]), |
1948 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2054 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1949 $CTD{W_t}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2055 $CTD{W_t}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1950 $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
2056 $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}], |
1951 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin], |
2057 $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin], |
1952 $LADCP{ENSEMBLE}[$ens]->{REFLR_W}, |
2058 $LADCP{ENSEMBLE}[$ens]->{REFLR_W}, |