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).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kspace-0.1.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

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

kspace-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file kspace-0.1.0.tar.gz.

File metadata

  • Download URL: kspace-0.1.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kspace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a8c9e93e8c33216463708759a5d474b38f9e260f0188c0d6eb32c0a0274a7fbf
MD5 958b9507ca19240c08bc6d9b8110bd21
BLAKE2b-256 71c8d2d6be49eb47bb89a746868ed317e83360873a8a58304fcd951ef8976d3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kspace-0.1.0.tar.gz:

Publisher: publish.yml on jzuhone/kspace

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

File details

Details for the file kspace-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kspace-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kspace-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cdc29773f5ba1b3e047c6b8850b4bae19577b022d4563cb3c3c25bc71790a9a
MD5 39f1ddf93fef44c5b05e70d217f60101
BLAKE2b-256 bcbabc136dc390e6f7c59974c6e23134aa9fb4721c49a016ce8e7384347996f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for kspace-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jzuhone/kspace

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 Sentry Error logging StatusPage Status page