Skip to content

Commit

Permalink
Merge pull request #60 from lawinslow/master
Browse files Browse the repository at this point in the history
Fixing edge-case issues in meta.depths
  • Loading branch information
Jordan S Read committed May 28, 2015
2 parents 2d7be6c + 8a3c2bd commit e9a4197
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rLakeAnalyzer
Title: Package for the Analysis of Lake Physics
Maintainer: Luke Winslow <[email protected]>
Version: 1.7.3
Version: 1.7.6
Author: Luke Winslow, Jordan Read, Richard Woolway, Jennifer Brentrup, Taylor
Leach, Jake Zwart
Description: Standardized methods for calculating common important derived
Expand Down
18 changes: 7 additions & 11 deletions R/meta.depths.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,16 @@ meta.depths = function(wtr, depths, slope=0.1, seasonal=TRUE, mixed.cutoff=1){
Tdepth[i] = mean(depths[ i:(i+1) ]);
}

tmp = sort.int(c(Tdepth, thermoD+1e-6), index.return = TRUE)
tmp = sort.int(unique(c(Tdepth, thermoD)), index.return = TRUE)
sortDepth = tmp$x
sortInd = tmp$ix
numDepths = length(sortDepth) #set numDepths again, it could have changed above
drho_dz = approx(Tdepth, drho_dz, sortDepth)
drho_dz = drho_dz$y

thermo_index = 1
thermoId = numDepths;
for(i in 1:numDepths){
if(thermoId == sortInd[i]){
thermo_index = i
break;
}
}
#find the thermocline index
# this is where we will start our search for meta depths
thermo_index = which(sortDepth == thermoD)

for (i in thermo_index:numDepths){ # moving down from thermocline index
if (!is.na(drho_dz[i]) && drho_dz[i] < slope){ #top of metalimnion
Expand All @@ -117,7 +113,7 @@ meta.depths = function(wtr, depths, slope=0.1, seasonal=TRUE, mixed.cutoff=1){
}
}

if (i-thermo_index > 1 && (!is.na(drho_dz[thermo_index]) && drho_dz[thermo_index] > slope)){
if (i-thermo_index >= 1 && (!is.na(drho_dz[thermo_index]) && drho_dz[thermo_index] > slope)){
metaBot_depth = approx(drho_dz[thermo_index:i],
sortDepth[thermo_index:i],slope)
metaBot_depth = metaBot_depth$y
Expand All @@ -134,7 +130,7 @@ meta.depths = function(wtr, depths, slope=0.1, seasonal=TRUE, mixed.cutoff=1){
}
}

if(thermo_index - i > 1 && (!is.na(drho_dz[thermo_index]) && drho_dz[thermo_index] > slope)){
if(thermo_index - i >= 1 && (!is.na(drho_dz[thermo_index]) && drho_dz[thermo_index] > slope)){
metaTop_depth = approx(drho_dz[i:thermo_index], sortDepth[i:thermo_index], slope);
metaTop_depth = metaTop_depth$y
}
Expand Down
2 changes: 1 addition & 1 deletion man/internal.energy.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/internal.energy.R
\name{internal.energy}
\alias{internal.energy}
Expand Down
2 changes: 1 addition & 1 deletion man/meta.depths.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/meta.depths.R
\name{meta.depths}
\alias{meta.depths}
Expand Down
2 changes: 1 addition & 1 deletion man/thermo.depth.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/thermo.depth.R
\name{thermo.depth}
\alias{thermo.depth}
Expand Down
2 changes: 1 addition & 1 deletion man/wtr.plot.temp.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/wtr.plot.temp.R
\name{wtr.plot.temp}
\alias{wtr.plot.temp}
Expand Down

0 comments on commit e9a4197

Please sign in to comment.