KevinSee / PITcleanr

Compress PIT tag capture histories for use in various analyses
https://kevinsee.github.io/PITcleanr/
Creative Commons Attribution 4.0 International
8 stars 6 forks source link

alt version of dam observations query function #46

Closed tbuehrens closed 5 months ago

tbuehrens commented 6 months ago

Hey @KevinSee,

I was playing around with this package yesterday to see how much I could use for a Wind R. project. I noticed your function queryObsDART only works on priest rapids or lower granite. I whipped up the following function that uses a different DART url (not the custom nez perce one you guys use). Anyway this function also has the ability to supply a list of species and years and will loop through them; no loop for run and rear since options for those in the dart API include "all" (via Null). Anyway let me know if you want me to submit a pull request. I did shamelessly poach the spp_code lookup approach ya'll used (see below).

get_unique_adult_dam_observations<-function(years, 
                                            species, #Chinook, Steelhead, Coho, Sockeye
                                            run, #1= spring, 2=summer, 3=fall, 4=winter 5=unknown, Null=all
                                            rear, #W or H or Null = all
                                            dam #B2A = BON
                                            ){
  spp_code = tibble(spp_nm = c('Chinook', 'Coho', 'Steelhead', 'Sockeye'),
                  spp_code = 1:4)  %>%
  filter(spp_nm %in% species) %>%
  pull(spp_code)

  results<-tibble()
  baseurl<-"https://www.cbr.washington.edu/dart/cs/php/rpt/pitall_obs_de.php?sc=1&queryName=pitadult_obs_de&outputFormat=csv&year="
  for(y in years){
    for(s in spp_code){
      fullurl=paste0(baseurl,y,"&proj=",dam,"&species=",s,"&run=",run,"&rear_type=",rear,"&span=no&startdate=1%2F1&enddate=12%2F31&syear=",y,"&eyear=",y,"&reltype=alpha&relloc=251&summary=no")
    dat<-readr::read_csv(fullurl)%>%
      filter(!is.na(`Tag ID`))
    results <- bind_rows(results, dat)
    }
  }
  return(results)
}
KevinSee commented 5 months ago

@tbuehrens ,

I think you'll find a very similar function already in the STADEM package. Check out the queryPITtagObs function. However, I think your suggestion could potentially improve that function, which currently only works for Lower Granite, by expanding it to more sites. I'll add an issue to the STADEM repo to investigate.