Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use spectral-cube common beam calculations for common beams (#385).
- Mosaic weights are now generated after convolution and regridding, and will undo any primary beam corrections (#396).
- Don't skip making large mosaics (but keep the log messages to inform users this is happening) (#405).
- Begin removal of analysisUtils (#402).

### Fixed

Expand Down
19 changes: 9 additions & 10 deletions phangsPipeline/casaCubeRoutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os

import analysisUtils as au
import numpy as np
import scipy.ndimage as nd
from astropy.io import fits
Expand Down Expand Up @@ -45,7 +44,7 @@ def check_getchunk_putchunk_memory_issue(

Args:
infile: input image file.
myia: optional, if not given then we will run `myia = au.createCasaTool(casaStuff.iatool)` then `myia.open(infile)`.
myia: optional, if not given then we will run `myia = casaStuff.iatool()` then `myia.open(infile)`.
return_data: if True then we will return the data if `getchunk()` runs properly withut a memory issue.
return_mask: if True then we will return the mask if `getchunk(getmask=True)` runs properly withut a memory issue.
return_shape: if True then we will return the shape of the cube data.
Expand All @@ -64,7 +63,7 @@ def check_getchunk_putchunk_memory_issue(
cube_mask = None
has_opened_file = False
if myia is None:
myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()
myia.open(infile)
has_opened_file = True
if not myia.isopen():
Expand Down Expand Up @@ -177,14 +176,14 @@ def get_mask(infile, huge_cube_workaround=True):
# os.system('rm -rf ' + infile + '.temp.fits')
#
#else:
# myia = au.createCasaTool(casaStuff.iatool)
# myia = casaStuff.iatool()
# myia.open(infile+'.temp_deg')
# mask = myia.getchunk(getmask=True)
# myia.close()
#
#os.system('rm -rf ' + infile + '.temp_deg')

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

myia.open(infile)

Expand Down Expand Up @@ -237,7 +236,7 @@ def copy_mask(infile, outfile, huge_cube_workaround=True):

# use putregion to update pixel mask

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

myia.open(outfile)

Expand All @@ -259,7 +258,7 @@ def copy_mask(infile, outfile, huge_cube_workaround=True):
else: # getchunk was unsuccessful, has memory issue
# putregion channel by channel
logger.debug('putregion channel by channel for known memory issue')
myrg = au.createCasaTool(casaStuff.rgtool)
myrg = casaStuff.rgtool()
nx = out_shape[0]
ny = out_shape[1]
#logger.debug('copy_mask mask.shape {}'.format(mask.shape))
Expand Down Expand Up @@ -324,13 +323,13 @@ def multiply_cube_by_value(infile, value, brightness_unit, huge_cube_workaround=
# overwrite=True)
# os.system('rm -rf ' + infile + '.fits')
#else:
# myia = au.createCasaTool(casaStuff.iatool)
# myia = casaStuff.iatool()
# myia.open(infile)
# vals = myia.getchunk()
# vals *= value
# myia.putchunk(vals)

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

myia.open(infile)

Expand Down Expand Up @@ -627,7 +626,7 @@ def trim_rind(
target_file = infile

# Figure out the extent of the image inside the cube
myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()
myia.open(target_file)
mask = myia.getchunk(getmask=True)
elt = nd.generate_binary_structure(2,1)
Expand Down
9 changes: 4 additions & 5 deletions phangsPipeline/casaFeatherRoutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import os

import analysisUtils as au
import numpy as np

from . import casaCubeRoutines as ccr
Expand Down Expand Up @@ -115,12 +114,12 @@ def prep_sd_for_feather(
overwrite=overwrite)

# Get out and match axis orders from interferometric images
myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()
myia.open(interf_file)
interf_cs = myia.coordsys()
myia.close()

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()
myia.open(current_outfile)
sd_cs = myia.coordsys()
myia.close()
Expand Down Expand Up @@ -235,7 +234,7 @@ def feather_two_cubes(
os.system('cp -rf '+interf_file+' '+current_interf_file)
os.system('cp -rf '+sd_file+' '+current_sd_file)

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

# As noted in [https://casa.nrao.edu/docs/casaref/image.putchunk.html],
# "If all the pixels didn't easily fit in memory, you would iterate through
Expand Down Expand Up @@ -390,7 +389,7 @@ def feather_two_cubes(

# Finally, if we don't have a 4th (Stokes I) axis, add this
# here to avoid feather crashing
myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

myia.open(current_interf_file)
interf_shape = myia.shape()
Expand Down
81 changes: 18 additions & 63 deletions phangsPipeline/casaImagingRoutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import logging
import os

import analysisUtils as au
import numpy as np

from . import casaMaskingRoutines as cmr
from . import casaStuff
from .casaVisRoutines import get_spw_info, pick_cell_and_im_size
from .clean_call import CleanCall

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -50,65 +50,21 @@ def estimate_cell_and_imsize(
else:
pblevel = clean_call.get_param('pblimit')

# These are the CASA-preferred sizes for fast FFTs

valid_sizes = []
for ii in range(10):
for kk in range(3):
for jj in range(3):
valid_sizes.append(2 ** (ii + 1) * 5 ** jj * 3 ** kk)
valid_sizes = sorted(valid_sizes)
valid_sizes = np.array(valid_sizes)

# Cell size implied by baseline distribution from analysis
# utilities.

au_cellsize, au_imsize, _ = au.pickCellSize(infile,
imsize=True,
npix=oversamp,
intent='',
pblevel=pblevel,
)
xextent = au_cellsize * au_imsize[0] * 1.2
yextent = au_cellsize * au_imsize[1] * 1.2

# Make the cell size a nice round number

if au_cellsize < 0.01:
cell_size = au_cellsize
elif 0.01 <= au_cellsize < 0.05:
cell_size = np.floor(au_cellsize / 0.005) * 0.005
elif 0.05 <= au_cellsize < 0.1:
cell_size = np.floor(au_cellsize / 0.01) * 0.01
elif 0.1 <= au_cellsize < 0.5:
cell_size = np.floor(au_cellsize / 0.05) * 0.05
elif 0.5 <= au_cellsize < 1.0:
cell_size = np.floor(au_cellsize / 0.1) * 0.1
elif 1.0 <= au_cellsize < 2.0:
cell_size = np.floor(au_cellsize / 0.25) * 0.25
elif 2.0 <= au_cellsize < 5.0:
cell_size = np.floor(au_cellsize / 0.5) * 0.5
else:
cell_size = np.floor(au_cellsize / 1.0) * 0.5

# Now make the image size a good number for the FFT

need_cells_x = xextent / cell_size
need_cells_y = yextent / cell_size

cells_x = np.min(valid_sizes[valid_sizes > need_cells_x])
cells_y = np.min(valid_sizes[valid_sizes > need_cells_y])
# Cell size implied by baseline distribution
cell_size, image_size = pick_cell_and_im_size(
infile,
npix=oversamp,
pblevel=pblevel,
)

# If requested, force the mosaic to be square. This avoids
# pathologies in CASA versions 5.1 and 5.3.

if force_square:
if cells_y < cells_x:
cells_y = cells_x
if cells_x < cells_y:
cells_x = cells_y
if image_size[0] < image_size[1]:
image_size[1] = image_size[0]
if image_size[0] > image_size[1]:
image_size[0] = image_size[1]

image_size = [int(cells_x), int(cells_y)]
cell_size_string = str(cell_size) + 'arcsec'

return cell_size_string, image_size
Expand Down Expand Up @@ -786,18 +742,17 @@ def clean_loop(
working_call.set_param('calcpsf', False)

# Note the number of channels, which is used in setting the number
# of iterations that we give to an individual clean call.

vm = au.ValueMapping(working_call.get_param('vis'))

# If we have a number of channels defined, then use that
# of iterations that we give to an individual clean call. If we
# have a number of channels defined, then use that
nchan = working_call.get_param('nchan')

# Otherwise, pull the total number of channels from the spwInfo
if nchan is None:
nchan = -1
if nchan <= 0:
nchan = vm.spwInfo[0]['numChannels']
vis = working_call.get_param('vis')
spw_info = get_spw_info(vis)
nchan = spw_info[0]['numChannels']

# Create a text record of progress through successive clean calls.

Expand Down Expand Up @@ -1016,7 +971,7 @@ def clean_loop(
pb_image = (_imagename + '.pb') if _imagename else None
if pb_image and os.path.isdir(pb_image):
try:
myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()
myia.open(pb_image)
pb_data = myia.getchunk()
myia.close()
Expand Down Expand Up @@ -1115,7 +1070,7 @@ def calc_residual_statistics(
logger.error('Error! The input file "' + mask_name + '" was not found!')
return

myia = au.createCasaTool(casaStuff.iatool)
myia = casaStuff.iatool()

myia.open(mask_name)
mask = myia.getchunk()
Expand Down
Loading
Loading