Skip to content

Commit 2c69ca4

Browse files
Merge branch 'master' into master
2 parents c74688b + bd0ec91 commit 2c69ca4

26 files changed

Lines changed: 2718 additions & 277 deletions

.RData

-1.89 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ data/general/nhd_hr
2727
output/
2828
old_dataset_dirs.tar.gz
2929
old_logs
30+
vault/*

src/.RData

2.57 KB
Binary file not shown.

src/acquisition_master.R

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ ms_init <- function(use_gpu = FALSE,
101101
successes <- 0
102102
which_machine <- 'unknown'
103103

104+
# example dev computer 'registration' code block
105+
## res <- try(setwd('~/your/file/path/to/macrosheds/data_processing'), silent=TRUE) # example
106+
## if(! 'try-error' %in% class(res)){
107+
## successes <- successes + 1
108+
## which_machine <- 'your_machine') # machine name is completely up to you, does not matter
109+
## instance_type <- 'dev' # instance type is 'dev' for all personal computers
110+
## machine_status <- 'n00b' # unless you have > 32GB of RAM and > 8 CPUS, your 'n00b'
111+
## op_system <- 'mac' # whats your OS?
112+
## }
113+
104114
res <- try(setwd('~/macrosheds_data_processing'), silent=TRUE) #DCC
105115
if(! 'try-error' %in% class(res)){
106116
successes <- successes + 1
@@ -127,6 +137,15 @@ ms_init <- function(use_gpu = FALSE,
127137
machine_status <- '1337'
128138
op_system <- 'windows'
129139
}
140+
141+
res <- try(setwd('/Users/hectorontiveros/Applications/data_processing'), silent=FALSE) #Hector
142+
if(! 'try-error' %in% class(res)){
143+
successes <- successes + 1
144+
which_machine <- 'hec'
145+
instance_type <- 'dev'
146+
machine_status <- 'n00b'
147+
op_system <- 'macOS'
148+
}
130149

131150
res <- try(setwd('~/desktop/macrosheds/data_acquisition'), silent=TRUE) #spencer
132151
if(! 'try-error' %in% class(res)){
@@ -137,6 +156,15 @@ ms_init <- function(use_gpu = FALSE,
137156
op_system <- 'mac'
138157
}
139158

159+
res <- try(setwd('~/Desktop/MacroSheds/data_processing/src/data_acquisition'), silent=TRUE) #pranavi
160+
if(! 'try-error' %in% class(res)){
161+
successes <- successes + 1
162+
which_machine <- 'Pranavi'
163+
instance_type <- 'dev'
164+
machine_status <- 'n00b'
165+
op_system <- 'mac'
166+
}
167+
140168
res <- try(setwd('C:/Users/gubbi/Documents/macrosheds/data_processing'), silent=TRUE) #Nick
141169
if(! 'try-error' %in% class(res)){
142170
successes <- successes + 1
@@ -172,6 +200,15 @@ ms_init <- function(use_gpu = FALSE,
172200
# machine_status <- '1337'
173201
# }
174202

203+
res <- try(setwd('/home/weston/science/macrosheds/data_processing'), silent=TRUE) # wes
204+
if(! 'try-error' %in% class(res)){
205+
successes <- successes + 1
206+
which_machine <- 'wes'
207+
instance_type <- 'dev'
208+
machine_status <- '1337'
209+
op_system <- 'linux'
210+
}
211+
175212
res <- try(setwd('/home/macrosheds/data_acquisition'), silent=TRUE) #server
176213
if(! 'try-error' %in% class(res)){
177214
successes <- successes + 1
@@ -218,24 +255,29 @@ ms_instance <- ms_init(use_ms_error_handling = FALSE,
218255
config_storage_location = 'remote')
219256

220257
#load authorization file for macrosheds google sheets
221-
googlesheets4::gs4_auth(path = 'googlesheet_service_accnt.json')
258+
## googlesheets4::gs4_auth(path = 'googlesheet_service_accnt.json')
222259

223260
#read in secrets
224261
conf <- jsonlite::fromJSON('config.json',
225262
simplifyDataFrame = FALSE)
226263

264+
227265
#connect rgee to earth engine and python
228266
gee_login <- case_when(
229267
ms_instance$which_machine %in% c('Mike', 'BM1') ~ conf$gee_login_mike,
230-
ms_instance$which_machine %in% c('Spencer', 'BM0', 'BM2') ~ conf$gee_login_spencer,
231-
ms_instance$which_machine %in% c('Nick') ~ conf$gee_login_spencer,
268+
ms_instance$which_machine %in% c('Spencer', 'BM0', 'BM2', 'Nick') ~ conf$gee_login_spencer,
269+
ms_instance$which_machine %in% c('Hector','Biniam','Pranavi', 'Wes') ~conf$gee_login_ms,
232270
TRUE ~ 'UNKNOWN')
233271

234-
# try(rgee::ee_Initialize(user = gee_login,
235-
# drive = TRUE))
236-
272+
#load authorization file for macrosheds google sheets and drive
273+
#same account must have GEE and GDrive access
274+
googlesheets4::gs4_auth(email = gee_login)
237275
googledrive::drive_auth(email = gee_login)
238276

277+
#initialize and authorize GEE account
278+
try(rgee::ee_Initialize(user = gee_login,
279+
drive = TRUE))
280+
239281
#set up global logger. network-domain loggers are set up later
240282
logging::basicConfig()
241283
logging::addHandler(logging::writeToFile,
@@ -249,7 +291,7 @@ if(ms_instance$use_ms_error_handling){
249291
source_decoratees('src/global/global_helpers.R') #parse decorators
250292
}
251293

252-
#puts ms_vars, site_data, ws_delin_specs, univ_products into the global environment
294+
#puts (google sheets) ms_vars, site_data, ws_delin_specs, univ_products into the global environment
253295
load_config_datasets(from_where = ms_instance$config_data_storage)
254296

255297

@@ -274,8 +316,6 @@ ms_globals <- c(ls(all.names = TRUE), 'ms_globals')
274316

275317
dir.create('logs', showWarnings = FALSE)
276318

277-
dmnrow = 29
278-
# print(network_domain, n=50)
279319
for(dmnrow in 1:nrow(network_domain)){
280320

281321
# drop_automated_entries('.') #use with caution!
@@ -284,17 +324,19 @@ for(dmnrow in 1:nrow(network_domain)){
284324
network <- network_domain$network[dmnrow]
285325
domain <- network_domain$domain[dmnrow]
286326

287-
# held_data = get_data_tracker(network, domain)
327+
held_data = get_data_tracker(network, domain)
288328

289-
# held_data = invalidate_tracked_data(network, domain, 'munge')
290-
# owrite_tracker(network, domain)
291-
# held_data = invalidate_tracked_data(network, domain, 'derive')
292-
# owrite_tracker(network, domain)
329+
## dangerous lines - use at your own risk! :0
330+
## held_data = invalidate_tracked_data(network, domain, 'munge')
331+
## owrite_tracker(network, domain)
332+
## held_data = invalidate_tracked_data(network, domain, 'derive')
333+
## owrite_tracker(network, domain)
293334

294-
# held_data = invalidate_tracked_data(network, domain, 'munge', 'precipitation')
295-
# owrite_tracker(network, domain)
296-
# held_data = invalidate_tracked_data(network, domain, 'derive', 'stream_flux_inst')
297-
# owrite_tracker(network, domain)
335+
## less dangerous version below, clears tracker for just a specified product
336+
## held_data = invalidate_tracked_data(network, domain, 'munge', 'stream_chemistry')
337+
## owrite_tracker(network, domain)
338+
## held_data = invalidate_tracked_data(network, domain, 'derive', 'stream_flux_inst')
339+
## owrite_tracker(network, domain)
298340

299341
logger_module <- set_up_logger(network = network,
300342
domain = domain)
@@ -306,23 +348,27 @@ for(dmnrow in 1:nrow(network_domain)){
306348

307349
update_product_statuses(network = network,
308350
domain = domain)
351+
309352
get_all_local_helpers(network = network,
310-
domain = domain)
353+
domain = domain)
311354

312355
ms_retrieve(network = network,
313356
# prodname_filter = c('stream_chemistry'),
314357
domain = domain)
358+
315359
ms_munge(network = network,
316360
prodname_filter = c('stream_chemistry'),
317361
domain = domain)
362+
318363
if(domain != 'mcmurdo'){
319364
sw(ms_delineate(network = network,
320365
domain = domain,
321366
dev_machine_status = ms_instance$machine_status,
322367
verbose = TRUE))
323368
}
369+
324370
ms_derive(network = network,
325-
prodname_filter = c('discharge'),
371+
prodname_filter = c('precip_pchem_pflux'),
326372
domain = domain)
327373

328374
if(domain != 'mcmurdo'){
@@ -356,3 +402,4 @@ if(length(email_err_msgs)){
356402

357403
loginfo(msg = 'Run complete',
358404
logger = logger_module)
405+

src/dev/dev_helpers.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,3 +1423,17 @@ insert_retrieval_datetimes <- function(){
14231423
write_lines(rt, f)
14241424
}
14251425
}
1426+
1427+
get_nonnumerics <- function(d){
1428+
1429+
#gets unique nonnumeric values by row. useful for identifying quality codes
1430+
#within data columns
1431+
1432+
nonnumerics = apply(d, 2, function(x){
1433+
xx = as.numeric(x)
1434+
nonnumerics = is.na(xx)
1435+
out = unique(x[nonnumerics])
1436+
})
1437+
1438+
return(nonnumerics)
1439+
}

src/global/function_aliases.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,9 @@ map = purrr::map
5050
map2 = purrr::map
5151
st_read = sf::st_read
5252
errors = errors::errors
53+
drop_errors = errors::drop_errors
54+
set_errors = errors::set_errors
5355
pivot_wider = tidyr::pivot_wider
5456
pivot_longer = tidyr::pivot_longer
57+
rename = dplyr::rename
58+
where = tidyselect:::where

src/global/general_kernels.R

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,36 +1822,24 @@ process_3_ms824 <- function(network, domain, prodname_ms, site_code,
18221822

18231823
googledrive::drive_rm('GEE/rgee.csv', verbose = FALSE)
18241824

1825-
1826-
final <- fin_table %>%
1825+
fin_table <- fin_table %>%
18271826
select(date, site_code, dayl, prcp, srad, swe, tmax, tmin, vp)
18281827

1829-
if(nrow(final) == 0){
1828+
if(nrow(fin_table) == 0){
18301829
return(generate_ms_exception(glue('No data was retrived for {s}',
18311830
s = site_code)))
18321831
}
18331832

18341833
dir.create(glue('data/{n}/{d}/ws_traits/daymet/',
18351834
n = network,
1836-
d = domain))
1835+
d = domain),
1836+
showWarnings = FALSE)
18371837

18381838
file_path <- glue('data/{n}/{d}/ws_traits/daymet/domain_climate.feather',
18391839
n = network,
18401840
d = domain)
18411841

1842-
write_feather(final, file_path)
1843-
1844-
# type <- str_split_fixed(prodname_ms, '__', n = Inf)[,1]
1845-
#
1846-
# dir <- glue('data/{n}/{d}/ws_traits/{v}/',
1847-
# n = network, d = domain, v = type)
1848-
#
1849-
# final <- append_unprod_prefix(final, prodname_ms)
1850-
# final_sum <- append_unprod_prefix(final_sum, prodname_ms)
1851-
#
1852-
# save_general_files(final_file = final_sum,
1853-
# raw_file = final,
1854-
# domain_dir = dir)
1842+
write_feather(fin_table, file_path)
18551843

18561844
return()
18571845
}

0 commit comments

Comments
 (0)