plotastrodata 1.8.18__tar.gz → 1.9.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.
Files changed (25) hide show
  1. {plotastrodata-1.8.18/plotastrodata.egg-info → plotastrodata-1.9.1}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/fitting_utils.py +17 -10
  4. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/plot_utils.py +53 -34
  5. {plotastrodata-1.8.18 → plotastrodata-1.9.1/plotastrodata.egg-info}/PKG-INFO +1 -1
  6. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/LICENSE +0 -0
  7. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/MANIFEST.in +0 -0
  8. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/README.md +0 -0
  9. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/analysis_utils.py +0 -0
  10. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/const_utils.py +0 -0
  11. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/coord_utils.py +0 -0
  12. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/ext_utils.py +0 -0
  13. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/fft_utils.py +0 -0
  14. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/fits_utils.py +0 -0
  15. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/los_utils.py +0 -0
  16. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/matrix_utils.py +0 -0
  17. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/noise_utils.py +0 -0
  18. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/setup.cfg +0 -0
  25. {plotastrodata-1.8.18 → plotastrodata-1.9.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.18
3
+ Version: 1.9.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
@@ -1,4 +1,4 @@
1
1
  import warnings
2
2
 
3
3
  warnings.simplefilter('ignore', FutureWarning)
4
- __version__ = '1.8.18'
4
+ __version__ = '1.9.1'
@@ -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)
@@ -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.5 / 15 ~ 2 grids for R.A.
136
- # 10^0.5 ~ 3 grids for Dec.
137
- scale = 1.5 if mode == 'ra' else 0.5
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
 
@@ -222,43 +221,51 @@ class Stretcher():
222
221
  getsigma = (islog + ispower) * novmin
223
222
  self.vmin = np.where(getsigma, sigma, vmin)
224
223
 
225
- def do(self, x: list | np.ndarray) -> np.ndarray:
224
+ def do(self, x: list | np.ndarray, i: int = 0) -> np.ndarray:
226
225
  """Get the stretched values.
227
226
 
228
227
  Args:
229
228
  x (list | np.ndarray): Input array in the linear scale.
229
+ i (int): Which element is used in the case where the stretch parameters are lists.
230
230
 
231
231
  Returns:
232
232
  np.ndarray: Output stretched array.
233
233
  """
234
+ st = self.stretch[i] if self.n > 1 else self.stretch
235
+ stsc = self.stretchscale[i] if self.n > 1 else self.stretchscale
236
+ stpw = self.stretchpower[i] if self.n > 1 else self.stretchpower
234
237
  t = np.array(x)
235
- match self.stretch:
238
+ match st:
236
239
  case 'log':
237
240
  t = np.log10(t) # To be consistent with logcbticks().
238
241
  case 'asinh':
239
- t = np.arcsinh(t / self.stretchscale)
242
+ t = np.arcsinh(t / stsc)
240
243
  case 'power':
241
- p = 1e-6 if self.stretchpower == 0 else self.stretchpower
244
+ p = 1e-6 if stpw == 0 else stpw
242
245
  t = t**p / p
243
246
  return t
244
247
 
245
- def undo(self, x: list | np.ndarray) -> np.ndarray:
248
+ def undo(self, x: list | np.ndarray, i: int = 0) -> np.ndarray:
246
249
  """Get the linear values from the stretched values.
247
250
 
248
251
  Args:
249
252
  x (list | np.ndarray): Input stretched array.
253
+ i (int): Which element is used in the case where the stretch parameters are lists.
250
254
 
251
255
  Returns:
252
256
  np.ndarray: Output array in the linear scale.
253
257
  """
258
+ st = self.stretch[i] if self.n > 1 else self.stretch
259
+ stsc = self.stretchscale[i] if self.n > 1 else self.stretchscale
260
+ stpw = self.stretchpower[i] if self.n > 1 else self.stretchpower
254
261
  t = np.array(x)
255
- match self.stretch:
262
+ match st:
256
263
  case 'log':
