Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Persefone.jl
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Persefone
Persefone.jl
Commits
69ee3eb9
Commit
69ee3eb9
authored
1 month ago
by
Marco Matthies
Browse files
Options
Downloads
Patches
Plain Diff
Add docstrings and improve function naming
parent
d353b955
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/world/weather.jl
+23
-5
23 additions, 5 deletions
src/world/weather.jl
with
23 additions
and
5 deletions
src/world/weather.jl
+
23
−
5
View file @
69ee3eb9
...
...
@@ -30,11 +30,23 @@ function Base.length(weather::Weather)
return
Dates
.
value
(
weather
.
lastdate
-
weather
.
firstdate
)
+
1
end
"""
daynumber(weather, date)
Returns the number of days, counting `weather.firstdate` as day `1`.
"""
function
daynumber
(
weather
::
Weather
,
date
::
Date
)
@assert
weather
.
firstdate
<=
date
<=
weather
.
lastdate
return
Dates
.
value
(
date
-
weather
.
firstdate
)
+
1
end
"""
findspans(predicate_fn, array) -> Vector{Tuple{Int, Int}}
Returns spans of indices in a 1-d `array` where a `predicate_fn`
returns `true`. The spans are returned as a `Vector{Tuple{Int,
Int}}`, where each tuple is of the form `(start_index, end_index)`.
"""
function
findspans
(
predicate_fn
,
arr
::
AbstractVector
)
spans
=
Tuple
{
Int
,
Int
}[]
startidx
=
nothing
...
...
@@ -54,10 +66,16 @@ function findspans(predicate_fn, arr::AbstractVector)
return
spans
end
function
fix_missing_weatherdata!
(
df
::
DataFrame
)
colnames_to_fix
=
[
"min_temperature"
,
"max_temperature"
,
"mean_temperature"
,
"precipitation"
,
"potential_evapotranspiration"
]
for
colname
in
colnames_to_fix
"""
check_missing_weatherdata(dataframe)
Check the weather input data for missing values in columns where input
values are required.
"""
function
check_missing_weatherdata
(
df
::
DataFrame
)
colnames
=
[
"min_temperature"
,
"max_temperature"
,
"mean_temperature"
,
"precipitation"
,
"potential_evapotranspiration"
]
for
colname
in
colnames
spans
=
findspans
(
ismissing
,
getproperty
(
df
,
colname
))
# TODO: fix missing values and warn here instead of error
if
!
isempty
(
spans
)
...
...
@@ -101,7 +119,7 @@ function initweather(weatherfile::String, startdate::Date, enddate::Date)
*
" expected
$
(Dates.value(enddate - startdate) + 1), got
$
(nrow(df)))."
*
" Missing dates are
$
(setdiff(startdate:enddate, df.date))."
)
end
fix
_missing_weatherdata
!
(
df
)
check
_missing_weatherdata
(
df
)
return
Weather
(;
firstdate
=
minimum
(
df
.
date
),
lastdate
=
maximum
(
df
.
date
),
windspeed
=
df
.
mean_windspeed
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment