Last updated: 2020-03-16

Checks: 7 0

Knit directory: Baltic_Productivity/

This reproducible R Markdown analysis was created with workflowr (version 1.6.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20191017) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/ARGO/
    Ignored:    data/Finnmaid/
    Ignored:    data/GETM/
    Ignored:    data/OSTIA/
    Ignored:    data/_merged_data_files/
    Ignored:    data/_merged_data_files_2019V1/
    Ignored:    data/_summarized_data_files/
    Ignored:    data/_summarized_data_files_2019V1/

Unstaged changes:
    Deleted:    code/SSS.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


1 Medium Salinity

In the following section, we want to calculate the medium salinity per month and transect section. We will therefore end up with 544 x 12 salinity values.

nc <- nc_open(paste("data/Finnmaid/", "FM_all_2019_on_standard_tracks.nc", sep = ""))

# read required vectors from netcdf file
route <- ncvar_get(nc, "route")
route <- unlist(strsplit(route, ""))
date_time <- ncvar_get(nc, "time")
latitude_east <- ncvar_get(nc, "latitude_east")
longitude_east <-ncvar_get(nc, "longitude_east")
date_time_o <- ncvar_get(nc, "otime_east")

  array <- ncvar_get(nc, var) # store the data in a 2-dimensional array
  #dim(array) # should have 2 dimensions: 544 coordinate, 2089 time steps
  
  fillvalue <- ncatt_get(nc, var, "_FillValue")
  array[array == fillvalue$value] <- NA
  rm(fillvalue)
  
  cor_vector <- c(1:544)
  
  for (i in seq(1,length(route),1)){
  
      
    if(route[i] == select_route) {
      slice <- array[i,]          #define slice of the data, per row (per measurment day)
      value <- slice
      date <- ymd("2000-01-01") + date_time[i]
      
      #if detailed date/time information is needed: uncomment that
      #date <- as.Date(c(1:544))   # set up "date" variable to be overwritten later, needs to be "Date" object
      #for (a in seq(1,length(latitude_east),1)){              # for slice i the corresponding 544 transect steps are  
      #temp_time <- ymd("2000-01-01") + date_time_o[i,a]       # adjoined by corresponding time ("otime_east")
      #date[a] <- temp_time
      #}
      #temp <- bind_cols(value = value, lon = longitude_east, lat = latitude_east, 
      #corvector =   cor_vector, date_time = date)
      #temp$date_time <- as.POSIXct(temp$date_time)
      
      #when detailed time/date information is needed, comment the following
      temp <- bind_cols(value = value, lon = longitude_east, lat = latitude_east,
      corvector =  cor_vector)
      temp$date <- date
      # 
      
      if (exists("fm_sss", inherits = FALSE)){
        fm_sss <- bind_rows(fm_sss, temp)
      } else{fm_sss <- temp}
      
      rm(temp, value, date)
    }
    print(i)
  }

nc_close(nc)

fm_sss_corvector <- fm_sss %>% 
  transmute(sss = value,
         year = year(date),
         month = month(date),
         corvector = corvector )

  for (cor in 1:544){
    
    temp <- fm_sss_corvector %>% 
      filter(corvector == cor) %>% 
      select(month, corvector, sss) %>% 
      group_by(month, corvector) %>% 
      summarise_all(mean, na.rm = TRUE)
    
    if (exists("fm_sss_monthly", inherits = FALSE)){
        fm_sss_monthly <- bind_rows(fm_sss_monthly, temp)
      } else{fm_sss_monthly <- temp}
    rm(temp)
  }
  

fm_sss_monthly %>% 
vroom_write(here::here("data/_summarized_data_files/", file = "fm_sss_monthly_perTransect.csv"))


rm(fm_sss_monthly,  fm_sss_corvector, var, select_route)
fm_sss_monthly <- vroom::vroom(
  here::here("data/_summarized_data_files","fm_sss_monthly_perTransect.csv"))

fm_sss_monthly <- fm_sss_monthly %>% 
  mutate(dist.trav = corvector * 2,
         month_factor = as.factor(month))

fm_sss_monthly %>% 
  ggplot(aes(dist.trav, sss, color = month_factor))+
  geom_point(size = 0.1)+
  labs(x="Distance to Travemuende [km]",
       y="Surface Salinity")+
  theme_bw()+
  scale_colour_brewer(palette = "Paired",
                      type = "qual",
                      name = "Month",
                      labels = c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))

rm(fm_sss_monthly)

sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] metR_0.5.0       here_0.1         xts_0.11-2       zoo_1.8-6       
 [5] dygraphs_1.1.1.6 geosphere_1.5-10 lubridate_1.7.4  vroom_1.2.0     
 [9] ncdf4_1.17       forcats_0.4.0    stringr_1.4.0    dplyr_0.8.3     
[13] purrr_0.3.3      readr_1.3.1      tidyr_1.0.0      tibble_2.1.3    
[17] ggplot2_3.3.0    tidyverse_1.3.0 

loaded via a namespace (and not attached):
 [1] nlme_3.1-137         bitops_1.0-6         fs_1.3.1            
 [4] bit64_0.9-7          RColorBrewer_1.1-2   httr_1.4.1          
 [7] rprojroot_1.3-2      tools_3.5.0          backports_1.1.5     
[10] R6_2.4.0             DBI_1.0.0            colorspace_1.4-1    
[13] withr_2.1.2          sp_1.3-2             tidyselect_0.2.5    
[16] gridExtra_2.3        bit_1.1-14           compiler_3.5.0      
[19] git2r_0.26.1         cli_1.1.0            rvest_0.3.5         
[22] xml2_1.2.2           labeling_0.3         scales_1.0.0        
[25] checkmate_1.9.4      digest_0.6.22        foreign_0.8-70      
[28] rmarkdown_2.0        pkgconfig_2.0.3      htmltools_0.4.0     
[31] dbplyr_1.4.2         maps_3.3.0           htmlwidgets_1.5.1   
[34] rlang_0.4.5          readxl_1.3.1         rstudioapi_0.10     
[37] generics_0.0.2       jsonlite_1.6         RCurl_1.95-4.12     
[40] magrittr_1.5         Formula_1.2-3        dotCall64_1.0-0     
[43] Matrix_1.2-14        Rcpp_1.0.2           munsell_0.5.0       
[46] lifecycle_0.1.0      stringi_1.4.3        yaml_2.2.0          
[49] plyr_1.8.4           grid_3.5.0           maptools_0.9-8      
[52] formula.tools_1.7.1  parallel_3.5.0       promises_1.1.0      
[55] crayon_1.3.4         lattice_0.20-35      haven_2.2.0         
[58] hms_0.5.2            zeallot_0.1.0        knitr_1.26          
[61] pillar_1.4.2         reprex_0.3.0         glue_1.3.1          
[64] evaluate_0.14        data.table_1.12.6    modelr_0.1.5        
[67] operator.tools_1.6.3 vctrs_0.2.0          spam_2.3-0.2        
[70] httpuv_1.5.2         cellranger_1.1.0     gtable_0.3.0        
[73] assertthat_0.2.1     xfun_0.10            broom_0.5.3         
[76] later_1.0.0          memoise_1.1.0        fields_9.9          
[79] workflowr_1.6.0