Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
HYCAR-Hydro
airGR
Commits
da421acb
Commit
da421acb
authored
Mar 29, 2021
by
Delaigue Olivier
Browse files
feat(Utils); add a DatesR argument in the .GetFeatModel function in order to manage the TimeUnit
Refs
#106
parent
d21eece8
Pipeline
#21787
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
R/Utils.R
View file @
da421acb
...
...
@@ -25,10 +25,10 @@
## function to extract model features
.GetFeatModel
<-
function
(
FUN_MOD
)
{
.GetFeatModel
<-
function
(
FUN_MOD
,
DatesR
)
{
FeatMod
<-
.FeatModels
()
FUN_MOD
<-
match.fun
(
FUN_MOD
)
NameFunMod
<-
ifelse
(
test
=
FeatMod
$
Class
%in%
"GR"
,
NameFunMod
<-
ifelse
(
test
=
FeatMod
$
Pkg
%in%
"
air
GR"
,
yes
=
paste
(
"RunModel"
,
FeatMod
$
NameMod
,
sep
=
"_"
),
no
=
FeatMod
$
NameMod
)
FunMod
<-
lapply
(
NameFunMod
,
FUN
=
get
)
...
...
@@ -38,15 +38,30 @@
}
else
{
res
<-
as.list
(
FeatMod
[
IdMod
,
])
res
$
NameFunMod
<-
NameFunMod
[
IdMod
]
DiffTimeStep
<-
as.numeric
(
difftime
(
DatesR
[
length
(
DatesR
)],
DatesR
[
length
(
DatesR
)
-1
],
units
=
"secs"
))
if
(
is.na
(
res
$
TimeUnit
))
{
if
(
any
(
DiffTimeStep
%in%
3600
:
3601
))
{
# 3601: leap second
res
$
TimeUnit
<-
"hourly"
}
else
{
res
$
TimeUnit
<-
"daily"
}
}
res
$
TimeStep
<-
switch
(
res
$
TimeUnit
,
hourly
=
1
,
daily
=
24
,
monthly
=
28
:
31
,
yearly
=
365
:
366
)
res
$
TimeStep
<-
res
$
TimeStep
*
3600
res
$
Class
<-
c
(
res
$
TimeUnit
,
res
$
Class
)
if
(
grepl
(
"CemaNeige"
,
res
$
NameFunMod
))
{
res
$
Class
<-
c
(
res
$
Class
,
"CemaNeige"
)
res
$
Class
<-
unique
(
c
(
res
$
Class
,
"CemaNeige"
))
}
if
(
DiffTimeStep
!=
res
$
TimeStep
)
{
stop
(
"the time step of the model inputs must be "
,
res
$
TimeUnit
,
"\n"
)
}
return
(
res
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment