Skip to content

Real calendars and time units#263

Merged
brian-rose merged 55 commits intoclimlab:mainfrom
brian-rose:calendar
Feb 3, 2026
Merged

Real calendars and time units#263
brian-rose merged 55 commits intoclimlab:mainfrom
brian-rose:calendar

Conversation

@brian-rose
Copy link
Copy Markdown
Collaborator

This PR adds support for time and date units to climlab.

As a first step, we have the ability to convert calendar dates to the "fractional days since Jan1" format needed by the solar calculators in climlab.solar.daily_insolation.

@brian-rose
Copy link
Copy Markdown
Collaborator Author

The latest push should finally get all tests passing again.

Internal time-keeping is now all set up. Every process now has an attribute self.current_time which is kept up to date, and also synchronized down the subprocess tree. It is also possible to initialize a process with an arbitrary initial_time, and/or reset the clock of a process and its subprocesses by assigning a new np.datetime64 object to self.current_time after process creation.

Everything seems to be working as it should now.

The next step is to get back to a more efficient insolation calculation. Currently we are calling the insolation calculator at every timestep. It is much slower than the previous strategy of pre-computing insolation for every timestep throughout a calendar year.

It would be great to have a parent class that handles this kind of logic for any type of diagnostic process that depends only on time, so it can be precomputed year by year.

@brian-rose
Copy link
Copy Markdown
Collaborator Author

Also need to write some documentation about the new time and date handling.

@brian-rose
Copy link
Copy Markdown
Collaborator Author

The latest push restores performance by pre-computing insolation one year at a time. The logic for this is now implemented in climlab.radiation.DailyInsolation by just matching the current time to a precomputed list of times.

It would be very simple to abstract this logic out to a parent class for diagnostic processes that depend on time alone. But I don't have any particular application for this right now so I'll leave it as is.

@brian-rose brian-rose marked this pull request as ready for review February 3, 2026 02:30
@brian-rose brian-rose changed the title WIP: add support for real calendars and time units Real calendars and time units Feb 3, 2026
@brian-rose
Copy link
Copy Markdown
Collaborator Author

Everything is working and the docs are written. This is ready to merge. Major new functionality for climlab v0.10

@brian-rose brian-rose merged commit ca28435 into climlab:main Feb 3, 2026
8 checks passed
@brian-rose brian-rose deleted the calendar branch February 3, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant