10  Tag Label

This script will guide you through the tag labelling of pressure and/or acceleration data and creation of the pressure map.

Tip

Delete this block when you have read!

  • These scripts should be adapted based on your project, but the same script should run for all your tags. You can always check the original version online.
  • Make sure you’ve read the GeoPressureManual, in particular the labelling instructions, before running this script
  • Nothing is saved at the end of the script and it is meant to be like that. The goal in this script is to (1) create the tag labels (./data/tag-label/) and (2) adapt config.yml.
# Choose the id
id <- "18LX"

# Set the directory to the project root
# see Working directory bullet point in https://bookdown.org/yihui/rmarkdown/notebook.html#executing-code
knitr::opts_knit$set(root.dir = here::here())
# Alternatively, you can change the global RStudio settings in menu "Tools/Global Options...", on the "R Markdown" panel, choose "Project" for "Evaluate chunks in directory:"

library(GeoPressureR)
library(ggplot2)
library(plotly)

10.1 Edit config.yml

Tip

Delete this block when you have read!

Edit the default config according to your study: Use default for all parameters which are the same for all your tracks and add any parameter that is tag specific.

config.yml is structured in the following level as defined by the indentation and :

tag_id:
  function_name:
    arguments: value

Note that the values are written in json format (and not R), so for a vector/array you need to use [, ] and for an array of objects (named lists), you need to use - and indentation. Here is an exemple:

18LX:
  tag_set_map:
    extent: [-16, 23, 0, 50]
    known: 
      - stap_id: 1
        known_lon: 7.05
        known_lat: 48.9
  bird:
    species_name: "Acrocephalus arundinaceus" # only if you have different species, otherwise add to default

Check that the config is correct.

str(config::get(config = id))
List of 12
 $ tag_set_map        :List of 5
  ..$ extent              : int [1:4] -16 23 0 50
  ..$ scale               : int 5
  ..$ include_stap_id     : NULL
  ..$ include_min_duration: int 0
  ..$ known               :List of 3
  .. ..$ stap_id  : int [1:2] 1 -1
  .. ..$ known_lon: num 17
  .. ..$ known_lat: num 48.9
 $ geopressure_map    :List of 5
  ..$ max_sample               : int 250
  ..$ margin                   : int 20
  ..$ sd                       : int 1
  ..$ thr_mask                 : num 0.9
  ..$ log_linear_pooling_weight:function (n)  
 $ twilight_create    : NULL
 $ geolight_map       :List of 2
  ..$ twl_calib_adjust: num 1.4
  ..$ twl_llp         :function (n)  
 $ graph_create       :List of 2
  ..$ thr_likelihood: num 0.99
  ..$ thr_gs        : int 150
 $ graph_add_wind     :List of 1
  ..$ thr_as: int 90
 $ graph_simulation   :List of 1
  ..$ nj: int 10
 $ pressurepath_create:List of 1
  ..$ variable: chr [1:2] "altitude" "surface_pressure"
 $ geopressuretemplate:List of 3
  ..$ likelihood  : chr [1:2] "map_pressure" "map_light"
  ..$ outputs     : chr [1:3] "marginal" "most_likely" "simulation"
  ..$ pressurepath: chr "most_likely"
 $ tag_create         :List of 2
  ..$ crop_start: chr "2017-06-20"
  ..$ crop_end  : chr "2018-05-02"
 $ bird_create        :List of 1
  ..$ scientific_name: chr "Acrocephalus arundinaceus"
 $ graph_set_movement :List of 1
  ..$ type: chr "as"
 - attr(*, "config")= chr "18LX"
 - attr(*, "file")= chr "/Users/rafnuss/Library/CloudStorage/OneDrive-Vogelwarte/GeoPressureManual/config.yml"
 - attr(*, "class")= chr "config"

10.2 Sensor data and crop date

Check if the crop dates (in red) are correct.

ggplotly(
  tag_create(id, quiet = TRUE) |>
    plot(type = "pressure", plot_plotly = FALSE) +
    geom_vline(
      xintercept = as.numeric(c(
        as.POSIXct(config::get("tag_create", id)$crop_start),
        as.POSIXct(config::get("tag_create", id)$crop_end)
      )),
      color = "red", lwd = 1
    )
)

You might want to change type to check the values of the other sensors (e.g., acceleration or light).

Create tag with cropped date

