Skip to contents

Accessing and working with LakeCat

The StreamCatTools package was designed to simplify the use of StreamCat data in R, leveraging the new API for StreamCat. We now have functionality in the StreamCat API for accessing and working with LakeCat data and have added functions in StreamCatTools to access LakeCata data in R using the API.

We can actually pull data into R from LakeCat by simply passing a URL to extract from json. We have to hard-wire parameters and are limited in the number of records returned through a GET request.

res <- jsonlite::fromJSON("https://api.epa.gov/StreamCat/lakes/metrics?name=pcturbmd2006&areaOfInterest=cat&comid=22538788")
res$items

List LakeCat API parameters

List LakeCat parameters: Get a list of available LakeCat values for certain parameters using the lc_get_params function (right now just metric names and areas of interest for this function) via the API

library(StreamCatTools)
region_params <- lc_get_params(param='areaOfInterest')

name_params <- lc_get_params(param='metric_names')

print(paste0('region parameters are: ', paste(region_params,collapse = ', ')))
#> [1] "region parameters are: cat, ws"
print(paste0('A selection of available LakrCat metrics include: ',paste(name_params[1:10],collapse = ', ')))
#> [1] "A selection of available LakrCat metrics include: agkffact, al2o3, bfi, canaldens, cao, cbnf, clay, coalminedens, compstrgth, damdens"

We can also see what metrics are available for what areas of interest and what years using the sc_get_params function (which returns a tibble of information about StreamCat metrics):

var_info <- lc_get_params(param='variable_info')
head(var_info)
#> # A tibble: 6 × 11
#>   category     metric aoi   year  short_description long_description units  dsid
#>   <chr>        <chr>  <chr> <chr> <chr>             <chr>            <chr> <dbl>
#> 1 Anthropogen… NABD_… Cat,… NA    NABD Dam Density  Density of geor… Coun…    33
#> 2 Anthropogen… NABD_… Cat,… NA    NABD NID Reservo… Volume all rese… Cubi…    33
#> 3 Anthropogen… NABD_… Cat,… NA    NABD Normal Rese… Volume all rese… Cubi…    33
#> 4 Natural      Preci… Cat,… NA    Surplus Precipit… This dataset re… Kilo…    75
#> 5 Natural      Rckde… Cat,… NA    Mean Bedrock Dep… Mean depth (cm)… Cent…    56
#> 6 Soils        agkff… Cat,… NA    Ag Soil Erodibil… Mean of STATSGO… Unit…    28
#> # ℹ 3 more variables: dataset <chr>, source_name <chr>, source_URL <chr>

Look up the display name or names for a metric using the lc_fullname function via the API

metric='pcthbwet2016'
fullname <- lc_fullname(metric)
fullname
#> NULL
metric='pctdecid2019,fert'
fullname <- lc_fullname(metric)
fullname
#> NULL

Get Waterbody COMIDs

In this example we use the lc_get_comid function to find COMIDs for a set of example lake locations we load into R.lc_get_comid is just a simple wrapper for get_waterbodies in the nhdplusTools R package. We can then use the COMIDs we derive for our lake locations to get LakeCat metrics for these lakes as we show in after this.

dd <- data.frame(x = c(-89.198,-114.125,-122.044),
                 y = c(45.502,47.877,43.730)) |> 
  sf::st_as_sf(coords = c('x', 'y'), crs = 4326)
    
comids <- lc_get_comid(dd)

Get data for COMIDs

In this example we access several variables, for several areas of interest, and for several COMIDs using the lc_get_data function. We’ll show using both the COMIDS we derived with lc_get_comid function in previous chunk as well as with known COMIDS for NHDPlus waterbodies. Loads data into a tibble we can view.

df <- lc_get_data(metric='pcturbmd2006,damdens', aoi='cat,ws', comid=comids)
knitr::kable(df)
comid damdenscat damdensws pcturbmd2006cat pcturbmd2006ws
23756298 0.0000000 0.0000000 0.0293228 0.0293228
120054065 0.0000000 0.0007270 0.4348181 0.1451495
167120863 0.0243986 0.0243986 0.2086078 0.2086078
df <- lc_get_data(metric='pcturbmd2006,damdens', aoi='cat,ws', comid='23783629,23794487,23812618')
knitr::kable(df)
comid damdenscat damdensws pcturbmd2006cat pcturbmd2006ws
23783629 0.0192097 0.0008875 0.2091942 0.0213267
23794487 0.0000000 0.2433268 0.1958225 0.8832762
23812618 0.0320852 0.0071455 0.0115507 0.0032155

