-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_repos.rmd
147 lines (97 loc) · 6.87 KB
/
create_repos.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Creating OHI repos
This is how you create OHI repos using the package `ohirepos`.
# Before R: First create repo on GitHub and register it
There are two things you need to do before executing the script below.
1. Make a repository on GitHub.com. You'll need a GitHub account and if you're making the repo within the [OHI-Science](https://github.com/OHI-Science) organization you'll need administration privileges. We typically make OHI repos with short, 3-letter keys, for example `bhi` and `gye`.
<center><img src="../ohirepos-log/images/create-new-gh-repo.png" width="450px"></center>
2. Add info by hand to `ohirepos-log/repo_registry.csv`. To create a Starter Repo with only a prep folder, all you need to input are the first two columns (`study_key` and `study_area`). Make sure the `study_key` is what you named your GitHub repository. If you're making a Full Repo, you'll need to provide a filepath for shapefiles. Additionally, if you want to populate the repo with data from global assessments, check `ohirepos-log/rgn_global.csv` to cross-check global name and rgn_id to populate the repo. See the OHI Manual section on [requesting your repositories](http://ohi-science.org/manual/#requesting-your-repositories) for more information between the Starter Repo and the Full Repo.
Now you're ready for R.
# Initial Setup
## Assign variables
You will need to assign two variables based on the repository you want to created. Once you set these variables you'll be able to run this code chunk.
1. your repo's key — the same one that you set above and registered in `repo_registry`
2. a temporary directory where you want to work locally on your computer
```{r setup, eval=FALSE}
## you set these variables
key <- 'tet-scores'
dir_temp <- '~/github/clip-n-ship' # create this folder
## load libraries. NOTE: functions.r and brew have trouble with install_github; need load_all.
library(tidyverse)
library(ohirepos) # devtools::install_github("ohi-science/ohirepos")
# devtools::load_all('~/github/ohi-science/ohirepos') # loading locally makes brew work better
## read in repo registry information, add working directory
repo_registry <- readr::read_csv('repo_registry.csv') %>%
dplyr::filter(study_key == key) %>%
dplyr::mutate(dir_repo = file.path(dir_temp, key))
## update Mazu directories if using NCEAS server
if (any(stringr::str_detect(repo_registry, 'git-annex'), na.rm=TRUE)) {
## mazu directories
dir_M <- c('Windows' = '//mazu.nceas.ucsb.edu/ohi',
'Darwin' = '/Volumes/ohi', ### connect (cmd-K) to smb://mazu/ohi
'Linux' = '/home/shares/ohi')[[ Sys.info()[['sysname']] ]]
repo_registry <- repo_registry %>%
dplyr::mutate(dir_shp_in = file.path(dir_M, dir_shp_in),
dir_shp_out = file.path(dir_M, dir_shp_out))
if (Sys.info()[['sysname']] != 'Linux' & !file.exists(dir_M)){
warning(sprintf("The Mazu directory dir_M set in src/R/common.R does not exist. Do you need to mount Mazu: %s?", dir_M))
}
}
## create working dir if it doesn't already exist
# if(!file.exists(repo_registry$dir_repo)) dir.create(repo_registry$dir_repo)
```
# Populate the Starter Repo
The Starter Repo has some initial files including a README, as well as a `prep` folder with sub-folders for every goal and sub-goal. Additionally, create and push the project website. The default for these functions is to push updates to github.com/ohi-science/[key].
If you need to unpopulate an existing repo, there are instructions below.
```{r starter repo, eval=FALSE}
## populate the prep repo — create a repo object for the master branch
repo <- ohirepos::populate_init(repo_registry, push = FALSE) # note: error with branch, workaround is to clone by hand to clip-n-ship
repo <- ohirepos::populate_prep(repo_registry, push = FALSE)
## deploy the website — don't create a repo object because it's a gh-pages branch
ohirepos::deploy_website(repo_registry, push = FALSE)
## create explore-global.Rmd.
## Takes several minutes. Requires connection to NCEAS's server
## Note! study_area must be an OHI-Global region; if not change temporarily ;)
source('create_global_explore.R')
ohirepos::commit_and_push(repo_registry, "create global_explore folder")
```
# Populate Full Repo
You'll need to fill out all fields in `repo_registry.csv` to populate the Full Repo. You can choose the origin of the files you'll copy (it defaults to ohi-global). You have to make sure there a copy of the origin repo cloned locally.
Populating the layers folder and layers.csv will also create the scenario folder. And then create conf. Run these in order.
If you need to unpopulate your repo's scenario folder if you've redefined regions or something, clone it locally and pull, delete the scenario folder, and then continue here (scripting this was overkill).
You'll run these as a suite of things, so just clone during populate_layers and push as the final move after the check.
```{r full repo, eval=FALSE}
## create repo's maps and push
repo <- ohirepos::create_repo_map(repo_registry, push = FALSE)
## create layers/ folder and layers.csv
repo <- ohirepos::populate_layers(repo_registry, multi_nation = FALSE)
## TODO come back here to make sure the empty layers don't cause a problem (removed swapping global mean stuff); still clean up.
## populate conf folder.
ohirepos::populate_conf(repo_registry)
## NOTE!! The fix to this error: `Error in 1:ln_beg : NA/NaN argument`
## -> Must go to functions.R, search `## Reference Point` and delete by hand between: `## Reference Point Accounting` and `## Reference Point End.`
## TODO Code this up at a later date
## NOTE!! Another troubleshooting thing to do by hand in order to calculate scores in next chunk below:
## 1. search for `eez/` and search-replace this with the scenario name (e.g. `region`).
## 2. create a temp folder in the scenario folder.
## 3. Finally, delete the `Oecussi Ambeno (rgn 237)` gapfilling part from ICO; this is ~40 lines.
ohirepos::populate_etc(repo_registry)
## TODO: add viz
```
## Calculate scores and create scores.csv
Can also test this from the repo itself (open the the clip-n-ship/key/.rproj)
```{r calculate, eval=FALSE}
## calculate scores
ohirepos::calculate_scores_check(repo_registry,
ohicore_version = 'ohicore')
## Troubleshooting:
## If this fails, try this:
## Open the `mse` (for example) repo in a new RStudio session
## Run calculate_scores.Rmd line by line and see where it fails.
## You'll then have to go to the specific function that failed and look for something that is global specific that is failing with OHI+
## For example, ICO will fail because of gapfilling, so you'll have to delete the gapfilling section
## Error in data.frame(goal = "ICO", dimension = rep(c("status", "trend"), :
## object 'regions_NA' not found
## and push!
ohirepos::commit_and_push(repo_registry,
commit_message = sprintf('finalized %s repo!', key))
```