This package is designed to:
- Process data through the online functional flows calculator
- Transform that data and return plots of the Dimensionless Reference Hydrograph (DRH) as well as boxplots showing the observed versus predicted percentile values for each metric.
- Have shortcut functions that handle all of this, while exposing the internals so you can access useful intermediate products, such as the functional flows calculator results as an R dataframe, in case you need to do more complex analysis.
It is meant to be used with simply a gage ID, or with a timeseries dataframe of flows along with either a stream segment COMID or longitude and latitude (it will look up the COMID for you). See Setup and Examples below for more.
We have moved all documentation and examples to our documentation website. A PDF manual is also available.
- If you don't already have
devtools
installed, runinstall.packages('devtools')
in your R console, or install the package any way you prefer. - Install this package with
devtools::install_github('ceff-tech/ffc_api_client/ffcAPIClient')
. If you get an error on this installation step, make sure you are using the latest version of the devtools package. - Now we need to retrieve your token. In Firefox or Chrome, log into https://eflows.ucdavis.edu. Once logged in, make sure you are on your user profile page at https://eflows.ucdavis.edu/profile and then press F12 on your keyboard to bring up the Inspector, then switch to the Console tab.
- In the console, type
localStorage.getItem('ff_jwt')
- you may need to type it in yourself instead of pasting (or follow Firefox's instructions to enable pasting - it will tell you how after you try to paste). Hit Enter to send the command. - Your browser will place text on the line below the command you typed - this is your "token". Save this value and copy it to your clipboard and we'll use it below. This value should stay private - if other people knew the value, they could use it to access your account on eflows.ucdavis.edu!
That's it. You can now run data through the online FFC using this package and process the results.
- [Bugfix]
get_predicted_flow_metrics()
no longer returns observed metrics, specifically returns only modeled or inferred.
- [Bugfix] Log messages weren't going to the screen when running CEFF steps with an output folder. They once again go to both the screen and the output file. We now have a known issue where when it prints the FFC percentiles to the console, they don't come out appropriately (due to our logging method) - use the output CSV instead in the meantime.
- [Bugfix] Internal stream class data occasionally had multiple records, which would cause bad parameters to be sent to the FFC and a failure in the package. Now checks if there's more than one stream class record and uses the first one.
- [Enhancement] The package now checks to make sure it received a valid COMID from web services, which helps when the web service is down. It prints a warning if the lookup failed.
- [Enhancement] The package now checks to make sure it obtained at least 24 predicted metric records. If it didn't but received some, then it prints a warning. If it received no records, it prints an error about the COMID
- [Enhancement] Added a new
$get_comid_online
(default TRUE) flag to FFCProcessor objects. The web service that we use to look up COMIDs for gages has been spotty recently, and we returned the option to do a lookup locally with spatial data. It will still download a large amount of spatial data for NHD segments the first time it runs with the flag set to FALSE, but then future lookups will be much faster. It uses the nhdR package, which is not included as a package requirement, and instead is installed only if you setffc$get_comid_online = FALSE
.
- [Update] Included updated data for peak flow metric predictions into package data. To support this,
we are temporarily changing the FFCProcessor object to use offline metrics instead of data
from the TNC API. If you wish to use the API again, set
ffc$predicted_percentiles_online <- TRUE
. We will revert it to using online data in the future once the API is updated
- [Enhancement] New code that fills NA values in the 10th percentile column of predicted metrics from the
TNC API if the 25th percentile column is 0. A warning will be raised if NA values are found
in the 10th percentile column. Can be turned off by setting
ffc$predicted_percentiles_fill_na_p10
to FALSE.
- [Bugfix] Previously, providing a timeseries with a date field that was not named "date" (case sensitive)
would fail when building the data frame to send to the FFC. This has been fixed, and any date
field name should be usable, so long as it is provided as a parameter, or set on the
ffc
object before runningffc$set_up
.
- [Update] Fixes for new versions of the eflows API launched recently. Everyone using this package will need to upgrade to this version or newer to keep using the package.
- Added function
clean_account
to remove all current runs from the online FFC. Helps with broken accounts after recent FFC update. To use, just callclean_account(token)
after setting your token value into the variable namedtoken
- [Change] Data sent to the FFC is now filtered according to CEFF Tech Team determined rules - water years
are dropped if they have more than 7 missing days or more than 2 consecutive missing days (by default).
See the documentation for the function
filter_timeseries
for more info. It applies to both automatically retrieved gage data and user-provided timeseries. It can be disabled by setting timeseries_enable_filtering to FALSe on the FFCProcessor object, but you're much better off just disabling it by filling gaps in your data yourself if you need to keep all water years. - [Enhancement] ffcAPIClient now logs both to the console and to a log file in the output folder, including the version of the package and any log messages (some R warnings and errors may not show up in the file yet)
- [Change] The package now stops running if you have fewer than 10 years of data after the filters implemented
in this version have run. It warns you, but still runs if you have fewer than 15 years of data. These
apply whether the data source is gage data or a provided timeseries. To change this behavior,
change the values of
fail_years_data
andwarn_years_data
on the FFCProcessor object - [Enhancement] You can now pass minimum and maximum dates for gage data retrieval. Set the values of
gage_start_date
andgage_end_date
on the FFCProcessor object.
- [Bugfix] Fixed issue preventing export of R6 Classes - FFCProcessor and USGSGage should now be available for use as the documentation describes
- [Enhancement] Code available for three steps of CEFF process - working on documentation for it still
- [Bugfix] Adjusted to change in FFM API from flows.codefornature.org
- [Enhancement] Code available to support first step of CEFF process
- [Enhancement] New function
force_consistent_naming
sets option to convert peak magnitude metrics to use same name format as other magnitude metrics.Peak_2
becomesPeak_Mag_2
, etc. Defaults to off to remain aligned with CEFF, but if you need metric names to follow a pattern, that will help. See documentation for usage. - [Change] Predicted flow metrics now use a character instead of a factor in the
metric
column.
- [Enhancement] ffc_results dataframe now filters out non-metrics (things starting with __ or ending with _Julian)
- [Bugfix] Handled a condition where the predicted flow metric API returns duplicate values for some metrics
- [Bugfix] Fixed an error where predicted Spring Duration metrics came through as SP_Du
- [Bugfix] Fixed error preventing
evaluate_alteration
from running with warnings aboutdate_format_string
.
- [Enhancement] Updated plotting to facet each metric with a free Y axis so that all boxplots can be clearly seen. Other minor enhancements to plotting, like titles and X axis labels as well.
- [Enhancement]
evaluate_alteration
family of functions now also returnspredicted_wyt_percentiles
in addition to thepredicted_percentiles
. The WYT form includes awyt
column that includes the water year type of the prediction - [Change] Using TNC's online API to pull predicted flow metrics instead of internal data by default
- [Change] Under the hood, the code behaves differently - most processing is now being handled in the FFCProcessor class, but more will be moved there
- [Change] Updated the rules used to determine alteration to match new rules for CEFF Appendix F - specifically, we now always check that >=50% of observations are within the i80r before declaring something unaltered.
- [Enhancement]
evaluate_alteration
now supports parameter to control plotting (similar toevaluate_gage_alteration
) and documentation has been added for the function.
- [Enhancement] Added the ability to pull predicted metrics from TNC's predicted metrics API instead of from internal data. To
use it, set
online=TRUE
when callingget_predicted_flow_metrics
. It includes one small difference - in the source field, values marked asobs
in the offline data show up asinferred
.
- [Change] No longer look up gage COMIDs by default due to error-prone nature of lookup near stream junctions. Use
force_comid_lookup
parameter toevaluate_gage_alteration
to enable previous lookup behavior. - [Enhancement] Added an automatic lookup that corrects bad data from comid lookups and returns the correct COMID. Only used for Jones Bar gage right now, but structure is there for if others are found.
- [Breaking Change] Where found, column names have been fully lowercased for consistency, including Metric -> metric and COMID -> comid
- [Breaking Change] Parameter
com_id
toget_predicted_flow_metrics
was renamedcomid
- [Enhancement] observed percentiles and predictions both include a
result_type
field, with observed FFC results containing the value "observed" and prediction percentiles fields containing the value "predicted" to allow for merging of the data frames in some contexts - [Enhancement]
evaluate_gage_alteration
now attaches a fieldgage_id
topredicted_percentiles
,observed_percentiles
, andalteration
data frames. - [Enhancement] observed percentiles now include a comid field to allow for merging and accessing the comid in other contexts
- [Enhancement]
evaluate_alteration
andevaluate_gage_alteration
now includes a fifth keyalteration
with the assessed flow alteration scores in a data frame
- [Breaking Change] Results from
evaluate_alteration
andevaluate_gage_alteration
now use the list keyffc_percentiles
instead of simplypercentiles
to be clear that the percentiles are from the observed FFC results. - [Change] Changed quantile processing type to the default of type 7 so that observed FFC data are processed into percentiles the same way that the predicted flow metrics were calculated to minimize resulting error.
- [Enhancement]
evaluate_alteration
andevaluate_gage_alteration
now includes a fourth keypredicted_percentiles
with the predicted flow metric percentile values so they don't need to be looked up separately.
- [Enhancement] Added
annual
parameter toassess_alteration
that runs a year over year analysis.
- [Enhancement] New parameter
plot
(boolean) toevaluate_gage_alteration
controls whether the function produces plots or not
- [Enhancement] New
assess_alteration
function returns a data frame with alteration results - documentation forthcoming. - [Change] Warning when can't determine stream segment's hydrogeomorphic type has been downgraded to a print statement.
- [Breaking Change] The client now detects and sends the appropriate parameters to the FFC online for the stream class that
it detects based on the COMID. If you are using low-level functions such as
get_ffc_results_for_df
, then you must provide an argumentcomid
- check the documentation for which functions need it. Further,process-data
now requires that the stream parameters be provided to it. I recommend moving to something likeget_ffc_results_for_df
as process_data may soon be moved to be internal only.
- [Enhancement] New code to support sending the correct stream class parameters to the FFC - includes the ability to identify stream classes by COMID, but not yet send the parameters
- [Change] Data loading code made more generic, and potentially faster - multiple calls to get predicted flow metrics should not result in reloading the dataset.
- [Breaking Change] List item
$ffc_results_df
returned fromevaluate_alteration
functions changed to$ffc_results
for consistency with FFCProcessor object and allowing for more flexibility in the future. - [Enhancement] Basic alteration assessment capabilities included. Require more testing before use
- [Documentation] Reworking documentation to make best workflows clearer
- [Enhancement] Can now provide a time format string to
evaluate_alteration
- it will use that to read the values in the time field and reformat them to send to the FFC as needed. - [Bugfix] FFC results no longer fail to transform if one flow metric is entirely NULL