-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcube_finalizing.py
44 lines (31 loc) · 1.31 KB
/
cube_finalizing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Cube finalizing:
1. Minimize the model, residual, and pb cubes
2. Compute the PSF epsilon
3. Create the JVM-corrected image and pb
"""
from beam_volume_tools import epsilon_from_psf, conv_model, rescale
from spectral_cube import SpectralCube
from radio_beam.utils import BeamError
def beam_correct_cube(basename, minimize=True):
modcube = SpectralCube.read(basename+".model", format='casa_image')
psfcube = SpectralCube.read(basename+".psf", format='casa_image')
residcube = SpectralCube.read(basename+".residual", format='casa_image')
if minimize:
cutslc = residcube.subcube_slices_from_mask(residcube.mask)
modcube = modcube[cutslc]
psfcube = psfcube[cutslc]
residcube = residcube[cutslc]
# there are sometimes problems with identifying a common beam
try:
epsdict = epsilon_from_psf(psfcube, export_clean_beam=True)
except BeamError:
epsdict = epsilon_from_psf(psfcube, epsilon=0.005, export_clean_beam=True)
clean_beam = epsdict['clean_beam']
convmod = conv_model(modcube, clean_beam)
merged = rescale(convmod, epsdict['epsilon'],
residual_image=residcube,
export_fits=False
)
merged.write(basename+".JvM.image.fits", overwrite=True)
return merged