kelpie-groupfinder 0.1.0__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.
- kelpie_groupfinder-0.1.0/LICENSE +21 -0
- kelpie_groupfinder-0.1.0/MANIFEST.in +3 -0
- kelpie_groupfinder-0.1.0/PKG-INFO +123 -0
- kelpie_groupfinder-0.1.0/README.md +92 -0
- kelpie_groupfinder-0.1.0/examples/example_config.yaml +44 -0
- kelpie_groupfinder-0.1.0/examples/example_notebook.ipynb +4056 -0
- kelpie_groupfinder-0.1.0/pyproject.toml +52 -0
- kelpie_groupfinder-0.1.0/setup.cfg +4 -0
- kelpie_groupfinder-0.1.0/src/kelpie/__init__.py +7 -0
- kelpie_groupfinder-0.1.0/src/kelpie/__main__.py +28 -0
- kelpie_groupfinder-0.1.0/src/kelpie/bijective_matching.py +135 -0
- kelpie_groupfinder-0.1.0/src/kelpie/cosmology.py +343 -0
- kelpie_groupfinder-0.1.0/src/kelpie/group_membership.py +731 -0
- kelpie_groupfinder-0.1.0/src/kelpie/group_probability.py +479 -0
- kelpie_groupfinder-0.1.0/src/kelpie/kelpie.py +800 -0
- kelpie_groupfinder-0.1.0/src/kelpie/utils.py +104 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/PKG-INFO +123 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/SOURCES.txt +26 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/dependency_links.txt +1 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/entry_points.txt +2 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/requires.txt +11 -0
- kelpie_groupfinder-0.1.0/src/kelpie_groupfinder.egg-info/top_level.txt +1 -0
- kelpie_groupfinder-0.1.0/tests/conftest.py +61 -0
- kelpie_groupfinder-0.1.0/tests/test_bijective_matching.py +43 -0
- kelpie_groupfinder-0.1.0/tests/test_cosmology.py +90 -0
- kelpie_groupfinder-0.1.0/tests/test_group_membership.py +88 -0
- kelpie_groupfinder-0.1.0/tests/test_group_probability.py +100 -0
- kelpie_groupfinder-0.1.0/tests/test_kelpie.py +316 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sam Philipsborn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kelpie-groupfinder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The kelpie galaxy group finder: an iterative halo-based group finder for redshift surveys
|
|
5
|
+
Author: Sam Philipsborn
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sampsussex/kelpie
|
|
8
|
+
Project-URL: Source, https://github.com/sampsussex/kelpie
|
|
9
|
+
Project-URL: Issues, https://github.com/sampsussex/kelpie/issues
|
|
10
|
+
Keywords: astronomy,galaxy groups,group finder,redshift survey,halo
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: numba
|
|
22
|
+
Requires-Dist: numba-kdtree
|
|
23
|
+
Requires-Dist: astropy
|
|
24
|
+
Requires-Dist: colossus
|
|
25
|
+
Requires-Dist: pyyaml
|
|
26
|
+
Requires-Dist: scipy
|
|
27
|
+
Requires-Dist: pyarrow
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest; extra == "test"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# kelpie
|
|
33
|
+
The kelpie galaxy groupfinder
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install kelpie-groupfinder
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The package installs as `kelpie-groupfinder` but is imported as `kelpie`, and provides a
|
|
42
|
+
`kelpie` command. For development, clone the repository and run `pip install -e .`.
|
|
43
|
+
|
|
44
|
+
`numba-kdtree` is compiled from source on some platforms. If its build fails with missing
|
|
45
|
+
C++ headers (e.g. `'cstdlib' file not found`), fix your compiler setup or install into a
|
|
46
|
+
fresh conda environment.
|
|
47
|
+
|
|
48
|
+
See [`examples/example_notebook.ipynb`](examples/example_notebook.ipynb) for a full walk-through
|
|
49
|
+
on a random mock catalogue.
|
|
50
|
+
|
|
51
|
+
## Run from a config file
|
|
52
|
+
|
|
53
|
+
Copy and edit [`examples/example_config.yaml`](examples/example_config.yaml), then:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
kelpie path/to/config.yaml # or: python -m kelpie path/to/config.yaml
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This loads the catalogue, runs the finder and writes the membership and group-property
|
|
60
|
+
parquet files given in `file_locations`. With `run_mock_comparison: True` (and
|
|
61
|
+
`column_names.group_id` set) it also prints the S-score.
|
|
62
|
+
|
|
63
|
+
The same thing from Python: `kelpie.run_from_config("config.yaml")`.
|
|
64
|
+
|
|
65
|
+
## Run as a package
|
|
66
|
+
|
|
67
|
+
Everything goes through `RedshiftCatalog`:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from kelpie import RedshiftCatalog
|
|
71
|
+
|
|
72
|
+
cat = RedshiftCatalog(ra, dec, redshift, stellar_mass, completeness=completeness)
|
|
73
|
+
# or: RedshiftCatalog.from_file("cat.parquet", {"ra": "RAcen", "dec": "Deccen",
|
|
74
|
+
# "redshift": "Z", "stellar_mass": "stellar_mass"})
|
|
75
|
+
|
|
76
|
+
cat.set_cosmology(h=0.6751, omega_matter=0.3121) # optional: omega_baryon=, sigma8=, ns=
|
|
77
|
+
cat.set_free_parameters(alpha=6.0, beta=2.3, completeness_coefficient=0.33)
|
|
78
|
+
cat.set_shmr("Li") # or set_shmr("custom_constant", constant_ratio=100)
|
|
79
|
+
cat.set_centre_definition("iter_centre") # or "bcg"
|
|
80
|
+
cat.run()
|
|
81
|
+
|
|
82
|
+
cat.galaxy_groups # astropy Table: galaxy_id, kelpie_group_id
|
|
83
|
+
cat.groups # astropy Table: one row per group
|
|
84
|
+
cat.save("members.parquet", "groups.parquet")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
All setters return the catalogue, so calls can be chained. Re-running after changing
|
|
88
|
+
the free parameters reuses the distances, KD-tree and lookup grids, so tuning on a mock
|
|
89
|
+
is cheap.
|
|
90
|
+
|
|
91
|
+
### Optimising on a mock
|
|
92
|
+
|
|
93
|
+
`optimise_on_mock` tunes `alpha` and `beta` with scipy's Nelder-Mead to maximise the
|
|
94
|
+
S-score. Both are kept in 1.0-10.0 and rounded to 2 significant figures, starting from
|
|
95
|
+
the current values (6.0, 2.3 by default); `completeness_coefficient` is held fixed.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
mock = RedshiftCatalog(ra, dec, z, sm, mock_group_ids=true_ids)
|
|
99
|
+
best = mock.optimise_on_mock()
|
|
100
|
+
best["alpha"], best["beta"], best["s_score"] # mock is left run at the best values
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
From a config, set `run_options.optimise_on_mock: True` (needs `column_names.group_id`);
|
|
104
|
+
the outputs are written using the optimised parameters.
|
|
105
|
+
|
|
106
|
+
The halo concentration-mass relation (colossus) needs a full cosmology. Beyond `h` and
|
|
107
|
+
`omega_matter` you can optionally pass `omega_baryon` (default 0.02226 / h²), `sigma8`
|
|
108
|
+
(default 0.8150) and `ns` (default 0.9653) to `set_cosmology`, or the same keys under
|
|
109
|
+
`cosmology:` in a config.
|
|
110
|
+
|
|
111
|
+
Stellar masses must be given in linear units of Msun/h (not log10). If your catalogue has
|
|
112
|
+
log masses, convert them first, e.g. `stellar_mass=10**cat["logmstar"]`.
|
|
113
|
+
|
|
114
|
+
## Tests
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install -e ".[test]"
|
|
118
|
+
pytest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The cosmology and geometry helpers are checked against astropy, and the group finder is
|
|
122
|
+
tested end to end on randomly generated mock catalogues. The first run takes a minute or
|
|
123
|
+
so while numba compiles.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# kelpie
|
|
2
|
+
The kelpie galaxy groupfinder
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install kelpie-groupfinder
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The package installs as `kelpie-groupfinder` but is imported as `kelpie`, and provides a
|
|
11
|
+
`kelpie` command. For development, clone the repository and run `pip install -e .`.
|
|
12
|
+
|
|
13
|
+
`numba-kdtree` is compiled from source on some platforms. If its build fails with missing
|
|
14
|
+
C++ headers (e.g. `'cstdlib' file not found`), fix your compiler setup or install into a
|
|
15
|
+
fresh conda environment.
|
|
16
|
+
|
|
17
|
+
See [`examples/example_notebook.ipynb`](examples/example_notebook.ipynb) for a full walk-through
|
|
18
|
+
on a random mock catalogue.
|
|
19
|
+
|
|
20
|
+
## Run from a config file
|
|
21
|
+
|
|
22
|
+
Copy and edit [`examples/example_config.yaml`](examples/example_config.yaml), then:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
kelpie path/to/config.yaml # or: python -m kelpie path/to/config.yaml
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This loads the catalogue, runs the finder and writes the membership and group-property
|
|
29
|
+
parquet files given in `file_locations`. With `run_mock_comparison: True` (and
|
|
30
|
+
`column_names.group_id` set) it also prints the S-score.
|
|
31
|
+
|
|
32
|
+
The same thing from Python: `kelpie.run_from_config("config.yaml")`.
|
|
33
|
+
|
|
34
|
+
## Run as a package
|
|
35
|
+
|
|
36
|
+
Everything goes through `RedshiftCatalog`:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from kelpie import RedshiftCatalog
|
|
40
|
+
|
|
41
|
+
cat = RedshiftCatalog(ra, dec, redshift, stellar_mass, completeness=completeness)
|
|
42
|
+
# or: RedshiftCatalog.from_file("cat.parquet", {"ra": "RAcen", "dec": "Deccen",
|
|
43
|
+
# "redshift": "Z", "stellar_mass": "stellar_mass"})
|
|
44
|
+
|
|
45
|
+
cat.set_cosmology(h=0.6751, omega_matter=0.3121) # optional: omega_baryon=, sigma8=, ns=
|
|
46
|
+
cat.set_free_parameters(alpha=6.0, beta=2.3, completeness_coefficient=0.33)
|
|
47
|
+
cat.set_shmr("Li") # or set_shmr("custom_constant", constant_ratio=100)
|
|
48
|
+
cat.set_centre_definition("iter_centre") # or "bcg"
|
|
49
|
+
cat.run()
|
|
50
|
+
|
|
51
|
+
cat.galaxy_groups # astropy Table: galaxy_id, kelpie_group_id
|
|
52
|
+
cat.groups # astropy Table: one row per group
|
|
53
|
+
cat.save("members.parquet", "groups.parquet")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
All setters return the catalogue, so calls can be chained. Re-running after changing
|
|
57
|
+
the free parameters reuses the distances, KD-tree and lookup grids, so tuning on a mock
|
|
58
|
+
is cheap.
|
|
59
|
+
|
|
60
|
+
### Optimising on a mock
|
|
61
|
+
|
|
62
|
+
`optimise_on_mock` tunes `alpha` and `beta` with scipy's Nelder-Mead to maximise the
|
|
63
|
+
S-score. Both are kept in 1.0-10.0 and rounded to 2 significant figures, starting from
|
|
64
|
+
the current values (6.0, 2.3 by default); `completeness_coefficient` is held fixed.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
mock = RedshiftCatalog(ra, dec, z, sm, mock_group_ids=true_ids)
|
|
68
|
+
best = mock.optimise_on_mock()
|
|
69
|
+
best["alpha"], best["beta"], best["s_score"] # mock is left run at the best values
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
From a config, set `run_options.optimise_on_mock: True` (needs `column_names.group_id`);
|
|
73
|
+
the outputs are written using the optimised parameters.
|
|
74
|
+
|
|
75
|
+
The halo concentration-mass relation (colossus) needs a full cosmology. Beyond `h` and
|
|
76
|
+
`omega_matter` you can optionally pass `omega_baryon` (default 0.02226 / h²), `sigma8`
|
|
77
|
+
(default 0.8150) and `ns` (default 0.9653) to `set_cosmology`, or the same keys under
|
|
78
|
+
`cosmology:` in a config.
|
|
79
|
+
|
|
80
|
+
Stellar masses must be given in linear units of Msun/h (not log10). If your catalogue has
|
|
81
|
+
log masses, convert them first, e.g. `stellar_mass=10**cat["logmstar"]`.
|
|
82
|
+
|
|
83
|
+
## Tests
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install -e ".[test]"
|
|
87
|
+
pytest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The cosmology and geometry helpers are checked against astropy, and the group finder is
|
|
91
|
+
tested end to end on randomly generated mock catalogues. The first run takes a minute or
|
|
92
|
+
so while numba compiles.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
run_options:
|
|
2
|
+
run_group_finder: True
|
|
3
|
+
run_mock_comparison: False
|
|
4
|
+
optimise_on_mock: False # Nelder-Mead over alpha/beta (1-10, 2 s.f.); starts from threshold_model_params
|
|
5
|
+
|
|
6
|
+
cosmology:
|
|
7
|
+
h: 0.6751
|
|
8
|
+
omega_matter: 0.3121
|
|
9
|
+
# Optional, only used for halo concentrations (defaults shown):
|
|
10
|
+
# omega_baryon: 0.0488 # default 0.02226 / h**2
|
|
11
|
+
# sigma8: 0.8150
|
|
12
|
+
# ns: 0.9653
|
|
13
|
+
|
|
14
|
+
column_names:
|
|
15
|
+
galaxy_id: "uberID"
|
|
16
|
+
ra: "RAcen"
|
|
17
|
+
dec: "Deccen"
|
|
18
|
+
redshift: "Z"
|
|
19
|
+
stellar_mass: "stellar_mass" # must be linear stellar mass in Msun/h (not log10)
|
|
20
|
+
completeness: "completeness" # local galaxy incompleteness
|
|
21
|
+
group_id: #"id_fof" # true group ids, only needed for mock comparison
|
|
22
|
+
|
|
23
|
+
file_locations:
|
|
24
|
+
galaxy_catalog_path: '/Users/sp624AA/Downloads/gama3/groupfinding_gama4_processed.parquet'
|
|
25
|
+
galaxy_group_path: "kelpie_membership_GAMA.parquet"
|
|
26
|
+
group_properties_path: "kelpie_groups_GAMA.parquet"
|
|
27
|
+
|
|
28
|
+
finder_options:
|
|
29
|
+
max_iterations: 10
|
|
30
|
+
centre_definition: "iter_centre" # bcg, iter_centre
|
|
31
|
+
|
|
32
|
+
threshold_model_params:
|
|
33
|
+
alpha_threshold: 6.0
|
|
34
|
+
beta_threshold: 2.3
|
|
35
|
+
completeness_coefficient: 0.33
|
|
36
|
+
|
|
37
|
+
shmr_params:
|
|
38
|
+
method: "Li" # Li, custom_constant (M_h = ratio * M_*)
|
|
39
|
+
custom_constant_mass_to_mass_ratio: 100
|
|
40
|
+
|
|
41
|
+
mock_comparison_options:
|
|
42
|
+
group_n_threshold: 5
|
|
43
|
+
optimiser_initial_step: 0.5
|
|
44
|
+
optimiser_max_evaluations: 200
|