Skip to content

Commit

Permalink
Bugfix in loading hourly data (#89)
Browse files Browse the repository at this point in the history
* fix bug in comparing hourly

* add tests

* bump version

* actually fix
  • Loading branch information
Datseris committed Feb 22, 2022
1 parent 70199ca commit b0f1ae6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimateBase"
uuid = "35604d93-0fb8-4872-9436-495b01d137e2"
authors = ["Datseris <[email protected]>", "Philippe Roy <[email protected]>"]
version = "0.14.3"
version = "0.14.4"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
4 changes: 2 additions & 2 deletions src/core/nc_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ function vector2range(t::Vector{<:Dates.AbstractTime})
tsamp = temporal_sampling(t)
period = tsamp2period(tsamp)
isnothing(period) && return t
t1 = period == :hourly ? t[1] : Date(t[1])
tf = period == :hourly ? t[end] : Date(t[end])
t1 = tsamp == :hourly ? t[1] : Date(t[1])
tf = tsamp == :hourly ? t[end] : Date(t[end])
r = t1:period:tf
return r == t ? r : t # final safety check to ensure equal values
end
Expand Down
4 changes: 2 additions & 2 deletions src/physical_dimensions/spatial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ using StatsBase

"""
spacemean(A::ClimArray [, W]) = spaceagg(mean, A, W)
Average given `A` over its spatial coordinates.
Average `A` over its spatial coordinates.
Optionally provide statistical weights in `W`.
"""
spacemean(A, exw=nothing) = spaceagg(mean, A, exw)
Expand All @@ -147,7 +147,7 @@ function spaceagg(::OrthogonalSpace, f, A::AbDimArray, w=nothing)
wtype = spaceweightassert(A, w)
cosweights = repeat(cosd.(dims(A, Lat).val)', size(A, Lon))
if dimindex(A, Lon) > dimindex(A, Lat)
error("At the moment this function assumes that Lon preceeds Lat, use `permutdims`.")
error("At the moment this function assumes that Lon preceeds Lat, use `permutedims`.")
end
other = otherdims(A, (Lon, Lat))
# pre-calculate weights if possible
Expand Down
9 changes: 8 additions & 1 deletion test/io_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
@testset "NetCDF IO" begin
@testset "NetCDF IO" begin

@testset "vector2range" begin
th = collect(thourly)
th2 = ClimateBase.vector2range(th)
@test th2 isa AbstractRange
@test th2 == th
end

@testset "NetCDF standard tests" begin
globat = Dict("history" => "test")
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lats = -86:4:86
lons = collect(0.5:10:360)
t = Date(2000, 3, 15):Month(1):Date(2020, 2, 15)
tdaily = Date(2000, 3, 15):Day(1):Date(2020, 3, 14)
thourly = DateTime(2000, 3, 15):Hour(1):DateTime(2000, 6, 14)

d = (Lon(lons), Lat(lats), Time(t))
A = zeros([length(x) for x in (lons, lats, t)]...)
Expand Down

0 comments on commit b0f1ae6

Please sign in to comment.