plotastrodata 1.1.1__tar.gz → 1.1.2.post1__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 (20) hide show
  1. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/PKG-INFO +1 -1
  2. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/analysis_utils.py +62 -12
  4. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/fitting_utils.py +1 -1
  5. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/other_utils.py +1 -1
  6. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/PKG-INFO +1 -1
  7. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/LICENSE +0 -0
  8. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/README.md +0 -0
  9. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/const_utils.py +0 -0
  10. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/fft_utils.py +0 -0
  11. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/fits_utils.py +0 -0
  12. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/los_utils.py +0 -0
  13. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata/plot_utils.py +0 -0
  14. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/SOURCES.txt +0 -0
  15. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/dependency_links.txt +0 -0
  16. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/not-zip-safe +0 -0
  17. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/requires.txt +0 -0
  18. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/plotastrodata.egg-info/top_level.txt +0 -0
  19. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/setup.cfg +0 -0
  20. {plotastrodata-1.1.1 → plotastrodata-1.1.2.post1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: plotastrodata
3
- Version: 1.1.1
3
+ Version: 1.1.2.post1
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', UserWarning)
4
- __version__ = '1.1.1'
4
+ __version__ = '1.1.2-1'
@@ -8,6 +8,7 @@ from plotastrodata.other_utils import (coord2xy, rel2abs, estimate_rms, trim,
8
8
  Mfac, Mrot, dot2d, gaussian2d)
9
9
  from plotastrodata.fits_utils import FitsData, data2fits, Jy2K
10
10
  from plotastrodata import const_utils as cu
11
+ from plotastrodata.fitting_utils import PTEmceeCorner
11
12
 
12
13
 
13
14
  def to4dim(data: np.ndarray) -> np.ndarray:
@@ -308,17 +309,54 @@ class AstroData():
308
309
  bmin_new = 1 / np.sqrt(alpha + Det)
309
310
  self.beam = np.array([bmaj_new, bmin_new, bpa_new])
310
311
 
311
- def histogram(self, **kwargs) -> tuple:
312
- """Output histogram of self.data using numpy.histogram. This method can take the arguments of numpy.histogram.
312
+ def fit2d(self, model: object, bounds: np.ndarray, progressbar: bool = False,
313
+ kwargs_fit: dict = {}, kwargs_plotcorner: dict = {},
314
+ chan: int | None = None):
315
+ """Fit a given 2D model function to self.data.
316
+
317
+ Args:
318
+ model (function): The model function in the form of f(par, x, y).
319
+ bounds (np.ndarray): bounds for fitting_utils.PTEmceeCorner.
320
+ progressbar (bool, optional): progressbar for fitting_utils.PTEmceeCorner. Defaults to False.
321
+ kwargs_fit (dict, optional): Arguments for fitting_utils.PTEmceeCorner.fit.
322
+ kwargs_plotcorner (dict, optional): Arguments for fitting_utils.PTEmceeCorner.plotcorner.
323
+ chan (int, optional): The channel number where the 2D model is fitted. Defaults to None.
313
324
 
314
325
  Returns:
315
- tuple: (bins, histogram)
326
+ dict: The parameter sets (popt, plow, pmid, and phigh), the best 2D model array (model), and the residual from the model (residual).
316
327
  """
317
- hist, hbin = np.histogram(self.data, **kwargs)
318
- hbin = (hbin[:-1] + hbin[1:]) / 2
319
- return hbin, hist
320
-
321
- def gaussfit2d(self, chan: int = None):
328
+ d = self.data if chan is None else self.data[chan]
329
+ x, y = np.meshgrid(self.x, self.y)
330
+ if None not in self.beam:
331
+ dx = self.x[1] - self.x[0]
332
+ dy = self.y[1] - self.y[0]
333
+ Omega = np.pi * self.beam[0] * self.beam[1] / 4 / np.log(2)
334
+ pixelperbeam = Omega / np.abs(dx * dy)
335
+ else:
336
+ pixelperbeam = 1.
337
+
338
+ def logl(p):
339
+ rss = np.nansum((model(p, x, y) - d)**2)
340
+ return -0.5 * rss / self.sigma**2 / pixelperbeam
341
+
342
+ mcmc = PTEmceeCorner(bounds=bounds, logl=logl, progressbar=progressbar)
343
+ kwargs_fit0 = {}
344
+ kwargs_fit0.update(kwargs_fit)
345
+ mcmc.fit(**kwargs_fit0)
346
+ kwargs_plotcorner0 = {'show': False, 'savefig': None}
347
+ kwargs_plotcorner0.update(kwargs_plotcorner)
348
+ if kwargs_plotcorner0['show'] or kwargs_plotcorner0['savefig'] is not None:
349
+ mcmc.plotcorner(**kwargs_plotcorner0)
350
+ popt = mcmc.popt
351
+ plow = mcmc.plow
352
+ pmid = mcmc.pmid
353
+ phigh = mcmc.phigh
354
+ modelopt = model(popt, x, y)
355
+ residual = d - modelopt
356
+ return {'popt': popt, 'plow': plow, 'pmid': pmid, 'phigh': phigh,
357
+ 'model': modelopt, 'residual': residual}
358
+
359
+ def gaussfit2d(self, chan: int | None = None):
322
360
  """Fit a 2D Gaussian function to self.data.
323
361
 
324
362
  Args:
@@ -330,14 +368,16 @@ class AstroData():
330
368
  d = self.data if chan is None else self.data[chan]
331
369
  x = self.x
332
370
  y = self.y
333
- p0 = (np.max(d), np.median(x), np.median(y), 1, 1, 0)
371
+ ds = np.min([np.abs(x[1] - x[0]), np.abs(y[1] - y[0])])
372
+ p0 = (np.max(d), np.median(x), np.median(y), 5 * ds, 5 * ds, 0)
334
373
  amax = np.max(np.abs(d))
335
374
  xmin = np.min(x)
336
375
  xmax = np.max(x)
337
376
  ymin = np.min(y)
338
377
  ymax = np.max(y)
339
- bounds = [[-amax, xmin, ymin, np.abs(x[1] - x[0]), np.abs(y[1] - y[0]), -90],
340
- [amax, xmax, ymax, xmax - xmin, ymax - ymin, 90]]
378
+ smax = np.max([xmax - xmin, ymax - ymin])
379
+ bounds = [[-amax, xmin, ymin, ds, ds, -90],
380
+ [amax, xmax, ymax, smax, smax, 90]]
341
381
  x, y = np.meshgrid(x, y)
342
382
  popt, pcov = curve_fit(gaussian2d, (x.ravel(), y.ravel()), d.ravel(),
343
383
  p0=p0, bounds=bounds)
@@ -345,6 +385,16 @@ class AstroData():
345
385
  residual = d - model
346
386
  return {'popt': popt, 'pcov': pcov, 'model': model, 'residual': residual}
347
387
 
388
+ def histogram(self, **kwargs) -> tuple:
389
+ """Output histogram of self.data using numpy.histogram. This method can take the arguments of numpy.histogram.
390
+
391
+ Returns:
392
+ tuple: (bins, histogram)
393
+ """
394
+ hist, hbin = np.histogram(self.data, **kwargs)
395
+ hbin = (hbin[:-1] + hbin[1:]) / 2
396
+ return hbin, hist
397
+
348
398
  def mask(self, dataformask: np.ndarray | None = None,
349
399
  includepix: list[float, float] = [],
350
400
  excludepix: list[float, float] = []):
@@ -690,7 +740,7 @@ class AstroFrame():
690
740
  x=grid[0], y=grid[1], v=grid[2],
691
741
  xlim=self.xlim, ylim=self.ylim,
692
742
  vlim=self.vlim, pv=self.pv)
