diskmelts 2.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.
- diskmelts-2.1/LICENSE +21 -0
- diskmelts-2.1/PKG-INFO +262 -0
- diskmelts-2.1/README.md +223 -0
- diskmelts-2.1/pyproject.toml +54 -0
- diskmelts-2.1/setup.cfg +4 -0
- diskmelts-2.1/src/diskmelts/__init__.py +98 -0
- diskmelts-2.1/src/diskmelts/consub/__init__.py +15 -0
- diskmelts-2.1/src/diskmelts/consub/_api.py +129 -0
- diskmelts-2.1/src/diskmelts/consub/_core.py +447 -0
- diskmelts-2.1/src/diskmelts/consub/cont_ranges.csv +206 -0
- diskmelts-2.1/src/diskmelts/consub/cont_ranges_PPan.csv +182 -0
- diskmelts-2.1/src/diskmelts/consub/regions/carbon_extended.csv +227 -0
- diskmelts-2.1/src/diskmelts/consub/regions/carbon_extended.json +29 -0
- diskmelts-2.1/src/diskmelts/consub/regions/carbon_rich.csv +360 -0
- diskmelts-2.1/src/diskmelts/consub/regions/carbon_rich.json +27 -0
- diskmelts-2.1/src/diskmelts/consub/regions/ttauri.csv +421 -0
- diskmelts-2.1/src/diskmelts/consub/regions/ttauri.json +17 -0
- diskmelts-2.1/src/diskmelts/consub/regions/water.csv +505 -0
- diskmelts-2.1/src/diskmelts/consub/regions/water.json +11 -0
- diskmelts-2.1/src/diskmelts/fitting.py +1408 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/13C12CH2_single_v2/net_13C12CH2_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/13CO2_single_v2/net_13CO2_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/C2H2_single_v2/net_C2H2_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/C2H4_single_v2/net_C2H4_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/C2H6_single_v2/net_C2H6_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/C2HD_single_v2/net_C2HD_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/C4H2_single_v2/net_C4H2_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/CH4_single_v2/net_CH4_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/CO17O_single_v2/net_CO17O_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/CO18O_single_v2/net_CO18O_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/CO2_single_v2/net_CO2_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/H2O_model_bank.json +129 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w13p5to19p2_n13to19_t100to1400.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w19to25_n13to19_t100to1400.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w4p9to7p4_n13to19_t100to1400.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w7p2to11p2_n13to19_t100to1400.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w9p9to15p1_n13to19_t100to1400.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/HC3N_single_v2/net_HC3N_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/models/Trained_model/HCN_single_v2/net_HCN_forward.pt +0 -0
- diskmelts-2.1/src/diskmelts/plotting.py +536 -0
- diskmelts-2.1/src/diskmelts/trainmodel.py +1349 -0
- diskmelts-2.1/src/diskmelts/v2_fitting.py +298 -0
- diskmelts-2.1/src/diskmelts/v2_grid_fitting.py +570 -0
- diskmelts-2.1/src/diskmelts/v2_paper_comparison.py +174 -0
- diskmelts-2.1/src/diskmelts/v2_read_plot.py +220 -0
- diskmelts-2.1/src/diskmelts/validation.py +505 -0
- diskmelts-2.1/src/diskmelts.egg-info/PKG-INFO +262 -0
- diskmelts-2.1/src/diskmelts.egg-info/SOURCES.txt +63 -0
- diskmelts-2.1/src/diskmelts.egg-info/dependency_links.txt +1 -0
- diskmelts-2.1/src/diskmelts.egg-info/requires.txt +27 -0
- diskmelts-2.1/src/diskmelts.egg-info/top_level.txt +1 -0
- diskmelts-2.1/tests/test_consub_package.py +99 -0
- diskmelts-2.1/tests/test_detection.py +133 -0
- diskmelts-2.1/tests/test_dev_v2_fitting_distance.py +41 -0
- diskmelts-2.1/tests/test_dev_v2_fitting_grids.py +116 -0
- diskmelts-2.1/tests/test_dev_v2_read_plot.py +95 -0
- diskmelts-2.1/tests/test_imports.py +60 -0
- diskmelts-2.1/tests/test_io.py +55 -0
- diskmelts-2.1/tests/test_mlp.py +43 -0
- diskmelts-2.1/tests/test_model_bank.py +228 -0
- diskmelts-2.1/tests/test_shared_area_fitting.py +152 -0
- diskmelts-2.1/tests/test_smoke.py +48 -0
- diskmelts-2.1/tests/test_v2_package_assets.py +25 -0
- diskmelts-2.1/tests/test_water_training.py +126 -0
- diskmelts-2.1/tests/test_workflows.py +227 -0
diskmelts-2.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chengyan Xie
|
|
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.
|
diskmelts-2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: diskmelts
|
|
3
|
+
Version: 2.1
|
|
4
|
+
Summary: Machine-learning Enabled Line fitting Tool for Spectra of protoplanetary disks
|
|
5
|
+
Author: Chengyan Xie, Dingshan Deng
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/wddlx/DiskMELTS
|
|
8
|
+
Project-URL: Documentation, https://diskmelts.readthedocs.io/en/latest/
|
|
9
|
+
Project-URL: Repository, https://github.com/wddlx/DiskMELTS
|
|
10
|
+
Project-URL: Issues, https://github.com/wddlx/DiskMELTS/issues
|
|
11
|
+
Keywords: astronomy,protoplanetary disks,JWST,spectral fitting,machine learning
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: torch
|
|
19
|
+
Requires-Dist: numpy<2,>=1.26; sys_platform == "darwin" and platform_machine == "x86_64"
|
|
20
|
+
Requires-Dist: numpy; sys_platform != "darwin" or platform_machine != "x86_64"
|
|
21
|
+
Requires-Dist: pandas
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: scikit-learn
|
|
24
|
+
Requires-Dist: matplotlib
|
|
25
|
+
Provides-Extra: io
|
|
26
|
+
Requires-Dist: astropy; extra == "io"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest; extra == "dev"
|
|
29
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
30
|
+
Requires-Dist: furo; extra == "dev"
|
|
31
|
+
Requires-Dist: myst-parser; extra == "dev"
|
|
32
|
+
Requires-Dist: sphinx-design; extra == "dev"
|
|
33
|
+
Requires-Dist: nbsphinx; extra == "dev"
|
|
34
|
+
Requires-Dist: nbsphinx-link; extra == "dev"
|
|
35
|
+
Provides-Extra: notebooks
|
|
36
|
+
Requires-Dist: jupyterlab; extra == "notebooks"
|
|
37
|
+
Requires-Dist: ipykernel; extra == "notebooks"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# DiskMELTS
|
|
41
|
+
|
|
42
|
+
DiskMELTS (Machine-learning Enabled Line fitting Tool for Spectra) is a
|
|
43
|
+
package for continuum subtraction and fitting molecular emission in JWST
|
|
44
|
+
mid-infrared spectra of protoplanetary disks. Its fitting workflow loads
|
|
45
|
+
pretrained molecular surrogate models and retrieves temperature (`T`), column
|
|
46
|
+
density (`logN`), and emitting area scaling (`A`) from observed spectra.
|
|
47
|
+
|
|
48
|
+
**Documentation:** [diskmelts.readthedocs.io](https://diskmelts.readthedocs.io/en/latest/)
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
Requires Python 3.9 or newer. Once the package is published to PyPI, install
|
|
53
|
+
it from any directory without cloning this repository:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
python -m pip install diskmelts
|
|
57
|
+
# Add [io] for FITS input, or [io,notebooks] for JupyterLab.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Until the first PyPI release, install directly from GitHub without a clone:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
python -m pip install "diskmelts[io] @ git+https://github.com/wddlx/DiskMELTS.git"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The package includes the production checkpoints and continuum reference tables.
|
|
67
|
+
Full slab grids for training and direct-grid fitting are separate downloads;
|
|
68
|
+
pass their local path as `grid_root`. See the
|
|
69
|
+
[installation guide](https://diskmelts.readthedocs.io/en/latest/installation.html)
|
|
70
|
+
for details.
|
|
71
|
+
|
|
72
|
+
### Development checkout (macOS, Linux, Windows)
|
|
73
|
+
|
|
74
|
+
From the repository root, use a native Python 3.10 or 3.11 interpreter to
|
|
75
|
+
create a virtual environment. For FITS input and the example notebooks:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python3.11 -m venv .venv
|
|
79
|
+
.venv/bin/python -m pip install -e ".[io,notebooks]"
|
|
80
|
+
.venv/bin/python -c "import diskmelts; print(diskmelts.__name__)"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `python3.10` if that is the native Python available on your machine.
|
|
84
|
+
For core fitting and CSV/array inputs only, replace the install command with
|
|
85
|
+
`.venv/bin/python -m pip install -e .`. See the
|
|
86
|
+
[installation guide](https://diskmelts.readthedocs.io/en/latest/installation.html) for Windows commands.
|
|
87
|
+
|
|
88
|
+
### Conda or Mamba
|
|
89
|
+
|
|
90
|
+
The YAML files use Conda only for Python and pip; pip installs the package and
|
|
91
|
+
its declared dependencies. Choose one from the repository root:
|
|
92
|
+
|
|
93
|
+
| File | Contents |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `environment.yaml` | Core package |
|
|
96
|
+
| `environment-notebooks.yaml` | Core package, FITS support, JupyterLab |
|
|
97
|
+
| `environment-dev.yaml` | Notebook environment, tests, documentation tools |
|
|
98
|
+
|
|
99
|
+
For the notebook setup, run `mamba env create --file environment-notebooks.yaml`
|
|
100
|
+
then `conda activate diskmelts-notebooks`. `conda env create --file` works with
|
|
101
|
+
the same files when using a current Conda release. On Apple Silicon, use a
|
|
102
|
+
native `osx-arm64` installation such as Miniforge; an older Intel Conda can
|
|
103
|
+
still spend a long time solving even these smaller files.
|
|
104
|
+
|
|
105
|
+
## Runtime dependencies
|
|
106
|
+
|
|
107
|
+
| Package | Purpose |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `torch` | Pretrained model inference |
|
|
110
|
+
| `numpy` | Array operations |
|
|
111
|
+
| `pandas` | CSV I/O |
|
|
112
|
+
| `scipy` | L-BFGS-B optimizer, NNLS, Sobol sampling |
|
|
113
|
+
| `scikit-learn` | Model scaling and PCA metadata |
|
|
114
|
+
| `matplotlib` | Plotting |
|
|
115
|
+
|
|
116
|
+
## Continuum subtraction
|
|
117
|
+
|
|
118
|
+
Try the [continuum subtraction notebook](https://github.com/wddlx/DiskMELTS/blob/main/notebooks/Example_Consub.ipynb)
|
|
119
|
+
with the included raw Upper Sco J16120505 spectrum. It demonstrates the
|
|
120
|
+
five-array result and a plot; change `RAW_CSV` to another file in
|
|
121
|
+
[`Realobs_data/Raw_data/`](https://github.com/wddlx/DiskMELTS/tree/main/Realobs_data/Raw_data) to process another source.
|
|
122
|
+
|
|
123
|
+
For a CSV with `wave,flux,err` columns (wavelength in µm and flux/error in the
|
|
124
|
+
same units):
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import diskmelts
|
|
128
|
+
|
|
129
|
+
wav, flux, error = diskmelts.consub.read_spectrum("raw_spectrum.csv")
|
|
130
|
+
wav, consub, err, cont, contOrig = diskmelts.consub.calculate(
|
|
131
|
+
wav, flux, error, preset="ttauri", exclude=[[12, 13]],
|
|
132
|
+
)
|
|
133
|
+
fig = diskmelts.consub.plot(
|
|
134
|
+
wav, consub, err, cont, contOrig, ranges=[(5, 12), (12, 25)], savedir=None,
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`calculate()` returns five NumPy arrays. `plot()` displays the raw spectrum,
|
|
139
|
+
continuum, and residual; `savedir="figures/consub"` also writes `continuum.png`.
|
|
140
|
+
Its `error` and `contOrig` inputs may be `None`.
|
|
141
|
+
|
|
142
|
+
Presets are `water`, `ttauri`, `carbon_rich`, and `carbon_extended`.
|
|
143
|
+
Use `preset=None, linefreefile="windows.csv"` for custom `xmin,xmax` windows.
|
|
144
|
+
With `preset=None, linefreefile=None` (or `""`), fitting uses all nonexcluded
|
|
145
|
+
pixels and skips the line-free correction, so `cont` equals `contOrig`.
|
|
146
|
+
Reference tables are bundled; normal continuum subtraction needs no model grids.
|
|
147
|
+
|
|
148
|
+
The private `0-Consub/` experiment directory is excluded from Git and is not
|
|
149
|
+
required by the installed package. Its runtime code and reference tables are
|
|
150
|
+
maintained under `src/diskmelts/consub/`.
|
|
151
|
+
The distributed tests in `tests/` exercise the installed continuum API and
|
|
152
|
+
bundled references without that private directory.
|
|
153
|
+
|
|
154
|
+
Returned `err` represents measurement/noise error, not correlated continuum
|
|
155
|
+
uncertainty. Broad excluded intervals require inspection. See the
|
|
156
|
+
[continuum guide](https://diskmelts.readthedocs.io/en/latest/continuum.html) for presets, regional box sizes,
|
|
157
|
+
special regions, FITS input, saving CSVs, and uncertainty diagnostics.
|
|
158
|
+
|
|
159
|
+
## Quick fitting example
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from diskmelts import load_fitting_models, load_observed_spectrum, fit_stage
|
|
163
|
+
|
|
164
|
+
pretrained = load_fitting_models(['H2O'])
|
|
165
|
+
|
|
166
|
+
obs_wav, obs_flux = load_observed_spectrum(
|
|
167
|
+
'Realobs_data/Consub_data/j16120505_v9.0_contsub_RVcorr.csv'
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
fit = fit_stage(
|
|
171
|
+
obs_wav,
|
|
172
|
+
obs_flux,
|
|
173
|
+
molecule='H2O',
|
|
174
|
+
wavelength_range=(11.0, 19.0),
|
|
175
|
+
pretrained=pretrained,
|
|
176
|
+
fit_ranges=[(11.0, 12.0), (16.5, 18.5)],
|
|
177
|
+
distance_pc=122.5,
|
|
178
|
+
n_samples=20000,
|
|
179
|
+
n_refine=32,
|
|
180
|
+
n_top=20,
|
|
181
|
+
sigma=0.001,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
print(fit['params'])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
You can also read spectra with your own code. DiskMELTS only requires
|
|
188
|
+
one-dimensional `obs_wav` and `obs_flux` arrays.
|
|
189
|
+
|
|
190
|
+
For a complete staged fit-and-subtract workflow from a checkout, edit and run:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
python examples/dev_v2_realobs.py
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The v2 fitting API is `load_fitting_models`, `fit_stage`, `fit_observation`, and
|
|
197
|
+
`plot_saved_observation`. The production checkpoints are packaged under
|
|
198
|
+
`src/diskmelts/models/` and included in the wheel. Model fitting requires no
|
|
199
|
+
`Model_grids/` or `Pretrain_grid/` directory. The model metadata, including
|
|
200
|
+
PCA counts and network layers, are in `diskmelts.MODEL_SPECS` and checked when
|
|
201
|
+
loading. The checkpoint flux convention is 1 au² at 140 pc; `distance_pc`
|
|
202
|
+
sets the source distance and makes the returned emitting area physical.
|
|
203
|
+
The [fitting notebook](https://github.com/wddlx/DiskMELTS/blob/main/notebooks/Example_Fitting.ipynb) requires 13C12CH2 to
|
|
204
|
+
be no hotter than C2H2 and gives them the same emitting area. It ties 13CO2
|
|
205
|
+
to CO2 in both temperature and area. Set
|
|
206
|
+
`isotopologue_groups`, `Tshare` (`free`, `equal`, or `less`), and `Ashare` in a
|
|
207
|
+
joint stage to choose those constraints. See the
|
|
208
|
+
[fitting guide](https://diskmelts.readthedocs.io/en/latest/quickstart.html) for examples.
|
|
209
|
+
|
|
210
|
+
For an optional fit directly from slab grids, use `fit_grid_stage` or
|
|
211
|
+
`fit_observation_grids` and supply `grid_root='Model_grids'` explicitly. This
|
|
212
|
+
separate method does require the full local grids. See the
|
|
213
|
+
[quick start](https://diskmelts.readthedocs.io/en/latest/quickstart.html) for both workflows and saved-result
|
|
214
|
+
plotting.
|
|
215
|
+
|
|
216
|
+
## Training and validation data
|
|
217
|
+
|
|
218
|
+
`Model_grids/` and `Pretrain_grid/` are intentionally ignored by Git because
|
|
219
|
+
they contain the full local training data. The generated checkpoint directories
|
|
220
|
+
under the top-level `Trained_model/` are also optional; the package bundles
|
|
221
|
+
only the production checkpoints needed for v2 fitting. To run
|
|
222
|
+
`examples/dev_v2_pt_validation.py` or
|
|
223
|
+
`notebooks/Example_Training_Validation.ipynb`, place the complete model grids
|
|
224
|
+
under `Model_grids/<molecule>/`. The workflows create or reuse the corresponding
|
|
225
|
+
pretraining CSV under `Pretrain_grid/`.
|
|
226
|
+
|
|
227
|
+
The maintained v2 workflow uses a hybrid design after restricting the expanded
|
|
228
|
+
IRIS grids to the intended physical domain. H2O uses five overlapping
|
|
229
|
+
wavelength checkpoints covering 4.9–25.0 µm, all sharing `T=100–1400 K` and
|
|
230
|
+
`logN=13–19`. Primary carbon-bearing and rarer molecules use one checkpoint
|
|
231
|
+
each, the same temperature range, and `logN=13–19.5`.
|
|
232
|
+
The new C2HD checkpoint spans 11.5–20.5 µm to include its 19 µm band;
|
|
233
|
+
CO17O and CO18O span 13–18 µm. The updated 13C12CH2 checkpoint keeps
|
|
234
|
+
11.5–17 µm. To retrain these four grids, run:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
DISKMELTS_MOLECULES=13C12CH2,C2HD,CO17O,CO18O python examples/dev_v2_pt_validation.py
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Five to ten percent of complete `(T, logN)` grid spectra are excluded before
|
|
241
|
+
PCA or neural-network training. They are used to select the PCA dimension and
|
|
242
|
+
to validate spectral reconstruction and full parameter fitting. The
|
|
243
|
+
`run_H2O`, `run_Cmol`, and `run_rarer` switches select which groups run.
|
|
244
|
+
|
|
245
|
+
## Forward model convention
|
|
246
|
+
|
|
247
|
+
```text
|
|
248
|
+
flux(T, logN, A, d) = A * (140 pc / d)^2 * peak(T, logN) * shape(T, logN)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Each molecule has two pretrained MLPs:
|
|
252
|
+
|
|
253
|
+
- `net_shape`: `(T, logN)` to PCA coefficients of the peak-normalized spectral shape
|
|
254
|
+
- `net_peak`: `(T, logN)` to `log10(peak flux)` in Jy
|
|
255
|
+
|
|
256
|
+
The linear amplitude `A` is solved analytically with NNLS or bounded least
|
|
257
|
+
squares after the nonlinear `(T, logN)` search.
|
|
258
|
+
|
|
259
|
+
## Contributors
|
|
260
|
+
|
|
261
|
+
- Chengyan Xie (University of Arizona)
|
|
262
|
+
- Dingshan Deng (University of Arizona)
|
diskmelts-2.1/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# DiskMELTS
|
|
2
|
+
|
|
3
|
+
DiskMELTS (Machine-learning Enabled Line fitting Tool for Spectra) is a
|
|
4
|
+
package for continuum subtraction and fitting molecular emission in JWST
|
|
5
|
+
mid-infrared spectra of protoplanetary disks. Its fitting workflow loads
|
|
6
|
+
pretrained molecular surrogate models and retrieves temperature (`T`), column
|
|
7
|
+
density (`logN`), and emitting area scaling (`A`) from observed spectra.
|
|
8
|
+
|
|
9
|
+
**Documentation:** [diskmelts.readthedocs.io](https://diskmelts.readthedocs.io/en/latest/)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Requires Python 3.9 or newer. Once the package is published to PyPI, install
|
|
14
|
+
it from any directory without cloning this repository:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python -m pip install diskmelts
|
|
18
|
+
# Add [io] for FITS input, or [io,notebooks] for JupyterLab.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Until the first PyPI release, install directly from GitHub without a clone:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
python -m pip install "diskmelts[io] @ git+https://github.com/wddlx/DiskMELTS.git"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The package includes the production checkpoints and continuum reference tables.
|
|
28
|
+
Full slab grids for training and direct-grid fitting are separate downloads;
|
|
29
|
+
pass their local path as `grid_root`. See the
|
|
30
|
+
[installation guide](https://diskmelts.readthedocs.io/en/latest/installation.html)
|
|
31
|
+
for details.
|
|
32
|
+
|
|
33
|
+
### Development checkout (macOS, Linux, Windows)
|
|
34
|
+
|
|
35
|
+
From the repository root, use a native Python 3.10 or 3.11 interpreter to
|
|
36
|
+
create a virtual environment. For FITS input and the example notebooks:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python3.11 -m venv .venv
|
|
40
|
+
.venv/bin/python -m pip install -e ".[io,notebooks]"
|
|
41
|
+
.venv/bin/python -c "import diskmelts; print(diskmelts.__name__)"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use `python3.10` if that is the native Python available on your machine.
|
|
45
|
+
For core fitting and CSV/array inputs only, replace the install command with
|
|
46
|
+
`.venv/bin/python -m pip install -e .`. See the
|
|
47
|
+
[installation guide](https://diskmelts.readthedocs.io/en/latest/installation.html) for Windows commands.
|
|
48
|
+
|
|
49
|
+
### Conda or Mamba
|
|
50
|
+
|
|
51
|
+
The YAML files use Conda only for Python and pip; pip installs the package and
|
|
52
|
+
its declared dependencies. Choose one from the repository root:
|
|
53
|
+
|
|
54
|
+
| File | Contents |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `environment.yaml` | Core package |
|
|
57
|
+
| `environment-notebooks.yaml` | Core package, FITS support, JupyterLab |
|
|
58
|
+
| `environment-dev.yaml` | Notebook environment, tests, documentation tools |
|
|
59
|
+
|
|
60
|
+
For the notebook setup, run `mamba env create --file environment-notebooks.yaml`
|
|
61
|
+
then `conda activate diskmelts-notebooks`. `conda env create --file` works with
|
|
62
|
+
the same files when using a current Conda release. On Apple Silicon, use a
|
|
63
|
+
native `osx-arm64` installation such as Miniforge; an older Intel Conda can
|
|
64
|
+
still spend a long time solving even these smaller files.
|
|
65
|
+
|
|
66
|
+
## Runtime dependencies
|
|
67
|
+
|
|
68
|
+
| Package | Purpose |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `torch` | Pretrained model inference |
|
|
71
|
+
| `numpy` | Array operations |
|
|
72
|
+
| `pandas` | CSV I/O |
|
|
73
|
+
| `scipy` | L-BFGS-B optimizer, NNLS, Sobol sampling |
|
|
74
|
+
| `scikit-learn` | Model scaling and PCA metadata |
|
|
75
|
+
| `matplotlib` | Plotting |
|
|
76
|
+
|
|
77
|
+
## Continuum subtraction
|
|
78
|
+
|
|
79
|
+
Try the [continuum subtraction notebook](https://github.com/wddlx/DiskMELTS/blob/main/notebooks/Example_Consub.ipynb)
|
|
80
|
+
with the included raw Upper Sco J16120505 spectrum. It demonstrates the
|
|
81
|
+
five-array result and a plot; change `RAW_CSV` to another file in
|
|
82
|
+
[`Realobs_data/Raw_data/`](https://github.com/wddlx/DiskMELTS/tree/main/Realobs_data/Raw_data) to process another source.
|
|
83
|
+
|
|
84
|
+
For a CSV with `wave,flux,err` columns (wavelength in µm and flux/error in the
|
|
85
|
+
same units):
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import diskmelts
|
|
89
|
+
|
|
90
|
+
wav, flux, error = diskmelts.consub.read_spectrum("raw_spectrum.csv")
|
|
91
|
+
wav, consub, err, cont, contOrig = diskmelts.consub.calculate(
|
|
92
|
+
wav, flux, error, preset="ttauri", exclude=[[12, 13]],
|
|
93
|
+
)
|
|
94
|
+
fig = diskmelts.consub.plot(
|
|
95
|
+
wav, consub, err, cont, contOrig, ranges=[(5, 12), (12, 25)], savedir=None,
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`calculate()` returns five NumPy arrays. `plot()` displays the raw spectrum,
|
|
100
|
+
continuum, and residual; `savedir="figures/consub"` also writes `continuum.png`.
|
|
101
|
+
Its `error` and `contOrig` inputs may be `None`.
|
|
102
|
+
|
|
103
|
+
Presets are `water`, `ttauri`, `carbon_rich`, and `carbon_extended`.
|
|
104
|
+
Use `preset=None, linefreefile="windows.csv"` for custom `xmin,xmax` windows.
|
|
105
|
+
With `preset=None, linefreefile=None` (or `""`), fitting uses all nonexcluded
|
|
106
|
+
pixels and skips the line-free correction, so `cont` equals `contOrig`.
|
|
107
|
+
Reference tables are bundled; normal continuum subtraction needs no model grids.
|
|
108
|
+
|
|
109
|
+
The private `0-Consub/` experiment directory is excluded from Git and is not
|
|
110
|
+
required by the installed package. Its runtime code and reference tables are
|
|
111
|
+
maintained under `src/diskmelts/consub/`.
|
|
112
|
+
The distributed tests in `tests/` exercise the installed continuum API and
|
|
113
|
+
bundled references without that private directory.
|
|
114
|
+
|
|
115
|
+
Returned `err` represents measurement/noise error, not correlated continuum
|
|
116
|
+
uncertainty. Broad excluded intervals require inspection. See the
|
|
117
|
+
[continuum guide](https://diskmelts.readthedocs.io/en/latest/continuum.html) for presets, regional box sizes,
|
|
118
|
+
special regions, FITS input, saving CSVs, and uncertainty diagnostics.
|
|
119
|
+
|
|
120
|
+
## Quick fitting example
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from diskmelts import load_fitting_models, load_observed_spectrum, fit_stage
|
|
124
|
+
|
|
125
|
+
pretrained = load_fitting_models(['H2O'])
|
|
126
|
+
|
|
127
|
+
obs_wav, obs_flux = load_observed_spectrum(
|
|
128
|
+
'Realobs_data/Consub_data/j16120505_v9.0_contsub_RVcorr.csv'
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
fit = fit_stage(
|
|
132
|
+
obs_wav,
|
|
133
|
+
obs_flux,
|
|
134
|
+
molecule='H2O',
|
|
135
|
+
wavelength_range=(11.0, 19.0),
|
|
136
|
+
pretrained=pretrained,
|
|
137
|
+
fit_ranges=[(11.0, 12.0), (16.5, 18.5)],
|
|
138
|
+
distance_pc=122.5,
|
|
139
|
+
n_samples=20000,
|
|
140
|
+
n_refine=32,
|
|
141
|
+
n_top=20,
|
|
142
|
+
sigma=0.001,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
print(fit['params'])
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
You can also read spectra with your own code. DiskMELTS only requires
|
|
149
|
+
one-dimensional `obs_wav` and `obs_flux` arrays.
|
|
150
|
+
|
|
151
|
+
For a complete staged fit-and-subtract workflow from a checkout, edit and run:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
python examples/dev_v2_realobs.py
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The v2 fitting API is `load_fitting_models`, `fit_stage`, `fit_observation`, and
|
|
158
|
+
`plot_saved_observation`. The production checkpoints are packaged under
|
|
159
|
+
`src/diskmelts/models/` and included in the wheel. Model fitting requires no
|
|
160
|
+
`Model_grids/` or `Pretrain_grid/` directory. The model metadata, including
|
|
161
|
+
PCA counts and network layers, are in `diskmelts.MODEL_SPECS` and checked when
|
|
162
|
+
loading. The checkpoint flux convention is 1 au² at 140 pc; `distance_pc`
|
|
163
|
+
sets the source distance and makes the returned emitting area physical.
|
|
164
|
+
The [fitting notebook](https://github.com/wddlx/DiskMELTS/blob/main/notebooks/Example_Fitting.ipynb) requires 13C12CH2 to
|
|
165
|
+
be no hotter than C2H2 and gives them the same emitting area. It ties 13CO2
|
|
166
|
+
to CO2 in both temperature and area. Set
|
|
167
|
+
`isotopologue_groups`, `Tshare` (`free`, `equal`, or `less`), and `Ashare` in a
|
|
168
|
+
joint stage to choose those constraints. See the
|
|
169
|
+
[fitting guide](https://diskmelts.readthedocs.io/en/latest/quickstart.html) for examples.
|
|
170
|
+
|
|
171
|
+
For an optional fit directly from slab grids, use `fit_grid_stage` or
|
|
172
|
+
`fit_observation_grids` and supply `grid_root='Model_grids'` explicitly. This
|
|
173
|
+
separate method does require the full local grids. See the
|
|
174
|
+
[quick start](https://diskmelts.readthedocs.io/en/latest/quickstart.html) for both workflows and saved-result
|
|
175
|
+
plotting.
|
|
176
|
+
|
|
177
|
+
## Training and validation data
|
|
178
|
+
|
|
179
|
+
`Model_grids/` and `Pretrain_grid/` are intentionally ignored by Git because
|
|
180
|
+
they contain the full local training data. The generated checkpoint directories
|
|
181
|
+
under the top-level `Trained_model/` are also optional; the package bundles
|
|
182
|
+
only the production checkpoints needed for v2 fitting. To run
|
|
183
|
+
`examples/dev_v2_pt_validation.py` or
|
|
184
|
+
`notebooks/Example_Training_Validation.ipynb`, place the complete model grids
|
|
185
|
+
under `Model_grids/<molecule>/`. The workflows create or reuse the corresponding
|
|
186
|
+
pretraining CSV under `Pretrain_grid/`.
|
|
187
|
+
|
|
188
|
+
The maintained v2 workflow uses a hybrid design after restricting the expanded
|
|
189
|
+
IRIS grids to the intended physical domain. H2O uses five overlapping
|
|
190
|
+
wavelength checkpoints covering 4.9–25.0 µm, all sharing `T=100–1400 K` and
|
|
191
|
+
`logN=13–19`. Primary carbon-bearing and rarer molecules use one checkpoint
|
|
192
|
+
each, the same temperature range, and `logN=13–19.5`.
|
|
193
|
+
The new C2HD checkpoint spans 11.5–20.5 µm to include its 19 µm band;
|
|
194
|
+
CO17O and CO18O span 13–18 µm. The updated 13C12CH2 checkpoint keeps
|
|
195
|
+
11.5–17 µm. To retrain these four grids, run:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
DISKMELTS_MOLECULES=13C12CH2,C2HD,CO17O,CO18O python examples/dev_v2_pt_validation.py
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Five to ten percent of complete `(T, logN)` grid spectra are excluded before
|
|
202
|
+
PCA or neural-network training. They are used to select the PCA dimension and
|
|
203
|
+
to validate spectral reconstruction and full parameter fitting. The
|
|
204
|
+
`run_H2O`, `run_Cmol`, and `run_rarer` switches select which groups run.
|
|
205
|
+
|
|
206
|
+
## Forward model convention
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
flux(T, logN, A, d) = A * (140 pc / d)^2 * peak(T, logN) * shape(T, logN)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Each molecule has two pretrained MLPs:
|
|
213
|
+
|
|
214
|
+
- `net_shape`: `(T, logN)` to PCA coefficients of the peak-normalized spectral shape
|
|
215
|
+
- `net_peak`: `(T, logN)` to `log10(peak flux)` in Jy
|
|
216
|
+
|
|
217
|
+
The linear amplitude `A` is solved analytically with NNLS or bounded least
|
|
218
|
+
squares after the nonlinear `(T, logN)` search.
|
|
219
|
+
|
|
220
|
+
## Contributors
|
|
221
|
+
|
|
222
|
+
- Chengyan Xie (University of Arizona)
|
|
223
|
+
- Dingshan Deng (University of Arizona)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "diskmelts"
|
|
7
|
+
version = "2.1"
|
|
8
|
+
description = "Machine-learning Enabled Line fitting Tool for Spectra of protoplanetary disks"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Chengyan Xie" },
|
|
15
|
+
{ name = "Dingshan Deng" },
|
|
16
|
+
]
|
|
17
|
+
keywords = ["astronomy", "protoplanetary disks", "JWST", "spectral fitting", "machine learning"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Astronomy",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"torch",
|
|
25
|
+
# Intel macOS wheels stop at PyTorch 2.2, whose NumPy bridge needs NumPy 1.x.
|
|
26
|
+
"numpy>=1.26,<2; sys_platform == 'darwin' and platform_machine == 'x86_64'",
|
|
27
|
+
"numpy; sys_platform != 'darwin' or platform_machine != 'x86_64'",
|
|
28
|
+
"pandas",
|
|
29
|
+
"scipy",
|
|
30
|
+
"scikit-learn",
|
|
31
|
+
"matplotlib",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/wddlx/DiskMELTS"
|
|
36
|
+
Documentation = "https://diskmelts.readthedocs.io/en/latest/"
|
|
37
|
+
Repository = "https://github.com/wddlx/DiskMELTS"
|
|
38
|
+
Issues = "https://github.com/wddlx/DiskMELTS/issues"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
io = ["astropy"]
|
|
42
|
+
dev = ["pytest", "sphinx", "furo", "myst-parser", "sphinx-design",
|
|
43
|
+
"nbsphinx", "nbsphinx-link"]
|
|
44
|
+
notebooks = ["jupyterlab", "ipykernel"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.package-data]
|
|
50
|
+
diskmelts = ["models/Trained_model/*/*.pt", "models/Trained_model/*/*.json",
|
|
51
|
+
"consub/*.csv", "consub/regions/*.csv", "consub/regions/*.json"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
diskmelts-2.1/setup.cfg
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""
|
|
2
|
+
diskmelts — Machine-learning Enabled Line fitting Tool for Spectra
|
|
3
|
+
|
|
4
|
+
A neural surrogate-assisted framework for retrieving molecular gas parameters
|
|
5
|
+
(T, logN, A) from JWST mid-IR spectra of protoplanetary disks.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from diskmelts.trainmodel import (
|
|
9
|
+
load_model_grid,
|
|
10
|
+
generate_pre_training_set,
|
|
11
|
+
pretrain_forward_model,
|
|
12
|
+
train_model_bank,
|
|
13
|
+
select_grid_holdout,
|
|
14
|
+
tune_pca_components,
|
|
15
|
+
)
|
|
16
|
+
from diskmelts.fitting import (
|
|
17
|
+
load_models,
|
|
18
|
+
load_model_bank,
|
|
19
|
+
generate_spectrum,
|
|
20
|
+
fit_nested,
|
|
21
|
+
fit_molecules,
|
|
22
|
+
load_observed_spectrum,
|
|
23
|
+
save_fit_outputs,
|
|
24
|
+
detect_stage_molecules,
|
|
25
|
+
save_running_spectrum,
|
|
26
|
+
print_fit_params,
|
|
27
|
+
save_fitted_comparison,
|
|
28
|
+
)
|
|
29
|
+
from diskmelts.validation import (
|
|
30
|
+
validate_nt,
|
|
31
|
+
validate_nt_holdout,
|
|
32
|
+
validate_full,
|
|
33
|
+
)
|
|
34
|
+
from diskmelts.plotting import (
|
|
35
|
+
plot_fit,
|
|
36
|
+
plot_validation,
|
|
37
|
+
plot_validation_split,
|
|
38
|
+
plot_bank_reconstruction,
|
|
39
|
+
)
|
|
40
|
+
from diskmelts.v2_fitting import (
|
|
41
|
+
MODEL_SPECS,
|
|
42
|
+
load_fitting_models,
|
|
43
|
+
fit_stage,
|
|
44
|
+
fit_observation,
|
|
45
|
+
)
|
|
46
|
+
from diskmelts.v2_grid_fitting import (
|
|
47
|
+
fit_grid_stage,
|
|
48
|
+
fit_observation_grids,
|
|
49
|
+
combine_grid_uncertainty,
|
|
50
|
+
)
|
|
51
|
+
from diskmelts.v2_read_plot import (
|
|
52
|
+
read_stage_result,
|
|
53
|
+
plot_saved_observation,
|
|
54
|
+
)
|
|
55
|
+
from diskmelts.v2_paper_comparison import plot_literature_comparisons
|
|
56
|
+
from diskmelts import consub
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
"consub",
|
|
60
|
+
"MODEL_SPECS",
|
|
61
|
+
"load_fitting_models",
|
|
62
|
+
"fit_stage",
|
|
63
|
+
"fit_observation",
|
|
64
|
+
"fit_grid_stage",
|
|
65
|
+
"fit_observation_grids",
|
|
66
|
+
"combine_grid_uncertainty",
|
|
67
|
+
"read_stage_result",
|
|
68
|
+
"plot_saved_observation",
|
|
69
|
+
"plot_literature_comparisons",
|
|
70
|
+
# trainmodel
|
|
71
|
+
"load_model_grid",
|
|
72
|
+
"generate_pre_training_set",
|
|
73
|
+
"pretrain_forward_model",
|
|
74
|
+
"train_model_bank",
|
|
75
|
+
"select_grid_holdout",
|
|
76
|
+
"tune_pca_components",
|
|
77
|
+
# fitting
|
|
78
|
+
"load_models",
|
|
79
|
+
"load_model_bank",
|
|
80
|
+
"generate_spectrum",
|
|
81
|
+
"fit_nested",
|
|
82
|
+
"fit_molecules",
|
|
83
|
+
"load_observed_spectrum",
|
|
84
|
+
"save_fit_outputs",
|
|
85
|
+
"detect_stage_molecules",
|
|
86
|
+
"save_running_spectrum",
|
|
87
|
+
"print_fit_params",
|
|
88
|
+
"save_fitted_comparison",
|
|
89
|
+
# validation
|
|
90
|
+
"validate_nt",
|
|
91
|
+
"validate_nt_holdout",
|
|
92
|
+
"validate_full",
|
|
93
|
+
# plotting
|
|
94
|
+
"plot_fit",
|
|
95
|
+
"plot_validation",
|
|
96
|
+
"plot_validation_split",
|
|
97
|
+
"plot_bank_reconstruction",
|
|
98
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Continuum subtraction and plotting for disk spectra.
|
|
2
|
+
|
|
3
|
+
Use ``calculate`` to return five arrays and ``plot`` to display or save them.
|
|
4
|
+
The diagnostic DataFrame interface remains available as ``subtract_continuum``.
|
|
5
|
+
"""
|
|
6
|
+
from ._core import (
|
|
7
|
+
generate_line_free_regions, load_regions, read_spectrum,
|
|
8
|
+
subtract_continuum, plot_consub, save_consub,
|
|
9
|
+
)
|
|
10
|
+
from ._api import calculate, plot
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"calculate", "plot", "read_spectrum", "load_regions",
|
|
14
|
+
"generate_line_free_regions", "subtract_continuum", "plot_consub", "save_consub",
|
|
15
|
+
]
|