kelpie
The kelpie galaxy groupfinder
Install
pip install kelpie-groupfinder
The package installs as kelpie-groupfinder but is imported as kelpie, and provides a
kelpie command. For development, clone the repository and run pip install -e ..
numba-kdtree is compiled from source on some platforms. If its build fails with missing
C++ headers (e.g. 'cstdlib' file not found), fix your compiler setup or install into a
fresh conda environment.
See examples/example_notebook.ipynb for a full walk-through
on a random mock catalogue.
Run from a config file
Copy and edit examples/example_config.yaml, then:
kelpie path/to/config.yaml # or: python -m kelpie path/to/config.yaml
This loads the catalogue, runs the finder and writes the membership and group-property
parquet files given in file_locations. With run_mock_comparison: True (and
column_names.group_id set) it also prints the S-score.
The same thing from Python: kelpie.run_from_config("config.yaml").
Run as a package
Everything goes through RedshiftCatalog:
from kelpie import RedshiftCatalog
cat = RedshiftCatalog(ra, dec, redshift, stellar_mass, completeness=completeness)
# or: RedshiftCatalog.from_file("cat.parquet", {"ra": "RAcen", "dec": "Deccen",
# "redshift": "Z", "stellar_mass": "stellar_mass"})
cat.set_cosmology(h=0.6751, omega_matter=0.3121) # optional: omega_baryon=, sigma8=, ns=
cat.set_free_parameters(alpha=6.0, beta=2.3, completeness_coefficient=0.33)
cat.set_shmr("Li") # or set_shmr("custom_constant", constant_ratio=100)
cat.set_centre_definition("iter_centre") # or "bcg"
cat.run()
cat.galaxy_groups # astropy Table: galaxy_id, kelpie_group_id
cat.groups # astropy Table: one row per group
cat.save("members.parquet", "groups.parquet")
All setters return the catalogue, so calls can be chained. Re-running after changing the free parameters reuses the distances, KD-tree and lookup grids, so tuning on a mock is cheap.
Optimising on a mock
optimise_on_mock tunes alpha and beta with scipy's Nelder-Mead to maximise the
S-score. Both are kept in 1.0-10.0 and rounded to 2 significant figures, starting from
the current values (6.0, 2.3 by default); completeness_coefficient is held fixed.
mock = RedshiftCatalog(ra, dec, z, sm, mock_group_ids=true_ids)
best = mock.optimise_on_mock()
best["alpha"], best["beta"], best["s_score"] # mock is left run at the best values
From a config, set run_options.optimise_on_mock: True (needs column_names.group_id);
the outputs are written using the optimised parameters.
The halo concentration-mass relation (colossus) needs a full cosmology. Beyond h and
omega_matter you can optionally pass omega_baryon (default 0.02226 / h²), sigma8
(default 0.8150) and ns (default 0.9653) to set_cosmology, or the same keys under
cosmology: in a config.
Stellar masses must be given in linear units of Msun/h (not log10). If your catalogue has
log masses, convert them first, e.g. stellar_mass=10**cat["logmstar"].
Number of cores
kelpie runs in parallel automatically using numba; there is nothing to switch on. By default it uses every core the process is allowed to run on: all cores on a laptop, or the cores bound to your job on a Linux cluster.
Two settings control this:
NUMBA_NUM_THREADS(environment variable) is the ceiling. numba reads it once when it starts and creates that many threads, so it must be set before Python starts; changing it inside a running session has no effect.numba.set_num_threads(n)chooses how many of those threads to use, and can be changed at any time, but only between 1 and the ceiling (higher values raise aValueError).
Limit the number of cores for a single run:
NUMBA_NUM_THREADS=4 kelpie config.yaml
or from Python, at any point before calling run():
import numba
numba.set_num_threads(4) # must be <= NUMBA_NUM_THREADS
cat.run()
On an HPC cluster
Set NUMBA_NUM_THREADS to the number of cores you requested, in the job script before
kelpie starts. Many clusters bind jobs to their cores, in which case numba already sees the
right number, but setting it explicitly avoids using more threads than you were allocated
(which slows the run down and can get the job flagged) on clusters that do not.
Example SLURM script:
#!/bin/bash
#SBATCH --job-name=kelpie
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=16
#SBATCH --mem=8G
#SBATCH --time=02:00:00
export NUMBA_NUM_THREADS=$SLURM_CPUS_PER_TASK
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK # numba may use OpenMP as its threading layer
kelpie config.yaml
kelpie runs on a single node: use one task with several CPUs (--cpus-per-task), not
several tasks or nodes. For other schedulers, set NUMBA_NUM_THREADS from the equivalent
variable (e.g. $NSLOTS on SGE, $PBS_NUM_PPN or $NCPUS on PBS).
What runs in parallel
The expensive steps are parallel: finding candidate members and computing their membership probabilities, group centres, and comoving distances. Two parts are not:
- assigning galaxies to groups within each pass, which must go from the most to the least massive group; it only does comparisons, so it is cheap, but it limits how well very large catalogues scale;
- building the halo concentration lookup grids (colossus), about 15 s once per catalogue and
cosmology, which is cached for later runs on the same
RedshiftCatalog.
Memory stays bounded for large catalogues: candidate members are processed in chunks of a few million pairs, and a run on 1.5 million galaxies peaks at about 1.3 GB.
Tests
pip install -e ".[test]"
pytest
The cosmology and geometry helpers are checked against astropy, and the group finder is tested end to end on randomly generated mock catalogues. The first run takes a minute or so while numba compiles.
Outputs
A run produces two tables, available as cat.galaxy_groups and cat.groups and written by
save() (or a config run) to the galaxy_group_path and group_properties_path parquet files.
Every column carries its astropy unit and description, which are kept in the saved files.
Units follow the input convention: masses are in Msun/h and lengths in Mpc/h (where
H0 = 100 h km/s/Mpc, with h set by set_cosmology or cosmology.h in the config), and all
masses are linear, not log10. Unit strings like solMass / littleh mean Msun/h. When reading saved files outside kelpie,
run astropy.units.add_enabled_units(astropy.cosmology.units) first so astropy recognises
littleh; otherwise it is kept as an unrecognised unit, but the values are unaffected.
Galaxy membership table (galaxy_groups, one row per galaxy)
| Column | Units | Description |
|---|---|---|
galaxy_id |
– | Galaxy identifier, as given in the input catalogue (or 0..N-1 if none was given). |
kelpie_group_id |
– | Identifier of the kelpie group the galaxy belongs to; matches group_id in the group table. Isolated galaxies are groups of one. |
Group table (groups, one row per group)
| Column | Units | Description |
|---|---|---|
group_id |
– | Group identifier; matches kelpie_group_id in the galaxy table. |
centre_galaxy_id |
– | galaxy_id of the galaxy chosen as the group centre: the most massive member for bcg, or the iterative stellar-mass-weighted centre for iter_centre. |
centre_ra |
deg | Right ascension of the group centre (the centre galaxy's position). |
centre_dec |
deg | Declination of the group centre (the centre galaxy's position). |
centre_redshift |
– | Observed redshift of the centre galaxy. |
halo_mass |
Msun/h | Halo mass M200m (mass within 200 times the mean matter density), from the stellar-to-halo mass relation. |
halo_radius |
Mpc/h (physical) | Halo radius R200m in physical (proper) Mpc/h, derived from halo_mass at centre_redshift. |
group_stellar_mass |
Msun/h | Total stellar mass of the members, corrected for galaxies below the survey's stellar mass limit at centre_redshift. This is the input to the stellar-to-halo mass relation. |
multiplicity |
– | Number of member galaxies in the catalogue. |
Metadata
Release files for kelpie-groupfinder 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kelpie_groupfinder-0.2.1.tar.gz | 89.2 kB | Without provenance | Details for kelpie_groupfinder-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kelpie_groupfinder-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for kelpie_groupfinder-0.2.1-py3-none-any.whl |
Total release size: 122.7 kB
Release files / kelpie_groupfinder-0.2.1.tar.gz
| Download URL | kelpie_groupfinder-0.2.1.tar.gz |
|---|---|
| Size | 89.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b312707df67d8591b20ee7fa1919f292ee052a42040fcf9ea4ffe7a41b7b3c1
|
|
BLAKE2b-256 checksum How to use checksums |
1f173d9657746156487010d8238e0db3393717ce8a8f50d35b9a2d19a0772284
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.17
|
Release files / kelpie_groupfinder-0.2.1-py3-none-any.whl
| Download URL | kelpie_groupfinder-0.2.1-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d50a03be77a7614f9b61efe6fe68a7733cffe92f0a60b44869143ced062f752f
|
|
BLAKE2b-256 checksum How to use checksums |
49b355c6d7827d60c8d7033465f05affbb4c97276ab6aea13f03e040cf5577e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.17
|
Security for kelpie-groupfinder 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.