Skip to main content

Utility functions for analyzing subhalo distributions.

Project description

SubScript

The subscript python package provides a library of ergonomic utility functions for analyzing Galacticus subhalo data. Example notebooks can be found in the example-notebooks/ directory.

Installation

Install via pip

pip install subhaloscript

Install via conda

conda install cgannonucm::subhaloscript

Features

Statistics Across Multiple Trees

Galacticus outputs contain multiple independent merger trees. SubScript automatically separates nodes into their respective trees and provides built-in statistical summarization across all of them. Pass summarize=True and statfuncs=[np.mean, np.std] to any analysis function to get the mean and standard deviation computed over all trees in a single call.

from subscript.scripts.histograms import massfunction
import subscript.scripts.nfilters as nf

out = massfunction(
    gout,
    bins=np.logspace(9, 13, 30),
    nfilter=nf.subhalos,
    summarize=True,
    statfuncs=[np.mean, np.std],
)
dndm_mean, mbins = out[0]
dndm_std, _      = out[1]

Node Filtering

Select subsets of nodes using composable filter functions. Filters can be combined with boolean logic and "frozen" for reuse.

import subscript.scripts.nfilters as nf

# Built-in filters
mass = nodedata(gout, key='basicMass', nfilter=nf.subhalos)
mass = nodedata(gout, key='basicMass', nfilter=nf.hosthalos)

# Spatial filters
inner = nf.r3d(None, 0, 0.05)  # Within 50 kpc (in Mpc)

# Combine with boolean logic
inner_subhalos = nf.logical_and(nf.subhalos, inner)
mass = nodedata(gout, key='basicMass', nfilter=inner_subhalos)

Write Once, Reuse Everywhere

The @gscript decorator wraps any analysis function to automatically handle input formatting, node filtering, multi-tree iteration, and statistical summarization. Write your analysis logic once and reuse it across different files, filters, and statistical configurations.

from subscript.wrappers import gscript
from subscript.defaults import ParamKeys

@gscript
def mass_ratio(gout, **kwargs):
    return np.mean(gout[ParamKeys.mass_bound] / gout[ParamKeys.mass_basic])

# Reuse with different filters, files, and statistics
result = mass_ratio(gout, nfilter=nf.subhalos, summarize=True, statfuncs=[np.mean, np.std])

Subhalo Tracking Across Snapshots

Track individual subhalos across all Galacticus output snapshots to study their evolution over time. The subhalo_timeseries() function extracts and caches per-subhalo time-series data for an entire tree.

from subscript.subhalo_timeseries import subhalo_timeseries

result = subhalo_timeseries(gout, tree_index=0)

for node_id, ts in result.items():
    plt.plot(ts['zsnaps'], ts['data'][ParamKeys.mass_bound])

Astropy Unit Integration

Optional astropy unit integration. When enabled, all node properties are returned as astropy Quantity objects with physical units, decomposed into a configurable base unit system (default: [Msun, Mpc, Myr]).

from subscript.units import enableUnitsFromGalacticus

enableUnitsFromGalacticus(gout)

mass = nodedata(gout, key=ParamKeys.mass_basic, nfilter=nf.hosthalos)
# mass is now an astropy Quantity in solar masses

rvir = nodedata(gout, key=ParamKeys.rvir, nfilter=nf.hosthalos)
print(rvir[0].to(apu.kpc))  # Convert Mpc to kpc

See example-notebooks/units.ipynb for a full walkthrough.

Claude Code Skill

This repository includes a Claude Code skill that gives Claude detailed knowledge of the SubScript library. To use it in your project, copy the skill directory into your project's .claude/skills/ folder:

# From your project root
mkdir -p .claude/skills
cp -r /path/to/SubScript/.claude/skills/galacticus-analysis .claude/skills/

When using Claude Code in your project, invoke the skill with:

/galacticus-analysis

Claude will then have access to the full SubScript API reference, including all function signatures, parameter keys, filter patterns, and usage examples, allowing it to write correct SubScript analysis code for your Galacticus data.

Publication

If you use SubScript in your research, please cite:

Gannon et al. (2025). "Dark Matter Substructure: A Lensing Perspective" arXiv:2501.17362

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

subhaloscript-1.1.7.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

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

subhaloscript-1.1.7-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file subhaloscript-1.1.7.tar.gz.

File metadata

  • Download URL: subhaloscript-1.1.7.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for subhaloscript-1.1.7.tar.gz
Algorithm Hash digest
SHA256 753bae40e18d0c0c0df37749b8f1fae5a08aec4e64a75793e0683c87c8e26dda
MD5 3d1c5aa040d3c387f779854c8fc3159c
BLAKE2b-256 088882d02c4c72d6ca5da72bb1a152a12f8cf8a29e9df108b7998314b34154cb

See more details on using hashes here.

File details

Details for the file subhaloscript-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: subhaloscript-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for subhaloscript-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 45542cc3ad325122d2c3e7439bad7474c8549ad187d421290a57cbc3143619e1
MD5 701c8ac93dec5f0e471d882e4a307f1f
BLAKE2b-256 966555fd43bc9e6c8f6fb1214d5715bd77320f5e7ab9a44a3f811794e21091d6

See more details on using hashes here.

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