library(ncdf4)
library(lubridate)
library(nctools)
library(multiApply)
devtools::load_all()
file_rh = "data-raw/CN05.1_Rhu_1961_2017_daily_025x025.nc"
nc_info(file_rh)
lon <- ncread(file_rh, "lon")
lat <- ncread(file_rh, "lat")
date <- nc_date(file_rh)
ind = which(year(date) <= 2016)
date %<>% .[ind]
dims <- nctools::ncdim_def_lonlat(lon, lat, date)
select_year <- function(x) x$data[[1]][,,ind]
rhu_arr <- ncread(file_rh) %>% select_year()
tmin_arr <- ncread("data-raw/CN05.1_Tmin_1961_2018_daily_025x025.nc") %>% select_year()
tmean_arr <- ncread("data-raw/CN05.1_Tavg_1961_2018_daily_025x025.nc") %>% select_year()
tmax_arr <- ncread("data-raw/CN05.1_Tmax_1961_2018_daily_025x025.nc") %>% select_year()
HI_Tmin <- heat_index_vec(tmin_arr, rhu_arr)
ncwrite(list(HI_Tmin = HI_Tmin), "HI_Tmin.nc", dims = dims)
HI_Tavg <- heat_index_vec(tmean_arr, rhu_arr)
ncwrite(list(HI_Tavg = HI_Tavg), "HI_Tavg.nc", dims = dims)
HI_Tmax <- heat_index_vec(tmax_arr, rhu_arr)
ncwrite(list(HI_Tmax = HI_Tmax), "HI_Tmax.nc", dims = dims)
# I_grid = grid_d025$id %>% which.notna()
# t = tmin_arr %>% array_3dTo2d(I_grid) %>% .[1:1000, ]
# rh = rhu_arr %>% array_3dTo2d(I_grid) %>% .[1:1000, ]
# julia_setup()
# temp <- heat_index_julia(tmin_arr, rhu_arr)
# tmax_arr_HI <- map2_dbl(tmax_arr, rhu_arr, heat_index)
# dt <- data.table(tmax_arr, rhu_arr)
# save(tmax_arr_HI, file = "OUTPUT/HI/tmax_arr_HI.rda")
# ncfile <- nc_open("data-raw/CN05.1_Tm_1961_2018_daily_025x025.nc")
# tmean_arr <- ncvar_get(ncfile, "tm")
# nc_close(ncfile)
# ncfile <- nc_open("data-raw/CN05.1_Tmin_1961_2018_daily_025x025.nc")
# tmin_arr <- ncvar_get(ncfile, "tmin")
# nc_close(ncfile)
# tmean_arr <- tmean_arr[, , 1:20574]
# tmin_arr <- tmin_arr[, , 1:20574]
# dim(tmin_arr) <- 283 * 163 * 20574
# dim(tmean_arr) <- 283 * 163 * 20574
# tmin_arr_HI <- map2_dbl(tmin_arr, rhu_arr, heat_index)
# tmean_arr_HI <- map2_dbl(tmean_arr, rhu_arr, heat_index)
# dim(tmin_arr_HI) <- c(283, 163, 20574)
# dim(tmean_arr_HI) <- c(283, 163, 20574)
# save(tmin_arr_HI, file = "OUTPUT/HI/tmin_arr_HI.rda")
# save(tmean_arr_HI, file = "OUTPUT/HI/tmean_arr_HI.rda")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.