Core Functions API Reference¶
Vigesimal Functions¶
maya_encoding.core.vigesimal
¶
Core vigesimal (base-20) number system functions.
The Maya vigesimal system decomposes numbers into positions of value 1, 20, 400, 8000, ... Each position (digit 0-19) further decomposes into bars (value 5, max 3) and dots (value 1, max 4).
This module provides pure functions for conversion, with numpy vectorization for performance.
to_vigesimal(n, n_levels=None)
¶
Convert a non-negative integer to a list of vigesimal digits (LSB first).
Parameters¶
n : int Non-negative integer to convert. n_levels : int or None Number of vigesimal levels. If None, auto-detected. Result is zero-padded or truncated to this length.
Returns¶
list[int] List of vigesimal digits, least significant first. Each digit is in range [0, 19].
Raises¶
ValueError If n is negative.
Examples¶
to_vigesimal(0) [0] to_vigesimal(19) [19] to_vigesimal(20) [0, 1] to_vigesimal(347) [7, 17] to_vigesimal(347, n_levels=4) [7, 17, 0, 0]
Source code in src/maya_encoding/core/vigesimal.py
from_vigesimal(digits)
¶
Convert a list of vigesimal digits (LSB first) back to an integer.
Parameters¶
digits : list[int] Vigesimal digits, least significant first. Each must be in [0, 19].
Returns¶
int The reconstructed integer.
Raises¶
ValueError If any digit is outside [0, 19].
Examples¶
from_vigesimal([7, 17]) 347 from_vigesimal([0, 1]) 20 from_vigesimal([0]) 0
Source code in src/maya_encoding/core/vigesimal.py
to_bars_dots(digit)
¶
Decompose a vigesimal digit (0-19) into bars and dots.
In the Maya system: - Each bar represents 5 - Each dot represents 1 - Maximum: 3 bars (15) + 4 dots (4) = 19
Parameters¶
digit : int A vigesimal digit in range [0, 19].
Returns¶
tuple[int, int] (bars, dots) where bars in [0, 3] and dots in [0, 4].
Raises¶
ValueError If digit is outside [0, 19].
Examples¶
to_bars_dots(0) (0, 0) to_bars_dots(7) (1, 2) to_bars_dots(19) (3, 4)
Source code in src/maya_encoding/core/vigesimal.py
maya_decompose(n, n_levels=None)
¶
Full Maya decomposition of a non-negative integer.
Returns the vigesimal digits, bars, and dots for each level.
Parameters¶
n : int Non-negative integer to decompose. n_levels : int or None Number of vigesimal levels. If None, auto-detected.
Returns¶
dict Dictionary with keys: - 'digits': list[int] — vigesimal digits (LSB first) - 'bars': list[int] — bars component per level - 'dots': list[int] — dots component per level - 'n_levels': int — number of levels used
Examples¶
maya_decompose(347) {'digits': [7, 17], 'bars': [1, 3], 'dots': [2, 2], 'n_levels': 2} maya_decompose(0) {'digits': [0], 'bars': [0], 'dots': [0], 'n_levels': 1}
Source code in src/maya_encoding/core/vigesimal.py
auto_n_levels(max_value)
¶
Calculate the minimum number of vigesimal levels needed to represent a value.
Parameters¶
max_value : int or float The maximum absolute value to represent.
Returns¶
int Number of vigesimal levels needed (minimum 1).
Examples¶
auto_n_levels(19) 1 auto_n_levels(20) 2 auto_n_levels(399) 2 auto_n_levels(400) 3
Source code in src/maya_encoding/core/vigesimal.py
maya_encode_array(values, n_levels, components='full', normalize=True)
¶
Vectorized Maya encoding for a 1D array of non-negative integers.
Parameters¶
values : np.ndarray 1D array of non-negative integers. n_levels : int Number of vigesimal levels to use. components : str Which components to include: - 'full': digits, bars, and dots (3 features per level) - 'lite': digits only (1 feature per level) - 'bars_dots': bars and dots only (2 features per level) normalize : bool If True, normalize each component to [0, 1].
Returns¶
np.ndarray 2D array of shape (len(values), n_features). n_features = n_levels * features_per_level.
Source code in src/maya_encoding/core/vigesimal.py
Calendar Functions¶
maya_encoding.core.calendar
¶
Maya calendar conversion functions.
Implements conversions from Gregorian dates to the three Maya calendar systems: - Tzolk'in (260-day sacred calendar): 13 numbers x 20 day names - Haab' (365-day solar calendar): 18 months of 20 days + 5-day Wayeb' - Long Count (linear day count): mixed-radix system (20, 20, 18, 20, 20...)
All conversions go through Julian Day Number (JDN) as intermediate representation. Uses the GMT (Goodman-Martinez-Thompson) correlation constant (JDN 584283) by default.
gregorian_to_jdn(date)
¶
Convert a Gregorian date to Julian Day Number (JDN).
Uses the standard algorithm for proleptic Gregorian calendar.
Parameters¶
date : DateLike The date to convert.
Returns¶
int Julian Day Number.
Examples¶
gregorian_to_jdn('2012-12-21') 2456283
Source code in src/maya_encoding/core/calendar.py
jdn_to_tzolkin(jdn, epoch_jdn=GMT_EPOCH_JDN)
¶
Convert a Julian Day Number to Tzolk'in date.
The Tzolk'in is a 260-day cycle composed of two interlocking sub-cycles: - A number from 1 to 13 - A day name from 0 to 19 (index into TZOLKIN_DAY_NAMES)
Since gcd(13, 20) = 1, every combination occurs exactly once per 260 days.
Parameters¶
jdn : int Julian Day Number. epoch_jdn : int JDN of the Maya epoch (default: GMT correlation).
Returns¶
tuple[int, int] (number, day_name_index) where number in [1, 13] and day_name_index in [0, 19].
Examples¶
jdn_to_tzolkin(2456283) # 2012-12-21 = 4 Ajaw (4, 19)
Source code in src/maya_encoding/core/calendar.py
jdn_to_haab(jdn, epoch_jdn=GMT_EPOCH_JDN)
¶
Convert a Julian Day Number to Haab' date.
The Haab' is a 365-day cycle: - 18 months of 20 days each (months 0-17) - 1 short month "Wayeb'" of 5 days (month 18)
Parameters¶
jdn : int Julian Day Number. epoch_jdn : int JDN of the Maya epoch (default: GMT correlation).
Returns¶
tuple[int, int] (month_index, day) where month_index in [0, 18] and day in [0, 19] (or [0, 4] for Wayeb' month 18).
Examples¶
jdn_to_haab(2456283) # 2012-12-21 = 3 K'ank'in (13, 3)
Source code in src/maya_encoding/core/calendar.py
jdn_to_long_count(jdn, n_levels=5, epoch_jdn=GMT_EPOCH_JDN)
¶
Convert a Julian Day Number to Maya Long Count.
The Long Count is a mixed-radix system: - Level 0: kin (1 day) - Level 1: uinal (20 kin) - Level 2: tun (18 uinal = 360 days) ← calendar exception - Level 3: katun (20 tun = 7,200 days) - Level 4: baktun (20 katun = 144,000 days)
Parameters¶
jdn : int Julian Day Number. n_levels : int Number of Long Count levels to return (1-5). Default 5 (full). epoch_jdn : int JDN of the Maya epoch.
Returns¶
tuple[int, ...] Long Count digits from highest to lowest level. For n_levels=5: (baktun, katun, tun, uinal, kin).
Examples¶
jdn_to_long_count(2456283) # 2012-12-21 = 13.0.0.0.0 (13, 0, 0, 0, 0)
Source code in src/maya_encoding/core/calendar.py
is_wayeb(jdn, epoch_jdn=GMT_EPOCH_JDN)
¶
Check if a Julian Day Number falls in the 5-day Wayeb' period.
Parameters¶
jdn : int Julian Day Number. epoch_jdn : int JDN of the Maya epoch.
Returns¶
bool True if the date is in Wayeb'.
Source code in src/maya_encoding/core/calendar.py
dates_to_jdn_array(dates)
¶
Convert an array of dates to Julian Day Numbers.
Parameters¶
dates : array-like Array of dates (strings, datetime, timestamps, or numpy datetime64).
Returns¶
np.ndarray 1D array of JDN integers.