plotastrodata 1.8.7__tar.gz → 1.8.9__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.9}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/plot_utils.py +116 -86
  4. {plotastrodata-1.8.7 → plotastrodata-1.8.9/plotastrodata.egg-info}/PKG-INFO +1 -1
  5. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/LICENSE +0 -0
  6. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/MANIFEST.in +0 -0
  7. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/README.md +0 -0
  8. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/analysis_utils.py +0 -0
  9. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/const_utils.py +0 -0
  10. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/coord_utils.py +0 -0
  11. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/ext_utils.py +0 -0
  12. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/fft_utils.py +0 -0
  13. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/fits_utils.py +0 -0
  14. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/fitting_utils.py +0 -0
  15. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/los_utils.py +0 -0
  16. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/matrix_utils.py +0 -0
  17. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/noise_utils.py +0 -0
  18. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/setup.cfg +0 -0
  25. {plotastrodata-1.8.7 → plotastrodata-1.8.9}/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.9
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.9'
@@ -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,36 @@ 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
295
- stretch = np.where(np.equal(stretch, None), sigma, stretch)
296
- minlinear = np.where(np.equal(kw['vmin'], None), sigma, kw['vmin'])
297
-
298
- z = (stretch, stretchscale, stretchpower, minlinear)
299
- for i, args in enumerate(zip(*z)):
300
- st, _, _, ml = args
308
+ for k in ['vmin', 'vmax']:
309
+ if k not in kw:
310
+ kw[k] = [None] * n
311
+ isnan = np.equal(stretchscale, None)
312
+ stretchscale = np.where(isnan, sigma, stretchscale)
313
+ isnan = np.equal(kw['vmin'], None)
314
+ cmin = np.where(isnan, sigma, kw['vmin'])
315
+
316
+ argslist = (stretch, stretchscale, stretchpower)
317
+ for i, stretch_args in enumerate(zip(*argslist)):
301
318
  c = data[i]
302
- if st in ['log', 'power']:
303
- c = c.clip(ml, None)
304
- c = _func_stretch(c, *args)
319
+ if stretch_args[0] in ['log', 'power']:
320
+ c = c.clip(cmin[i], None)
321
+ c = do_stretch(c, *stretch_args)
305
322
  data[i] = c
306
- cmin = np.nanmin(c)
307
- cmax = np.nanmax(c)
308
323
  for k in ['vmin', 'vmax']:
309
324
  if kw[k][i] is None:
310
- kw[k][i] = cmin if k == 'vmin' else cmax
325
+ kw[k][i] = np.nanmin(c) if k == 'vmin' else np.nanmax(c)
311
326
  else:
312
- kw[k][i] = _func_stretch(kw[k][i], *args)
327
+ kw[k][i] = do_stretch(kw[k][i], *stretch_args)
313
328
  data = [c.clip(a, b) for c, a, b in zip(data, kw['vmin'], kw['vmax'])]
314
329
  if n == 1:
315
330
  data = data[0]
316
- kw['vmin'] = kw['vmin'][0]
317
- kw['vmax'] = kw['vmax'][0]
331
+ for k in ['vmin', 'vmax']:
332
+ kw[k] = kw[k][0]
318
333
  return data
319
334
 
320
335
 
@@ -819,10 +834,50 @@ class PlotAstroData(AstroFrame):
819
834
  axnow.plot([x[0] - length/2., x[0] + length/2.], [y[0], y[0]],
820
835
  '-', linewidth=linewidth, color=color)
821
836
 
837
+ def _set_colorbar(self, mappable, ch: int, show_cbar: bool,
838
+ cblabel: str, cbformat: str,
839
+ cbticks: list | None, cbticklabels: list | None,
840
+ cblocation: str, stretch: str,
841
+ stretchscale: float, stretchpower: float,
842
+ vmin: float, vmax: float):
843
+ if not show_cbar:
844
+ return
845
+
846
+ if self.fig is None:
847
+ fig = plt.figure(ch // self.rowcol)
848
+ else:
849
+ fig = self.fig
850
+ if len(self.ax) == 1:
851
+ ax = self.ax[ch]
852
+ cb = fig.colorbar(mappable[ch], ax=ax, label=cblabel,
853
+ format=cbformat, location=cblocation)
854
+ else:
855
+ cax = plt.axes([0.88, 0.105, 0.015, 0.77])
856
+ cb = fig.colorbar(mappable[ch], cax=cax, label=cblabel,
857
+ format=cbformat)
858
+ cb.ax.tick_params(labelsize=14)
859
+ font = mpl.font_manager.FontProperties(size=16)
860
+ cb.ax.yaxis.label.set_font_properties(font)
861
+ stretch_args = (stretch, stretchscale, stretchpower)
862
+ if cbticks is not None and ch // self.rowcol == 0:
863
+ cbticks = do_stretch(cbticks, *stretch_args)
864
+ if cbticks is None and stretch == 'log':
865
+ cbticks, cbticklabels = logcbticks()
866
+ if cbticks is None:
867
+ cbticks = cb.get_ticks()
868
+ cond = (vmin < cbticks) * (cbticks < vmax)
869
+ cb.set_ticks(cbticks[cond])
870
+ if cbticklabels is not None:
871
+ tl = np.array(cbticklabels)[cond]
872
+ else:
873
+ t = undo_stretch(cb.get_ticks(), *stretch_args)
874
+ tl = [f'{d:{cbformat[1:]}}' for d in t]
875
+ cb.set_ticklabels(tl)
876
+
822
877
  def add_color(self,
823
878
  stretch: str = 'linear',
824
879
  stretchscale: float | None = None,
825
- stretchpower: float = 0,
880
+ stretchpower: float = 0.5,
826
881
  show_cbar: bool = True,
827
882
  cblabel: str | None = None,
828
883
  cbformat: float = '%.1e',
@@ -833,9 +888,9 @@ class PlotAstroData(AstroFrame):
833
888
  """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
889
 
835
890
  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.
891
+ 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'.
892
+ stretchscale (float, optional): Color scale is asinh(data / stretchscale). Defaults to None.
893
+ 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 0.5.
839
894
  show_cbar (bool, optional): Show color bar. Defaults to True.
840
895
  cblabel (str, optional): Colorbar label. Defaults to None.
841
896
  cbformat (float, optional): Format for ticklabels of colorbar. Defaults to '%.1e'.
@@ -851,11 +906,13 @@ class PlotAstroData(AstroFrame):
851
906
  print('No pixel size. Skip add_color.')
852
907
  return
853
908
 
854
- minlinear = _kw['vmin'] if 'vmin' in _kw else sigma
855
909
  if cblabel is None:
856
910
  cblabel = bunit
911
+ if stretchscale is None:
912
+ stretchscale = sigma
857
913
 
858
- c = set_minmax(c, stretch, stretchscale, stretchpower, sigma, _kw)
914
+ stretch_args = (stretch, stretchscale, stretchpower)
915
+ c = set_minmax(c, *stretch_args, sigma, _kw)
859
916
  c = self.vskipfill(c, v)
860
917
  if type(self.channelnumber) is int:
861
918
  c = [c[self.channelnumber]]
@@ -865,37 +922,9 @@ class PlotAstroData(AstroFrame):
865
922
  if ch in self.bottomleft:
866
923
  p[ch] = pnow
867
924
  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)
925
+ self._set_colorbar(p, ch, show_cbar, cblabel, cbformat,
926
+ cbticks, cbticklabels, cblocation,
927
+ *stretch_args, _kw['vmin'], _kw['vmax'])
899
928
  self.add_beam(beam=beam, **beam_kwargs)
900
929
 
901
930
  def add_contour(self,
@@ -987,14 +1016,14 @@ class PlotAstroData(AstroFrame):
987
1016
  def add_rgb(self,
988
1017
  stretch: list[str, str, str] = ['linear'] * 3,
989
1018
  stretchscale: list[float | None, float | None, float | None] = [None] * 3,
990
- stretchpower: list[float, float, float] = [0, 0, 0],
1019
+ stretchpower: list[float, float, float] = [1, 1, 1],
991
1020
  **kwargs) -> None:
992
1021
  """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
1022
 
994
1023
  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.
1024
+ 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'.
1025
+ stretchscale (float, optional): Color scale is asinh(data / stretchscale). Defaults to None.
1026
+ 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
1027
  """
999
1028
  from PIL import Image
1000
1029
 
@@ -1005,7 +1034,8 @@ class PlotAstroData(AstroFrame):
1005
1034
  print('No pixel size. Skip add_rgb.')
1006
1035
  return
1007
1036
 
1008
- c = set_minmax(c, stretch, stretchscale, stretchpower, sigma, _kw)
1037
+ stretch_args = (stretch, stretchscale, stretchpower)
1038
+ c = set_minmax(c, *stretch_args, sigma, _kw)
1009
1039
  if not (np.shape(c[0]) == np.shape(c[1]) == np.shape(c[2])):
1010
1040
  print('RGB shapes mismatch. Skip add_rgb.')
1011
1041
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.7
3
+ Version: 1.8.9
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