Skip to content
Snippets Groups Projects
Commit eed9ba20 authored by Mattia Mancini's avatar Mattia Mancini
Browse files

SSB-47: Split function in two to increase readibility

parent ee25e2f0
No related branches found
No related tags found
1 merge request!44Merge back holography to master
......@@ -5,6 +5,7 @@ import logging
from lofar.calibration.common.utils import *
import lofar.calibration.processing as processing
import sys
DEFAULT_SLEEP_TIME = 1
logger = logging.getLogger('mshologextract')
......@@ -29,7 +30,7 @@ def parse_command_line_arguments_and_set_verbose_logging(parser):
:return: the parsed arguments
:rtype: argparse.Namespace
"""
arguments=parser.parse_args()
arguments = parser.parse_args()
if arguments.v:
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG)
......@@ -64,6 +65,20 @@ def specify_command_line_arguments():
return parser
def average_by_sample(input_path, average_samples):
logger.info('Averaging %s with a sample window of %s', input_path, average_samples)
output_hds = processing.average_dataset_by_sample(input_path, average_samples)
logger.info('Averaged %s with a sample window of %s', input_path, average_samples)
return output_hds
def average_by_time_interval(input_path, time_interval):
logger.info('Averaging %s with a time sample window of %s s', input_path, time_interval)
output_hds = processing.average_dataset_by_time(input_path, time_interval)
logger.info('Averaged %s with a time sample window of %s', input_path, time_interval)
return output_hds
def preaverage_holography_dataset(input_path, output_path, average_samples, time_average_step):
"""
......@@ -79,26 +94,18 @@ def preaverage_holography_dataset(input_path, output_path, average_samples, time
' or the time average step in seconds')
raise ValueError('Both average_samples and time_average_step have been specified')
if average_samples is None and time_average_step is None:
logger.error('Neither average_samples nor time_average_step has been specified')
if average_samples is not None:
logger.info('Averaging %s with a time sample window of %s', input_path, average_samples)
output_hds = processing.average_dataset_by_sample(input_path, average_samples)
logger.info('Averaged %s with a time sample window of %s', input_path, time_average_step)
logger.info('Storing processed file %s in %s', input_path, output_path)
output_hds.store_to_file(output_path)
logger.info('Stored processed file %s in %s', input_path, output_path)
output_hds = average_by_sample(input_path, average_samples)
elif time_average_step is not None:
output_hds = average_by_time_interval(input_path, time_average_step)
else:
logger.error('Neither average_samples nor time_average_step has been specified')
raise ValueError('Neither average_samples nor time_average_step has been specified')
if time_average_step is not None:
logger.info('Averaging %s with a time sample window of %s s', input_path, time_average_step)
output_hds = processing.average_dataset_by_time(input_path, time_average_step)
logger.info('Averaged %s with a time sample window of %s', input_path, time_average_step)
logger.info('Storing processed file %s in %s', input_path, output_path)
output_hds.store_to_file(output_path)
logger.info('Stored processed file %s in %s', input_path, output_path)
logger.info('Storing processed file %s in %s', input_path, output_path)
output_hds.store_to_file(output_path)
logger.info('Stored processed file %s in %s', input_path, output_path)
if __name__ == '__main__':
main()
\ No newline at end of file
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment