plotastrodata 1.10.1__tar.gz → 1.10.3__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.10.3/PKG-INFO +125 -0
- plotastrodata-1.10.3/README.md +96 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/__init__.py +1 -1
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/analysis_utils.py +100 -31
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/fits_utils.py +12 -4
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/fitting_utils.py +22 -3
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/matrix_utils.py +2 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/noise_utils.py +11 -2
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/other_utils.py +16 -12
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/plot_utils.py +32 -28
- plotastrodata-1.10.3/plotastrodata.egg-info/PKG-INFO +125 -0
- plotastrodata-1.10.1/PKG-INFO +0 -128
- plotastrodata-1.10.1/README.md +0 -99
- plotastrodata-1.10.1/plotastrodata.egg-info/PKG-INFO +0 -128
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/LICENSE +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/MANIFEST.in +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/const_utils.py +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/coord_utils.py +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/ext_utils.py +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/fft_utils.py +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata/los_utils.py +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata.egg-info/SOURCES.txt +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata.egg-info/dependency_links.txt +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata.egg-info/not-zip-safe +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata.egg-info/requires.txt +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/plotastrodata.egg-info/top_level.txt +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/setup.cfg +0 -0
- {plotastrodata-1.10.1 → plotastrodata-1.10.3}/setup.py +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plotastrodata
|
|
3
|
+
Version: 1.10.3
|
|
4
|
+
Summary: plotastrodata is a tool for astronomers to create figures from FITS files and perform fundamental data analyses with ease.
|
|
5
|
+
Home-page: https://github.com/yusukeaso-astron/plotastrodata
|
|
6
|
+
Download-URL: https://github.com/yusukeaso-astron/plotastrodata
|
|
7
|
+
Author: yusukeaso-astron
|
|
8
|
+
License: GNU General Public License Version 3
|
|
9
|
+
Keywords: astronomy,FITS,plot
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: astropy>=7.2
|
|
15
|
+
Requires-Dist: corner
|
|
16
|
+
Requires-Dist: dynesty
|
|
17
|
+
Requires-Dist: emcee>=3.1.5
|
|
18
|
+
Requires-Dist: matplotlib
|
|
19
|
+
Requires-Dist: numpy>=2.0
|
|
20
|
+
Requires-Dist: pillow
|
|
21
|
+
Requires-Dist: plotly
|
|
22
|
+
Requires-Dist: ptemcee
|
|
23
|
+
Requires-Dist: pydantic>=2
|
|
24
|
+
Requires-Dist: scikit-image
|
|
25
|
+
Requires-Dist: scipy
|
|
26
|
+
Requires-Dist: tqdm
|
|
27
|
+
Dynamic: download-url
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# plotastrodata
|
|
31
|
+
Python package to make figures from radio astronomical data by astropy and matplotlib.
|
|
32
|
+
The API, examples, and gallery are available in [readthedocs](https://plotastrodata.readthedocs.io/en/latest/).
|
|
33
|
+
The PDF manual is available [here](https://github.com/yusukeaso-astron/plotastrodata/blob/main/plotastrodata_manual.pdf).
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Highlights
|
|
37
|
+
|
|
38
|
+
* Read, write, and process astronomical FITS images, spectral cubes, position-velocity diagrams, and NumPy arrays, including WCS coordinates, spectral axes, beam information, and brightness-temperature conversion.
|
|
39
|
+
* Create 2D maps, channel maps, position-velocity diagrams, RGB composites, line profiles, spatial slices, and interactive 3D isosurface visualizations.
|
|
40
|
+
* Overlay color, contour, polarization-vector, and RGB data from different spatial grids, with astronomical coordinates, beams, scale bars, regions, markers, and other annotations.
|
|
41
|
+
* Prepare data through trimming, interpolation, binning, masking, centering, rotation, deprojection, beam circularization, and profile extraction.
|
|
42
|
+
* Estimate image noise, including support for primary-beam-corrected data.
|
|
43
|
+
* Fit Gaussian models to line profiles and two-dimensional image components.
|
|
44
|
+
* Use supporting tools for coordinate and line-of-sight transformations, centered Fourier transforms and visibility sampling, and Bayesian or grid-based parameter estimation.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
Install from conda-forge:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
conda install conda-forge::plotastrodata
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
or from PyPI:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install plotastrodata
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To install the latest source from GitHub:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/yusukeaso-astron/plotastrodata
|
|
64
|
+
cd plotastrodata
|
|
65
|
+
python -m pip install .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To update a source installation, run the following commands in the cloned repository:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git pull
|
|
72
|
+
python -m pip install --upgrade .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Demo and Usage
|
|
76
|
+
|
|
77
|
+
The repository includes [`example.py`](example.py), which demonstrates the main plotting and analysis features. After cloning the repository and installing the package, run:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
python example.py
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
More examples and the complete API reference are available in the [online documentation](https://plotastrodata.readthedocs.io/en/latest/).
|
|
84
|
+
|
|
85
|
+
## Requirement
|
|
86
|
+
|
|
87
|
+
* Python >= 3.11
|
|
88
|
+
* astropy >= 7.2
|
|
89
|
+
* corner (only for fitting)
|
|
90
|
+
* dynesty (only for fitting)
|
|
91
|
+
* emcee >= 3.1.5 (only for fitting)
|
|
92
|
+
* ffmpeg (only for movie)
|
|
93
|
+
* matplotlib
|
|
94
|
+
* numpy >= 2.0
|
|
95
|
+
* pillow (only for RGB figures)
|
|
96
|
+
* plotly (only for html cube)
|
|
97
|
+
* ptemcee (only for fitting)
|
|
98
|
+
* pydantic >= 2
|
|
99
|
+
* scikit-image (only for html cube)
|
|
100
|
+
* scipy
|
|
101
|
+
* tqdm (only for fitting)
|
|
102
|
+
|
|
103
|
+
## Conventions and Limitations
|
|
104
|
+
|
|
105
|
+
* Array axes are ordered as `(y, x)` for a 2D image, `(v, y, x)` for a spectral cube, and `(v, x)` for a position-velocity diagram. With NumPy-array input, supply matching one-dimensional coordinate arrays; a spectral cube requires `v` to construct channel maps. FITS input obtains these coordinates from its header.
|
|
106
|
+
* Spatial coordinates are offsets from `center`. They are expressed in arcseconds when `dist=1`. When `dist` is set to the source distance in parsecs, spatial offsets and beam sizes are expressed in au.
|
|
107
|
+
* By default, the R.A. axis increases toward the left (`xflip=True`), following the usual astronomical image convention. Use `xflip=False` to reverse this behavior.
|
|
108
|
+
* Velocity coordinates and `vsys` are in km/s, while `restfreq` is in Hz. A frequency axis read from FITS is converted to velocity relative to `vsys`.
|
|
109
|
+
* Sky positions may be given as coordinate strings, such as `'ICRS 01h23m45.6s 01d23m45.6s'`. Numeric positions supplied through `poslist`, such as `[0.2, 0.3]`, are relative plotting positions: 0 is the left or bottom edge and 1 is the right or top edge. They are not spatial offsets.
|
|
110
|
+
* Angles are in degrees unless an API explicitly states otherwise. Sky position angles are measured from north toward east. The polar-coordinate arrays `theta` and `phi` used by the line-of-sight utilities are in radians.
|
|
111
|
+
* A beam is represented by `[bmaj, bmin, bpa]`, where the first two values use the current spatial unit and `bpa` is in degrees. `Tb=True` converts data from Jy/beam to brightness temperature and requires a valid rest frequency and spatial-resolution metadata.
|
|
112
|
+
* `sigma` may be a numeric RMS value, a string selecting a noise-estimation method, or `None` to disable noise-dependent behavior. See the API documentation for the available estimation methods.
|
|
113
|
+
* Annotation methods accept a single value or a list of values. `include_chan` selects displayed channels by zero-based index; `None` applies the annotation to all channels.
|
|
114
|
+
* Position-velocity mode (`pv=True`) does not support regions, lines, arrows, or segment maps because its spatial and velocity axes use different units. Markers and text may still be placed using relative plotting positions.
|
|
115
|
+
* Constants in `const_utils` are plain numerical values in SI units, not `astropy.units.Quantity` objects.
|
|
116
|
+
|
|
117
|
+
## Author
|
|
118
|
+
|
|
119
|
+
* Name: Yusuke Aso
|
|
120
|
+
* Affiliation: Korea Astronomy and Space Science Institute
|
|
121
|
+
* E-mail: yaso@kasi.re.kr
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
"plotastrodata" is under [GNU General Public License Version 3](https://www.gnu.org/licenses/gpl-3.0.html).
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# plotastrodata
|
|
2
|
+
Python package to make figures from radio astronomical data by astropy and matplotlib.
|
|
3
|
+
The API, examples, and gallery are available in [readthedocs](https://plotastrodata.readthedocs.io/en/latest/).
|
|
4
|
+
The PDF manual is available [here](https://github.com/yusukeaso-astron/plotastrodata/blob/main/plotastrodata_manual.pdf).
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Highlights
|
|
8
|
+
|
|
9
|
+
* Read, write, and process astronomical FITS images, spectral cubes, position-velocity diagrams, and NumPy arrays, including WCS coordinates, spectral axes, beam information, and brightness-temperature conversion.
|
|
10
|
+
* Create 2D maps, channel maps, position-velocity diagrams, RGB composites, line profiles, spatial slices, and interactive 3D isosurface visualizations.
|
|
11
|
+
* Overlay color, contour, polarization-vector, and RGB data from different spatial grids, with astronomical coordinates, beams, scale bars, regions, markers, and other annotations.
|
|
12
|
+
* Prepare data through trimming, interpolation, binning, masking, centering, rotation, deprojection, beam circularization, and profile extraction.
|
|
13
|
+
* Estimate image noise, including support for primary-beam-corrected data.
|
|
14
|
+
* Fit Gaussian models to line profiles and two-dimensional image components.
|
|
15
|
+
* Use supporting tools for coordinate and line-of-sight transformations, centered Fourier transforms and visibility sampling, and Bayesian or grid-based parameter estimation.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install from conda-forge:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
conda install conda-forge::plotastrodata
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
or from PyPI:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install plotastrodata
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
To install the latest source from GitHub:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/yusukeaso-astron/plotastrodata
|
|
35
|
+
cd plotastrodata
|
|
36
|
+
python -m pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To update a source installation, run the following commands in the cloned repository:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git pull
|
|
43
|
+
python -m pip install --upgrade .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Demo and Usage
|
|
47
|
+
|
|
48
|
+
The repository includes [`example.py`](example.py), which demonstrates the main plotting and analysis features. After cloning the repository and installing the package, run:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
python example.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
More examples and the complete API reference are available in the [online documentation](https://plotastrodata.readthedocs.io/en/latest/).
|
|
55
|
+
|
|
56
|
+
## Requirement
|
|
57
|
+
|
|
58
|
+
* Python >= 3.11
|
|
59
|
+
* astropy >= 7.2
|
|
60
|
+
* corner (only for fitting)
|
|
61
|
+
* dynesty (only for fitting)
|
|
62
|
+
* emcee >= 3.1.5 (only for fitting)
|
|
63
|
+
* ffmpeg (only for movie)
|
|
64
|
+
* matplotlib
|
|
65
|
+
* numpy >= 2.0
|
|
66
|
+
* pillow (only for RGB figures)
|
|
67
|
+
* plotly (only for html cube)
|
|
68
|
+
* ptemcee (only for fitting)
|
|
69
|
+
* pydantic >= 2
|
|
70
|
+
* scikit-image (only for html cube)
|
|
71
|
+
* scipy
|
|
72
|
+
* tqdm (only for fitting)
|
|
73
|
+
|
|
74
|
+
## Conventions and Limitations
|
|
75
|
+
|
|
76
|
+
* Array axes are ordered as `(y, x)` for a 2D image, `(v, y, x)` for a spectral cube, and `(v, x)` for a position-velocity diagram. With NumPy-array input, supply matching one-dimensional coordinate arrays; a spectral cube requires `v` to construct channel maps. FITS input obtains these coordinates from its header.
|
|
77
|
+
* Spatial coordinates are offsets from `center`. They are expressed in arcseconds when `dist=1`. When `dist` is set to the source distance in parsecs, spatial offsets and beam sizes are expressed in au.
|
|
78
|
+
* By default, the R.A. axis increases toward the left (`xflip=True`), following the usual astronomical image convention. Use `xflip=False` to reverse this behavior.
|
|
79
|
+
* Velocity coordinates and `vsys` are in km/s, while `restfreq` is in Hz. A frequency axis read from FITS is converted to velocity relative to `vsys`.
|
|
80
|
+
* Sky positions may be given as coordinate strings, such as `'ICRS 01h23m45.6s 01d23m45.6s'`. Numeric positions supplied through `poslist`, such as `[0.2, 0.3]`, are relative plotting positions: 0 is the left or bottom edge and 1 is the right or top edge. They are not spatial offsets.
|
|
81
|
+
* Angles are in degrees unless an API explicitly states otherwise. Sky position angles are measured from north toward east. The polar-coordinate arrays `theta` and `phi` used by the line-of-sight utilities are in radians.
|
|
82
|
+
* A beam is represented by `[bmaj, bmin, bpa]`, where the first two values use the current spatial unit and `bpa` is in degrees. `Tb=True` converts data from Jy/beam to brightness temperature and requires a valid rest frequency and spatial-resolution metadata.
|
|
83
|
+
* `sigma` may be a numeric RMS value, a string selecting a noise-estimation method, or `None` to disable noise-dependent behavior. See the API documentation for the available estimation methods.
|
|
84
|
+
* Annotation methods accept a single value or a list of values. `include_chan` selects displayed channels by zero-based index; `None` applies the annotation to all channels.
|
|
85
|
+
* Position-velocity mode (`pv=True`) does not support regions, lines, arrows, or segment maps because its spatial and velocity axes use different units. Markers and text may still be placed using relative plotting positions.
|
|
86
|
+
* Constants in `const_utils` are plain numerical values in SI units, not `astropy.units.Quantity` objects.
|
|
87
|
+
|
|
88
|
+
## Author
|
|
89
|
+
|
|
90
|
+
* Name: Yusuke Aso
|
|
91
|
+
* Affiliation: Korea Astronomy and Space Science Institute
|
|
92
|
+
* E-mail: yaso@kasi.re.kr
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
"plotastrodata" is under [GNU General Public License Version 3](https://www.gnu.org/licenses/gpl-3.0.html).
|
|
@@ -19,7 +19,7 @@ from plotastrodata.other_utils import (isdeg, nearest_index,
|
|
|
19
19
|
|
|
20
20
|
def quadrantmean(data: np.ndarray, x: np.ndarray, y: np.ndarray,
|
|
21
21
|
quadrants: str = '13'
|
|
22
|
-
) -> tuple[np.ndarray, np.ndarray, np.ndarray]
|
|
22
|
+
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
23
23
|
"""Take mean between 1st and 3rd (or 2nd and 4th) quadrants.
|
|
24
24
|
|
|
25
25
|
Args:
|
|
@@ -32,12 +32,10 @@ def quadrantmean(data: np.ndarray, x: np.ndarray, y: np.ndarray,
|
|
|
32
32
|
tuple: Averaged (data, x, y).
|
|
33
33
|
"""
|
|
34
34
|
if np.ndim(data) != 2:
|
|
35
|
-
|
|
36
|
-
return
|
|
35
|
+
raise ValueError('data must be a 2D array.')
|
|
37
36
|
|
|
38
37
|
if quadrants not in ['13', '24']:
|
|
39
|
-
|
|
40
|
-
return
|
|
38
|
+
raise ValueError("quadrants must be '13' or '24'.")
|
|
41
39
|
|
|
42
40
|
dx = x[1] - x[0]
|
|
43
41
|
dy = y[1] - y[0]
|
|
@@ -65,6 +63,8 @@ def filled2d(data: np.ndarray, x: np.ndarray, y: np.ndarray, n: int = 1,
|
|
|
65
63
|
Returns:
|
|
66
64
|
tuple: The interpolated (data, x, y).
|
|
67
65
|
"""
|
|
66
|
+
if not isinstance(n, (int, np.integer)) or n < 1:
|
|
67
|
+
raise ValueError('n must be a positive integer.')
|
|
68
68
|
xnew = np.linspace(x[0], x[-1], n * (len(x) - 1) + 1)
|
|
69
69
|
ynew = np.linspace(y[0], y[-1], n * (len(y) - 1) + 1)
|
|
70
70
|
d = RGIxy(y, x, data, np.meshgrid(ynew, xnew, indexing='ij'),
|
|
@@ -73,11 +73,11 @@ def filled2d(data: np.ndarray, x: np.ndarray, y: np.ndarray, n: int = 1,
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
def _need_multipixels(method: Callable) -> Callable:
|
|
76
|
-
def wrapper(cls: Any, *args: Any, **kwargs: Any) -> Any
|
|
76
|
+
def wrapper(cls: Any, *args: Any, **kwargs: Any) -> Any:
|
|
77
77
|
singlepixel = cls.dx is None or cls.dy is None
|
|
78
78
|
if singlepixel:
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
raise ValueError(
|
|
80
|
+
f'{method.__name__}() requires at least two x and y pixels.')
|
|
81
81
|
return method(cls, *args, **kwargs)
|
|
82
82
|
return wrapper
|
|
83
83
|
|
|
@@ -125,17 +125,26 @@ class AstroData():
|
|
|
125
125
|
bunit: str = ''
|
|
126
126
|
|
|
127
127
|
def __post_init__(self) -> None:
|
|
128
|
+
fits_values = (self.fitsimage if isinstance(self.fitsimage, list)
|
|
129
|
+
else [self.fitsimage])
|
|
130
|
+
has_fits = any(a is not None for a in fits_values)
|
|
131
|
+
if isinstance(self.data, list):
|
|
132
|
+
has_data = any(a is not None for a in self.data)
|
|
133
|
+
else:
|
|
134
|
+
has_data = self.data is not None
|
|
135
|
+
if has_fits and has_data:
|
|
136
|
+
raise ValueError('Provide either data or fitsimage, not both.')
|
|
137
|
+
if not has_fits and not has_data:
|
|
138
|
+
raise ValueError('Either data or fitsimage must be given.')
|
|
139
|
+
|
|
128
140
|
n = 0
|
|
129
|
-
if
|
|
141
|
+
if has_fits:
|
|
130
142
|
if not isinstance(self.fitsimage, list):
|
|
131
143
|
n = 1
|
|
132
|
-
elif any(a is not None for a in self.fitsimage):
|
|
133
|
-
n = len(self.fitsimage)
|
|
134
144
|
else:
|
|
135
|
-
n =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if self.data is not None:
|
|
145
|
+
n = len(self.fitsimage)
|
|
146
|
+
self.data = None
|
|
147
|
+
if has_data:
|
|
139
148
|
if _is_data_list(self.data):
|
|
140
149
|
n = len(self.data)
|
|
141
150
|
elif (isinstance(self.data, list)
|
|
@@ -144,8 +153,6 @@ class AstroData():
|
|
|
144
153
|
else:
|
|
145
154
|
self.data = np.asarray(self.data)
|
|
146
155
|
n = 1
|
|
147
|
-
if n == 0:
|
|
148
|
-
print('Either data or fitsimage must be given.')
|
|
149
156
|
self.n = n
|
|
150
157
|
self.fitsimage_org = None
|
|
151
158
|
self.sigma_org = None
|
|
@@ -154,8 +161,11 @@ class AstroData():
|
|
|
154
161
|
|
|
155
162
|
def _binning_one(self, t: str, width: float) -> None:
|
|
156
163
|
grid = getattr(self, t)
|
|
157
|
-
if width == 1
|
|
164
|
+
if width == 1:
|
|
158
165
|
return
|
|
166
|
+
if grid is None:
|
|
167
|
+
raise ValueError(
|
|
168
|
+
f'Binning in the {t}-axis requires a {t} coordinate array.')
|
|
159
169
|
|
|
160
170
|
dt = f'd{t}'
|
|
161
171
|
sep = getattr(self, dt)
|
|
@@ -184,6 +194,10 @@ class AstroData():
|
|
|
184
194
|
Args:
|
|
185
195
|
width (list, optional): Number of channels, y-pixels, and x-pixels for binning. Defaults to [1, 1, 1].
|
|
186
196
|
"""
|
|
197
|
+
if len(width) > 3 or any(not isinstance(a, (int, np.integer))
|
|
198
|
+
or a < 1 for a in width):
|
|
199
|
+
raise ValueError(
|
|
200
|
+
'width must contain one to three positive integers.')
|
|
187
201
|
w = np.array([1] * (3 - len(width)) + list(width), dtype=int)
|
|
188
202
|
if self.pv:
|
|
189
203
|
w[1] = max(w[0], w[1])
|
|
@@ -252,8 +266,7 @@ class AstroData():
|
|
|
252
266
|
"""Make the beam circular by convolving with 1D Gaussian
|
|
253
267
|
"""
|
|
254
268
|
if None in self.beam:
|
|
255
|
-
|
|
256
|
-
return
|
|
269
|
+
raise ValueError('circularbeam() requires a complete beam.')
|
|
257
270
|
|
|
258
271
|
bmaj, bmin, bpa = self.beam
|
|
259
272
|
self.rotate(-bpa)
|
|
@@ -411,14 +424,25 @@ class AstroData():
|
|
|
411
424
|
"""
|
|
412
425
|
if dataformask is None:
|
|
413
426
|
dataformask = self.data
|
|
427
|
+
if len(includepix) not in [0, 2] or len(excludepix) not in [0, 2]:
|
|
428
|
+
raise ValueError(
|
|
429
|
+
'includepix and excludepix must be empty or [min, max].')
|
|
414
430
|
if np.ndim(self.data) > np.ndim(dataformask):
|
|
415
431
|
print('The mask is broadcasted.')
|
|
416
|
-
|
|
432
|
+
try:
|
|
433
|
+
mask = np.broadcast_to(dataformask, np.shape(self.data))
|
|
434
|
+
except ValueError as exc:
|
|
435
|
+
raise ValueError(
|
|
436
|
+
'dataformask must be broadcastable to the data shape; '
|
|
437
|
+
f'got {np.shape(dataformask)} and {np.shape(self.data)}.'
|
|
438
|
+
) from exc
|
|
417
439
|
else:
|
|
418
440
|
mask = dataformask
|
|
419
441
|
if np.shape(self.data) != np.shape(mask):
|
|
420
|
-
|
|
421
|
-
|
|
442
|
+
raise ValueError(
|
|
443
|
+
'dataformask must have the same shape as data after '
|
|
444
|
+
f'broadcasting; got {np.shape(dataformask)} and '
|
|
445
|
+
f'{np.shape(self.data)}.')
|
|
422
446
|
|
|
423
447
|
if len(includepix) == 2:
|
|
424
448
|
self.data[(mask < includepix[0]) + (includepix[1] < mask)] = np.nan
|
|
@@ -445,7 +469,7 @@ class AstroData():
|
|
|
445
469
|
ellipse: list[float, float, float] | None = None,
|
|
446
470
|
ninterp: int = 1,
|
|
447
471
|
flux: bool = False, gaussfit: bool = False
|
|
448
|
-
) -> tuple[np.ndarray, np.ndarray, dict]
|
|
472
|
+
) -> tuple[np.ndarray, np.ndarray, dict]:
|
|
449
473
|
"""Get a list of line profiles at given spatial coordinates.
|
|
450
474
|
|
|
451
475
|
Args:
|
|
@@ -461,8 +485,11 @@ class AstroData():
|
|
|
461
485
|
tuple: (v, list of profiles, result of Gaussian fit)
|
|
462
486
|
"""
|
|
463
487
|
if np.ndim(self.data) != 3 or self.v is None:
|
|
464
|
-
|
|
465
|
-
|
|
488
|
+
raise ValueError('profile() requires 3D data with v, y, and x axes.')
|
|
489
|
+
if len(xlist) != len(ylist):
|
|
490
|
+
raise ValueError('xlist and ylist must have the same length.')
|
|
491
|
+
if len(coords) == 0 and len(xlist) == 0:
|
|
492
|
+
raise ValueError('Provide coords or matching xlist and ylist values.')
|
|
466
493
|
|
|
467
494
|
data, xf, yf = filled2d(self.data, self.x, self.y, ninterp)
|
|
468
495
|
x, y = np.meshgrid(xf, yf)
|
|
@@ -484,7 +511,8 @@ class AstroData():
|
|
|
484
511
|
prof[i] = [calc(d[r <= 1]) for d in data]
|
|
485
512
|
if flux:
|
|
486
513
|
if None in self.beam or None in [self.dx, self.dy]:
|
|
487
|
-
|
|
514
|
+
raise ValueError(
|
|
515
|
+
'flux=True requires a complete beam and x/y pixel sizes.')
|
|
488
516
|
else:
|
|
489
517
|
Omega = np.pi * self.beam[0] * self.beam[1] / 4. / np.log(2.)
|
|
490
518
|
prof *= np.abs(self.dx * self.dy) / Omega
|
|
@@ -503,7 +531,7 @@ class AstroData():
|
|
|
503
531
|
self.beam[2] = self.beam[2] + pa
|
|
504
532
|
|
|
505
533
|
def slice(self, length: float = 0, pa: float = 0,
|
|
506
|
-
dx: float | None = None, **kwargs: Any) -> np.ndarray
|
|
534
|
+
dx: float | None = None, **kwargs: Any) -> np.ndarray:
|
|
507
535
|
"""Get 1D slice with given a length and a position-angle.
|
|
508
536
|
|
|
509
537
|
Args:
|
|
@@ -517,8 +545,11 @@ class AstroData():
|
|
|
517
545
|
if dx is None and self.dx is not None:
|
|
518
546
|
dx = np.abs(self.dx)
|
|
519
547
|
if dx is None:
|
|
520
|
-
|
|
521
|
-
|
|
548
|
+
raise ValueError('slice() requires dx or an x grid with pixel size.')
|
|
549
|
+
if not np.isfinite(dx) or dx <= 0:
|
|
550
|
+
raise ValueError('dx must be finite and positive.')
|
|
551
|
+
if not np.isfinite(length) or length < 0:
|
|
552
|
+
raise ValueError('length must be finite and nonnegative.')
|
|
522
553
|
|
|
523
554
|
n = int(np.ceil(length / 2 / dx))
|
|
524
555
|
r = np.linspace(-n, n, 2 * n + 1) * dx
|
|
@@ -772,13 +803,41 @@ class AstroFrame():
|
|
|
772
803
|
d.v = v
|
|
773
804
|
|
|
774
805
|
def _xyskip(self, d: AstroData, i: int,
|
|
775
|
-
|
|
806
|
+
x: np.ndarray | None, y: np.ndarray | None) -> None:
|
|
776
807
|
d.x = x[::self.xskip]
|
|
777
808
|
d.y = y[::self.yskip]
|
|
778
809
|
data = np.moveaxis(d.data[i], [-2, -1], [0, 1])
|
|
779
810
|
data = data[::self.yskip, ::self.xskip]
|
|
780
811
|
d.data[i] = np.moveaxis(data, [0, 1], [-2, -1])
|
|
781
812
|
|
|
813
|
+
def _validate_data_grid(self, data: np.ndarray, grid: list,
|
|
814
|
+
dataset: int) -> None:
|
|
815
|
+
"""Validate array axes before trimming or spatial subsampling."""
|
|
816
|
+
shape = np.shape(np.squeeze(data))
|
|
817
|
+
if len(shape) not in [2, 3]:
|
|
818
|
+
raise ValueError(
|
|
819
|
+
f'Dataset {dataset} must be 2D or 3D; got shape {shape}.')
|
|
820
|
+
|
|
821
|
+
x, y, v = grid
|
|
822
|
+
required = [('x', x, shape[-1])]
|
|
823
|
+
if self.pv:
|
|
824
|
+
required.append(('v', v, shape[-2]))
|
|
825
|
+
else:
|
|
826
|
+
required.append(('y', y, shape[-2]))
|
|
827
|
+
if len(shape) == 3:
|
|
828
|
+
required.append(('v', v, shape[-3]))
|
|
829
|
+
for name, axis, expected in required:
|
|
830
|
+
if axis is None:
|
|
831
|
+
raise ValueError(
|
|
832
|
+
f'Dataset {dataset} requires a {name} coordinate array.')
|
|
833
|
+
if np.ndim(axis) != 1:
|
|
834
|
+
raise ValueError(
|
|
835
|
+
f'Dataset {dataset} {name} must be a 1D array.')
|
|
836
|
+
if len(axis) != expected:
|
|
837
|
+
raise ValueError(
|
|
838
|
+
f'Dataset {dataset} {name} has length {len(axis)}, but '
|
|
839
|
+
f'the corresponding data axis has length {expected}.')
|
|
840
|
+
|
|
782
841
|
def _trim_skip(self, d: AstroData, i: int, grid: list) -> None:
|
|
783
842
|
d.data[i], grid = trim(data=d.data[i],
|
|
784
843
|
x=grid[0], y=grid[1], v=grid[2],
|
|
@@ -831,6 +890,7 @@ class AstroFrame():
|
|
|
831
890
|
d.sigma_org[i] = d.sigma[i]
|
|
832
891
|
grid = self._read_fitsimage(d, i, grid=grid)
|
|
833
892
|
if d.data[i] is not None:
|
|
893
|
+
self._validate_data_grid(d.data[i], grid, i)
|
|
834
894
|
d.sigma[i] = estimate_rms(d.data[i], d.sigma[i])
|
|
835
895
|
grid = self._shift_center(d, i, grid)
|
|
836
896
|
self._trim_skip(d, i, grid)
|
|
@@ -857,11 +917,20 @@ class AstroFrame():
|
|
|
857
917
|
d (AstroData): Dataclass for the add_* input.
|
|
858
918
|
xskip, yskip (int): Spatial pixel skip. Defaults to 1.
|
|
859
919
|
"""
|
|
920
|
+
if (not isinstance(xskip, (int, np.integer)) or xskip < 1
|
|
921
|
+
or not isinstance(yskip, (int, np.integer)) or yskip < 1):
|
|
922
|
+
raise ValueError('xskip and yskip must be positive integers.')
|
|
860
923
|
self.xskip = xskip
|
|
861
924
|
self.yskip = yskip
|
|
862
925
|
for name in ASTRODATA_ARGS:
|
|
863
926
|
setattr(d, name, _as_list(getattr(d, name), d.n))
|
|
864
927
|
d.beam = _as_list(d.beam, d.n, isbeam=True)
|
|
928
|
+
for name in ASTRODATA_ARGS + ['beam']:
|
|
929
|
+
value = getattr(d, name)
|
|
930
|
+
if len(value) != d.n:
|
|
931
|
+
raise ValueError(
|
|
932
|
+
f'{name} must contain one value or {d.n} values; '
|
|
933
|
+
f'got {len(value)}.')
|
|
865
934
|
grid = [d.x, d.y, d.v]
|
|
866
935
|
for i in range(d.n):
|
|
867
936
|
self._read_one(d, i, grid.copy()) # .copy() not to updated d.x again ang again.
|
|
@@ -12,7 +12,7 @@ from plotastrodata.other_utils import isdeg, RGIxy, trim
|
|
|
12
12
|
|
|
13
13
|
def Jy2K(header: Any = None, bmaj: float | None = None,
|
|
14
14
|
bmin: float | None = None,
|
|
15
|
-
restfreq: float | None = None) -> float
|
|
15
|
+
restfreq: float | None = None) -> float:
|
|
16
16
|
"""Calculate a conversion factor in the unit of K/Jy.
|
|
17
17
|
|
|
18
18
|
Args:
|
|
@@ -28,7 +28,7 @@ def Jy2K(header: Any = None, bmaj: float | None = None,
|
|
|
28
28
|
if header is not None:
|
|
29
29
|
if 'BMAJ' in header and 'BMIN' in header:
|
|
30
30
|
bmaj, bmin = header['BMAJ'] * 3600, header['BMIN'] * 3600
|
|
31
|
-
|
|
31
|
+
elif 'CDELT1' in header and 'CUNIT1' in header:
|
|
32
32
|
print('Use CDELT1^2 for Tb conversion.')
|
|
33
33
|
todiameter = np.sqrt(4 * np.log(2) / np.pi) * 3600
|
|
34
34
|
bmaj = bmin = np.abs(header['CDELT1']) * todiameter
|
|
@@ -41,8 +41,16 @@ def Jy2K(header: Any = None, bmaj: float | None = None,
|
|
|
41
41
|
if restfreq is not None:
|
|
42
42
|
freq = restfreq
|
|
43
43
|
if freq is None:
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
raise ValueError(
|
|
45
|
+
'Brightness-temperature conversion requires restfreq or a '
|
|
46
|
+
'RESTFREQ/RESTFRQ header value.')
|
|
47
|
+
if not np.isfinite(freq) or freq <= 0:
|
|
48
|
+
raise ValueError('restfreq must be finite and positive.')
|
|
49
|
+
if (bmaj is None or bmin is None or not np.isfinite(bmaj)
|
|
50
|
+
or not np.isfinite(bmin) or bmaj <= 0 or bmin <= 0):
|
|
51
|
+
raise ValueError(
|
|
52
|
+
'Brightness-temperature conversion requires finite, positive '
|
|
53
|
+
'bmaj and bmin values or equivalent FITS header metadata.')
|
|
46
54
|
omega = bmaj * bmin * units.arcsec**2 * np.pi / 4. / np.log(2.)
|
|
47
55
|
equiv = units.brightness_temperature(freq * units.Hz, beam_area=omega)
|
|
48
56
|
T = (1 * units.Jy / units.beam).to(units.K, equivalencies=equiv)
|
|
@@ -107,17 +107,30 @@ class EmceeCorner():
|
|
|
107
107
|
sigma: float | np.ndarray = 1, progressbar: bool = False,
|
|
108
108
|
percent: list = [16, 84]) -> None:
|
|
109
109
|
global global_bounds, global_progressbar
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
bounds_array = np.asarray(bounds, dtype=float)
|
|
111
|
+
if bounds_array.ndim != 2 or 2 not in bounds_array.shape:
|
|
112
|
+
raise ValueError('bounds must have shape (dim, 2) or (2, dim).')
|
|
113
|
+
if bounds_array.shape[1] != 2:
|
|
114
|
+
global_bounds = np.transpose(bounds_array)
|
|
112
115
|
print('bounds has been transposed because its shape is (2, dim).')
|
|
113
116
|
else:
|
|
114
|
-
global_bounds =
|
|
117
|
+
global_bounds = bounds_array
|
|
118
|
+
if (not np.all(np.isfinite(global_bounds))
|
|
119
|
+
or np.any(global_bounds[:, 0] >= global_bounds[:, 1])):
|
|
120
|
+
raise ValueError(
|
|
121
|
+
'Each parameter bound must be finite with lower < upper.')
|
|
122
|
+
if (len(percent) != 2 or not 0 <= percent[0] < percent[1] <= 100):
|
|
123
|
+
raise ValueError(
|
|
124
|
+
'percent must contain two increasing values between 0 and 100.')
|
|
115
125
|
global_progressbar = progressbar
|
|
116
126
|
if logl is None and (model is not None
|
|
117
127
|
and xdata is not None
|
|
118
128
|
and ydata is not None):
|
|
119
129
|
logl = partial(_gaussian_log_likelihood, model=model,
|
|
120
130
|
xdata=xdata, ydata=ydata, sigma=sigma)
|
|
131
|
+
if logl is None:
|
|
132
|
+
raise ValueError(
|
|
133
|
+
'Provide logl, or provide model, xdata, and ydata together.')
|
|
121
134
|
self.bounds = global_bounds
|
|
122
135
|
self.dim = len(self.bounds)
|
|
123
136
|
self.logl = logl
|
|
@@ -221,6 +234,12 @@ class EmceeCorner():
|
|
|
221
234
|
pt (bool, optional): Whether to use ptemcee; otherwise, emcee is used. Defaults to False.
|
|
222
235
|
"""
|
|
223
236
|
global bar
|
|
237
|
+
if nsteps < 1:
|
|
238
|
+
raise ValueError('nsteps must be positive.')
|
|
239
|
+
if nburnin < 0 or nburnin >= nsteps:
|
|
240
|
+
raise ValueError('nburnin must satisfy 0 <= nburnin < nsteps.')
|
|
241
|
+
if ntemps < 1 or ntry < 1 or ncores < 1:
|
|
242
|
+
raise ValueError('ntemps, ntry, and ncores must be positive.')
|
|
224
243
|
if nwalkersperdim < 2:
|
|
225
244
|
print('nwalkersperdim < 2 is not allowed.'
|
|
226
245
|
+ f' Use 2 instead of {nwalkersperdim:d}.')
|
|
@@ -56,6 +56,8 @@ def Mrot3d(t: float, axis: int = 3) -> np.ndarray:
|
|
|
56
56
|
Returns:
|
|
57
57
|
np.ndarray: 3x3 rotation matrix that rotates coordinates around the specified axis by t degrees.
|
|
58
58
|
"""
|
|
59
|
+
if axis not in [1, 2, 3]:
|
|
60
|
+
raise ValueError('axis must be 1, 2, or 3.')
|
|
59
61
|
cos_t = np.cos(np.radians(t))
|
|
60
62
|
sin_t = np.sin(np.radians(t))
|
|
61
63
|
match axis:
|
|
@@ -123,9 +123,15 @@ class Noise:
|
|
|
123
123
|
"""
|
|
124
124
|
def __init__(self, data: np.ndarray, sigma: str) -> None:
|
|
125
125
|
self.data = select_noise(data, sigma)
|
|
126
|
+
if self.data.size < 2:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
'Noise estimation requires at least two selected finite pixels.')
|
|
126
129
|
self.sigma = sigma
|
|
127
130
|
self.m0 = np.mean(self.data)
|
|
128
131
|
self.s0 = np.std(self.data)
|
|
132
|
+
if not np.isfinite(self.s0):
|
|
133
|
+
raise ValueError(
|
|
134
|
+
'Noise estimation requires selected pixels with finite values.')
|
|
129
135
|
|
|
130
136
|
def gen_histogram(self, **kwargs: Any) -> None:
|
|
131
137
|
"""Generate a pair of histogram and bins using numpy.histogram.
|
|
@@ -135,6 +141,10 @@ class Noise:
|
|
|
135
141
|
Default keyword values:
|
|
136
142
|
numpy.histogram: ``bins=100``, ``range=(-3.5, 3.5)``, and ``density=True``. User-supplied keyword arguments override these values.
|
|
137
143
|
"""
|
|
144
|
+
if self.s0 == 0:
|
|
145
|
+
raise ValueError(
|
|
146
|
+
'Histogram noise estimation requires selected pixels with '
|
|
147
|
+
'nonzero variance.')
|
|
138
148
|
_kw = {'bins': 100, 'range': (-3.5, 3.5), 'density': True}
|
|
139
149
|
_kw.update(kwargs)
|
|
140
150
|
self.bins = _kw['bins']
|
|
@@ -215,8 +225,7 @@ def estimate_rms(data: np.ndarray,
|
|
|
215
225
|
return sigma
|
|
216
226
|
|
|
217
227
|
if np.ndim(np.squeeze(data)) == 0:
|
|
218
|
-
|
|
219
|
-
return 0.0
|
|
228
|
+
raise ValueError('sigma cannot be estimated from only one pixel.')
|
|
220
229
|
|
|
221
230
|
n = Noise(data, sigma)
|
|
222
231
|
if 'hist' in sigma:
|