Source
_ia.calc('iif ("'+imagetoadd+'">'+str(threshold)+',("'+sumimage+'"+"'+imagetoadd+'")/("'+sumimage+'"+"'+imagetoadd+'"),"'+sumimage+'")',False)
################################################
# Task to make masks.
# reorganized after diesuccsion on Oct1, 2012
# with Jeurgen and Urvashi
#
# modified by TT
# based on the original code,
# v1.0: 2012.03.20, U.Rau
#
################################################
# Notes (to self) - TT
# 1. expanding one mask to another
# e.g.) expanding a continuum mask (both image mask/boolean mask)
# channel mask
# 2. part of copy mode func.: merging of different types of masks
# e.g.) inpimage and inpmask are lists of the mask to be merged
# output mask is written to either outimage or outmask as embedded
# T/F mask
# 3. copying mask to another or create a new one
# regrid if necessary (i.e. if the coords are different)
# ----------------------------------------------
# basic rules:
# for mask image (1/0 mask): as it is
# for internal mask : parent_imagename:mask_name
#
# For input,
# inpimage is the casa image
# - mode='list': list internal masks of inpimage
# - other mode: used as a template for output
# if region files are specified -> make mask specifeid with the regions on to inpimage
# output is '' => modified inpimage unless overwrite=F else exception
#
# if inpmask='': use inpimage as input mask
# if inpmask='mask0' or other embedded mask name of the inpimage,
# use that T/F mask
#
# =expand=
# case1: on the same image (outimage=''), expand mask image from
# prev. run etc. No regriding. Use nearest chan mask
# image to expand.
# 1.a: inpimage is clean image mask (1s and 0s)
# i) outimage != inpimage and outmask='' => new expanded mask image to outimage
# ii) outimage != inpimage and outmask!='' => convert expanded mask image to T/F mask to store inside outimage
# iii) outimage ==inpimage and outmask='' => update input mask image by expanding it
# iv) outimage ==inpimage and outmask!=''=> update input image with the expanded T/F mask
# 1.b: if inpmask!='', do T/F mask to 1/0 image mask conversion, then do as in 1.a
# case2: outimage is in diffirent coords. (need to regrid)
#
#################
# tests
# 1. for input: mask image
# 2. for input: mask/or regular image with internal mask
# 3. for input: mask image; for output: mask image with different spectral grid
# 4. for input: mask/regular image with internal mask; for output: image with
# internal mask with different spectral grid
###################
from __future__ import absolute_import
import os
import shutil
import numpy as np
# get is_CASA6 and is_python3