plotastrodata 1.8.0__tar.gz → 1.8.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.8.0/plotastrodata.egg-info → plotastrodata-1.8.2}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/noise_utils.py +43 -18
  4. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/plot_utils.py +73 -50
  5. {plotastrodata-1.8.0 → plotastrodata-1.8.2/plotastrodata.egg-info}/PKG-INFO +1 -1
  6. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/LICENSE +0 -0
  7. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/MANIFEST.in +0 -0
  8. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/README.md +0 -0
  9. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/analysis_utils.py +0 -0
  10. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/const_utils.py +0 -0
  11. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/coord_utils.py +0 -0
  12. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/ext_utils.py +0 -0
  13. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/fft_utils.py +0 -0
  14. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/fits_utils.py +0 -0
  15. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/fitting_utils.py +0 -0
  16. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/los_utils.py +0 -0
  17. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/matrix_utils.py +0 -0
  18. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/setup.cfg +0 -0
  25. {plotastrodata-1.8.0 → plotastrodata-1.8.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.0
3
+ Version: 1.8.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.8.0'
4
+ __version__ = '1.8.2'
@@ -1,5 +1,6 @@
1
1
  import warnings
2
2
  import numpy as np
3
+ import matplotlib.pyplot as plt
3
4
  from scipy.special import erf
4
5
 
5
6
  from plotastrodata.fitting_utils import EmceeCorner
@@ -100,23 +101,23 @@ def select_noise(data: np.ndarray, sigma: str) -> np.ndarray:
100
101
 
101
102
 
102
103
  class Noise:
103
- def __init__(self, data: np.ndarray, sigma: str):
104
- """This class holds the data selected as noise, histogram, and best-fit function.
105
- The following methods are acceptable for data selection. Multiple options are possible.
106
- 'edge': use data[0] and data[-1].
107
- 'out': exclude inner 60% about axes=-2 and -1.
108
- 'neg': use only negative values.
109
- 'iter': exclude outliers.
110
- The following methods are acceptable for noise estimation. Only single option is possible.
111
- 'med': calculate rms from the median of data^2 assuming Gaussian.
112
- 'hist': fit histgram with Gaussian.
113
- 'hist-pbcor': fit histgram with PB-corrected Gaussian.
114
- '(no string)': calculate the mean and standard deviation.
104
+ """This class holds the data selected as noise, histogram, and best-fit function.
105
+ The following methods are acceptable for data selection. Multiple options are possible.
106
+ 'edge': use data[0] and data[-1].
107
+ 'out': exclude inner 60% about axes=-2 and -1.
108
+ 'neg': use only negative values.
109
+ 'iter': exclude outliers.
110
+ The following methods are acceptable for noise estimation. Only single option is possible.
111
+ 'med': calculate rms from the median of data^2 assuming Gaussian.
112
+ 'hist': fit histgram with Gaussian.
113
+ 'hist-pbcor': fit histgram with PB-corrected Gaussian.
114
+ '(no string)': calculate the mean and standard deviation.
115
115
 
116
- Args:
117
- data (np.ndarray): Original data array.
118
- sigma (str): Methods above, like 'edge,neg,hist-pbcor'.
119
- """
116
+ Args:
117
+ data (np.ndarray): Original data array.
118
+ sigma (str): Methods above, like 'edge,neg,hist-pbcor'.
119
+ """
120
+ def __init__(self, data: np.ndarray, sigma: str):
120
121
  self.data = select_noise(data, sigma)
121
122
  self.sigma = sigma
122
123
  self.m0 = np.mean(self.data)
@@ -157,12 +158,36 @@ class Noise:
157
158
  self.std = float(self.popt[0] * self.s0)
158
159
  self.model = model(self.hbin, *self.popt)
159
160
 
161
+ def plot_histogram(self, savefig: dict | str | None = None,
162
+ show: bool = False):
163
+ """Make a simple figure of the histogram and model.
164
+
165
+ Args:
166
+ savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
167
+ show (bool, optional): True means doing plt.show(). Defaults to False.
168
+ """
169
+ savefig0 = {'bbox_inches': 'tight', 'transparent': True}
170
+ fig = plt.figure()
171
+ ax = fig.add_subplot(1, 1, 1)
172
+ ax.plot(self.hbin, self.hist, drawstyle='steps-mid')
173
+ ax.plot(self.hbin, self.model, '-')
174
+ ax.set_xlabel('(noise - m0) / s0')
175
+ ax.set_ylabel('Probability density')
176
+ fig.tight_layout()
177
+ if savefig is not None:
178
+ s = {'fname': savefig} if type(savefig) is str else savefig
179
+ savefig0.update(s)
180
+ fig.savefig(**savefig0)
181
+ if show:
182
+ plt.show()
183
+ plt.close()
184
+
160
185
 
161
186
  def estimate_rms(data: np.ndarray,
162
187
  sigma: float | str | None = 'hist'
163
188
  ) -> float:
164
- """Estimate a noise level of a N-D array.
165
- When a float number or None is given, this function just outputs it.
189
+ """Estimate a noise level of a data array.
190
+ When a float number or None is given as sigma, this function just outputs it.
166
191
 
167
192
  Args:
168
193
  data (np.ndarray): Data array whose noise is estimated.
@@ -88,7 +88,7 @@ class PlotAxes2D():
88
88
  aspect (dict or float, optional): Defaults to None.
89
89
  """
90
90
  samexy: bool = True
91
- loglog: bool | None = None
91
+ loglog: float | None = None
92
92
  xscale: str = 'linear'
93
93
  yscale: str = 'linear'
94
94
  xlim: list | None = None
@@ -99,8 +99,8 @@ class PlotAxes2D():
99
99
  yticks: list | None = None
100
100
  xticklabels: list | None = None
101
101
  yticklabels: list | None = None
102
- xticksminor: list | int = None
103
- yticksminor: list | int = None
102
+ xticksminor: list | int | None = None
103
+ yticksminor: list | int | None = None
104
104
  grid: dict | None = None
105
105
  aspect: dict | float | None = None
106
106
 
@@ -271,6 +271,8 @@ def kwargs2AstroFrame(kw: dict) -> AstroFrame:
271
271
  for k in vars(f):
272
272
  if k in kw:
273
273
  tmp[k] = kw[k]
274
+ if k not in ['fitsimage', 'center']:
275
+ del kw[k]
274
276
  f = AstroFrame(**tmp)
275
277
  return f
276
278
 
@@ -1161,6 +1163,30 @@ class PlotAstroData(AstroFrame):
1161
1163
  return fig, self.ax[0]
1162
1164
 
1163
1165
 
1166
+ def close_figure(fig: object,
1167
+ savefig: dict | str | None = None,
1168
+ show: bool = False) -> tuple[object, object]:
1169
+ """Save, show, and close the figure.
1170
+
1171
+ Args:
1172
+ fig (optional): External plt.figure(). Defaults to None.
1173
+ savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
1174
+ show (bool, optional): True means doing plt.show(). Defaults to False.
1175
+
1176
+ Returns:
1177
+ tuple: (fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
1178
+ """
1179
+ savefig0 = {'bbox_inches': 'tight', 'transparent': True}
1180
+ fig.tight_layout()
1181
+ if savefig is not None:
1182
+ s = {'fname': savefig} if type(savefig) is str else savefig
1183
+ savefig0.update(s)
1184
+ fig.savefig(**savefig0)
1185
+ if show:
1186
+ plt.show()
1187
+ plt.close()
1188
+
1189
+
1164
1190
  def plotprofile(coords: list[str] | str = [],
1165
1191
  xlist: list[float] = [], ylist: list[float] = [],
1166
1192
  ellipse: list[float, float, float] | None = None,
@@ -1169,12 +1195,14 @@ def plotprofile(coords: list[str] | str = [],
1169
1195
  gaussfit: bool = False, gauss_kwargs: dict = {},
1170
1196
  title: list[str] | None = None,
1171
1197
  text: list[str] | None = None,
1172
- dist: float = 1., vsys: float = 0.,
1173
- nrows: int = 0, ncols: int = 1, fig=None, ax=None,
1198
+ nrows: int = 0, ncols: int = 1,
1199
+ fig: object | None = None,
1200
+ ax: object | None = None,
1174
1201
  getfigax: bool = False,
1175
- savefig: dict = None, show: bool = True,
1202
+ savefig: dict | str | None = None,
1203
+ show: bool = False,
1176
1204
  **kwargs) -> tuple[object, object]:
1177
- """Use Axes.plot of matplotlib to plot line profiles at given coordinates. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs can include the arguments of PlotAxes2D to adjust x and y axes.
1205
+ """Use Axes.plot of matplotlib to plot line profiles at given coordinates. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs must include the arguments of AstroFrame to specify the ranges and so on for plotting. kwargs can include the arguments of PlotAxes2D to adjust x and y axes.
1178
1206
 
1179
1207
  Args:
1180
1208
  coords (list, optional): Coordinates. Defaults to [].
@@ -1188,6 +1216,13 @@ def plotprofile(coords: list[str] | str = [],
1188
1216
  gauss_kwargs (dict, optional): Kwargs for Axes.plot. Defaults to {}.
1189
1217
  title (list, optional): For each plot. Defaults to None.
1190
1218
  text (list, optional): For each plot. Defaults to None.
1219
+ nrows (int, optional): Used for channel maps. Defaults to 0.
1220
+ ncols (int, optional): Used for channel maps. Defaults to 1.
1221
+ fig (optional): External plt.figure(). Defaults to None.
1222
+ ax (optional): External fig.add_subplot(). Defaults to None.
1223
+ getfigax (bool, optional): Defaults to False.
1224
+ savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
1225
+ show (bool, optional): True means doing plt.show(). Defaults to False.
1191
1226
 
1192
1227
  Returns:
1193
1228
  tuple: (fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
@@ -1196,13 +1231,10 @@ def plotprofile(coords: list[str] | str = [],
1196
1231
  _kw.update(kwargs)
1197
1232
  _kwgauss = {'drawstyle': 'default', 'color': 'g'}
1198
1233
  _kwgauss.update(gauss_kwargs)
1199
- savefig0 = {'bbox_inches': 'tight', 'transparent': True}
1200
1234
  if type(coords) is str:
1201
1235
  coords = [coords]
1202
- vmin, vmax = _kw['xlim'] if 'xlim' in _kw else [-1e10, 1e10]
1203
- f = AstroFrame(dist=dist, vsys=vsys, vmin=vmin, vmax=vmax)
1236
+ f = kwargs2AstroFrame(_kw)
1204
1237
  d = kwargs2AstroData(_kw)
1205
- Tb = d.Tb
1206
1238
  f.read(d)
1207
1239
  d.binning([width, 1, 1])
1208
1240
  v, prof, gfitres = d.profile(coords=coords, xlist=xlist, ylist=ylist,
@@ -1211,7 +1243,7 @@ def plotprofile(coords: list[str] | str = [],
1211
1243
  nprof = len(prof)
1212
1244
  if 'ylabel' in _kw:
1213
1245
  ylabel = _kw['ylabel']
1214
- elif Tb:
1246
+ elif d.Tb:
1215
1247
  ylabel = r'$T_b$ (K)'
1216
1248
  elif flux:
1217
1249
  ylabel = 'Flux (Jy)'
@@ -1237,7 +1269,7 @@ def plotprofile(coords: list[str] | str = [],
1237
1269
  if 'xlim' not in _kw:
1238
1270
  _kw['xlim'] = [v.min(), v.max()]
1239
1271
  _kw['samexy'] = False
1240
- pa2d = kwargs2PlotAxes2D(_kw)
1272
+ pa2 = kwargs2PlotAxes2D(_kw)
1241
1273
  for i in range(nprof):
1242
1274
  sharex = None if i < nrows - 1 else ax[i - 1]
1243
1275
  ax[i] = fig.add_subplot(nrows, ncols, i + 1, sharex=sharex)
@@ -1246,7 +1278,7 @@ def plotprofile(coords: list[str] | str = [],
1246
1278
  ax[i].plot(v, prof[i], **_kw)
1247
1279
  ax[i].hlines([0], v.min(), v.max(), linestyle='dashed', color='k')
1248
1280
  ax[i].set_ylabel(ylabel[i])
1249
- pa2d.set_xyaxes(ax[i])
1281
+ pa2.set_xyaxes(ax[i])
1250
1282
  if text is not None:
1251
1283
  ax[i].text(**text[i])
1252
1284
  if title is not None:
@@ -1257,59 +1289,51 @@ def plotprofile(coords: list[str] | str = [],
1257
1289
  plt.setp(ax[i].get_xticklabels(), visible=False)
1258
1290
  if getfigax:
1259
1291
  return fig, ax
1260
- fig.tight_layout()
1261
- if savefig is not None:
1262
- s = {'fname': savefig} if type(savefig) is str else savefig
1263
- savefig0.update(s)
1264
- fig.savefig(**savefig0)
1265
- if show:
1266
- plt.show()
1267
- plt.close()
1292
+
1293
+ close_figure(fig, savefig, show)
1268
1294
 
1269
1295
 
1270
1296
  def plotslice(length: float, dx: float | None = None, pa: float = 0,
1271
- dist: float = 1, xoff: float = 0, yoff: float = 0,
1272
- xflip: bool = True, yflip: bool = False,
1273
1297
  txtfile: str | None = None,
1274
1298
  fig: object | None = None, ax: object | None = None,
1275
1299
  getfigax: bool = False,
1276
1300
  savefig: str | dict | None = None, show: bool = False,
1277
- **kwargs) -> None:
1278
- """Use Axes.plot of matplotlib to plot a 1D spatial slice in a 2D map. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs can include the arguments of PlotAxes2D to adjust x and y axes.
1301
+ **kwargs) -> tuple[object, object]:
1302
+ """Use Axes.plot of matplotlib to plot a 1D spatial slice in a 2D map. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs must include the arguments of AstroFrame to specify the ranges and so on for plotting. kwargs can include the arguments of PlotAxes2D to adjust x and y axes.
1279
1303
 
1280
1304
  Args:
1281
1305
  length (float): Slice length.
1282
1306
  dx (float, optional): Grid increment. Defaults to None.
1283
1307
  pa (float, optional): Degree. Position angle. Defaults to 0.
1284
- fitsimage to show: same as in PlotAstroData.
1308
+ txtfile (str, optional): File name for numpy.savetxt(). Defaults to None.
1309
+ fig (optional): External plt.figure(). Defaults to None.
1310
+ ax (optional): External fig.add_subplot(). Defaults to None.
1311
+ getfigax (bool, optional): Defaults to False.
1312
+ savefig (dict or str, optional): For plt.figure().savefig(). Defaults to None.
1313
+ show (bool, optional): True means doing plt.show(). Defaults to False.
1314
+
1315
+ Returns:
1316
+ tuple: (fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
1285
1317
  """
1286
1318
  _kw = {'linestyle': '-', 'marker': 'o'}
1287
1319
  _kw.update(kwargs)
1288
- savefig0 = {'bbox_inches': 'tight', 'transparent': True}
1289
- center = _kw['center'] if 'center' in _kw else None
1290
- f = AstroFrame(rmax=length / 2, dist=dist, xoff=xoff, yoff=yoff,
1291
- xflip=xflip, yflip=yflip, center=center)
1320
+ _kw['rmax'] = length / 2
1321
+ f = kwargs2AstroFrame(_kw)
1292
1322
  d = kwargs2AstroData(_kw)
1293
- Tb = d.Tb
1294
1323
  f.read(d)
1295
1324
  if np.ndim(d.data) > 2:
1296
1325
  print('Only 2D map is supported.')
1297
1326
  return
1298
1327
 
1299
1328
  r, z = d.slice(length=length, pa=pa, dx=dx)
1300
- xunit = 'arcsec' if dist == 1 else 'au'
1301
- yunit = 'K' if Tb else d.bunit
1302
- yquantity = 'Tb' if Tb else 'intensity'
1329
+ xunit = 'arcsec' if f.dist == 1 else 'au'
1330
+ yunit = 'K' if d.Tb else d.bunit
1331
+ yquantity = r'$T_b$' if d.Tb else 'intensity'
1303
1332
 
1304
1333
  if txtfile is not None:
1305
1334
  np.savetxt(txtfile, np.c_[r, z],
1306
1335
  header=f'x ({xunit}), {yquantity} ({yunit}); '
1307
1336
  + f'positive x is pa={pa:.2f} deg.')
1308
- set_rcparams()
1309
- if fig is None:
1310
- fig = plt.figure()
1311
- if ax is None:
1312
- ax = fig.add_subplot(1, 1, 1)
1313
1337
  if 'xlabel' not in _kw:
1314
1338
  _kw['xlabel'] = f'Offset ({xunit})'
1315
1339
  if 'ylabel' not in _kw:
@@ -1317,21 +1341,20 @@ def plotslice(length: float, dx: float | None = None, pa: float = 0,
1317
1341
  if 'xlim' not in _kw:
1318
1342
  _kw['xlim'] = [r.min(), r.max()]
1319
1343
  _kw['samexy'] = False
1320
- pa2d = kwargs2PlotAxes2D(_kw)
1344
+ set_rcparams()
1345
+ if fig is None:
1346
+ fig = plt.figure()
1347
+ if ax is None:
1348
+ ax = fig.add_subplot(1, 1, 1)
1349
+ pa2 = kwargs2PlotAxes2D(_kw)
1321
1350
  ax.plot(r, z, **_kw)
1322
1351
  if d.sigma is not None:
1323
1352
  ax.plot(r, r * 0 + 3 * d.sigma, 'k--')
1324
- pa2d.set_xyaxes(ax)
1353
+ pa2.set_xyaxes(ax)
1325
1354
  if getfigax:
1326
1355
  return fig, ax
1327
- fig.tight_layout()
1328
- if savefig is not None:
1329
- s = {'fname': savefig} if type(savefig) is str else savefig
1330
- savefig0.update(s)
1331
- fig.savefig(**savefig0)
1332
- if show:
1333
- plt.show()
1334
- plt.close()
1356
+
1357
+ close_figure(fig, savefig, show)
1335
1358
 
1336
1359
 
1337
1360
  def plot3d(levels: list[float] = [3, 6, 12],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.0
3
+ Version: 1.8.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