DOI-USGS / EGRET

An R-package for the analysis of long-term changes in water quality and streamflow, including the water-quality method Weighted Regressions on Time, Discharge, and Season (WRTDS). https://doi-usgs.github.io/EGRET/

Home Page:http://doi-usgs.github.io/EGRET/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add example of converting user data to EGRET format

woodwards opened this issue · comments

From the documentation I can only see examples using existing NWIS files or existing Daily and INFO dataframes.

Many users like myself will have data in different file formats or in dataframes in their session. Can you provide some guidance on how to convert such data into the right format for Daily and INFO? I can't find any information on the required columns in these dataframes.

Can you provide a vignette that constructs minimal Daily and INFO from scratch?

Thank you Robert.

Ok I see the instructions now. In my case the data is in a dataframe in the R environment, rather than in a file. I suppose I could write it to a text file and then read it back in. I have two solutes.

> glimpse(tdata)
Observations: 5,479
Variables: 9
$ shortname <chr> "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", "Ta", ...
$ TF        <dbl> 4.54200, 4.36800, 4.19800, 4.36667, 4.40000, 4.03000, 4.06000, 3.84500, ...
$ TP        <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ TN        <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ x         <int> 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 38...
$ xdate     <date> 2002-01-01, 2002-01-02, 2002-01-03, 2002-01-04, 2002-01-05, 2002-01-06,...
$ day       <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2...
$ month     <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
$ year      <dbl> 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, ...
>

It occurred to me after I wrote this that the INFO and Daily dataframes might be described in the written documentation. Thanks for your help.

The readDataFromFile function doesn't seem to work. It doesn't normalise the column names or add the LogQ column, and it returns Q as chr. Also it doesn't add the JulianMonthDayDecYearMonthSeq expected by mergeReport.

  # convert my data to EGRET format
  Daily <- data.frame(Date=tdata$xdate, Q=tdata$TF, LogQ=log(tdata$TF))
  write_csv(Daily, "temp_egret_daily.csv")
  Daily <- readDataFromFile(getwd(), "temp_egret_daily.csv")
  Daily$Q <- as.numeric(Daily$Q)
  Sample <- data.frame(Date=tdata$xdate, Remark="", TP=tdata$TP) %>% drop_na()
  write_csv(Sample, "temp_egret_sample.csv")
  Sample <- readUserSample(getwd(), "temp_egret_sample.csv")
  INFO <- data.frame(param.units="mg/L",
                     shortName=tdata$shortname[1], 
                     paramShortName="TP",
                     drainSqKm=1,
                     constitAbbrev="TP",
                     staAbbrev=tdata$shortname[1],
                     paStart=1,
                     paLong=60,
                     queryTime=Sys.time()
                     stringsAsFactors=FALSE)
  write_csv(INFO, "temp_egret_info.csv")
  INFO <- readUserInfo(getwd(), "temp_egret_info.csv", interactive=FALSE)
  edata <- mergeReport(INFO, Daily, Sample)


 Discharge Record is 5479 days long, which is 15 years
 First day of the discharge record is 2002-01-01 and last day is 2016-12-31
 The water quality record has 180 samples
 The first sample is from 2002-01-30 and the last sample is from 2016-12-15
 Discharge: Minimum, mean and maximum 1.82 4.37 52.4
 Concentration: Minimum, mean and maximum 0.032 0.066 0.79
 Percentage of the sample values that are censored is 0 %
Daily data frame expecting columns: JulianMonthDayDecYearMonthSeq

There's a mistake in the user manual page 9

Daily <-readDataFromFile(filePath,fileName,
separator="\t")

should say

Daily <-readUserDaily(filePath,fileName,
separator="\t")

Is there any user forum for this software? I have a lot of questions.

Thanks Robert

And just to mention again that the documentation incorrectly uses readDataFromFile on page 9

I have got it working now.

Simon