Commit 8248b35c authored by Heraut Louis's avatar Heraut Louis
Browse files

INI variable

parent b0d43708
No related merge requests found
Showing with 62 additions and 49 deletions
+62 -49
...@@ -273,6 +273,12 @@ get_VCN10trend = function (df_data, df_meta, period, p_thresold) { ...@@ -273,6 +273,12 @@ get_VCN10trend = function (df_data, df_meta, period, p_thresold) {
} }
### 1.4. tINI date ### 1.4. tINI date
which_underfirst = function (L, UpLim) {
id = which(L < UpLim)[1]
return (id)
}
get_tINItrend = function (df_data, df_meta, period, p_thresold) { get_tINItrend = function (df_data, df_meta, period, p_thresold) {
# Get all different stations code # Get all different stations code
...@@ -308,6 +314,7 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) { ...@@ -308,6 +314,7 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) {
for (per in period) { for (per in period) {
df_tINIEx = tibble() df_tINIEx = tibble()
df_tINIlist = list(data=tibble(), info=tibble())
# For all the code # For all the code
for (k in 1:nCode) { for (k in 1:nCode) {
...@@ -317,27 +324,64 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) { ...@@ -317,27 +324,64 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) {
# Get the data associated to the code # Get the data associated to the code
df_data_roll_code = df_data_roll[df_data_roll$code == code,] df_data_roll_code = df_data_roll[df_data_roll$code == code,]
# Get the data associated to the code
df_data_code = df_data[df_data$code == code,]
# Prepare the data to fit the entry of extract.Var
df_QNAlist_code = prepare(df_data_code,
colnamegroup=c('code'))
# Compute the yearly mean over the data
df_QNAEx_code = extract.Var(data.station=df_QNAlist_code,
funct=min,
timestep='year',
period=per,
pos.datetime=1,
na.rm=TRUE)
print(code)
print(df_QNAEx_code)
QNAmax = max(df_QNAEx_code$values, na.rm=TRUE)
print(QNAmax)
# Prepare the data to fit the entry of extract.Var # Prepare the data to fit the entry of extract.Var
df_tINIlist_code = prepare(df_data_roll_code, df_tINIlist_code = prepare(df_data_roll_code,
colnamegroup=c('code')) colnamegroup=c('code'))
per.start = df_meta$start_year[df_meta$code == code] per.start = df_meta$start_year[df_meta$code == code]
per.start = paste(sprintf("%02d", per.start), '-01', sep='') per.start = paste(sprintf("%02d", per.start), '-01', sep='')
print(per.start)
# Compute the yearly min over the averaged data # Compute the yearly min over the averaged data
df_tINIEx_code = extract.Var(data.station=df_tINIlist_code, df_tINIEx_code = extract.Var(data.station=df_tINIlist_code,
funct=which.min, funct=which_underfirst,
period=per, period=per,
per.start=per.start, per.start=per.start,
timestep='year', timestep='year',
pos.datetime=1) pos.datetime=1,
####### UpLim=QNAmax)
df_tINIEx_code$group1 = k df_tINIEx_code$group1 = k
df_tINIlist_code$data$group = k
df_tINIlist_code$info$group = k
# Store the results # Store the results
df_tINIEx = bind_rows(df_tINIEx, df_tINIEx_code) df_tINIEx = bind_rows(df_tINIEx, df_tINIEx_code)
df_tINIlist$data = bind_rows(df_tINIlist$data,
df_tINIlist_code$data)
df_tINIlist$info = bind_rows(df_tINIlist$info,
df_tINIlist_code$info)
} }
# print(df_tINIEx)
# print(df_tINIlist)
# Converts index of the tINI to the julian date associated # Converts index of the tINI to the julian date associated
df_tINIEx = prepare_date(df_tINIEx, df_tINIlist) df_tINIEx = prepare_date(df_tINIEx, df_tINIlist)
......
...@@ -112,40 +112,6 @@ reprepare = function(df_XEx, df_Xlist, colnamegroup=NULL) { ...@@ -112,40 +112,6 @@ reprepare = function(df_XEx, df_Xlist, colnamegroup=NULL) {
prepare_date = function(df_XEx, df_Xlist) { prepare_date = function(df_XEx, df_Xlist) {
# dateMD = substr(df_Xlist$data$Date, 6, 10)
# idYearList = which(dateMD == "01-01")
# YearList = df_Xlist$data$Date[idYearList]
# groupList = df_Xlist$data$group[idYearList]
# Group = levels(factor(df_XEx$group1))
# for (group in Group) {
# Year = YearList[groupList == group]
# for (idyear in 1:length(Year)) {
# year = Year[idyear]
# idShift = which(df_Xlist$data$group == group
# & df_Xlist$data$Date == year)
# okEx = df_XEx$group1 == group & df_XEx$datetime == substr(year, 1, 4)
# df_XEx$values[okEx] = df_XEx$values[okEx] + idShift
# }
# }
# idDate = df_XEx$values
# dateEx = as.Date(df_Xlist$data$Date[idDate])
# origin = as.Date(paste(format(dateEx, "%Y"), '-01-01', sep=''))
# ndate = length(origin)
# dateExJul = rep(0, times=ndate)
# for (i in 1:ndate) {
# dateExJul[i] = julian(dateEx[i], origin=origin[i])
# }
# df_XEx$values = dateExJul
dateStart_group = summarise(group_by(df_Xlist$data, group), dateStart_group = summarise(group_by(df_Xlist$data, group),
Date = min(Date)) Date = min(Date))
# filter(group_by(df_Xlist$data, group), Date == min(Date)) # filter(group_by(df_Xlist$data, group), Date == min(Date))
...@@ -173,18 +139,16 @@ prepare_date = function(df_XEx, df_Xlist) { ...@@ -173,18 +139,16 @@ prepare_date = function(df_XEx, df_Xlist) {
OkXEx_code = df_XEx$group1 == group OkXEx_code = df_XEx$group1 == group
XEx_code = df_XEx$values[OkXEx_code] XEx_code = df_XEx$values[OkXEx_code]
# dXExUp = abs(XEx_code - c(XEx_code[2:length(XEx_code)],
# XEx_code[length(XEx_code)]))
# dXExDown = abs(XEx_code - c(XEx_code[1],
# XEx_code[1:(length(XEx_code) - 1)]))
# dExMean = apply(rbind(dXExUp, dXExDown), 2, mean, na.rm=TRUE)
meanXEx_code = mean(XEx_code, na.rm=TRUE) meanXEx_code = mean(XEx_code, na.rm=TRUE)
dXEx_code = meanXEx_code - XEx_code dXEx_code = meanXEx_code - XEx_code
stdXEx_code = sd(XEx_code, na.rm=TRUE) stdXEx_code = sd(XEx_code, na.rm=TRUE)
OkOverStd = dXEx_code >= stdXEx_code*3
OkOverStd[is.na(OkOverStd)] = FALSE
XEx_code[dXEx_code >= stdXEx_code*3] = XEx_code[OkOverStd] = XEx_code[OkOverStd] + 365
XEx_code[dXEx_code >= stdXEx_code*3] + 365
print(OkOverStd)
# print(group) # print(group)
# print(df_XEx$datetime[df_XEx$group1 == group][dXEx_code >= stdXEx_code*3]) # print(df_XEx$datetime[df_XEx$group1 == group][dXEx_code >= stdXEx_code*3])
...@@ -306,10 +270,15 @@ get_period = function (per, df_Xtrend, df_XEx, df_Xlist) { ...@@ -306,10 +270,15 @@ get_period = function (per, df_Xtrend, df_XEx, df_Xlist) {
id = which(df_Xtrend$group1 == g) id = which(df_Xtrend$group1 == g)
# Computes index of the nearest accessible start and end date # Computes index of the nearest accessible start and end date
iStart = which.min(abs(df_XExtmp_code$Date OkStart = df_XExtmp_code$Date >= as.Date(per[1])
- as.Date(per[1]))) OkEnd = df_XExtmp_code$Date <= as.Date(per[2])
iEnd = which.min(abs(df_XExtmp_code$Date
- as.Date(per[2]))) distStart = abs(df_XExtmp_code$Date[OkStart] - as.Date(per[1]))
distEnd = abs(df_XExtmp_code$Date[OkEnd] - as.Date(per[2]))
iStart = which.min(distStart)
iEnd = which.min(distEnd)
# Stores the start and end of the trend analysis # Stores the start and end of the trend analysis
df_Xtrend$period_start[id] = df_Xtrend$period_start[id] =
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment