GLEON / rLakeAnalyzer

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

help troubleshooting errors for wtr.heat.map and similar functions using load.ts #89

Closed algavin closed 4 years ago

algavin commented 6 years ago

I was hoping to get some help with trouble-shooting error messages in rLakeAnalyzer. My dataset is structured similar to rLakeAnalyzer examples:

str(second.temp) 'data.frame': 4202 obs. of 12 variables: $ datetime: POSIXct, format: ... $ wtr_1.0 : num 16.9 16.9 16.9 16.8 17 ... $ wtr_2.0 : num 16.8 16.5 16.5 16 16.3 ... $ wtr_3.0 : num 15.7 15.6 15.6 15.7 15.6 ... $ wtr_4.0 : num 12.1 12.2 11.6 12.3 13.1 ... ..... etc...

and I am able to perform some functions, like ts.thermocline.depth() but am getting a variety of error messages for other functions. Any assistance with troubleshooting these error messages would be greatly appreciated. I am guessing it is one issue that is causing all of these errors. Thank you!

Here are some examples:

wtr.heat.map(second.temp) Error in if (any(diff(x) <= 0) || any(diff(y) <= 0)) stop("increasing 'x' and 'y' values expected") : missing value where TRUE/FALSE needed

wtr.plot.temp(second.temp) Error in if (tt < 1.1 * 60) { : missing value where TRUE/FALSE needed In addition: Warning message: In drop.datetime(data) : Unable to find a datetime column. Assuming no datetime column was supplied.

wtr.lineseries(second.temp, ylab = "Temperature C") Error in if (tt < 1.1 * 60) { : missing value where TRUE/FALSE needed

lawinslow commented 6 years ago

Hmm, could you include an *.Rdata file with your data frame? There is no reason what you show shouldn't work that I know of, so I find this behavior odd. It would be best if I can experiment with a subset of your data that exhibits this issue.

algavin commented 6 years ago

Thanks for getting back to me so quickly! As I went to send the data frame, I found some pesky NAs that were introduced on accident.

Thanks for offering to help- this is a great tool!

On Mon, Dec 18, 2017 at 2:01 PM, Luke Winslow notifications@github.com wrote:

Hmm, could you include an *.Rdata file with your data frame? There is no reason what you show shouldn't work that I know of, so I find this behavior odd. It would be best if I can experiment with a subset of your data that exhibits this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GLEON/rLakeAnalyzer/issues/89#issuecomment-352525266, or mute the thread https://github.com/notifications/unsubscribe-auth/AhDYUNGkIKydvlmq1Zr7y8GYsujxkWSpks5tBrZtgaJpZM4RF3ng .

-- ​ Amanda Gavin (she, her, hers) M.S. Student Ecology and Environmental Science University of Maine amanda.gavin@maine.edu

lawinslow commented 6 years ago

So were the NA values in the datetime column? I am pretty sure anywhere else they shouldn't have mattered.

algavin commented 6 years ago

There was one in the datetime column, which must have been the culprit. You are right- if I remove only the NA in the datetime column and leave the wtr NA values, it works fine.

On Mon, Dec 18, 2017 at 2:36 PM, Luke Winslow notifications@github.com wrote:

So were the NA values in the datetime column? I am pretty sure anywhere else they shouldn't have mattered.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GLEON/rLakeAnalyzer/issues/89#issuecomment-352535149, or mute the thread https://github.com/notifications/unsubscribe-auth/AhDYULofrPj_-xVRrs3Aps-WGoTVAgy8ks5tBr7ZgaJpZM4RF3ng .

-- ​ Amanda Gavin (she, her, hers) M.S. Student Ecology and Environmental Science University of Maine amanda.gavin@maine.edu

joshculpepper commented 4 years ago

I'm also having an issue with the wtr.heat.map function. I have loaded my data as above:

> str(wtr.hourlytemp) 'data.frame': 24400 obs. of 20 variables: $ datetime: POSIXct, format: "2016-10-22 19:00:00" "2016-10-22 20:00:00" ... $ wtr_1.0 : num 7.93 7.62 8.81 9.88 10.69 ... $ wtr_2.0 : num 7.81 7.75 10.76 11.57 11.76 ... $ wtr_4.0 : num 7.81 7.75 10.44 11.45 11.76 ... $ wtr_5.0 : num 7.5 7.5 10 11 11 11.5 11.5 11.5 11 11 ... $ wtr_6.0 : num 7.76 7.33 9.89 10.83 11.33 ... $ wtr_7.5 : num 7.77 7.39 8.9 10.22 10.91 ... $ wtr_9.0 : num 8.33 7.39 8.77 10.28 11.03 ... $ wtr_10.0: num 8.33 7.46 9.9 11.16 11.66 ...

I ensured that the dates were correctly sorted as per the example here.

But I am getting this error: `wtr.heat.map(wtr.hourlysorted)

Error in graphics::filled.contour(wtr.dates, y, wtr.mat, ylim = c(max(depths), : increasing 'x' and 'y' values expected`

There are no NAs in my dates. I am missing some data in the depths. Any ideas why I'm getting this error?

hdugan commented 4 years ago

Hey Josh, It probably has to do with your dates. A couple of things to try. 1) Make sure your wtr.hourlysorted is a data.frame and not a "tbl" (this messes up the one of the internal functions) 2) Make sure your dates are POSIXct or DATE format (and not characters or factors)

