def setUpClass(cls): unittest.TestCase.setUpClass() cls._inputDir = getenv('DDFACET_TEST_DATA_DIR', './') + "/" cls._outputDir = getenv('DDFACET_TEST_OUTPUT_DIR', '/tmp/') + "/" cls._inputParsetFilename = cls._inputDir + cls.__name__ + ".parset.cfg" cls._outputParsetFilename = cls._outputDir + cls.__name__ + ".run.parset.cfg" if not path.isfile(cls._inputParsetFilename): raise RuntimeError("Default parset file %s does not exist" % cls._inputParsetFilename) p = Parset(cls._inputParsetFilename) cls._defaultParset = p cls._imagePrefix = cls._outputDir + cls.__name__ + ".run" # set up path to each ms relative to environment variable if type(p.DicoPars["Data"]["MS"]) is list: for ms in p.DicoPars["Data"]["MS"]: if path.dirname(ms) != "": raise RuntimeError("Expected only measurement set name, " "not relative or absolute path in %s" % ms) abs_ms = [cls._inputDir + ms for ms in p.DicoPars["Data"]["MS"]] cls._ms_list = abs_ms cls.setParsetOption("Data", "MS", "[" + (",".join(abs_ms)) + "]") else: ms = p.DicoPars["Data"]["MS"] if path.dirname(ms) != "": raise RuntimeError("Expected only measurement set name, " "not relative or absolute path in %s" % ms) abs_ms = cls._inputDir + ms cls._ms_list = [abs_ms] cls.setParsetOption("Data", "MS", abs_ms) ms = p.DicoPars["Predict"]["FromImage"] abs_skymodel = cls._inputDir + ms cls.setParsetOption("Predict", "FromImage", abs_skymodel) ms = p.DicoPars["Beam"]["FITSFile"] abs_beam = cls._inputDir + ms cls.setParsetOption("Beam", "FITSFile", abs_beam) # write out parset file to output directory fOutputParset = open(cls._outputParsetFilename, mode='w') cls._defaultParset.write(fOutputParset) fOutputParset.close()
def setUp(self): cname = self.__class__.__name__ self._input_dir = os.getenv('DDFACET_TEST_DATA_DIR', '/') + "/" self._output_dir = os.getenv('DDFACET_TEST_OUTPUT_DIR', '/tmp/') + "/" self._image_prefix = ''.join((self._output_dir, cname, ".run")) self._input_parset_filename = ''.join( (self._input_dir, cname, '.parset.cfg')) self._output_parset_filename = ''.join( (self._output_dir, cname, '.run.parset.cfg')) self._stdout_filename = ''.join( (self._output_dir, cname, ".run.out.log")) self._stderr_filename = ''.join( (self._output_dir, cname, ".run.err.log")) if not os.path.isfile(self._input_parset_filename): raise RuntimeError("Parset file %s does not exist" % self._input_parset_filename) self._parset = Parset(self._input_parset_filename)
def setUpClass(cls): unittest.TestCase.setUpClass() cls._inputDir = getenv('DDFACET_TEST_DATA_DIR', './') + "/" cls._outputDir = getenv('DDFACET_TEST_OUTPUT_DIR', '/tmp/') + "/" cls._refHDUList = [] cls._outHDUList = [] #Read and override default parset cls._inputParsetFilename = cls._inputDir + cls.__name__ + ".parset.cfg" cls._outputParsetFilename = cls._outputDir + cls.__name__ + ".run.parset.cfg" cls._inputLog = cls._inputDir + cls.__name__ + ".log" cls._outputLog = cls._outputDir + cls.__name__ + ".run.log" if not path.isfile(cls._inputParsetFilename): raise RuntimeError("Default parset file %s does not exist" % cls._inputParsetFilename) p = Parset(cls._inputParsetFilename) cls._defaultParset = p cls._imagePrefix = cls._outputDir + cls.__name__ + ".run" cls.setParsetOption("Output", "Name", cls._imagePrefix) # set up path to each ms relative to environment variable if type(p.DicoPars["Data"]["MS"]) is list: #MSdir can actually contain strange directives to select fields and DDIDs... so may appear invalid #for ms in p.DicoPars["Data"]["MS"]: #if path.dirname(ms) != "": # raise RuntimeError("Expected only measurement set name, " # "not relative or absolute path in %s" % ms) abs_ms = [cls._inputDir + ms for ms in p.DicoPars["Data"]["MS"]] cls.setParsetOption("Data", "MS", "[" + (",".join(abs_ms)) + "]") else: ms = p.DicoPars["Data"]["MS"] #MSdir can actually contain strange directives to select fields and DDIDs... so may appear invalid #if path.dirname(ms) != "": # raise RuntimeError("Expected only measurement set name, " # "not relative or absolute path in %s" % ms) abs_ms = cls._inputDir + ms cls.setParsetOption("Data", "MS", abs_ms) mask_name = p.DicoPars.get("Mask", {}).get("External", None) if mask_name: cls.setParsetOption("Mask", "External", cls._inputDir + mask_name) fOutputParset = open(cls._outputParsetFilename, mode='w') cls._defaultParset.write(fOutputParset) fOutputParset.close() #Build dictionary of HDUs for ref_id in cls.defineImageList(): fname = cls._inputDir + cls.__name__ + "." + ref_id + ".fits" if not path.isfile(fname): raise RuntimeError("Reference image %s does not exist" % fname) fitsHDU = fits.open(fname) cls._refHDUList.append(fitsHDU) #Setup test constants cls._maxSqErr = cls.defineMaxSquaredError() cls._thresholdMSE = cls.defMeanSquaredErrorLevel() #Run DDFacet with desired setup. Crash the test if DDFacet gives a non-zero exit code: cls._stdoutLogFile = cls._outputDir + cls.__name__ + ".run.out.log" cls._stderrLogFile = cls._outputDir + cls.__name__ + ".run.err.log" args = [ 'DDF.py', cls._outputParsetFilename, #'--Debug-APPVerbose=2', #enable if you ever need verbose logs '--Log-Boring=1', '--Output-Name=%s' % cls._imagePrefix, '--Cache-Dir=.' ] #not necessary #stdout_file = open(cls._stdoutLogFile, 'w') #stderr_file = open(cls._stderrLogFile, 'w') #with stdout_file, stderr_file: p = Popen(args, env=os.environ.copy()) #not necessary # stdout=stdout_file, # stderr=stderr_file) x = cls.timeoutsecs() delay = 1.0 timeout = int(x / delay) while p.poll() is None and timeout > 0: time.sleep(delay) timeout -= delay #timeout reached, kill process if it is still rolling ret = p.poll() if ret is None: p.kill() ret = 99 if ret == 99: raise RuntimeError("Test timeout reached. Killed process.") elif ret != 0: raise RuntimeError("DDF exited with non-zero return code %d" % ret) #Finally open up output FITS files for testing and build a dictionary of them for ref_id in cls.defineImageList(): fname = cls._outputDir + cls.__name__ + ".run." + ref_id + ".fits" if not path.isfile(fname): raise RuntimeError("Reference image %s does not exist" % fname) fitsHDU = fits.open(fname) cls._outHDUList.append(fitsHDU) #Save diffmaps for later use: for ref_id in cls.defineImageList(): fname = cls._inputDir + cls.__name__ + "." + ref_id + ".fits" compfname = cls._outputDir + cls.__name__ + ".run." + ref_id + ".fits" difffname = cls._outputDir + cls.__name__ + ".diff." + ref_id + ".fits" args = [ "fitstool.py", "-f", "--diff", "--output", difffname, fname, compfname ] subprocess.check_call(args, env=os.environ.copy())