Get data for county

In this example we access a couple variables at the watershed scale for the area of interest of a county (Benton County in this case) using the sc_get_data function.

df <- lc_get_data(metric='pctwdwet2006', aoi='ws', county='41003')
knitr::kable(head(df))
comid pctwdwet2006ws
23768945 0.1662971
23768987 0.0000000
23888156 0.4161465
23768895 0.1344990
23769007 1.0194538
23768947 0.5524862

Get all metrics for COMIDs or an Area of Interest

We can also get all LakeCat metrics for a set of COMIDs or an area of interest. Please do not request all metrics for conus in order not to overload requests to the server.

df <- lc_get_data(comid='23783629', aoi='ws', metric='all')
knitr::kable(head(df))
comid pcthighsev1984ws pctincvegresp1984ws pctlowsev1984ws pctmodsev1984ws pctnonprocmask1984ws pctundsev1984ws pcthighsev2014ws pctincvegresp2014ws pctlowsev2014ws pctmodsev2014ws pctnonprocmask2014ws pctundsev2014ws mtbs1984ws mtbs1985ws mtbs1986ws mtbs1987ws mtbs1988ws mtbs1989ws mtbs1990ws mtbs1991ws mtbs1992ws mtbs1993ws mtbs1994ws mtbs1995ws mtbs1996ws mtbs1997ws mtbs1998ws mtbs1999ws mtbs2000ws mtbs2001ws mtbs2002ws mtbs2003ws mtbs2004ws mtbs2005ws mtbs2006ws mtbs2007ws mtbs2008ws mtbs2009ws mtbs2010ws mtbs2011ws mtbs2012ws mtbs2013ws mtbs2014ws mtbs2015ws mtbs2016ws mtbs2017ws mtbs2018ws agkffactws kffactws huden2010ws popden2010ws hydrlcondws inorgnwetdep2008ws nh42008ws no32008ws sn2008ws pctalkintruvolws pctalluvcoastws pctcarbresidws pctcoastcrsws pctcolluvsedws pcteolcrsws pcteolfinews pctextruvolws pctglaclakecrsws pctglaclakefinews pctglactilclayws pctglactilcrsws pctglactilloamws pcthydricws pctnoncarbresidws pctsallakews pctsilicicws pctwaterws minedensws pcthighsev1985ws pctincvegresp1985ws pctlowsev1985ws pctmodsev1985ws pctnonprocmask1985ws pctundsev1985ws pcthighsev1986ws pctincvegresp1986ws pctlowsev1986ws pctmodsev1986ws pctnonprocmask1986ws pctundsev1986ws pcthighsev1987ws pctincvegresp1987ws pctlowsev1987ws pctmodsev1987ws pctnonprocmask1987ws pctundsev1987ws pcthighsev1988ws pctincvegresp1988ws pctlowsev1988ws pctmodsev1988ws pctnonprocmask1988ws pctundsev1988ws pcthighsev1989ws pctincvegresp1989ws pctlowsev1989ws pctmodsev1989ws pctnonprocmask1989ws pctundsev1989ws pcthighsev1990ws pctincvegresp1990ws pctlowsev1990ws pctmodsev1990ws pctnonprocmask1990ws pctundsev1990ws pcthighsev1991ws pctincvegresp1991ws pctlowsev1991ws pctmodsev1991ws pctnonprocmask1991ws pctundsev1991ws pcthighsev1992ws pctincvegresp1992ws pctlowsev1992ws pctmodsev1992ws pctnonprocmask1992ws pctundsev1992ws pcthighsev2013ws pctincvegresp2013ws pctlowsev2013ws pctmodsev2013ws pctnonprocmask2013ws pctundsev2013ws pcthighsev2015ws pctincvegresp2015ws pctlowsev2015ws pctmodsev2015ws pctnonprocmask2015ws pctundsev2015ws pcthighsev2016ws pctincvegresp2016ws pctlowsev2016ws pctmodsev2016ws pctnonprocmask2016ws pctundsev2016ws nws nabd_densws nabd_nidstorws nabd_nrmstorws nh42014ws nh42015ws nh42016ws nh42017ws nh42018ws no32014ws no32015ws no32016ws no32017ws no32018ws pctbl2001ws pctconif2001ws pctcrop2001ws pctdecid2001ws pctgrs2001ws pcthay2001ws pcthbwet2001ws pctice2001ws pctmxfst2001ws pctow2001ws pctshrb2001ws pcturbhi2001ws pcturblo2001ws pcturbmd2001ws pcturbop2001ws pctwdwet2001ws pctbl2004ws pctconif2004ws pctcrop2004ws pctdecid2004ws pctgrs2004ws pcthay2004ws pcthbwet2004ws pctice2004ws pctmxfst2004ws pctow2004ws pctshrb2004ws pcturbhi2004ws pcturblo2004ws pcturbmd2004ws pcturbop2004ws pctwdwet2004ws rdcrsws rddensws runoffws wetindexws damdensws damnidstorws damnrmstorws elevws pctfire2000ws pctfire2001ws pctfire2002ws pctfire2003ws pctfire2004ws pctfire2005ws pctfire2006ws pctfire2007ws pctfire2008ws pctfire2009ws pctfire2010ws pcthighsev2004ws pctincvegresp2004ws pctlowsev2004ws pctmodsev2004ws pctnonprocmask2004ws pctundsev2004ws pctnonagintrodmanagvegws pestic1997ws precip8110ws tmax8110ws tmean8110ws tmin8110ws precip2008ws precip2009ws tmean2008ws tmean2009ws cbnfws fertws manurews al2o3ws caows fe2o3ws k2ows mgows na2ows p2o5ws sio2ws sws bfiws canaldensws clayws sandws coalminedensws compstrgthws pcthighsev1993ws pctincvegresp1993ws pctlowsev1993ws pctmodsev1993ws pctnonprocmask1993ws pctundsev1993ws pcthighsev1994ws pctincvegresp1994ws pctlowsev1994ws pctmodsev1994ws pctnonprocmask1994ws pctundsev1994ws pcthighsev1995ws pctincvegresp1995ws pctlowsev1995ws pctmodsev1995ws pctnonprocmask1995ws pctundsev1995ws pcthighsev1996ws pctincvegresp1996ws pctlowsev1996ws pctmodsev1996ws pctnonprocmask1996ws pctundsev1996ws pcthighsev1997ws pctincvegresp1997ws pctlowsev1997ws pctmodsev1997ws pctnonprocmask1997ws pctundsev1997ws pcthighsev1998ws pctincvegresp1998ws pctlowsev1998ws pctmodsev1998ws pctnonprocmask1998ws pctundsev1998ws pcthighsev1999ws pctincvegresp1999ws pctlowsev1999ws pctmodsev1999ws pctnonprocmask1999ws pctundsev1999ws pcthighsev2000ws pctincvegresp2000ws pctlowsev2000ws pctmodsev2000ws pctnonprocmask2000ws pctundsev2000ws pcthighsev2001ws pctincvegresp2001ws pctlowsev2001ws pctmodsev2001ws pctnonprocmask2001ws pctundsev2001ws pcthighsev2002ws pctincvegresp2002ws pctlowsev2002ws pctmodsev2002ws pctnonprocmask2002ws pctundsev2002ws pcthighsev2003ws pctincvegresp2003ws pctlowsev2003ws pctmodsev2003ws pctnonprocmask2003ws pctundsev2003ws pcthighsev2005ws pctincvegresp2005ws pctlowsev2005ws pctmodsev2005ws pctnonprocmask2005ws pctundsev2005ws pcthighsev2006ws pctincvegresp2006ws pctlowsev2006ws pctmodsev2006ws pctnonprocmask2006ws pctundsev2006ws pcthighsev2007ws pctincvegresp2007ws pctlowsev2007ws pctmodsev2007ws pctnonprocmask2007ws pctundsev2007ws pcthighsev2008ws pctincvegresp2008ws pctlowsev2008ws pctmodsev2008ws pctnonprocmask2008ws pctundsev2008ws pcthighsev2009ws pctincvegresp2009ws pctlowsev2009ws pctmodsev2009ws pctnonprocmask2009ws pctundsev2009ws pcthighsev2010ws pctincvegresp2010ws pctlowsev2010ws pctmodsev2010ws pctnonprocmask2010ws pctundsev2010ws pcthighsev2011ws pctincvegresp2011ws pctlowsev2011ws pctmodsev2011ws pctnonprocmask2011ws pctundsev2011ws pcthighsev2012ws pctincvegresp2012ws pctlowsev2012ws pctmodsev2012ws pctnonprocmask2012ws pctundsev2012ws pctbl2006ws pctconif2006ws pctcrop2006ws pctdecid2006ws pctgrs2006ws pcthay2006ws pcthbwet2006ws pctice2006ws pctmxfst2006ws pctow2006ws pctshrb2006ws pcturbhi2006ws pcturblo2006ws pcturbmd2006ws pcturbop2006ws pctwdwet2006ws pctbl2008ws pctconif2008ws pctcrop2008ws pctdecid2008ws pctgrs2008ws pcthay2008ws pcthbwet2008ws pctice2008ws pctmxfst2008ws pctow2008ws pctshrb2008ws pcturbhi2008ws pcturblo2008ws pcturbmd2008ws pcturbop2008ws pctwdwet2008ws pctbl2011ws pctconif2011ws pctcrop2011ws pctdecid2011ws pctgrs2011ws pcthay2011ws pcthbwet2011ws pctice2011ws pctmxfst2011ws pctow2011ws pctshrb2011ws pcturbhi2011ws pcturblo2011ws pcturbmd2011ws pcturbop2011ws pctwdwet2011ws pctbl2013ws pctconif2013ws pctcrop2013ws pctdecid2013ws pctgrs2013ws pcthay2013ws pcthbwet2013ws pctice2013ws pctmxfst2013ws pctow2013ws pctshrb2013ws pcturbhi2013ws pcturblo2013ws pcturbmd2013ws pcturbop2013ws pctwdwet2013ws pctbl2016ws pctconif2016ws pctcrop2016ws pctdecid2016ws pctgrs2016ws pcthay2016ws pcthbwet2016ws pctice2016ws pctmxfst2016ws pctow2016ws pctshrb2016ws pcturbhi2016ws pcturblo2016ws pcturbmd2016ws pcturbop2016ws pctwdwet2016ws pctbl2019ws pctconif2019ws pctcrop2019ws pctdecid2019ws pctgrs2019ws pcthay2019ws pcthbwet2019ws pctice2019ws pctmxfst2019ws pctow2019ws pctshrb2019ws pcturbhi2019ws pcturblo2019ws pcturbmd2019ws pcturbop2019ws pctwdwet2019ws npdesdensws superfunddensws tridensws omws permws rckdepws wtdepws pctfrstloss2001ws pctfrstloss2002ws pctfrstloss2003ws pctfrstloss2004ws pctfrstloss2005ws pctfrstloss2006ws pctfrstloss2007ws pctfrstloss2008ws pctfrstloss2009ws pctfrstloss2010ws pctfrstloss2011ws pctfrstloss2012ws pctfrstloss2013ws pctimp2001ws pctimp2004ws pctimp2006ws pctimp2008ws pctimp2011ws pctimp2013ws pctimp2016ws pctimp2019ws pctimpslphigh2001ws pctimpslphigh2004ws pctimpslphigh2006ws pctimpslphigh2008ws pctimpslphigh2011ws pctimpslphigh2013ws pctimpslphigh2016ws pctimpslphigh2019ws pctimpslpmid2001ws pctimpslpmid2004ws pctimpslpmid2006ws pctimpslpmid2008ws pctimpslpmid2011ws pctimpslpmid2013ws pctimpslpmid2016ws pctimpslpmid2019ws slopews wdrw_ldws
23783629 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5.637929 0 0 1.875955 0 0 0 0.543233 0 0 0 0 0 0 5.052282 0 0 0.2356484 0.5842783 0.7493086 11.11531 1.774634 1.261661 3.530727 224.5275 0 3.954554 0 0 0 0 0 32.7197 0 0 0 3.905511 0 0 35.2591 0 22.73511 1.426017 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.072162 0.0008875 498097.5 169681.6 1.430049 1.180849 2.058496 1.312133 0.8989733 3.630198 2.070264 2.590723 2.977603 2.053362 1.855667 87.21521 0 0.0016774 0.2855548 0.0037541 0.0253205 0.2318785 0.0681338 1.221695 7.996732 0.0022365 0.0813132 0.0204481 0.8194423 0.1709335 1.850155 83.03445 0 0.0019969 4.492915 0.0008786 0.0239626 0.2318785 0.0682935 1.246856 7.953279 0.0023164 0.0817126 0.0209274 0.8198417 0.1705341 0.2351888 1.193335 1822.654 654.5787 0.0008875 498097.5 169681.6 1144.259 0 0 0.0536763 5.474744 0 0 2.353451 0 0 0.0010384 1.179521 0 0 0 0 0 0 0.3268504 0.0128735 2205.557 12.76105 7.264357 -4.038394 2187.239 1892.191 6.940714 7.336437 0 0 0 14.70179 7.044081 9.947896 1.322077 4.26524 2.812915 0.2878032 55.1177 0.0297734 68.62486 0 14.52621 41.75572 0 105.6155 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.249172 0.0240425 1.127921 2.534448 0.0010384 0.7627308 0 0 0 0 0 0 0.9273541 0.0018371 0.3492954 0.3876356 0.0001598 0.2492114 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.849676 81.53902 0 0.0027956 6.059192 0.0007988 0.0227645 0.2318785 0.069252 1.266505 7.860943 0.0023164 0.0821918 0.0213267 0.8208801 0.1704542 1.851114 81.57784 0 0.0032749 6.02205 0.0007988 0.0250809 0.2318785 0.0781981 1.263869 7.848243 0.0024761 0.0821918 0.0221255 0.8206405 0.1702146 1.848558 82.34393 0 0.0055913 6.412961 0.0007988 0.02564 0.2318785 0.0909781 1.239188 6.701231 0.0024761 0.0822717 0.0222054 0.822238 0.1700549 1.815569 82.85841 0 0.0055913 2.146972 0.0007988 0.0219658 0.2318785 0.0977676 1.255562 10.46313 0.0026359 0.0829107 0.022445 0.8217587 0.1726109 1.823796 82.53938 0 0.005112 0.7568998 0.0007988 0.0232438 0.2318785 0.0791566 1.214906 12.21983 0.0027158 0.0831504 0.0226048 0.8231965 0.1733297 1.560127 82.84179 0 0.0627022 3.367949 0.0007988 0.0228444 0.2318785 0.106474 1.500061 9.200375 0.0027956 0.0838692 0.0232438 0.8217587 0.1733297 0 0 0 2.803794 12.44819 120.0767 181.6733 0.0798755 1.324096 2.41136 1.726188 0.1529615 0.91074 0.2945008 0.0970487 0.0975279 0.1762053 0.2168619 0.1607893 0.0457686 0.1599099 0.1605912 0.1610697 0.161719 0.1618341 0.1625569 0.1629955 0.1668558 0.1436533 0.1439122 0.1439475 0.1442216 0.1442946 0.1448418 0.1451359 0.1494674 0.1457156 0.1461536 0.146346 0.1466604 0.146752 0.1474512 0.1477601 0.1518069 34.34347 0

