#Tidyverselibrary(plyr); library(dplyr)library(tidyverse); library(lubridate);library(magrittr)#Time serieslibrary(zoo);library(xts);library(timetk);library(hydroTSM);library(dygraphs)#ggplot supportlibrary(ggmap);library(ggpmisc);library(ggrepel);library(ggsn)#spreadsheetslibrary(openxlsx);library(readxl)#paralel computinglibrary(parallel);library(pbapply)#general supportlibrary(here);library(glue);library(udunits2);library(usethis);library(matrixStats);library(pander);library(reshape2);library(Hydro)library(geosphere);library(nasapower)#data table supportlibrary(data.table);library(dtplyr);library(arrow)#raster supportlibrary(raster);library(sp);library(kgc)#These directories are implemented to organize the regional analysisuse_directory("data")use_directory("data/csv")use_directory("data/netcdf")use_directory("data/rds")use_directory("graphs")use_directory("reports")use_directory("scripts")use_directory("outputs")glue::glue("Work directory: {here()}")
Site Location
Show the code
Longitude=-162.85Latitude =68.07source(here::here("scripts","hydro_support.r"))#For more information#Get elevation from google mapsElevation=GM_elev(Longitude,Latitude,key_google = key_google)site.info<-data.frame(Location="Site",Longitude=Longitude,Latitude=Latitude,Elevation=Elevation) #Site in looped with variablessite.info_xy<-site.info %>% dplyr::rename(x="Longitude",y="Latitude",z="Elevation") %>% reshape2::melt(id.vars="Location")pandoc.table(site.info)
Location
Longitude
Latitude
Elevation
Site
-162.8
68.07
299.7
Show the code
#minimum year of information used, to be defined after seen the available infomin.ywi<-10
[1] “Stations N 1 : 15746983 / RED DOG MINE CLEAN WATER D NR KIVALINA AK” [1] “Stations N 2 : 15746988 / NF RED DOG C NR KIVALINA AK” [1] “Stations N 3 : 15746990 / RED DOG C AB MOUTH NR KIVALINA AK” [1] “Stations N 4 : 15746980 / IKALUKROK C AB RED DOG C NR KIVALINA AK” [1] “Stations N 5 : 1574699020 / IKALUKROK C 0.6 MI BL RED DOG C NR KIVALINA AK” [1] “Stations N 6 : 15746991 / IKALUKROK C BL RED DOG C NR KIVALINA AK” [1] “Stations N 7 : 15746900 / WULIK R AB FERRIC C NR KIVALINA AK” [1] “Stations N 8 : 15747000 / WULIK R BL TUTAK C NR KIVALINA AK” [1] “Stations N 9 : 15746000 / NOATAK R AT NOATAK AK” [1] “Stations N 10 : 15748000 / OGOTORUK C NR POINT HOPE AK” [1] “Stations N 11 : 15743000 / JUNE C NR KOTZEBUE AK” [1] “Stations N 12 : 15744500 / KOBUK R NR KIANA AK” [1] “Stations N 13 : 15744000 / KOBUK R AT AMBLER AK” [1] “Stations N 14 : 15716010 / HUMBOLT C NR SERPENTINE HOT SPRINGS NR NOME AK” [1] “Stations N 15 : 15743850 / DAHL C NR KOBUK AK” [1] “Stations N 16 : 15712000 / KUZITRIN R NR NOME AK” [1] “Stations N 17 : 15803000 / MEADE R AT ATKASUK AK” [1] “Stations N 18 : 15668200 / CRATER C NR NOME AK” [1] “Stations N 19 : 15635000 / ELDORADO C NR TELLER AK” [1] “Stations N 20 : 15583500 / ETTA C NR COUNCIL AK” [1] “Stations N 21 : 15625850 / STEWART R 0.1 MI BL BOULDER C MTH NR NOME AK” [1] “Stations N 22 : 15625900 / STEWART R 0.2 MI BL DURRANT C MTH NR NOME AK” [1] “Stations N 23 : 15621000 / SNAKE R NR NOME AK” [1] “Stations N 24 : 15798700 / NUNAVAK C NR BARROW AK” [1] “Stations N 25 : 15799000 / ESATKUAT C NR BARROW AK” [1] “Stations N 26 : 15799300 / ESATKUAT LAGOON OUTLET AT BARROW AK” [1] “Stations N 27 : 15564900 / KOYUKUK R AT HUGHES AK” [1] “Stations N 28 : 15830000 / MIGUAKIAK R NR TESHEKPUK LK NR LONELY AK” [1] “Stations N 29 : 15565200 / YUKON R NR KALTAG AK” [1] “Stations N 30 : 15875000 / COLVILLE R AT UMIAT AK”
Show the code
#selected the station with more than 20 valuesgauge_sel<-lapply(NAflow.db$annual.peak,FUN=function(x)length(x))>20flow_peak_tbl<-lapply(NAflow.db$annual.peak[gauge_sel],FUN=function(x){fortify.zoo(x)}) %>%do.call(rbind,.) %>%rownames_to_column(var="id") %>%mutate(id=str_split(id,"\\.",simplify = T) %>% .[,1] %>%str_remove_all("X")) %>%mutate(mon_day=month(Index)+day(Index)/31,yr=year(Index)) %>%rename(date="Index",peak="x")flow_peak_idx<-readNWISsite(siteNumbers =unique(flow_peak_tbl$id)) %>% dplyr::select(id="site_no",name="station_nm",lat="dec_lat_va",lon="dec_long_va",area_mi2="drain_area_va") %>%mutate(area_km2=ud.convert(area_mi2,"mi2","km2")) %>%mutate(dist_km=geosphere::distVincentyEllipsoid(p1=cbind(lon,lat),p2=cbind(Longitude,Latitude))/1000) %>%arrange(dist_km)