subhaloscript 1.0.10__tar.gz → 1.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/.claude/skills/galacticus-analysis/SKILL.md +139 -17
- subhaloscript-1.1.1/.claude/skills/galacticus-analysis/references/subscript_functions.md +1814 -0
- subhaloscript-1.1.1/.claude/skills/update/SKILL.md +121 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/.github/workflows/main.yml +1 -1
- subhaloscript-1.1.1/PKG-INFO +145 -0
- subhaloscript-1.1.1/README.md +128 -0
- subhaloscript-1.1.1/example-notebooks/basic-usage.ipynb +319 -0
- subhaloscript-1.1.1/example-notebooks/units.ipynb +260 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/meta.yaml +2 -1
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/pyproject.toml +2 -2
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/defaults.py +28 -4
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/macros.py +15 -1
- subhaloscript-1.1.1/subscript/subhalo_timeseries.py +79 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/tabulatehdf5.py +21 -10
- subhaloscript-1.1.1/subscript/units.py +178 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/wrappers.py +52 -5
- subhaloscript-1.1.1/tests/data/dump.txt +91034 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_histograms.py +1 -0
- subhaloscript-1.1.1/tests/test_units.py +289 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_wrappers.py +5 -2
- subhaloscript-1.0.10/.claude/skills/update/SKILL.md +0 -55
- subhaloscript-1.0.10/PKG-INFO +0 -27
- subhaloscript-1.0.10/README.md +0 -11
- subhaloscript-1.0.10/example-notebooks/basic-usage.ipynb +0 -339
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/.gitignore +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/LICENSE +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/external.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/scripts/histograms.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/scripts/nfilters.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/scripts/nodes.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/scripts/spatial.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/tracking.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/subscript/util.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_macros.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_nfilters.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_nfilters_legacy.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_nodes.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_spatial.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_symphony.py +0 -0
- {subhaloscript-1.0.10 → subhaloscript-1.1.1}/tests/test_tabulatehdf5.py +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
**SubScript** is a Python library providing ergonomic utility functions for analyzing Galacticus semi-analytic model outputs.
|
|
4
4
|
|
|
5
5
|
**Repository:** https://github.com/cgannonucm/SubScript
|
|
6
|
-
**Package:** `subhaloscript` (v1.
|
|
6
|
+
**Package:** `subhaloscript` (v1.1.1)
|
|
7
7
|
**Author:** Charles Gannon (cgannon@ucmerced.edu)
|
|
8
8
|
|
|
9
9
|
---
|
|
@@ -101,10 +101,13 @@ ParamKeys.mass_halo_enclosed_current # Enclosed mass within radius
|
|
|
101
101
|
### Structural Properties
|
|
102
102
|
```python
|
|
103
103
|
ParamKeys.rvir # Virial radius
|
|
104
|
-
ParamKeys.scale_radius
|
|
104
|
+
ParamKeys.scale_radius / ParamKeys.rscale # Scale radius (r_s) for density profile
|
|
105
105
|
ParamKeys.density_profile_radius # Array of radii for density profile
|
|
106
106
|
ParamKeys.density_profile # Array of densities at radii
|
|
107
107
|
ParamKeys.concentration # Concentration parameter
|
|
108
|
+
ParamKeys.tnfw_rt # Tidal truncation radius (truncated NFW)
|
|
109
|
+
ParamKeys.tnfw_p0 # Density normalization (truncated NFW)
|
|
110
|
+
ParamKeys.dark_matter_profile_scale # Dark matter profile scale
|
|
108
111
|
```
|
|
109
112
|
|
|
110
113
|
### Classification & Hierarchy
|
|
@@ -134,6 +137,7 @@ ParamKeys.node_index # Unique node identifier (with indexS
|
|
|
134
137
|
ParamKeys.parent_index # Index of parent node
|
|
135
138
|
ParamKeys.satellite_index # Index if this is a satellite
|
|
136
139
|
ParamKeys.sibling_index # Index of sibling node
|
|
140
|
+
ParamKeys.subsampling_weight # Subsampling weight for node
|
|
137
141
|
```
|
|
138
142
|
|
|
139
143
|
### Tree Metadata
|
|
@@ -516,7 +520,9 @@ result = projected_subhalo_count(gout, normvector=np.identity(3))
|
|
|
516
520
|
|
|
517
521
|
## Time-Series Analysis: Tracking
|
|
518
522
|
|
|
519
|
-
Extract properties of individual subhalos across all Galacticus snapshots
|
|
523
|
+
Extract properties of individual subhalos across all Galacticus snapshots.
|
|
524
|
+
|
|
525
|
+
> **Prefer `subhalo_timeseries()`** when extracting time-series for subhalos in a full tree. It wraps `track_subhalos()` + `track_subhalo()` with automatic disk caching, making repeated runs significantly faster. Use the lower-level `track_subhalos()` / `track_subhalo()` directly only when you need fine-grained control over which nodes to track or which parameters to extract.
|
|
520
526
|
|
|
521
527
|
### track_subhalos() - Extract Full Time-Series
|
|
522
528
|
|
|
@@ -573,6 +579,43 @@ plt.xlabel('Redshift')
|
|
|
573
579
|
plt.ylabel('Bound Mass [M_☉]')
|
|
574
580
|
```
|
|
575
581
|
|
|
582
|
+
### subhalo_timeseries() - Cached Full-Tree Time-Series
|
|
583
|
+
|
|
584
|
+
Convenience wrapper that extracts and **caches** time-series for every subhalo in a tree:
|
|
585
|
+
|
|
586
|
+
```python
|
|
587
|
+
from subscript.subhalo_timeseries import subhalo_timeseries
|
|
588
|
+
|
|
589
|
+
# Extract (or load from cache) all subhalo time-series for tree 0
|
|
590
|
+
result = subhalo_timeseries(gout, tree_index=0)
|
|
591
|
+
|
|
592
|
+
# Force recompute, ignoring cache
|
|
593
|
+
result = subhalo_timeseries(gout, tree_index=0, refresh=True)
|
|
594
|
+
|
|
595
|
+
# result structure:
|
|
596
|
+
# result[node_id]['data'] -> dict of {param_key: time_series_array}
|
|
597
|
+
# result[node_id]['zsnaps'] -> corresponding redshift array
|
|
598
|
+
|
|
599
|
+
# Plot bound-mass evolution for a single subhalo
|
|
600
|
+
import matplotlib.pyplot as plt
|
|
601
|
+
from subscript.defaults import ParamKeys
|
|
602
|
+
|
|
603
|
+
for node_id, ts in result.items():
|
|
604
|
+
plt.plot(ts['zsnaps'], ts['data'][ParamKeys.mass_bound])
|
|
605
|
+
|
|
606
|
+
plt.xlabel('Redshift')
|
|
607
|
+
plt.ylabel('Bound Mass [M_☉]')
|
|
608
|
+
plt.show()
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**Cache behaviour:**
|
|
612
|
+
- Cache file is written to the same directory as the HDF5 file
|
|
613
|
+
- Filename: `{stem}-{sha256[:16]}-tree{tree_index}.pkl`
|
|
614
|
+
- Cache is invalidated automatically when the file content changes (hash-based)
|
|
615
|
+
- Pass `refresh=True` to force recomputation
|
|
616
|
+
|
|
617
|
+
**Requirements:** same as `track_subhalos()` — Galacticus must be run with `<nodeOperator value="indexShift" />`.
|
|
618
|
+
|
|
576
619
|
---
|
|
577
620
|
|
|
578
621
|
## Batch Processing: Macros
|
|
@@ -646,11 +689,83 @@ with h5py.File('analysis_results.hdf5', 'w') as f:
|
|
|
646
689
|
```python
|
|
647
690
|
from subscript.defaults import Meta
|
|
648
691
|
|
|
649
|
-
# Cache HDF5 reads in memory (default: True, faster but uses memory)
|
|
650
|
-
Meta.cache = True
|
|
651
|
-
|
|
652
692
|
# Disable deprecation warnings for old filter names
|
|
653
693
|
Meta.disableDepreciatedWarning = False
|
|
694
|
+
|
|
695
|
+
# Units system (see Astropy Units Integration below)
|
|
696
|
+
Meta.units_enable = False # Enable/disable astropy units (default: False)
|
|
697
|
+
Meta.units_in_si = None # Dict mapping keys → astropy SI units
|
|
698
|
+
Meta.units_in_si_conversion = None # Dict mapping keys → numerical SI conversion factors
|
|
699
|
+
Meta.unit_bases = [apu.Msun, apu.kpc, apu.Myr] # Base units for decomposition
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## Astropy Units Integration
|
|
705
|
+
|
|
706
|
+
SubScript supports optional astropy units on all node properties via `subscript.units`.
|
|
707
|
+
|
|
708
|
+
### Quick Setup
|
|
709
|
+
|
|
710
|
+
```python
|
|
711
|
+
import h5py
|
|
712
|
+
from subscript.units import enableUnitsFromGalacticus
|
|
713
|
+
|
|
714
|
+
gout = h5py.File('galacticus.hdf5')
|
|
715
|
+
|
|
716
|
+
# Read unitsInSI from the HDF5 file and enable units globally
|
|
717
|
+
enableUnitsFromGalacticus(gout)
|
|
718
|
+
|
|
719
|
+
# Now all nodedata() calls return astropy Quantities in the base unit system
|
|
720
|
+
# Default bases: [Msun, kpc, Myr]
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### Functions
|
|
724
|
+
|
|
725
|
+
#### `galacticus_units_si(gal_out)` — Extract SI conversion factors
|
|
726
|
+
|
|
727
|
+
Reads the `unitsInSI` attribute from every dataset in the final output's `nodeData` group and returns a dict of `{property_name: conversion_factor}`.
|
|
728
|
+
|
|
729
|
+
```python
|
|
730
|
+
from subscript.units import galacticus_units_si
|
|
731
|
+
|
|
732
|
+
units_si = galacticus_units_si(gout)
|
|
733
|
+
# units_si['basicMass'] → 1.989e30 (kg per unit stored in file)
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
#### `enableUnits(units_in_si_conversion, units_in_si=UNITS_IN_SI, base_units=Meta.unit_bases)` — Enable units manually
|
|
737
|
+
|
|
738
|
+
```python
|
|
739
|
+
from subscript.units import enableUnits, UNITS_IN_SI
|
|
740
|
+
from subscript.units import galacticus_units_si
|
|
741
|
+
|
|
742
|
+
conversion = galacticus_units_si(gout)
|
|
743
|
+
enableUnits(conversion)
|
|
744
|
+
# Meta.units_enable is now True; node properties return astropy Quantities
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
#### `enableUnitsFromGalacticus(galacticus_output, ...)` — Enable from file
|
|
748
|
+
|
|
749
|
+
Convenience wrapper that calls `galacticus_units_si()` then `enableUnits()` in one step.
|
|
750
|
+
|
|
751
|
+
### `UNITS_IN_SI` — Default unit map
|
|
752
|
+
|
|
753
|
+
Pre-built dict mapping all `ParamKeys` to their astropy SI units:
|
|
754
|
+
|
|
755
|
+
```python
|
|
756
|
+
from subscript.units import UNITS_IN_SI
|
|
757
|
+
from astropy import units as apu
|
|
758
|
+
|
|
759
|
+
# Examples:
|
|
760
|
+
# UNITS_IN_SI[ParamKeys.mass_basic] → apu.kg
|
|
761
|
+
# UNITS_IN_SI[ParamKeys.x] → apu.m
|
|
762
|
+
# UNITS_IN_SI[ParamKeys.rvir] → apu.m
|
|
763
|
+
# UNITS_IN_SI[ParamKeys.satellite_tidal_field] → 1/apu.s**2
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
When units are enabled, `NodeProperties.__getitem__` automatically converts values:
|
|
767
|
+
```python
|
|
768
|
+
out_quantity = (raw_value * conversion_factor * si_unit).decompose(base_units)
|
|
654
769
|
```
|
|
655
770
|
|
|
656
771
|
---
|
|
@@ -831,7 +946,7 @@ result = subhalo_statistics(
|
|
|
831
946
|
|
|
832
947
|
## Units & Conventions
|
|
833
948
|
|
|
834
|
-
- **Default coordinates**:
|
|
949
|
+
- **Default coordinates**: physical (not comoving)
|
|
835
950
|
- **Distance**: Megaparsecs (Mpc) unless otherwise noted
|
|
836
951
|
- **Mass**: Solar masses (M_☉)
|
|
837
952
|
- **Time**: Gigayears (Gyr) or Billions of years
|
|
@@ -841,9 +956,6 @@ For cosmological conversions, use `colossus`:
|
|
|
841
956
|
from colossus.cosmology import cosmology
|
|
842
957
|
cosmo = cosmology.setCosmology("planck18")
|
|
843
958
|
|
|
844
|
-
# Convert comoving to physical distance
|
|
845
|
-
physical_distance = comoving_distance / (1 + z)
|
|
846
|
-
|
|
847
959
|
# Convert kpc to arcsec at redshift z
|
|
848
960
|
rad_to_arcsec = 2.06E5
|
|
849
961
|
kpc_to_arcsec = (1E-3 / cosmo.angularDiameterDistance(z)) * rad_to_arcsec
|
|
@@ -868,13 +980,6 @@ A: tracking.py requires Galacticus to output node indices consistently across sn
|
|
|
868
980
|
<nodeOperator value="indexShift" />
|
|
869
981
|
```
|
|
870
982
|
|
|
871
|
-
**Q: Memory issues with large files**
|
|
872
|
-
A: Disable caching:
|
|
873
|
-
```python
|
|
874
|
-
from subscript.defaults import Meta
|
|
875
|
-
Meta.cache = False
|
|
876
|
-
```
|
|
877
|
-
|
|
878
983
|
**Q: Deprecation warnings for old filter names**
|
|
879
984
|
A: Use new filter names (e.g., `subhalos()` instead of `nfilter_subhalos()`)
|
|
880
985
|
|
|
@@ -890,12 +995,29 @@ pandas
|
|
|
890
995
|
scipy
|
|
891
996
|
h5py
|
|
892
997
|
scikit-learn
|
|
998
|
+
astropy
|
|
893
999
|
```
|
|
894
1000
|
|
|
895
1001
|
---
|
|
896
1002
|
|
|
897
1003
|
## References
|
|
898
1004
|
|
|
1005
|
+
### Comprehensive Function Reference
|
|
1006
|
+
|
|
1007
|
+
📄 **`references/subscript_functions.md`**
|
|
1008
|
+
|
|
1009
|
+
Complete documentation of all SubScript functions organized by module:
|
|
1010
|
+
- **Function signatures** with full parameter descriptions
|
|
1011
|
+
- **Return types** and data structures
|
|
1012
|
+
- **Usage examples** for each function
|
|
1013
|
+
- **Implementation notes** and performance considerations
|
|
1014
|
+
- **Complete parameter key reference** (50+ available properties)
|
|
1015
|
+
- **Summary table** of all functions by category
|
|
1016
|
+
|
|
1017
|
+
Use this document for detailed function lookup and integration into custom analysis workflows.
|
|
1018
|
+
|
|
1019
|
+
### Other Resources
|
|
1020
|
+
|
|
899
1021
|
- **Public Repository**: https://github.com/cgannonucm/SubScript
|
|
900
1022
|
- **Galacticus**: https://github.com/galacticusorg/galacticus
|
|
901
1023
|
- **Example Notebooks**: See `example-notebooks/` in the repository
|