Compute time block IDs since major climate agreements.
Project description
ClimateTimer
ClimateTimer is a pure-Python library that computes time block IDs and time periods based on elapsed time units (seconds, minutes, quarters, hours, days, weeks, etc.) since major climate agreements.
It supports two reference points:
- Paris Agreement (April 22, 2016, UTC)
- Kyoto Protocol (February 16, 2005, UTC)
This package is designed for Python 3, is OS independent, and is licensed under the MIT License.
Features
Flexible Time Reference Selection
Choose between the Paris Agreement and the Kyoto Protocol as your starting point.
Time Block Calculations
Compute block IDs and corresponding time periods for various units:
- Seconds
- Minutes
- Quarters (15-minute intervals)
- Hours
- Days
- Weeks
Simple and intuitive API
-
blockid(date, blocktype="quarter"): Compute the time block ID.- date: A timezone-aware datetime (positional).
- blocktype: The type of block (e.g., "second", "minute", "quarter", "hour", "day", "week"). Defaults to
"quarter".
-
period(block_id, blocktype="quarter"): Retrieve the start and end datetimes for a given block.
Reference Information
The info() method returns a plain-text description of the instantiated reference event.
Modern Packaging
Built with a pyproject.toml–only configuration.
Installation
Using pip
pip install climatetimer
From Source
Clone the repository and install:
git clone https://github.com/cameraink/climatetimer.git
cd climatetimer
pip install .
Quick Start
from climatetimer import ClimateTimer
from datetime import datetime, timezone
# Initialize using the Paris Agreement reference
timer = ClimateTimer("paris")
# Compute the block ID for the current hour (date is positional; blocktype defaults to "quarter")
block_id = timer.blockid(datetime.utcnow(), blocktype="hour")
print(f"Current hour block ID: {block_id}")
# Retrieve the start and end times for that block
start, end = timer.period(block_id, blocktype="hour")
print(f"Block {block_id} starts at {start} and ends at {end}")
# Get information about the reference event for this instance
print("Reference Info:", timer.info())
Usage
Initializing ClimateTimer
You must specify the reference as a positional argument:
# For Paris Agreement
timer_paris = ClimateTimer("paris")
# For Kyoto Protocol
timer_kyoto = ClimateTimer("kyoto")
Computing a Block ID
Pass a timezone-aware datetime and specify the block type:
block_id = timer_paris.blockid(datetime(2023, 5, 10, 15, 30, tzinfo=timezone.utc), blocktype="hour")
Retrieving a Time Block Period
info = timer_paris.info()
print("Reference Info:", info)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file climatetimer-0.2.0.tar.gz.
File metadata
- Download URL: climatetimer-0.2.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
141f7156c3ec77357e0332939b782e12b8c33f9a64ac18d900bb09d336421ccc
|
|
| MD5 |
f146ceba8c623616b89547e57ca68542
|
|
| BLAKE2b-256 |
efd5c8c438fa8c727ea33d34b2ed98ddabdb6f16d13e30fc44cbf7b0855cdd3c
|
File details
Details for the file climatetimer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: climatetimer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caab34f047681bab97cc96b0ee9ec37ced252ea8505168c6cdadae5fcb968535
|
|
| MD5 |
40f6ae9567d5255ebc1dd47897368885
|
|
| BLAKE2b-256 |
6a6116d7cb5d1837b60ab4553deea313322df1f3095983ce4fdb590131459776
|