cosmoglint 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
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.
- cosmoglint/__init__.py +1 -1
- cosmoglint/model/__init__.py +0 -2
- cosmoglint-1.0.2.dist-info/METADATA +131 -0
- {cosmoglint-1.0.0.dist-info → cosmoglint-1.0.2.dist-info}/RECORD +7 -7
- cosmoglint-1.0.0.dist-info/METADATA +0 -164
- {cosmoglint-1.0.0.dist-info → cosmoglint-1.0.2.dist-info}/WHEEL +0 -0
- {cosmoglint-1.0.0.dist-info → cosmoglint-1.0.2.dist-info}/licenses/LICENSE +0 -0
- {cosmoglint-1.0.0.dist-info → cosmoglint-1.0.2.dist-info}/top_level.txt +0 -0
cosmoglint/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.0.
|
|
1
|
+
__version__ = "1.0.2"
|
cosmoglint/model/__init__.py
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cosmoglint
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Transformer-based generative model for galaxies
|
|
5
|
+
Author: Kana Moriwaki
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Kana Moriwaki
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/knmoriwaki/cosmoglint
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: numpy
|
|
33
|
+
Requires-Dist: tqdm
|
|
34
|
+
Requires-Dist: h5py
|
|
35
|
+
Requires-Dist: astropy
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# CosmoGLINT: Cosmological Generative model for Line INtensity mapping with Transformer
|
|
39
|
+
|
|
40
|
+
Transformer-based models that generate galaxies.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
This package is available on PyPI.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install cosmoglint
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This package requires PyTorch.
|
|
53
|
+
Please install PyTorch first following https://pytorch.org
|
|
54
|
+
|
|
55
|
+
## Documentation & Source code
|
|
56
|
+
|
|
57
|
+
GitHub: https://github.com/knmoriwaki/cosmoglint
|
|
58
|
+
|
|
59
|
+
## Basic usage
|
|
60
|
+
|
|
61
|
+
Load model:
|
|
62
|
+
```python
|
|
63
|
+
import json
|
|
64
|
+
from cosmoglint.model.transformer import transformer_model
|
|
65
|
+
|
|
66
|
+
with open(f"args.json", "r") as f:
|
|
67
|
+
option = json.load(f, object_hook=lambda d: argparse.Namespace(**d))
|
|
68
|
+
|
|
69
|
+
model = transformer_model(option)
|
|
70
|
+
```
|
|
71
|
+
with a json file (example):
|
|
72
|
+
```json
|
|
73
|
+
{"model_name": "transformer1", "max_length": 50, "d_model": 128, "num_layers": 4, "num_heads": 8, "num_features_out": 100, "num_features_in": 4}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Predict probability:
|
|
77
|
+
```python
|
|
78
|
+
prob = model(context, x)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Generate new galaxies:
|
|
82
|
+
```python
|
|
83
|
+
generated, prob = model.generate(context, x, prob_threshold=1e-5)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Input:
|
|
87
|
+
- `context`: a tensor of shape `(N, C_h)`, containing the properties of halo.
|
|
88
|
+
- `x`: a tensor of shape `(N, L, C_g)`, containing the properties of up to `L` galaxies for each of the `N` halos in the batch. Each feature vector of size `C_g` may include, for example, the halo mass, relative distance to the halo center, radial velocity, and tangential velocity. Input `None` to generate from scratch.
|
|
89
|
+
- `prob_threshold` (optional): when sampling, the probability below this threshold is set to zero.
|
|
90
|
+
|
|
91
|
+
Output:
|
|
92
|
+
- `prob`: a tensor of shape `(N, L, C_g, d)`. `prob[i,j,k,:]` is the probability distribution over `d` bins for the k-th parameter of the **(j+1)-th galaxy** in the sequence for the i-th batch element.
|
|
93
|
+
- `generated`: a tensor of shape `(N, L, C_g)`. `generated[i,j,k]` is the sampled values for each parameter of **(j+1)-th galaxy** in the sequence for the i-th batch element.
|
|
94
|
+
|
|
95
|
+
Shape:
|
|
96
|
+
- `N`: Batch size
|
|
97
|
+
- `L`: Sequence length
|
|
98
|
+
- `C_h`: Number of halo properties
|
|
99
|
+
- `C_g`: Number of galaxy properties predicted
|
|
100
|
+
- `d`: Number of bins for the probability distribution of each parameter
|
|
101
|
+
|
|
102
|
+
Options:
|
|
103
|
+
| Key | Description |
|
|
104
|
+
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
105
|
+
| **`model_name`** | Name or identifier for the model configuration (default: `"transformer1"`). Available options are:<br> - `"transformer1"`: halo is prepended to the sequence<br> - `"transformer2"`: halo and galaxy features are embedded together | |
|
|
106
|
+
| **`max_length`** | Maximum number of galaxies (sequence length) the model will process per halo.|
|
|
107
|
+
| **`d_model`** | Dimensionality of the internal feature space (i.e., size of the token embeddings and hidden layers in the transformer). |
|
|
108
|
+
| **`num_layers`** | Number of transformer decoder layers stacked in the model. |
|
|
109
|
+
| **`num_heads`** | Number of attention heads in the multi-head self-attention layers. |
|
|
110
|
+
| **`num_features_out`** | Total number of output bins for the probability distribution. |
|
|
111
|
+
| **`num_features_in`** | Number of features per galaxy (e.g., SFR, relative distance, radial/tangential velocity). |
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## Citation
|
|
115
|
+
|
|
116
|
+
If you use CosmoGLINT in your research, please cite [Moriwaki et al. 2025](https://arxiv.org/abs/2506.16843)
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
@ARTICLE{CosmoGLINT,
|
|
120
|
+
title = {CosmoGLINT: Cosmological Generative Model for Line Intensity Mapping with Transformer},
|
|
121
|
+
author = {{Moriwaki}, Kana and {Jun}, Rui Lan and {Osato}, Ken and {Yoshida}, Naoki},
|
|
122
|
+
journal = {arXiv preprints},
|
|
123
|
+
year = 2025,
|
|
124
|
+
month = jun,
|
|
125
|
+
eid = {arXiv:2506.16843},
|
|
126
|
+
doi = {10.48550/arXiv.2506.16843},
|
|
127
|
+
archivePrefix = {arXiv},
|
|
128
|
+
eprint = {2506.16843},
|
|
129
|
+
primaryClass = {astro-ph.CO}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
cosmoglint/__init__.py,sha256=
|
|
2
|
-
cosmoglint/model/__init__.py,sha256=
|
|
1
|
+
cosmoglint/__init__.py,sha256=JqmBIiZnO_c1ce6zv6JZzf01tRk6jFq-SGGuvkL_r1U,21
|
|
2
|
+
cosmoglint/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
cosmoglint/model/transformer.py,sha256=woFgnk_uWKZEl6EIQX6PBU0ERtUKSk1W_2_sPjYujnM,21949
|
|
4
4
|
cosmoglint/model/transformer_nf.py,sha256=MXMYdj1KY1dZgmEzCeFxWp_QdqgHO7Sc3tDguoNG7P0,14459
|
|
5
5
|
cosmoglint/utils/ReadPinocchio5.py,sha256=17v3GFydE-Ha45TohwtUsU60xmGzfuZ1sNjPJEzUguI,39714
|
|
@@ -7,8 +7,8 @@ cosmoglint/utils/__init__.py,sha256=r19103JGuFfnKqPa0Oi0jmeAeKM5darGcTEY-_wLzpg,
|
|
|
7
7
|
cosmoglint/utils/cosmology_utils.py,sha256=Ergv-REB-0LERfbXc0AnB4KJTLdUOCeVmze2u3H4KUE,7606
|
|
8
8
|
cosmoglint/utils/generation_utils.py,sha256=cnMVTjZdHaefKKBUpEFL7BSN2pSEyiQgyR48MdMqy9c,15301
|
|
9
9
|
cosmoglint/utils/io_utils.py,sha256=XUF7znHmGSZ8wQpOPk-KqNJvYN6-0rU8NE8mEtO1q2I,13068
|
|
10
|
-
cosmoglint-1.0.
|
|
11
|
-
cosmoglint-1.0.
|
|
12
|
-
cosmoglint-1.0.
|
|
13
|
-
cosmoglint-1.0.
|
|
14
|
-
cosmoglint-1.0.
|
|
10
|
+
cosmoglint-1.0.2.dist-info/licenses/LICENSE,sha256=xMgUlRtQRou9wDsNl4o8Op0w_VHlQmhY_uPwFCl7SWo,1070
|
|
11
|
+
cosmoglint-1.0.2.dist-info/METADATA,sha256=Cs05S-aKvWlATsFG087DEqaKaxDwHizFjV5VreszF3U,5736
|
|
12
|
+
cosmoglint-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
13
|
+
cosmoglint-1.0.2.dist-info/top_level.txt,sha256=gKGGdFf41h3PsCSMtVYESsfUqfxNLsYXSCe3tQKiPxw,11
|
|
14
|
+
cosmoglint-1.0.2.dist-info/RECORD,,
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: cosmoglint
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Transformer-based generative model for galaxies
|
|
5
|
-
Author: Kana Moriwaki
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2026 Kana Moriwaki
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
|
|
28
|
-
Project-URL: Homepage, https://github.com/knmoriwaki/cosmoglint
|
|
29
|
-
Requires-Python: >=3.9
|
|
30
|
-
Description-Content-Type: text/markdown
|
|
31
|
-
License-File: LICENSE
|
|
32
|
-
Requires-Dist: numpy
|
|
33
|
-
Requires-Dist: tqdm
|
|
34
|
-
Requires-Dist: h5py
|
|
35
|
-
Requires-Dist: nflows
|
|
36
|
-
Requires-Dist: astropy
|
|
37
|
-
Dynamic: license-file
|
|
38
|
-
|
|
39
|
-
# CosmoGLINT: Cosmological Generative model for Line INtensity mapping with Transformer
|
|
40
|
-
|
|
41
|
-
This repository includes:
|
|
42
|
-
|
|
43
|
-
- cosmoglint, a package of Transformer-based models that generate galaxy properties from halo mass.
|
|
44
|
-
- Scripts for training and mock catalog generation.
|
|
45
|
-
- Example notebooks for result visualization.
|
|
46
|
-
|
|
47
|
-
Models trained with TNG300-1 at z = 0.5 - 6 and generated data are available at [Google Drive](https://drive.google.com/drive/folders/1IFje9tNRf4Dr3NufqzlDdGMFTEDpsm35?usp=share_link).
|
|
48
|
-
|
|
49
|
-
For detailed usage and options, see [DOCUMENTATION](./DOCUMENTATION.md).
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## Installation
|
|
54
|
-
|
|
55
|
-
Python>=3.9 is required.
|
|
56
|
-
|
|
57
|
-
This package requires PyTorch.
|
|
58
|
-
Please install PyTorch first following https://pytorch.org
|
|
59
|
-
|
|
60
|
-
Install package and from local clone:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
git clone https://github.com/knmoriwaki/cosmoglint.git
|
|
64
|
-
cd cosmoglint
|
|
65
|
-
pip install .
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
If you only need the `cosmoglint` package (e.g., to import it in your own code), you can install it directly:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
pip install git+https://github.com/knmoriwaki/cosmoglint.git
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Several libraries needs to be additionally installed to run the scripts and notebooks:
|
|
76
|
-
```bash
|
|
77
|
-
pip install -r requirements.txt
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Training
|
|
81
|
-
|
|
82
|
-
Example:
|
|
83
|
-
```bash
|
|
84
|
-
python train_transformer.py --data_path [data_path] --norm_param_file [norm_param_file]
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Options:
|
|
88
|
-
- `--data_path`: Path(s) to the training data. Data is an hdf5 file that contains properties of halos and galaxies. In addition to those for input and output features, the number of galaxies in each halo (`GroupNsubs`) should be provided. Multiple files can be passed.
|
|
89
|
-
- `--norm_param_file`: Path to the json file that specifies the normalization settings. Each key (e.g., `HaloMass`) maps to a dictionary with `min` / `max` and `norm`. If `norm` is `"log"` or `"log_with_sign"`, the `min` / `max` normalization is applied after the log conversion.
|
|
90
|
-
- `--input_features`: List of the input properties (default: `["GroupMass"]`)
|
|
91
|
-
- `--output_features`: List of the output properties (default: `["SubhaloSFR", "SubhaloDist", "SubhaloVrad", "SubhaloVtan"]`)
|
|
92
|
-
- `--max_length`: Maximum number of galaxies (sequence length) per halo (default: 30).
|
|
93
|
-
- `--use_flat_representation`: If true, use flattened point features (B, N * M). If false, keep (B, N, M). Use `--no-use_flat_representation` to set it to false (default: true).
|
|
94
|
-
|
|
95
|
-
## Create mock data cube
|
|
96
|
-
|
|
97
|
-
Example:
|
|
98
|
-
```bash
|
|
99
|
-
python create_data_cube.py --input_fname [input_fname] --model_dir [model_dir]
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Options:
|
|
103
|
-
- `--input_fname`: Path to the halo catalog. Text file that contains halo mass [Msun] in log scale (1st column), comving positions [Mpc/h] (2nd to 4th columns), and velocities [km/s] (5th to 8th columns) and catalog in [Pinocchio](https://github.com/pigimonaco/Pinocchio) format are supported.
|
|
104
|
-
- `--model_dir`: Path to a directory containing the trained model (`model.pth` and `args.json`). If not set, column 7 of the input file is used as intensity.
|
|
105
|
-
- `--boxsize`: Size of the simulation box in comoving units [Mpc/h] (default: 100.0).
|
|
106
|
-
- `--redshift_space`: If set, positions are converted to redshift space using halo velocities.
|
|
107
|
-
- `--gen_both`: If set, generates both real-space and redshift-space data cubes.
|
|
108
|
-
- `--npix`: Number of pixels in the x and y directions for the data cube (default: 100).
|
|
109
|
-
- `--npix_z`: Number of pixels in the z direction (default: 90).
|
|
110
|
-
|
|
111
|
-
## Create lightcone
|
|
112
|
-
|
|
113
|
-
Example:
|
|
114
|
-
```bash
|
|
115
|
-
python create_lightcone.py --input_fname [input_fname] --model_dir [model_dir] --model_config_file [model_config_file]
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
Example of `model_config_file`:
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"33": ["transformer1_33_ep40_bs512_w0.02", 2.002],
|
|
122
|
-
"21": ["transformer1_21_ep60_bs512_w0.02", 4.008]
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
- `--input_fname`: Path to the lightcone halo catalog. Pinocchio format is supported.
|
|
127
|
-
- `--output_fname`: Output filename (HDF5 format).
|
|
128
|
-
- `--model_dir`: Path to a directory containing the trained models.
|
|
129
|
-
- `--model_config_file`: Path to a JSON file that contains the names of the trained models to be used for each redshift bin. The JSON file is a dictionary where each key is a stringified snapshot ID, and the value is a list containing the model directory relative to `model_dir` and the redshift.
|
|
130
|
-
- `--redshift_space`: If set, generate output in redshift space.
|
|
131
|
-
- `redshift_min`, `--redshift_max`: Redshift range for the lightcone.
|
|
132
|
-
- `dz`: Redshift bin width. Indicates dlogz if `--use_logz` is given.
|
|
133
|
-
- `use_logz`: Use dlogz instead of dz for redshift binning.
|
|
134
|
-
- `--side_length`, `--angular_resolution`: Angular size and resolution (arcsec) of the simulated map.
|
|
135
|
-
- `--gen_catalog`: If set, generate a galaxy catalog with SFR greater than --catalog_threshold.
|
|
136
|
-
- `--catalog_threshold`: SFR threshold for inclusion in the catalog.
|
|
137
|
-
|
|
138
|
-
## Visualization
|
|
139
|
-
|
|
140
|
-
Example Jupyter notebooks are available in the `notebooks/` directory:
|
|
141
|
-
|
|
142
|
-
- `plot_transformer.ipynb`: visualize training results
|
|
143
|
-
- `plot_data_cube.ipynb`: visualize created data cube
|
|
144
|
-
- `plot_lightcone.ipynb`: visualize lightcone data
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## Citation
|
|
148
|
-
|
|
149
|
-
If you use CosmoGLINT in your research, please cite [Moriwaki et al. 2025](https://arxiv.org/abs/2506.16843)
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
@ARTICLE{CosmoGLINT,
|
|
153
|
-
title = {CosmoGLINT: Cosmological Generative Model for Line Intensity Mapping with Transformer},
|
|
154
|
-
author = {{Moriwaki}, Kana and {Jun}, Rui Lan and {Osato}, Ken and {Yoshida}, Naoki},
|
|
155
|
-
journal = {arXiv preprints},
|
|
156
|
-
year = 2025,
|
|
157
|
-
month = jun,
|
|
158
|
-
eid = {arXiv:2506.16843},
|
|
159
|
-
doi = {10.48550/arXiv.2506.16843},
|
|
160
|
-
archivePrefix = {arXiv},
|
|
161
|
-
eprint = {2506.16843},
|
|
162
|
-
primaryClass = {astro-ph.CO}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|