forked from dankelley/oce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adp.R
2901 lines (2851 loc) · 155 KB
/
adp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## vim: tw=120 shiftwidth=4 softtabstop=4 expandtab:
#' Class to Hold adp (adcp) Data
#'
#' This class stores data from acoustic Doppler profilers. Some manufacturers
#' call these ADCPs, while others call them ADPs; here the shorter form is
#' used by analogy to ADVs.
#'
#' The \code{metadata} slot contains various
#' items relating to the dataset, including source file name, sampling rate,
#' velocity resolution, velocity maximum value, and so on. Some of these are
#' particular to particular instrument types, and prudent researchers will take
#' a moment to examine the whole contents of the metadata, either in summary
#' form (with \code{str(adp[["metadata"]])}) or in detail (with
#' \code{adp[["metadata"]]}). Perhaps the most useful general properties are
#' \code{adp[["bin1Distance"]]} (the distance, in metres, from the sensor to
#' the bottom of the first bin), \code{adp[["cellSize"]]} (the cell height, in
#' metres, in the vertical direction, \emph{not} along the beam), and
#' \code{adp[["beamAngle"]]} (the angle, in degrees, between beams and an
#' imaginary centre line that bisects all beam pairs).
#'
#' The diagram provided below indicates the coordinate-axis and beam-numbering
#' conventions for three- and four-beam ADP devices, viewed as though the
#' reader were looking towards the beams being emitted from the transducers.
#'
#' \if{html}{\figure{adp_beams.png}{options: width=400px alt="Figure: adp_beams.png"}}
#'
#' The bin geometry of a four-beam profiler is illustrated below, for
#' \code{adp[["beamAngle"]]} equal to 20 degrees, \code{adp[["bin1Distance"]]}
#' equal to 2m, and \code{adp[["cellSize"]]} equal to 1m. In the diagram, the
#' viewer is in the plane containing two beams that are not shown, so the two
#' visible beams are separated by 40 degrees. Circles indicate the centres of
#' the range-gated bins within the beams. The lines enclosing those circles
#' indicate the coverage of beams that spread plus and minus 2.5 degrees from
#' their centreline.
#'
#' \if{html}{\figure{adpgeometry2.png}{options: width=400px alt="Figure: adpgeometry2.png"}}
#'
#' Note that \code{adp[["oceCoordinate"]]} stores the present coordinate system
#' of the object, and it has possible values \code{"beam"}, \code{"xyz"} or
#' \code{"enu"}. (This should not be confused with
#' \code{adp[["originalCoordinate"]]}, which stores the coordinate system used
#' in the original data file.)
#'
#' The \code{data} slot holds some standardized items, and
#' many that vary from instrument to instrument. One standard item is
#' \code{adp[["v"]]}, a three-dimensional numeric matrix of velocities in
#' m/s. In this matrix, the first index indicates time, the second bin
#' number, and the third beam number. The meanings of the beams depends on
#' whether the object is in beam coordinates, frame coordinates, or earth
#' coordinates.
#'
#' Corresponding to the velocity matrix are two matrices of type raw, and
#' identical dimension, accessed by \code{adp[["a"]]} and \code{adp[["q"]]},
#' holding measures of signal strength and data quality quality,
#' respectively. (The exact meanings of these depend on the particular type
#' of instrument, and it is assumed that users will be familiar enough with
#' instruments to know both the meanings and their practical consequences in
#' terms of data-quality assessment, etc.)
#'
#' In addition to the matrices, there are time-based vectors. The vector
#' \code{adp[["time"]]} (of length equal to the first index of
#' \code{adp[["v"]]}, etc.) holds times of observation. Depending on type of
#' instrument and its configuration, there may also be corresponding vectors
#' for sound speed (\code{adp[["soundSpeed"]]}), pressure
#' (\code{adp[["pressure"]]}), temperature (\code{adp[["temperature"]]}),
#' heading (\code{adp[["heading"]]}) pitch (\code{adp[["pitch"]]}), and roll
#' (\code{adp[["roll"]]}), depending on the setup of the instrument.
#'
#' The precise meanings of the data items depend on the instrument type. All
#' instruments have \code{v} (for velocity), \code{q} (for a measure of data
#' quality) and \code{a} (for a measure of backscatter amplitude, also called
#' echo intensity).
#'
#' Teledyne-RDI profilers have an additional item \code{g} (for
#' percent-good).
#'
#' VmDas-equiped Teledyne-RDI profilers additional navigation data, with
#' details listed in the table below; note that the RDI documentation [2] and
#' the RDI gui use inconsistent names for most items.
#'
#' \tabular{lll}{
#' \strong{Oce name}\tab \strong{RDI doc name}\tab \strong{RDI GUI name}\cr
#' \code{avgSpeed}\tab Avg Speed\tab Speed/Avg/Mag\cr
#' \code{avgMagnitudeVelocityEast}\tab Avg Mag Vel East\tab ?\cr
#' \code{avgMagnitudeVelocityNorth}\tab Avg Mag Vel North\tab ?\cr
#' \code{avgTrackMagnetic}\tab Avg Track Magnetic\tab Speed/Avg/Dir (?)\cr
#' \code{avgTrackTrue}\tab Avg Track True\tab Speed/Avg/Dir (?)\cr
#' \code{avgTrueVelocityEast}\tab Avg True Vel East\tab ?\cr
#' \code{avgTrueVelocityNorth}\tab Avg True Vel North\tab ?\cr
#' \code{directionMadeGood}\tab Direction Made Good\tab Speed/Made Good/Dir\cr
#' \code{firstLatitude}\tab First latitude\tab Start Lat\cr
#' \code{firstLongitude}\tab First longitude\tab Start Lon\cr
#' \code{firstTime}\tab UTC Time of last fix\tab End Time\cr
#' \code{lastLatitude}\tab Last latitude\tab End Lat\cr
#' \code{lastLongitude}\tab Last longitude\tab End Lon\cr
#' \code{lastTime}\tab UTC Time of last fix\tab End Time\cr
#' \code{numberOfHeadingSamplesAveraged}\tab Number heading samples averaged\tab ?\cr
#' \code{numberOfMagneticTrackSamplesAveraged}\tab Number of magnetic track samples averaged\tab ? \cr
#' \code{numberOfPitchRollSamplesAvg}\tab Number of magnetic track samples averaged\tab ? \cr
#' \code{numberOfSpeedSamplesAveraged}\tab Number of speed samples averaged\tab ? \cr
#' \code{numberOfTrueTrackSamplesAvg}\tab Number of true track samples averaged\tab ? \cr
#' \code{primaryFlags}\tab Primary Flags\tab ?\cr
#' \code{shipHeading}\tab Heading\tab ?\cr
#' \code{shipPitch}\tab Pitch\tab ?\cr
#' \code{shipRoll}\tab Roll\tab ?\cr
#' \code{speedMadeGood}\tab Speed Made Good\tab Speed/Made Good/Mag\cr
#' \code{speedMadeGoodEast}\tab Speed MG East\tab ?\cr
#' \code{speedMadeGoodNorth}\tab Speed MG North\tab ?\cr
#' }
#'
#' For Teledyne-RDI profilers, there are four three-dimensional arrays
#' holding beamwise data. In these, the first index indicates time, the
#' second bin number, and the third beam number (or coordinate number, for
#' data in \code{xyz}, \code{enu} or \code{other} coordinate systems). In
#' the list below, the quoted phrases are quantities as defined in Figure 9
#' of reference 1.
#'
#' \itemize{
#'
#' \item \code{v} is ``velocity'' in m/s, inferred from two-byte signed
#' integer values (multiplied by the scale factor that is stored in
#' \code{velocityScale} in the metadata).
#'
#' \item \code{q} is ``correlation magnitude'' a one-byte quantity stored
#' as type \code{raw} in the object. The values may range from 0 to 255.
#'
#' \item \code{a} is ``backscatter amplitude``, also known as ``echo
#' intensity'' a one-byte quantity stored as type \code{raw} in the object.
#' The values may range from 0 to 255.
#'
#' \item \code{g} is ``percent good'' a one-byte quantity stored as \code{raw}
#' in the object. The values may range from 0 to 100.
#'
#' }
#'
#' Finally, there is a vector \code{adp[["distance"]]} that indicates the bin
#' distances from the sensor, measured in metres along an imaginary centre
#' line bisecting beam pairs. The length of this vector equals
#' \code{dim(adp[["v"]])[2]}.
#'
#' The \code{processingLog} slot is in standard form and needs little comment.
#'
#' @section Accessing and altering information within \code{adp-class} objects:
#' \emph{Extracting values} Matrix data may be accessed as illustrated
#' above, e.g. or an adp object named \code{adv}, the data are provided by
#' \code{adp[["v"]]}, \code{adp[["a"]]}, and \code{adp[["q"]]}. As a
#' convenience, the last two of these can be accessed as numeric (as opposed to
#' raw) values by e.g. \code{adp[["a", "numeric"]]}. The vectors are accessed
#' in a similar way, e.g. \code{adp[["heading"]]}, etc. Quantities in the
#' \code{metadata} slot are also available by name, e.g.
#' \code{adp[["velocityResolution"]]}, etc.
#'
#' \emph{Assigning values.} This follows the standard form, e.g. to increase
#' all velocity data by 1 cm/s, use \code{adp[["v"]] <- 0.01 + adp[["v"]]}.
#'
#' \emph{Overview of contents} The \code{show} method (e.g.
#' \code{show(d)}) displays information about an ADP object named \code{d}.
#'
#' @section Dealing with suspect data:
#' There are many possibilities for confusion
#' with \code{adp} devices, owing partly to the flexibility that manufacturers
#' provide in the setup. Prudent users will undertake many tests before trusting
#' the details of the data. Are mean currents in the expected direction, and of
#' the expected magnitude, based on other observations or physical constraints?
#' Is the phasing of currents as expected? If the signals are suspect, could an
#' incorrect scale account for it? Could the transformation matrix be incorrect?
#' Might the data have exceeded the maximum value, and then ``wrapped around'' to
#' smaller values? Time spent on building confidence in data quality is seldom
#' time wasted.
#'
#' @section References:
#' 1. Teledyne-RDI, 2007. \emph{WorkHorse commands and output data
#' format.} P/N 957-6156-00 (November 2007).
#'
#' 2. Teledyne-RDI, 2012. \emph{VmDas User's Guide, Ver. 1.46.5}.
#'
#' @seealso
#' A file containing ADP data is usually recognized by Oce, and so
#' \code{\link{read.oce}} will usually read the data. If not, one may use the
#' general ADP function \code{\link{read.adp}} or specialized variants
#' \code{\link{read.adp.rdi}}, \code{\link{read.adp.nortek}} or
#' \code{\link{read.adp.sontek}} or \code{\link{read.adp.sontek.serial}}.
#'
#' ADP data may be plotted with \code{\link{plot,adp-method}}, which is a
#' generic function so it may be called simply as \code{plot}.
#'
#' Statistical summaries of ADP data are provided by the generic function
#' \code{summary}, while briefer overviews are provided with \code{show}.
#'
#' Conversion from beam to xyz coordinates may be done with
#' \code{\link{beamToXyzAdp}}, and from xyz to enu (east north up) may be done
#' with \code{\link{xyzToEnuAdp}}. \code{\link{toEnuAdp}} may be used to
#' transfer either beam or xyz to enu. Enu may be converted to other coordinates
#' (e.g. aligned with a coastline) with \code{\link{enuToOtherAdp}}.
#'
#' @family classes provided by \code{oce}
#' @family things related to \code{adp} data
setClass("adp", contains="oce")
#' ADP (acoustic-doppler profiler) dataset
#'
#' This is degraded subsample of measurements that were made with an
#' upward-pointing ADP manufactured by Teledyne-RDI, as part of the St Lawrence
#' Internal Wave Experiment (SLEIWEX).
#'
#' @name adp
#'
#' @docType data
#'
#' @usage data(adp)
#'
#' @examples
#' \dontrun{
#' library(oce)
#' data(adp)
#'
#' # Velocity components. (Note: we should probably trim some bins at top.)
#' plot(adp)
#'
#' # Note that tides have moved the mooring.
#' plot(adp, which=15:18)
#' }
#'
#'
#' @source This file came from the SLEIWEX-2008 experiment.
#'
#' @family datasets provided with \code{oce}
#' @family things related to \code{adp} data
NULL
setMethod(f="initialize",
signature="adp",
definition=function(.Object, time, distance, v, a, q, oceCoordinate="enu", orientation="upward") {
if (!missing(time)) .Object@data$time <- time
if (!missing(distance)) {
.Object@data$distance <- distance
.Object@metadata$cellSize <- tail(diff(distance), 1) # first one has blanking, perhaps
}
if (!missing(v)) {
.Object@data$v <- v
.Object@metadata$numberOfBeams <- dim(v)[3]
.Object@metadata$numberOfCells <- dim(v)[2]
}
if (!missing(a)) .Object@data$a <- a
if (!missing(q)) .Object@data$q <- q
.Object@metadata$units$v <- list(unit=expression(m/s), scale="")
.Object@metadata$units$distance <- list(unit=expression(m), scale="")
.Object@metadata$oceCoordinate <- oceCoordinate # FIXME: should check that it is allowed
.Object@metadata$orientation <- orientation # FIXME: should check that it is allowed
.Object@processingLog$time <- as.POSIXct(Sys.time())
.Object@processingLog$value <- "create 'adp' object"
return(.Object)
})
#' Summarize an ADP object
#'
#' Summarize data in an \code{adp} object.
#'
#' Pertinent summary information is presented.
#'
#' @aliases summary.adp summary,adp,missing-method summary,adp-method
#' @param object an object of class \code{"adp"}, usually, a result of a call
#' to \code{\link{read.oce}}, \code{\link{read.adp.rdi}}, or
#' \code{\link{read.adp.nortek}}.
#' @param \dots further arguments passed to or from other methods.
#' @return A matrix containing statistics of the elements of the \code{data}
#' slot.
#' @author Dan Kelley
#'
#' @family things related to \code{adp} data
setMethod(f="summary",
signature="adp",
definition=function(object, ...) {
mnames <- names(object@metadata)
cat("ADP Summary\n-----------\n\n", ...)
if ("instrumentType" %in% mnames)
cat(paste("* Instrument: ", object@metadata$instrumentType, "\n", sep=""), ...)
if ("manufacturere" %in% mnames)
cat("* Manufacturer: ", object@metadata$manufacturer, "\n")
if ("serialNumber" %in% mnames)
cat(paste("* Serial number: ", object@metadata$serialNumber, "\n", sep=""), ...)
if ("firmwareVersion" %in% mnames)
cat(paste("* Firmware version: ", object@metadata$firmwareVersion, "\n", sep=""), ...)
if ("filename" %in% mnames)
cat(paste("* Source filename: ``", object@metadata$filename, "``\n", sep=""), ...)
if ("latitude" %in% names(object@metadata)) {
cat(paste("* Location: ",
if (is.na(object@metadata$latitude)) "unknown latitude" else sprintf("%.5f N", object@metadata$latitude), ", ",
if (is.na(object@metadata$longitude)) "unknown longitude" else sprintf("%.5f E",
object@metadata$longitude),
"\n", sep=''))
}
v.dim <- dim(object@data$v)
cat("* Number of profiles:", v.dim[1], "\n")
cat("* Number of cells: ", v.dim[2], "\n")
cat("* Number of beams: ", v.dim[3], "\n")
cat("* Cell size: ", object@metadata$cellSize, "m\n")
if (1 == length(agrep("nortek", object@metadata$manufacturer, ignore.case=TRUE))) {
resSpecific <- list(internalCodeVersion=object@metadata$internalCodeVersion,
hardwareRevision=object@metadata$hardwareRevision,
recSize=object@metadata$recSize*65536/1024/1024,
velocityRange=object@metadata$velocityRange,
firmwareVersion=object@metadata$firmwareVersion,
config=object@metadata$config,
configPressureSensor=object@metadata$configPressureSensor,
configMagnetometerSensor=object@metadata$configMagnetometerSensor,
configTiltSensor=object@metadata$configPressureSensor,
configPressureSensor=object@metadata$configTiltSensor,
serialNumberHead=object@metadata$serialNumberHead,
blankingDistance=object@metadata$blankingDistance,
measurementInterval=object@metadata$measurementInterval,
deploymentName=object@metadata$deploymentName,
velocityScale=object@metadata$velocityScale)
} else if (1 == length(agrep("rdi", object@metadata$manufacturer, ignore.case=TRUE))) {
resSpecific <- list(instrumentSubtype=object@metadata[["instrumentSubtype"]],
manufacturer=object@metadata$manufacturer,
numberOfDataTypes=object@metadata$numberOfDataTypes,
headingAlignment=object@metadata$headingAlignment,
headingBias=object@metadata$headingBias,
pingsPerEnsemble=object@metadata$pingsPerEnsemble,
bin1Distance=object@metadata$bin1Distance,
xmitPulseLength=object@metadata$xmitPulseLength,
oceBeamSpreaded=object@metadata$oceBeamSpreaded,
beamConfig=object@metadata$beamConfig)
} else if (1 == length(agrep("sontek", object@metadata$manufacturer, ignore.case=TRUE))) {
resSpecific <- list(cpuSoftwareVerNum=object@metadata$cpuSoftwareVerNum,
dspSoftwareVerNum=object@metadata$dspSoftwareVerNum,
boardRev=object@metadata$boardRev,
adpType=object@metadata$adpType,
slantAngle=object@metadata$slantAngle,
orientation=object@metadata$orientation)
} else {
resSpecific <- list(orientation=object@metadata$orientation)
#stop("can only summarize ADP objects of sub-type \"rdi\", \"sontek\", or \"nortek\", not class ", paste(class(object),collapse=","))
}
cat(sprintf("* Measurements: %s %s to %s %s sampled at %.4g Hz\n",
format(object@metadata$measurementStart), attr(object@metadata$measurementStart, "tzone"),
format(object@metadata$measurementEnd), attr(object@metadata$measurementEnd, "tzone"),
1 / object@metadata$measurementDeltat))
subsampleStart <- object@data$time[1]
subsampleDeltat <- as.numeric(object@data$time[2]) - as.numeric(object@data$time[1])
subsampleEnd <- object@data$time[length(object@data$time)]
cat(sprintf("* Subsample: %s %s to %s %s sampled at %.4g Hz\n",
format(subsampleStart), attr(subsampleStart, "tzone"),
format(subsampleEnd), attr(subsampleEnd, "tzone"),
1 / subsampleDeltat))
if (object@metadata$numberOfCells > 1)
cat(sprintf("* Cells: %d, centered at %.3f m to %.3f m, spaced by %.3f m\n",
object@metadata$numberOfCells, object@data$distance[1], tail(object@data$distance, 1), diff(object@data$distance[1:2])), ...)
else
cat(sprintf("* Cells: one cell, centered at %.3f m\n", object@data$distance[1]), ...)
cat("* Coordinate system: ", object@metadata$originalCoordinate, "[originally],", object@metadata$oceCoordinate, "[presently]\n", ...)
cat("* Frequency: ", object@metadata$frequency, "kHz\n", ...)
if ("oceBeamUnspreaded" %in% mnames)
cat("* Beams: ", object@metadata$numberOfBeams, if (!is.null(object@metadata$oceBeamUnspreaded) &
object@metadata$oceBeamUnspreaded) "beams (attenuated)" else "beams (not attenuated)",
"oriented", object@metadata$orientation, "with angle", object@metadata$beamAngle, "deg to axis\n", ...)
if (!is.null(object@metadata$transformationMatrix)) {
digits <- 4
cat("* Transformation matrix::\n\n")
cat(" ", format(object@metadata$transformationMatrix[1,], width=digits+4, digits=digits, justify="right"), "\n")
cat(" ", format(object@metadata$transformationMatrix[2,], width=digits+4, digits=digits, justify="right"), "\n")
cat(" ", format(object@metadata$transformationMatrix[3,], width=digits+4, digits=digits, justify="right"), "\n")
if (object@metadata$numberOfBeams > 3)
cat(" ", format(object@metadata$transformationMatrix[4,], width=digits+4, digits=digits, justify="right"), "\n")
}
callNextMethod()
})
#' @title Extract Parts of an \code{adp} Object
#'
#' In addition to the usual extraction of elements by name, some shortcuts
#' are also provided, e.g. \code{x[["u1"]]} retrieves \code{v[,1]}, and similarly
#' for the other velocity components. The \code{a} and \code{q}
#' data can be retrieved in \code{\link{raw}} form or numeric
#' form (see examples). The coordinate system may be
#' retrieved with e.g. \code{x[["coordinate"]]}.
#'
#' @param x An \code{adp} object, i.e. one inheriting from \code{\link{adp-class}}.
#' @template sub_subTemplate
#'
#' @examples
#' data(adp)
#' # Tests for beam 1, distance bin 1, first 5 observation times
#' adp[["v"]][1:5,1,1]
#' adp[["a"]][1:5,1,1]
#' adp[["a", "numeric"]][1:5,1,1]
#' as.numeric(adp[["a"]][1:5,1,1]) # same as above
#'
#' @author Dan Kelley
#'
#' @family things related to \code{adp} data
setMethod(f="[[",
signature(x="adp", i="ANY", j="ANY"),
definition=function(x, i, j, ...) {
if (i == "a") {
if (!missing(j) && j == "numeric") {
res <- x@data$a
dim <- dim(res)
res <- as.numeric(res)
dim(res) <- dim
} else {
res <- x@data$a
}
res
} else if (i == "q") {
if (!missing(j) && j == "numeric") {
res <- x@data$q
dim <- dim(res)
res <- as.numeric(res)
dim(res) <- dim
} else {
res <- x@data$q
}
res
} else if (i == "g") {
if (!missing(j) && j == "numeric") {
res <- x@data$g
dim <- dim(res)
res <- as.numeric(res)
dim(res) <- dim
} else {
res <- x@data$g
}
res
} else if (i == "coordinate") {
res <- x@metadata$oceCoordinate
} else {
callNextMethod()
}
})
#' @title Replace Parts of an \code{adp} Object
#' @param x An \code{adp} object, i.e. one inheriting from \code{\link{adp-class}}.
#' @template sub_subsetTemplate
#'
#' @details
#' In addition to the usual insertion of elements by name, note
#' that e.g. \code{pitch} gets stored into \code{pitchSlow}.
#'
#' @author Dan Kelley
#'
#' @family things related to \code{adp} data
setMethod(f="[[<-",
signature="adp",
definition=function(x, i, j, value) { # FIXME: use j for e.g. times
if (i %in% names(x@metadata)) {
x@metadata[[i]] <- value
} else if (i %in% names(x@data)) {
x@data[[i]] <- value
} else {
x <- callNextMethod()
}
## Not checking validity because user may want to shorten items one by one, and check validity later.
## validObject(x)
invisible(x)
})
setValidity("adp",
function(object) {
if (!("v" %in% names(object@data))) {
cat("object@data$v is missing")
return(FALSE)
}
if (!("a" %in% names(object@data))) {
cat("object@data$a is missing")
return(FALSE)
}
if (!("q" %in% names(object@data))) {
cat("object@data$q is missing")
return(FALSE)
}
mdim <- dim(object@data$v)
if ("a" %in% names(object@data) && !all.equal(mdim, dim(object@data$a))) {
cat("dimension of 'a' is (", dim(object@data$a), "), which does not match that of 'v' (", mdim, ")\n")
return(FALSE)
}
if ("q" %in% names(object@data) && !all.equal(mdim, dim(object@data$q))) {
cat("dimension of 'a' is (", dim(object@data$a), "), which does not match that of 'v' (", mdim, ")\n")
return(FALSE)
}
if ("time" %in% names(object@data)) {
n <- length(object@data$time)
for (item in c("pressure", "temperature", "salinity", "depth", "heading", "pitch", "roll")) {
if (item %in% names(object@data) && length(object@data[[item]]) != n) {
cat("length of time vector is ", n, " but the length of ", item, " is ",
length(object@data[[item]]), "\n")
return(FALSE)
}
}
return(TRUE)
}
})
#' Subset an adp object
#'
#' Subset an adp (acoustic Doppler profile) object, in a manner that is function
#' is somewhat analogous to \code{\link{subset.data.frame}}. Subsetting can be by
#' \code{time} or \code{distance}, but these may not be combined; use a sequence
#' of calls to subset by both.
#'
#' @param x An \code{adp} object, i.e. one inheriting from \code{\link{adp-class}}.
#'
#' @param subset A condition to be applied to the \code{data} portion of
#' \code{x}. See \sQuote{Details}.
#'
#' @param ... Ignored.
#'
#' @return A new \code{\link{adp-class}} object.
#'
#' @examples
#' library(oce)
#' data(adp)
#' # First part of time series
#' plot(subset(adp, time < mean(range(adp[['time']]))))
#'
#' @author Dan Kelley
#'
#' @family things related to \code{adp} data
setMethod(f="subset",
signature="adp",
definition=function(x, subset, ...) {
subsetString <- paste(deparse(substitute(subset)), collapse=" ")
res <- x
dots <- list(...)
debug <- getOption("oceDebug")
if (length(dots) && ("debug" %in% names(dots)))
debug <- dots$debug
if (missing(subset))
stop("must give 'subset'")
if (length(grep("time", subsetString))) {
oceDebug(debug, "subsetting an adp by time\n")
if (length(grep("distance", subsetString)))
stop("cannot subset by both time and distance; split into multiple calls")
keep <- eval(substitute(subset), x@data, parent.frame(2))
names <- names(x@data)
haveDia <- "timeDia" %in% names
if (haveDia) {
subsetDiaString <- gsub("time", "timeDia", subsetString)
keepDia <- eval(parse(text=subsetDiaString), x@data)
oceDebug(debug, "for diagnostics, keeping ", 100*sum(keepDia) / length(keepDia), "% of data\n")
}
oceDebug(debug, vectorShow(keep, "keeping bins:"))
oceDebug(debug, "number of kept bins:", sum(keep), "\n")
if (sum(keep) < 2)
stop("must keep at least 2 profiles")
res <- x
## FIXME: are we handling slow timescale data?
for (name in names(x@data)) {
if (length(grep("Dia$", name))) {
if ("distance" == name)
next
if (name == "timeDia" || is.vector(x@data[[name]])) {
oceDebug(debug, "subsetting x@data$", name, ", which is a vector\n", sep="")
res@data[[name]] <- x@data[[name]][keepDia]
} else if (is.matrix(x@data[[name]])) {
oceDebug(debug, "subsetting x@data$", name, ", which is a matrix\n", sep="")
res@data[[name]] <- x@data[[name]][keepDia,]
} else if (is.array(x@data[[name]])) {
oceDebug(debug, "subsetting x@data$", name, ", which is an array\n", sep="")
res@data[[name]] <- x@data[[name]][keepDia,,, drop=FALSE]
}
} else {
if (name == "time" || is.vector(x@data[[name]])) {
if ("distance" == name)
next
oceDebug(debug, "subsetting x@data$", name, ", which is a vector\n", sep="")
res@data[[name]] <- x@data[[name]][keep] # FIXME: what about fast/slow
} else if (is.matrix(x@data[[name]])) {
oceDebug(debug, "subsetting x@data$", name, ", which is a matrix\n", sep="")
res@data[[name]] <- x@data[[name]][keep,]
} else if (is.array(x@data[[name]])) {
oceDebug(debug, "subsetting x@data$", name, ", which is an array\n", sep="")
res@data[[name]] <- x@data[[name]][keep,,, drop=FALSE]
}
}
}
} else if (length(grep("distance", subsetString))) {
oceDebug(debug, "subsetting an adp by distance\n")
if (length(grep("time", subsetString)))
stop("cannot subset by both time and distance; split into multiple calls")
keep <- eval(substitute(subset), x@data, parent.frame(2))
oceDebug(debug, vectorShow(keep, "keeping bins:"), "\n")
if (sum(keep) < 2)
stop("must keep at least 2 bins")
res <- x
res@data$distance <- x@data$distance[keep]
for (name in names(x@data)) {
if (name == "time")
next
if (is.array(x@data[[name]]) && 3 == length(dim(x@data[[name]]))) {
oceDebug(debug, "subsetting array data[[", name, "]] by distance\n")
oceDebug(debug, "before, dim(", name, ") =", dim(res@data[[name]]), "\n")
res@data[[name]] <- x@data[[name]][,keep,, drop=FALSE]
oceDebug(debug, "after, dim(", name, ") =", dim(res@data[[name]]), "\n")
}
}
} else if (length(grep("pressure", subsetString))) {
keep <- eval(substitute(subset), x@data, parent.frame(2))
res <- x
res@data$v <- res@data$v[keep,,]
res@data$a <- res@data$a[keep,,]
res@data$q <- res@data$q[keep,,]
res@data$time <- res@data$time[keep]
## the items below may not be in the dataset
names <- names(res@data)
if ("bottomRange" %in% names) res@data$bottomRange <- res@data$bottomRange[keep,]
if ("pressure" %in% names) res@data$pressure <- res@data$pressure[keep]
if ("temperature" %in% names) res@data$temperature <- res@data$temperature[keep]
if ("salinity" %in% names) res@data$salinity <- res@data$salinity[keep]
if ("depth" %in% names) res@data$depth <- res@data$depth[keep]
if ("heading" %in% names) res@data$heading <- res@data$heading[keep]
if ("pitch" %in% names) res@data$pitch <- res@data$pitch[keep]
if ("roll" %in% names) res@data$roll <- res@data$roll[keep]
} else {
stop("should express the subset in terms of distance or time")
}
res@metadata$numberOfSamples <- dim(res@data$v)[1]
res@metadata$numberOfCells <- dim(res@data$v)[2]
res@processingLog <- processingLogAppend(res@processingLog, paste("subset.adp(x, subset=", subsetString, ")", sep=""))
res
})
#' Create an adp Object
#'
#' @details
#' Construct an object of \code{\link{adp-class}}. Only a basic
#' subset of the typical \code{data} slot is represented in the arguments
#' to this function, on the assumption that typical usage in reading data
#' is to set up a nearly-blank \code{\link{adp-class}} object, the \code{data}
#' slot of which is then inserted. However, in some testing situations it
#' can be useful to set up artificial \code{adp} objects, so the other
#' arguments may be useful.
#'
#' @param time of observations in POSIXct format
#' @param distance to centre of bins
#' @param v array of velocities, with first index for time, second for bin number, and third for beam number
#' @param a amplitude, a \code{\link{raw}} array with dimensions matching \code{u}
#' @param q quality, a \code{\link{raw}} array with dimensions matching \code{u}
#' @param orientation a string indicating sensor orientation, e.g. \code{"upward"} and \code{"downward"}
#' @param coordinate a string indicating the coordinate system, \code{"enu"}, \code{"beam"}, \code{"xy"}, or \code{"other"}
#' @return An object of \code{\link{adp-class}}.
#'
#' @examples
#' data(adp)
#' t <- adp[["time"]]
#' d <- adp[["distance"]]
#' v <- adp[["v"]]
#' a <- as.adp(time=t, distance=d, v=v)
#' \dontrun{
#' plot(a)
#' }
#'
#' @author Dan Kelley
#'
#' @family things related to \code{adp} data
as.adp <- function(time, distance, v, a=NULL, q=NULL, orientation="upward", coordinate="enu")
{
res <- new("adp", time=time, distance=distance, v=v, a=a, q=q)
if (!missing(v)) {
res@metadata$numberOfBeams <- dim(v)[3]
res@metadata$numberOfCells <- dim(v)[2]
}
res@metadata$oceCoordinate <- coordinate
res@metadata$orientation <- orientation
res@metadata$cellSize <- if (missing(distance)) NA else diff(distance[1:2])
res@metadata$units <- list(v="m/s", distance="m")
res
}
## head.adp <- function(x, n=6L, ...)
## {
## numberOfProfiles <- dim(x@data$v)[1]
## if (n < 0)
## look <- seq.int(max(1, (1 + numberOfProfiles + n)), numberOfProfiles)
## else
## look <- seq.int(1, min(n, numberOfProfiles))
## res <- x
## for (name in names(x@data)) {
## if ("distance" == name)
## next
## if (is.vector(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look]
## } else if (is.matrix(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look,]
## } else if (is.array(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look,,]
## } else {
## res@data[[name]] <- x@data[[name]][look] # for reasons unknown, 'time' is not a vector
## }
## }
## res@processingLog <- processingLogAppend(res@processingLog, paste(deparse(match.call()), sep="", collapse=""))
## res
## }
## tail.adp <- function(x, n = 6L, ...)
## {
## numberOfProfiles <- dim(x@data$v)[1]
## if (n < 0)
## look <- seq.int(1, min(numberOfProfiles, numberOfProfiles + n))
## else
## look <- seq.int(max(1, (1 + numberOfProfiles - n)), numberOfProfiles)
## res <- x
## for (name in names(x@data)) {
## if (is.vector(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look]
## } else if (is.matrix(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look,]
## } else if (is.array(x@data[[name]])) {
## res@data[[name]] <- x@data[[name]][look,,]
## } else {
## res@data[[name]] <- x@data[[name]][look] # for reasons unknown, 'time' is not a vector
## }
## }
## res@processingLog <- processingLogAppend(res@processingLog, paste(deparse(match.call()), sep="", collapse=""))
## res
## }
#' Get names of Acoustic-Doppler Beams
#'
#' @param x An \code{adp} object, i.e. one inheriting from \code{\link{adp-class}}.
#' @param which an integer indicating beam number.
#' @return A character string containing a reasonable name for the beam, of the
#' form \code{"beam 1"}, etc., for beam coordinates, \code{"east"}, etc. for
#' enu coordinates, \code{"u"}, etc. for \code{"xyz"}, or \code{"u'"}, etc.,
#' for \code{"other"} coordinates. The coordinate system is determined
#' with \code{x[["coordinate"]]}.
#' @author Dan Kelley
#' @seealso This is used by \code{\link{read.oce}}.
#' @family things related to \code{adp} data
#' @family things related to \code{adv} data
beamName <- function(x, which)
{
if (x@metadata$oceCoordinate == "beam") {
paste(gettext("beam", domain="R-oce"), 1:4)[which]
} else if (x@metadata$oceCoordinate == "enu") {
c(gettext("east", domain="R-oce"),
gettext("north", domain="R-oce"),
gettext("up", domain="R-oce"),
gettext("error", domain="R-oce"))[which]
} else if (x@metadata$oceCoordinate == "xyz") {
c("u", "v", "w", "e")[which]
} else if (x@metadata$oceCoordinate == "other") {
c("u'", "v'", "w'", "e")[which]
} else {
" "
}
}
#' Read an ADP data file
#'
#' Read an ADP data file, producing an \code{adp} object, i.e. one inheriting
#' from \code{\link{adp-class}}.
#'
#' Several file types can be handled. Some of
#' these functions are wrappers that map to device names, e.g.
#' \code{read.aquadoppProfiler} does its work by calling
#' \code{read.adp.nortek}; in this context, it is worth noting that the
#' ``aquadopp'' instrument is a one-cell profiler that might just as well have
#' been documented under the heading \code{\link{read.adv}}.
#'
#' @param manufacturer a character string indicating the manufacturer, used by
#' the general function \code{read.adp} to select a subsidiary function to use,
#' such as \code{read.adp.nortek}.
#' @param despike if \code{TRUE}, \code{\link{despike}} will be used to clean
#' anomalous spikes in heading, etc.
#' @template adpTemplate
#'
#' @author Dan Kelley and Clark Richards
#'
#' @family things related to \code{adp} data
read.adp <- function(file, from=1, to, by=1, tz=getOption("oceTz"),
longitude=NA, latitude=NA,
manufacturer=c("rdi", "nortek", "sontek"),
monitor=FALSE, despike=FALSE, processingLog,
debug=getOption("oceDebug"),
...)
{
oceDebug(debug, "read.adp(...,from=", from,
",to=", if (missing(to)) "(missing)" else to,
",by=", by,
",manufacturer=", if (missing(manufacturer)) "(missing)" else manufacturer, ",...)\n")
manufacturer <- match.arg(manufacturer)
if (monitor)
cat(file, "\n", ...)
if (manufacturer == "rdi")
read.adp.rdi(file=file, from=from, to=to, by=by, tz=tz,
longitude=longitude, latitude=latitude,
debug=debug-1, monitor=monitor, despike=despike,
processingLog=processingLog, ...)
else if (manufacturer == "nortek")
read.adp.nortek(file=file, from=from, to=to, by=by, tz=tz,
longitude=longitude, latitude=latitude,
debug=debug-1, monitor=monitor, despike=despike,
processingLog=processingLog, ...)
else if (manufacturer == "sontek")
read.adp.sontek(file=file, from=from, to=to, by=by, tz=tz,
longitude=longitude, latitude=latitude,
debug=debug-1, monitor=monitor, despike=despike,
processingLog=processingLog, ...)
}
#' Plot ADP data
#'
#' Create a summary plot of data measured by an acoustic doppler profiler.
#'
#' The plot may have one or more panels, with the content being controlled by
#' the \code{which} argument.
#'
#' \itemize{
#'
#' \item \code{which=1:4} (or \code{which="u1"} to \code{"u4"}) yield a
#' distance-time image plot of a velocity component. If \code{x} is in
#' \code{beam} coordinates (signalled by
#' \code{x@metadata$oce.coordinate=="beam"}), this will be the beam velocity,
#' labelled \code{b[1]} etc. If \code{x} is in xyz coordinates (sometimes
#' called frame coordinates, or ship coordinates), it will be the velocity
#' component to the right of the frame or ship (labelled \code{u} etc).
#' Finally, if \code{x} is in \code{"enu"} coordinates, the image will show the
#' the eastward component (labelled \code{east}). If \code{x} is in
#' \code{"other"} coordinates, it will be component corresponding to east,
#' after rotation (labelled \code{u\'}). Note that the coordinate is set by
#' \code{\link{read.adp}}, or by \code{\link{beamToXyzAdp}},
#' \code{\link{xyzToEnuAdp}}, or \code{\link{enuToOtherAdp}}.
#'
#' \item \code{which=5:8} (or \code{which="a1"} to \code{"a4"}) yield
#' distance-time images of backscatter intensity of the respective beams. (For
#' data derived from Teledyn-RDI instruments, this is the item called ``echo
#' intensity.'')
#'
#' \item \code{which=9:12} (or \code{which="q1"} to \code{"q4"}) yield
#' distance-time images of signal quality for the respective beams. (For RDI
#' data derived from instruments, this is the item called ``correlation
#' magnitude.'')
#'
#' \item \code{which=60} or \code{which="map"} draw a map of location(s).
#'
#' \item \code{which=70:73} (or \code{which="g1"} to \code{"g4"}) yield
#' distance-time images of percent-good for the respective beams. (For data
#' derived from Teledyne-RDI instruments, which are the only instruments that
#' yield this item, it is called ``percent good.'')
#'
#' \item \code{which=13} (or \code{which="salinity"}) yields a time-series plot
#' of salinity.
#'
#' \item \code{which=14} (or \code{which="temperature"}) yields a time-series
#' plot of temperature.
#'
#' \item \code{which=15} (or \code{which="pressure"}) yields a time-series plot
#' of pressure.
#'
#' \item \code{which=16} (or \code{which="heading"}) yields a time-series plot
#' of instrument heading.
#'
#' \item \code{which=17} (or \code{which="pitch"}) yields a time-series plot of
#' instrument pitch.
#'
#' \item \code{which=18} (or \code{which="roll"}) yields a time-series plot of
#' instrument roll.
#'
#' \item \code{which=19} yields a time-series plot of distance-averaged
#' velocity for beam 1, rightward velocity, eastward velocity, or
#' rotated-eastward velocity, depending on the coordinate system.
#'
#' \item \code{which=20} yields a time-series of distance-averaged velocity for
#' beam 2, foreward velocity, northward velocity, or rotated-northward
#' velocity, depending on the coordinate system.
#'
#' \item \code{which=21} yields a time-series of distance-averaged velocity for
#' beam 3, up-frame velocity, upward velocity, or rotated-upward velocity,
#' depending on the coordinate system.
#'
#' \item \code{which=22} yields a time-series of distance-averaged velocity for
#' beam 4, for \code{beam} coordinates, or velocity estimate, for other
#' coordinates. (This is ignored for 3-beam data.)
#'
#' \item \code{which=23} yields a progressive-vector diagram in the horizontal
#' plane, plotted with \code{asp=1}. Normally, the depth-averaged velocity
#' components are used, but if the \code{control} list contains an item named
#' \code{bin}, then the depth bin will be used (with an error resulting if the
#' bin is out of range).
#'
#' \item \code{which=24} yields a time-averaged profile of the first component
#' of velocity (see \code{which=19} for the meaning of the component, in
#' various coordinate systems).
#'
#' \item \code{which=25} as for 24, but the second component.
#'
#' \item \code{which=26} as for 24, but the third component.
#'
#' \item \code{which=27} as for 24, but the fourth component (if that makes
#' sense, for the given instrument).
#'
#' \item \code{which=28} or \code{"uv"} yields velocity plot in the horizontal
#' plane, i.e. u[2] versus u[1]. If the number of data points is small, a
#' scattergraph is used, but if it is large, \code{\link{smoothScatter}} is
#' used.
#'
#' \item \code{which=29} or \code{"uv+ellipse"} as the \code{"uv"} case, but
#' with an added indication of the tidal ellipse, calculated from the eigen
#' vectors of the covariance matrix.
#'
#' \item \code{which=30} or \code{"uv+ellipse+arrow"} as the
#' \code{"uv+ellipse"} case, but with an added arrow indicating the mean
#' current.
#'
#' \item \code{which=40} or \code{"bottomRange"} for average bottom range from
#' all beams of the instrument.
#'
#' \item \code{which=41} to \code{44} (or \code{"bottomRange1"} to
#' \code{"bottomRange4"}) for bottom range from beams 1 to 4.
#'
#' \item \code{which=50} or \code{"bottomVelocity"} for average bottom velocity
#' from all beams of the instrument.
#'
#' \item \code{which=51} to \code{54} (or \code{"bottomVelocity1"} to
#' \code{"bottomVelocity4"}) for bottom velocity from beams 1 to 4.
#'
#' \item \code{which=55} (or \code{"heaving"}) for time-integrated,
#' depth-averaged, vertical velocity, i.e. a time series of heaving.
#'
#' \item \code{which=100} (or \code{"soundSpeed"}) for a time series of sound
#' speed.
#'
#' } In addition to the above, there are some groupings defined: \itemize{
#' \item \code{which="velocity"} equivalent to \code{which=1:3} (velocity
#' components) \item \code{which="amplitude"} equivalent to \code{which=5:7}
#' (backscatter intensity components) \item \code{which="quality"} equivalent
#' to \code{which=9:11} (quality components) \item \code{which="hydrography"}
#' equivalent to \code{which=14:15} (temperature and pressure) \item
#' \code{which="angles"} equivalent to \code{which=16:18} (heading, pitch and
#' roll) }
#'
#' The colour scheme for image plots (\code{which} in 1:12) is provided by the
#' \code{col} argument, which is passed to \code{\link{image}} to do the actual
#' plotting. See \dQuote{Examples} for some comparisons.
#'
#' A common quick-look plot to assess mooring movement is to use
#' \code{which=15:18} (pressure being included to signal the tide, and tidal
#' currents may dislodge a mooring or cause it to settle).
#'
#' By default, \code{plot,adp-method} uses a \code{zlim} value for the
#' \code{\link{image}} that is constructed to contain all the data, but to be
#' symmetric about zero. This is done on a per-panel basis, and the scale is
#' plotted at the top-right corner, along with the name of the variable being
#' plotted. You may also supply \code{zlim} as one of the \dots{} arguments,
#' but be aware that a reasonable limit on horizontal velocity components is
#' unlikely to be of much use for the vertical component.
#'
#' A good first step in the analysis of measurements made from a moored device
#' (stored in \code{d}, say) is to do \code{plot(d, which=14:18)}. This shows
#' time series of water properties and sensor orientation, which is helpful in
#' deciding which data to trim at the start and end of the deployment, because
#' they were measured on the dock or on the ship as it travelled to the mooring
#' site.
#'
#' @param x An \code{adp} object, i.e. one inheriting from \code{\link{adp-class}}.
#' @param which list of desired plot types. These are graphed in panels
#' running down from the top of the page. See \dQuote{Details} for the
#' meanings of various values of \code{which}.
#' @param mode a string indicating whether to plot the conventional signal
#' (\code{normal}) or or, in the special case of Aquadopp single-bin profilers,
#' possibly the \code{diagnostic} signal. This argument is ignored except in
#' the case of Aquadopp instruments. Perhaps a third option will become
#' available in the future, for the \code{burst} mode that some instruments
#' provide.
#' @param col optional indication of colour(s) to use. If not provided, the
#' default for images is \code{oce.colorsPalette(128,1)}, and for lines and
#' points is black.
#' @param breaks optional breaks for colour scheme
#' @param zlim a range to be used as the \code{zlim} parameter to the
#' \code{\link{imagep}} call that is used to create the image. If omitted,
#' \code{zlim} is set for each panel individually, to encompass the data of the
#' panel and to be centred around zero. If provided as a two-element vector,
#' then that is used for each panel. If provided as a two-column matrix, then
#' each panel of the graph uses the corresponding row of the matrix; for
#' example, setting \code{zlim=rbind(c(-1,1),c(-1,1),c(-.1,.1))} might make
#' sense for \code{which=1:3}, so that the two horizontal velocities have one
#' scale, and the smaller vertical velocity has another.
#' @param titles optional vector of character strings to be used as labels for
#' the plot panels. For images, these strings will be placed in the right hand
#' side of the top margin. For timeseries, these strings are ignored. If this
#' is provided, its length must equal that of \code{which}.
#' @param lwd if the plot is of a time-series or scattergraph format with
#' lines, this is used in the usual way; otherwise, e.g. for image formats,
#' this is ignored.
#' @param type if the plot is of a time-series or scattergraph format, this is
#' used in the usual way, e.g. \code{"l"} for lines, etc.; otherwise, as for
#' image formats, this is ignored.
#' @param ytype character string controlling the type of the y axis for images