diff --git a/ProcessorDeposition.py b/ProcessorDeposition.py index e460cba9e3a64e69cf5674b9bac8e61752b4a08c..d6a6e8418d17a9cb13373df4d1d22fa9b1b49274 100644 --- a/ProcessorDeposition.py +++ b/ProcessorDeposition.py @@ -1,19 +1,22 @@ #ProcessorDeposition.py '''Functions to process the deposition component.''' -import logging -import os from glob import glob +import logging from pathlib import Path +import os from string import Template +import iris +from iris.cube import CubeList + +from plotting.common.plotting_coordinator.ews_depo_disease_plotting_coordinator import EWSPlottingDepoBase + from ProcessorUtils import ( - get_only_existing_globs, - subprocess_and_log, - add_filters_to_sublogger, + get_only_existing_globs, + subprocess_and_log, + add_filters_to_sublogger, ) -from ews_postprocessing.deposition.deposition_post_processor import DepositionPostProcessor - logger = logging.getLogger('Processor.Deposition') add_filters_to_sublogger(logger) @@ -48,8 +51,19 @@ def process_in_job_dep(jobPath,status,config,component): # basic check that contents are as expected # 132 files of NAME .txt timesteps and one summary png file - if len(glob(f"{jobPath}/{file_name}/deposition_srcs_allregions_C1_T*.txt")) != 56: - msg = f"Unexpect number of deposition .txt files in input tar file. Expected 56." + # if len(glob(f"{jobPath}/{file_name}/deposition_srcs_allregions_C1_T*.txt")) != 56: + # msg = f"Unexpect number of deposition .txt files in input tar file. Expected 56." + # logger.error(msg) + # raise RuntimeError(msg) + + # basic check that contents are as expected (56 timepoints in the file) + cube_wildcard = f"{jobPath}/{file_name}/deposition_srcs_allregions*.nc" + cubes: CubeList = iris.load(cube_wildcard) + for cube in cubes: + coord = cube.coord("time") + timepoint_count = coord.shape[0] + if timepoint_count != 56: + msg = f"Unexpected number of timepoints ({timepoint_count}) in cube {cube.name()}" logger.error(msg) raise RuntimeError(msg) return @@ -92,23 +106,23 @@ def process_EWS_plotting_dep(jobPath,config): logger.info(f"Running EWS-Plotting with the following configs:\n{sys_config}\n{name_extraction_config}\n{run_config}\n{run_config_norm}\n{chart_config}") - depo_processor = DepositionPostProcessor() - depo_processor.set_param_config_files(sys_config_file_arg = sys_config, - depo_name_extraction_config_file_arg = name_extraction_config, - chart_config_file_arg = chart_config, - depo_plotting_run_config_file_arg = run_config, - depo_plotting_normalized_run_config_file_arg = run_config_norm, - name_file_wildcard_arg = name_file_wildcard, - wheat_sources_dir_arg = deposition_path, - output_dir_arg = output_dir, - issue_date_arg = config['StartString'], - extraction_file_prefix_arg = extraction_file_prefix) + depo_plotter = EWSPlottingDepoBase() + depo_plotter.set_param_config_files(sys_config_file_arg=sys_config, + depo_name_extraction_config_file_arg=name_extraction_config, + chart_config_file_arg= chart_config, + depo_plotting_run_config_file_arg=run_config, + depo_plotting_normalized_run_config_file_arg=run_config_norm, + name_file_wildcard_arg=name_file_wildcard, + wheat_sources_dir_arg=deposition_path, + output_dir_arg=output_dir, + issue_date_arg=config['StartString'], + extraction_file_prefix_arg=extraction_file_prefix) # asia/east africa env suit should not perform normalization, false gets passed here for these areas - depo_processor.name_extract_params.NORMALIZE = (normalize.upper() == "TRUE") + depo_plotter.name_extract_params.NORMALIZE = (normalize.upper() == "TRUE") - depo_processor.process() + depo_plotter.plot_depo() # check the output EWSPlottingOutputDir = f"{output_dir}/images/"