plotastrodata 1.1.2.post1__tar.gz → 1.1.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.
Files changed (20) hide show
  1. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/PKG-INFO +3 -1
  2. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/README.md +1 -0
  3. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/__init__.py +1 -1
  4. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/analysis_utils.py +7 -7
  5. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/fitting_utils.py +47 -15
  6. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/PKG-INFO +3 -1
  7. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/requires.txt +1 -0
  8. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/setup.cfg +1 -0
  9. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/LICENSE +0 -0
  10. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/const_utils.py +0 -0
  11. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/fft_utils.py +0 -0
  12. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/fits_utils.py +0 -0
  13. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/los_utils.py +0 -0
  14. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/other_utils.py +0 -0
  15. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata/plot_utils.py +0 -0
  16. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/SOURCES.txt +0 -0
  17. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/dependency_links.txt +0 -0
  18. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/not-zip-safe +0 -0
  19. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/plotastrodata.egg-info/top_level.txt +0 -0
  20. {plotastrodata-1.1.2.post1 → plotastrodata-1.1.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: plotastrodata
3
- Version: 1.1.2.post1
3
+ Version: 1.1.3
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
@@ -13,6 +13,7 @@ License-File: LICENSE
13
13
  Requires-Dist: astropy
14
14
  Requires-Dist: corner
15
15
  Requires-Dist: dynesty
16
+ Requires-Dist: emcee
16
17
  Requires-Dist: matplotlib
17
18
  Requires-Dist: multiprocess
18
19
  Requires-Dist: numpy
@@ -79,6 +80,7 @@ plotastrodata can do the following things.
79
80
  * astropy
80
81
  * corner (only for fitting)
81
82
  * dynesty (only for fitting)
83
+ * emcee (only for fitting)
82
84
  * ffmpeg (only for movie)
83
85
  * matplotlib
84
86
  * multiprocess (only for fitting)
@@ -54,6 +54,7 @@ plotastrodata can do the following things.
54
54
  * astropy
55
55
  * corner (only for fitting)
56
56
  * dynesty (only for fitting)
57
+ * emcee (only for fitting)
57
58
  * ffmpeg (only for movie)
58
59
  * matplotlib
59
60
  * multiprocess (only for fitting)
@@ -1,4 +1,4 @@
1
1
  import warnings
2
2
 
3
3
  warnings.simplefilter('ignore', UserWarning)
4
- __version__ = '1.1.2-1'
4
+ __version__ = '1.1.3'
@@ -8,7 +8,7 @@ from plotastrodata.other_utils import (coord2xy, rel2abs, estimate_rms, trim,
8
8
  Mfac, Mrot, dot2d, gaussian2d)
9
9
  from plotastrodata.fits_utils import FitsData, data2fits, Jy2K
10
10
  from plotastrodata import const_utils as cu
11
- from plotastrodata.fitting_utils import PTEmceeCorner
11
+ from plotastrodata.fitting_utils import EmceeCorner
12
12
 
13
13
 
14
14
  def to4dim(data: np.ndarray) -> np.ndarray:
@@ -316,10 +316,10 @@ class AstroData():
316
316
 
317
317
  Args:
318
318
  model (function): The model function in the form of f(par, x, y).
319
- bounds (np.ndarray): bounds for fitting_utils.PTEmceeCorner.
320
- progressbar (bool, optional): progressbar for fitting_utils.PTEmceeCorner. Defaults to False.
321
- kwargs_fit (dict, optional): Arguments for fitting_utils.PTEmceeCorner.fit.
322
- kwargs_plotcorner (dict, optional): Arguments for fitting_utils.PTEmceeCorner.plotcorner.
319
+ bounds (np.ndarray): bounds for fitting_utils.EmceeCorner.
320
+ progressbar (bool, optional): progressbar for fitting_utils.EmceeCorner. Defaults to False.
321
+ kwargs_fit (dict, optional): Arguments for fitting_utils.EmceeCorner.fit.
322
+ kwargs_plotcorner (dict, optional): Arguments for fitting_utils.EmceeCorner.plotcorner.
323
323
  chan (int, optional): The channel number where the 2D model is fitted. Defaults to None.
324
324
 
325
325
  Returns:
@@ -338,8 +338,8 @@ class AstroData():
338
338
  def logl(p):
339
339
  rss = np.nansum((model(p, x, y) - d)**2)
340
340
  return -0.5 * rss / self.sigma**2 / pixelperbeam
341
-
342
- mcmc = PTEmceeCorner(bounds=bounds, logl=logl, progressbar=progressbar)
341
+
342
+ mcmc = EmceeCorner(bounds=bounds, logl=logl, progressbar=progressbar)
343
343
  kwargs_fit0 = {}
344
344
  kwargs_fit0.update(kwargs_fit)
345
345
  mcmc.fit(**kwargs_fit0)
@@ -1,5 +1,6 @@
1
1
  import numpy as np
2
2
  import matplotlib.pyplot as plt
3
+ import emcee
3
4
  import ptemcee
4
5
  import corner
5
6
  from dynesty import DynamicNestedSampler as DNS
@@ -30,7 +31,7 @@ def logp(x: np.ndarray) -> float:
30
31
  return -np.inf
31
32
 
32
33
 
33
- class PTEmceeCorner():
34
+ class EmceeCorner():
34
35
  warnings.simplefilter('ignore', RuntimeWarning)
35
36
 
36
37
  def __init__(self, bounds: np.ndarray, logl: object | None = None,
@@ -65,8 +66,8 @@ class PTEmceeCorner():
65
66
 
66
67
  def fit(self, nwalkersperdim: int = 2, ntemps: int = 1, nsteps: int = 1000,
67
68
  nburnin: int = 500, ntry: int = 1, pos0: np.ndarray | None = None,
68
- savechain: str | None = None, ncores: int = 1, grcheck: bool = False
69
- ) -> None:
69
+ savechain: str | None = None, ncores: int = 1, grcheck: bool = False,
70
+ pt: bool = False) -> None:
70
71
  """Perform a Markov Chain Monte Carlo (MCMC) fitting process using the ptemcee library, which is a parallel tempering version of the emcee package, and make a corner plot of the samples using the corner package.
71
72
 
72
73
  Args:
@@ -79,11 +80,15 @@ class PTEmceeCorner():
79
80
  savechain (str, optional): File name of the chain in format of .npy. Defaults to None.
80
81
  ncores (int, optional): Number of cores for multiprocessing.Pool. ncores=1 does not use multiprocessing. Defaults to 1.
81
82
  grcheck (bool, optional): Whether to check Gelman-Rubin statistics. Defaults to False.
83
+ pt (bool, optional): Whether to use ptemcee; otherwise, emcee is used. Defaults to False.
82
84
  """
83
85
  global bar
84
86
  if nwalkersperdim < 2:
85
87
  print(f'nwalkersperdim < 2 is not allowed. Use 2 instead of {nwalkersperdim:d}.')
86
88
  nwalkers = max(nwalkersperdim, 2) * self.dim # must be even and >= 2 * dim
89
+ if ntemps > 1 and not pt:
90
+ print('ntemps>1 is supported only with pt=True. Set pt=True.')
91
+ pt = True
87
92
  if global_progressbar:
88
93
  bar = tqdm(total=ntry * ntemps * nwalkers * (nsteps + 1) // ncores)
89
94
  bar.set_description('Within the ranges')
@@ -95,16 +100,37 @@ class PTEmceeCorner():
95
100
  if pos0 is None:
96
101
  pos0 = np.random.rand(ntemps, nwalkers, self.dim) \
97
102
  * (self.bounds[1] - self.bounds[0]) + self.bounds[0]
98
- pars = {'ntemps': ntemps, 'nwalkers': nwalkers, 'dim': self.dim,
99
- 'logl': self.logl, 'logp': self.logp}
100
- if ncores > 1:
101
- with Pool(ncores) as pool:
102
- sampler = ptemcee.Sampler(**pars, pool=pool)
103
+ if not pt:
104
+ pos0 = pos0[0]
105
+ if pt:
106
+ pars = {'ntemps': ntemps, 'nwalkers': nwalkers, 'dim': self.dim,
107
+ 'logl': self.logl, 'logp': self.logp}
108
+ if ncores > 1:
109
+ with Pool(ncores) as pool:
110
+ sampler = ptemcee.Sampler(**pars, pool=pool)
111
+ sampler.run_mcmc(pos0, nsteps)
112
+ else:
113
+ sampler = ptemcee.Sampler(**pars)
103
114
  sampler.run_mcmc(pos0, nsteps)
115
+ samples = sampler.chain[0, :, nburnin:, :] # temperature, walker, step, dim
104
116
  else:
105
- sampler = ptemcee.Sampler(**pars)
106
- sampler.run_mcmc(pos0, nsteps)
107
- samples = sampler.chain[0, :, nburnin:, :] # temperature, walker, step, dim
117
+ if ncores > 1:
118
+ print('Use logl as log_prob_fn to avoid function-in-function.')
119
+ log_prob_fn = self.logl
120
+ else:
121
+ def log_prob_fn(x):
122
+ return self.logp(x) + self.logl(x)
123
+
124
+ pars = {'nwalkers': nwalkers, 'ndim': self.dim,
125
+ 'log_prob_fn': log_prob_fn}
126
+ if ncores > 1:
127
+ with Pool(ncores) as pool:
128
+ sampler = emcee.EnsembleSampler(**pars, pool=pool)
129
+ sampler.run_mcmc(pos0, nsteps)
130
+ else:
131
+ sampler = emcee.EnsembleSampler(**pars)
132
+ sampler.run_mcmc(pos0, nsteps)
133
+ samples = sampler.chain[:, nburnin:, :] # walker, step, dim
108
134
  if grcheck:
109
135
  # Gelman-Rubin statistics #
110
136
  B = np.std(np.mean(samples, axis=1), axis=0)
@@ -122,9 +148,14 @@ class PTEmceeCorner():
122
148
  self.samples = samples
123
149
  if savechain is not None:
124
150
  np.save(savechain.replace('.npy', '') + '.npy', samples)
125
- lnps = sampler.logprobability[0] # [0] is in the temperature axis.
126
- idx_best = np.unravel_index(np.argmax(lnps), lnps.shape)
127
- self.popt = sampler.chain[0][idx_best]
151
+ if pt:
152
+ lnps = sampler.logprobability[0] # [0] is in the temperature axis.
153
+ idx_best = np.unravel_index(np.argmax(lnps), lnps.shape)
154
+ self.popt = sampler.chain[0][idx_best] # [0] is in the temperature axis.
155
+ else:
156
+ lnps = sampler.lnprobability
157
+ idx_best = np.unravel_index(np.argmax(lnps), lnps.shape)
158
+ self.popt = sampler.chain[idx_best]
128
159
  self.lnps = lnps[:, nburnin:]
129
160
  s = samples.reshape((-1, self.dim))
130
161
  self.plow = np.percentile(s, self.percent[0], axis=0)
@@ -199,7 +230,8 @@ class PTEmceeCorner():
199
230
  plt.show()
200
231
  plt.close()
201
232
 
202
- def posteriorongrid(self, ngrid: list = 100, log: list[bool] = False, pcut: float = 0):
233
+ def posteriorongrid(self, ngrid: list[int] | int = 100,
234
+ log: list[bool] | bool = False, pcut: float = 0):
203
235
  """Calculate the posterior on a grid of ngrid x ngrid x ... x ngrid.
204
236
 
205
237
  Args:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: plotastrodata
3
- Version: 1.1.2.post1
3
+ Version: 1.1.3
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
@@ -13,6 +13,7 @@ License-File: LICENSE
13
13
  Requires-Dist: astropy
14
14
  Requires-Dist: corner
15
15
  Requires-Dist: dynesty
16
+ Requires-Dist: emcee
16
17
  Requires-Dist: matplotlib
17
18
  Requires-Dist: multiprocess
18
19
  Requires-Dist: numpy
@@ -79,6 +80,7 @@ plotastrodata can do the following things.
79
80
  * astropy
80
81
  * corner (only for fitting)
81
82
  * dynesty (only for fitting)
83
+ * emcee (only for fitting)
82
84
  * ffmpeg (only for movie)
83
85
  * matplotlib
84
86
  * multiprocess (only for fitting)
@@ -1,6 +1,7 @@
1
1
  astropy
2
2
  corner
3
3
  dynesty
4
+ emcee
4
5
  matplotlib
5
6
  multiprocess
6
7
  numpy
@@ -19,6 +19,7 @@ install_requires =
19
19
  astropy
20
20
  corner
21
21
  dynesty
22
+ emcee
22
23
  matplotlib
23
24
  multiprocess
24
25
  numpy