Skip to content
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

Internal energy question #93

Closed
mcxmcx opened this issue Feb 21, 2018 · 10 comments
Closed

Internal energy question #93

mcxmcx opened this issue Feb 21, 2018 · 10 comments

Comments

@mcxmcx
Copy link

mcxmcx commented Feb 21, 2018

Hi

From the source code to calculate internal.energy in rLakeAnalyzer, I found there may exist some problems which is shown below:

From line 51-53 of internal.energy.R, it shows that:

if(max(bthD) > depths[numD]){ wtr[numD+1] = wtr[numD] depths[numD+1] = max(bthD)

From line 76-79 , it shows that:

layerD = seq(min(depths), max(depths), by=dz) layerP = stats::approx(depths, rhoL, layerD)$y layerT = stats::approx(depths,wtr, layerD)$y layerA = stats::approx(bthD, bthA, layerD)$y

It means that if the maximum depth of wtr is smaller the the maximum bthD, it will automatically add the maximum bthD as the maximum depth for calculation. However, when the water level is lower than the maximum bthD(which is very commom), the results of internal energy is wrong.

For example, if we write

bthA <- c(1000,900,864,820,200,10) bthD <- c(0,2.3,2.5,4.2,5.8,7) wtr1 <- c(28,28,27) depth1 <- c(0,1,2) internal.energy(wtr1, depth1, bthA, bthD)
the results is

internal.energy(wtr1, depth1, bthA, bthD)
[1] 545180514

However, if we write

bthA <- c(1000,900,864,820,200,10) bthD <- c(0,2.3,2.5,4.2,5.8,7) wtr2 <- c(28,28,27,27) depth2 <- c(0,1,2,7)

the result is also

internal.energy(wtr2, depth2, bthA, bthD)
[1] 545180514

When the water level decreases to 2m, the internal energy is the same as the level of 7m. So I suppose there should be some changes about the source code.

Best Cheers
Chenxi

@jordansread
Copy link
Member

Hi Chenxi - what answer are you expecting for the first value? Should it be higher/lower than the second one?

The code extends the deepest measurement down to the bottom to perform this calculation, so the two evaluations are equivalent in the code.

rLA will give you an answer, but the accuracy of that answer depends on the data you give it. If your provide data that are more resolved vertically, it will yield a more accurate result.

@mcxmcx
Copy link
Author

mcxmcx commented Feb 21, 2018

Dear Jordan:

Many thanks for the quick replo! If the maximum depth of wtr is smaller than the maximum bthD, the internal energy should be calculated based on the the real water level.

For this example, the first value should be smaller than the second one.

Best Cheers
Chenxi

@jordansread
Copy link
Member

If that is the case, then you should adjust the bthA and bthD to reflect it.

I don't think rLA supports time-varying lake levels in these calculations except by modifying the bthD and bthA vectors. Is that right @lawinslow ?

@mcxmcx
Copy link
Author

mcxmcx commented Feb 21, 2018

Dear Jordan:

I mean if we used
"ts.internal.energy(wtr, bathy, na.rm=FALSE)"
to calculate the internal energy at different time, the bathy should be also different over time.

If we can't change the bahty under differet time, there will be some problems when using the ts.schmidt.stability and ts.internal.energy (especially if the water level shows big changes during the calculating period).

Best Cheers
Chenxi

@jordansread
Copy link
Member

Correct. The ts. functions don't support changing water levels. So you would want to loop through time and modify bthA and bthD to reflect the water level at each timestep.

@mcxmcx
Copy link
Author

mcxmcx commented Feb 21, 2018

Dear Jordan:

Got it! Then I need to write a loop so as to use ts. functions to calculate internal energy at different time.

I just suppose if there is a ts.bathy function in rLakeAnalyzer, it will be very convenient for calculating the schmidt stability and internal energy over time.

Best Cheers
Chenxi

@jordansread
Copy link
Member

yes, but if you are using a loop w/ time, you don't need to use the ts. functions, and instead would use the regular ones, e.g., rLakeAnalyzer::internal.energy

@mcxmcx
Copy link
Author

mcxmcx commented Feb 21, 2018

Dear Jordan:

Got it ! Many thanks!

Chenxi

@lawinslow
Copy link
Member

Just a quick reference, there is an example of dealing with variable depths with rLA here
#62. Might be of help to you!

@jordansread
Copy link
Member

Seems these questions were answered. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants