baro review

Author

Victor Munoz

Site Gauges

gauge_loc<-tibble::tribble(
        ~Gauge,        ~Lat,        ~Lon,
         "G01", 47.10191667,     75.4545,
         "G02", 47.10069444, 75.45394444,
         "G03", 46.79672222, 75.48727778,
         "G04",      46.796, 75.48763889,
         "G05", 46.98530556, 75.10533333
        )

pander::pandoc.table(gauge_loc)
Gauge Lat Lon
G01 47.1 75.45
G02 47.1 75.45
G03 46.8 75.49
G04 46.8 75.49
G05 46.99 75.11

Capturing hourly records from MERRA2

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(zoo)

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric
source(here::here("scripts","nc_read_files.r"))

PS

reanalysis_fn(file = here::here("data","MERRA","MERRA2_hly_ps.nc"),
              par = "PS",fun = mean,yrs = 2000:2022)
terra 1.7.46

Attaching package: 'terra'
The following object is masked from 'package:zoo':

    time<-
The following object is masked from 'package:tidyr':

    extract
daily raster for MERRA2              : merra2_ras
mean annual raster for MERRA2        : merra2_ma_ras
mean annual TABLE for MERRA2         : merra2_ma_tbl

gauge_ps_z<-pbapply::pblapply(1:nrow(gauge_loc),FUN=function(x){

        ps_z<-nc2z_fn(Longitude = gauge_loc[x,3] %>% pull(),
                      Latitude = gauge_loc[x,2] %>% pull(),
                      source = "MERRA2") %>% 
                udunits2::ud.convert(.,"Pa","kPa")*0.102  #conversion from Kpa to meters of head
        
}) %>% do.call(merge,.)

names(gauge_ps_z)<-gauge_loc$Gauge

plot(gauge_ps_z,main="Hourly records for PS from MERRA2[m Head]")

Air Temperature

reanalysis_fn(file = here::here("data","MERRA","MERRA2_hly_t2m.nc"),
              par = "T2M",
              fun = mean,yrs = 2000:2022)
daily raster for MERRA2              : merra2_ras
mean annual raster for MERRA2        : merra2_ma_ras
mean annual TABLE for MERRA2         : merra2_ma_tbl

gauge_t2m_z<-pbapply::pblapply(1:nrow(gauge_loc),FUN=function(x){

        ps_z<-nc2z_fn(Longitude = gauge_loc[x,3] %>% pull(),
                      Latitude = gauge_loc[x,2] %>% pull(),
                      source = "MERRA2") %>% 
                udunits2::ud.convert(.,"K","degC")
        
}) %>% do.call(merge,.)

names(gauge_t2m_z)<-gauge_loc$Gauge

plot(gauge_t2m_z,main="Hourly records for Air Temperature from MERRA2[degC]")

Comparison of results

library(readr)
library(hydroTSM)
Loading required package: xts

######################### Warning from 'xts' package ##########################
#                                                                             #
# The dplyr lag() function breaks how base R's lag() function is supposed to  #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
# source() into this session won't work correctly.                            #
#                                                                             #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
# dplyr from breaking base R's lag() function.                                #
#                                                                             #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#                                                                             #
###############################################################################

Attaching package: 'xts'
The following objects are masked from 'package:dplyr':

    first, last
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
     (status 2 uses the sf package in place of rgdal)
Please note that 'maptools' will be retired during October 2023,
plan transition at your earliest convenience (see
https://r-spatial.org/r/2023/05/15/evolution4.html and earlier blogs
for guidance);some functionality will be moved to 'sp'.
 Checking rgeos availability: FALSE

Attaching package: 'hydroTSM'
The following object is masked from 'package:terra':

    extract
The following object is masked from 'package:tidyr':

    extract
baro_tbl <- read_csv(here::here("data","csv","1037A_Baro.csv"), 
    col_types = cols(Date = col_date(format = "%Y-%m-%d"), 
        Time = col_time(format = "%H:%M:%S")), 
    skip = 10)

baro_ps_z<-zoo(baro_tbl$LEVEL,ymd_hms(paste0(baro_tbl$Date," ",baro_tbl$Time)))

plot(baro_ps_z,main="Barometric Pressure measured at Barologger")

baro_t2m_z<-zoo(baro_tbl$TEMPERATURE,ymd_hms(paste0(baro_tbl$Date," ",baro_tbl$Time)))

plot(baro_t2m_z,main="Air Temperature measured at Barologger")

PS

merge(baro_ps_z-4.25,
      "MERRA2@G01"=gauge_ps_z$G01) %>%
        na.approx() %>% 
        dygraphs::dygraph(ylab = "m of Head")
merge("baro-4.25m"=baro_ps_z-4.25,
      "MERRA2"=gauge_ps_z) %>% 
        subdaily2daily(FUN=mean) %>% 
        as.data.frame() %>% 
        dplyr::filter(complete.cases(.)) %>% 
        hydroTSM::hydropairs()

Air Temperature

merge(baro_t2m_z,
      "MERRA2@G01"=gauge_t2m_z$G01) %>%
        na.approx() %>% 
        dygraphs::dygraph(ylab = "m of Head")
merge("air_temp_baro"=baro_t2m_z,
      "MERRA2"=gauge_t2m_z) %>% 
        subdaily2daily(FUN=mean) %>% 
        as.data.frame() %>% 
        dplyr::filter(complete.cases(.)) %>% 
        hydroTSM::hydropairs()