Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion gofish/gofish.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, path, FOV=None, velocity_range=None, verbose=True,
if self.data.ndim != 3 and self.verbose:
print("WARNING: Provided cube is only 2D. Shifting not available.")

self._cached_average_spectra={}

# -- Fishing Functions -- #

def average_spectrum(self, r_min=None, r_max=None, dr=None,
Expand Down Expand Up @@ -154,6 +156,20 @@ def average_spectrum(self, r_min=None, r_max=None, dr=None,
bin, ``scatter``. The latter two are in units of either [Jy/beam]
or [K] depending on the ``unit``.
"""
# Check whether this tuple of inputs was already calculated
args = (r_min, r_max, dr,
PA_min, PA_max, exclude_PA,
abs_PA, x0, y0, inc, PA, z0,
psi, z1, phi, z_func, mstar,
dist, resample, beam_spacing,
mask_frame, unit.lower(), mask,
assume_correlated, skip_empty_annuli,
shadowed)
print(args)
if args in self._cached_average_spectra.keys():
print("Using cached!")
return self._cached_average_spectra[args]

# Check is cube is 2D.
self._test_2D()

Expand Down Expand Up @@ -251,6 +267,7 @@ def average_spectrum(self, r_min=None, r_max=None, dr=None,
if unit[0] == 'm':
spectrum *= 1e3
scatter *= 1e3
self._cached_average_spectra[args] = x, spectrum, scatter
return x, spectrum, scatter

def integrated_spectrum(self, r_min=None, r_max=None, dr=None, x0=0.0,
Expand Down Expand Up @@ -503,7 +520,7 @@ def radial_profile(self, rvals=None, rbins=None, dr=None,
z0=0.0, psi=1.0, z1=0.0, phi=1.0, z_func=None,
mstar=1.0, dist=100., resample=1, beam_spacing=False,
r_min=None, r_max=None, PA_min=None, PA_max=None,
exclude_PA=False, abs_PA=False, mask_frame='disk',
exclude_PA=None, abs_PA=False, mask_frame='disk',
velo_range=None, assume_correlated=True, shadowed=True):
"""
Generate a radial profile from shifted and stacked spectra. There are
Expand Down