GLEON / rLakeAnalyzer

An R version of Lake Analyzer
43 stars 26 forks source link

whole lake heat temperature question #91

Closed algavin closed 4 years ago

algavin commented 6 years ago

Hello-

I am having trouble getting whole lake heat temperature to run and am getting an NA instead of a value. I am able to get internal.energy() to work, so I am not sure it is a problem with my vectors.

I have attached a xlsx file (i have been using csv but i can't upload that here) of my data and code is below.

Any input would be much appreciated! Thank you!

wlt = read.csv(file = "/Users/Amanda/Documents/rltm/write.csv/secondpond_wlt.csv", header = TRUE, sep = ",")

check for NA

is.na(wlt)

str(wlt)

bthA = as.numeric(bthA)

is.vector(bthA) is.numeric(bthA)

wtr = wlt[["wtr"]] depths = wlt[["depths"]] bthA = wlt[["bthA"]] bthD = wlt[["bthD"]]

str(wtr) str(depths) str(bthA) str(bthD)

whole lake heat temperature for 5_24

whole.lake.temperature(wtr, depths, bthA, bthD)

internal.energy(wtr, depths, bthA, bthD)

secondpond_wlt.xlsx

lawinslow commented 6 years ago

Hi @algavin,

Ok, a few thoughts.

  1. The non ts.* functions are meant to take one timestep worth of data. The dataset you supplied seems to be multiple profile observations (but no date/time indication). For an accurate number, you will need to break up observations into individual time points. The usual rLA format for that is a wide format, you can see an example here.

  2. bthD (bathy depths) are the depths at which each bthA (bathy area) values apply. In your dataset, this column only varies from 1 to 2, but your depths column ranges from 1 to 12.2. bthD should really cover the same (at least similar) depths as your profile. You can see an example of bathymetry data here.

  3. Below, I have included quick code that will give you an estimate based on some of your data. I just pulled out one unique profile (based on depths) and used the corresponding bthA, which may not make any sense. I noticed that even with that, I get NA with whole.lake.temperature. This is a bit of an over-simplified convenience function. I instead use layer.temperature and modify the min depth to be the minimum depth of observed data. This then returns a meaningful answer. If you want to run this on multiple observations, I would look at the ts.layer.temperature function, which is a fully-functional form of a tool that will give you the answer you're looking for.

wtr = wtr[!duplicated(depths)]
bthA = bthA[!duplicated(depths)]
bthD = bthD[!duplicated(depths)]
depths = depths[!duplicated(depths)]

whole.lake.temperature(wtr, depths, bthA, depths)

layer.temperature(1,max(depths), wtr=wtr, depths=depths, bthA=bthA, bthD=depths)

Let me know how you get on with this. Hope this helps!

algavin commented 6 years ago

Thank you! That was all very helpful. Do you know what formula is used for the ts.layer.temperature function?

Thanks again!

lawinslow commented 6 years ago

Pretty much summed up here. https://github.com/GLEON/rLakeAnalyzer/blob/master/R/layer.temperature.R#L87-L89 Just simple volume-weighted average.

jordansread commented 4 years ago

Closing this issue because I think the questions were answered w/ Luke's replies.