Get NLCD data

In this example we access National Land Cover Dataset (NLCD) data for 2019, just at the catchment level for several COMIDs using the lc_nlcd function. Loads data into a tibble we can view.

df <- lc_nlcd(comid='23783629,23794487,23812618', year='2019', aoi='ws')
knitr::kable(df)
comid pctbl2019ws pctconif2019ws pctcrop2019ws pctdecid2019ws pctgrs2019ws pcthay2019ws pcthbwet2019ws pctice2019ws pctmxfst2019ws pctow2019ws pctshrb2019ws pcturbhi2019ws pcturblo2019ws pcturbmd2019ws pcturbop2019ws pctwdwet2019ws
23783629 1.5601274 82.8417931 0.00000 0.0627022 3.3679487 0.0007988 0.0228444 0.2318785 0.1064740 1.500061 9.2003748 0.0027956 0.0838692 0.0232438 0.8217587 0.1733297
23794487 0.0000000 0.4014892 31.64465 1.8176509 0.1167968 42.3096576 11.9132783 0.0000000 3.0878166 1.744653 0.2043945 0.2627929 3.6718009 1.0146726 1.6351559 0.1751953
23812618 0.0006431 84.9302559 0.00000 0.0623806 0.9241336 0.0000000 0.5498498 0.0000000 0.0032155 4.111976 5.2984945 0.0000000 0.0533772 0.0032155 1.8714187 2.1910391