Skip to main content

Space Curves (spacecurves, Uzay Eğrileri) Space Curves (spacecurves, Uzay Eğrileri)

PyPI version License: AGPL DOI WorkflowHub DOI figshare DOI

Anaconda-Server Badge Anaconda-Server Badge Anaconda-Server Badge Anaconda-Server Badge

Open Source Documentation Status OpenSSF Best Practices

Python CI codecov Documentation Status Binder

PyPI version Contributor Covenant Linted with Ruff Lang:Python

PyPI Downloads PyPI Downloads PyPI Downloads


PyPI PyPI version
Conda conda-forge version
DOI DOI
License: AGPL License


Space Curves (spacecurves, Uzay Eğrileri)

# Space Curves (spacecurves) / Uzay Eğrileri

[![License](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)](https://www.python.org/)
[![Version](https://img.shields.io/badge/version-0.1.0-green.svg)]()

> **English** | [Türkçe](#türkçe)

---

## English

### 📌 Overview

**Space Curves (spacecurves)** is a comprehensive Python module for space-filling curves, providing a complete implementation of Hilbert curves and other space-filling curves with advanced features.

### ✨ Features

- **Multi-dimensional support**: 1-5 dimensions
- **Configurable depth**: 1-10 iterations (2^p grid size)
- **3 curve types**: Hilbert, Morton, Moore
- **High performance**: LRU cache support, batch operations
- **Neighbor search**: Find neighbors in Hilbert space
- **Image compression**: Hilbert curve-based image compression
- **Dimension reduction**: High-dimensional data → 2D visualization
- **Hilbert ordering**: Spatial data organization
- **Grid system**: Hilbert-based data structure
- **Path optimization**: TSP-like route optimization
- Görselleştirme araçları (HilbertVisualizer)
- Yaklaşık kümeleme (HilbertClustering)

### 🚀 Quick Start

```python
from spacecurves import SpaceFillingCurve, CurveType

# Create a 2D Hilbert curve (16x16 grid)
curve = SpaceFillingCurve(p=4, n=2)

# Transform: distance → coordinates
point = curve[42]           # [7, 0]

# Inverse transform: coordinates → distance
distance = curve.inverse([7, 0])  # 42

# Batch transform
distances = [0, 10, 20, 30, 40]
points = curve.batch_transform(distances)

# Find neighbors
neighbors = curve.get_neighbors([5, 5], radius=2)

📦 Installation

pip install spacecurves

Or directly from source:

git clone https://github.com/yourusername/spacecurves.git
cd spacecurves
pip install -e .

📚 Examples

1. GPS Coordinate Indexing

from spacecurves import SpaceFillingCurve

curve = SpaceFillingCurve(p=8, n=2)

# City coordinates (latitude, longitude)
cities = {
    'Istanbul': [41.0082, 28.9784],
    'Ankara': [39.9334, 32.8597],
}

# Convert to Hilbert index
for name, coord in cities.items():
    x = int((coord[0] - 36) / 6 * 255)
    y = int((coord[1] - 26) / 15 * 255)
    idx = curve.inverse([x, y])
    print(f"{name}: {idx}")

2. Image Compression

import numpy as np
from spacecurves import HilbertImageCompressor

# Create test image
image = np.random.randint(0, 256, (256, 256), dtype=np.uint8)

# Compress
compressor = HilbertImageCompressor(image)
compressed = compressor.compress(keep_ratio=0.2)  # Keep 20% of pixels

3. Dimension Reduction

from spacecurves import HilbertDimensionReducer

# 10D data → 2D visualization
reducer = HilbertDimensionReducer(target_dim=2, p=6)
reduced = reducer.fit_transform(high_dim_data)

4. Route Optimization

from spacecurves import HilbertPathOptimizer

curve = SpaceFillingCurve(p=8, n=2)
optimizer = HilbertPathOptimizer(curve)

# Optimize delivery route
optimized_route = optimizer.optimize_order(delivery_points)

5. Hilbert Grid

from spacecurves import HilbertGrid

grid = HilbertGrid(curve)
grid[[10, 20]] = "Value A"
grid[[30, 40]] = "Value B"

print(grid[[10, 20]])  # Value A

🔧 API Reference

SpaceFillingCurve(p, n, curve_type=CurveType.HILBERT, use_cache=True)

Parameter Type Default Description
p int required Iteration count (2^p grid size), 1-10
n int required Number of dimensions, 1-5
curve_type CurveType HILBERT Curve type
use_cache bool True Enable caching

Methods:

Method Description
transform(distance) Convert distance to coordinates
inverse(point) Convert coordinates to distance
batch_transform(distances) Batch conversion
batch_inverse(points) Batch inverse conversion
get_neighbors(point, radius) Find neighbors
sample(n_points, method) Sample points along curve

Curve Types

Type Description Best For
HILBERT Classic Hilbert curve General purpose
MORTON Z-order curve Fast indexing
MOORE Moore curve (Hilbert variant) Closed loops
ALTAIR Hybrid curve Speed/locality balance

📊 Performance

  • Transform speed: ~2.6M ops/sec (2D, p=4)
  • Cache hit rate: >95% with repeated queries
  • Grid access: ~0.01ms per operation

📄 License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-or-later).

👤 Author

Mehmet Keçeci
Email: mkececi@yaani.com


Türkçe

📌 Genel Bakış

Space Curves (spacecurves), uzay dolduran eğriler için kapsamlı bir Python modülüdür. Hilbert eğrisi ve diğer uzay dolduran eğrilerin tam bir implementasyonunu gelişmiş özelliklerle sunar.

✨ Özellikler

  • Çok boyutlu destek: 1-5 boyut
  • Ayarlanabilir derinlik: 1-16 iterasyon (2^p grid boyutu)
  • 3 eğri tipi: Hilbert, Morton, Moore
  • Yüksek performans: LRU önbellek, toplu işlemler
  • Komşuluk arama: Hilbert uzayında komşu bulma
  • Görüntü sıkıştırma: Hilbert eğrisi tabanlı görüntü sıkıştırma
  • Boyut indirgeme: Yüksek boyutlu veri → 2D görselleştirme
  • Hilbert sıralama: Mekansal veri düzenleme
  • Grid sistemi: Hilbert tabanlı veri yapısı
  • Rota optimizasyonu: TSP benzeri rota optimizasyonu
  • Görselleştirme araçları (HilbertVisualizer)
  • Yaklaşık kümeleme (HilbertClustering)

🚀 Hızlı Başlangıç

from spacecurves import SpaceFillingCurve, CurveType

# 2D Hilbert eğrisi oluştur (16x16 grid)
curve = SpaceFillingCurve(p=4, n=2)

# Dönüşüm: mesafe → koordinat
point = curve[42]           # [7, 0]

# Ters dönüşüm: koordinat → mesafe
distance = curve.inverse([7, 0])  # 42

# Toplu dönüşüm
distances = [0, 10, 20, 30, 40]
points = curve.batch_transform(distances)

# Komşu bulma
neighbors = curve.get_neighbors([5, 5], radius=2)

📦 Kurulum

pip install spacecurves

Veya doğrudan kaynaktan:

git clone https://github.com/WhiteSymmetry/spacecurves.git
cd spacecurves
pip install -e .

📚 Örnekler

1. GPS Koordinat İndeksleme

from spacecurves import SpaceFillingCurve

curve = SpaceFillingCurve(p=8, n=2)

# Şehir koordinatları (enlem, boylam)
sehirler = {
    'İstanbul': [41.0082, 28.9784],
    'Ankara': [39.9334, 32.8597],
}

# Hilbert indeksine dönüştür
for ad, koord in sehirler.items():
    x = int((koord[0] - 36) / 6 * 255)
    y = int((koord[1] - 26) / 15 * 255)
    idx = curve.inverse([x, y])
    print(f"{ad}: {idx}")

2. Görüntü Sıkıştırma

import numpy as np
from spacecurves import HilbertImageCompressor

# Test görüntüsü oluştur
gorsel = np.random.randint(0, 256, (256, 256), dtype=np.uint8)

# Sıkıştır
sikistirici = HilbertImageCompressor(gorsel)
sikistirilmis = sikistirici.compress(keep_ratio=0.2)  # Piksellerin %20'sini tut

3. Boyut İndirgeme

from spacecurves import HilbertDimensionReducer

# 10D veri → 2D görselleştirme
indirgeyici = HilbertDimensionReducer(target_dim=2, p=6)
indirgenmis = indirgeyici.fit_transform(yuksek_boyutlu_veri)

4. Rota Optimizasyonu

from spacecurves import HilbertPathOptimizer

curve = SpaceFillingCurve(p=8, n=2)
optimizer = HilbertPathOptimizer(curve)

# Teslimat rotasını optimize et
optimize_rota = optimizer.optimize_order(teslimat_noktalari)

5. Hilbert Grid

from spacecurves import HilbertGrid

grid = HilbertGrid(curve)
grid[[10, 20]] = "Değer A"
grid[[30, 40]] = "Değer B"

print(grid[[10, 20]])  # Değer A

🔧 API Referansı

SpaceFillingCurve(p, n, curve_type=CurveType.HILBERT, use_cache=True)

Parametre Tip Varsayılan Açıklama
p int gerekli İterasyon sayısı (2^p grid boyutu), 1-10
n int gerekli Boyut sayısı, 1-5
curve_type CurveType HILBERT Eğri tipi
use_cache bool True Önbellek kullanımı

Metotlar:

Metot Açıklama
transform(distance) Mesafeyi koordinata dönüştürür
inverse(point) Koordinatı mesafeye dönüştürür
batch_transform(distances) Toplu dönüşüm
batch_inverse(points) Toplu ters dönüşüm
get_neighbors(point, radius) Komşuları bulur
sample(n_points, method) Eğri boyunca örnek noktalar

Eğri Tipleri

Tip Açıklama En İyi Kullanım Alanı
HILBERT Klasik Hilbert eğrisi Genel amaçlı
MORTON Z-order eğrisi Hızlı indeksleme
MOORE Moore eğrisi (Hilbert varyantı) Kapalı döngüler
ALTAIR Hibrid eğri Hız/lokalite dengesi

📊 Performans

  • Dönüşüm hızı: ~2.6M işlem/saniye (2D, p=4)
  • Önbellek isabet oranı: Tekrarlı sorgularda >%95
  • Grid erişimi: ~0.01ms işlem başına

📄 Lisans

Bu proje GNU Affero General Public License v3.0 (AGPL-3.0-or-later) ile lisanslanmıştır.

👤 Yazar

Mehmet Keçeci


Acknowledgments / Teşekkürler

  • Hilbert curve algorithm based on the work of David Hilbert (1891)
  • Morton order (Z-order curve) by Guy Macdonald Morton (1966)
  • Moore curve by E. H. Moore (1900)

---

# Pixi:

[![Pixi](https://img.shields.io/badge/Pixi-Pixi-brightgreen.svg)](https://prefix.dev/channels/bilgi)

pixi init spacecurves

cd spacecurves

pixi workspace channel add [https://prefix.dev/channels/bilgi](https://prefix.dev/channels/bilgi) --prepend

✔ Added https://prefix.dev/channels/bilgi

pixi add spacecurves

✔ Added spacecurves >=...,<1

pixi install

pixi shell

pixi run python -c "import spacecurves; print(spacecurves.__version__)"

### Çıktı: 

pixi remove spacecurves

conda install -c https://prefix.dev/channels/bilgi spacecurves

pixi run python -c "import spacecurves; print(spacecurves.__version__)"

### Çıktı: 

pixi run pip list | grep spacecurves

### spacecurves  

pixi run pip show spacecurves

Name: spacecurves

Version: 

Summary: Keçeci Numbers: Keçeci Sayıları (Keçeci Conjecture)

Home-page: https://github.com/WhiteSymmetry/spacecurves

Author: Mehmet Keçeci

Author-email: Mehmet Keçeci <...>

License: GNU AFFERO GENERAL PUBLIC LICENSE

Copyright (c) 2025-2026 Mehmet Keçeci

----

1. https://pypi.org/project/spacecurves/
2. https://anaconda.org/bilgi/spacecurves
3. https://prefix.dev/channels/bilgi/packages/spacecurves

---

## License / Lisans

This project is licensed under the AGPL3.0 or Later License. See the `LICENSE` file for details.

## Citation

If this library was useful to you in your research, please cite us. Following the [GitHub citation standards](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files), here is the recommended citation.

### BibTeX

```bibtex
@misc{kececi_2026_19672791,
  author       = {Keçeci, Mehmet},
  title        = {spacecurves},
  month        = apr,
  year         = 2026,
  publisher    = {Zenodo},
  version      = {0.1.3},
  doi          = {10.5281/zenodo.19672791},
  url          = {https://doi.org/10.5281/zenodo.19672791},
}

APA


Keçeci, M. (2026). spacecurves (0.1.3). Open Science Articles (OSAs), Zenodo. https://doi.org/10.5281/zenodo.19672791

Metadata

Release files for spacecurves 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spacecurves 0.1.5
File Size Uploaded
spacecurves-0.1.5.tar.gz 38.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spacecurves 0.1.5
File Interpreter ABI Platform
spacecurves-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 71.1 kB

Release files / spacecurves-0.1.5.tar.gz

Download URL spacecurves-0.1.5.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
be7db5a9b1fe4b21be9a0a564b84a08847df9b8e6ad57d4e113f820373ae3739
BLAKE2b-256 checksum
How to use checksums
eee55bc148f4bde8a094986f63dc0758b599eb7eb10b70d6dd1bdc3d2e399b72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / spacecurves-0.1.5-py3-none-any.whl

Download URL spacecurves-0.1.5-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7cbcabfe39b3c7a61274ff0c5a22d9a74b0ee8e53b6a542610744b432fc9f8b9
BLAKE2b-256 checksum
How to use checksums
61106783f5cb93104f87d910c86b6bce7243fa34ce29f4feb045c8667ed3f0c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page