plotastrodata 1.8.1__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.1/plotastrodata.egg-info → plotastrodata-1.8.2}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/noise_utils.py +16 -16
  4. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/plot_utils.py +49 -51
  5. {plotastrodata-1.8.1 → plotastrodata-1.8.2/plotastrodata.egg-info}/PKG-INFO +1 -1
  6. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/LICENSE +0 -0
  7. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/MANIFEST.in +0 -0
  8. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/README.md +0 -0
  9. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/analysis_utils.py +0 -0
  10. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/const_utils.py +0 -0
  11. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/coord_utils.py +0 -0
  12. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/ext_utils.py +0 -0
  13. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/fft_utils.py +0 -0
  14. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/fits_utils.py +0 -0
  15. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/fitting_utils.py +0 -0
  16. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/los_utils.py +0 -0
  17. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/matrix_utils.py +0 -0
  18. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.1 → plotastrodata-1.8.2}/setup.cfg +0 -0
  25. {plotastrodata-1.8.1 → 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.1
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.1'
4
+ __version__ = '1.8.2'
@@ -101,23 +101,23 @@ def select_noise(data: np.ndarray, sigma: str) -> np.ndarray:
101
101
 
102
102
 
103
103
  class Noise:
104
- def __init__(self, data: np.ndarray, sigma: str):
105
- """This class holds the data selected as noise, histogram, and best-fit function.
106
- The following methods are acceptable for data selection. Multiple options are possible.
107
- 'edge': use data[0] and data[-1].
108
- 'out': exclude inner 60% about axes=-2 and -1.
109
- 'neg': use only negative values.
110
- 'iter': exclude outliers.
111
- The following methods are acceptable for noise estimation. Only single option is possible.
112
- 'med': calculate rms from the median of data^2 assuming Gaussian.
113
- 'hist': fit histgram with Gaussian.
114
- 'hist-pbcor': fit histgram with PB-corrected Gaussian.
115
- '(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.
116
115
 
117
- Args:
118
- data (np.ndarray): Original data array.
119
- sigma (str): Methods above, like 'edge,neg,hist-pbcor'.
120
- """
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):
121
121
  self.data = select_noise(data, sigma)
122
122
  self.sigma = sigma
123
123
  self.m0 = np.mean(self.data)
@@ -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,7 +1195,6 @@ 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
1198
  nrows: int = 0, ncols: int = 1,
1174
1199
  fig: object | None = None,
1175
1200
  ax: object | None = None,
@@ -1177,7 +1202,7 @@ def plotprofile(coords: list[str] | str = [],
1177
1202
  savefig: dict | str | None = None,
1178
1203
  show: bool = False,
1179
1204
  **kwargs) -> tuple[object, object]:
1180
- """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.
1181
1206
 
1182
1207
  Args:
1183
1208
  coords (list, optional): Coordinates. Defaults to [].
@@ -1191,8 +1216,6 @@ def plotprofile(coords: list[str] | str = [],
1191
1216
  gauss_kwargs (dict, optional): Kwargs for Axes.plot. Defaults to {}.
1192
1217
  title (list, optional): For each plot. Defaults to None.
1193
1218
  text (list, optional): For each plot. Defaults to None.
1194
- dist (float, optional): Change x and y in arcsec to au. Defaults to 1..
1195
- vsys (float, optional): Each channel shows v-vsys. Defaults to 0..
1196
1219
  nrows (int, optional): Used for channel maps. Defaults to 0.
1197
1220
  ncols (int, optional): Used for channel maps. Defaults to 1.
1198
1221
  fig (optional): External plt.figure(). Defaults to None.
@@ -1208,13 +1231,10 @@ def plotprofile(coords: list[str] | str = [],
1208
1231
  _kw.update(kwargs)
1209
1232
  _kwgauss = {'drawstyle': 'default', 'color': 'g'}
1210
1233
  _kwgauss.update(gauss_kwargs)
1211
- savefig0 = {'bbox_inches': 'tight', 'transparent': True}
1212
1234
  if type(coords) is str:
1213
1235
  coords = [coords]
1214
- vmin, vmax = _kw['xlim'] if 'xlim' in _kw else [-1e10, 1e10]
1215
- f = AstroFrame(dist=dist, vsys=vsys, vmin=vmin, vmax=vmax)
1236
+ f = kwargs2AstroFrame(_kw)
1216
1237
  d = kwargs2AstroData(_kw)
1217
- Tb = d.Tb
1218
1238
  f.read(d)
1219
1239
  d.binning([width, 1, 1])
1220
1240
  v, prof, gfitres = d.profile(coords=coords, xlist=xlist, ylist=ylist,
@@ -1223,7 +1243,7 @@ def plotprofile(coords: list[str] | str = [],
1223
1243
  nprof = len(prof)
1224
1244
  if 'ylabel' in _kw:
1225
1245
  ylabel = _kw['ylabel']
1226
- elif Tb:
1246
+ elif d.Tb:
1227
1247
  ylabel = r'$T_b$ (K)'
1228
1248
  elif flux:
1229
1249
  ylabel = 'Flux (Jy)'
@@ -1249,7 +1269,7 @@ def plotprofile(coords: list[str] | str = [],
1249
1269
  if 'xlim' not in _kw:
1250
1270
  _kw['xlim'] = [v.min(), v.max()]
1251
1271
  _kw['samexy'] = False
1252
- pa2d = kwargs2PlotAxes2D(_kw)
1272
+ pa2 = kwargs2PlotAxes2D(_kw)
1253
1273
  for i in range(nprof):
1254
1274
  sharex = None if i < nrows - 1 else ax[i - 1]
1255
1275
  ax[i] = fig.add_subplot(nrows, ncols, i + 1, sharex=sharex)
@@ -1258,7 +1278,7 @@ def plotprofile(coords: list[str] | str = [],
1258
1278
  ax[i].plot(v, prof[i], **_kw)
1259
1279
  ax[i].hlines([0], v.min(), v.max(), linestyle='dashed', color='k')
1260
1280
  ax[i].set_ylabel(ylabel[i])
1261
- pa2d.set_xyaxes(ax[i])
1281
+ pa2.set_xyaxes(ax[i])
1262
1282
  if text is not None:
1263
1283
  ax[i].text(**text[i])
1264
1284
  if title is not None:
@@ -1269,35 +1289,22 @@ def plotprofile(coords: list[str] | str = [],
1269
1289
  plt.setp(ax[i].get_xticklabels(), visible=False)
1270
1290
  if getfigax:
1271
1291
  return fig, ax
1272
- fig.tight_layout()
1273
- if savefig is not None:
1274
- s = {'fname': savefig} if type(savefig) is str else savefig
1275
- savefig0.update(s)
1276
- fig.savefig(**savefig0)
1277
- if show:
1278
- plt.show()
1279
- plt.close()
1292
+
1293
+ close_figure(fig, savefig, show)
1280
1294
 
1281
1295
 
1282
1296
  def plotslice(length: float, dx: float | None = None, pa: float = 0,
1283
- dist: float = 1, xoff: float = 0, yoff: float = 0,
1284
- xflip: bool = True, yflip: bool = False,
1285
1297
  txtfile: str | None = None,
1286
1298
  fig: object | None = None, ax: object | None = None,
1287
1299
  getfigax: bool = False,
1288
1300
  savefig: str | dict | None = None, show: bool = False,
1289
- **kwargs) -> None:
1290
- """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.
1291
1303
 
1292
1304
  Args:
1293
1305
  length (float): Slice length.
1294
1306
  dx (float, optional): Grid increment. Defaults to None.
1295
1307
  pa (float, optional): Degree. Position angle. Defaults to 0.
1296
- dist (float, optional): For AstroFrame. Defaults to 1.
1297
- xoff (float, optional): For AstroFrame. Defaults to 0.
1298
- yoff (float, optional): For AstroFrame. Defaults to 0.
1299
- xflip (bool, optional): For AstroFrame. Defaults to True.
1300
- yflip (bool, optional): For AstroFrame. Defaults to False.
1301
1308
  txtfile (str, optional): File name for numpy.savetxt(). Defaults to None.
1302
1309
  fig (optional): External plt.figure(). Defaults to None.
1303
1310
  ax (optional): External fig.add_subplot(). Defaults to None.
@@ -1310,31 +1317,23 @@ def plotslice(length: float, dx: float | None = None, pa: float = 0,
1310
1317
  """
1311
1318
  _kw = {'linestyle': '-', 'marker': 'o'}
1312
1319
  _kw.update(kwargs)
1313
- savefig0 = {'bbox_inches': 'tight', 'transparent': True}
1314
- center = _kw['center'] if 'center' in _kw else None
1315
- f = AstroFrame(rmax=length / 2, dist=dist, xoff=xoff, yoff=yoff,
1316
- xflip=xflip, yflip=yflip, center=center)
1320
+ _kw['rmax'] = length / 2
1321
+ f = kwargs2AstroFrame(_kw)
1317
1322
  d = kwargs2AstroData(_kw)
1318
- Tb = d.Tb
1319
1323
  f.read(d)
1320
1324
  if np.ndim(d.data) > 2:
1321
1325
  print('Only 2D map is supported.')
1322
1326
  return
1323
1327
 
1324
1328
  r, z = d.slice(length=length, pa=pa, dx=dx)
1325
- xunit = 'arcsec' if dist == 1 else 'au'
1326
- yunit = 'K' if Tb else d.bunit
1327
- 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'
1328
1332
 
1329
1333
  if txtfile is not None:
1330
1334
  np.savetxt(txtfile, np.c_[r, z],
1331
1335
  header=f'x ({xunit}), {yquantity} ({yunit}); '
1332
1336
  + f'positive x is pa={pa:.2f} deg.')
1333
- set_rcparams()
1334
- if fig is None:
1335
- fig = plt.figure()
1336
- if ax is None:
1337
- ax = fig.add_subplot(1, 1, 1)
1338
1337
  if 'xlabel' not in _kw:
1339
1338
  _kw['xlabel'] = f'Offset ({xunit})'
1340
1339
  if 'ylabel' not in _kw:
@@ -1342,21 +1341,20 @@ def plotslice(length: float, dx: float | None = None, pa: float = 0,
1342
1341
  if 'xlim' not in _kw:
1343
1342
  _kw['xlim'] = [r.min(), r.max()]
1344
1343
  _kw['samexy'] = False
1345
- 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)
1346
1350
  ax.plot(r, z, **_kw)
1347
1351
  if d.sigma is not None:
1348
1352
  ax.plot(r, r * 0 + 3 * d.sigma, 'k--')
1349
- pa2d.set_xyaxes(ax)
1353
+ pa2.set_xyaxes(ax)
1350
1354
  if getfigax:
1351
1355
  return fig, ax
1352
- fig.tight_layout()
1353
- if savefig is not None:
1354
- s = {'fname': savefig} if type(savefig) is str else savefig
1355
- savefig0.update(s)
1356
- fig.savefig(**savefig0)
1357
- if show:
1358
- plt.show()
1359
- plt.close()
1356
+
1357
+ close_figure(fig, savefig, show)
1360
1358
 
1361
1359
 
1362
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.1
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