plotastrodata 1.11.2__tar.gz → 1.12.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.11.2/plotastrodata.egg-info → plotastrodata-1.12.1}/PKG-INFO +35 -6
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/README.md +34 -5
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/__init__.py +1 -1
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/analysis_utils.py +41 -31
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/const_utils.py +1 -3
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/coord_utils.py +1 -1
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/ext_utils.py +2 -1
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/fits_utils.py +8 -5
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/fitting_utils.py +76 -38
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/matrix_utils.py +2 -2
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/noise_utils.py +12 -7
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/other_utils.py +4 -3
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/plot_utils.py +30 -22
- plotastrodata-1.12.1/plotastrodata/script_utils.py +595 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1/plotastrodata.egg-info}/PKG-INFO +35 -6
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata.egg-info/SOURCES.txt +1 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/LICENSE +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/MANIFEST.in +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/_type_utils.py +2 -2
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/_validation_utils.py +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/fft_utils.py +4 -4
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata/los_utils.py +1 -1
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata.egg-info/dependency_links.txt +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata.egg-info/not-zip-safe +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata.egg-info/requires.txt +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/plotastrodata.egg-info/top_level.txt +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.1}/setup.cfg +0 -0
- {plotastrodata-1.11.2 → plotastrodata-1.12.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.12.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
|
|
@@ -45,6 +45,8 @@ The PDF manual is available [here](https://github.com/yusukeaso-astron/plotastro
|
|
|
45
45
|
|
|
46
46
|
## Installation
|
|
47
47
|
|
|
48
|
+
### Released version
|
|
49
|
+
|
|
48
50
|
Install from conda-forge:
|
|
49
51
|
|
|
50
52
|
```bash
|
|
@@ -57,19 +59,22 @@ or from PyPI:
|
|
|
57
59
|
pip install plotastrodata
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
### Development version from GitHub
|
|
63
|
+
|
|
64
|
+
Clone the repository to install the latest development version, which may
|
|
65
|
+
include changes not yet available in the published releases:
|
|
61
66
|
|
|
62
67
|
```bash
|
|
63
68
|
git clone https://github.com/yusukeaso-astron/plotastrodata
|
|
64
|
-
cd plotastrodata
|
|
65
|
-
python -m pip install .
|
|
69
|
+
(cd plotastrodata)
|
|
70
|
+
(python -m pip install .)
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
To update
|
|
73
|
+
To update the development version, run the following commands in the cloned repository:
|
|
69
74
|
|
|
70
75
|
```bash
|
|
71
76
|
git pull
|
|
72
|
-
python -m pip install --upgrade .
|
|
77
|
+
(python -m pip install --upgrade .)
|
|
73
78
|
```
|
|
74
79
|
|
|
75
80
|
## Demo and Usage
|
|
@@ -82,6 +87,30 @@ python example.py
|
|
|
82
87
|
|
|
83
88
|
More examples and the complete API reference are available in the [online documentation](https://plotastrodata.readthedocs.io/en/latest/).
|
|
84
89
|
|
|
90
|
+
## Generate plotting scripts
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from plotastrodata.script_utils import generate_image_script
|
|
94
|
+
|
|
95
|
+
script = generate_image_script(
|
|
96
|
+
"image.fits", output="image.py",
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Review the inline values, then run `python image.py`. The script uses existing
|
|
101
|
+
library APIs to visualize a hist-pbcor noise fit, fit a 2D Gaussian and report
|
|
102
|
+
its sky center and east/north uncertainties, and plot a logarithmic image
|
|
103
|
+
with contours, a beam, and RA/Dec axes. It saves separate noise and image PNGs.
|
|
104
|
+
Noise estimation uses the full image. Fitting and plotting ranges are estimated automatically and written inline
|
|
105
|
+
with three significant digits for editing.
|
|
106
|
+
For a spectral cube, use `generate_cube_script("cube.fits", output="cube.py")`
|
|
107
|
+
from the same module. It generates an edge-channel noise visualization, a flux-integrated line
|
|
108
|
+
profile and 3D channel maps over estimated spatial and velocity ranges,
|
|
109
|
+
with intrinsic channel spacing. The flux profile assumes Jy/beam data with beam metadata.
|
|
110
|
+
Both generators return an absolute pathlib.Path and write the script
|
|
111
|
+
without executing it.
|
|
112
|
+
See the [script-generation guide](docs/script_generation.rst).
|
|
113
|
+
|
|
85
114
|
## Requirement
|
|
86
115
|
|
|
87
116
|
* Python >= 3.11
|
|
@@ -16,6 +16,8 @@ The PDF manual is available [here](https://github.com/yusukeaso-astron/plotastro
|
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
|
+
### Released version
|
|
20
|
+
|
|
19
21
|
Install from conda-forge:
|
|
20
22
|
|
|
21
23
|
```bash
|
|
@@ -28,19 +30,22 @@ or from PyPI:
|
|
|
28
30
|
pip install plotastrodata
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
### Development version from GitHub
|
|
34
|
+
|
|
35
|
+
Clone the repository to install the latest development version, which may
|
|
36
|
+
include changes not yet available in the published releases:
|
|
32
37
|
|
|
33
38
|
```bash
|
|
34
39
|
git clone https://github.com/yusukeaso-astron/plotastrodata
|
|
35
|
-
cd plotastrodata
|
|
36
|
-
python -m pip install .
|
|
40
|
+
(cd plotastrodata)
|
|
41
|
+
(python -m pip install .)
|
|
37
42
|
```
|
|
38
43
|
|
|
39
|
-
To update
|
|
44
|
+
To update the development version, run the following commands in the cloned repository:
|
|
40
45
|
|
|
41
46
|
```bash
|
|
42
47
|
git pull
|
|
43
|
-
python -m pip install --upgrade .
|
|
48
|
+
(python -m pip install --upgrade .)
|
|
44
49
|
```
|
|
45
50
|
|
|
46
51
|
## Demo and Usage
|
|
@@ -53,6 +58,30 @@ python example.py
|
|
|
53
58
|
|
|
54
59
|
More examples and the complete API reference are available in the [online documentation](https://plotastrodata.readthedocs.io/en/latest/).
|
|
55
60
|
|
|
61
|
+
## Generate plotting scripts
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from plotastrodata.script_utils import generate_image_script
|
|
65
|
+
|
|
66
|
+
script = generate_image_script(
|
|
67
|
+
"image.fits", output="image.py",
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Review the inline values, then run `python image.py`. The script uses existing
|
|
72
|
+
library APIs to visualize a hist-pbcor noise fit, fit a 2D Gaussian and report
|
|
73
|
+
its sky center and east/north uncertainties, and plot a logarithmic image
|
|
74
|
+
with contours, a beam, and RA/Dec axes. It saves separate noise and image PNGs.
|
|
75
|
+
Noise estimation uses the full image. Fitting and plotting ranges are estimated automatically and written inline
|
|
76
|
+
with three significant digits for editing.
|
|
77
|
+
For a spectral cube, use `generate_cube_script("cube.fits", output="cube.py")`
|
|
78
|
+
from the same module. It generates an edge-channel noise visualization, a flux-integrated line
|
|
79
|
+
profile and 3D channel maps over estimated spatial and velocity ranges,
|
|
80
|
+
with intrinsic channel spacing. The flux profile assumes Jy/beam data with beam metadata.
|
|
81
|
+
Both generators return an absolute pathlib.Path and write the script
|
|
82
|
+
without executing it.
|
|
83
|
+
See the [script-generation guide](docs/script_generation.rst).
|
|
84
|
+
|
|
56
85
|
## Requirement
|
|
57
86
|
|
|
58
87
|
* Python >= 3.11
|
|
@@ -1,35 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import warnings
|
|
1
|
+
import numbers
|
|
3
2
|
import re
|
|
3
|
+
import warnings
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
|
-
from os import PathLike
|
|
6
5
|
from functools import wraps
|
|
7
|
-
import
|
|
6
|
+
from os import PathLike
|
|
7
|
+
from typing import Any, Callable, Literal, ParamSpec, TypedDict, TypeVar
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
8
10
|
from astropy.io.fits import Header
|
|
9
|
-
from scipy.interpolate import RegularGridInterpolator as RGI
|
|
10
|
-
from scipy.signal import convolve
|
|
11
11
|
from pydantic import ConfigDict
|
|
12
12
|
from pydantic.dataclasses import dataclass as pydantic_dataclass
|
|
13
|
-
from
|
|
14
|
-
|
|
13
|
+
from scipy.interpolate import RegularGridInterpolator as RGI
|
|
14
|
+
from scipy.signal import convolve
|
|
15
15
|
|
|
16
16
|
from plotastrodata import const_utils as cu
|
|
17
|
-
from plotastrodata.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
from plotastrodata.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
from plotastrodata._type_utils import (
|
|
18
|
+
BeamInput,
|
|
19
|
+
Position,
|
|
20
|
+
RealScalar,
|
|
21
|
+
ValidatedFloat,
|
|
22
|
+
_internal_field,
|
|
23
|
+
_normalize_float,
|
|
24
|
+
)
|
|
25
|
+
from plotastrodata._validation_utils import (
|
|
26
|
+
_is_finite_real_scalar,
|
|
27
|
+
_is_positive_real_scalar,
|
|
28
|
+
_is_zero_dimensional_array,
|
|
29
|
+
_require_integer,
|
|
30
|
+
_require_positive_real_scalar,
|
|
31
|
+
)
|
|
32
|
+
from plotastrodata.coord_utils import _getframe, coord2xy, rel2abs, xy2coord
|
|
33
|
+
from plotastrodata.fits_utils import FitsData, Jy2K, data2fits
|
|
34
|
+
from plotastrodata.fitting_utils import (
|
|
35
|
+
EmceeCorner, gaussfit1d, gaussfit2d, gaussian2d
|
|
36
|
+
)
|
|
37
|
+
from plotastrodata.matrix_utils import Mfac, Mrot, dot2d
|
|
30
38
|
from plotastrodata.noise_utils import estimate_rms
|
|
31
|
-
from plotastrodata.other_utils import (
|
|
32
|
-
|
|
39
|
+
from plotastrodata.other_utils import (
|
|
40
|
+
RGIxy, RGIxyv, nearest_index, to4dim, trim
|
|
41
|
+
)
|
|
33
42
|
|
|
34
43
|
|
|
35
44
|
def _profile_ellipses(ellipse: Any, nprof: int) -> np.ndarray:
|
|
@@ -497,10 +506,8 @@ class AstroData():
|
|
|
497
506
|
if not np.isfinite(area) or area <= 0:
|
|
498
507
|
raise ValueError('Fitting requires finite, nonzero pixel sizes.')
|
|
499
508
|
factor = np.pi * sizes[0] * sizes[1] / (4 * np.log(2) * area)
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
+ ' beam noise correlation.',
|
|
503
|
-
UserWarning)
|
|
509
|
+
print('In the fitting, sigma is multiplied by sqrt(pixel-per-beam)'
|
|
510
|
+
+ ' to account for beam noise correlation.')
|
|
504
511
|
return factor
|
|
505
512
|
|
|
506
513
|
@_need_multipixels
|
|
@@ -580,8 +587,8 @@ class AstroData():
|
|
|
580
587
|
'model': modelopt, 'residual': residual}
|
|
581
588
|
|
|
582
589
|
@_need_multipixels
|
|
583
|
-
def gaussfit2d(self, chan: int | np.integer | None = None
|
|
584
|
-
) -> _GaussFit2DResult:
|
|
590
|
+
def gaussfit2d(self, chan: int | np.integer | None = None,
|
|
591
|
+
*, progressbar: bool = False) -> _GaussFit2DResult:
|
|
585
592
|
"""Fit a 2D Gaussian function to self.data using
|
|
586
593
|
fitting_utils.gaussfit2d(). With sigma=None, noise is estimated
|
|
587
594
|
from an initial fit. Supplied sigma must be a finite positive real
|
|
@@ -592,6 +599,7 @@ class AstroData():
|
|
|
592
599
|
chan (int): The channel number where the 2D Gaussian is
|
|
593
600
|
fitted. Required for cubes; must be None for images.
|
|
594
601
|
NumPy integer indices are also accepted.
|
|
602
|
+
progressbar (bool): Display the MCMC progress bar. Defaults to False.
|
|
595
603
|
|
|
596
604
|
Returns:
|
|
597
605
|
dict: The best parameter set (popt), the error set (perr),
|
|
@@ -613,7 +621,8 @@ class AstroData():
|
|
|
613
621
|
sigma = self.sigma * np.sqrt(self._fit_pixelperbeam())
|
|
614
622
|
sigma = _normalize_float(sigma)
|
|
615
623
|
res = gaussfit2d(xdata=self.x, ydata=self.y, zdata=z,
|
|
616
|
-
sigma=sigma, show=False,
|
|
624
|
+
sigma=sigma, show=False, progressbar=progressbar,
|
|
625
|
+
nwalkersperdim=4)
|
|
617
626
|
popt, perr = res['popt'], res['perr']
|
|
618
627
|
model = gaussian2d(np.meshgrid(self.x, self.y), *popt)
|
|
619
628
|
residual = z - model
|
|
@@ -868,7 +877,8 @@ class AstroData():
|
|
|
868
877
|
raise ValueError('restfreq must be finite and positive,'
|
|
869
878
|
+ ' or None/0.')
|
|
870
879
|
if self.restfreq is None or self.restfreq == 0:
|
|
871
|
-
warnings.warn('No valid restfreq.
|
|
880
|
+
warnings.warn('No valid restfreq.'
|
|
881
|
+
+ ' The velocity axis is saved as is.',
|
|
872
882
|
UserWarning)
|
|
873
883
|
else:
|
|
874
884
|
cv = (1 - cv / cu.c_kms) * self.restfreq
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
+
from astropy import constants, units
|
|
2
3
|
|
|
3
4
|
from plotastrodata._type_utils import _normalize_float
|
|
4
5
|
|
|
5
|
-
from astropy import constants
|
|
6
|
-
from astropy import units
|
|
7
|
-
|
|
8
6
|
# astropy.units in the SI unit system
|
|
9
7
|
Angstrom = units.Angstrom.to('m')
|
|
10
8
|
angstrom = units.angstrom.to('m')
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import numpy as np
|
|
2
1
|
import shlex
|
|
3
2
|
import subprocess
|
|
4
3
|
from typing import Any
|
|
5
4
|
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
6
7
|
from plotastrodata import const_utils as cu
|
|
7
8
|
from plotastrodata._type_utils import _normalize_float
|
|
8
9
|
from plotastrodata._validation_utils import _require_integer
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import numpy as np
|
|
2
1
|
import numbers
|
|
3
2
|
from os import PathLike
|
|
3
|
+
from typing import Any, Callable
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
4
6
|
from astropy import units, wcs
|
|
5
7
|
from astropy.io import fits
|
|
6
|
-
from typing import Any, Callable
|
|
7
8
|
|
|
8
9
|
from plotastrodata import const_utils as cu
|
|
9
|
-
from plotastrodata._validation_utils import (_is_positive_real_scalar,
|
|
10
|
-
_require_positive_real_scalar)
|
|
11
10
|
from plotastrodata._type_utils import _normalize_float
|
|
11
|
+
from plotastrodata._validation_utils import (
|
|
12
|
+
_is_positive_real_scalar,
|
|
13
|
+
_require_positive_real_scalar,
|
|
14
|
+
)
|
|
12
15
|
from plotastrodata.coord_utils import coord2xy, xy2coord
|
|
13
16
|
from plotastrodata.matrix_utils import dot2d
|
|
14
17
|
from plotastrodata.noise_utils import estimate_rms
|
|
15
|
-
from plotastrodata.other_utils import
|
|
18
|
+
from plotastrodata.other_utils import RGIxy, isdeg, trim
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
def _jy2k_metadata(header: fits.Header | dict[str, Any] | None,
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
import warnings
|
|
3
|
+
from functools import partial
|
|
4
|
+
from multiprocessing import Pool
|
|
5
|
+
from typing import Any, Callable
|
|
6
|
+
|
|
1
7
|
import corner
|
|
2
8
|
import emcee
|
|
3
9
|
import matplotlib.pyplot as plt
|
|
4
10
|
import numpy as np
|
|
5
|
-
import pickle
|
|
6
11
|
import ptemcee
|
|
7
|
-
import warnings
|
|
8
12
|
from dynesty import DynamicNestedSampler as DNS
|
|
9
|
-
from functools import partial
|
|
10
|
-
from multiprocessing import Pool
|
|
11
|
-
from tqdm import tqdm
|
|
12
|
-
from typing import Any, Callable
|
|
13
13
|
from matplotlib.figure import Figure
|
|
14
|
+
from tqdm import tqdm
|
|
14
15
|
|
|
15
|
-
from plotastrodata._validation_utils import _require_integer
|
|
16
16
|
from plotastrodata._type_utils import _normalize_float
|
|
17
|
+
from plotastrodata._validation_utils import _require_integer
|
|
17
18
|
from plotastrodata.matrix_utils import Mrot, dot2d
|
|
18
19
|
from plotastrodata.other_utils import close_figure
|
|
19
20
|
|
|
20
|
-
|
|
21
21
|
global_bounds = None
|
|
22
22
|
bar = None
|
|
23
23
|
global_progressbar = True
|
|
@@ -342,31 +342,35 @@ class EmceeCorner():
|
|
|
342
342
|
nwalkers = nwalkersperdim * self.dim # must be even and >= 2 * dim
|
|
343
343
|
if ntemps > 1:
|
|
344
344
|
pt = True
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
345
|
+
active_bar = None
|
|
346
|
+
try:
|
|
347
|
+
if global_progressbar:
|
|
348
|
+
total = ntry * ntemps * nwalkers * (nsteps + 1) // ncores
|
|
349
|
+
active_bar = bar = tqdm(total=total)
|
|
350
|
+
active_bar.set_description('Within the ranges')
|
|
351
|
+
samples = None
|
|
352
|
+
sampler = None
|
|
353
|
+
for i in range(1, ntry + 1):
|
|
354
|
+
if pos0 is None:
|
|
355
|
+
pos0 = self._get_pos0(ntemps=ntemps, nwalkers=nwalkers, pt=pt)
|
|
356
|
+
sampler = self._run_sampler(pos0=pos0, pt=pt, ncores=ncores,
|
|
357
|
+
ntemps=ntemps, nsteps=nsteps,
|
|
358
|
+
nwalkers=nwalkers)
|
|
359
|
+
samples = self._get_samples(sampler=sampler,
|
|
360
|
+
nburnin=nburnin, pt=pt)
|
|
361
|
+
i = _check_GR(samples=samples, nwalkers=nwalkers,
|
|
362
|
+
ndata=self.ndata, dim=self.dim,
|
|
363
|
+
i=i, ntry=ntry, grcheck=grcheck)
|
|
364
|
+
if savechain is not None:
|
|
365
|
+
np.save(savechain.removesuffix('.npy') + '.npy', samples)
|
|
366
|
+
self.lnp, self.popt = self._get_lnp_popt(sampler=sampler, pt=pt,
|
|
367
|
+
nburnin=nburnin)
|
|
368
|
+
self.plow, self.pmid, self.phigh = self._get_percentiles(samples)
|
|
369
|
+
self.samples = samples
|
|
370
|
+
finally:
|
|
371
|
+
if active_bar is not None:
|
|
372
|
+
active_bar.close()
|
|
373
|
+
bar = None
|
|
370
374
|
|
|
371
375
|
def plotcorner(self, labels: list[str] | None = None,
|
|
372
376
|
cornerrange: list[float | tuple[float, float] | list[float]]
|
|
@@ -707,9 +711,15 @@ def gaussian2d(xy: np.ndarray | list[float | np.ndarray]
|
|
|
707
711
|
|
|
708
712
|
def gaussfit1d(xdata: np.ndarray, ydata: np.ndarray,
|
|
709
713
|
sigma: float | np.floating | np.ndarray | None = None,
|
|
710
|
-
show: bool = False,
|
|
714
|
+
show: bool = False, progressbar: bool = False,
|
|
715
|
+
**kwargs: Any) -> dict:
|
|
711
716
|
"""Gaussian fitting to a pair of 1D arrays.
|
|
712
717
|
|
|
718
|
+
NaN and infinite values in xdata or ydata are rejected. Both arrays
|
|
719
|
+
must contain at least two values and have nonzero ranges. Two fitting
|
|
720
|
+
passes are always performed: broad initial bounds, then bounds refined
|
|
721
|
+
around the first result. Noise is estimated only when sigma is None.
|
|
722
|
+
|
|
713
723
|
Args:
|
|
714
724
|
xdata (np.ndarray): ydata is compared with Gauss(xdata).
|
|
715
725
|
ydata (np.ndarray): ydata is compared with Gauss(xdata).
|
|
@@ -718,12 +728,23 @@ def gaussfit1d(xdata: np.ndarray, ydata: np.ndarray,
|
|
|
718
728
|
residuals of an initial fit.
|
|
719
729
|
show (bool, optional): True means to show the best-fit
|
|
720
730
|
parameters and uncertainties. Defaults to False.
|
|
731
|
+
progressbar (bool): Display the MCMC progress bar. Defaults to False.
|
|
721
732
|
|
|
722
733
|
Returns:
|
|
723
734
|
dict: popt and perr are arrays. Scalar sigma, including a supplied
|
|
724
735
|
integer, is a Python float, except that extended precision is preserved.
|
|
725
736
|
Array-valued sigma retains its dtype.
|
|
726
737
|
"""
|
|
738
|
+
if not np.all(np.isfinite(xdata)) or not np.all(np.isfinite(ydata)):
|
|
739
|
+
raise ValueError('gaussfit1d requires finite samples; crop or remove'
|
|
740
|
+
+ ' NaN and infinite values before fitting.')
|
|
741
|
+
if np.size(xdata) < 2 or np.size(ydata) < 2:
|
|
742
|
+
raise ValueError('gaussfit1d requires at least two samples.')
|
|
743
|
+
if np.min(ydata) == np.max(ydata):
|
|
744
|
+
raise ValueError('gaussfit1d requires at least two samples'
|
|
745
|
+
+ ' with different values.')
|
|
746
|
+
if np.min(xdata) == np.max(xdata):
|
|
747
|
+
raise ValueError('gaussfit1d requires at least two different coordinates.')
|
|
727
748
|
if sigma is None:
|
|
728
749
|
print('gaussfit1d: sigma is None;'
|
|
729
750
|
+ ' estimating noise from an initial fit.')
|
|
@@ -735,10 +756,15 @@ def gaussfit1d(xdata: np.ndarray, ydata: np.ndarray,
|
|
|
735
756
|
bounds = [[ymin - yw * 10, ymax + yw * 10], [xmin, xmax], [dx, xw]]
|
|
736
757
|
sigtmp = (max(np.abs(ymin), np.abs(ymax)) * 0.01
|
|
737
758
|
if sigma is None else sigma)
|
|
738
|
-
for i in range(2
|
|
759
|
+
for i in range(2):
|
|
739
760
|
fitter = EmceeCorner(bounds=bounds, model=gaussian1d,
|
|
740
|
-
sigma=sigtmp, xdata=xdata, ydata=ydata
|
|
761
|
+
sigma=sigtmp, xdata=xdata, ydata=ydata,
|
|
762
|
+
progressbar=progressbar)
|
|
741
763
|
fitter.fit(**kwargs)
|
|
764
|
+
a, center, width = fitter.popt
|
|
765
|
+
bounds = [sorted([a / 2, a * 2]),
|
|
766
|
+
[center - width, center + width],
|
|
767
|
+
[width / 2, width * 2]]
|
|
742
768
|
if i == 0 and sigma is None:
|
|
743
769
|
sigtmp = np.std(ydata - gaussian1d(xdata, *fitter.popt))
|
|
744
770
|
popt = fitter.popt
|
|
@@ -756,9 +782,13 @@ def gaussfit1d(xdata: np.ndarray, ydata: np.ndarray,
|
|
|
756
782
|
|
|
757
783
|
def gaussfit2d(xdata: np.ndarray, ydata: np.ndarray, zdata: np.ndarray,
|
|
758
784
|
sigma: float | np.floating | np.ndarray | None = None,
|
|
759
|
-
show: bool = False,
|
|
785
|
+
show: bool = False, progressbar: bool = False,
|
|
786
|
+
**kwargs: Any) -> dict:
|
|
760
787
|
"""Fit a two-dimensional Gaussian to zdata on the xdata/ydata grid.
|
|
761
788
|
|
|
789
|
+
Nonfinite image pixels are rejected. At least two pixels with
|
|
790
|
+
different values are required.
|
|
791
|
+
|
|
762
792
|
Args:
|
|
763
793
|
xdata (np.ndarray): zdata is compared with Gauss(xdata, ydata).
|
|
764
794
|
ydata (np.ndarray): zdata is compared with Gauss(xdata, ydata).
|
|
@@ -768,6 +798,7 @@ def gaussfit2d(xdata: np.ndarray, ydata: np.ndarray, zdata: np.ndarray,
|
|
|
768
798
|
residuals of an initial fit.
|
|
769
799
|
show (bool, optional): True means to show the best-fit
|
|
770
800
|
parameters and uncertainties. Defaults to False.
|
|
801
|
+
progressbar (bool): Display the MCMC progress bar. Defaults to False.
|
|
771
802
|
|
|
772
803
|
Returns:
|
|
773
804
|
dict: popt and perr are arrays. Scalar sigma, including a supplied
|
|
@@ -779,6 +810,12 @@ def gaussfit2d(xdata: np.ndarray, ydata: np.ndarray, zdata: np.ndarray,
|
|
|
779
810
|
+ ' estimating noise from an initial fit.')
|
|
780
811
|
xmin, xmax = np.min(xdata), np.max(xdata)
|
|
781
812
|
ymin, ymax = np.min(ydata), np.max(ydata)
|
|
813
|
+
if not np.all(np.isfinite(zdata)):
|
|
814
|
+
raise ValueError('gaussfit2d requires finite pixels; crop or remove'
|
|
815
|
+
+ ' NaN and infinite values before fitting.')
|
|
816
|
+
if np.size(zdata) < 2 or np.min(zdata) == np.max(zdata):
|
|
817
|
+
raise ValueError('gaussfit2d requires at least two pixels'
|
|
818
|
+
+ ' with different values.')
|
|
782
819
|
zmin, zmax = np.min(zdata), np.max(zdata)
|
|
783
820
|
xw = xmax - xmin
|
|
784
821
|
yw = ymax - ymin
|
|
@@ -803,7 +840,8 @@ def gaussfit2d(xdata: np.ndarray, ydata: np.ndarray, zdata: np.ndarray,
|
|
|
803
840
|
[dx, xw], [dx, xw], [-90, 90]]
|
|
804
841
|
for i in range(2):
|
|
805
842
|
fitter = EmceeCorner(bounds=bounds, model=model,
|
|
806
|
-
sigma=sigtmp, xdata=xy, ydata=zdata
|
|
843
|
+
sigma=sigtmp, xdata=xy, ydata=zdata,
|
|
844
|
+
progressbar=progressbar)
|
|
807
845
|
fitter.fit(**kwargs)
|
|
808
846
|
a, cx, cy, wmaj, wmin, pa = fitter.popt
|
|
809
847
|
wmax = max(wmaj, wmin)
|
|
@@ -41,8 +41,8 @@ def dot2d(M: np.ndarray | list[list[float]] = [[1, 0], [0, 1]],
|
|
|
41
41
|
Returns:
|
|
42
42
|
np.ndarray: The 2D vector after the matrix multiplied.
|
|
43
43
|
"""
|
|
44
|
-
x = M[0][0] * np.
|
|
45
|
-
y = M[1][0] * np.
|
|
44
|
+
x = M[0][0] * np.asarray(a[0]) + M[0][1] * np.asarray(a[1])
|
|
45
|
+
y = M[1][0] * np.asarray(a[0]) + M[1][1] * np.asarray(a[1])
|
|
46
46
|
return np.array([x, y])
|
|
47
47
|
|
|
48
48
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import matplotlib.pyplot as plt
|
|
2
1
|
import numbers
|
|
3
|
-
import numpy as np
|
|
4
2
|
import warnings
|
|
5
|
-
from scipy.special import erf
|
|
6
3
|
from typing import Any, Callable
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
from scipy.special import erf
|
|
8
|
+
|
|
10
9
|
from plotastrodata._type_utils import _normalize_float
|
|
10
|
+
from plotastrodata._validation_utils import (
|
|
11
|
+
_is_uniform_spacing,
|
|
12
|
+
_require_integer
|
|
13
|
+
)
|
|
11
14
|
from plotastrodata.fitting_utils import EmceeCorner
|
|
12
15
|
from plotastrodata.other_utils import close_figure
|
|
13
16
|
|
|
@@ -123,7 +126,9 @@ def gauss_pbcor(x: float | np.floating | np.ndarray,
|
|
|
123
126
|
The variable of the probability density.
|
|
124
127
|
s (float): Standard deviation of the Gaussian noise.
|
|
125
128
|
m (float): Mean of the Gaussian noise.
|
|
126
|
-
R (float):
|
|
129
|
+
R (float): Dimensionless outer radius r_out / r_p, where r_p is
|
|
130
|
+
the primary-beam half-width at half maximum (HWHM). The
|
|
131
|
+
primary-beam response at radius r is 2**(-(r / r_p)**2).
|
|
127
132
|
|
|
128
133
|
Returns:
|
|
129
134
|
float or np.longdouble or np.ndarray: Probability density.
|
|
@@ -159,7 +164,7 @@ def select_noise(data: np.ndarray, sigma: str) -> np.ndarray:
|
|
|
159
164
|
Returns:
|
|
160
165
|
np.ndarray: 1D array that includes only the selected pixels.
|
|
161
166
|
"""
|
|
162
|
-
n = np.array(data
|
|
167
|
+
n = np.array(data, copy=True)
|
|
163
168
|
if 'edge' in sigma:
|
|
164
169
|
if np.ndim(n) <= 2:
|
|
165
170
|
print('\'edge\' is ignored because ndim <= 2.')
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from os import PathLike
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
2
5
|
import matplotlib.pyplot as plt
|
|
3
6
|
import numpy as np
|
|
4
|
-
import warnings
|
|
5
|
-
from scipy.interpolate import RegularGridInterpolator as RGI
|
|
6
7
|
from matplotlib.figure import Figure
|
|
7
|
-
from
|
|
8
|
+
from scipy.interpolate import RegularGridInterpolator as RGI
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def isdeg(s: Any) -> bool:
|