A Python package
Project description
Dekad
A Python package for handling dekads (10-day periods) commonly used in agrometeorology and climate science.
Overview
A dekad is a period of 10 days used in meteorological and agricultural applications. Each month is divided into three dekads:
- Dekad 1: Days 1-10
- Dekad 2: Days 11-20
- Dekad 3: Days 21 to the end of the month
Each year consists of 36 dekads (12 months x 3 dekads).
This package provides a Dekad class for working with dekad-based temporal data, including conversion to and from dates, arithmetic operations, and iteration.
Installation
Install using pip:
pip install dekad
Quick Start
from dekad import Dekad, dekad_range
import datetime
# Create a Dekad from a date
date = datetime.date(2024, 5, 15)
d = Dekad.from_date(date)
print(d) # 2024-D14
# Create a Dekad directly
d = Dekad(2024, 15) # 15th dekad of 2024
# Create from year, month, and dekad of month
d = Dekad.from_ymd(2024, 5, 3) # 3rd dekad of May 2024
# Convert to dates
print(d.first_date()) # 2024-05-21
print(d.last_date()) # 2024-05-31
# Access properties
print(d.year) # 2024
print(d.dekad_of_year) # 15
print(d.month) # 5
print(d.dekad_of_month) # 3
# Arithmetic operations
d2 = d + 5 # Add 5 dekads
d3 = d - 3 # Subtract 3 dekads
diff = d2 - d3 # Difference in dekads (returns 8)
# Iterate over dekads
for dekad in dekad_range(Dekad(2024, 1), Dekad(2024, 4)):
print(dekad)
# Output:
# 2024-D01
# 2024-D02
# 2024-D03
API Reference
Dekad Class
Constructors
Dekad(year: int, dekad_of_year: int)- Create a Dekad from year and dekad number (1-36)Dekad.from_date(date: datetime.date)- Create a Dekad from a dateDekad.from_ymd(year: int, month: int, dekad_of_month: int)- Create from year, month, and dekad of month (1-3)
Properties
year: int- The yeardekad_of_year: int- Dekad number within the year (1-36)month: int- The month (1-12)dekad_of_month: int- Dekad number within the month (1-3)
Methods
first_date() -> datetime.date- Get the first date of the dekadlast_date() -> datetime.date- Get the last date of the dekad
Arithmetic Operations
dekad + int- Add dekadsdekad - int- Subtract dekadsdekad - dekad- Calculate difference in dekads (returns int)int + dekad- Add dekads (commutative)
Comparison Operations
Supports all comparison operators: ==, !=, <, <=, >, >=
Collections Support
Dekad objects are hashable and can be used in sets and as dictionary keys.
Utility Functions
dekad_range(start: Dekad, end: Dekad, step: int = 1)- Generate a range of Dekad objects, similar to Python'srange()function. The range is inclusive of start but exclusive of end.
Examples
Working with Leap Years
from dekad import Dekad
# February 2024 (leap year)
feb_dekad3_2024 = Dekad.from_ymd(2024, 2, 3)
print(feb_dekad3_2024.last_date()) # 2024-02-29
# February 2023 (non-leap year)
feb_dekad3_2023 = Dekad.from_ymd(2023, 2, 3)
print(feb_dekad3_2023.last_date()) # 2023-02-28
Iterating Over a Year
from dekad import Dekad, dekad_range
# Iterate through all dekads in 2024
for dekad in dekad_range(Dekad(2024, 1), Dekad(2025, 1)):
print(f"{dekad}: {dekad.first_date()} to {dekad.last_date()}")
Calculating Time Differences
from dekad import Dekad
start = Dekad(2024, 1, 1)
end = Dekad(2024, 5, 15)
dekad_start = Dekad.from_date(start)
dekad_end = Dekad.from_date(end)
dekad_diff = dekad_end - dekad_start
print(f"Difference: {dekad_diff} dekads")
Using Dekads in Collections
from dekad import Dekad
# Use in sets
dekad_set = {Dekad(2024, 1), Dekad(2024, 2), Dekad(2024, 1)}
print(len(dekad_set)) # 2 (duplicates removed)
# Use as dictionary keys
data = {
Dekad(2024, 1): 150.5,
Dekad(2024, 2): 175.3,
Dekad(2024, 3): 162.1,
}
Development
Setting Up Development Environment
This project uses pixi for environment management.
# Install pixi (if not already installed)
curl -fsSL https://pixi.sh/install.sh | bash
# Install dependencies
pixi install
# Activate the development environment
pixi shell -e development
Running Tests
# Run tests with coverage
pixi run -e test test
# Run in development environment
pixi shell -e development
pytest --cov=src/dekad
Code Quality
# Check code style and types
pixi run -e development check
# Auto-fix issues
pixi run -e development fix
Requirements
- Python >= 3.9
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 dekad-1.0.1.tar.gz.
File metadata
- Download URL: dekad-1.0.1.tar.gz
- Upload date:
- Size: 59.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e612933927c0e4f0ca7e141ca686d62b50f898b46302a3ac7221d6fa2a3528d
|
|
| MD5 |
97a8358a6a518da5ad5b900c5b00cb6b
|
|
| BLAKE2b-256 |
a7f0ecc84efb39b85cdad212e0fc1b76ddc3a5ce57b0ad6130841246032bc420
|
Provenance
The following attestation bundles were made for dekad-1.0.1.tar.gz:
Publisher:
publish.yml on amano-takahisa/dekad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dekad-1.0.1.tar.gz -
Subject digest:
2e612933927c0e4f0ca7e141ca686d62b50f898b46302a3ac7221d6fa2a3528d - Sigstore transparency entry: 689046854
- Sigstore integration time:
-
Permalink:
amano-takahisa/dekad@ba0f73e5cfcad148307925e576decd274903f570 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/amano-takahisa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ba0f73e5cfcad148307925e576decd274903f570 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dekad-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dekad-1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74afe8fd2f4e8ecee886b7c23272d98cc923857a9aee2757b45109da9b402283
|
|
| MD5 |
4461e5e3bc7491435641398664d64b6d
|
|
| BLAKE2b-256 |
c7c1ac17ed70c7215499f967f065319d49a18b83f4c5f5faeafc2291726d0a23
|
Provenance
The following attestation bundles were made for dekad-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on amano-takahisa/dekad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dekad-1.0.1-py3-none-any.whl -
Subject digest:
74afe8fd2f4e8ecee886b7c23272d98cc923857a9aee2757b45109da9b402283 - Sigstore transparency entry: 689046913
- Sigstore integration time:
-
Permalink:
amano-takahisa/dekad@ba0f73e5cfcad148307925e576decd274903f570 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/amano-takahisa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ba0f73e5cfcad148307925e576decd274903f570 -
Trigger Event:
push
-
Statement type: