plotastrodata 1.8.7__tar.gz → 1.8.8__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.7/plotastrodata.egg-info → plotastrodata-1.8.8}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/plot_utils.py +110 -85
  4. {plotastrodata-1.8.7 → plotastrodata-1.8.8/plotastrodata.egg-info}/PKG-INFO +1 -1
  5. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/LICENSE +0 -0
  6. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/MANIFEST.in +0 -0
  7. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/README.md +0 -0
  8. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/analysis_utils.py +0 -0
  9. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/const_utils.py +0 -0
  10. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/coord_utils.py +0 -0
  11. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/ext_utils.py +0 -0
  12. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/fft_utils.py +0 -0
  13. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/fits_utils.py +0 -0
  14. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/fitting_utils.py +0 -0
  15. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/los_utils.py +0 -0
  16. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/matrix_utils.py +0 -0
  17. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/noise_utils.py +0 -0
  18. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/setup.cfg +0 -0
  25. {plotastrodata-1.8.7 → plotastrodata-1.8.8}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.7
3
+ Version: 1.8.8
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.7'
4
+ __version__ = '1.8.8'
@@ -95,43 +95,50 @@ def logcbticks(vmin: float = -3.01, vmax: float = 3.01
95
95
  return ticks, ticklabels
96
96
 
97
97
 
98
- def pow10(x: np.ndarray, stretchpower: float, xmin: float
99
- ) -> np.ndarray:
98
+ def pow10(x: np.ndarray, stretchpower: float) -> np.ndarray:
100
99
  """A power-law function scaled by xmin. This function is used for the case of stretch='power' in PlotAstroData.add_color().
101
100
 
102
101
  Args:
103
102
  x (np.ndarray): Input in the linear scale.
104
- stretchpower (float): Power-law index between 0 and 1. 0 means the linear scale, while 1 means the logarithmic scale.
105
- stretchscale (float): The minimum value of x. xmin must be positive.
103
+ stretchpower (float, optional): The output is (data**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale.
106
104
 
107
105
  Returns:
108
106
  np.ndarray: Output values.
109
107
  """
110
- p = 1 - stretchpower
111
- y = ((x / xmin)**p - 1) / p / np.log(10)
108
+ p = 1e-6 if stretchpower == 0 else stretchpower
109
+ y = (x**p - 1) / p / np.log(10)
112
110
  return y
113
111
 
114
112
 
115
- def ipow10(x: np.ndarray, stretchpower: float, xmin: float
116
- ) -> np.ndarray:
113
+ def ipow10(x: np.ndarray, stretchpower: float) -> np.ndarray:
117
114
  """The inverse function of pow10. This function is used for the case of stretch='power' in PlotAstroData.add_color().
118
115
 
119
116
  Args:
120
117
  x (np.ndarray): Input values.
121
- stretchpower (float): Power-law index between 0 and 1. 0 means the linear scale, while 1 means the logarithmic scale.
122
- xmin (float): The minimum value of x. xmin must be positive.
118
+ stretchpower (float, optional): The input is (data**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale.
123
119
 
124
120
  Returns:
125
121
  np.ndarray: Output values in the linear scale.
126
122
  """
127
- p = 1 - stretchpower
128
- y = xmin * (1 + p * np.log(10) * x)**(1 / p)
123
+ p = 1e-6 if stretchpower == 0 else stretchpower
124
+ y = (1 + p * np.log(10) * x)**(1 / p)
129
125
  return y
130
126
 
131
127
 
132
- def _func_stretch(x: list | np.ndarray,
133
- stretch: str, stretchscale: float,
134
- stretchpower: float, minlinear: float):
128
+ def do_stretch(x: list | np.ndarray,
129
+ stretch: str, stretchscale: float,
130
+ stretchpower: float) -> np.ndarray:
131
+ """Get the stretched values.
132
+
133
+ Args:
134
+ x (list | np.ndarray): Input array in the linear scale.
135
+ stretch (str): 'log', 'asinh', 'power', or 'linear'. Any other means 'linear'. 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
136
+ stretchscale (float, optional): The output is asinh(data / stretchscale). Defaults to None.
137
+ stretchpower (float, optional): The output is ((data / stretchscale)**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale.
138
+
139
+ Returns:
140
+ np.ndarray: Output stretched array.
141
+ """
135
142
  t = np.array(x)
136
143
  match stretch:
137
144
  case 'log':
@@ -139,13 +146,24 @@ def _func_stretch(x: list | np.ndarray,
139
146
  case 'asinh':
140
147
  t = np.arcsinh(t / stretchscale)
141
148
  case 'power':
142
- t = pow10(t, stretchpower, minlinear)
149
+ t = pow10(t / stretchscale, stretchpower)
143
150
  return t
144
151
 
145
152
 
146
- def _ifunc_stretch(x: object,
147
- stretch: str, stretchscale: float,
148
- stretchpower: float, minlinear: float):
153
+ def undo_stretch(x: list | np.ndarray,
154
+ stretch: str, stretchscale: float,
155
+ stretchpower: float) -> np.ndarray:
156
+ """Get the linear values from the stretched values.
157
+
158
+ Args:
159
+ x (list | np.ndarray): Input stretched array.
160
+ stretch (str): 'log', 'asinh', 'power', or 'linear'. Any other means 'linear'. 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
161
+ stretchscale (float, optional): The input is asinh(data / stretchscale). Defaults to None.
162
+ stretchpower (float, optional): The input is ((data / stretchscale)**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale.
163
+
164
+ Returns:
165
+ np.ndarray: Output array in the linear scale.
166
+ """
149
167
  t = np.array(x)
150
168
  match stretch:
151
169
  case 'log':
@@ -153,7 +171,7 @@ def _ifunc_stretch(x: object,
153
171
  case 'asinh':
154
172
  t = np.sinh(t) * stretchscale
155
173
  case 'power':
156
- t = ipow10(t, stretchpower, minlinear)
174
+ t = ipow10(t, stretchpower) * stretchscale
157
175
  return t
158
176
 
159
177
 
@@ -268,7 +286,7 @@ def set_minmax(data: np.ndarray, stretch: str, stretchscale: float,
268
286
  Args:
269
287
  data (np.ndarray): Plotted data.
270
288
  stretch (str): 'log', 'asinh', 'power'. Any other means linear.
271
- stretchscale (float): For the arcsinh strech.
289
+ stretchscale (float): For the arcsinh strech and the power stretch.
272
290
  stretchpower (float): For the power strech.
273
291
  sigma (float): Noise level.
274
292
  kw (dict): Probably like {'vmin':0, 'vmax':1}.
@@ -282,39 +300,34 @@ def set_minmax(data: np.ndarray, stretch: str, stretchscale: float,
282
300
  stretch = [stretch]
283
301
  stretchscale = [stretchscale]
284
302
  stretchpower = [stretchpower]
285
- if 'vmin' in kw:
286
- kw['vmin'] = [kw['vmin']]
287
- if 'vmax' in kw:
288
- kw['vmax'] = [kw['vmax']]
303
+ for k in ['vmin', 'vmax']:
304
+ if k in kw:
305
+ kw[k] = [kw[k]]
289
306
 
290
307
  n = len(data)
291
- if 'vmin' not in kw:
292
- kw['vmin'] = [None] * n
293
- if 'vmax' not in kw:
294
- kw['vmax'] = [None] * n
308
+ for k in ['vmin', 'vmax']:
309
+ if k not in kw:
310
+ kw[k] = [None] * n
295
311
  stretch = np.where(np.equal(stretch, None), sigma, stretch)
296
- minlinear = np.where(np.equal(kw['vmin'], None), sigma, kw['vmin'])
312
+ cmin = np.where(np.equal(kw['vmin'], None), sigma, kw['vmin'])
297
313
 
298
- z = (stretch, stretchscale, stretchpower, minlinear)
299
- for i, args in enumerate(zip(*z)):
300
- st, _, _, ml = args
314
+ argslist = (stretch, stretchscale, stretchpower)
315
+ for i, stretch_args in enumerate(zip(*argslist)):
301
316
  c = data[i]
302
- if st in ['log', 'power']:
303
- c = c.clip(ml, None)
304
- c = _func_stretch(c, *args)
317
+ if stretch_args[0] in ['log', 'power']:
318
+ c = c.clip(cmin[i], None)
319
+ c = do_stretch(c, *stretch_args)
305
320
  data[i] = c
306
- cmin = np.nanmin(c)
307
- cmax = np.nanmax(c)
308
321
  for k in ['vmin', 'vmax']:
309
322
  if kw[k][i] is None:
310
- kw[k][i] = cmin if k == 'vmin' else cmax
323
+ kw[k][i] = np.nanmin(c) if k == 'vmin' else np.nanmax(c)
311
324
  else:
312
- kw[k][i] = _func_stretch(kw[k][i], *args)
325
+ kw[k][i] = do_stretch(kw[k][i], *stretch_args)
313
326
  data = [c.clip(a, b) for c, a, b in zip(data, kw['vmin'], kw['vmax'])]
314
327
  if n == 1:
315
328
  data = data[0]
316
- kw['vmin'] = kw['vmin'][0]
317
- kw['vmax'] = kw['vmax'][0]
329
+ for k in ['vmin', 'vmax']:
330
+ kw[k] = kw[k][0]
318
331
  return data
319
332
 
320
333
 
@@ -819,10 +832,49 @@ class PlotAstroData(AstroFrame):
819
832
  axnow.plot([x[0] - length/2., x[0] + length/2.], [y[0], y[0]],
820
833
  '-', linewidth=linewidth, color=color)
821
834
 
835
+ def _set_colorbar(self, mappable, ch: int, show_cbar: bool,
836
+ cblabel: str, cbformat: str,
837
+ cbticks: list | None, cbticklabels: list | None,
838
+ cblocation: str, stretch: str,
839
+ stretchscale: float, stretchpower: float,
840
+ vmin: float, vmax: float):
841
+ if not show_cbar:
842
+ return
843
+
844
+ if self.fig is None:
845
+ fig = plt.figure(ch // self.rowcol)
846
+ else:
847
+ fig = self.fig
848
+ if len(self.ax) == 1:
849
+ ax = self.ax[ch]
850
+ cb = fig.colorbar(mappable[ch], ax=ax, label=cblabel,
851
+ format=cbformat, location=cblocation)
852
+ else:
853
+ cax = plt.axes([0.88, 0.105, 0.015, 0.77])
854
+ cb = fig.colorbar(mappable[ch], cax=cax, label=cblabel,
855
+ format=cbformat)
856
+ cb.ax.tick_params(labelsize=14)
857
+ font = mpl.font_manager.FontProperties(size=16)
858
+ cb.ax.yaxis.label.set_font_properties(font)
859
+ stretch_args = (stretch, stretchscale, stretchpower)
860
+ if cbticks is not None and ch // self.rowcol == 0:
861
+ cbticks = do_stretch(cbticks, *stretch_args)
862
+ if cbticks is None and stretch == 'log':
863
+ cbticks, cbticklabels = logcbticks()
864
+ if cbticks is not None:
865
+ cond = (vmin < cbticks) * (cbticks < vmax)
866
+ cb.set_ticks(cbticks[cond])
867
+ if cbticklabels is not None:
868
+ tl = np.array(cbticklabels)[cond]
869
+ else:
870
+ t = undo_stretch(cb.get_ticks(), *stretch_args)
871
+ tl = [f'{d:{cbformat[1:]}}' for d in t]
872
+ cb.set_ticklabels(tl)
873
+
822
874
  def add_color(self,
823
875
  stretch: str = 'linear',
824
876
  stretchscale: float | None = None,
825
- stretchpower: float = 0,
877
+ stretchpower: float = 1,
826
878
  show_cbar: bool = True,
827
879
  cblabel: str | None = None,
828
880
  cbformat: float = '%.1e',
@@ -833,9 +885,9 @@ class PlotAstroData(AstroFrame):
833
885
  """Use Axes.pcolormesh of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs may include arguments for add_beam() and a dict of beam_kwargs to specify the beam patch in more detail. kwargs may include xskiip and yskip.
834
886
 
835
887
  Args:
836
- stretch (str, optional): 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
837
- stretchscale (float, optional): color scale is asinh(data / stretchscale). Defaults to None.
838
- stretchpower (float, optional): color scale is ((data / vmin)**(1 - stretchpower) - 1) / (1 - stretchpower) / ln(10). 0 means the linear scale. 1 means the logarithmic scale. Defaults to 0.
888
+ stretch (str, optional): 'log', 'asinh', 'power', or 'linear'. Any other means 'linear'. 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
889
+ stretchscale (float, optional): Color scale is asinh(data / stretchscale). Defaults to None.
890
+ stretchpower (float, optional): Color scale is ((data / stretchscale)**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale. Defaults to 1.
839
891
  show_cbar (bool, optional): Show color bar. Defaults to True.
840
892
  cblabel (str, optional): Colorbar label. Defaults to None.
841
893
  cbformat (float, optional): Format for ticklabels of colorbar. Defaults to '%.1e'.
@@ -851,11 +903,11 @@ class PlotAstroData(AstroFrame):
851
903
  print('No pixel size. Skip add_color.')
852
904
  return
853
905
 
854
- minlinear = _kw['vmin'] if 'vmin' in _kw else sigma
855
906
  if cblabel is None:
856
907
  cblabel = bunit
857
-
858
- c = set_minmax(c, stretch, stretchscale, stretchpower, sigma, _kw)
908
+
909
+ stretch_args = (stretch, stretchscale, stretchpower)
910
+ c = set_minmax(c, *stretch_args, sigma, _kw)
859
911
  c = self.vskipfill(c, v)
860
912
  if type(self.channelnumber) is int:
861
913
  c = [c[self.channelnumber]]
@@ -865,37 +917,9 @@ class PlotAstroData(AstroFrame):
865
917
  if ch in self.bottomleft:
866
918
  p[ch] = pnow
867
919
  for ch in self.bottomleft:
868
- if not show_cbar:
869
- break
870
- if self.fig is None:
871
- fig = plt.figure(ch // self.rowcol)
872
- else:
873
- fig = self.fig
874
- if len(self.ax) == 1:
875
- ax = self.ax[ch]
876
- cb = fig.colorbar(p[ch], ax=ax, label=cblabel,
877
- format=cbformat, location=cblocation)
878
- else:
879
- cax = plt.axes([0.88, 0.105, 0.015, 0.77])
880
- cb = fig.colorbar(p[ch], cax=cax, label=cblabel,
881
- format=cbformat)
882
- cb.ax.tick_params(labelsize=14)
883
- font = mpl.font_manager.FontProperties(size=16)
884
- cb.ax.yaxis.label.set_font_properties(font)
885
- args = [stretch, stretchscale, stretchpower, minlinear]
886
- if cbticks is not None and ch // self.rowcol == 0:
887
- cbticks = _func_stretch(cbticks, *args)
888
- if cbticks is None and stretch == 'log':
889
- cbticks, cbticklabels = logcbticks()
890
- if cbticks is not None:
891
- cond = (_kw['vmin'] < cbticks) * (cbticks < _kw['vmax'])
892
- cb.set_ticks(cbticks[cond])
893
- if cbticklabels is not None:
894
- tl = np.array(cbticklabels)[cond]
895
- else:
896
- t = _ifunc_stretch(cb.get_ticks(), *args)
897
- tl = [f'{d:{cbformat[1:]}}' for d in t]
898
- cb.set_ticklabels(tl)
920
+ self._set_colorbar(p, ch, show_cbar, cblabel, cbformat,
921
+ cbticks, cbticklabels, cblocation,
922
+ *stretch_args, _kw['vmin'], _kw['vmax'])
899
923
  self.add_beam(beam=beam, **beam_kwargs)
900
924
 
901
925
  def add_contour(self,
@@ -987,14 +1011,14 @@ class PlotAstroData(AstroFrame):
987
1011
  def add_rgb(self,
988
1012
  stretch: list[str, str, str] = ['linear'] * 3,
989
1013
  stretchscale: list[float | None, float | None, float | None] = [None] * 3,
990
- stretchpower: list[float, float, float] = [0, 0, 0],
1014
+ stretchpower: list[float, float, float] = [1, 1, 1],
991
1015
  **kwargs) -> None:
992
1016
  """Use PIL.Image and imshow of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. A three-element array ([red, green, blue]) is supposed for all arguments, except for xskip, yskip and show_beam, including vmax and vmin. kwargs may include arguments for add_beam() and a dict of beam_kwargs to specify the beam patch in more detail. kwargs may include xskiip and yskip.
993
1017
 
994
1018
  Args:
995
- stretch (str, optional): 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
996
- stretchscale (float, optional): color scale is asinh(data / stretchscale). Defaults to None.
997
- stretchpower (float, optional): color scale is ((data / vmin)**(1 - stretchpower) - 1) / (1 - stretchpower) / ln(10). 0 means the linear scale. 1 means the logarithmic scale. Defaults to 0.
1019
+ stretch (str, optional): 'log', 'asinh', 'power', or 'linear'. Any other means 'linear'. 'log' means the mapped data are logarithmic. 'asinh' means the mapped data are arc sin hyperbolic. 'power' means the mapped data are power-law (see also stretchpower). Defaults to 'linear'.
1020
+ stretchscale (float, optional): Color scale is asinh(data / stretchscale). Defaults to None.
1021
+ stretchpower (float, optional): Color scale is ((data / stretchscale)**stretchpower - 1) / stretchpower / ln(10). 1 means the linear scale, while 0 means the logarithmic scale. Defaults to 1.
998
1022
  """
999
1023
  from PIL import Image
1000
1024
 
@@ -1005,7 +1029,8 @@ class PlotAstroData(AstroFrame):
1005
1029
  print('No pixel size. Skip add_rgb.')
1006
1030
  return
1007
1031
 
1008
- c = set_minmax(c, stretch, stretchscale, stretchpower, sigma, _kw)
1032
+ stretch_args = (stretch, stretchscale, stretchpower)
1033
+ c = set_minmax(c, *stretch_args, sigma, _kw)
1009
1034
  if not (np.shape(c[0]) == np.shape(c[1]) == np.shape(c[2])):
1010
1035
  print('RGB shapes mismatch. Skip add_rgb.')
1011
1036
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.7
3
+ Version: 1.8.8
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