HARPgroup / r-dh-ecohydro

A set of R scripts for generating Ecological Limit Functions (ELF), storing the modeled output with REST in drupal VAHydro (dH), and a set of scripts for querying and analyzing processed ELF data
0 stars 1 forks source link

Quantreg only subsetting by drainage area #9

Closed passeroe closed 6 years ago

passeroe commented 6 years ago

In QR data is always subsetted by DA regardless of the x_metric of interest. Data with DA values larger than ghi in sqkm is removed. The breakpoint value, ghi, is stored in sqmi or cfs even though the breakpoint on the plot is in sqkm. Why don’t we subset the data by a mean flow threshold if the x_metric of interest is mean flow? Also, is it necessary to convert to and from sqkm?

Snippet from the QR script where data is subsetted only by drainage area.

  #Convert ghi input from sqmi to sqkm, and remove datapoints greater than the ghi DA threashold
  data<-data[!(data$drainage_area > (ghi * 2.58999)),]
  subset_n <- length(data$metric_value)
  # do not convert ghi here since we want to store breakpoint as sqmi not sqkm
  stat_quantreg_bkpt <- ghi

Snippet from PWIT script where ghi and glo are only converted to sqkm if the x_metric is DA. Breakpoint values are found using whatever the x_metric of interest is rather than using DA by default.

  #Statement to convert PWIT breakpoint boundaries for plotting against drainage area 
    #[convert cfs (which is roughly equal to mi^2) to km^2]
  # store glo and ghi before converting for use in admincode/properties
  u_input_lo = glo;
  u_input_hi = ghi;
  if(x_metric == "nhdp_drainage_sqkm") {
    glo <- glo * 2.58999
    ghi <- ghi * 2.58999
  }
jdkleiner commented 6 years ago

I have imported a drainage area property in mi^2 for every EDAS station feature, and I'm in the process of updating our ELF codes to handle this new property (thus eliminating the use of sqkm all together, and the need for unit conversions between sqkm and sqmi)

This should tidy things up a bit, will let you know when these updates have been pushed.

passeroe commented 6 years ago

Since the quantreg only subsets by drainage area, we should be making our ghi guesses in sqmi. If we say that the PWIT is looking for a better ELF breakpoint below the ghi that the quantreg used, should the PWIT still have the option to search for breakpoints in cfs too?

For example: ghi = 500; glo = 1 Quantreg builds ELF below 500 sqmi PWIT looks for breakpoints below 500 sqmi or 500 cfs depending on whether our x_values are DA or flow.

passeroe commented 6 years ago

Should we be using something like this:

`

#set initial guess range based on DA
breaks <- upper_points[which(upper_points$drainage_area_sqmi >= glo & upper_points$drainage_area_sqmi <= ghi)]
#build list of breakpoints
breaks <- breaks$x_value

Instead of our current breakpoint guess range: ` ```

set initial guess range

breaks <- x[which(x >= glo & x <= ghi)] as.numeric(breaks)

print(breaks)

jdkleiner commented 6 years ago

I think we want to leave the piecewise method as it is (subsetting on drainage area OR flow depending on what you're plotting).

We'll keep the basic quantreg function as ALWAYS subsetting on drainage area for now - let's just make sure we're clear about this difference between the 2 methods in our documentation.