Skip to main content
kspace

Documentation

Tools for generating and analyzing Gaussian random fields (GRFs) and their power spectra on regular grids, in 1, 2, or 3 dimensions. Built for astrophysical/cosmological applications where fields are specified by a power spectrum in Fourier space and realized on a real-space grid.

Features:

  • Generate scalar or vector Gaussian random field realizations from an arbitrary power spectrum (GaussianRandomField), including divergence-free vector fields.
  • Built-in power spectrum models (PowerLaw, PowerLawBetaModel), or supply your own callable.
  • FFT-based analysis (FourierAnalysis): binned power spectra, divergence and curl of vector fields, windowing to reduce FFT boundary effects.

Install

pip install kspace

For development, clone the repo and use uv:

uv sync

To also install the heavier dependencies used by the example notebooks (matplotlib, pandas, yt, h5py, pooch):

uv sync --group docs

Quick example

import numpy as np
from kspace import GaussianRandomField, FourierAnalysis, PowerLawBetaModel

# A power-law power spectrum with large- and small-scale cutoffs
power_spec = PowerLawBetaModel(l_min=10.0, l_max=200.0, alpha=-11.0 / 3.0)
power_spec.renormalize(f_rms=10.0)

le = np.array([0.0, 0.0, 0.0])
re = np.array([750.0, 750.0, 750.0])
ddims = [256, 256, 256]

grf = GaussianRandomField(le, re, ddims, power_spec, seed=10)
field = grf.generate_scalar_field_realization()

fa = FourierAnalysis(re - le, ddims)
kbins, pk = fa.make_binned_powerspec(field, nbins=60)

See docs/examples/ for more complete, runnable notebooks (GRF generation, vector field decomposition, power spectrum estimation, and analysis of simulation data).

Metadata

Release files for kspace 0.1.0

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

Source distribution (sdist)

Source distribution for kspace 0.1.0
File Size Uploaded
kspace-0.1.0.tar.gz 1.7 MB Details

Built distribution (wheel)

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

Total release size: 1.7 MB

Release files / kspace-0.1.0.tar.gz

Download URL kspace-0.1.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
a8c9e93e8c33216463708759a5d474b38f9e260f0188c0d6eb32c0a0274a7fbf
BLAKE2b-256 checksum
How to use checksums
71c8d2d6be49eb47bb89a746868ed317e83360873a8a58304fcd951ef8976d3d
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 Aug 11, 2026.

Transparency log

Release files / kspace-0.1.0-py3-none-any.whl

Download URL kspace-0.1.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cdc29773f5ba1b3e047c6b8850b4bae19577b022d4563cb3c3c25bc71790a9a
BLAKE2b-256 checksum
How to use checksums
bcbabc136dc390e6f7c59974c6e23134aa9fb4721c49a016ce8e7384347996f0
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 Aug 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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