From ac92e6c43c3978b7c1cd63ea290fab95838c8c72 Mon Sep 17 00:00:00 2001 From: Alice Stears Date: Tue, 10 Sep 2024 16:18:55 -0600 Subject: [PATCH] create COGs for temperature --- ...xt90Days_from_2024-09-17_to_2024-12-09.tif | Bin 0 -> 1135 bytes ...xt90Days_from_2024-09-17_to_2024-12-09.tif | Bin 0 -> 1104 bytes projects/07_TestOutputForFRESC/CreateCOGs.R | 44 ++++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 outputs/20240903/COGs/TMean_predictionDiffFromNormalPeriod_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif create mode 100644 outputs/20240903/COGs/TMean_prediction_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif diff --git a/outputs/20240903/COGs/TMean_predictionDiffFromNormalPeriod_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif b/outputs/20240903/COGs/TMean_predictionDiffFromNormalPeriod_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif new file mode 100644 index 0000000000000000000000000000000000000000..17529f77c158381ac4e2081ee015b068fdad5fa9 GIT binary patch literal 1135 zcmebD)MDUZU|*y7Mi#K%PfQF9 zqDbOmP&UXMaj2SFpavNvHMU6XU?`gzsGhHxhXF(f0nKb`;bC9{va^8f_3g|I3PAQO zAbUeQ4+D^5xCJCOwljf!@(RdqSi;1R0JP^5P_7ZkW&zT9iFrVhfx*Vz#nHz%wInem zu_V!sOF_ZLvm`ZFAulmE)mAAu#4*G(IKs?%for63BLOlIZT&z%(5Au9UYH@N=W3&pyxXD{KiQ<>wa{P^Yq8M~luEXj{|FPLZRtv2=XMWzy8!4z@!1q~O@RQ<}* z2w%Hl)849kMz-P$rat;mb*xOqeeIU)j;e*iZS3d7UVNz0o3mOls!E{oWnBq};!6j{ zPR5r$wd}4BrQ`$;-gHWytNP%Kx4hzuS>j>~UpPh0WqhIGG&%8wo|5pw7j;^kiXSHU iOgQ+mOZMmzjb~2ni#gdM*&AQH$!u>oT;kH+!2tlH8$#Lu literal 0 HcmV?d00001 diff --git a/outputs/20240903/COGs/TMean_prediction_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif b/outputs/20240903/COGs/TMean_prediction_MeanOverNext90Days_from_2024-09-17_to_2024-12-09.tif new file mode 100644 index 0000000000000000000000000000000000000000..a02b522d7ce1bd73880a8ee3c22bd90c361d500b GIT binary patch literal 1104 zcmebD)MDUZU|*y7Mi#K%4@?XU zqDbOmP&UXMaj2REpavNvHMU6XU?`gzsGhHxhXF(f0L^S_;bC9{vNM3}_3g|I3PAP@ zAbUeQ4+D^5xB(bKNJIWErEcrHcvkctBv(6jf^eLOifHp3=Is;2$~Tb z;^N{OMy%y7uEEYho&h1A{wVHMD9Q)AQF9#~!$U7YL@hI>3}Ng3}W)-2kJG5g5n7!~>*(Q3_0~j112N z7&$h!gHjb6nBS+&$+4jwB+m_|85lZpOQy*#DFT`2uq-6PG2A^^!NR15p+Tf8=MvLJ zflCTzhu#z&YjIB&IiU?-ck>`zJ9K{9#b&^KMAu`a6$Pp*zILb)n{eQGIO> zhDnD-8kCBhIoEzW$k=wJ!_rN!h{;3ly@KZH{6ma)~x~R zy?QGLlY`IKAC?&tgwxn|GOQ5H7Z5z-vG_``jN&}`Bg_&;4)H=BY-$^I62maN~l4V8gVFiF=PY7@6E-Vd=KB_)xdkgZI+%H!=NqaQU=RBnztmw~|}VZHE`v6&X$m?n?dnYKc%2<0A#h=8s<6S$RAs zSco<;TnZIi#JGiJx)Q??<(ZEdR;frTF=(VOWD2mF*TQsLE2n!oLqoWbmJ$;HT}vFm literal 0 HcmV?d00001 diff --git a/projects/07_TestOutputForFRESC/CreateCOGs.R b/projects/07_TestOutputForFRESC/CreateCOGs.R index d48fe33..b590115 100644 --- a/projects/07_TestOutputForFRESC/CreateCOGs.R +++ b/projects/07_TestOutputForFRESC/CreateCOGs.R @@ -329,25 +329,53 @@ terra::writeRaster(precip_diff_means, filename = paste0(outLoc,"Precip_predictio # (from tmean_dy_gridSTDF_median-prediction.nc) ## currently just the next 3 months # get data -precip_preds<- rast(paste0(fileLoc, "ppt_dy_gridSTDF_median-prediction_", format(currDate, "%m%Y"), ".nc")) +temp_preds<- rast(paste0(fileLoc, "tmean_dy_gridSTDF_median-prediction_", format(currDate, "%m%Y"), ".nc")) # get the information from the time axis -precip_pred_time <- var.get.nc(ncfile = open.nc(paste0(fileLoc, "ppt_dy_gridSTDF_median-prediction_", format(currDate, "%m%Y"), ".nc")), variable = "time") +temp_pred_time <- var.get.nc(ncfile = open.nc(paste0(fileLoc, "tmean_dy_gridSTDF_median-prediction_", format(currDate, "%m%Y"), ".nc")), variable = "time") # calculate the dates (were previously # of days since 1-1-1970) -precip_pred_time <- lubridate::as_date(precip_pred_time, origin = "1970-01-01") +temp_pred_time <- lubridate::as_date(temp_pred_time, origin = "1970-01-01") # get the indices of values that are within the next three months (next 90 days) -goodDates <- which(precip_pred_time %in% as_date(c(currDate:(currDate+90)))) +goodDates_temp <- which(temp_pred_time %in% as_date(c(currDate:(currDate+90)))) ## get data for the next three months -precip_pred_90days <- terra::subset(precip_preds, goodDates) -precip_pred_mean_90days <- mean(precip_pred_90days, na.rm = TRUE) +temp_pred_90days <- terra::subset(temp_preds, goodDates_temp) +temp_pred_mean_90days <- mean(temp_pred_90days, na.rm = TRUE) # save the mean data as a COG -terra::writeRaster(precip_pred_mean_90days, filename = paste0(outLoc,"Precip_prediction_MeanOverNext90Days_from_", precip_pred_time[goodDates][1],"_to_",currDate+90, ".tif"), gdal = "COG", overwrite = TRUE) - +terra::writeRaster(temp_pred_mean_90days, filename = paste0(outLoc,"TMean_prediction_MeanOverNext90Days_from_", temp_pred_time[goodDates][1],"_to_",currDate+90, ".tif"), gdal = "COG", overwrite = TRUE) # Temp: Deltas for temp over the next three months ------------------------------------------------------------------ # (comparison of mean to normal period for the same period) (from tmean_dy_gridSTDF_median-diffs-prediction.nc) +# get data +temp_hist <- rast(paste0(fileLoc, "tmean_dy_gridSTDF_historical_19910101-20201231-median_", format(currDate, "%m%Y"), ".nc")) +# get the information from the time axis +temp_hist_time <- var.get.nc(ncfile = open.nc(paste0(fileLoc, "tmean_dy_gridSTDF_historical_19910101-20201231-median_", format(currDate, "%m%Y"), ".nc")), variable = "time") +# calculate the dates (were previously # of days since 1-1-1970) +temp_hist_time <- lubridate::as_date(temp_hist_time, origin = "1970-01-01") + +# get the indices of values that are within the next three months (next 90 days) +goodDates_preds <- which(temp_pred_time %in% as_date(c(currDate:(currDate+90)))) +goodDates_hist <- which(temp_hist_time %in% as_date(c(temp_pred_time[1]:(currDate+90)))) +# make sure the range of dates is the same +sum(temp_pred_time[goodDates_preds] != temp_hist_time[goodDates_hist]) # should be zero +length(goodDates_preds) == length(goodDates_hist) # should be true + +## get data for the next three months +# for prediction data +temp_pred_90days <- terra::subset(temp_preds, goodDates_preds) +# for historical data +temp_hist_90days <- terra::subset(temp_hist, goodDates_hist) +# calculate diffs between each day (prediction - normal) +diffList <- lapply(X = 1:length(goodDates_preds), FUN = function(x) { + temp <- subset(temp_pred_90days, x) - subset(temp_hist_90days, x) + return(temp) +}) +diffs <- rast(diffList) +# average across all days to get the mean diff over the next 90 days +temp_diff_means <- mean(diffs, na.rm = TRUE) +# save the mean data as a COG +terra::writeRaster(temp_diff_means, filename = paste0(outLoc,"TMean_predictionDiffFromNormalPeriod_MeanOverNext90Days_from_", temp_pred_time[goodDates_preds][1],"_to_",currDate+90, ".tif"), gdal = "COG", overwrite = TRUE) ###Idea: could use some sort of stippling/shading to indicate when predictions are “significantly different” from the normal period (i.e. CIs don’t overlap)--especially for deltas