Skip to contents

This function converts the body structure of a CSSY file into a list of matrices that conform to the data structure required for creating a SeaSondeRCS object. The conversion is performed by mapping specific fields:

SSA1, SSA2, SSA3

Matrices are built using the numeric vectors found in the cs1a, cs2a and cs3a fields respectively.

CS12, CS13, CS23

Each complex cross-spectra matrix is formed by combining the real parts from c12r, c13r and c23r with the corresponding imaginary parts from c12i, c13i and c23i.

QC

The quality control matrix is obtained directly from the csqf field.

Usage

seasonder_CSSY2CSData(body)

Arguments

body

A list representing the body of a CSSY file. Each element of the list is expected to be a cell containing the following fields: indx (which includes an index), cs1a, cs2a, cs3a, c12r, c12i, c13r, c13i, c23r, c23i and csqf.

Value

A list with the following components:

SSA1

A numeric matrix containing self-spectra from cs1a.

SSA2

A numeric matrix containing self-spectra from cs2a.

SSA3

A numeric matrix containing self-spectra from cs3a.

CS12

A complex matrix formed by pairing c12r (real) and c12i (imaginary).

CS13

A complex matrix formed by pairing c13r (real) and c13i (imaginary).

CS23

A complex matrix formed by pairing c23r (real) and c23i (imaginary).

QC

A numeric matrix containing the quality control data from csqf.

Details

Each row in the output matrices corresponds to the index provided by cell$indx$index in the input list.

The function first determines the maximum index among the cells in the body, which defines the number of rows for the matrices. Then, it calculates the number of columns for each matrix based on the length of the corresponding vectors from the first cell where they appear. Finally, each cell's data is inserted into the appropriate row of the matrices as indicated by the cell's indx$index value.

Examples

  # Example with a single cell
  cell <- list(
    indx  = list(index = 1),
    cs1a  = c(1, 2, 3),
    cs2a  = c(4, 5, 6),
    cs3a  = c(7, 8, 9),
    c12r  = c(10, 11, 12),
    c12i  = c(13, 14, 15),
    c13r  = c(16, 17, 18),
    c13i  = c(19, 20, 21),
    c23r  = c(22, 23, 24),
    c23i  = c(25, 26, 27),
    csqf  = c(28, 29, 30)
  )
  body <- list(cell)
  transformed <- seasonder_CSSY2CSData(body)
  print(transformed)
#> $SSA1
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> 
#> $SSA2
#>      [,1] [,2] [,3]
#> [1,]    4    5    6
#> 
#> $SSA3
#>      [,1] [,2] [,3]
#> [1,]    7    8    9
#> 
#> $CS12
#>        [,1]   [,2]   [,3]
#> [1,] 10+13i 11+14i 12+15i
#> 
#> $CS13
#>        [,1]   [,2]   [,3]
#> [1,] 16+19i 17+20i 18+21i
#> 
#> $CS23
#>        [,1]   [,2]   [,3]
#> [1,] 22+25i 23+26i 24+27i
#> 
#> $QC
#>      [,1] [,2] [,3]
#> [1,]   28   29   30
#>