693
- if grid[2] is not None and grid[2][1] < grid[2][0]:
743
+ if grid[2] is not None and len(grid[2]) > 1 and grid[2][1] < grid[2][0]:
694
744
  d.data[i], grid[2] = d.data[i][::-1], grid[2][::-1]
695
745
  print('Inverted velocity.')
696
746
  d.v = grid[2]
@@ -135,7 +135,7 @@ class PTEmceeCorner():
135
135
 
136
136
  def plotcorner(self, show: bool = False,
137
137
  savefig: str | None = None, labels: list[float] | None = None,
138
- cornerrange: list[float] = None) -> None:
138
+ cornerrange: list[float] | None = None) -> None:
139
139
  """Make the corner plot from self.samples.
140
140
 
141
141
  Args:
@@ -419,6 +419,6 @@ def gaussian2d(xy: np.ndarray,
419
419
  Returns:
420
420
  g (np.ndarray): 2D numpy array.
421
421
  """
422
- s, t = dot2d(Mrot(pa), [xy[1] - yo, xy[0] - xo])
422
+ s, t = dot2d(Mrot(-pa), [xy[1] - yo, xy[0] - xo])
423
423
  g = amplitude * np.exp2(-4 * ((s / fwhm_major)**2 + (t / fwhm_minor)**2))
424
424
  return g
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: plotastrodata
3
- Version: 1.1.1
3
+ Version: 1.1.2.post1
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