Source
"""Bloutput Test 013: default values for all parameters except blfunc=variable, blparam='analytic_variable_blparam.txt', blformat=['csv','text','table'], and bloutput=['test.csv','test.txt','test.table']"""
import contextlib
import filecmp
import glob
import numpy as np
import os
import shutil
import unittest
from casatasks import sdbaseline
from casatasks.private.sdutil import table_manager
from casatasks.private.task_sdbaseline import check_fftthresh, is_empty, parse_wavenumber_param
from casatestutils import selection_syntax
from casatools import ctsys, table
tb = table()
ctsys_resolve = ctsys.resolve
# default is necessary in CASA6
def default(atask):
pass
### Utilities for reading blparam file
class FileReader(object):
def __init__(self, filename):
self.__filename = filename
self.__data = None
self.__nline = None
def read(self):
if self.__data is None:
f = open(self.__filename, 'r')
self.__data = f.readlines()
f.close()
self.__nline = len(self.__data)
return
def nline(self):
self.read()
return self.__nline
def index(self, txt, start):
return self.__data[start:].index(txt) + 1 + start
def getline(self, idx):
return self.__data[idx]
class BlparamFileParser(FileReader):
def __init__(self, blfile):
FileReader.__init__(self, blfile)
self.__nrow = None
self.__coeff = None
self.__rms = None
self.__ctxt = 'Baseline parameters\n'
self.__rtxt = 'Results of baseline fit\n'
def nrow(self):
self.read()
if self.__nrow is None:
return self._nrow()
else:
return self.__nrow
def coeff(self):
self.read()
if self.__coeff is None:
self.parseCoeff()
return self.__coeff
def rms(self):
self.read()
if self.__rms is None:
self.parseRms()
return self.__rms
def _nrow(self):
self.__nrow = 0
for i in range(self.nline()):
if self.getline(i) == self.__ctxt:
self.__nrow += 1
return self.__nrow
def parse(self):
self.read()
self.parseCoeff()
self.parseRms()
return
def parseCoeff(self):