Skip to content

Commit

Permalink
spelling check + minor + bump version 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafnuss committed Oct 29, 2022
1 parent c24356a commit 2bc60d5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 35 deletions.
Binary file removed .RDataTmp
Binary file not shown.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: GeoPressureTemplate
Title: These are the Goal of my Study (One Line, Title Case)
Version: 0.6
URL: https://github.com/Rafnuss/GeoPressureTemplate
Description: More detailed description of my research objective with my dataset available (one paragraph).
Authors@R:
person("Raphaël", "Nussbaumer", , "rafnuss@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-8185-1020"))
Description: More detailed description of my research objective with my dataset available (one paragraph).
License: GPL (>= 3)
URL: https://github.com/Rafnuss/GeoPressureTemplate
Version: 0.7
Depends:
R (>= 3.5.0)
Imports:
Expand Down Expand Up @@ -35,4 +35,4 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GeoPressureTemplate

Analysing geolocator data with pressure is full of potential, but the the path is long and the journey can be challenging. `GeoPressureTemplate` is a [Github repository template](https://docs.github.com/articles/creating-a-repository-from-a-template/) for a startup R project to make that journey easier.
Analyzing geolocator data with pressure is full of potential, but the the path is long and the journey can be challenging. `GeoPressureTemplate` is a [Github repository template](https://docs.github.com/articles/creating-a-repository-from-a-template/) for a start-up R project to make that journey easier.

## What is this template and who is it for? :mag_right:

Expand All @@ -11,7 +11,7 @@ In essence, it contains the code from all the [GeoPressureManual](https://raphae
## What do you need to use this template? :computer:

- Geolocator data containing pressure, light and activity data.
- Have read the [GeoPressureManual](https://raphaelnussbaumer.com/GeoPressureManual) (:warning: You should be familar with the **full process involved** before starting with your own project)
- Have read the [GeoPressureManual](https://raphaelnussbaumer.com/GeoPressureManual) (:warning: You should be familiar with the **full process involved** before starting with your own project)
- Basic R experience (I'm using the [tidyverse](https://www.tidyverse.org/) syntax here).
- A [Github account](https://github.com/signup).

Expand All @@ -20,7 +20,7 @@ In essence, it contains the code from all the [GeoPressureManual](https://raphae

Following the recommendations of [rrrpkg](https://github.com/ropensci/rrrpkg), the project contains:
1. Standard description files at the root (`DESCRIPTION`, `.Rproj`, `README.md`, `LICENCES`,...).
2. `data/` folder containing the raw geolocator data, the pressure and light labelled files and the data generated with the code from `analysis/`. Note that you could instead keep the geolocator and labelization files seperately in a `raw-data/` folder, following `usethis()` standard.
2. `data/` folder containing the raw geolocator data, the pressure and light labelled files and the data generated with the code from `analysis/`. Note that you could instead keep the geolocator and labelization files separately in a `raw-data/` folder, following `usethis()` standard.
3. `analysis/` contains all the `.R` code used for your project.
4. `report/` reads the data generated and produces sharable results (figures, html page, manuscript, etc...).
<details>
Expand Down Expand Up @@ -113,7 +113,7 @@ devtools::install()

## Start analysing the data :chart_with_upwards_trend:

Now that you are set-up, it's time to start the serious work. :grimacing: Follow the order of the `.R` code in the `analysis/` folder. They follow the same order as the GeoPressureManual (but with different numerotation to be able to analyse multiple track at the same time).
Now that you are set-up, it's time to start the serious work. :grimacing: Follow the order of the `.R` code in the `analysis/` folder. They follow the same order as the GeoPressureManual (but with different numeration to be able to analyse multiple track at the same time).

| GeoPressureTemplate analysis | GeoPressureManual |
|---|---|
Expand All @@ -126,7 +126,7 @@ Now that you are set-up, it's time to start the serious work. :grimacing: Follow
| `5-3-wind-graph_analyse.R` | [5. Wind graph - Outputs](https://raphaelnussbaumer.com/GeoPressureManual/wind-graph.html#compute-the-transition-probability-1) |
| `99-combined.R` | Run all steps for multiple tracks. |

In order to keep your code clean, we isolate all the key paramters used in all functions in the `gpr_setting.xlsx` spreadsheet located in the `data/` folder. You can adjust these parameters seperatly for each track or add any informations on your individuals bird that might be useful for your analysis.
In order to keep your code clean, we isolate all the key parameters used in all functions in the `gpr_setting.xlsx` spreadsheet located in the `data/` folder. You can adjust these parameters separately for each track or add any information on your individuals bird that might be useful for your analysis.

<details>
<summary>Click to see explanations on the parameters of <code>gpr_setting.xlsx</code></summary>
Expand All @@ -145,12 +145,12 @@ In order to keep your code clean, we isolate all the key paramters used in all f
|map_max_sample |300 |see [`geopressure_map()`](https://raphaelnussbaumer.com/GeoPressureR/reference/geopressure_map.html) |
|map_margin |30 |see [`geopressure_map()`](https://raphaelnussbaumer.com/GeoPressureR/reference/geopressure_map.html) |
|prob_map_s |1 |see [`geopressure_prob_map()`](https://raphaelnussbaumer.com/GeoPressureR/reference/geopressure_prob_map.html) |
|prob_map_s_calib | |Alternative value for `prob_map_s` for calibration site. Useful for species living in moutain only during calibration. |
|prob_map_s_calib | |Alternative value for `prob_map_s` for calibration site. Useful for species living in mountain only during calibration. |
|prob_map_thr |0.9 |see [`geopressure_prob_map()`](https://raphaelnussbaumer.com/GeoPressureR/reference/geopressure_prob_map.html) |
|shift_k |0 |see [`find_twilights()`](https://raphaelnussbaumer.com/GeoPressureR/reference/find_twilights.html) |
|kernel_adjust |1.4 |see [Calibration of light data](https://raphaelnussbaumer.com/GeoPressureManual/light-map.html#calibrate-zenith-angles) |
|calib_lon |17.05 |Longitude of the calibration site. |
|calib_lat |48.9 |Latitude of the calibrataion site. |
|calib_lat |48.9 |Latitude of the calibration site. |
|calib_1_start |2017-06-20 |Start date of the first calibration period. |
|calib_1_end |2017-08-05 |End date of the first calibration period. |
|calib_2_start | |Start date of the second calibration period. |
Expand All @@ -162,7 +162,6 @@ In order to keep your code clean, we isolate all the key paramters used in all f
|thr_gs |120 |see [`graph_create()`](https://raphaelnussbaumer.com/GeoPressureR/reference/graph_create.html) |
|thr_as |100 |see [`graph_add_wind()`](https://raphaelnussbaumer.com/GeoPressureR/reference/graph_add_wind.html) |
|low_speed_fix |15 |see [`flight_prob()`](https://raphaelnussbaumer.com/GeoPressureR/reference/flight_prob.html) |
|ringNo | |Ring number if available (not used). |
|scientific_name |Acrocephalus arundinaceus|see [`flight_bird()`](https://raphaelnussbaumer.com/GeoPressureR/reference/flight_bird.html) |
|common_name |Great Reed Warbler | |
|mass | |see [`flight_bird()`](https://raphaelnussbaumer.com/GeoPressureR/reference/flight_bird.html) |
Expand All @@ -182,12 +181,12 @@ The main idea is to produce report templates (`_name_of_the_report_template.Rmd`
3. Look at `make_reports.R` script to see how you can generate the HTML for multiple tracks and reports templates at once.
4. Edit `index.Rmd` as you wishes
5. Run `{r} render_site('./reports')` (also provided at the bottom of `make_reports.R`) to generate the full website in `docs/`.
6. Push your changes on Gihub and create your [Github Page](https://rstudio.github.io/distill/publish_website.html#github-pages).
6. Push your changes on Github and create your [Github Page](https://rstudio.github.io/distill/publish_website.html#github-pages).


## Advanced options :link:

- Generate your DOI with [Zenodo](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content) (e.g., https://zenodo.org/record/6720386)
- Generate a citation file with [`usethis::use_citation`](https://usethis.r-lib.org/reference/use_citation.html) and [`cffr`](https://github.com/ropensci/cffr).
- Use [`renv`](https://rstudio.github.io/renv/index.html) to make your work reproducable.
- Use [`renv`](https://rstudio.github.io/renv/index.html) to make your work reproducible.
- Export your data on [Movebank](https://www.movebank.org/cms/movebank-content/import-custom-tabular-data).
3 changes: 1 addition & 2 deletions analysis/1-pressure.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if (debug) {


# Filter stationary period based on the number of pressure datapoint available
thr_dur <- gpr$thr_dur # 24*4 # duration in hour. Decrease this value down to gpr$thr_dur
thr_dur <- gpr$thr_dur # duration in hour. Decrease this value zero if possible
res <- as.numeric(difftime(pam$pressure$date[2], pam$pressure$date[1], units = "hours"))
sta_id_keep <- pam$pressure %>%
filter(!isoutlier & sta_id > 0) %>%
Expand All @@ -122,7 +122,6 @@ pam_short$pressure <- pam_short$pressure %>%
mutate(sta_id = ifelse(sta_id %in% sta_id_keep, sta_id, NA))

# Query pressure map
# We overwrite the setting parameter for resolution to make query faster at first
pressure_maps <- geopressure_map(pam_short$pressure,
extent = c(gpr$extent_N, gpr$extent_W, gpr$extent_S, gpr$extent_E),
scale = gpr$map_scale,
Expand Down
18 changes: 7 additions & 11 deletions analysis/3-static.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gdl <- "18LX"
load(paste0("data/1_pressure/", gdl, "_pressure_prob.Rdata"))
load(paste0("data/2_light/", gdl, "_light_prob.Rdata"))

# Defint the threashold of the stationay period to consider
# Define the threshold of the stationary period to consider
thr_sta_dur <- gpr$thr_dur # in hours

sta_pres <- unlist(lapply(pressure_prob, function(x) raster::metadata(x)$sta_id))
Expand Down Expand Up @@ -52,11 +52,6 @@ static_prob <- mapply(function(light, pressure, flight) {
# define static prob as the product of light and pressure prob
static_prob <- light * pressure

# replace na by zero
# tmp <- values(static_prob)
# tmp[is.na(tmp)] <- 0
# values(static_prob) <- tmp

# define metadata
metadata(static_prob) <- metadata(pressure)
metadata(static_prob)$flight <- flight
Expand Down Expand Up @@ -84,7 +79,7 @@ tmp[!is.na(tmp)] <- 0
tmp[lat_calib_id, lon_calib_id] <- 1
values(static_prob[[1]]) <- tmp

if (!is.na(gpr$calib_2_start) & abs(difftime(gpr$calib_2_end, gpr$crop_end, units = "days"))<3) {
if (!is.na(gpr$calib_2_start) & abs(difftime(gpr$calib_2_end, gpr$crop_end, units = "days")) < 3) {
if (!is.na(gpr$calib_2_lat)) {
lon_calib_id <- which.min(abs(gpr$calib_2_lon - lon))
lat_calib_id <- which.min(abs(gpr$calib_2_lat - lat))
Expand Down Expand Up @@ -123,7 +118,7 @@ if (debug) {
# impact your code
pam_diff <- pam
pam_diff$pressure <- pam_diff$pressure %>%
left_join(path_modified_ts_bind %>% dplyr::select(c("date","pressure0")), by="date") %>%
left_join(path_modified_ts_bind %>% dplyr::select(c("date", "pressure0")), by = "date") %>%
rename(obs_ref = pressure0)

trainset_write(pam_diff, "data/1_pressure/labels/", filename = paste0(pam$id, "_act_pres"))
Expand All @@ -135,7 +130,8 @@ if (debug) {
twl_path <- left_join(twl, path_modified) %>%
mutate(
twilight = twilight(twilight,
lon = lon, lat = lat, rise = rise, zenith = 96)
lon = lon, lat = lat, rise = rise, zenith = 96
)
) %>%
filter(!is.na(twilight))

Expand All @@ -145,14 +141,14 @@ if (debug) {
series = ifelse(twl$rise, "Rise", "Set"),
timestamp = strftime(twl$twilight, "%Y-%m-%dT00:00:00Z", tz = "UTC"),
value = (as.numeric(format(twl$twilight, "%H")) * 60 + as.numeric(format(twl$twilight, "%M"))
+ gpr$shift_k / 60 + 60 * 12) %% (60 * 24),
+ gpr$shift_k / 60 + 60 * 12) %% (60 * 24),
label = ifelse(is.na(twl$delete), "", ifelse(twl$delete, "Delete", ""))
),
data.frame(
series = ifelse(twl_path$rise, "Set_ref", "Rise_ref"),
timestamp = strftime(twl_path$twilight, "%Y-%m-%dT00:00:00Z", tz = "UTC"),
value = (as.numeric(format(twl_path$twilight, "%H")) * 60 + as.numeric(format(twl_path$twilight, "%M"))
+ gpr$shift_k / 60 + 60 * 12) %% (60 * 24),
+ gpr$shift_k / 60 + 60 * 12) %% (60 * 24),
label = ""
)
),
Expand Down
12 changes: 5 additions & 7 deletions analysis/5-1-wind-graph_download.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
library(GeoPressureR)
library(ecmwfr)

# Define which track to work with
gdl <- "18LX"

# Load
load(paste0("data/1_pressure/", gdl, "_pressure_prob.Rdata"))
load(paste0("data/3_static/", gdl, "_static_prob.Rdata"))

# Set credential
Sys.setenv( cds_key="Insert_your_CDS_API_KEY_here")
Sys.setenv( cds_user="Insert_your_CDS_UID_here")
Sys.setenv(cds_key = "Insert_your_CDS_API_KEY_here")
Sys.setenv(cds_user = "Insert_your_CDS_UID_here")

# You can see them with
# usethis::edit_r_environ()
# cds_key <- Sys.getenv("cds_key")
# cds_user <- Sys.getenv("cds_user")

graph_download_wind(pam,
area = static_prob,
# cds_key="Insert_your_CDS_API_KEY_here"
# cds_user="Insert_your_CDS_UID_here"
)
graph_download_wind(pam, area = static_prob)

# Check request at https://cds.climate.copernicus.eu/cdsapp#!/yourrequests
2 changes: 1 addition & 1 deletion analysis/99-combined.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dir.create("data/5_wind_graph", showWarnings = FALSE)
for (i in seq(1, length(gdl_list))) {
gdl <- gdl_list[i]
source("analysis/5-1-wind-graph_download.R")
# Use job to avoid blocking your console.
# You can also make this request with a background job in Rstudio (https://solutions.rstudio.com/r/jobs/)
# rstudioapi::jobRunScript("analysis/5-1-wind-graph_download.R",
# name = paste0("wind_graph_download_", gdl),
# workingDir = ".",
Expand Down
Binary file modified data/gpr_settings.xlsx
Binary file not shown.

0 comments on commit 2bc60d5

Please sign in to comment.