astro-frap 1.0.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.
- astro_frap-1.0.0/LICENSE +21 -0
- astro_frap-1.0.0/PKG-INFO +47 -0
- astro_frap-1.0.0/README.md +30 -0
- astro_frap-1.0.0/README_pypi.md +28 -0
- astro_frap-1.0.0/astro_frap.egg-info/PKG-INFO +47 -0
- astro_frap-1.0.0/astro_frap.egg-info/SOURCES.txt +16 -0
- astro_frap-1.0.0/astro_frap.egg-info/dependency_links.txt +1 -0
- astro_frap-1.0.0/astro_frap.egg-info/requires.txt +7 -0
- astro_frap-1.0.0/astro_frap.egg-info/top_level.txt +1 -0
- astro_frap-1.0.0/frap/__init__.py +9 -0
- astro_frap-1.0.0/frap/_constants.py +12 -0
- astro_frap-1.0.0/frap/_utilities.py +356 -0
- astro_frap-1.0.0/frap/cv.py +103 -0
- astro_frap-1.0.0/frap/model.py +1221 -0
- astro_frap-1.0.0/frap/msdata.py +448 -0
- astro_frap-1.0.0/frap/visualizer.py +235 -0
- astro_frap-1.0.0/pyproject.toml +31 -0
- astro_frap-1.0.0/setup.cfg +4 -0
astro_frap-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomohiro C. Yoshida
|
|
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,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: astro-frap
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Flexible Radial Analysis of Protoplanetary disks
|
|
5
|
+
Author-email: "Tomohiro C. Yoshida" <tomohiroyoshida.astro@gmail.com>
|
|
6
|
+
Project-URL: Documentation, https://frap.readthedocs.io/en/latest/index.html
|
|
7
|
+
Project-URL: Source, https://github.com/tomyoshida/frap
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: astropy>=7.2.0
|
|
12
|
+
Requires-Dist: jax>=0.10.0
|
|
13
|
+
Requires-Dist: matplotlib>=3.11.0
|
|
14
|
+
Requires-Dist: numpy>=2.5.1
|
|
15
|
+
Requires-Dist: numpyro>=0.20.1
|
|
16
|
+
Requires-Dist: scipy>=1.18.0
|
|
17
|
+
Requires-Dist: tqdm>=4.67.3
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Flexible Radial Analysis of Protoplanetary disks: FRAP
|
|
21
|
+
|
|
22
|
+
Do you have observational data of the dust continuum emission from a protoplanetary disk? Flexible Radial Analysis of Protoplanetary disks (FRAP) provides an easy-to-use tool to retrieve dust properties, such as the dust surface density distribution, in disks.
|
|
23
|
+
|
|
24
|
+
See our [documentation](https://frap.readthedocs.io/en/latest/index.html) for details!
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
If you use [uv](https://docs.astral.sh/uv/) for the package manager:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
uv add git+https://github.com/tomyoshida/frap.git
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or you can use pip:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install git+https://github.com/tomyoshida/frap.git
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
We'll upload the code to PyPI soon!
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Citation
|
|
44
|
+
|
|
45
|
+
Available soon!
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Flexible Radial Analysis of Protoplanetary disks: FRAP
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Do you have observational data of the dust continuum emission from a protoplanetary disk? Flexible Radial Analysis of Protoplanetary disks (FRAP) provides an easy-to-use tool to retrieve dust properties, such as the dust surface density distribution, in disks.
|
|
6
|
+
|
|
7
|
+
See our [documentation](https://frap.readthedocs.io/en/latest/index.html) for details!
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
If you use [uv](https://docs.astral.sh/uv/) for the package manager:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
uv add git+https://github.com/tomyoshida/frap.git
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or you can use pip:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pip install git+https://github.com/tomyoshida/frap.git
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
We'll upload the code to PyPI soon!
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Citation
|
|
27
|
+
|
|
28
|
+
Available soon!
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Flexible Radial Analysis of Protoplanetary disks: FRAP
|
|
2
|
+
|
|
3
|
+
Do you have observational data of the dust continuum emission from a protoplanetary disk? Flexible Radial Analysis of Protoplanetary disks (FRAP) provides an easy-to-use tool to retrieve dust properties, such as the dust surface density distribution, in disks.
|
|
4
|
+
|
|
5
|
+
See our [documentation](https://frap.readthedocs.io/en/latest/index.html) for details!
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
If you use [uv](https://docs.astral.sh/uv/) for the package manager:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
uv add git+https://github.com/tomyoshida/frap.git
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or you can use pip:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pip install git+https://github.com/tomyoshida/frap.git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
We'll upload the code to PyPI soon!
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Citation
|
|
25
|
+
|
|
26
|
+
Available soon!
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: astro-frap
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Flexible Radial Analysis of Protoplanetary disks
|
|
5
|
+
Author-email: "Tomohiro C. Yoshida" <tomohiroyoshida.astro@gmail.com>
|
|
6
|
+
Project-URL: Documentation, https://frap.readthedocs.io/en/latest/index.html
|
|
7
|
+
Project-URL: Source, https://github.com/tomyoshida/frap
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: astropy>=7.2.0
|
|
12
|
+
Requires-Dist: jax>=0.10.0
|
|
13
|
+
Requires-Dist: matplotlib>=3.11.0
|
|
14
|
+
Requires-Dist: numpy>=2.5.1
|
|
15
|
+
Requires-Dist: numpyro>=0.20.1
|
|
16
|
+
Requires-Dist: scipy>=1.18.0
|
|
17
|
+
Requires-Dist: tqdm>=4.67.3
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Flexible Radial Analysis of Protoplanetary disks: FRAP
|
|
21
|
+
|
|
22
|
+
Do you have observational data of the dust continuum emission from a protoplanetary disk? Flexible Radial Analysis of Protoplanetary disks (FRAP) provides an easy-to-use tool to retrieve dust properties, such as the dust surface density distribution, in disks.
|
|
23
|
+
|
|
24
|
+
See our [documentation](https://frap.readthedocs.io/en/latest/index.html) for details!
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
If you use [uv](https://docs.astral.sh/uv/) for the package manager:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
uv add git+https://github.com/tomyoshida/frap.git
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or you can use pip:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install git+https://github.com/tomyoshida/frap.git
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
We'll upload the code to PyPI soon!
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Citation
|
|
44
|
+
|
|
45
|
+
Available soon!
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
README_pypi.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
astro_frap.egg-info/PKG-INFO
|
|
6
|
+
astro_frap.egg-info/SOURCES.txt
|
|
7
|
+
astro_frap.egg-info/dependency_links.txt
|
|
8
|
+
astro_frap.egg-info/requires.txt
|
|
9
|
+
astro_frap.egg-info/top_level.txt
|
|
10
|
+
frap/__init__.py
|
|
11
|
+
frap/_constants.py
|
|
12
|
+
frap/_utilities.py
|
|
13
|
+
frap/cv.py
|
|
14
|
+
frap/model.py
|
|
15
|
+
frap/msdata.py
|
|
16
|
+
frap/visualizer.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
frap
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
|
|
2
|
+
###### Utiities #########
|
|
3
|
+
|
|
4
|
+
import jax
|
|
5
|
+
import jax.numpy as jnp
|
|
6
|
+
import numpy as np
|
|
7
|
+
from ._constants import *
|
|
8
|
+
from astropy import units as u
|
|
9
|
+
import warnings
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
import jax.numpy as jnp
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from scipy.ndimage import gaussian_filter1d
|
|
16
|
+
|
|
17
|
+
from scipy.special import i0
|
|
18
|
+
|
|
19
|
+
from scipy.special import j1
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from scipy.interpolate import interp1d as scipy_interp1d
|
|
24
|
+
|
|
25
|
+
def check_range_old(x, lower, upper, alpha=10.0):
|
|
26
|
+
# Apply exponential penalty if x is outside [lower, upper]
|
|
27
|
+
penalty_lower = -jnp.exp(-alpha * (x - lower))
|
|
28
|
+
penalty_upper = -jnp.exp(alpha * (x - upper))
|
|
29
|
+
penalty = jnp.where(x < lower, penalty_lower,
|
|
30
|
+
jnp.where(x > upper, penalty_upper, 0.0))
|
|
31
|
+
return penalty
|
|
32
|
+
|
|
33
|
+
def check_range(x, lower, upper, alpha=100.0):
|
|
34
|
+
|
|
35
|
+
# 境界から外れた距離を計算
|
|
36
|
+
dist_lower = lower - x
|
|
37
|
+
dist_upper = x - upper
|
|
38
|
+
|
|
39
|
+
# 範囲外(dist > 0)の場合のみ、その距離の2乗をペナルティとする
|
|
40
|
+
penalty_lower = -alpha * jnp.square(jnp.maximum(0.0, dist_lower))
|
|
41
|
+
penalty_upper = -alpha * jnp.square(jnp.maximum(0.0, dist_upper))
|
|
42
|
+
|
|
43
|
+
return penalty_lower + penalty_upper
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def term_pbcor( nu, incl, r, D ):
|
|
47
|
+
|
|
48
|
+
lam = c / nu # cm
|
|
49
|
+
|
|
50
|
+
FoV = np.rad2deg(1.13 * lam * 1e-2 / D)*3600
|
|
51
|
+
|
|
52
|
+
Theta = FoV / (2*np.sqrt(2 * np.log(2)))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
a1 = np.exp( -(r**2 / 4 / Theta**2) * ( 1 + np.cos(incl)**2 ) )
|
|
56
|
+
a2 = i0( r**2/4/Theta**2 * np.sin(incl)**2 )
|
|
57
|
+
|
|
58
|
+
return a1 * a2
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def hankel_transform_0_jax(f, r, k, bessel):
|
|
63
|
+
'''
|
|
64
|
+
Perform the Hankel transform of order 0 using JAX.
|
|
65
|
+
f: jnp.ndarray, function values at radial distances r (shape: [n_r])
|
|
66
|
+
r: jnp.ndarray, radial distances (shape: [n_r])
|
|
67
|
+
k: jnp.ndarray, spatial frequencies (shape: [n_k])
|
|
68
|
+
bessel: jnp.ndarray, precomputed Bessel function values (shape: [n_k, n_r])
|
|
69
|
+
Returns the Hankel transform values at spatial frequencies k (shape: [n_k]).
|
|
70
|
+
'''
|
|
71
|
+
|
|
72
|
+
dr = jnp.gradient(r)
|
|
73
|
+
fr = f * r
|
|
74
|
+
|
|
75
|
+
#def integrate(ki):
|
|
76
|
+
# integrand = fr * j0(k * r)
|
|
77
|
+
# return jnp.sum(integrand * dr)
|
|
78
|
+
|
|
79
|
+
return jnp.sum( 2*np.pi * fr * bessel * dr, axis=1)
|
|
80
|
+
|
|
81
|
+
def rbf_kernel(X1, X2, variance, lengthscale):
|
|
82
|
+
'''
|
|
83
|
+
Compute the Radial Basis Function (RBF) kernel between two sets of input points using JAX.
|
|
84
|
+
X1: jnp.ndarray, first set of input points (shape: [n1, d])
|
|
85
|
+
X2: jnp.ndarray, second set of input points (shape: [n2 , d])
|
|
86
|
+
variance: float, variance parameter of the RBF kernel
|
|
87
|
+
lengthscale: float, lengthscale parameter of the RBF kernel
|
|
88
|
+
Returns the RBF kernel matrix (shape: [n1, n2]).
|
|
89
|
+
'''
|
|
90
|
+
|
|
91
|
+
sq_dist = jnp.sum(X1**2, 1)[:, None] + jnp.sum(X2**2, 1)[None, :] - 2 * jnp.dot(X1, X2.T)
|
|
92
|
+
|
|
93
|
+
return variance**2 * jnp.exp(-0.5 / lengthscale**2 * sq_dist)
|
|
94
|
+
|
|
95
|
+
def B(nu, T):
|
|
96
|
+
'''
|
|
97
|
+
Calculate the Planck function B(nu, T).
|
|
98
|
+
nu: jnp.ndarray or float, frequency in Hz
|
|
99
|
+
T: jnp.ndarray or float, temperature in Kelvin
|
|
100
|
+
Returns the Planck function values.
|
|
101
|
+
'''
|
|
102
|
+
|
|
103
|
+
return 2*h*nu**3/c**2 / ( jnp.exp(h*nu/k_B/T) - 1 )
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def I2Tb(nu, I):
|
|
107
|
+
|
|
108
|
+
'''
|
|
109
|
+
Convert intensity I(nu) to brightness temperature Tb using the Reighleigh-Jeans approximation.
|
|
110
|
+
nu: jnp.ndarray or float, frequency in Hz
|
|
111
|
+
I: jnp.ndarray or float, intensity in cgs units (erg/s/cm^2/Hz/sr)
|
|
112
|
+
Returns the brightness temperature Tb in Kelvin.
|
|
113
|
+
'''
|
|
114
|
+
return c**2 / (2*k_B*nu**2) * I
|
|
115
|
+
|
|
116
|
+
def sigmoid_transform(x, min_val=0.0, max_val=1.0, leak = 0.01):
|
|
117
|
+
'''
|
|
118
|
+
Apply a sigmoid transformation to the input array x.
|
|
119
|
+
The transformed values will be in the range [min_val, max_val].
|
|
120
|
+
x: jnp.ndarray, input array to be transformed
|
|
121
|
+
min_val: float, minimum value of the transformed output
|
|
122
|
+
max_val: float, maximum value of the transformed output
|
|
123
|
+
Returns the transformed array with values in the range [min_val, max_val].
|
|
124
|
+
'''
|
|
125
|
+
|
|
126
|
+
return min_val + (max_val - min_val) / (1 + jnp.exp(-x))
|
|
127
|
+
|
|
128
|
+
def sigmoid_transform_old(x, min_val=0.0, max_val=1.0):
|
|
129
|
+
y = (2.0 / jnp.pi) * jnp.arctan(x) # 範囲は (-1, 1)
|
|
130
|
+
y01 = 0.5 * (y + 1.0)
|
|
131
|
+
return min_val + (max_val - min_val) * y01
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def F(tau, omega):
|
|
135
|
+
'''
|
|
136
|
+
Calculate the function F(tau, omega) used in radiative transfer.
|
|
137
|
+
tau: jnp.ndarray or float, optical depth
|
|
138
|
+
omega: jnp.ndarray or float, single scattering albedo
|
|
139
|
+
Returns the computed values of F(tau, omega).
|
|
140
|
+
Ref. Miyake & Nakagawa 1993, Icarus, 106, 20; Sierra et al. 2020, ApJ, 892, 136
|
|
141
|
+
'''
|
|
142
|
+
|
|
143
|
+
w = omega
|
|
144
|
+
|
|
145
|
+
term1 = (jnp.sqrt(1 - w) - 1.0) * jnp.exp(-jnp.sqrt(3.0 / (1.0 - w)) * tau)
|
|
146
|
+
|
|
147
|
+
A_num = 1.0 - jnp.exp(-(jnp.sqrt(3.0 * (1.0 - w)) + 1.0) * tau / (1.0 - w))
|
|
148
|
+
A_den = jnp.sqrt(3.0 * (1.0 - w)) + 1.0
|
|
149
|
+
A = A_num / A_den
|
|
150
|
+
|
|
151
|
+
B_num = jnp.exp(-tau / (1.0 - w)) - jnp.exp(-jnp.sqrt(3.0 / (1.0 - w)) * tau)
|
|
152
|
+
B_den = jnp.sqrt(3.0 * (1.0 - w)) - 1.0
|
|
153
|
+
B = B_num / B_den
|
|
154
|
+
|
|
155
|
+
term2 = (jnp.sqrt(1 - w) + 1.0)
|
|
156
|
+
|
|
157
|
+
denom = term1 - term2
|
|
158
|
+
|
|
159
|
+
return (A + B) / denom
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def f_I(nu, incl, T, Sigma_d, k_abs_tot, k_sca_eff_tot, output_tau = False):
|
|
163
|
+
'''
|
|
164
|
+
Calculate the intensity I(nu) using radiative transfer with scattering.
|
|
165
|
+
nu: jnp.ndarray or float, frequency in Hz
|
|
166
|
+
incl: jnp.ndarray or float, inclination angle in radians
|
|
167
|
+
T: jnp.ndarray or float, temperature in Kelvin
|
|
168
|
+
Sigma_d: jnp.ndarray or float, dust surface density in g/cm^2
|
|
169
|
+
dust_params: list of jnp.ndarray or float, dust parameters (e.g., maximum grain size). Assuming the order matches the interpolators.
|
|
170
|
+
f_log10_ka: function, interpolator for log10 of absorption opacity
|
|
171
|
+
f_log10_ks: function, interpolator for log10 of scattering opacity
|
|
172
|
+
Returns the computed intensity I(nu).
|
|
173
|
+
'''
|
|
174
|
+
|
|
175
|
+
ka = k_abs_tot
|
|
176
|
+
ks = k_sca_eff_tot
|
|
177
|
+
|
|
178
|
+
chi = ka + ks
|
|
179
|
+
omega = ks / chi
|
|
180
|
+
|
|
181
|
+
tau = ka * Sigma_d / jnp.cos(incl)
|
|
182
|
+
|
|
183
|
+
if output_tau:
|
|
184
|
+
return tau
|
|
185
|
+
|
|
186
|
+
else:
|
|
187
|
+
return B(nu, T) * ( 1 - jnp.exp( -tau/(1-omega) ) + omega*F(tau, omega) )
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def size_average_opacity( log10_a, log10_k_abs, log10_k_sca_eff, log10_a_max, log10_a_min, q):
|
|
191
|
+
|
|
192
|
+
a = 10**log10_a
|
|
193
|
+
a_max = 10**log10_a_max
|
|
194
|
+
a_min = 10**log10_a_min
|
|
195
|
+
|
|
196
|
+
mask = jnp.where( (a <= a_max) & (a >= a_min), 1.0, 0.0)
|
|
197
|
+
n = a**(4.0-q) * mask #* jnp.exp(-(a / a_max)**gamma) * jnp.exp(-(a_min/a)**gamma)
|
|
198
|
+
|
|
199
|
+
sum_n = jnp.sum(n)
|
|
200
|
+
|
|
201
|
+
log10_k_abs_tot = jnp.log10(jnp.dot(n, 10**log10_k_abs) /sum_n)
|
|
202
|
+
log10_k_sca_eff_tot = jnp.log10(jnp.dot(n, 10**log10_k_sca_eff) /sum_n)
|
|
203
|
+
|
|
204
|
+
return log10_k_abs_tot, log10_k_sca_eff_tot
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def create_opacity_table(lam, a, k_abs, k_sca_eff, lam0, log10_a_dense, q_dense, smooth=True, log10_a_smooth=0.1, log10_a_min = -5.0):
|
|
208
|
+
'''
|
|
209
|
+
Create opacity tables by interpolating and averaging over grain size distributions.
|
|
210
|
+
lam: np.ndarray, wavelengths in microns (shape: [M])
|
|
211
|
+
a: np.ndarray, grain sizes in microns (shape: [N])
|
|
212
|
+
k_abs: np.ndarray, absorption opacities (shape: [N, M])
|
|
213
|
+
k_sca_eff: np.ndarray, effective scattering opacities (shape: [N, M])
|
|
214
|
+
lam0: np.ndarray, target wavelengths for interpolation in microns (shape: [L])
|
|
215
|
+
log10_a_dense: jnp.ndarray, dense grid of log10 grain sizes in microns (shape: [P])
|
|
216
|
+
q_dense: jnp.ndarray, dense grid of size distribution indices (shape: [Q])
|
|
217
|
+
smooth: bool, whether to apply smoothing to the interpolated opacities
|
|
218
|
+
log10_a_smooth: float, smoothing scale in log10 grain size
|
|
219
|
+
Returns:
|
|
220
|
+
log10_k_abs_tot: jnp.ndarray, size-averaged log10 absorption opacities (shape: [P, Q])
|
|
221
|
+
log10_k_sca_eff_tot: jnp.ndarray, size-averaged log10 effective scattering opacities (shape: [P, Q])
|
|
222
|
+
'''
|
|
223
|
+
|
|
224
|
+
log10_k_abs_itp_lam = scipy_interp1d( np.log10(lam), np.log10(k_abs), axis=1, kind="cubic")( np.log10(lam0) )
|
|
225
|
+
log10_k_sca_eff_itp_lam = scipy_interp1d( np.log10(lam), np.log10(k_sca_eff), axis=1, kind="cubic")( np.log10(lam0) )
|
|
226
|
+
|
|
227
|
+
log10_k_abs_itp = jnp.array( scipy_interp1d( np.log10(a), log10_k_abs_itp_lam , kind='cubic', bounds_error=False, fill_value="extrapolate")(log10_a_dense))
|
|
228
|
+
log10_k_sca_eff_itp = jnp.array( scipy_interp1d( np.log10(a), log10_k_sca_eff_itp_lam, kind='cubic', bounds_error=False, fill_value="extrapolate")(log10_a_dense))
|
|
229
|
+
|
|
230
|
+
# smoothing to avoid Mie interference wiggles
|
|
231
|
+
|
|
232
|
+
if smooth:
|
|
233
|
+
sigma_a = log10_a_smooth/ ( log10_a_dense[1] - log10_a_dense[0])
|
|
234
|
+
|
|
235
|
+
log10_k_abs_itp = jnp.array( gaussian_filter1d( np.array(log10_k_abs_itp), sigma=sigma_a ) )
|
|
236
|
+
log10_k_sca_eff_itp = jnp.array( gaussian_filter1d( np.array(log10_k_sca_eff_itp), sigma=sigma_a ) )
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
vmap_over_q = jax.vmap(
|
|
242
|
+
size_average_opacity,
|
|
243
|
+
in_axes=(None, None, None, None, None, 0) # q だけが配列
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
vmap_over_a_and_q = jax.vmap(
|
|
248
|
+
vmap_over_q,
|
|
249
|
+
in_axes=(None, None, None, 0, None, None) # log10_a_max だけが配列
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
log10_k_abs_tot, log10_k_sca_eff_tot = vmap_over_a_and_q(
|
|
254
|
+
log10_a_dense,
|
|
255
|
+
log10_k_abs_itp,
|
|
256
|
+
log10_k_sca_eff_itp,
|
|
257
|
+
log10_a_dense,
|
|
258
|
+
log10_a_min,
|
|
259
|
+
q_dense
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
return log10_k_abs_tot, log10_k_sca_eff_tot
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def pbcor_fac_ALMA_12m( r, nu, D = 10.7e2, d = 0.75e2 ):
|
|
267
|
+
'''
|
|
268
|
+
This is the same equation implemented in CASA. Note that this is not the same as the physically correct equation.
|
|
269
|
+
See the CASA documentation for details.
|
|
270
|
+
r: radius in arcsec
|
|
271
|
+
nu: frequeny in Hz
|
|
272
|
+
'''
|
|
273
|
+
|
|
274
|
+
eps = d/D
|
|
275
|
+
|
|
276
|
+
k = np.pi * nu/c
|
|
277
|
+
x = k*D*np.sin(np.deg2rad(r/3600))
|
|
278
|
+
|
|
279
|
+
t1 = 2.0 * j1(x)/x
|
|
280
|
+
t2 = 2.0 * eps * j1( x /eps )/ x
|
|
281
|
+
|
|
282
|
+
V = 1/(1-eps**2)**2 * ( t1 - eps**2 * t2 )**2
|
|
283
|
+
|
|
284
|
+
return V
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def obscured_airy_pattern_CASA(theta, D, d, nu):
|
|
288
|
+
'''
|
|
289
|
+
In a function in CASA (PBMath1DAiry::fillPBArray()), the obscured Airy disk is implimented as follows.
|
|
290
|
+
I think this is likely not correct, as the "lengthRatio" parameter is multiplied to D,
|
|
291
|
+
resulting in larger effective blockage than the aparture itself.
|
|
292
|
+
|
|
293
|
+
theta : offset from the center (arcsec)
|
|
294
|
+
D : aparture diameter (cm)
|
|
295
|
+
d : blockage diameter (cm)
|
|
296
|
+
nu : frequency (Hz)
|
|
297
|
+
'''
|
|
298
|
+
|
|
299
|
+
areaRatio = (D/d)**2
|
|
300
|
+
areaNorm = areaRatio - 1.0
|
|
301
|
+
lengthRatio = D/d
|
|
302
|
+
|
|
303
|
+
k = np.pi * nu/c
|
|
304
|
+
x = k*D*np.sin(np.deg2rad(theta/3600))
|
|
305
|
+
|
|
306
|
+
v = ( areaRatio * 2.0 * j1(x)/x - 2.0 * j1( x * lengthRatio)/(x*lengthRatio) )/ areaNorm
|
|
307
|
+
|
|
308
|
+
V = v**2
|
|
309
|
+
|
|
310
|
+
return V
|
|
311
|
+
|
|
312
|
+
def beam_func(rho, nu):
|
|
313
|
+
|
|
314
|
+
D = 10.7*100
|
|
315
|
+
d = 0.75*100
|
|
316
|
+
return obscured_airy_pattern_CASA(rho, D, d, nu)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def get_deprojected_beam_arcsec(r_grid, nu, incl, pa=0.0, dx=0.0, dy=0.0, n_theta=360):
|
|
320
|
+
|
|
321
|
+
i_rad = incl
|
|
322
|
+
pa_rad = pa
|
|
323
|
+
|
|
324
|
+
theta = np.linspace(0, 2 * np.pi, n_theta, endpoint=False)
|
|
325
|
+
|
|
326
|
+
R, Theta = np.meshgrid(r_grid, theta, indexing='ij')
|
|
327
|
+
|
|
328
|
+
x_d = R * np.cos(Theta)
|
|
329
|
+
y_d = R * np.sin(Theta)
|
|
330
|
+
|
|
331
|
+
x_s = x_d
|
|
332
|
+
y_s = y_d * np.cos(i_rad)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
cos_pa, sin_pa = np.cos(pa_rad), np.sin(pa_rad)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
ra_off = x_s * cos_pa - y_s * sin_pa + dx
|
|
339
|
+
dec_off = x_s * sin_pa + y_s * cos_pa + dy
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
rho = np.sqrt(ra_off**2 + dec_off**2)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
beam_values = beam_func(rho, nu)
|
|
347
|
+
A_eff = np.mean(beam_values, axis=1)
|
|
348
|
+
|
|
349
|
+
return A_eff
|
|
350
|
+
|
|
351
|
+
#f_A = get_deprojected_beam_arcsec(r_GP, beam_func, incl=6.0, pa=6.0, dx=-1.0, dy=2.0, n_theta=360)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
#plt.plot(r_GP, f_A)
|
|
356
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
##### utility functions for cross-validation and data splitting ####
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import jax
|
|
6
|
+
import jax.numpy as jnp
|
|
7
|
+
import numpy as np
|
|
8
|
+
from ._constants import *
|
|
9
|
+
from astropy import units as u
|
|
10
|
+
import warnings
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _get_indices(n_folds, bands, obs, seed = 1):
|
|
16
|
+
'''get indices for cross-validation splitting
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
n_folds (int): number of folds for cross-validation
|
|
20
|
+
bands (list): list of band names to split
|
|
21
|
+
obs (dict): dictionary containing observation data for each band
|
|
22
|
+
seed (int): random seed for reproducibility (default: 1)
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
all_fold_indices (dict): dictionary containing indices for each fold
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
np.random.seed(seed)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# all_fold_indices[data_id][sub_key] = [fold0_idx, fold1_idx, ...]
|
|
32
|
+
all_fold_indices = {}
|
|
33
|
+
|
|
34
|
+
for band in bands:
|
|
35
|
+
|
|
36
|
+
all_fold_indices[band] = {}
|
|
37
|
+
|
|
38
|
+
for ch_id in obs[band]['q'].keys():
|
|
39
|
+
|
|
40
|
+
n_vis = len(obs[band]['q'][ch_id])
|
|
41
|
+
|
|
42
|
+
indices = np.arange(n_vis)
|
|
43
|
+
|
|
44
|
+
np.random.shuffle(indices)
|
|
45
|
+
|
|
46
|
+
all_fold_indices[band][ch_id] = np.array_split(indices, n_folds)
|
|
47
|
+
|
|
48
|
+
return all_fold_indices
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def split_data(n_folds, bands, obs, seed = 1):
|
|
53
|
+
'''Split the observation data into training and test sets for cross-validation.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
n_folds (int): number of folds for cross-validation
|
|
57
|
+
bands (list): list of band names to split
|
|
58
|
+
obs (dict): dictionary containing observation data for each band
|
|
59
|
+
seed (int): random seed for reproducibility (default: 1)
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
train_obs (dict): dictionary containing training observation data for each fold
|
|
63
|
+
test_obs (dict): dictionary containing test observation data for each fold
|
|
64
|
+
|
|
65
|
+
'''
|
|
66
|
+
|
|
67
|
+
all_fold_indices = _get_indices(n_folds, bands, obs, seed = seed)
|
|
68
|
+
|
|
69
|
+
test_obs = {}
|
|
70
|
+
train_obs = {}
|
|
71
|
+
|
|
72
|
+
for fold_idx in range(n_folds):
|
|
73
|
+
|
|
74
|
+
test_obs[fold_idx] = {}
|
|
75
|
+
train_obs[fold_idx] = {}
|
|
76
|
+
|
|
77
|
+
for band in bands:
|
|
78
|
+
|
|
79
|
+
train_q, train_V, train_s = {}, {}, {}
|
|
80
|
+
val_q, val_V, val_s = {}, {}, {}
|
|
81
|
+
|
|
82
|
+
for ch_id in obs[band]['q'].keys():
|
|
83
|
+
|
|
84
|
+
# get index
|
|
85
|
+
folds = all_fold_indices[band][ch_id]
|
|
86
|
+
|
|
87
|
+
val_idx = folds[fold_idx]
|
|
88
|
+
train_idx = np.concatenate([folds[i] for i in range(n_folds) if i != fold_idx])
|
|
89
|
+
|
|
90
|
+
# slice for training
|
|
91
|
+
train_q[ch_id] = obs[band]['q'][ch_id][train_idx]
|
|
92
|
+
train_V[ch_id] = obs[band]['V'][ch_id][train_idx]
|
|
93
|
+
train_s[ch_id] = obs[band]['s'][ch_id][train_idx]
|
|
94
|
+
|
|
95
|
+
# slice for test
|
|
96
|
+
val_q[ch_id] = obs[band]['q'][ch_id][val_idx]
|
|
97
|
+
val_V[ch_id] = obs[band]['V'][ch_id][val_idx]
|
|
98
|
+
val_s[ch_id] = obs[band]['s'][ch_id][val_idx]
|
|
99
|
+
|
|
100
|
+
test_obs[fold_idx][band] = {'q': val_q, 'V': val_V, 's': val_s, 'nu' : obs[band]['nu'], 'Nch': obs[band]['Nch']}
|
|
101
|
+
train_obs[fold_idx][band] = {'q': train_q, 'V': train_V, 's': train_s, 'nu' : obs[band]['nu'], 'Nch': obs[band]['Nch']}
|
|
102
|
+
|
|
103
|
+
return train_obs, test_obs
|