plotastrodata 1.7.14__tar.gz → 1.8.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.
- {plotastrodata-1.7.14/plotastrodata.egg-info → plotastrodata-1.8.1}/PKG-INFO +1 -1
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/__init__.py +1 -1
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/analysis_utils.py +2 -2
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/fits_utils.py +2 -2
- plotastrodata-1.8.1/plotastrodata/noise_utils.py +222 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/other_utils.py +0 -124
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/plot_utils.py +33 -7
- {plotastrodata-1.7.14 → plotastrodata-1.8.1/plotastrodata.egg-info}/PKG-INFO +1 -1
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata.egg-info/SOURCES.txt +1 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/LICENSE +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/MANIFEST.in +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/README.md +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/const_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/coord_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/ext_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/fft_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/fitting_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/los_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata/matrix_utils.py +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata.egg-info/dependency_links.txt +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata.egg-info/not-zip-safe +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata.egg-info/requires.txt +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/plotastrodata.egg-info/top_level.txt +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/setup.cfg +0 -0
- {plotastrodata-1.7.14 → plotastrodata-1.8.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plotastrodata
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.1
|
|
4
4
|
Summary: plotastrodata is a tool for astronomers to create figures from FITS files and perform fundamental data analyses with ease.
|
|
5
5
|
Home-page: https://github.com/yusukeaso-astron/plotastrodata
|
|
6
6
|
Download-URL: https://github.com/yusukeaso-astron/plotastrodata
|
|
@@ -7,8 +7,8 @@ from scipy.signal import convolve
|
|
|
7
7
|
|
|
8
8
|
from plotastrodata.coord_utils import coord2xy, xy2coord, rel2abs
|
|
9
9
|
from plotastrodata.matrix_utils import Mfac, Mrot, dot2d
|
|
10
|
-
from plotastrodata.
|
|
11
|
-
|
|
10
|
+
from plotastrodata.noise_utils import estimate_rms
|
|
11
|
+
from plotastrodata.other_utils import (trim, gaussian2d, isdeg,
|
|
12
12
|
RGIxy, RGIxyv, to4dim)
|
|
13
13
|
from plotastrodata.fits_utils import FitsData, data2fits, Jy2K
|
|
14
14
|
from plotastrodata import const_utils as cu
|
|
@@ -4,8 +4,8 @@ from astropy import units, wcs
|
|
|
4
4
|
|
|
5
5
|
from plotastrodata.coord_utils import coord2xy, xy2coord
|
|
6
6
|
from plotastrodata.matrix_utils import dot2d
|
|
7
|
-
from plotastrodata.
|
|
8
|
-
|
|
7
|
+
from plotastrodata.noise_utils import estimate_rms
|
|
8
|
+
from plotastrodata.other_utils import trim, isdeg, RGIxy
|
|
9
9
|
from plotastrodata import const_utils as cu
|
|
10
10
|
|
|
11
11
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
import numpy as np
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from scipy.special import erf
|
|
5
|
+
|
|
6
|
+
from plotastrodata.fitting_utils import EmceeCorner
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def normalize(range: tuple = (-3.5, 3.5), bins: int = 100):
|
|
10
|
+
"""Decorator factory to normalize a function over the given range."""
|
|
11
|
+
def decorator(f):
|
|
12
|
+
h = np.linspace(*range, bins + 1)
|
|
13
|
+
h = (h[1:] + h[:-1]) / 2
|
|
14
|
+
dh = (range[1] - range[0]) / 100
|
|
15
|
+
|
|
16
|
+
def wrapper(x, *args):
|
|
17
|
+
area = np.sum(f(h, *args)) * dh
|
|
18
|
+
if area == 0:
|
|
19
|
+
p = np.where(np.abs(x - args[1]) < dh / 2, 1 / dh, 0)
|
|
20
|
+
else:
|
|
21
|
+
p = f(x, *args) / area
|
|
22
|
+
return p
|
|
23
|
+
|
|
24
|
+
return wrapper
|
|
25
|
+
return decorator
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def gauss(x: np.ndarray, s: float, m: float) -> np.ndarray:
|
|
29
|
+
"""Probability density of Gaussian noise.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
x (np.ndarray): Intensity. The variable of the probability density.
|
|
33
|
+
s (float): Standard deviation of the Gaussian noise.
|
|
34
|
+
m (float): Mean of the Gaussian noise.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
np.ndarray: Probability density.
|
|
38
|
+
"""
|
|
39
|
+
x1 = (x - m) / np.sqrt(2) / s
|
|
40
|
+
p = np.exp(-x1**2)
|
|
41
|
+
p = p / (np.sqrt(2 * np.pi) * s)
|
|
42
|
+
return p
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def gauss_pbcor(x: np.ndarray, s: float, m: float, R: float
|
|
46
|
+
) -> np.ndarray:
|
|
47
|
+
"""Probability density of Gaussian noise after primary-beam correction.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
x (np.ndarray): Intensity. The variable of the probability density.
|
|
51
|
+
s (float): Standard deviation of the Gaussian noise.
|
|
52
|
+
m (float): Mean of the Gaussian noise.
|
|
53
|
+
R (float): The maximum radius scaled by the FWHM of the primary beam.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
np.ndarray: Probability density.
|
|
57
|
+
"""
|
|
58
|
+
x1 = (x - m) / np.sqrt(2) / s
|
|
59
|
+
x0 = (x * 2**(-R**2) - m) / np.sqrt(2) / s
|
|
60
|
+
p = erf(x1) - erf(x0)
|
|
61
|
+
p = p / (2 * np.log(2) * x * R**2)
|
|
62
|
+
return p
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def select_noise(data: np.ndarray, sigma: str) -> np.ndarray:
|
|
66
|
+
"""Select data pixels to be used for noise estimation.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
data (np.ndarray): Original data array.
|
|
70
|
+
sigma (str): Selection methods. Multiple options are possible. 'edge', 'out', 'neg', or 'iter'.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
np.ndarray: 1D array that includes only the selected pixels.
|
|
74
|
+
"""
|
|
75
|
+
n = data * 1
|
|
76
|
+
if 'edge' in sigma:
|
|
77
|
+
if np.ndim(n) <= 2:
|
|
78
|
+
print('\'edge\' is ignored because ndim <= 2.')
|
|
79
|
+
else:
|
|
80
|
+
n = n[::len(n) - 1]
|
|
81
|
+
if 'out' in sigma and 'pbcor' in sigma:
|
|
82
|
+
print('\'out\' is ignored because of \'pbcor\'.')
|
|
83
|
+
elif 'out' in sigma:
|
|
84
|
+
nx = np.shape(n)[-1]
|
|
85
|
+
ny = np.shape(n)[-2]
|
|
86
|
+
ntmp = np.moveaxis(n, [-2, -1], [0, 1])
|
|
87
|
+
ntmp[ny // 5: ny * 4 // 5, nx // 5: nx * 4 // 5] = np.nan
|
|
88
|
+
if np.all(np.isnan(ntmp)):
|
|
89
|
+
print('\'out\' is ignored because'
|
|
90
|
+
+ ' the outer region is filled with nan.')
|
|
91
|
+
else:
|
|
92
|
+
n = ntmp
|
|
93
|
+
n = n[~np.isnan(n)]
|
|
94
|
+
if 'neg' in sigma:
|
|
95
|
+
n = n[n < 0]
|
|
96
|
+
n = np.r_[n, -n]
|
|
97
|
+
if 'iter' in sigma:
|
|
98
|
+
for _ in range(5):
|
|
99
|
+
n = n[np.abs(n - np.mean(n)) < 3.5 * np.std(n)]
|
|
100
|
+
return n.ravel()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class Noise:
|
|
104
|
+
def __init__(self, data: np.ndarray, sigma: str):
|
|
105
|
+
"""This class holds the data selected as noise, histogram, and best-fit function.
|
|
106
|
+
The following methods are acceptable for data selection. Multiple options are possible.
|
|
107
|
+
'edge': use data[0] and data[-1].
|
|
108
|
+
'out': exclude inner 60% about axes=-2 and -1.
|
|
109
|
+
'neg': use only negative values.
|
|
110
|
+
'iter': exclude outliers.
|
|
111
|
+
The following methods are acceptable for noise estimation. Only single option is possible.
|
|
112
|
+
'med': calculate rms from the median of data^2 assuming Gaussian.
|
|
113
|
+
'hist': fit histgram with Gaussian.
|
|
114
|
+
'hist-pbcor': fit histgram with PB-corrected Gaussian.
|
|
115
|
+
'(no string)': calculate the mean and standard deviation.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
data (np.ndarray): Original data array.
|
|
119
|
+
sigma (str): Methods above, like 'edge,neg,hist-pbcor'.
|
|
120
|
+
"""
|
|
121
|
+
self.data = select_noise(data, sigma)
|
|
122
|
+
self.sigma = sigma
|
|
123
|
+
self.m0 = np.mean(self.data)
|
|
124
|
+
self.s0 = np.std(self.data)
|
|
125
|
+
|
|
126
|
+
def gen_histogram(self, **kwargs):
|
|
127
|
+
"""Generage a pair of histogram and bins using numpy.histogram. The data values are shifted and scaled by the mean and standard deviation, respectively, to generate the histogram. The mean and standard deviation are stored as self.m0 and self.s0, respectively.
|
|
128
|
+
"""
|
|
129
|
+
_kw = {'bins': 100, 'range': (-3.5, 3.5), 'density': True}
|
|
130
|
+
_kw.update(kwargs)
|
|
131
|
+
self.bins = _kw['bins']
|
|
132
|
+
self.range = _kw['range']
|
|
133
|
+
n = (self.data - self.m0) / self.s0
|
|
134
|
+
hist, hbin = np.histogram(n, **_kw)
|
|
135
|
+
hbin = (hbin[:-1] + hbin[1:]) / 2
|
|
136
|
+
self.hist = hist
|
|
137
|
+
self.hbin = hbin
|
|
138
|
+
|
|
139
|
+
def fit_histogram(self, **kwargs):
|
|
140
|
+
"""kwargs is for plotastrodata.fitting_utils.EmceeCorner.
|
|
141
|
+
"""
|
|
142
|
+
_kw = {'nwalkersperdim': 4, 'nsteps': 200, 'nburnin': 0}
|
|
143
|
+
_kw.update(kwargs)
|
|
144
|
+
f = gauss_pbcor if 'pbcor' in self.sigma else gauss
|
|
145
|
+
model = normalize(range=self.range, bins=self.bins)(f)
|
|
146
|
+
bounds = [[0.1, 2], [-2, 2]]
|
|
147
|
+
if 'pbcor' in self.sigma:
|
|
148
|
+
bounds.append([0.1, 2])
|
|
149
|
+
# curve_fit does not work for this fitting.
|
|
150
|
+
# 0.01 in sigma is set only to search the best-fit parameters.
|
|
151
|
+
# Thus, this sigma does not justify the parameter errors.
|
|
152
|
+
fitter = EmceeCorner(bounds=bounds, model=model,
|
|
153
|
+
xdata=self.hbin, ydata=self.hist,
|
|
154
|
+
sigma=np.max(self.hist) * 0.01)
|
|
155
|
+
fitter.fit(**_kw)
|
|
156
|
+
self.popt = fitter.popt
|
|
157
|
+
self.mean = float(self.popt[1] * self.s0 + self.m0)
|
|
158
|
+
self.std = float(self.popt[0] * self.s0)
|
|
159
|
+
self.model = model(self.hbin, *self.popt)
|
|
160
|
+
|
|
161
|
+
def plot_histogram(self, savefig: dict | str | None = None,
|
|
162
|
+
show: bool = False):
|
|
163
|
+
"""Make a simple figure of the histogram and model.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
|
|
167
|
+
show (bool, optional): True means doing plt.show(). Defaults to False.
|
|
168
|
+
"""
|
|
169
|
+
savefig0 = {'bbox_inches': 'tight', 'transparent': True}
|
|
170
|
+
fig = plt.figure()
|
|
171
|
+
ax = fig.add_subplot(1, 1, 1)
|
|
172
|
+
ax.plot(self.hbin, self.hist, drawstyle='steps-mid')
|
|
173
|
+
ax.plot(self.hbin, self.model, '-')
|
|
174
|
+
ax.set_xlabel('(noise - m0) / s0')
|
|
175
|
+
ax.set_ylabel('Probability density')
|
|
176
|
+
fig.tight_layout()
|
|
177
|
+
if savefig is not None:
|
|
178
|
+
s = {'fname': savefig} if type(savefig) is str else savefig
|
|
179
|
+
savefig0.update(s)
|
|
180
|
+
fig.savefig(**savefig0)
|
|
181
|
+
if show:
|
|
182
|
+
plt.show()
|
|
183
|
+
plt.close()
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def estimate_rms(data: np.ndarray,
|
|
187
|
+
sigma: float | str | None = 'hist'
|
|
188
|
+
) -> float:
|
|
189
|
+
"""Estimate a noise level of a data array.
|
|
190
|
+
When a float number or None is given as sigma, this function just outputs it.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
data (np.ndarray): Data array whose noise is estimated.
|
|
194
|
+
sigma (float or str): Methods for the Noise class, like 'edge,neg,hist-pbcor'. Defaults to 'hist'.
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
float: The estimated standard deviation of noise.
|
|
198
|
+
"""
|
|
199
|
+
nums = [float, int, np.float64, np.int64, np.float32, np.int32]
|
|
200
|
+
if sigma is None or type(sigma) in nums:
|
|
201
|
+
return sigma
|
|
202
|
+
|
|
203
|
+
if np.ndim(np.squeeze(data)) == 0:
|
|
204
|
+
print('sigma cannot be estimated from only one pixel.')
|
|
205
|
+
return 0.0
|
|
206
|
+
|
|
207
|
+
n = Noise(data, sigma)
|
|
208
|
+
if 'hist' in sigma:
|
|
209
|
+
n.gen_histogram()
|
|
210
|
+
n.fit_histogram()
|
|
211
|
+
ave = n.mean
|
|
212
|
+
noise = n.std
|
|
213
|
+
elif 'med' in sigma:
|
|
214
|
+
ave = 0
|
|
215
|
+
noise = np.sqrt(np.median(n.data**2) / 0.454936)
|
|
216
|
+
else:
|
|
217
|
+
ave = n.m0
|
|
218
|
+
noise = n.s0
|
|
219
|
+
if np.abs(ave) > 0.2 * noise:
|
|
220
|
+
s = 'Mean > 0.2 x standard deviation.'
|
|
221
|
+
warnings.warn(s, UserWarning)
|
|
222
|
+
return noise
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import warnings
|
|
2
1
|
import numpy as np
|
|
3
|
-
from scipy.special import erf
|
|
4
2
|
from scipy.interpolate import RegularGridInterpolator as RGI
|
|
5
3
|
|
|
6
|
-
from plotastrodata.fitting_utils import EmceeCorner
|
|
7
4
|
from plotastrodata.matrix_utils import Mrot, dot2d
|
|
8
5
|
|
|
9
6
|
|
|
@@ -37,127 +34,6 @@ def isdeg(s: str) -> bool:
|
|
|
37
34
|
return False
|
|
38
35
|
|
|
39
36
|
|
|
40
|
-
def _estimate_rms_hist(data: np.ndarray, sigma: str) -> tuple:
|
|
41
|
-
h_range = (-3.5, 3.5)
|
|
42
|
-
h = np.linspace(*h_range, 101)
|
|
43
|
-
dh = 0.07
|
|
44
|
-
m0 = np.mean(data)
|
|
45
|
-
s0 = np.std(data)
|
|
46
|
-
hist, hbin = np.histogram((data - m0) / s0, bins=100,
|
|
47
|
-
density=True, range=h_range)
|
|
48
|
-
hbin = (hbin[:-1] + hbin[1:]) / 2
|
|
49
|
-
|
|
50
|
-
def normalize(f):
|
|
51
|
-
"""Decorator to normalize a function over h_range."""
|
|
52
|
-
def wrapper(x, *args):
|
|
53
|
-
area = np.sum(f(h, *args)) * dh
|
|
54
|
-
if area == 0:
|
|
55
|
-
p = np.where(np.abs(x - args[1]) < dh / 2, 1 / dh, 0)
|
|
56
|
-
else:
|
|
57
|
-
p = f(x, *args) / area
|
|
58
|
-
return p
|
|
59
|
-
return wrapper
|
|
60
|
-
|
|
61
|
-
if 'pbcor' in sigma:
|
|
62
|
-
@normalize
|
|
63
|
-
def model(x, *args):
|
|
64
|
-
s, m, R = args
|
|
65
|
-
x1 = (x - m) / np.sqrt(2) / s
|
|
66
|
-
x0 = (x * 2**(-R**2) - m) / np.sqrt(2) / s
|
|
67
|
-
p = erf(x1) - erf(x0)
|
|
68
|
-
p = p / (2 * np.log(2) * x * R**2)
|
|
69
|
-
return p
|
|
70
|
-
bounds = [[0.1, 2], [-2, 2], [0.1, 2]]
|
|
71
|
-
else:
|
|
72
|
-
@normalize
|
|
73
|
-
def model(x, *args):
|
|
74
|
-
s, m = args
|
|
75
|
-
x1 = (x - m) / np.sqrt(2) / s
|
|
76
|
-
p = np.exp(-x1**2)
|
|
77
|
-
p = p / (np.sqrt(2 * np.pi) * s)
|
|
78
|
-
return p
|
|
79
|
-
bounds = [[0.1, 2], [-2, 2]]
|
|
80
|
-
# curve_fit does not work for this fitting.
|
|
81
|
-
fitter = EmceeCorner(bounds=bounds, sigma=np.max(hist) * 0.01,
|
|
82
|
-
model=model, xdata=hbin, ydata=hist)
|
|
83
|
-
fitter.fit(nwalkersperdim=4, nsteps=200, nburnin=0)
|
|
84
|
-
popt = fitter.popt
|
|
85
|
-
ave = popt[1] * s0 + m0
|
|
86
|
-
noise = popt[0] * s0
|
|
87
|
-
return ave, noise
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def estimate_rms(data: np.ndarray, sigma: float | str | None = 'hist'
|
|
91
|
-
) -> float:
|
|
92
|
-
"""Estimate a noise level of a N-D array.
|
|
93
|
-
When a float number or None is given, this function just outputs it.
|
|
94
|
-
The following methods are acceptable for data selection. Multiple options are possible.
|
|
95
|
-
'edge': use data[0] and data[-1].
|
|
96
|
-
'out': exclude inner 60% about axes=-2 and -1.
|
|
97
|
-
'neg': use only negative values.
|
|
98
|
-
'iter': exclude outliers.
|
|
99
|
-
The following methods are acceptable for noise estimation. Only single option is possible.
|
|
100
|
-
'med': calculate rms from the median of data^2 assuming Gaussian.
|
|
101
|
-
'hist': fit histgram with Gaussian.
|
|
102
|
-
'hist-pbcor': fit histgram with PB-corrected Gaussian.
|
|
103
|
-
'(no string)': calculate the mean and standard deviation.
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
data (np.ndarray): N-D array.
|
|
107
|
-
sigma (float or str): Methods above, like 'edge,neg,hist-pbcor'. Defaults to 'hist'.
|
|
108
|
-
|
|
109
|
-
Returns:
|
|
110
|
-
float: The estimated standard deviation of noise.
|
|
111
|
-
"""
|
|
112
|
-
nums = [float, int, np.float64, np.int64, np.float32, np.int32]
|
|
113
|
-
if sigma is None or type(sigma) in nums:
|
|
114
|
-
return sigma
|
|
115
|
-
|
|
116
|
-
if np.ndim(np.squeeze(data)) == 0:
|
|
117
|
-
print('sigma cannot be estimated from only one pixel.')
|
|
118
|
-
return 0.0
|
|
119
|
-
|
|
120
|
-
# Selection
|
|
121
|
-
n = data * 1
|
|
122
|
-
if 'edge' in sigma:
|
|
123
|
-
if np.ndim(n) <= 2:
|
|
124
|
-
print('\'edge\' is ignored because ndim <= 2.')
|
|
125
|
-
else:
|
|
126
|
-
n = n[::len(n) - 1]
|
|
127
|
-
if 'out' in sigma and 'pbcor' in sigma:
|
|
128
|
-
print('\'out\' is ignored because of \'pbcor\'.')
|
|
129
|
-
elif 'out' in sigma:
|
|
130
|
-
nx = np.shape(n)[-1]
|
|
131
|
-
ny = np.shape(n)[-2]
|
|
132
|
-
ntmp = np.moveaxis(n, [-2, -1], [0, 1])
|
|
133
|
-
ntmp[ny // 5 : ny * 4 // 5, nx // 5 : nx * 4 // 5] = np.nan
|
|
134
|
-
if np.all(np.isnan(ntmp)):
|
|
135
|
-
print('\'out\' is ignored because'
|
|
136
|
-
+ ' the outer region is filled with nan.')
|
|
137
|
-
else:
|
|
138
|
-
n = ntmp
|
|
139
|
-
n = n[~np.isnan(n)]
|
|
140
|
-
if 'neg' in sigma:
|
|
141
|
-
n = n[n < 0]
|
|
142
|
-
n = np.r_[n, -n]
|
|
143
|
-
if 'iter' in sigma:
|
|
144
|
-
for _ in range(5):
|
|
145
|
-
n = n[np.abs(n - np.mean(n)) < 3.5 * np.std(n)]
|
|
146
|
-
# Estimation
|
|
147
|
-
if 'hist' in sigma:
|
|
148
|
-
ave, noise = _estimate_rms_hist(n, sigma)
|
|
149
|
-
elif 'med' in sigma:
|
|
150
|
-
ave = 0
|
|
151
|
-
noise = np.sqrt(np.median(n**2) / 0.454936)
|
|
152
|
-
else:
|
|
153
|
-
ave = np.mean(n)
|
|
154
|
-
noise = np.std(n)
|
|
155
|
-
if np.abs(ave) > 0.2 * noise:
|
|
156
|
-
s = 'The intensity offset is larger than 0.2 sigma.'
|
|
157
|
-
warnings.warn(s, UserWarning)
|
|
158
|
-
return noise
|
|
159
|
-
|
|
160
|
-
|
|
161
37
|
def trim(data: np.ndarray | None = None, x: np.ndarray | None = None,
|
|
162
38
|
y: np.ndarray | None = None, v: np.ndarray | None = None,
|
|
163
39
|
xlim: list[float, float] | None = None,
|
|
@@ -6,7 +6,8 @@ from matplotlib.patches import Ellipse, Rectangle
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
|
|
8
8
|
from plotastrodata.coord_utils import coord2xy, xy2coord
|
|
9
|
-
from plotastrodata.
|
|
9
|
+
from plotastrodata.noise_utils import estimate_rms
|
|
10
|
+
from plotastrodata.other_utils import listing
|
|
10
11
|
from plotastrodata.analysis_utils import AstroData, AstroFrame
|
|
11
12
|
|
|
12
13
|
|
|
@@ -87,7 +88,7 @@ class PlotAxes2D():
|
|
|
87
88
|
aspect (dict or float, optional): Defaults to None.
|
|
88
89
|
"""
|
|
89
90
|
samexy: bool = True
|
|
90
|
-
loglog:
|
|
91
|
+
loglog: float | None = None
|
|
91
92
|
xscale: str = 'linear'
|
|
92
93
|
yscale: str = 'linear'
|
|
93
94
|
xlim: list | None = None
|
|
@@ -98,8 +99,8 @@ class PlotAxes2D():
|
|
|
98
99
|
yticks: list | None = None
|
|
99
100
|
xticklabels: list | None = None
|
|
100
101
|
yticklabels: list | None = None
|
|
101
|
-
xticksminor: list | int = None
|
|
102
|
-
yticksminor: list | int = None
|
|
102
|
+
xticksminor: list | int | None = None
|
|
103
|
+
yticksminor: list | int | None = None
|
|
103
104
|
grid: dict | None = None
|
|
104
105
|
aspect: dict | float | None = None
|
|
105
106
|
|
|
@@ -1169,9 +1170,12 @@ def plotprofile(coords: list[str] | str = [],
|
|
|
1169
1170
|
title: list[str] | None = None,
|
|
1170
1171
|
text: list[str] | None = None,
|
|
1171
1172
|
dist: float = 1., vsys: float = 0.,
|
|
1172
|
-
nrows: int = 0, ncols: int = 1,
|
|
1173
|
+
nrows: int = 0, ncols: int = 1,
|
|
1174
|
+
fig: object | None = None,
|
|
1175
|
+
ax: object | None = None,
|
|
1173
1176
|
getfigax: bool = False,
|
|
1174
|
-
savefig: dict
|
|
1177
|
+
savefig: dict | str | None = None,
|
|
1178
|
+
show: bool = False,
|
|
1175
1179
|
**kwargs) -> tuple[object, object]:
|
|
1176
1180
|
"""Use Axes.plot of matplotlib to plot line profiles at given coordinates. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs can include the arguments of PlotAxes2D to adjust x and y axes.
|
|
1177
1181
|
|
|
@@ -1187,6 +1191,15 @@ def plotprofile(coords: list[str] | str = [],
|
|
|
1187
1191
|
gauss_kwargs (dict, optional): Kwargs for Axes.plot. Defaults to {}.
|
|
1188
1192
|
title (list, optional): For each plot. Defaults to None.
|
|
1189
1193
|
text (list, optional): For each plot. Defaults to None.
|
|
1194
|
+
dist (float, optional): Change x and y in arcsec to au. Defaults to 1..
|
|
1195
|
+
vsys (float, optional): Each channel shows v-vsys. Defaults to 0..
|
|
1196
|
+
nrows (int, optional): Used for channel maps. Defaults to 0.
|
|
1197
|
+
ncols (int, optional): Used for channel maps. Defaults to 1.
|
|
1198
|
+
fig (optional): External plt.figure(). Defaults to None.
|
|
1199
|
+
ax (optional): External fig.add_subplot(). Defaults to None.
|
|
1200
|
+
getfigax (bool, optional): Defaults to False.
|
|
1201
|
+
savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
|
|
1202
|
+
show (bool, optional): True means doing plt.show(). Defaults to False.
|
|
1190
1203
|
|
|
1191
1204
|
Returns:
|
|
1192
1205
|
tuple: (fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
|
|
@@ -1280,7 +1293,20 @@ def plotslice(length: float, dx: float | None = None, pa: float = 0,
|
|
|
1280
1293
|
length (float): Slice length.
|
|
1281
1294
|
dx (float, optional): Grid increment. Defaults to None.
|
|
1282
1295
|
pa (float, optional): Degree. Position angle. Defaults to 0.
|
|
1283
|
-
|
|
1296
|
+
dist (float, optional): For AstroFrame. Defaults to 1.
|
|
1297
|
+
xoff (float, optional): For AstroFrame. Defaults to 0.
|
|
1298
|
+
yoff (float, optional): For AstroFrame. Defaults to 0.
|
|
1299
|
+
xflip (bool, optional): For AstroFrame. Defaults to True.
|
|
1300
|
+
yflip (bool, optional): For AstroFrame. Defaults to False.
|
|
1301
|
+
txtfile (str, optional): File name for numpy.savetxt(). Defaults to None.
|
|
1302
|
+
fig (optional): External plt.figure(). Defaults to None.
|
|
1303
|
+
ax (optional): External fig.add_subplot(). Defaults to None.
|
|
1304
|
+
getfigax (bool, optional): Defaults to False.
|
|
1305
|
+
savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
|
|
1306
|
+
show (bool, optional): True means doing plt.show(). Defaults to False.
|
|
1307
|
+
|
|
1308
|
+
Returns:
|
|
1309
|
+
tuple: (fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
|
|
1284
1310
|
"""
|
|
1285
1311
|
_kw = {'linestyle': '-', 'marker': 'o'}
|
|
1286
1312
|
_kw.update(kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plotastrodata
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.1
|
|
4
4
|
Summary: plotastrodata is a tool for astronomers to create figures from FITS files and perform fundamental data analyses with ease.
|
|
5
5
|
Home-page: https://github.com/yusukeaso-astron/plotastrodata
|
|
6
6
|
Download-URL: https://github.com/yusukeaso-astron/plotastrodata
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|