diff --git a/CEP/Pipeline/recipes/sip/nodes/imager_prepare.py b/CEP/Pipeline/recipes/sip/nodes/imager_prepare.py index 6d75d26b47cdc028be6513f2cab2c05d773db552..95d0f73da5583672c2f499edd5d0bb0557ff4f55 100644 --- a/CEP/Pipeline/recipes/sip/nodes/imager_prepare.py +++ b/CEP/Pipeline/recipes/sip/nodes/imager_prepare.py @@ -227,6 +227,22 @@ class imager_prepare(LOFARnodeTCP): catch_segfaults(cmd, working_dir, environment, logger, cleanup = None, usageStats=self.resourceMonitor) + def _get_nchan_from_ms(self, file): + """ + Wrapper for pt call to retrieve the number of channels in a ms + + Uses Pyrap functionality throws 'random' exceptions. + """ + + # open the datasetassume same nchan for all sb + table = pt.table(file) # + + # get the data column, get description, get the + # shape, first index returns the number of channels + nchan = str(pt.tablecolumn(table, 'DATA').getdesc()["shape"][0]) + + return nchan + def _run_dppp(self, working_dir, time_slice_dir_path, slices_per_image, processed_ms_map, subbands_per_image, collected_ms_dir_name, parset, ndppp): @@ -251,6 +267,7 @@ class imager_prepare(LOFARnodeTCP): # filling with zeros ndppp_input_ms = [] nchan_known = False + for item in processed_ms_map[start_slice_range:end_slice_range]: if item.skip: ndppp_input_ms.append("SKIPPEDSUBBAND") @@ -258,16 +275,10 @@ class imager_prepare(LOFARnodeTCP): # From the first non skipped filed get the nchan if not nchan_known: try: - # Automatically average the number of channels in - # the output to 1 - # open the datasetassume same nchan for all sb - table = pt.table(item.file) # - - # get the data column, get description, get the - # shape, first index returns the number of channels - nchan_input = str( - pt.tablecolumn(table, - 'DATA').getdesc()["shape"][0]) + # We want toAutomatically average the number + # of channels in the output to 1, get the current + # nr of channels + nchan_input = self._get_nchan_from_ms(item.file) nchan_known = True # corrupt input measurement set diff --git a/CEP/Pipeline/test/recipes/nodes/imager_prepare_test.py b/CEP/Pipeline/test/recipes/nodes/imager_prepare_test.py index 35e61a823acbc5d50635faae89d9228840efb14b..d0716889161a307c33d068ff5616a5df091992c7 100644 --- a/CEP/Pipeline/test/recipes/nodes/imager_prepare_test.py +++ b/CEP/Pipeline/test/recipes/nodes/imager_prepare_test.py @@ -12,6 +12,7 @@ from lofarpipe.support.utilities import create_directory from lofarpipe.recipes.nodes.imager_prepare import imager_prepare \ as imager_prepare_node from logger import logger +from lofarpipe.support.data_map import DataMap class ImagerPrepareTestWrapper(imager_prepare_node): """ @@ -29,6 +30,9 @@ class ImagerPrepareTestWrapper(imager_prepare_node): def _dppp_call(self, working_dir, ndppp, cmd, environment): self.dppp_call_vars = (working_dir, ndppp, cmd, environment) + def _get_nchan_from_ms(self, file): + return 4 + class ImagerPrepareTest(unittest.TestCase): """ @@ -104,6 +108,11 @@ class ImagerPrepareTest(unittest.TestCase): ("lce072", "test_file_path2"), ("lce072", "test_file_path3"), ("lce072", "test_file_path4")] + + input_datamap = DataMap() + for entry in input_map: + input_datamap.append(entry) + subbands_per_image = 2 collected_ms_dir_name = "" fp = open(os.path.join(self.test_path, "parset"), 'w') @@ -115,7 +124,7 @@ class ImagerPrepareTest(unittest.TestCase): sut = ImagerPrepareTestWrapper() output = sut._run_dppp(working_dir, time_slice_dir_path, slices_per_image, - input_map, subbands_per_image, collected_ms_dir_name, parset, + input_datamap, subbands_per_image, collected_ms_dir_name, parset, ndppp) # The output should contain two timeslices ms prepended with the time_slice_dir_path @@ -127,6 +136,7 @@ class ImagerPrepareTest(unittest.TestCase): # Two parset should be written in the time_slice_dir_path parset_1_content_expected = [('replace', 'uselogger', 'True'), + ('replace', 'avg1.freqstep', '4'), ('replace', 'msin', "['test_file_path1', 'test_file_path2']"), ('replace', 'msout', '{0}'.format( os.path.join(time_slice_dir_path, "time_slice_0.dppp.ms")))] @@ -138,6 +148,7 @@ class ImagerPrepareTest(unittest.TestCase): # Two parset should be written in the time_slice_dir_path parset_2_content_expected = [('replace', 'uselogger', 'True'), + ('replace', 'avg1.freqstep', '4'), ('replace', 'msin', "['test_file_path3', 'test_file_path4']"), ('replace', 'msout', '{0}'.format( os.path.join(time_slice_dir_path, "time_slice_1.dppp.ms")))]