Skip to main content

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 date
  • Dekad.from_ymd(year: int, month: int, dekad_of_month: int) - Create from year, month, and dekad of month (1-3)

Properties

  • year: int - The year
  • dekad_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 dekad
  • last_date() -> datetime.date - Get the last date of the dekad

Arithmetic Operations

  • dekad + int - Add dekads
  • dekad - int - Subtract dekads
  • dekad - 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's range() 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

dekad-1.1.0.tar.gz (59.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dekad-1.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file dekad-1.1.0.tar.gz.

File metadata

  • Download URL: dekad-1.1.0.tar.gz
  • Upload date:
  • Size: 59.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dekad-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f6fab3a50f669c57f62c0a638a415e026d7b7dd3ae851beb8fc5010a52b9ace9
MD5 1a249d0ecdc61c9b9f67d4673eb8c88d
BLAKE2b-256 3bfaa7d319f95edec064c50a9093a61f0f390afb62dcc0a92212b0ff4e7e02cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekad-1.1.0.tar.gz:

Publisher: publish.yml on amano-takahisa/dekad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekad-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: dekad-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dekad-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7ea14b13254e0bf758f209c8e9c75ec423c645fe1c091435c49a72adeb525f3
MD5 265656e36ba32f5a6a75b5acdce605f2
BLAKE2b-256 c246cc682b4becc5ed3918ee0aec90accb32b35ec892e59d55a8332d16b6a2ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekad-1.1.0-py3-none-any.whl:

Publisher: publish.yml on amano-takahisa/dekad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page