from abc import abstractmethod
from typing import Any, Dict, List, Tuple, Union
from numpy import array, uint64
from casatasks import casalog
from casatasks.private.ialib import write_image_history
from casatasks.private.sdutil import (sdtask_decorator, table_manager,
from casatasks.private.task_imsmooth import imsmooth
from casatasks.private.task_sdbaseline import sdbaseline
from casatasks.private.task_sdsmooth import sdsmooth
from casatasks.private.update_spw import sets_to_spwchan, spwchan_to_sets
from casatools import image, quanta, table
IMAGE_STACK_MAX_HEIGHT = 5
do_not_erase_temporary_files = False
"""Abstract class has Image/MeasurementSet file path.
This class and child classes are wrapper of CasaImage/MeasurementSet file.
The wrapped path could be decided to erase by which child classes are implemented.
def __init__(self, file: str = None) -> None:
"""Initialize a Folder object."""
if not os.path.exists(file):
raise ValueError(f'file {file} is not found')
"""Erase the file pointed path."""
raise RuntimeError('Not implemented')
class _EraseableFolder(AbstractFolder):
"""Image/MeasurementSet file path class. The file path is permitted to erase."""
def __init__(self, file: str = None) -> None:
_eraseable_folder_register.register(self)
def erase(self, dry_run: bool = True) -> None:
casalog.post(f'[DRY RUN] erase file: {self.path}', 'DEBUG2')
casalog.post(f'erase file: {self.path}', 'DEBUG2')
if os.path.exists(self.path):
if not os.path.exists(self.path):
casalog.post(f'not found the file to erase: {self.path}', 'WARN')
class _UnerasableFolder(AbstractFolder):
"""Image/MeasurementSet file path class. The file path is NOT permitted to erase."""
def erase(self, dry_run: bool = True) -> None:
casalog.post(f'un-erase file: {self.path}', 'DEBUG2')
class _EraseableFolderRegister():
"""Class of the register of folders that need to be erased."""
def register(self, folder: _EraseableFolder):
if isinstance(folder, _EraseableFolder) and folder.path not in self._register.keys():