diskmelts 2.1__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.
- diskmelts/__init__.py +98 -0
- diskmelts/consub/__init__.py +15 -0
- diskmelts/consub/_api.py +129 -0
- diskmelts/consub/_core.py +447 -0
- diskmelts/consub/cont_ranges.csv +206 -0
- diskmelts/consub/cont_ranges_PPan.csv +182 -0
- diskmelts/consub/regions/carbon_extended.csv +227 -0
- diskmelts/consub/regions/carbon_extended.json +29 -0
- diskmelts/consub/regions/carbon_rich.csv +360 -0
- diskmelts/consub/regions/carbon_rich.json +27 -0
- diskmelts/consub/regions/ttauri.csv +421 -0
- diskmelts/consub/regions/ttauri.json +17 -0
- diskmelts/consub/regions/water.csv +505 -0
- diskmelts/consub/regions/water.json +11 -0
- diskmelts/fitting.py +1408 -0
- diskmelts/models/Trained_model/13C12CH2_single_v2/net_13C12CH2_forward.pt +0 -0
- diskmelts/models/Trained_model/13CO2_single_v2/net_13CO2_forward.pt +0 -0
- diskmelts/models/Trained_model/C2H2_single_v2/net_C2H2_forward.pt +0 -0
- diskmelts/models/Trained_model/C2H4_single_v2/net_C2H4_forward.pt +0 -0
- diskmelts/models/Trained_model/C2H6_single_v2/net_C2H6_forward.pt +0 -0
- diskmelts/models/Trained_model/C2HD_single_v2/net_C2HD_forward.pt +0 -0
- diskmelts/models/Trained_model/C4H2_single_v2/net_C4H2_forward.pt +0 -0
- diskmelts/models/Trained_model/CH4_single_v2/net_CH4_forward.pt +0 -0
- diskmelts/models/Trained_model/CO17O_single_v2/net_CO17O_forward.pt +0 -0
- diskmelts/models/Trained_model/CO18O_single_v2/net_CO18O_forward.pt +0 -0
- diskmelts/models/Trained_model/CO2_single_v2/net_CO2_forward.pt +0 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/H2O_model_bank.json +129 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w13p5to19p2_n13to19_t100to1400.pt +0 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w19to25_n13to19_t100to1400.pt +0 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w4p9to7p4_n13to19_t100to1400.pt +0 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w7p2to11p2_n13to19_t100to1400.pt +0 -0
- diskmelts/models/Trained_model/H2O_wavelength_bank_v2_fixed/net_H2O_w9p9to15p1_n13to19_t100to1400.pt +0 -0
- diskmelts/models/Trained_model/HC3N_single_v2/net_HC3N_forward.pt +0 -0
- diskmelts/models/Trained_model/HCN_single_v2/net_HCN_forward.pt +0 -0
- diskmelts/plotting.py +536 -0
- diskmelts/trainmodel.py +1349 -0
- diskmelts/v2_fitting.py +298 -0
- diskmelts/v2_grid_fitting.py +570 -0
- diskmelts/v2_paper_comparison.py +174 -0
- diskmelts/v2_read_plot.py +220 -0
- diskmelts/validation.py +505 -0
- diskmelts-2.1.dist-info/METADATA +262 -0
- diskmelts-2.1.dist-info/RECORD +46 -0
- diskmelts-2.1.dist-info/WHEEL +5 -0
- diskmelts-2.1.dist-info/licenses/LICENSE +21 -0
- diskmelts-2.1.dist-info/top_level.txt +1 -0
diskmelts/__init__.py
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
|
+
]
|
diskmelts/consub/_api.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Array-based continuum API."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from ._core import subtract_continuum, plot_consub
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def calculate(wav, flux, error=None, preset="ttauri", exclude=None,
|
|
11
|
+
linefreefile="", *, boxsizes=None, special=None, method="robust",
|
|
12
|
+
shift=True, correction_scale=0.75, special_blend=0.15):
|
|
13
|
+
"""Calculate and subtract a continuum, returning five NumPy arrays.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
wav, flux : array-like
|
|
18
|
+
Matching one-dimensional wavelength (microns) and raw flux arrays.
|
|
19
|
+
Wavelength must be finite, positive, unique, and increasing. Nonfinite
|
|
20
|
+
flux is excluded from fitting and returned as NaN in the residual.
|
|
21
|
+
error : array-like or None, optional
|
|
22
|
+
Measurement errors in the same units as flux. Missing or nonpositive
|
|
23
|
+
values are replaced by local noise estimates. None estimates all errors.
|
|
24
|
+
preset : str or None, optional
|
|
25
|
+
``water``, ``ttauri``, ``carbon_rich``, or ``carbon_extended`` selects
|
|
26
|
+
bundled windows. Carbon presets exclude 12.5--16.5 microns. None uses
|
|
27
|
+
a custom linefreefile, or an unrestricted robust fit if no file is given.
|
|
28
|
+
exclude : sequence of (float, float) or None, optional
|
|
29
|
+
Additional wavelength intervals excluded from fitting and correction.
|
|
30
|
+
linefreefile : str, pathlib.Path or None, optional
|
|
31
|
+
Used only with preset=None. A CSV containing ``xmin,xmax`` specifies
|
|
32
|
+
fit and correction windows. None or an empty string fits all nonexcluded
|
|
33
|
+
pixels and disables line-free correction, so cont equals contOrig.
|
|
34
|
+
boxsizes : number, sequence or None, optional
|
|
35
|
+
Pixel count, regional ``(xmin,xmax,pixels)`` rows, or automatic widths.
|
|
36
|
+
special : sequence of (float, float) or None, optional
|
|
37
|
+
Intervals where the reference correction is suppressed.
|
|
38
|
+
method : {"robust", "arpls"}, optional
|
|
39
|
+
Baseline estimator. The default uses robust local fits and PCHIP.
|
|
40
|
+
shift : bool, optional
|
|
41
|
+
Apply the reference correction when windows are available.
|
|
42
|
+
correction_scale, special_blend : float, optional
|
|
43
|
+
Correction-bin width and special-region transition width in microns.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
wav, consub, err, cont, contOrig : tuple of numpy.ndarray
|
|
48
|
+
Five independent, one-dimensional arrays of the input length:
|
|
49
|
+
wavelength, continuum-subtracted flux, measurement/estimated noise
|
|
50
|
+
error, final continuum, and continuum before the reference correction.
|
|
51
|
+
The returned err does not include correlated continuum uncertainty.
|
|
52
|
+
|
|
53
|
+
Notes
|
|
54
|
+
-----
|
|
55
|
+
Large excluded intervals require interpolation and may be poorly constrained.
|
|
56
|
+
Use ``subtract_continuum`` for support masks and uncertainty diagnostics.
|
|
57
|
+
All default reference tables are bundled with the installed package.
|
|
58
|
+
"""
|
|
59
|
+
custom_file = linefreefile is not None and str(linefreefile) != ""
|
|
60
|
+
if preset is not None and custom_file:
|
|
61
|
+
raise ValueError("Set preset=None to use linefreefile")
|
|
62
|
+
result = subtract_continuum(
|
|
63
|
+
wav, flux, error=error, preset=preset, exclude=exclude,
|
|
64
|
+
line_free_regions=linefreefile if custom_file else None,
|
|
65
|
+
reference_regions="curated" if preset is not None else None,
|
|
66
|
+
boxsizes=boxsizes, special=special, method=method, shift=shift,
|
|
67
|
+
correction_scale=correction_scale, special_blend=special_blend,
|
|
68
|
+
)
|
|
69
|
+
return tuple(result[name].to_numpy(copy=True) for name in
|
|
70
|
+
("wave", "flux", "err", "cont", "cont_unshifted"))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def plot(wav, consub, error=None, cont=None, contOrig=None, savedir=None, *,
|
|
74
|
+
ranges=None, title=None, filename="continuum.png"):
|
|
75
|
+
"""Plot continuum and residual arrays, optionally saving the figure.
|
|
76
|
+
|
|
77
|
+
Parameters
|
|
78
|
+
----------
|
|
79
|
+
wav, consub : array-like
|
|
80
|
+
Wavelength in microns and continuum-subtracted flux.
|
|
81
|
+
error : array-like or None, optional
|
|
82
|
+
Errors for the shaded residual band. None omits the band.
|
|
83
|
+
cont : array-like
|
|
84
|
+
Final continuum; required. The raw spectrum is reconstructed as
|
|
85
|
+
consub + cont. It can be passed as the fourth positional argument.
|
|
86
|
+
contOrig : array-like or None, optional
|
|
87
|
+
Unshifted continuum. None omits that curve.
|
|
88
|
+
savedir : str, pathlib.Path or None, optional
|
|
89
|
+
Output directory, created if needed. None creates no files.
|
|
90
|
+
ranges : (float, float), sequence of pairs or None, optional
|
|
91
|
+
Plot limits in microns; None shows the full wavelength range.
|
|
92
|
+
title : str or None, optional
|
|
93
|
+
Figure title.
|
|
94
|
+
filename : str, optional
|
|
95
|
+
Image basename inside savedir, default ``continuum.png``. A suffix such
|
|
96
|
+
as .png, .pdf or .svg selects the Matplotlib output format.
|
|
97
|
+
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
matplotlib.figure.Figure
|
|
101
|
+
Open figure, displayed by Jupyter's Matplotlib backend. In scripts,
|
|
102
|
+
call matplotlib.pyplot.show() to display it interactively.
|
|
103
|
+
"""
|
|
104
|
+
x = np.asarray(wav, dtype=float)
|
|
105
|
+
if x.ndim != 1 or len(x) < 2 or not np.isfinite(x).all() or np.any(np.diff(x) <= 0):
|
|
106
|
+
raise ValueError("wav must be a finite, increasing 1D array with at least 2 samples")
|
|
107
|
+
if cont is None:
|
|
108
|
+
raise ValueError("cont is required to plot the continuum")
|
|
109
|
+
values = {}
|
|
110
|
+
for name, value in (("flux", consub), ("cont", cont),
|
|
111
|
+
("err", error), ("cont_unshifted", contOrig)):
|
|
112
|
+
if value is not None:
|
|
113
|
+
array = np.asarray(value, dtype=float)
|
|
114
|
+
if array.shape != x.shape:
|
|
115
|
+
raise ValueError(f"{name} must have the same shape as wav")
|
|
116
|
+
values[name] = array
|
|
117
|
+
if "flux" not in values:
|
|
118
|
+
raise ValueError("consub is required")
|
|
119
|
+
if "err" in values and np.any(values["err"] < 0):
|
|
120
|
+
raise ValueError("error must be nonnegative")
|
|
121
|
+
output = None
|
|
122
|
+
if savedir is not None:
|
|
123
|
+
if not filename or Path(filename).name != filename:
|
|
124
|
+
raise ValueError("filename must be a basename, not a path")
|
|
125
|
+
output = Path(savedir) / filename
|
|
126
|
+
result = pd.DataFrame({"wave": x, **values,
|
|
127
|
+
"raw_flux": values["flux"] + values["cont"],
|
|
128
|
+
"reference_mask": False, "weak_support": False})
|
|
129
|
+
return plot_consub(result, ranges=ranges, title=title, output=output)
|