-
Couldn't load subscription status.
- Fork 271
Add Matt Kim's R scripts to data.remote/inst #3615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sarahkanee
wants to merge
6
commits into
PecanProject:develop
Choose a base branch
from
sarahkanee:mattykim-import
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+167
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b7f552
Add Matty Kim exploratory R scripts to data.remote/inst
sarahkanee 9bff8e2
Keep NASA DAAC functions in R/, move updated workflow additions to inst/
sarahkanee 04bbd69
Move Matt's scripts from data.remote/inst to meta.analysis/inst/magic/
sarahkanee 05a78f6
Move download_updated.R into data.remote/inst
sarahkanee 14c5e7f
Fix: move SMAP + netCDF scripts back to data.remote/inst, keep only M…
sarahkanee 15a141c
Remove run_local.R from meta.analysis/inst/magic
sarahkanee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #DAAC_Set_Credential(replace = TRUE) | ||
|
|
||
| # California bounding box is: | ||
| # up_lat <- 42.0095082699265845 | ||
| # up_lon <- -124.4820168611238245 | ||
| # low_lat <- 32.5288367369123748 | ||
| # low_lon <- -114.1312224747231312 | ||
|
|
||
| ul_lat <- 42.0095082699265845 # y = 4651894 in crs | ||
| ul_lon <- -124.4820168611238245 # x = 377279.7 in crs | ||
| lr_lat <- 32.5288367369123748 # y = 3633946 in crs | ||
| lr_lon <- -114.1312224747231312 # x = 1334269 in crs | ||
|
|
||
| from <- "2019-01-01" | ||
| to <- "2019-12-31" | ||
| doi <- "10.5067/HLS/HLSS30.002" | ||
| outdir <- "//projectnb/dietzelab/XinyuanJi/State_of_California_HLSS/2019_Fmask" | ||
| # SWIR - Landsat (B6&7), Sentinel (B11&12) | ||
| band <- "Fmask" | ||
| credential.folder <- "~/projectnb/XinyuanJi" | ||
| paths <- NASA_DAAC_download(ul_lat = ul_lat, | ||
| ul_lon = ul_lon, | ||
| lr_lat = lr_lat, | ||
| lr_lon = lr_lon, | ||
| ncore = 16, | ||
| from = from, | ||
| to = to, | ||
| outdir = outdir, | ||
| band = band, | ||
| credential.folder = credential.folder, | ||
| doi = doi, | ||
| just_path = F) | ||
|
|
||
| provider_conceptID <- NASA_CMR_finder("10.5067/HLS/HLSS30.002") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| library(readxl) | ||
| library(dplyr) | ||
|
|
||
| extract_rows_traitID <- function(excel_path, sheet_name = 1, trait_ID) { | ||
|
|
||
| #reads the excel sheet | ||
| data <- readxl::read_excel(excel_path, sheet = sheet_name, col_types = NULL) | ||
|
|
||
| #throws an error if TraitID is not within the sheet | ||
| if (!"TraitID" %in% colnames(data)) { | ||
| stop("Column TraitID not found within the excel sheet") | ||
| } | ||
|
|
||
| # finds the rows with the desired TraitID | ||
| matched_rows <- which(data$TraitID == trait_ID) | ||
|
|
||
| if (length(matched_rows) > 0) { | ||
| filtered_rows <- data[matched_rows, ] | ||
| } else { | ||
| filtered_rows <- data.frame() | ||
| message("No rows found with TraitID of ", trait_ID) | ||
| } | ||
|
|
||
|
|
||
| # df2 now has a `common_name` column right after `SpeciesName` | ||
|
|
||
| return (filtered_rows) | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| library(dplyr) | ||
|
|
||
| get_stats <- function(data, value_column, group_column, species_column = "SpeciesName", species_name) { | ||
|
|
||
| # Filter by species | ||
| data_filtered <- data %>% | ||
| filter(.data[[species_column]] == species_name) | ||
|
|
||
| # Convert value column to numeric | ||
| data_filtered[[value_column]] <- as.numeric(data_filtered[[value_column]]) | ||
|
|
||
| # Summarize statistics | ||
| summary_df <- data_filtered %>% | ||
| group_by(across(all_of(group_column))) %>% | ||
| summarise( | ||
| mean_value = mean(.data[[value_column]], na.rm = TRUE), | ||
| sd = sd(.data[[value_column]], na.rm = TRUE), | ||
| n = sum(!is.na(.data[[value_column]])), | ||
| .groups = "drop" | ||
| ) %>% | ||
| rename(TraitID = 1) | ||
|
|
||
| return(summary_df) | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| library(dplyr) | ||
|
|
||
| initialize_planting <- function(species_name) { | ||
|
|
||
| species_stats <- data.frame( | ||
| get_stats(planting_df, "OrigValueStr", "TraitID", "SpeciesName", species_name) | ||
| ) | ||
| return(species_stats) | ||
|
|
||
| #calculate for each trait | ||
|
|
||
| #3441 leafC | ||
|
|
||
| #128 wood/stemC | ||
|
|
||
| #3450 rootC | ||
|
|
||
| #2005 fine-rootC | ||
|
|
||
| #1534 coarse-rootC | ||
|
|
||
| #output a table with the information | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #this will be the main file where the entire program will be run | ||
| library(readxl) | ||
| library(dplyr) | ||
|
|
||
| source("extract_rows_traitID.R") | ||
|
|
||
| main <- function(files, trait_IDs, sheet_name = 1) { | ||
| combined_data <- data.frame() | ||
|
|
||
| for (file in files) { | ||
| for (id in trait_IDs) { | ||
| temp <- extract_rows_traitID(file, sheet_name = 1, trait_ID = id) | ||
| combined_data <- bind_rows(combined_data, temp) | ||
| } | ||
| } | ||
| return (combined_data) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #this will run the entire program | ||
|
|
||
| #example run: test_df1 <- run_program(time = "planting", species = "Rubus idaeus") | ||
|
|
||
| library(readxl) | ||
| library(dplyr) | ||
| library(taxize) | ||
|
|
||
| source("get_stats.R") | ||
|
|
||
| run_program <- function(time, species) { | ||
| #time is harvest/planting | ||
| #pool is part of plant | ||
| #species is species | ||
|
|
||
| temp_plant_df <- get_stats(master_data, value_column = "OrigValueStr", trait_column = "TraitID", species_column = "SpeciesName", species_name = species) | ||
|
|
||
| #need to implement if NA, return species with like traits | ||
|
|
||
| if (time == "planting") { | ||
| temp_plant_df <- temp_plant_df[temp_plant_df$TraitID %in% c("3441", "128", "2005", "1534"),] | ||
| } | ||
| else if (time == "harvest") { | ||
| temp_plant_df <- temp_plant_df[temp_plant_df$TraitID %in% c("3962", "470"),] | ||
|
|
||
| } | ||
|
|
||
| if (nrow(temp_plant_df) == 0) { | ||
| return(paste(species, "has nothing")) | ||
| } | ||
|
|
||
| return (temp_plant_df) | ||
|
|
||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest putting this in a subdirectory named
magic, as done for the files in meta.analysis -- even though there's only one file here it should help us keep track of where things came from.Even better but obviously more effort would be to add a short README to each subdirectory -- future viewers will be grateful for even a couple sentences explaining whose scripts they are, what project they were part of / how they're used, and how finished they are.