Skip to content

Commit

Permalink
rename TimeManager to CallbackManager
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Sep 10, 2024
1 parent c9b7c0c commit 97be0c5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 40 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ClimaUtilities.jl
to process input data and remap it onto the simulation grid.
- [`OutputPathGenerator`](https://clima.github.io/ClimaUtilities.jl/dev/outputpathgenerator/)
to prepare the output directory structure of a simulation.
- [`TimeManager`](https://clima.github.io/ClimaUtilities.jl/dev/timemanager/) to
- [`CallbackManager`](https://clima.github.io/ClimaUtilities.jl/dev/callbackmanager/) to
handle dates.

## ClimaUtilities.jl Developer Guidelines
Expand Down Expand Up @@ -178,6 +178,5 @@ two commits when the second just fixes the first).

The `Space` and `TimeVaryingInputs` modules were initially developed in the
context of [`ClimaLand`](https://github.com/CliMA/ClimaLand.jl), the
`TempestRegridder` and `TimeManager` ones were initially developed in
`TempestRegridder` and `CallbackManager` ones were initially developed in
[`ClimaCoupler`](https://github.com/CliMA/ClimaCoupler.jl).

2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pages = [
"DataHandling" => "datahandling.md",
"Regridders" => "regridders.md",
"OutputPathGenerator" => "outputpathgenerator.md",
"TimeManager" => "timemanager.md",
"CallbackManager" => "callbackmanager.md",
"Frequently Asked Questions" => "faqs.md",
]

Expand Down
16 changes: 16 additions & 0 deletions docs/src/callbackmanager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CallbackManager

This module contains functions that handle dates and times
in simulations. The functions in this module often call
functions from Julia's [Dates](https://docs.julialang.org/en/v1/stdlib/Dates/) module.

## CallbackManager API

```@docs
ClimaUtilities.CallbackManager.to_datetime
ClimaUtilities.CallbackManager.strdate_to_datetime
ClimaUtilities.CallbackManager.datetime_to_strdate
ClimaUtilities.CallbackManager.trigger_callback
ClimaUtilities.CallbackManager.Monthly
ClimaUtilities.CallbackManager.EveryTimestep
```
16 changes: 0 additions & 16 deletions docs/src/timemanager.md

This file was deleted.

6 changes: 3 additions & 3 deletions src/TimeManager.jl → src/CallbackManager.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
TimeManager
CallbackManager
This module facilitates calendar functions and temporal interpolations
of data.
"""
module TimeManager
module CallbackManager

import Dates

Expand Down Expand Up @@ -105,4 +105,4 @@ function trigger_callback(
end
end

end # module TimeManager
end # module CallbackManager
2 changes: 1 addition & 1 deletion src/ClimaUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ClimaUtilities

include("Utils.jl")
include("MPIUtils.jl")
include("TimeManager.jl")
include("CallbackManager.jl")
include("DataStructures.jl")
include("FileReaders.jl")
include("Regridders.jl")
Expand Down
28 changes: 14 additions & 14 deletions test/timemanager.jl → test/callbackmanager.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ClimaUtilities: TimeManager
import ClimaUtilities: CallbackManager
import Dates
import CFTime
using Test
Expand All @@ -9,32 +9,32 @@ for FT in (Float32, Float64)
year = 2001
dt_noleap = CFTime.DateTimeNoLeap(year)
dt = Dates.DateTime(year)
@test TimeManager.to_datetime(dt_noleap) == dt
@test CallbackManager.to_datetime(dt_noleap) == dt
# In non-leap year, DateTime and DateTimeNoLeap are the same
@test TimeManager.to_datetime(dt_noleap + Dates.Day(365)) ==
@test CallbackManager.to_datetime(dt_noleap + Dates.Day(365)) ==
dt + Dates.Day(365)

# Test leap year behavior
leap_year = 2000
dt_noleap_ly = CFTime.DateTimeNoLeap(leap_year)
dt_ly = Dates.DateTime(leap_year)
# DateTime includes leap days, DateTimeNoLeap does not, so DateTime has one extra day in leap year
@test TimeManager.to_datetime(dt_noleap_ly + Dates.Day(365)) ==
@test CallbackManager.to_datetime(dt_noleap_ly + Dates.Day(365)) ==
dt_ly + Dates.Day(366)

end

@testset "test strdate_to_datetime for FT=$FT" begin
@test TimeManager.strdate_to_datetime("19000101") ==
@test CallbackManager.strdate_to_datetime("19000101") ==
Dates.DateTime(1900, 1, 1)
@test TimeManager.strdate_to_datetime("00000101") ==
@test CallbackManager.strdate_to_datetime("00000101") ==
Dates.DateTime(0, 1, 1)
end

@testset "test datetime_to_strdate for FT=$FT" begin
@test TimeManager.datetime_to_strdate(Dates.DateTime(1900, 1, 1)) ==
@test CallbackManager.datetime_to_strdate(Dates.DateTime(1900, 1, 1)) ==
"19000101"
@test TimeManager.datetime_to_strdate(Dates.DateTime(0, 1, 1)) ==
@test CallbackManager.datetime_to_strdate(Dates.DateTime(0, 1, 1)) ==
"00000101"
end

Expand All @@ -47,10 +47,10 @@ for FT in (Float32, Float64)
arg_copy = copy(arg)
date_current =
date_nextcall = date_nextcall_copy = Dates.DateTime(1979, 3, 21)
date_nextcall = TimeManager.trigger_callback(
date_nextcall = CallbackManager.trigger_callback(
date_nextcall,
date_current,
TimeManager.Monthly(),
CallbackManager.Monthly(),
func!,
(arg,),
)
Expand All @@ -61,10 +61,10 @@ for FT in (Float32, Float64)
# Case 2: date_current > date_nextcall
date_nextcall = date_nextcall_copy = Dates.DateTime(1979, 3, 21)
date_current = date_nextcall + Dates.Day(1)
date_nextcall = TimeManager.trigger_callback(
date_nextcall = CallbackManager.trigger_callback(
date_nextcall,
date_current,
TimeManager.Monthly(),
CallbackManager.Monthly(),
func!,
(arg,),
)
Expand All @@ -75,10 +75,10 @@ for FT in (Float32, Float64)
# Case 3: date_current < date_nextcall
date_nextcall = date_nextcall_copy = Dates.DateTime(1979, 3, 21)
date_current = date_nextcall - Dates.Day(1)
date_nextcall = TimeManager.trigger_callback(
date_nextcall = CallbackManager.trigger_callback(
date_nextcall,
date_current,
TimeManager.Monthly(),
CallbackManager.Monthly(),
func!,
(arg,),
)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ end
include("output_path_generator.jl")
end

@safetestset "TimeManager tests" begin
include("timemanager.jl")
@safetestset "CallbackManager tests" begin
include("callbackmanager.jl")
end

@safetestset "DataStructures tests" begin
Expand Down

0 comments on commit 97be0c5

Please sign in to comment.