257
264
  t = 10**t # To be consistent with logcbticks().
258
265
  case 'asinh':
259
- t = np.sinh(t) * self.stretchscale
266
+ t = np.sinh(t) * stsc
260
267
  case 'power':
261
- p = 1e-6 if self.stretchpower == 0 else self.stretchpower
268
+ p = 1e-6 if stpw == 0 else stpw
262
269
  t = (t * p)**(1 / p)
263
270
  return t
264
271
 
@@ -277,7 +284,7 @@ class Stretcher():
277
284
  vmaxout = [self.vmax] if single else self.vmax
278
285
  dataout = [data] if single else data
279
286
  for i, (c, v0, v1) in enumerate(zip(dataout, vminout, vmaxout)):
280
- dataout[i] = cout = self.do(c.clip(v0, v1))
287
+ dataout[i] = cout = self.do(c.clip(v0, v1), i)
281
288
  vminout[i] = np.nanmin(cout)
282
289
  vmaxout[i] = np.nanmax(cout)
283
290
  if single:
@@ -428,7 +435,7 @@ def kwargs2instance(cls: type[T], kw: dict) -> T:
428
435
 
429
436
  Args:
430
437
  cls (class): Class to make the instance.
431
- kw (dict): Parameters to make Stretcher.
438
+ kw (dict): Parameters to make the instance.
432
439
 
433
440
  Returns:
434
441
  instance: an instance of cls made from the parameters in kwargs.
@@ -787,7 +794,9 @@ class PlotAstroData(AstroFrame):
787
794
  def _set_colorbar(self, mappable, ch: int, show_cbar: bool,
788
795
  cblabel: str, cbformat: str,
789
796
  cbticks: list | None, cbticklabels: list | None,
790
- cblocation: str, st: Stretcher):
797
+ cblocation: str,
798
+ cblabelfontsize: int, cbtickfontsize: int,
799
+ st: Stretcher):
791
800
  if not show_cbar:
792
801
  return
793
802
 
@@ -803,8 +812,8 @@ class PlotAstroData(AstroFrame):
803
812
  cax = plt.axes([0.88, 0.105, 0.015, 0.77])
804
813
  cb = fig.colorbar(mappable[ch], cax=cax, label=cblabel,
805
814
  format=cbformat)
806
- cb.ax.tick_params(labelsize=14)
807
- font = mpl.font_manager.FontProperties(size=16)
815
+ cb.ax.tick_params(labelsize=cbtickfontsize)
816
+ font = mpl.font_manager.FontProperties(size=cblabelfontsize)
808
817
  cb.ax.yaxis.label.set_font_properties(font)
809
818
  if cbticks is None and st.stretch == 'log':
810
819
  cbticks, cbticklabels = logcbticks(10**st.vmin, 10**st.vmax)
@@ -825,6 +834,8 @@ class PlotAstroData(AstroFrame):
825
834
  cbticks: list[float] | None = None,
826
835
  cbticklabels: list[str] | None = None,
827
836
  cblocation: str = 'right',
837
+ cblabelfontsize: int = 16,
838
+ cbtickfontsize: int = 14,
828
839
  **kwargs) -> None:
829
840
  """Use Axes.pcolormesh of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs may include the arguments for Stretcher (stretch, stretchscale, and stretchpower) to specify the stretch parameters. kwargs may include arguments of Beam; a dict of beam_kwargs specifies the beam patch in more detail. kwargs may include xskiip and yskip.
830
841
 
@@ -835,6 +846,8 @@ class PlotAstroData(AstroFrame):
835
846
  cbticks (list, optional): Ticks of colorbar. Defaults to None.
836
847
  cbticklabels (list, optional): Ticklabels of colorbar. Defaults to None.
837
848
  cblocation (str, optional): 'left', 'top', 'left', 'right'. Only for 2D images. Defaults to 'right'.
849
+ cblabelfontsize (int, optional): Fontsize for the colorbar label. This is independent of set_rcparams().
850
+ cbtickfontsize (int, optional): Fontsize for the colorbar ticks. This is independent of set_rcparams().
838
851
  """