... although looking at what you've posted, you seem to have done this

hdugan commented 4 years ago

Also, feel free to send me a copy of your data (or a subset) to troubleshoot if no one else chimes in with something more helpful

joshculpepper commented 4 years ago

Also, feel free to send me a copy of your data (or a subset) to troubleshoot if no one else chimes in with something more helpful

Thank you for the quick response. How should I send the data to you?

hdugan commented 4 years ago

Just wrapping this up, the error was thrown by a duplicate time stamp

NHDES-Kirsten commented 4 years ago

Hello, I am encountering this error with rLakeAnalyzer: Error in if (any(diff(x) <= 0) || any(diff(y) <= 0)) stop("increasing 'x' and 'y' values expected") : missing value where TRUE/FALSE needed

The code I've used so far: head(AllRussell) datetime wtr_0.1 wtr_1 wtr_2 wtr_3 wtr_4 wtr_5 wtr_6 wtr_7 1 2018-10-12 00:01:00 NA 15.939 15.843 15.700 15.605 15.509 15.438 15.318 2 2018-10-12 01:01:00 NA 15.939 15.772 15.676 15.557 15.509 15.438 15.199 AllRussell$datetime <- as.POSIXct(AllRussell$datetime, format="%Y-%m-%d %H:%M:%S") wtr.heat.map(AllRussell)

I have combined two datafiles from two different time periods. There is a difference in the depths that were collected, namely that the first datafile has data collected every meter from 1 - 21 meters, with no surface temperature. The second datafile has data collected every meter from 0.1 - 20 meters, no data at 21 meters.

I can't use na.omit as it deletes every record due to the depth mismatch. I tried: AllRussell$datetime <- na.omit(AllRussell$datetime) but I get the error: Error in $<-.data.frame(*tmp*, datetime, value = c(1539316860, 1539320460, : replacement has 8375 rows, data has 8376 I also can't visually identify any NAs or duplicate readings in the datetime column. I would appreciate any suggestions! Thank you.

hdugan commented 4 years ago

That last error makes me think you have a an NA value in your datetime column. You can check for duplicate timestamps using the following:

library(dplyr)
AllRussell %>% group_by(datetime) %>% 
  filter(n()>1)

You can check for NA timestamps using:

library(dplyr)
AllRussell %>% filter(is.na(datetime))

Also, if you're just interested in heat mapping, the plot_var_df function in the glmtools R package is more recent. Install using devtools::install_github('USGS-R/glmtools',ref = 'ggplot_overhaul')

NHDES-Kirsten commented 4 years ago

Thank you so much! There was an NA in the datetime column, although I can’t seem to find it when looking at the csv file. I was able to remove it and now the heat map is working.

I really appreciate the response; this is my first time working with rLakeAnalyzer.

Take care,

Kirsten Nelson, Aquatic Ecologist Watershed Management Bureau Water Division, NH Department of Environmental Services 29 Hazen Dr. P.O. Box 95 Concord, NH 03302-0095 Phone: (603) 271-1152 Email: Kirsten.Nelson@des.nh.govmailto:Kirsten.Nelson@des.nh.gov NH Lake Mapperhttp://nhdes.maps.arcgis.com/apps/webappviewer/index.html?id=1f45dc20877b4b959239b8a4a60ef540

[Twitter Image]http://www.twitter.com/nhdesFollow us on Twitter!http://www.twitter.com/nhdes [Facebook Image]https://www.facebook.com/NHEnvironmentalServices Like us on Facebook!https://www.facebook.com/NHEnvironmentalServices

From: hdugan notifications@github.com Sent: Thursday, June 4, 2020 5:09 PM To: GLEON/rLakeAnalyzer rLakeAnalyzer@noreply.github.com Cc: Nelson, Kirsten Kirsten.Nelson@des.nh.gov; Comment comment@noreply.github.com Subject: Re: [GLEON/rLakeAnalyzer] help troubleshooting errors for wtr.heat.map and similar functions using load.ts (#89)

EXTERNAL: Do not open attachments or click on links unless you recognize and trust the sender.


That last error makes me think you have a an NA value in your datetime column. You can check for duplicate timestamps using the following:

library(dplyr)

AllRussell %>% group_by(datetime) %>%

filter(n()>1)

You can check for NA timestamps using:

library(dplyr)

AllRussell %>% filter(is.na(datetime))

Also, if you're just interested in heat mapping, the plot_var_df function in the glmtools R package is more recent. Install using devtools::install_github('USGS-R/glmtools',ref = 'ggplot_overhaul')

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/GLEON/rLakeAnalyzer/issues/89*issuecomment-639117186__;Iw!!Oai6dtTQULp8Sw!BsN6lQKM0mNez0yAz4qduw7162sFvnyHuUHR6LKZNIJyFK_W-DFibieljf1EQ0HOvw1lKg$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AP2332WGGVL7IIOJKGJDELDRVAENHANCNFSM4EIXPHQA__;!!Oai6dtTQULp8Sw!BsN6lQKM0mNez0yAz4qduw7162sFvnyHuUHR6LKZNIJyFK_W-DFibieljf1EQ0GaOi_bPA$.