Skip to content

Commit

Permalink
Merge pull request #90 from lawinslow/master
Browse files Browse the repository at this point in the history
mda.lakes cleanup
  • Loading branch information
Luke Winslow committed May 6, 2016
2 parents beef237 + c52e1a4 commit 630bebe
Show file tree
Hide file tree
Showing 51 changed files with 434 additions and 3,359 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mda.lakes
Type: Package
Title: Tools for combining models, data, and processing for lakes
Version: 3.0.4
Version: 4.1.2
Date: 2015-12-03
Author: Luke Winslow, Jordan Read
Maintainer: Luke Winslow <lwinslow@usgs.gov>
Expand All @@ -15,7 +15,8 @@ Imports:
httr,
rLakeAnalyzer (>= 1.5),
insol,
plyr
plyr,
accelerometry
Enhances: geoknife
Description: More about what it does (maybe more than one line)
License: LICENSE file
Expand Down
18 changes: 5 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ export(area_light_temp_threshold)
export(area_light_threshold)
export(area_temp_threshold)
export(calc_mod_obs_metric)
export(calc_stratified_periods)
export(calc_toha)
export(calc_toha_stats)
export(chained.habitat.calc)
export(chained.habitat.calc.kevin)
export(comb_output_table)
export(continuous.habitat.calc)
export(create_irr_day_cycle)
export(driver_add_burnin_years)
export(driver_add_rain)
Expand All @@ -37,26 +35,20 @@ export(getZmean)
export(get_driver_index)
export(get_driver_path)
export(get_ice_onoff)
export(get_wtr_chained)
export(hansen_habitat_calc)
export(interp_hypso)
export(load_gdp_file)
export(met_check_download_gdp)
export(met_drivers_start_gdp)
export(met_from_hostetler)
export(met_from_nldas)
export(necsc_thermal_metrics_core)
export(opti_thermal_habitat)
export(populate_base_lake_nml)
export(prep_run_chained_glm)
export(prep_run_chained_glm_kd)
export(prep_run_glm_kd)
export(sens_seasonal_site)
export(set_driver_url)
export(write_error_log)
import(GLMr)
import(glmtools)
import(lakeattributes)
import(lubridate)
import(rLakeAnalyzer)
import(stringr)
importFrom(accelerometry,rle2)
importFrom(insol,JD)
importFrom(insol,insolation)
importFrom(insol,normalvector)
Expand Down
50 changes: 0 additions & 50 deletions R/Libraries/htcondor-R.R

This file was deleted.

69 changes: 0 additions & 69 deletions R/calc.strat.days.R

This file was deleted.

78 changes: 0 additions & 78 deletions R/calc.strat.onset.R

This file was deleted.

49 changes: 49 additions & 0 deletions R/calc_stratified_periods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' @title Calculate all stratified periods based on temp threshold
#'
#' @param surfT data.frame with two columns, datetime and surface temperature
#' @param botT data.frame with two columns, datetime and bottom temperature (must be same nrow as surfT)
#' @param temp_thresh Threshold to define stratified in deg C (default = 1)
#' @param force_positive Is only warm stratified periods to be considered (drop winter when 0 is above 4 deg water, default TRUE)
#'
#' @description
#' A function to calculate
#'
#' @importFrom accelerometry rle2
#'
#' @export
calc_stratified_periods = function(surfT, botT, temp_thresh = 1, force_positive = TRUE){


##assume they are data.frames to start
datetime = surfT[,1]
surfT = surfT[,2]
botT = botT[,2]


if(length(botT) != length(surfT)){
stop('botT and surfT must be the same length or number of rows')
}

t_diff = surfT - botT
if(force_positive){
t_diff[t_diff < 0] = 0 #force only warm stratification
}else{
t_diff = abs(t_diff) #use both warm and cold stratification
}


periods = rle2(as.numeric(t_diff >= temp_thresh), indices = TRUE)

strat_periods = as.data.frame(periods[periods[,'values'] == 1, ,drop=FALSE])
strat_periods$values = NULL

#if no strat periods were found, just return empty data.frame
if(nrow(strat_periods) == 0){
return(strat_periods)
}

strat_periods$onset = datetime[strat_periods$starts]
strat_periods$breakdown = datetime[strat_periods$stops]

return(strat_periods)
}
Loading

0 comments on commit 630bebe

Please sign in to comment.