tag <- tag_create(
  id,
  crop_start = config::get("tag_create", id)$crop_start,
  crop_end = config::get("tag_create", id)$crop_end
)
✔ Read './data/raw-tag/18LX/18LX_20180725.pressure'
✔ Read './data/raw-tag/18LX/18LX_20180725.glf'
✔ Read './data/raw-tag/18LX/18LX_20180725.acceleration'
✔ Read './data/raw-tag/18LX/18LX_20180725.temperature'

10.3 Create label and edit on Trainset

ℹ No label data.
→ Initialize automatically label using `tag_label_auto()`
✔ './data/tag-label/18LX.csv' written successfully.

Open csv and edit on https://trainset.raphaelnussbaumer.com/.

10.4 Run simple labelling checks

Check 1

tag <- tag_label(tag)
── Short stationary periods (<6hr): ────────────────────────────────────────────
! Stap 25 (2018-04-15 15:02 - 2018-04-15 18:47) : 3h 45m
── Short flights (<2hr): ───────────────────────────────────────────────────────
! Flight 13 -> 14 (2017-09-11 23:27 - 2017-09-12 00:22) : 55m
! Flight 17 -> 18 (2017-09-19 23:32 - 2017-09-20 01:07) : 1h 35m
Tip

Delete this block when you have read!

Edit and export label on Trainset and simply run the same chunk until you’re happy with it! This principle (edit your label file and re-run the same chunk) is valid throughout this script.

Check 2

plot(tag, type = "pressure")
── Pre-processed pressure data length 
✔ All stationary periods have more than 12 datapoints.
── Pressure difference 
✔ All hourly changes in pressure are below 3 hPa.

10.5 Run Pressurepath checks

Compute pressure map on a coarse grid to perform checks 3-5.

tag <- tag_set_map(tag,
  extent = config::get("tag_set_map", id)$extent,
  scale = 1,
  known = config::get("tag_set_map", id)$known,
  include_min_duration = 24
) |>
  geopressure_map()
ℹ Pre-process pressure data
✔ Pre-process pressure data [33ms]
ℹ Generate requests for 11 stapelev on <glp.mgravey.com/GeoPressure/v2/map/>: 5…
✔ Generate requests for 11 stapelev on <glp.mgravey.com/GeoPressure/v2/map/> [7…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
ℹ Compute (on GEE server) and download .geotiff for 11 stapelev (on 11 workers)…
✔ Compute (on GEE server) and download .geotiff for 11 stapelev [1.9s]
ℹ Read .geotiff: "18|0" | 1/11
ℹ Read .geotiff: "18|0" | 1/11
ℹ Read .geotiff: "14|0" | 2/11
ℹ Read .geotiff: "5|0" | 3/11
ℹ Read .geotiff: "10|0" | 4/11
ℹ Read .geotiff: "11|0" | 5/11
ℹ Read .geotiff: "27|0" | 6/11
ℹ Read .geotiff: "5|1" | 7/11
ℹ Read .geotiff: "26|0" | 8/11
ℹ Read .geotiff: "9|0" | 9/11
ℹ Read .geotiff: "20|0" | 10/11
ℹ Read .geotiff: "16|0" | 11/11
✔ Read .geotiff [8.5s]
ℹ Post-process maps
✔ Post-process maps [123ms]
pressurepath <- pressurepath_create(tag)
ℹ Prepare pressure
✔ Prepare pressure [15ms]
ℹ Generate request on <glp.mgravey.com/GeoPressure/v2/pressurePath> and downloa…
✔ Generate request on <glp.mgravey.com/GeoPressure/v2/pressurePath> and downloa…
ℹ Post-process pressurepath
✔ Post-process pressurepath [876ms]

Check 3

plot_pressurepath(pressurepath)

Check 4

plot_pressurepath(pressurepath, type = "histogram")

10.6 Run GeoPressureViz checks

geopressureviz(
  tag,
  # path = pressurepath,
  # path = most_likely_path,
  # marginal = marginal
)

10.7 Update of tag and pressurepath

Tip

Delete this block when you have read!

You can use tag_upate() and pressurepath_update() every time you edit and export a new label file from Trainset. You might want to start from a new tag and pressurepath variable if you encounter any problem.

tag <- tag_update(tag)
pressurepath <- pressurepath_update(pressurepath, tag)