bcgov / climr

An R package for downscaling monthly climate data for North America
https://bcgov.github.io/climr/
16 stars 5 forks source link

precipitation isn't bias-correcting properly #245

Closed cmahony closed 6 months ago

cmahony commented 6 months ago

The 1961-1990 normals for models and observations don't match up for precipitation. since this is the reference period, everything should have the same 1961-1990 mean. something is wrong.

my_points <- data.frame(lon = c(-127.7300,-127.7500), lat = c(55.34114, 55.25), elev = c(711, 500), id = 1:2)
my_data <- plot_timeSeries_input(my_points) # generate the input data
plot_timeSeries(my_data, "MAP")

image

kdaust commented 6 months ago

@cmahony yes I know there are some issues with the climatena historic ts - hopefully the updated version (tomorrow) should fix the issue. Could you check if precip looks on these plots with the cru_gpcc now it's fixed?

cmahony commented 6 months ago

the CRU time series is fixed for temperature, but has the same problem for precipitation. I have a hunch what may be the problem. we should check if this is a problem wiht monthly precip (i can't do that in the plot function becuase we need to change the variable naming conventions first... something i wanted to check in with you on). image

cmahony commented 6 months ago

@kdaust i did a basic check of the data and it looks like this is a problem with my function, not with the database or downscaling.

library(data.table)
library(scales)
library(stinepack)

# data frame of arbitrary points
my_points <- data.frame(lon = c(-127.7300), lat = c(55.34114), elev = c(711), id = 1)

# generate the input data
my_data <- plot_timeSeries_input(my_points, historic_ts_dataset = "cru_gpcc", gcm_models = list_gcm()[1])

# use the input to create a plot
plot_timeSeries(my_data, "MAP", historic_ts_dataset = "cru_gpcc", gcm_models = list_gcm()[1])

variable <- "MAP"
baseline <- my_data[PERIOD=="1961_1990", get(variable)]
variable <- "MAP"
(baseline.normal <- my_data[PERIOD=="1961_1990", get(variable)])
(baseline.obs <- mean(my_data[is.na(GCM) & PERIOD%in%1961:1990, get(variable)]))
(baseline.model <- mean(my_data[!is.na(GCM) & PERIOD%in%1961:1990, get(variable)]))
> (baseline.normal <- my_data[PERIOD=="1961_1990", get(variable)])
[1] 619.2334
> (baseline.obs <- mean(my_data[is.na(GCM) & PERIOD%in%1961:1990, get(variable)]))
[1] 621.0265
> (baseline.model <- mean(my_data[!is.na(GCM) & PERIOD%in%1961:1990, get(variable)]))
[1] 617.8569
cmahony commented 6 months ago

it was a problem in my function. the bug is fixed in 0317513cd8feb303ccd27cb1bde0b4a2621ce6d4