plotastrodata package
Submodules
plotastrodata.analysis_utils module
- class plotastrodata.analysis_utils.AstroData(data: ndarray | None = None, x: ndarray | None = None, y: ndarray | None = None, v: ndarray | None = None, beam: ndarray | tuple[None] = (None, None, None), fitsimage: str | None = None, Tb: bool = False, sigma: str | float | None = 'hist', center: str = 'common', restfreq: float | None = None, cfactor: float = 1, pvpa: float | None = None, pv: bool = False, bunit: str = '')[source]
Bases:
objectData to be processed and parameters for processing the data.
- Parameters:
data (np.ndarray, optional) – 2D or 3D array. Defaults to None.
x (np.ndarray, optional) – 1D array. Defaults to None.
y (np.ndarray, optional) – 1D array. Defaults to None.
v (np.ndarray, optional) – 1D array. Defaults to None.
beam (np.ndarray, optional) – [bmaj, bmin, bpa]. Defaults ot [None, None, None].
fitsimage (str, optional) – Input fits name. Defaults to None.
Tb (bool, optional) – True means the data array is brightness temperature. Defaults to False.
sigma (float or str, optional) – Noise level or method for measuring it. Defaults to ‘hist’.
center (str, optional) – Text coordinates. ‘common’ means initialized value. Defaults to ‘common’.
restfreq (float, optional) – Used for velocity and brightness temperature. Defaults to None.
cfactor (float, optional) – The data array is multiplied by cfactor. Defaults to 1.
pvpa (float, optional) – Position angle of the PV cut. Defaults to None.
pv (bool, optional) – True means the data array is a position-velocity diagram. Defaults to False.
bunit (str, optional) – The unit of the data array. Defaults to ‘’.
- Tb: bool = False
- beam: ndarray | tuple[None] = (None, None, None)
- binning(width: list[int, int, int] = [1, 1, 1])[source]
Binning up neighboring pixels in the v, y, and x domain.
- Parameters:
width (list, optional) – Number of channels, y-pixels, and x-pixels for binning. Defaults to [1, 1, 1].
- bunit: str = ''
- center: str = 'common'
- centering(includexy: bool = True, includev: bool = False, **kwargs)[source]
Spatial regridding to set the center at (x,y,v)=(0,0,0).
- Parameters:
includexy (bool, optional) – Centering in the x and y directions at each channel. Defaults to True.
includev (bool, optional) – Centering in the v direction at each position. Defaults to False.
- cfactor: float = 1
- data: ndarray | None = None
- deproject(pa: float = 0, incl: float = 0, **kwargs)[source]
Exapnd by a factor of 1/cos(incl) in the direction of pa+90 deg.
- Parameters:
pa (float, optional) – Position angle in the unit of degree. Defaults to 0.
incl (float, optional) – Inclination angle in the unit of degree. Defaults to 0.
- fitsimage: str | None = None
- histogram(**kwargs) tuple[source]
Output histogram of self.data using numpy.histogram. This method can take the arguments of numpy.histogram.
- Returns:
(bins, histogram)
- Return type:
tuple
- mask(dataformask: ndarray | None = None, includepix: list[float, float] = [], excludepix: list[float, float] = [])[source]
Mask self.data using a 2D or 3D array of dataformask.
- Parameters:
dataformask (np.ndarray, optional) – 2D or 3D array is used for specifying the mask.
includepix (list, optional) – Data in this range survivies. Defaults to [].
excludepix (list, optional) – Data in this range is masked. Defaults to [].
- profile(coords: list[str] = [], xlist: list[float] = [], ylist: list[float] = [], ellipse: list[float, float, float] | None = None, ninterp: int = 1, flux: bool = False, gaussfit: bool = False) tuple[ndarray, ndarray, dict][source]
Get a list of line profiles at given spatial coordinates.
- Parameters:
coords (list, optional) – Text coordinates. Defaults to [].
xlist (list, optional) – Offset from center. Defaults to [].
ylist (list, optional) – Offset from center. Defaults to [].
ellipse (list, optional) – [major, minor, pa]. For average. Defaults to None.
ninterp (int, optional) – Number of points for interpolation. Defaults to 1.
flux (bool, optional) – Jy/beam to Jy. Defaults to False.
gaussfit (bool, optional) – Fit the profiles. Defaults to False.
- Returns:
(v, list of profiles, result of Gaussian fit)
- Return type:
tuple
- pv: bool = False
- pvpa: float | None = None
- restfreq: float | None = None
- rotate(pa: float = 0, **kwargs)[source]
Counter clockwise rotation with respect to the center.
- Parameters:
pa (float, optional) – Position angle in the unit of degree. Defaults to 0.
- sigma: str | float | None = 'hist'
- slice(length: float = 0, pa: float = 0, dx: float | None = None, **kwargs) ndarray[source]
Get 1D slice with given a length and a position-angle.
- Parameters:
length (float, optional) – Slice line length. Defaults to 0.
pa (float, optional) – Position angle in the unit of degree. Defaults to 0.
dx (float, optional) – Grid increment. Defaults to None.
- Returns:
[x, data]. If self.data is 3D, the output data are in the shape of (len(v), len(x)).
- Return type:
np.ndarray
- todict() dict[source]
Output the attributes as a dictionary that can be input to PlotAstroData.
- Returns:
Output that can be input to PlotAstroData.
- Return type:
dict
- v: ndarray | None = None
- x: ndarray | None = None
- y: ndarray | None = None
- class plotastrodata.analysis_utils.AstroFrame(rmax: float = 10000000000.0, xmax: float | None = None, xmin: float | None = None, ymax: float | None = None, ymin: float | None = None, dist: float = 1, center: str | None = None, fitsimage: str | None = None, xoff: float = 0, yoff: float = 0, vsys: float = 0, vmin: float = -1e+20, vmax: float = 1e+20, xflip: bool = True, yflip: bool = False, swapxy: bool = False, pv: bool = False, quadrants: str | None = None)[source]
Bases:
objectParameter set to limit and reshape the data in the AstroData format.
- Parameters:
vmin (float, optional) – Velocity at the upper left. Defaults to -1e10.
vmax (float, optional) – Velocity at the lower bottom. Defaults to 1e10.
vsys (float, optional) – Each channel shows v-vsys. Defaults to 0..
center (str, optional) – Central coordinate like ‘12h34m56.7s 12d34m56.7s’. Defaults to None.
fitsimage (str, optional) – Fits to get center. Defaults to None.
rmax (float, optional) – The x range is [-rmax, rmax]. The y range is [-rmax, ramx]. Defaults to 1e10.
xmax (float, optional) – The x range is [xmin, xmax]. Defaults to None.
xmin (float, optional) – The x range is [xmin, xmax]. Defaults to None.
ymax (float, optional) – The y range is [ymin, ymax]. Defaults to None.
ymin (float, optional) – The y range is [ymin, ymax]. Defaults to None.
dist (float, optional) – Change x and y in arcsec to au. Defaults to 1..
xoff (float, optional) – Map center relative to the center. Defaults to 0.
yoff (float, optional) – Map center relative to the center. Defaults to 0.
xflip (bool, optional) – True means left is positive x. Defaults to True.
yflip (bool, optional) – True means bottom is positive y. Defaults to False.
swapxy (bool, optional) – True means x and y are swapped. Defaults to False.
pv (bool, optional) – Mode for PV diagram. Defaults to False.
quadrants (str, optional) – ‘13’ or ‘24’. Quadrants to take mean. None means not taking mean. Defaults to None.
- center: str | None = None
- dist: float = 1
- fitsimage: str | None = None
- pos2xy(poslist: list[str | list[float, float]] = []) ndarray[source]
Text or relative to absolute coordinates.
- Parameters:
poslist (list, optional) – Text coordinates or relative coordinates. Defaults to [].
- Returns:
absolute coordinates.
- Return type:
np.ndarray
- pv: bool = False
- quadrants: str | None = None
- read(d: AstroData, xskip: int = 1, yskip: int = 1)[source]
Get data, grid, sigma, beam, and bunit from AstroData, which is a part of the input of add_color, add_contour, add_segment, and add_rgb.
- Parameters:
d (AstroData) – Dataclass for the add_* input.
xskip (int) – Spatial pixel skip. Defaults to 1.
yskip (int) – Spatial pixel skip. Defaults to 1.
- rmax: float = 10000000000.0
- swapxy: bool = False
- vmax: float = 1e+20
- vmin: float = -1e+20
- vsys: float = 0
- xflip: bool = True
- xmax: float | None = None
- xmin: float | None = None
- xoff: float = 0
- yflip: bool = False
- ymax: float | None = None
- ymin: float | None = None
- yoff: float = 0
- plotastrodata.analysis_utils.filled2d(data: ndarray, x: ndarray, y: ndarray, n: int = 1, **kwargs) tuple[ndarray, ndarray, ndarray][source]
Fill 2D data, 1D x, and 1D y by a factor of n using RGI.
- Parameters:
data (np.ndarray) – 2D or 3D array.
x (np.ndarray) – 1D array.
y (np.ndarray) – 1D array.
n (int, optional) – How many times more the new grid is. Defaults to 1.
- Returns:
The interpolated (data, x, y).
- Return type:
tuple
- plotastrodata.analysis_utils.quadrantmean(data: ndarray, x: ndarray, y: ndarray, quadrants: str = '13') tuple[ndarray, ndarray, ndarray][source]
Take mean between 1st and 3rd (or 2nd and 4th) quadrants.
- Parameters:
data (np.ndarray) – 2D array.
x (np.ndarray) – 1D array. First coordinate.
y (np.ndarray) – 1D array. Second coordinate.
quadrants (str, optional) – ‘13’ or ‘24’. Defaults to ‘13’.
- Returns:
Averaged (data, x, y).
- Return type:
tuple
plotastrodata.const_utils module
plotastrodata.coord_utils module
- plotastrodata.coord_utils.abs2rel(xabs: float, yabs: float, x: ndarray, y: ndarray) ndarray[source]
Transform absolute coordinates to relative ones.
- Parameters:
xabs (float) – In the same frame of x.
yabs (float) – In the same frame of y.
x (np.ndarray) – [x0, x0+dx, x0+2dx, …]
y (np.ndarray) – [y0, y0+dy, y0+2dy, …]
- Returns:
[xrel, yrel]. Each has the input’s shape. 0 <= xrel, yrel <= 1. 0 and 1 correspond to x[0] and x[-1], respectively.
- Return type:
ndarray
- plotastrodata.coord_utils.coord2xy(coords: str | list, coordorg: str = '00h00m00s 00d00m00s', frame: str | None = None, frameorg: str | None = None) ndarray[source]
Transform R.A.-Dec. to relative (deg, deg).
- Parameters:
coords (str, list) – something like ‘01h23m45.6s 01d23m45.6s’. The input can be a list of str in an arbitrary shape.
coordorg (str, optional) – something like ‘01h23m45.6s 01d23m45.6s’. The origin of the relative (deg, deg). Defaults to ‘00h00m00s 00d00m00s’.
frame (str, optional) – coordinate frame. Defaults to None.
frameorg (str, optional) – coordinate frame of the origin. Defaults to None.
- Returns:
[(array of) alphas, (array of) deltas] in degree. The shape of alphas and deltas is the input shape. With a single input, the output is [alpha0, delta0].
- Return type:
np.ndarray
- plotastrodata.coord_utils.get_hmdm(coord: str, mode: str) str[source]
Pick up the coordinate string before the second part from a hsmdms string.
- Parameters:
coord (str) – hmsdms string.
mode (str) – ‘ra’ or ‘dec’
- Returns:
The hm or dm string with the units.
- Return type:
str
- plotastrodata.coord_utils.get_min(coord: str, mode: str) str[source]
Pick up the minute number from a hmsdms string.
- Parameters:
coord (str) – hmsdms string.
mode (str) – ‘ra’ or ‘dec’
- Returns:
The minute number as a string without the unit.
- Return type:
str
- plotastrodata.coord_utils.get_sec(coord: str, mode: str) str[source]
Pick up the second number from a hmsdms string.
- Parameters:
coord (str) – hmsdms string.
mode (str) – ‘ra’ or ‘dec’
- Returns:
The second number as a string without the unit.
- Return type:
str
- plotastrodata.coord_utils.rel2abs(xrel: float, yrel: float, x: ndarray, y: ndarray) ndarray[source]
Transform relative coordinates to absolute ones.
- Parameters:
xrel (float) – 0 <= xrel <= 1. 0 and 1 correspond to x[0] and x[-1], respectively. Arbitrary shape.
yrel (float) – same as xrel.
x (np.ndarray) – [x0, x0+dx, x0+2dx, …]
y (np.ndarray) – [y0, y0+dy, y0+2dy, …]
- Returns:
[xabs, yabs]. Each has the input’s shape.
- Return type:
np.ndarray
- plotastrodata.coord_utils.xy2coord(xy: list, coordorg: str = '00h00m00s 00d00m00s', frame: str | None = None, frameorg: str | None = None) str | ndarray[source]
Transform relative (deg, deg) to R.A.-Dec.
- Parameters:
xy (list) – [(array of) alphas, (array of) deltas] in degree. alphas and deltas can have an arbitrary shape.
coordorg (str) – something like ‘01h23m45.6s 01d23m45.6s’. The origin of the relative (deg, deg). Defaults to ‘00h00m00s 00d00m00s’.
frame (str) – coordinate frame. Defaults to None.
frameorg (str) – coordinate frame of the origin. Defaults to None.
- Returns:
something like ‘01h23m45.6s 01d23m45.6s’. With multiple inputs, the output has the input shape.
- Return type:
str
plotastrodata.ext_utils module
- plotastrodata.ext_utils.BnuT(T: float = 30, nu: float = 230000000000.0) float[source]
Planck function.
- Parameters:
T (float, optional) – Temperature in the unit of K. Defaults to 30.
nu (float, optional) – Frequency in the unit of Hz. Defaults to 230e9.
- Returns:
Planck function in the SI units.
- Return type:
float
- plotastrodata.ext_utils.JnuT(T: float = 30, nu: float = 230000000000.0) float[source]
Brightness templerature from the Planck function.
- Parameters:
T (float, optional) – Temperature in the unit of K. Defaults to 30.
nu (float, optional) – Frequency in the unit of Hz. Defaults to 230e9.
- Returns:
Brightness temperature of Planck function in the unit of K.
- Return type:
float
plotastrodata.fft_utils module
- plotastrodata.fft_utils.fftcentering(f: ndarray, x: ndarray | None = None, xcenter: float = 0) tuple[ndarray, ndarray][source]
FFT with the phase referring to a specific point.
- Parameters:
f (np.ndarray) – 1D array for FFT.
x (np.ndarray, optional) – 1D array. The spatial coordinate. Defaults to None.
xcenter (float, optional) – x of phase reference. Defaults to 0.
- Returns:
(F, u). F is FFT of f. u is a 1D array of the frequency coordinate.
- Return type:
tuple
- plotastrodata.fft_utils.fftcentering2(f: ndarray, x: ndarray | None = None, y: ndarray | None = None, xcenter: float = 0, ycenter: float = 0) tuple[ndarray, ndarray, ndarray][source]
FFT with the phase referring to a specific point.
- Parameters:
f (np.ndarray) – 2D array for FFT.
x (np.ndarray, optional) – 1D or 2D array. The first spatial coordinate. Defaults to None.
y (np.ndarray, optional) – 1D or 2D array. The second spatial coordinate. Defaults to None.
xcenter (float, optional) – x of phase reference. Defaults to 0.
ycenter (float, optional) – y of phase reference. Defaults to 0.
- Returns:
(F, u, v). F is FFT of f. u and v are 1D arrays of the frequency coordinates.
- Return type:
tuple
- plotastrodata.fft_utils.fftfits(fitsimage: str, center: str | None = None, lam: float = 1, xlim: list | None = None, ylim: list | None = None, savefig: dict | str | None = None, show: bool = False) tuple[ndarray, ndarray, ndarray][source]
FFT a fits image with the phase referring to a specific point.
- Parameters:
fitsimage (str) – Input fits name in the unit of Jy/pixel.
center (str, optional) – Text coordinate. Defaults to None.
lam (float, optional) – Return u * lam and v * lam. Defaults to 1.
xlim (list, optional) – Range of x for zero padding in arcsec.
ylim (list, optional) – Range of y for zero padding in arcsec.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- Returns:
(F, u, v). F is FFT of f in the unit of Jy. u and v are 1D arrays in the unit of lambda or meter if lam it not unity.
- Return type:
tuple
- plotastrodata.fft_utils.fftfitssample(fitsimage: str, center: str | None = None, index_u: ndarray | None = None, index_v: ndarray | None = None, xlim: list | None = None, ylim: list | None = None, getindex: bool = False, u_sample: ndarray | None = None, v_sample: ndarray | None = None) ndarray[source]
Find indicies or the visibilities on them from an image fits file.
- Parameters:
fitsimage (str) – Input fits name in the unit of Jy/pixel.
center (str, optional) – Text coordinate. Defaults to None.
index_u (np.ndarray, optional) – Indicies. Output from the getindex mode. Defaults to None.
index_v (np.ndarray, optional) – Indicies. Output from the getindex mode. Defaults to None.
xlim (list, optional) – Range of x for zero padding in arcsec.
ylim (list, optional) – Range of y for zero padding in arcsec.
getindex (bool, optional) – True outputs [index_u, index_v]. Defaults to False.
u_sample (np.ndarray, optional) – 1D array. Observed u. Defaults to None.
v_sample (np.ndarray, optional) – 1D array. Observed u. Defaults to None.
- Returns:
Array of indicies or sampled FFT.
- Return type:
np.ndarray
- plotastrodata.fft_utils.findindex(u: ndarray | None = None, v: ndarray | None = None, uobs: ndarray | None = None, vobs: ndarray | None = None) ndarray[source]
Find indicies of the observed visibility points.
- Parameters:
u (np.ndarray, optional) – 1D array. The first frequency coordinate. Defaults to None.
v (np.ndarray, optional) – 1D array. The second frequency cooridnate. Defaults to None.
uobs (np.ndarray, optional) – 1D array. Observed u. Defaults to None.
vobs (np.ndarray, optional) – 1D array. Observed v. Defaults to None.
- Returns:
Indicies or an array of indicies.
- Return type:
np.ndarray
- plotastrodata.fft_utils.ifftcentering(F: ndarray, u: ndarray | None = None, xcenter: float = 0, x0: float = None, outreal: bool = True) tuple[ndarray, ndarray][source]
inverse FFT with the phase referring to a specific point.
- Parameters:
F (np.ndarray) – 1D array. A result of FFT.
u (np.ndarray, optional) – 1D array. The frequency coordinate. Defaults to None.
xcenter (float, optional) – x of phase reference (used in fftcentering). Defaults to 0.
x0 (float, optional) – spatial coordinate of x[0]. Defaults to None.
outreal (bool, optional) – whether output only the real part. Defaults to True.
- Returns:
(f, x). f is iFFT of F. x is a 1D array of the spatial coordinate.
- Return type:
tuple
- plotastrodata.fft_utils.ifftcentering2(F: ndarray, u: ndarray | None = None, v: ndarray | None = None, xcenter: float = 0, ycenter: float = 0, x0: float | None = None, y0: float | None = None, outreal: bool = True) tuple[ndarray, ndarray, ndarray][source]
inverse FFT with the phase referring to a specific point.
- Parameters:
F (np.ndarray) – 2D array. A result of FFT.
u (np.ndarray, optional) – 1D or 2D array. The first frequency coordinate. Defaults to None.
v (np.ndarray, optional) – 1D or 2D array. The second frequency cooridnate. Defaults to None.
xcenter (float, optional) – x of phase reference (used in fftcentering2). Defaults to 0.
ycenter (float, optional) – y of phase reference (used in fftcentering2). Defaults to 0.
x0 (float, optional) – spatial coordinate of x[0]. Defaults to None.
y0 (float, optional) – spatial coordinate of y[0]. Defaults to None.
outreal (bool, optional) – whether output only the real part. Defaults to True.
- Returns:
(f, x, y). f is iFFT of F. x and y are 1D arrays of the spatial coordinates.
- Return type:
tuple
- plotastrodata.fft_utils.shiftphase(F: ndarray, u: ndarray, xoff: float = 0) ndarray[source]
Shift the phase of 1D FFT by xoff.
- Parameters:
F (np.ndarray) – 1D FFT.
u (np.ndarray) – 1D array. The first frequency coordinate.
xoff (float) – From old to new center. Defaults to 0.
- Returns:
phase-shifted FFT.
- Return type:
np.ndarray
- plotastrodata.fft_utils.shiftphase2(F: ndarray, u: ndarray, v: ndarray, xoff: float = 0, yoff: float = 0) ndarray[source]
Shift the phase of 2D FFT by (xoff, yoff).
- Parameters:
F (np.ndarray) – 2D FFT.
u (np.ndarray) – 1D or 2D array. The first frequency coordinate.
v (np.ndarray) – 1D or 2D array. The second frequency coordinate. Defaults to None.
xoff (float) – From old to new center. Defaults to 0.
yoff (float) – From old to new center. Defaults to 0.
- Returns:
phase-shifted FFT.
- Return type:
np.ndarray
- plotastrodata.fft_utils.zeropadding(f: ndarray, x: ndarray, y: ndarray, xlim: list, ylim: list) tuple[ndarray, ndarray, ndarray][source]
Pad an outer region with zero.
- Parameters:
f (np.ndarray) – Input 2D array.
x (np.ndarray) – 1D array.
y (np.ndarray) – 1D array.
xlim (list) – range of x after the zero padding.
ylim (list) – range of y after the zero padding.
- Returns:
(fnew, xnew, ynew). fnew is an 2D array and xnew and ynew are 1D arrays after the zero padding.
- Return type:
tuple
plotastrodata.fits_utils module
- class plotastrodata.fits_utils.FitsData(fitsimage: str)[source]
Bases:
objectFor practical treatment of data in a FITS file.
- Parameters:
fitsimage (str) – Input FITS file name.
- gen_beam(dist: float = 1.0) None[source]
Generate sef.bmaj, self.bmin, self.bpa from header[‘BMAJ’], etc.
- Parameters:
dist (float, optional) – bmaj and bmin are multiplied by dist. Defaults to 1..
- gen_data(Tb: bool = False, log: bool = False, drop: bool = True, restfreq: float = None) None[source]
Generate data, which may be brightness temperature.
- Parameters:
Tb (bool, optional) – True means the data are brightness temperatures. Defaults to False.
log (bool, optional) – True means the data are after taking the logarithm to the base 10. Defaults to False.
drop (bool, optional) – True means the data are after using np.squeeze. Defaults to True.
restfreq (float, optional) – Rest frequency for calculating the brightness temperature. Defaults to None.
- gen_grid(center: str | None = None, dist: float = 1.0, restfreq: float | None = None, vsys: float = 0.0, pv: bool = False) None[source]
Generate grids relative to the center and vsys.
- Parameters:
center (str, optional) – Center for the spatial grids. Defaults to None.
dist (float, optional) – The spatial grids are multiplied by dist. Defaults to 1..
restfreq (float, optional) – Rest frequency for converting the frequencies to velocities. Defaults to None.
vsys (float, optional) – The velocity is relative to vsys. Defaults to 0..
pv (bool, optional) – Mode for position-velocity diagram. Defaults to False.
- get_beam(dist: float = 1.0) ndarray[source]
Output the beam array of [bmaj, bmin, bpa].
- Parameters:
dist (float, optional) – bmaj and bmin are multiplied by dist. Defaults to 1..
- Returns:
[bmaj, bmin, bpa].
- Return type:
np.ndarray
- get_center() str[source]
Output the central coordinates as text.
- Returns:
The central coordinates.
- Return type:
str
- get_data(**kwargs) ndarray[source]
Output data. This method can take the arguments of gen_data().
- Returns:
data in the format of np.ndarray.
- Return type:
np.ndarray
- get_grid(**kwargs) tuple[ndarray, ndarray, ndarray][source]
Output the grids, [x, y, v]. This method can take the arguments of gen_grid().
- Returns:
(x, y, v).
- Return type:
tuple
- get_header(key: str | None = None) dict | float[source]
Output the entire header or a value when a key is given.
- Parameters:
key (str, optional) – Key name of the FITS header. Defaults to None.
- Returns:
The entire header or a value.
- Return type:
dict or float
- trim(rmax: float = 10000000000.0, xoff: float = 0.0, yoff: float = 0.0, vmin: float = -10000000000.0, vmax: float = 10000000000.0, pv: bool = False) None[source]
Trim the data and grids. The data range will be from xoff - rmax, yoff - rmax, vmin to xoff + rmax, yoff + rmax, vmax.
- Parameters:
rmax (float, optional) – Defaults to 1e10.
xoff (float, optional) – Defaults to 0..
yoff (float, optional) – Defaults to 0..
vmin (float, optional) – Defaults to -1e10.
vmax (float, optional) – Defaults to 1e10.
pv (bool, optional) – Mode for position-velocity diagram. Defaults to False.
- plotastrodata.fits_utils.Jy2K(header=None, bmaj: float | None = None, bmin: float | None = None, restfreq: float | None = None) float[source]
Calculate a conversion factor in the unit of K/Jy.
- Parameters:
header (optional) – astropy.io.fits.open(‘a.fits’)[0].header. Defaults to None.
bmaj (float, optional) – beam major axis in degree. Defaults to None.
bmin (float, optional) – beam minor axis in degree. Defaults to None.
freq (float, optional) – rest frequency in Hz. Defaults to None.
- Returns:
the conversion factor in the unit of K/Jy.
- Return type:
float
- plotastrodata.fits_utils.data2fits(d: ndarray, h: dict = {}, templatefits: str | None = None, fitsimage: str = 'test') None[source]
Make a fits file from a N-D array.
- Parameters:
d (np.ndarray) – N-D array.
h (dict, optional) – Additional FITS header. Defaults to {}.
templatefits (str, optional) – FITS file whose header is used as a temperate. Defaults to None.
fitsimage (str, optional) – Output filename, with or without ‘.fits’. Defaults to ‘test’.
- plotastrodata.fits_utils.fits2data(fitsimage: str, Tb: bool = False, log: bool = False, dist: float = 1.0, sigma: str | None = None, restfreq: float | None = None, center: str | None = None, vsys: float = 0.0, pv: bool = False, **kwargs) tuple[ndarray, tuple[ndarray, ndarray, ndarray], tuple[float, float, float], float, float][source]
Extract data from a fits file. kwargs are arguments of FitsData.trim().
- Parameters:
fitsimage (str) – Input fits name.
Tb (bool, optional) – True means ouput data are brightness temperature. Defaults to False.
log (bool, optional) – True means output data are logarhismic. Defaults to False.
dist (float, optional) – Change x and y in arcsec to au. Defaults to 1..
sigma (str, optional) – Noise level or method for measuring it. Defaults to None.
restfreq (float, optional) – Used for velocity and brightness temperature. Defaults to None.
center (str, optional) – Text coordinates. Defaults to None.
vsys (float, optional) – In the unit of km/s. Defaults to 0.
pv (bool, optional) – True means PV fits file. Defaults to False.
- Returns:
(data, (x, y, v), (bmaj, bmin, bpa), bunit, rms)
- Return type:
tuple
plotastrodata.fitting_utils module
- class plotastrodata.fitting_utils.EmceeCorner(bounds: ndarray, logl: object | None = None, model: object | None = None, xdata: ndarray | None = None, ydata: ndarray | None = None, sigma: ndarray = 1, progressbar: bool = False, percent: list = [16, 84])[source]
Bases:
object- fit(nwalkersperdim: int = 2, ntemps: int = 1, nsteps: int = 1000, nburnin: int = 500, ntry: int = 1, pos0: ndarray | None = None, savechain: str | None = None, ncores: int = 1, grcheck: bool = False, pt: bool = False) None[source]
Perform a Markov Chain Monte Carlo (MCMC) fitting process using the ptemcee library, which is a parallel tempering version of the emcee package, and make a corner plot of the samples using the corner package.
- Parameters:
nwalkersperdim (int, optional) – Number of walkers per dimension. Defaults to 2.
ntemps (int, optional) – Number of temperatures. Defaults to 2.
nsteps (int, optional) – Number of steps, including the steps for burn-in. Defaults to 1000.
nburnin (int, optional) – Number of burn-in steps. Defaults to 500.
ntry (int, optional) – Number of trials for the Gelman-Rubin check. Defaults to 1.
pos0 (np.nparray, optional) – Initial parameter set in the shape of (ntemps, nwalkers, dim). Defaults to None.
savechain (str, optional) – File name of the chain in format of .npy. Defaults to None.
ncores (int, optional) – Number of cores for multiprocessing.Pool. ncores=1 does not use multiprocessing. Defaults to 1.
grcheck (bool, optional) – Whether to check Gelman-Rubin statistics. Defaults to False.
pt (bool, optional) – Whether to use ptemcee; otherwise, emcee is used. Defaults to False.
- getDNSevidence(**kwargs)[source]
Calculate the Bayesian evidence for a model using dynamic nested sampling through dynesty.
- plotchain(labels: list = None, ylim: list = None, savefig: dict | str = None, show: bool = False)[source]
Plot parameters as a function of steps using self.samples. This method plots nine lines: percent[0], 50%, percent[1] percentiles (over the steps by 1% binning) of percent[0], 50%, percent[1] percentiles (over the walkers).
- Parameters:
labels (list, optional) – Labels for the chain plot. Defaults to None.
ylim (list, optional) – Y-range for the chain plot. Defaults to None.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- plotcorner(labels: list[str] | None = None, cornerrange: list[float] | None = None, savefig: dict | str | None = None, show: bool = False) None[source]
Make the corner plot from self.samples.
- Parameters:
labels (list, optional) – Labels for the corner plot. Defaults to None.
cornerrange (list, optional) – Range for the corner plot. Defaults to None.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- plotongrid(show: bool = False, savefig: str | None = None, labels: list[str] = None, cornerrange: list[float] = None, cmap: str = 'binary', levels: list[float] = [0.011109, 0.135335, 0.606531]) None[source]
Make the corner plot from the posterior calculated on a grid.
- Parameters:
show (bool, optional) – Whether to show the corner plot. Defaults to False.
savefig (str, optional) – File name of the corner plot. Defaults to None.
labels (list, optional) – Labels for the corner plot. Defaults to None.
cornerrange (list, optional) – Range for the corner plot. Defaults to None.
cmap – (str, optional): cmap for matplotlib.pyplot.plt.pcolormesh(). Defaults to ‘binary’.
levels – (list, optional): levels for matplotlib.pyplot.plt.contour() relative to the peak. Defaults to [exp(-0.5*3^2), exp(-0.5*2^2), exp(-0.5*1^2)].
- posteriorongrid(ngrid: list[int] | int = 100, log: list[bool] | bool = False, pcut: float = 0)[source]
Calculate the posterior on a grid of ngrid x ngrid x … x ngrid.
- Parameters:
ngrid (list, optional) – Number of grid on each parameter. Defaults to 100.
log (list, optional) – Whether to search in the logarithmic space. The percentile is counted in the linear space regardless of this option. Defaults to False.
pcut (float, optional) – Posterior is reset to be zero if it is below this cut off.
- plotastrodata.fitting_utils.gaussfit1d(xdata: ndarray, ydata: ndarray, sigma: float | ndarray | None, show: bool = False, **kwargs) dict[source]
Gaussian fitting to a pair of 1D arrays.
- Parameters:
xdata (np.ndarray) – ydata is compared with Gauss(xdata).
ydata (np.ndarray) – ydata is compared with Gauss(xdata).
sigma (float | np.ndarray | None) – Noise level of ydata. If None is given, sigma is estimated by a temporary fitting. Defaults to None.
show (bool, optional) – True means to show the best-fit parameters and uncertainties. Defaults to False.
- Returns:
The keys are popt, perr, and sigma.
- Return type:
dict
- plotastrodata.fitting_utils.gaussfit2d(xdata: ndarray, ydata: ndarray, zdata: ndarray, sigma: float | ndarray | None, show: bool = False, **kwargs) dict[source]
Gaussian fitting to a pair of 1D arrays.
- Parameters:
xdata (np.ndarray) – zdata is compared with Gauss(xdata, ydata).
ydata (np.ndarray) – zdata is compared with Gauss(xdata, ydata).
zdata (np.ndarray) – zdata is compared with Gauss(xdata, ydata).
sigma (float | np.ndarray | None) – Noise level of ydata. If None is given, sigma is estimated by a temporary fitting. Defaults to None.
show (bool, optional) – True means to show the best-fit parameters and uncertainties. Defaults to False.
- Returns:
The keys are popt, perr, and sigma.
- Return type:
dict
- plotastrodata.fitting_utils.gaussian1d(x: ndarray | float, amplitude: float, xo: float, fwhm: float) ndarray[source]
One dimensional Gaussian function.
- Parameters:
x (np.ndarray) – Variable of the Gaussian function.
amplitude (float) – Peak value.
xo (float) – Offset in the x direction.
fwhm (float) – Full width at half maximum.
- Returns:
1D numpy array.
- Return type:
g (np.ndarray)
- plotastrodata.fitting_utils.gaussian2d(xy: ndarray, amplitude: float, xo: float, yo: float, fwhm_major: float, fwhm_minor: float, pa: float) ndarray[source]
Two dimensional Gaussian function.
- Parameters:
xy (np.ndarray) – A pair of (x, y).
amplitude (float) – Peak value.
xo (float) – Offset in the x direction.
yo (float) – Offset in the y direction.
fwhm_major (float) – Full width at half maximum in the major axis (but can be shorter than the minor axis).
fwhm_minor (float) – Full width at half maximum in the minor axis (but can be longer then the major axis).
pa (float) – Position angle of the major axis from the +y axis to the +x axis in the unit of degree.
- Returns:
Output array in the same shape as xy.
- Return type:
g (np.ndarray)
- plotastrodata.fitting_utils.logp(x: ndarray) float[source]
Log prior function made from the boundary (global_bounds) of fitting parameters.
- Parameters:
x (np.ndarray) – The fitting parameters.
- Returns:
The log prior function. 0 if all the parameters are in the boundary else -np.inf.
- Return type:
float
plotastrodata.los_utils module
- plotastrodata.los_utils.obs2sys(xobs: ndarray, yobs: ndarray, zobs: ndarray, pa: float = 0, incl: float = 0, phi0: float = 0, theta0: float = 90, polar: bool = False) ndarray[source]
Convert observed coordinates to system coordinates. In the system coordinates, the observer is at the direction of (0, -sin i, cos i). The observer’s +z (i.e., line-of-sight) is from the observer to the system center. The system’s x coordinate and the observer’s x coordinate have opposite signs.
- Parameters:
xobs (np.ndarray) – Observed x-coordinates. The distance to the east.
yobs (np.ndarray) – Observed y-coordinates. The distance to the north.
zobs (np.ndarray) – Observed z-coordinates. The line-of-sight distance.
pa (float, optional) – Position angle of the “blueshifted outflow” (not the disk major axis) in degrees from yobs (north) to xobs (east). Defaults to 0.
incl (float, optional) – Inclination of the system in degrees. i=0 means face-on. Defaults to 0.
phi0 (float, optional) – Azimuthal angle of the system in degrees, relative to the system that is observed. Defaults to 0.
theta0 (float, optional) – Polar angle of the x-axis of the system in degrees, relative to the x-axis of the system that is observed. Defaults to pi/2.
polar (bool, optional) – If True, the coordinates are in polar coordinates, where theta and phi are in radian. Defaults to False.
- Returns:
System x, y, z coordinates ([xsys, ysys, zsys]) or r, theta, phi coordinates ([r, theta, phi]). The polar coordinates are in radian.
- Return type:
np.ndarray
- plotastrodata.los_utils.polarvel2losvel(v_r: ndarray, v_theta: ndarray, v_phi: ndarray, theta: ndarray, phi: ndarray, incl: float = 0, phi0: float = 0, theta0: float = 90) ndarray[source]
Convert the polar velocities in the system’s coordinates to the line-of-sight velocity in the observer’s coordinates. In the system coordinates, the observer is at the direction of (0, -sin i, cos i). The observer’s +z (i.e., line-of-sight) is from the observer to the system. The system’s x coordinate and the observer’s x coordinate have opposite signs.
- Parameters:
v_r (np.ndarray) – The velocity component in the radial direction.
v_theta (np.ndarray) – The velocity component in the polar angle direction.
v_phi (np.ndarray) – The velocity component in the azimuthal angle direction.
theta (np.ndarray) – The polar angle in radian from the z-axis.
phi (np.ndarray) – The azimuthal angle in radian from the x-axis.
incl (float, optional) – Inclination of the system in degrees. i=0 means face-on. Defaults to 0.
phi0 (float, optional) – Azimuthal angle of the system in degrees, relative to the system that is observed. Defaults to 0.
theta0 (float, optional) – Polar angle of the x-axis of the system in degrees, relative to the x-axis of the system that is observed. Defaults to pi/2.
- Returns:
The line-of-sight velocity.
- Return type:
np.ndarray
- plotastrodata.los_utils.sys2obs(xsys: ndarray, ysys: ndarray, zsys: ndarray, pa: float = 0, incl: float = 0, phi0: float = 0, theta0: float = 90, polar: bool = False) ndarray[source]
Convert system coordinates to observed coordinates. In the system coordinates, the observer is at the direction of (0, -sin i, cos i). The observer’s +z (i.e., line-of-sight) is from the observer to the system center. The system’s x coordinate and the observer’s x coordinate have opposite signs.
- Parameters:
xsys (np.ndarray) – System x-coordinates (or r).
ysys (np.ndarray) – System y-coordinates (or theta).
zsys (np.ndarray) – System z-coordinates (or phi).
pa (float, optional) – Position angle of the “blueshifted outflow” (not the disk major axis) in degrees from yobs (north) to xobs (east). Defaults to 0.
incl (float, optional) – Inclination of the system in degrees. i=0 means face-on. Defaults to 0.
phi0 (float, optional) – Azimuthal angle of the system in degrees, relative to the system that is observed. Defaults to 0.
theta0 (float, optional) – Polar angle of the x-axis of the system in degrees, relative to the x-axis of the system that is observed. Defaults to pi/2.
polar (bool, optional) – If True, the coordinates are in polar coordinates, where theta and phi are in radian. Defaults to False.
- Returns:
Observed x, y, z coordinates ([xobs, yobs, zobs]).
- Return type:
np.ndarray
plotastrodata.matrix_utils module
- plotastrodata.matrix_utils.Mfac(f0: float = 1, f1: float = 1) ndarray[source]
2 x 2 matrix for (x,y) –> (f0 * x, f1 * y).
- Parameters:
f0 (float, optional) – Defaults to 1.
f1 (float, optional) – Defaults to 1.
- Returns:
Matrix for the multiplication.
- Return type:
np.ndarray
- plotastrodata.matrix_utils.Mrot(pa: float = 0) ndarray[source]
2 x 2 matrix for rotation.
- Parameters:
pa (float, optional) – How many degrees are the image rotated by. Defaults to 0.
- Returns:
Matrix for the rotation.
- Return type:
np.ndarray
- plotastrodata.matrix_utils.Mrot3d(t: float, axis: int = 3) ndarray[source]
3D rotation matrix around a specified axis.
This function creates a 3x3 rotation matrix for rotating coordinates around the x-axis (axis=1), y-axis (axis=2), or z-axis (axis=3) by t degrees.
- Parameters:
t (float) – Rotation angle in degrees.
axis (int, optional) – Axis to rotate around - 1 for x-axis, 2 for y-axis, 3 for z-axis. Defaults to 3.
- Returns:
3x3 rotation matrix that rotates coordinates around the specified axis by t degrees.
- Return type:
np.ndarray
- plotastrodata.matrix_utils.dot2d(M: ndarray = [[1, 0], [0, 1]], a: ndarray = [0, 0]) ndarray[source]
To maltiply a 2 x 2 matrix to (x,y) with arrays of x and y.
- Parameters:
M (np.ndarray, optional) – 2 x 2 matrix. Defaults to [[1, 0], [0, 1]].
a (np.ndarray, optional) – 2D vector (of 1D arrays). Defaults to [0].
- Returns:
The 2D vector after the matrix multiplied.
- Return type:
np.ndarray
plotastrodata.noise_utils module
- class plotastrodata.noise_utils.Noise(data: ndarray, sigma: str)[source]
Bases:
object- This class holds the data selected as noise, histogram, and best-fit function.
The following methods are acceptable for data selection. Multiple options are possible. ‘edge’: use data[0] and data[-1]. ‘out’: exclude inner 60% about axes=-2 and -1. ‘neg’: use only negative values. ‘iter’: exclude outliers. The following methods are acceptable for noise estimation. Only single option is possible. ‘med’: calculate rms from the median of data^2 assuming Gaussian. ‘hist’: fit histgram with Gaussian. ‘hist-pbcor’: fit histgram with PB-corrected Gaussian. ‘(no string)’: calculate the mean and standard deviation.
- Parameters:
data (np.ndarray) – Original data array.
sigma (str) – Methods above, like ‘edge,neg,hist-pbcor’.
- plotastrodata.noise_utils.estimate_rms(data: ndarray, sigma: float | str | None = 'hist') float[source]
- Estimate a noise level of a data array.
When a float number or None is given as sigma, this function just outputs it.
- Parameters:
data (np.ndarray) – Data array whose noise is estimated.
sigma (float or str) – Methods for the Noise class, like ‘edge,neg,hist-pbcor’. Defaults to ‘hist’.
- Returns:
The estimated standard deviation of noise.
- Return type:
float
- plotastrodata.noise_utils.gauss(x: ndarray, s: float, m: float) ndarray[source]
Probability density of Gaussian noise.
- Parameters:
x (np.ndarray) – Intensity. The variable of the probability density.
s (float) – Standard deviation of the Gaussian noise.
m (float) – Mean of the Gaussian noise.
- Returns:
Probability density.
- Return type:
np.ndarray
- plotastrodata.noise_utils.gauss_pbcor(x: ndarray, s: float, m: float, R: float) ndarray[source]
Probability density of Gaussian noise after primary-beam correction.
- Parameters:
x (np.ndarray) – Intensity. The variable of the probability density.
s (float) – Standard deviation of the Gaussian noise.
m (float) – Mean of the Gaussian noise.
R (float) – The maximum radius scaled by the FWHM of the primary beam.
- Returns:
Probability density.
- Return type:
np.ndarray
- plotastrodata.noise_utils.normalize(range: tuple = (-3.5, 3.5), bins: int = 100)[source]
Decorator factory to normalize a function over the given range.
- plotastrodata.noise_utils.select_noise(data: ndarray, sigma: str) ndarray[source]
Select data pixels to be used for noise estimation.
- Parameters:
data (np.ndarray) – Original data array.
sigma (str) – Selection methods. Multiple options are possible. ‘edge’, ‘out’, ‘neg’, or ‘iter’.
- Returns:
1D array that includes only the selected pixels.
- Return type:
np.ndarray
plotastrodata.other_utils module
- plotastrodata.other_utils.RGIxy(y: ndarray, x: ndarray, data: ndarray, yxnew: tuple[ndarray, ndarray] | None = None, **kwargs) object | ndarray[source]
RGI for x and y at each channel.
- Parameters:
y (np.ndarray) – 1D array. Second coordinate.
x (np.ndarray) – 1D array. First coordinate.
data (np.ndarray) – 2D, 3D, or 4D array.
yxnew (tuple, optional) – (ynew, xnew), where ynew and xnew are 1D or 2D arrays. Defaults to None.
- Returns:
The RGI function or the interpolated array.
- Return type:
np.ndarray
- plotastrodata.other_utils.RGIxyv(v: ndarray, y: ndarray, x: ndarray, data: ndarray, vyxnew: tuple[ndarray, ndarray, ndarray] | None = None, **kwargs) object | ndarray[source]
RGI in the x-y-v space.
- Parameters:
v (np.ndarray) – 1D array. Third coordinate.
y (np.ndarray) – 1D array. Second coordinate.
x (np.ndarray) – 1D array. First coordinate.
data (np.ndarray) – 3D or 4D array.
vyxnew (tuple, optional) – (vnew, ynew, xnew), where vnew, ynew, and xnew are 1D or 2D arrays. Defaults to None.
- Returns:
The RGI function or the interpolated array.
- Return type:
np.ndarray
- plotastrodata.other_utils.close_figure(fig: object, savefig: dict | str | None = None, show: bool = False, tight: bool = True) None[source]
Save, show, and close the figure.
- Parameters:
fig (object) – External plt.figure(). Defaults to None.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
tight (bool, optional) – True means doing fig.tight_layout(). Defaults to False.
- plotastrodata.other_utils.isdeg(s: str) bool[source]
Whether the given string means degree.
- Parameters:
s (str) – The string to be checked.
- Returns:
Whether the given string means degree.
- Return type:
bool
- plotastrodata.other_utils.listing(*args) list[source]
Output a list of the input when the input is string or number.
- Returns:
With a single non-list input, the output is a list like [‘a’], rather than [[‘a’]].
- Return type:
list
- plotastrodata.other_utils.nearest_index(arr: ndarray, x: float = 0) int[source]
Get the index of the (sorted) arrary that gives a value nearest to x. This is equivalent to np.argmin(np.abs(arr - x)) but optimized for the sorted array.
- Parameters:
arr (np.ndarray) – Sorted array.
x (float, optional) – Value to approach. Defaults to 0.
- Returns:
The index that gives a value nearest to x.
- Return type:
int
- plotastrodata.other_utils.reform_data(c: ndarray, v_in: ndarray | None, nv: int, v_org: ndarray | None = None, vskip: int = 1) ndarray[source]
Skip and fill channels with nan.
- Parameters:
c (np.ndarray) – The input 2D or 3D arrays.
v_in (np.ndarray) – The input velocity 1D array.
nv (int) – The number of channels with a label.
v (np.ndarray, optional) – The velocity 1D array, including the channels with and without a label. Defaults to None.
vskip (int, optional) – How many channels are skipped. Defaults to 1.
- Returns:
3D arrays skipped and filled with nan.
- Return type:
np.ndarray
- plotastrodata.other_utils.reform_grid(v: ndarray | None = None, k0: int | None = None, k1: int | None = None, vmin: float | None = None, vmax: float | None = None) ndarray[source]
Extend or cut the given 1D array based on the given range.
- Parameters:
v (np.ndarray | None, optional) – Input 1D array. Defaults to None.
k0 (int | None, optional) – How many channels are added before v[0]; the minus sign means extension. k0 has the priority over vmin. Defaults to None.
k1 (int | None, optional) – How many channels are added after v[-1]; the plus sign means extension. k1 has the priority over vmax. Defaults to None.
vmin (float | None, optional) – New minimum velocity. Defaults to None.
vmax (float | None, optional) – New maximum velocity. Defaults to None.
- Returns:
Extended or cut 1D array.
- Return type:
np.ndarray
- plotastrodata.other_utils.to4dim(data: ndarray) ndarray[source]
Change a 2D, 3D, or 4D array to a 4D array.
- Parameters:
data (np.ndarray) – Input data. 2D, 3D, or 4D.
- Returns:
Output 4D array.
- Return type:
np.ndarray
- plotastrodata.other_utils.trim(data: ndarray | None = None, x: ndarray | None = None, y: ndarray | None = None, v: ndarray | None = None, xlim: list[float] | None = None, ylim: list[float] | None = None, vlim: list[float] | None = None, pv: bool = False) tuple[ndarray | None, list[ndarray | None]][source]
Trim 2D or 3D data by given coordinates and their limits.
- Parameters:
data (np.ndarray, optional) – 2D or 3D array. Defaults to None.
x (np.ndarray, optional) – 1D array. Defaults to None.
y (np.ndarray, optional) – 1D array. Defaults to None.
v (np.ndarray, optional) – 1D array. Defaults to None.
xlim (list, optional) – [xmin, xmax]. Defaults to None.
ylim (list, optional) – [ymin, ymax]. Defaults to None.
vlim (list, optional) – [vmin, vmax]. Defaults to None.
- Returns:
Trimmed (data, [x,y,v]).
- Return type:
tuple
plotastrodata.plot_utils module
- class plotastrodata.plot_utils.Beam(show_beam: bool = True, beam: list[float | None] = [None, None, None], beamcolor: str = 'gray', beampos: list[float] | None = None, beam_kwargs: dict = {})[source]
Bases:
objectArguments for PlotAstroData.add_beam().
- Parameters:
show_beam (bool, optional) – Defaults to True.
beam (list, optional) – [bmaj, bmin, bpa]. This may be a list of list. Defaults to [None, None, None].
beamcolor (str, optional) – matplotlib color. This may be a list of str. Defaults to ‘gray’.
beampos (list, optional) – Relative position. This may be a list of list or a list of None. Defaults to None.
beam_kwargs (dict, optional) – Additional arguments for matplotlib.patches. Defaults to {}.
- class plotastrodata.plot_utils.PlotAstroData(v: ndarray | None = None, vskip: int = 1, veldigit: int = 2, restfreq: float | None = None, channelnumber: int | None = None, nrows: int = 4, ncols: int = 6, fontsize: int | None = None, nancolor: str = 'w', dpi: int = 256, figsize: tuple[float, float] | None = None, fig: object | None = None, ax: object | None = None, **kwargs)[source]
Bases:
AstroFrameMake a figure from 2D/3D FITS files or 2D/3D arrays.
Basic rules — For 3D data, a 1D velocity array or a FITS file with a velocity axis must be given to set up channels in each page. For 2D/3D data, the spatial center can be read from a FITS file or manually given. len(v)=1 (default) means to make a 2D figure. Spatial lengths are in the unit of arcsec, or au if dist (!= 1) is given. Angles are in the unit of degree. For region, line, arrow, label, and marker, a single input can be treated without a list, e.g., anglelist=60, as well as anglelist=[60]. Each element of poslist supposes a text coordinate like ‘01h23m45.6s 01d23m45.6s’ or a list of relative x and y like [0.2, 0.3] (0 is left or bottom, 1 is right or top). Parameters for original methods in matplotlib.axes.Axes can be used as kwargs; see the default _kw for reference. Position-velocity diagrams (pv=True) does not yet suppot region, line, arrow, and segment because the units of abscissa and ordinate are different.
kwargs is the arguments of AstroFrame to define plotting ranges.
- Parameters:
v (np.ndarray, optional) – Used to set up channels if fitsimage not given. Defaults to None.
vskip (int, optional) – How many channels are skipped. Defaults to 1.
veldigit (int, optional) – How many digits after the decimal point. Defaults to 2.
restfreq (float, optional) – Used for velocity and brightness T. Defaults to None.
channelnumber (int, optional) – Specify a channel number to make 2D maps. Defaults to None.
nrows (int, optional) – Used for channel maps. Defaults to 4.
ncols (int, optional) – Used for channel maps. Defaults to 6.
fontsize (int, optional) – rc_Params[‘font.size’]. None means 18 (2D) or 12 (3D). Defaults to None.
nancolor (str, optional) – Color for masked regions. Defaults to white.
dpi (int, optional) – Dot per inch for plotting an image. Defaults to 256.
figsize (tuple, optional) – Defaults to None.
fig (optional) – External plt.figure(). Defaults to None.
ax (optional) – External fig.add_subplot(). Defaults to None.
- add_arrow(poslist: list[str | list[float, float]] = [], anglelist: list[float] = [], rlist: list[float] = [], include_chan: list[int] | None = None, **kwargs) None[source]
Use Axes.quiver of matplotlib.
- Parameters:
poslist (list, optional) – Text or relative. Defaults to [].
anglelist (list, optional) – North to east. Defaults to [].
rlist (list, optional) – List of radius. Defaults to [].
include_chan (list, optional) – None means all. Defaults to None.
- add_beam(**kwargs) None[source]
Use add_region(). kwargs may include the arguments of Beam, except for beam_kwargs, to specify the beam apparance. Those arguments may be a list of each format.
- add_color(show_cbar: bool = True, cblabel: str | None = None, cbformat: float = '%.1e', cbticks: list[float] | None = None, cbticklabels: list[str] | None = None, cblocation: str = 'right', cblabelfontsize: int = 16, cbtickfontsize: int = 14, **kwargs) None[source]
Use Axes.pcolormesh of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs may include the arguments for Stretcher (stretch, stretchscale, and stretchpower) to specify the stretch parameters. kwargs may include arguments of Beam; a dict of beam_kwargs specifies the beam patch in more detail. kwargs may include xskiip and yskip.
- Parameters:
show_cbar (bool, optional) – Show color bar. Defaults to True.
cblabel (str, optional) – Colorbar label. Defaults to None.
cbformat (float, optional) – Format for ticklabels of colorbar. Defaults to ‘%.1e’.
cbticks (list, optional) – Ticks of colorbar. Defaults to None.
cbticklabels (list, optional) – Ticklabels of colorbar. Defaults to None.
cblocation (str, optional) – ‘left’, ‘top’, ‘left’, ‘right’. Only for 2D images. Defaults to ‘right’.
cblabelfontsize (int, optional) – Fontsize for the colorbar label. This is independent of set_rcparams().
cbtickfontsize (int, optional) – Fontsize for the colorbar ticks. This is independent of set_rcparams().
- add_contour(levels: list[float] = [-12, -6, -3, 3, 6, 12, 24, 48, 96, 192, 384], **kwargs) None[source]
Use Axes.contour of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. kwargs may include arguments of Beam; a dict of beam_kwargs specifies the beam patch in more detail. kwargs may include xskiip and yskip.
- Parameters:
levels (list, optional) – Contour levels in the unit of sigma. Defaults to [-12,-6,-3,3,6,12,24,48,96,192,384].
- add_line(poslist: list[str | list[float, float]] = [], anglelist: list[float] = [], rlist: list[float] = [], include_chan: list[int] | None = None, **kwargs) None[source]
Use Axes.plot of matplotlib.
- Parameters:
poslist (list, optional) – Text or relative. Defaults to [].
anglelist (list, optional) – North to east. Defaults to [].
rlist (list, optional) – List of radius. Defaults to [].
include_chan (list, optional) – None means all. Defaults to None.
- add_marker(poslist: list[str | list[float, float]] = [], include_chan: list[int] | None = None, **kwargs) None[source]
Use Axes.plot of matplotlib.
- Parameters:
poslist (list, optional) – Text or relative. Defaults to [].
include_chan (list, optional) – None means all. Defaults to None.
- add_region(patch: str = 'ellipse', poslist: list[str | list[float, float]] = [], majlist: list[float] = [], minlist: list[float] = [], palist: list[float] = [], include_chan: list[int] | None = None, **kwargs) None[source]
Use add_patch() and Rectangle or Ellipse of matplotlib.
- Parameters:
patch (str, optional) – ‘ellipse’ or ‘rectangle’. Defaults to ‘ellipse’.
poslist (list, optional) – Text or relative center. Defaults to [].
majlist (list, optional) – Ellipse major axis. Defaults to [].
minlist (list, optional) – Ellipse minor axis. Defaults to [].
palist (list, optional) – Position angle (north to east). Defaults to [].
include_chan (list, optional) – None means all. Defaults to None.
- add_rgb(**kwargs) None[source]
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, including vmax and vmin, except for xskip, yskip and show_beam. kwargs may include the arguments for Stretcher (stretch, stretchscale, and stretchpower; three-element array for each) to specify the stretch parameters. kwargs may include arguments of Beam (three-element arrays); a single dict of beam_kwargs specifies the beam patch in more detail. kwargs may include xskiip and yskip.
- add_scalebar(length: float = 0, label: str = '', color: str = 'gray', barpos: tuple[float, float] = (0.8, 0.12), fontsize: float | None = None, linewidth: float = 3, bbox: dict = {'alpha': 0}) None[source]
Use Axes.text and Axes.plot of matplotlib.
- Parameters:
length (float, optional) – In the unit of arcsec. Defaults to 0.
label (str, optional) – Text like ‘100 au’. Defaults to ‘’.
color (str, optional) – Same for bar and label. Defaults to ‘gray’.
barpos (tuple, optional) – Relative position. Defaults to (0.8, 0.12).
fontsize (float, optional) – None means 15 if one channel else 20. Defaults to None.
linewidth (float, optional) – Width of the bar. Defaults to 3.
- add_segment(ampfits: str = None, angfits: str = None, Ufits: str = None, Qfits: str = None, amp: list[ndarray] | None = None, ang: list[ndarray] | None = None, stU: list[ndarray] | None = None, stQ: list[ndarray] | None = None, ampfactor: float = 1.0, angonly: bool = False, rotation: float = 0.0, cutoff: float = 3.0, **kwargs) None[source]
Use Axes.quiver of matplotlib. kwargs must include the arguments of AstroData to specify the data to be plotted. fitsimage = [ampfits, angfits, Ufits, Qfits]. data = [amp, ang, stU, stQ]. kwargs may include arguments of Beam; a dict of beam_kwargs specifies the beam patch in more detail. kwargs may include xskiip and yskip.
- Parameters:
ampfits (str, optional) – In put fits name. Length of segment. Defaults to None.
angfits (str, optional) – In put fits name. North to east. Defaults to None.
Ufits (str, optional) – In put fits name. Stokes U. Defaults to None.
Qfits (str, optional) – In put fits name. Stokes Q. Defaults to None.
amp (list, optional) – Length of segment. Defaults to None.
ang (list, optional) – North to east. Defaults to None.
stU (list, optional) – Stokes U. Defaults to None.
stQ (list, optional) – Stokes Q. Defaults to None.
ampfactor (float, optional) – Length of segment is amp times ampfactor. Defaults to 1..
angonly (bool, optional) – True means amp=1 for all. Defaults to False.
rotation (float, optional) – Segment angle is ang + rotation. Defaults to 0..
cutoff (float, optional) – Used when amp and ang are calculated from Stokes U and Q. In the unit of sigma. Defaults to 3..
- add_text(poslist: list[str | list[float, float]] = [], slist: list[str] = [], include_chan: list[int] | None = None, **kwargs) None[source]
Use Axes.text of matplotlib.
- Parameters:
poslist (list, optional) – Text or relative. Defaults to [].
slist (list, optional) – List of text. Defaults to [].
include_chan (list, optional) – None means all. Defaults to None.
- get_figax() tuple[object, object][source]
Output the external fig and ax after plotting.
- Returns:
(fig, ax)
- Return type:
tuple
- savefig(filename: str | None = None, show: bool = False, **kwargs) None[source]
Use savefig of matplotlib.
- Parameters:
filename (str, optional) – Output image file name. Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- set_axis(title: dict | str | None = None, **kwargs) None[source]
Use Axes.set_* of matplotlib. kwargs can include the arguments of PlotAxes2D to adjust x and y axis.
- Parameters:
title (dict | str | None) – str means set_title(str) for 2D or fig.suptitle(str) for 3D. Defaults to None.
- set_axis_radec(center: str | None = None, xlabel: str = 'R.A. (ICRS)', ylabel: str = 'Dec. (ICRS)', nticksminor: int = 2, grid: dict | None = None, title: dict | None = None) None[source]
Use Axes.set_* of matplotlib. kwargs can include the arguments of PlotAxes2D to adjust x and y axis.
- Parameters:
center (str, optional) – Defaults to None, initial one.
xlabel (str, optional) – Defaults to ‘R.A. (ICRS)’.
ylabel (str, optional) – Defaults to ‘Dec. (ICRS)’.
nticksminor (int, optional) – Interval ratio of major and minor ticks. Defaults to 2.
grid (dict, optional) – True means merely grid(). Defaults to None.
title (dict | str | None) – str means set_title(str) for 2D or fig.suptitle(str) for 3D. Defaults to None.
- class plotastrodata.plot_utils.PlotAxes2D(samexy: bool = True, loglog: float | None = None, xscale: str = 'linear', yscale: str = 'linear', xlim: list | None = None, ylim: list | None = None, xlabel: str | None = None, ylabel: str | None = None, xticks: list | None = None, yticks: list | None = None, xticklabels: list | None = None, yticklabels: list | None = None, xticksminor: list | int | None = None, yticksminor: list | int | None = None, grid: dict | None = None, aspect: dict | float | None = None)[source]
Bases:
objectUse Axes.set_* to adjust x and y axes.
- Parameters:
samexy (bool, optional) – True supports same ticks between x and y. Defaults to True.
loglog (float, optional) – If a float is given, plot on a log-log plane, and xim=(xmax / loglog, xmax) and so does ylim. Defaults to None.
xscale (str, optional) – Defaults to None.
yscale (str, optional) – Defaults to None.
xlim (list, optional) – Defaults to None.
ylim (list, optional) – Defaults to None.
xlabel (str, optional) – Defaults to None.
ylabel (str, optional) – Defaults to None.
xticks (list, optional) – Defaults to None.
yticks (list, optional) – Defaults to None.
xticklabels (list, optional) – Defaults to None.
yticklabels (list, optional) – Defaults to None.
xticksminor (list or int, optional) – If int, int times more than xticks. Defaults to None.
yticksminor (list or int, optional) – Defaults to None. If int, int times more than xticks. Defaults to None.
grid (dict, optional) – True means merely grid(). Defaults to None.
aspect (dict or float, optional) – Defaults to None.
- aspect: dict | float | None = None
- grid: dict | None = None
- loglog: float | None = None
- samexy: bool = True
- xlabel: str | None = None
- xlim: list | None = None
- xscale: str = 'linear'
- xticklabels: list | None = None
- xticks: list | None = None
- xticksminor: list | int | None = None
- ylabel: str | None = None
- ylim: list | None = None
- yscale: str = 'linear'
- yticklabels: list | None = None
- yticks: list | None = None
- yticksminor: list | int | None = None
- class plotastrodata.plot_utils.Stretcher(stretch: str = 'linear', stretchscale: float | None = None, stretchpower: float = 0.5, vmin: float | None = None, vmax: float | None = None, sigma: float = 0)[source]
Bases:
objectArguments and methods related to the stretch in PlotAstroData.add_color() and add_rgb().
- Parameters:
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’.
stretchscale (float, optional) – The output is asinh(data / stretchscale). Defaults to None.
stretchpower (float, optional) – The output is data**stretchpower / stretchpower. 1 means the linear scale, while 0 means the logarithmic scale. Defaults to 0.5.
vmin (float, optional) – The minimum value for Axes.pcolormesh() of matplotlib. Defaults to None.
vmax (float, optional) – The maximum value for Axes.pcolormesh() of matplotlib. Defaults to None.
sigma (float, optional) – Noise level. Defaults to 0.
- do(x: list | ndarray, i: int = 0) ndarray[source]
Get the stretched values.
- Parameters:
x (list | np.ndarray) – Input array in the linear scale.
i (int) – Which element is used in the case where the stretch parameters are lists.
- Returns:
Output stretched array.
- Return type:
np.ndarray
- set_minmax(data: ndarray) tuple[ndarray, ndarray, ndarray][source]
Set vmin and vmax for color pcolormesh and RGB maps.
- Parameters:
data (np.ndarray) – 2D/3D data to plot.
- Returns:
(Clipped stretched data, new vmin, new vmax).
- Return type:
tuple[np.ndarray, np.ndarray, np.ndarray]
- sigma: float = 0
- stretch: str = 'linear'
- stretchpower: float = 0.5
- stretchscale: float | None = None
- undo(x: list | ndarray, i: int = 0) ndarray[source]
Get the linear values from the stretched values.
- Parameters:
x (list | np.ndarray) – Input stretched array.
i (int) – Which element is used in the case where the stretch parameters are lists.
- Returns:
Output array in the linear scale.
- Return type:
np.ndarray
- vmax: float | None = None
- vmin: float | None = None
- plotastrodata.plot_utils.get_figsize(xmin: float, xmax: float, ymin: float, ymax: float, figsize: tuple | None = None, ncols: int = 1, nrows: int = 1, nchan: int = 1) tuple[float, float][source]
Get a nice figsize (tuple) with the given x and y ranges.
- Parameters:
xmin (float) – The figsize is based on the aspect ratio of (ymax - ymin) / (xmax - xmin).
xmax (float) – The figsize is based on the aspect ratio of (ymax - ymin) / (xmax - xmin).
ymin (float) – The figsize is based on the aspect ratio of (ymax - ymin) / (xmax - xmin).
ymax (float) – The figsize is based on the aspect ratio of (ymax - ymin) / (xmax - xmin).
figsize (tuple | None, optional) – If this is not None, this will be the output as is. Defaults to None.
ncols (int, optional) – The number of columns for the channel map. Defaults to 1.
nrows (int, optional) – The number of rows for the channel map. Defaults to 1.
nchan (int, optional) – The number of total channels for the channel map. Defaults to 1.
- Returns:
figsize for matplotlib.pyplot.Figure.
- Return type:
tuple[float, float]
- plotastrodata.plot_utils.kwargs2instance(cls: type[T], kw: dict) T[source]
Get an instance and remove its arguments from kwargs.
- Parameters:
cls (class) – Class to make the instance.
kw (dict) – Parameters to make the instance.
- Returns:
an instance of cls made from the parameters in kwargs.
- Return type:
instance
- plotastrodata.plot_utils.logcbticks(vmin: float = 0.001, vmax: float = 1000.0) tuple[ndarray, ndarray][source]
Make nice ticks for a log color bar.
- Parameters:
vmin (float, optional) – Minimum value. Defaults to 1e-3.
vmax (float, optional) – Maximum value. Defaults to 1e3.
- Returns:
(ticks, ticklabels).
- Return type:
tuple
- plotastrodata.plot_utils.logticks(ticks: list[float], lim: list[float, float]) tuple[list[float], list[str]][source]
Make nice ticks for a log axis.
- Parameters:
ticks (list) – List of ticks.
lim (list) – [min, max].
- Returns:
(new ticks, new labels).
- Return type:
tuple
- plotastrodata.plot_utils.plot3d(levels: list[float] = [3, 6, 12], cmap: str = 'Jet', alpha: float = 0.08, xlabel: str = 'R.A. (arcsec)', ylabel: str = 'Dec. (arcsec)', vlabel: str = 'Velocity (km/s)', xskip: int = 1, yskip: int = 1, eye_p: float = 0, eye_i: float = 180, xplus: dict = {}, xminus: dict = {}, yplus: dict = {}, yminus: dict = {}, vplus: dict = {}, vminus: dict = {}, outname: str = 'plot3d', show: bool = False, return_data_layout: bool = False, **kwargs) None | dict[source]
Use Plotly. 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.
- Parameters:
levels (list, optional) – Contour levels. Defaults to [3,6,12].
cmap (str, optional) – Color map name. Defaults to ‘Jet’.
alpha (float, optional) – opacity in plotly. Defaults to 0.08.
xlabel (str, optional) – Defaults to ‘R.A. (arcsec)’.
ylabel (str, optional) – Defaults to ‘Dec. (arcsec)’.
vlabel (str, optional) – Defaults to ‘Velocity (km/s)’.
xskip (int, optional) – Number of pixel to skip. Defaults to 1.
yskip (int, optional) – Number of pixel to skip. Defaults to 1.
eye_p (float, optional) – Azimuthal angle of camera. Defaults to 0.
eye_i (float, optional) – Inclination angle of camera. Defaults to 180.
xplus (dict, optional) – 2D data to be plotted on the y-v plane at the positive edge of x. This dictionary must have a key of data and can have keys of levels, sigma, cmap, and alpha. Defaults to {}.
xminus (dict, optional) – See xplus. Defaults to {}.
yplus (dict, optional) – See xplus. Defaults to {}.
yminus (dict, optional) – See xplus. Defaults to {}.
vplus (dict, optional) – See xplus. Defaults to {}.
vminus (dict, optional) – See xplus. Defaults to {}.
outname (str, optional) – Output file name. Defaults to ‘plot3d’.
show (bool, optional) – auto_play in plotly. Defaults to False.
return_data_layout (bool, optional) – Whether to return data and layout for plotly.graph_objs.Figure. Defaults to False.
- Returns:
{‘data’: data, ‘layout’: layout}, if return_data_layout=True. Otherwise, no return.
- Return type:
dict
- plotastrodata.plot_utils.plotprofile(coords: list[str] | str = [], xlist: list[float] = [], ylist: list[float] = [], ellipse: list[float, float, float] | None = None, ninterp: int = 1, flux: bool = False, width: int = 1, gaussfit: bool = False, gauss_kwargs: dict = {}, title: list[str] | None = None, text: list[str] | None = None, nrows: int = 0, ncols: int = 1, fig: object | None = None, ax: object | None = None, getfigax: bool = False, savefig: dict | str | None = None, show: bool = False, **kwargs) tuple[object, object][source]
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.
- Parameters:
coords (list, optional) – Coordinates. Defaults to [].
xlist (list, optional) – Offset from the center. Defaults to [].
ylist (list, optional) – Offset from the center. Defaults to [].
ellipse (list, optional) – [major, minor, pa], For average. Defaults to None.
ninterp (int, optional) – Number of points for interpolation. Defaults to 1.
flux (bool, optional) – y axis is flux density. Defaults to False.
width (int, optional) – Rebinning step along v. Defaults to 1.
gaussfit (bool, optional) – Fit the profiles. Defaults to False.
gauss_kwargs (dict, optional) – Kwargs for Axes.plot. Defaults to {}.
title (list, optional) – For each plot. Defaults to None.
text (list, optional) – For each plot. Defaults to None.
nrows (int, optional) – Used for channel maps. Defaults to 0.
ncols (int, optional) – Used for channel maps. Defaults to 1.
fig (object, optional) – External plt.figure(). Defaults to None.
ax (object, optional) – External fig.add_subplot(). Defaults to None.
getfigax (bool, optional) – Defaults to False.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- Returns:
(fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
- Return type:
tuple
- plotastrodata.plot_utils.plotslice(length: float, dx: float | None = None, pa: float = 0, txtfile: str | None = None, fig: object | None = None, ax: object | None = None, getfigax: bool = False, savefig: str | dict | None = None, show: bool = False, **kwargs) tuple[object, object][source]
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.
- Parameters:
length (float) – Slice length.
dx (float, optional) – Grid increment. Defaults to None.
pa (float, optional) – Degree. Position angle. Defaults to 0.
txtfile (str, optional) – File name for numpy.savetxt(). Defaults to None.
fig (object, optional) – External plt.figure(). Defaults to None.
ax (object, optional) – External fig.add_subplot(). Defaults to None.
getfigax (bool, optional) – Defaults to False.
savefig (dict or str, optional) – For plt.figure().savefig(). Defaults to None.
show (bool, optional) – True means doing plt.show(). Defaults to False.
- Returns:
(fig, ax), where ax is a list, if getfigax=True. Otherwise, no return.
- Return type:
tuple
- plotastrodata.plot_utils.set_rcparams(fontsize: int = 18, nancolor: str = 'w', dpi: int = 256) None[source]
Nice rcParams for figures.
- Parameters:
fontsize (int, optional) – plt.rcParams[‘font.size’]. Defaults to 18.
nancolor (str, optional) – plt.rcParams[‘axes.facecolor’]. Defaults to ‘w’.
dpi (int, optional) – plt.rcParams[‘savefig.dpi’]. Defaults to 256.