839
852
  self._kw = {'cmap': 'cubehelix', 'alpha': 1,
840
853
  'edgecolors': 'none', 'zorder': 1,
@@ -861,7 +874,8 @@ class PlotAstroData(AstroFrame):
861
874
  p[ch] = pnow
862
875
  for ch in self.bottomleft:
863
876
  self._set_colorbar(p, ch, show_cbar, cblabel, cbformat,
864
- cbticks, cbticklabels, cblocation, st)
877
+ cbticks, cbticklabels, cblocation,
878
+ cblabelfontsize, cbtickfontsize, st)
865
879
 
866
880
  def add_contour(self,
867
881
  levels: list[float] = [-12, -6, -3, 3, 6, 12, 24, 48, 96, 192, 384],
@@ -1088,21 +1102,22 @@ class PlotAstroData(AstroFrame):
1088
1102
  'dec': {'d': r'$^{\circ}$',
1089
1103
  'm': r'$^{\prime}$',
1090
1104
  's': r'.$\hspace{-0.4}^{\prime\prime}$'}}
1091
- cos_dec = np.cos(np.radians(coord2xy(center)[1]))
1105
+ dec_center = coord2xy(center)[1]
1106
+ sign_dec = np.sign(dec_center)
1107
+ cos_dec = np.cos(np.radians(dec_center))
1092
1108
  intgrid = np.array([-3, -2, -1, 0, 1, 2, 3])
1093
- i_mid = (len(intgrid) - 1) // 2
1094
1109
 
1095
1110
  def makegrid(mode: str):
1096
1111
  second = float(get_sec(center, mode))
1097
1112
  no_sec = on_min_scale and (mode == 'dec')
1098
1113
  # gridwidth is a float like 2 x 10^order (arcsec).
1099
- gridwidth, order = _get_gridwidth(mode, self.rmax)
1114
+ gridwidth, order = _get_gridwidth(mode, self.rmax, cos_dec)
1100
1115
  # ndigits = -1 is the largest case for 10", 20", ...
1101
1116
  decimals = str(max(-order, 0))
1102
1117
  rounded = round(second, ndigits=max(-order, -1))
1103
1118
  # Get a grid point closest to the input second.
1104
1119
  rounded = round(rounded / gridwidth) * gridwidth
1105
- factor = 15 * cos_dec if mode == 'ra' else 1
1120
+ factor = 15 * cos_dec if mode == 'ra' else sign_dec
1106
1121
  ticks = (intgrid * gridwidth - second + rounded) * factor
1107
1122
  ticksminor = np.linspace(ticks[0], ticks[-1], 6*nticksminor + 1)
1108
1123
  tickvalues = get_tickvalues(ticks, mode, no_sec)
@@ -1114,14 +1129,18 @@ class PlotAstroData(AstroFrame):
1114
1129
 
1115
1130
  xticks, xticksminor, xticklabels = makegrid('ra')
1116
1131
  yticks, yticksminor, yticklabels = makegrid('dec')
1117
- ra_hm = get_hmdm(xy2coord([xticks[i_mid] / 3600., 0], center), 'ra')
1118
- 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')
1119
1137
  if on_min_scale:
1120
1138
  dec_dm = dec_dm.split('d')[0] + 'd'
1121
1139
  ra_hm = ra_hm.translate(str.maketrans(units['ra']))
1122
1140
  dec_dm = dec_dm.translate(str.maketrans(units['dec']))
1123
- xticklabels[i_mid] = ra_hm + xticklabels[i_mid]
1124
- 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]
1125
1144
  pa2 = PlotAxes2D(True, None, 'linear', 'linear',
1126
1145
  self.Xlim, self.Ylim, xlabel, ylabel,
1127
1146
  xticks, yticks, xticklabels, yticklabels,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.18
3
+ Version: 1.9.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