Chapter 4 Data storage

kaltoa handles data storage in a simple manner. We’ve provided functions that allow writing most kaltoa data objects to text files.

The benefit of text files is they are human readable and portable (can be read by any software). Someone can examine an exported kaltoa file and do a reasonable job of guessing its contents, even if they’ve never used the kaltoa package. The drawback here is file size.

To export kaltoa objects in a portable manner that doesn’t take up too much space, you can write them to gz archives using gzfile. Below we’ll show some examples of this.

Note that DetectionsList objects are written to a tar archive (containing a txt file for each Detection object). Hence, DetectionsList objects must be written/read from binary streams ("wb" and "rb").

fname_tar <- tempfile(fileext = ".tar.gz")
fname_txt <- tempfile(fileext = ".txt.gz")

# --- DetectionsList
export(detlst, con = gzfile(fname_tar, open = "wb"))
detlst_import <- import_DetectionsList(gzfile(fname_tar, open = "rb"))
print(detlst_import)
## DetectionsList
## 
## Receiver Summary
##                    1     2     3     4     5     6    
## Sync-tag ID        62041 62042 62074 62368 62581 62584
## Sync-tag emissions 144   144   144   144   142   144  
## Tag detections     651   827   677   611   765   425  
## Tags detected      7     7     7     7     7     6    
## 
## Detections Summary
##     Tag-ID     First detection      Last detection   n Detection period (h)
##   HR-53883 2021-05-08 20:41:34 2021-05-08 21:29:30 708                 0.80
##      62074 2021-05-08 18:00:09 2021-05-09 05:59:56 587                12.00
##      62368 2021-05-08 18:02:21 2021-05-09 05:55:31 564                11.89
##      62584 2021-05-08 18:00:48 2021-05-09 05:52:23 548                11.86
##      62041 2021-05-08 18:01:03 2021-05-09 05:58:01 514                11.95
##      62042 2021-05-08 18:00:38 2021-05-09 05:56:37 498                11.93
##      62581 2021-05-08 18:00:42 2021-05-09 05:55:42 465                11.92
##  PPM-53883 2021-05-08 20:55:51 2021-05-08 21:22:06  72                 0.44
# --- Detections
export(det, con = gzfile(fname_txt, open = "w"))
det_import <- import_Detections(gzfile(fname_txt, open = "r"))
head(det_import)
## Telemetry Detections
## Name: 1
## Sync-tag ID: 62041
## Depth: NA
## Coords: (481460.3 m, 6243492 m)
## Sync tag emissions: 1
## Detections: 5
## First detection on: 2021-05-08 18:00:09
## Last detection on: 2021-05-08 18:05:23
## Time zone: CET
##                second millisecond detect_id     type sync_emission
## 1 2021-05-08 18:00:09    427.3985     62074      PPM         FALSE
## 2 2021-05-08 18:00:38    772.6640     62042      PPM         FALSE
## 3 2021-05-08 18:00:48    244.0411     62584      PPM         FALSE
## 4 2021-05-08 18:01:03    878.7920  PPM_SELF PPM_SELF          TRUE
## 5 2021-05-08 18:02:21    749.5333     62368      PPM         FALSE
## 6 2021-05-08 18:05:23    948.8101     62074      PPM         FALSE
# --- TOAMatrix
export(toa, con = gzfile(fname_txt, open = "w"))
toa_import <- import_TOAMatrix(gzfile(fname_txt, open = "r"))
summary(toa_import)
## TOAMatrix
## Tag ID:  PPM-53883 
## Transmission speed: 1420.00 m s⁻¹
## Time zone: CET
## ------ Detections
## First Detection: 2021-05-08 20:55:51 
## Last Detection: 2021-05-08 21:22:06 
## Reference time: 2021-05-08 20:55:51 
## Detection Period: 0.44 hours 
## ------ Emissions
## Emissions: 29 
## Detections per emission (proportional)
##    1    2    3    4    5 
## 0.48 0.03 0.10 0.28 0.10 
## ------ Receiver Positions
##          x       y
## 1 481460.3 6243492
## 2 481435.5 6243491
## 3 481446.8 6243518
## 4 481465.0 6243550
## 5 481433.3 6243530
## 6 481473.4 6243513
head(toa_import)
##           1  2         3         4           5  6                time
## 1        NA NA        NA        NA   0.2439038 NA 2021-05-08 20:55:51
## 2        NA NA        NA  66.74919  66.7592932 NA 2021-05-08 20:56:57
## 3  98.05163 NA  98.03187  98.01397  98.0232994 NA 2021-05-08 20:57:29
## 4 166.67533 NA 166.65562 166.64440 166.6467375 NA 2021-05-08 20:58:37
## 5        NA NA 194.08471 194.07666 194.0744584 NA 2021-05-08 20:59:05
## 6        NA NA 226.26185 226.25289 226.2521278 NA 2021-05-08 20:59:37
# --- KaltoaKalmanPositions
export(track_toa, con = gzfile(fname_txt, open = "w"))
track_toa_import <- import_KaltoaKalmanPositions(gzfile(fname_txt, open = "r"))
print(track_toa_import)
## KaltoaKalmanPositions
## Start time: 2021-05-08 20:55:51 CEST
## Smoothed: FALSE
##        pos.x               pos.y          emission_error  
##   Estimate | SE        Estimate | SE     Estimate | SE    
## 481470.734   2.7403 6243534.045   2.7403   -0.009   0.0018
## 481464.413   2.7455 6243543.631   1.7426   -0.005   0.0016
## 481449.232   3.0576 6243543.906   1.7797   -0.007   0.0013
## 481445.449   2.4391 6243546.003   2.5284   -0.012   0.0014
## 481444.093   2.6082 6243548.387   3.0043   -0.013   0.0017
## 481442.796   2.7193 6243550.322   3.1446   -0.015   0.0020
## 481436.521   2.9018 6243543.269   3.4162   -0.008   0.0023
## 481435.358   3.2802 6243531.915   3.1430   -0.003   0.0022
## 481450.274   2.0447 6243515.194   2.3188    0.002   0.0014
## 481450.956   2.0315 6243502.142   1.4773   -0.009   0.0010
## 481455.115   1.9375 6243496.919   1.4460   -0.003   0.0010
## 481452.645   1.8330 6243492.765   1.5745   -0.004   0.0010
## 481450.059   1.6837 6243488.243   2.0631   -0.007   0.0012
## 481450.639   1.7586 6243486.648   2.9674   -0.007   0.0015
## 481446.760   3.4115 6243482.366   4.4780   -0.008   0.0032
# --- KaltoaPointPositions
export(points, con = gzfile(fname_txt, open = "w"))
points_import <- import_KaltoaPointPositions(gzfile(fname_txt, open = "r"))
print(points_import)
## KaltoaPointPositions
## Start time: 2021-05-08 20:55:51 CEST
##        pos.x               pos.y          emission_error  
##   Estimate | SE        Estimate | SE     Estimate | SE    
## 481470.734   2.7403 6243534.045   2.7403   -0.009   0.0018
## 481464.413   2.7455 6243543.631   1.7426   -0.005   0.0016
## 481449.232   3.0576 6243543.906   1.7797   -0.007   0.0013
## 481445.449   2.4391 6243546.003   2.5284   -0.012   0.0014
## 481444.093   2.6082 6243548.387   3.0043   -0.013   0.0017
## 481442.796   2.7193 6243550.322   3.1446   -0.015   0.0020
## 481436.521   2.9018 6243543.269   3.4162   -0.008   0.0023
## 481435.358   3.2802 6243531.915   3.1430   -0.003   0.0022
## 481450.274   2.0447 6243515.194   2.3188    0.002   0.0014
## 481450.956   2.0315 6243502.142   1.4773   -0.009   0.0010
## 481455.115   1.9375 6243496.919   1.4460   -0.003   0.0010
## 481452.645   1.8330 6243492.765   1.5745   -0.004   0.0010
## 481450.059   1.6837 6243488.243   2.0631   -0.007   0.0012
## 481450.639   1.7586 6243486.648   2.9674   -0.007   0.0015
## 481446.760   3.4115 6243482.366   4.4780   -0.008   0.0032