plotastrodata 1.9.0__tar.gz → 1.9.2__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 (25) hide show
  1. {plotastrodata-1.9.0/plotastrodata.egg-info → plotastrodata-1.9.2}/PKG-INFO +1 -1
  2. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/fitting_utils.py +17 -10
  4. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/other_utils.py +4 -5
  5. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/plot_utils.py +20 -18
  6. {plotastrodata-1.9.0 → plotastrodata-1.9.2/plotastrodata.egg-info}/PKG-INFO +1 -1
  7. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/LICENSE +0 -0
  8. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/MANIFEST.in +0 -0
  9. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/README.md +0 -0
  10. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/analysis_utils.py +0 -0
  11. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/const_utils.py +0 -0
  12. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/coord_utils.py +0 -0
  13. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/ext_utils.py +0 -0
  14. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/fft_utils.py +0 -0
  15. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/fits_utils.py +0 -0
  16. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/los_utils.py +0 -0
  17. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/matrix_utils.py +0 -0
  18. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata/noise_utils.py +0 -0
  19. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/setup.cfg +0 -0
  25. {plotastrodata-1.9.0 → plotastrodata-1.9.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.9.0
3
+ Version: 1.9.2
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
@@ -1,4 +1,4 @@
1
1
  import warnings
2
2
 
3
3
  warnings.simplefilter('ignore', FutureWarning)
4
- __version__ = '1.9.0'
4
+ __version__ = '1.9.2'
@@ -34,6 +34,18 @@ def logp(x: np.ndarray) -> float:
34
34
  return -np.inf
35
35
 
36
36
 
37
+ def _get_GR(samples: np.ndarray, nwalkers: int, ndata: int, dim: int
38
+ ) -> np.ndarray:
39
+ # Gelman-Rubin statistics #
40
+ B = np.std(np.mean(samples, axis=1), axis=0)
41
+ W = np.mean(np.std(samples, axis=1), axis=0)
42
+ V = (len(samples[0]) - 1) / len(samples[0]) * W \
43
+ + (nwalkers + 1) / (nwalkers - 1) * B
44
+ d = ndata - dim - 1
45
+ GR = np.sqrt((d + 3) / (d + 1) * V / W)
46
+ return GR
47
+
48
+
37
49
  class EmceeCorner():
38
50
  warnings.simplefilter('ignore', RuntimeWarning)
39
51
 
@@ -130,7 +142,8 @@ class EmceeCorner():
130
142
  samples = sampler.chain[0, :, nburnin:, :] # temperatures, walkers, steps, dim
131
143
  else:
132
144
  if ncores > 1:
133
- print('Use logl as log_prob_fn to avoid function-in-function.')
145
+ print('Use logl as log_prob_fn to avoid'
146
+ + ' function-in-function.')
134
147
  log_prob_fn = self.logl
135
148
  else:
136
149
  def log_prob_fn(x):
@@ -147,14 +160,8 @@ class EmceeCorner():
147
160
  sampler.run_mcmc(pos0, nsteps)
148
161
  samples = sampler.chain[:, nburnin:, :] # walkers, steps, dim
149
162
  if grcheck:
150
- # Gelman-Rubin statistics #
151
- B = np.std(np.mean(samples, axis=1), axis=0)
152
- W = np.mean(np.std(samples, axis=1), axis=0)
153
- V = (len(samples[0]) - 1) / len(samples[0]) * W \
154
- + (nwalkers + 1) / (nwalkers - 1) * B
155
- d = self.ndata - self.dim - 1
156
- GR = np.sqrt((d + 3) / (d + 1) * V / W)
157
- ###########################
163
+ GR = _get_GR(samples=samples, nwalkers=nwalkers,
164
+ ndata=self.ndata, dim=self.dim)
158
165
  else:
159
166
  GR = np.zeros(self.dim)
160
167
  if i == ntry - 1 and np.max(GR) > 1.25:
@@ -162,7 +169,7 @@ class EmceeCorner():
162
169
 
163
170
  self.samples = samples
164
171
  if savechain is not None:
165
- np.save(savechain.replace('.npy', '') + '.npy', samples)
172
+ np.save(savechain.removesuffix('.npy') + '.npy', samples)
166
173
  if pt:
167
174
  lnps = sampler.logprobability[0] # [0] is in the temperature axis.
168
175
  idx_best = np.unravel_index(np.argmax(lnps), lnps.shape)
@@ -35,7 +35,7 @@ def isdeg(s: str) -> bool:
35
35
 
36
36
 
37
37
  def nearest_index(arr: np.ndarray, x: float = 0) -> int:
38
- """Get the index of the (sorted) arrary that gives a value nearest to x. This is equivalent to np.argmin(np.abs(arr - x)) but optimized for the sorted array.
38
+ """Get the index of the input arrary that gives a value nearest to the given value x. np.searchsorted() does not work with a descending array.
39
39
 
40
40
  Args:
41
41
  arr (np.ndarray): Sorted array.
@@ -44,8 +44,7 @@ def nearest_index(arr: np.ndarray, x: float = 0) -> int:
44
44
  Returns:
45
45
  int: The index that gives a value nearest to x.
46
46
  """
47
- idx = np.searchsorted(arr, x).clip(1, len(arr) - 1)
48
- return idx - 1 if x - arr[idx - 1] <= arr[idx] - x else idx
47
+ return np.argmin(np.abs(arr - x))
49
48
 
50
49
 
51
50
  def trim(data: np.ndarray | None = None, x: np.ndarray | None = None,
@@ -72,8 +71,8 @@ def trim(data: np.ndarray | None = None, x: np.ndarray | None = None,
72
71
  def get_bounds(arr, lim):
73
72
  if arr is None or lim is None or None in lim:
74
73
  return arr, 0, None
75
- lo = nearest_index(arr, max(np.min(arr), lim[0]))
76
- hi = nearest_index(arr, min(np.max(arr), lim[1]))
74
+ lo = nearest_index(arr, max(np.min(arr), np.min(lim)))
75
+ hi = nearest_index(arr, min(np.max(arr), np.max(lim)))
77
76
  lo, hi = sorted((lo, hi))
78
77
  return arr[lo:hi + 1], lo, hi + 1
79
78
 
@@ -131,19 +131,18 @@ def get_figsize(xmin: float, xmax: float, ymin: float, ymax: float,
131
131
  return figsize
132
132
 
133
133
 
134
- def _get_gridwidth(mode: str, rmax: float) -> tuple[float, int]:
135
- # 10^1.45 / 15 ~ 2 grids for R.A.
136
- # 10^0.45 ~ 3 grids for Dec.
137
- scale = 1.45 if mode == 'ra' else 0.45
138
- x = np.log10(2. * rmax) - scale
139
- order = np.floor(x)
140
- frac = x - order
141
- if frac <= 0.33:
142
- base = 1
143
- elif frac <= 0.68:
144
- base = 2
134
+ def _get_gridwidth(mode: str, rmax: float, cos_dec: float
135
+ ) -> tuple[float, int]:
136
+ # Length in the units of s for R.A. and " for Dec., respectively.
137
+ length = 2 * rmax / (15 * cos_dec if mode == 'ra' else 1)
138
+ p = np.floor(np.log10(length))
139
+ b = length / 10**p
140
+ if b <= 2:
141
+ base, order = 5, p - 1
142
+ elif b <= 4:
143
+ base, order = 1, p
145
144
  else:
146
- base = 5
145
+ base, order = 2, p
147
146
  return base * 10**order, int(order)
148
147
 
149
148
 
@@ -1107,13 +1106,12 @@ class PlotAstroData(AstroFrame):
1107
1106
  sign_dec = np.sign(dec_center)
1108
1107
  cos_dec = np.cos(np.radians(dec_center))
1109
1108
  intgrid = np.array([-3, -2, -1, 0, 1, 2, 3])
1110
- i_mid = (len(intgrid) - 1) // 2
1111
1109
 
1112
1110
  def makegrid(mode: str):
1113
1111
  second = float(get_sec(center, mode))
1114
1112
  no_sec = on_min_scale and (mode == 'dec')
1115
1113
  # gridwidth is a float like 2 x 10^order (arcsec).
1116
- gridwidth, order = _get_gridwidth(mode, self.rmax)
1114
+ gridwidth, order = _get_gridwidth(mode, self.rmax, cos_dec)
1117
1115
  # ndigits = -1 is the largest case for 10", 20", ...
1118
1116
  decimals = str(max(-order, 0))
1119
1117
  rounded = round(second, ndigits=max(-order, -1))
@@ -1131,14 +1129,18 @@ class PlotAstroData(AstroFrame):
1131
1129
 
1132
1130
  xticks, xticksminor, xticklabels = makegrid('ra')
1133
1131
  yticks, yticksminor, yticklabels = makegrid('dec')
1134
- ra_hm = get_hmdm(xy2coord([xticks[i_mid] / 3600., 0], center), 'ra')
1135
- dec_dm = get_hmdm(xy2coord([0, yticks[i_mid] / 3600.], center), 'dec')
1132
+ i_ref = np.where(np.abs(xticks) < self.rmax)[0][-1]
1133
+ idx_top = -1 if sign_dec > 0 else 0
1134
+ j_ref = np.where(np.abs(yticks) < self.rmax)[0][idx_top]
1135
+ ra_hm = get_hmdm(xy2coord([xticks[i_ref] / 3600., 0], center), 'ra')
1136
+ dec_dm = get_hmdm(xy2coord([0, yticks[j_ref] / 3600.], center), 'dec')
1136
1137
  if on_min_scale:
1137
1138
  dec_dm = dec_dm.split('d')[0] + 'd'
1138
1139
  ra_hm = ra_hm.translate(str.maketrans(units['ra']))
1139
1140
  dec_dm = dec_dm.translate(str.maketrans(units['dec']))
1140
- xticklabels[i_mid] = ra_hm + xticklabels[i_mid]
1141
- yticklabels[i_mid] = dec_dm + '\n' + yticklabels[i_mid]
1141
+ textpad = ' ' * 12 # To shift the tick label to left.
1142
+ xticklabels[i_ref] = ra_hm + xticklabels[i_ref] + textpad
1143
+ yticklabels[j_ref] = dec_dm + '\n' + yticklabels[j_ref]
1142
1144
  pa2 = PlotAxes2D(True, None, 'linear', 'linear',
1143
1145
  self.Xlim, self.Ylim, xlabel, ylabel,
1144
1146
  xticks, yticks, xticklabels, yticklabels,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.9.0
3
+ Version: 1.9.2
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