diff --git a/NEWS.txt b/NEWS.txt index 84d80f33567a7831f9875bd578894760b8cfa50b..4ec8d4a1b8d99b40130f24c221e991ded8a717cd 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,6 +1,9 @@ Latest changes ============== +Python: fix several bugs when using manip_cas.py script to check steering files +and time consistence with input files + HERMES: read boundary information in MED files regardless of the presence or not of a boundary conditions file diff --git a/scripts/python3/pretel/check_cas.py b/scripts/python3/pretel/check_cas.py index 6cdefb2b776707a1e957635eeffd17970eee33ec..a84d9da5629406cdaf2aa1174ca22472446214b3 100644 --- a/scripts/python3/pretel/check_cas.py +++ b/scripts/python3/pretel/check_cas.py @@ -5,7 +5,6 @@ from datetime import datetime, timedelta import re import numpy as np from data_manip.extraction.telemac_file import TelemacFile -from utils.exceptions import TelemacException def check_cas(module, cas): """ @@ -45,16 +44,16 @@ def get_simulation_date(module, cas): ntimestep = max(ntimestep, int(duration/time_step + 0.5)) - previous_comp = cas.get('COMPUTATION CONTINUED') + previous_file = cas.get("PREVIOUS COMPUTATION FILE") tel_date = get_cas_date(module, cas) - if previous_comp: + if previous_file != '': # Get time from previous computation file - previous_file = cas.get("PREVIOUS COMPUTATION FILE") record_prev = cas.get('RECORD NUMBER FOR RESTART') # Record are starting from 0 in python 1 n the steering file - # 0 in steering file means last time step - record_prev -= 1 + # -1 in steering file means last time step + if record_prev != -1: + record_prev -= 1 date, _, time = get_file_date(previous_file, last=record_prev) start_date = date + timedelta(seconds=time) else: @@ -152,47 +151,6 @@ def get_lid_date(file_name): return time_start, time_end, date -def check_previous_comp(module, cas, comp_cont="COMPUTATION CONTINUED", - prev_file="PREVIOUS COMPUTATION FILE"): - """ - Check for compuration continued - """ - # Checking that same date in steering file and previous computation file - previous_comp = cas.get(comp_cont) - - - if previous_comp: - print(" ~> Checking {} coherence".format(comp_cont.lower())) - - tel_date = get_cas_date(module, cas) - reset_time = cas.get('INITIAL TIME SET TO ZERO') - record_prev = cas.get('RECORD NUMBER FOR RESTART') - # Record are starting from 0 in python 1 n the steering file - # 0 in steering file means last time step - record_prev -= 1 - - previous_file = cas.get(prev_file) - prev_date, _, end = get_file_date(previous_file, last=record_prev) - - prev_date = prev_date + timedelta(seconds=end) - - - if not reset_time: - tel_date = tel_date + timedelta(seconds=end) - - if tel_date != prev_date: - raise TelemacException( - "Warning:\nMissmatch between previous computation date ({}) " - "and steering file date ({})\n" - "The good values should be:\n" - "if reset time to zero:\n" - "steering date = previous_file date + last_timestep" - "else\n" - "steering date = previous_file date" - .format(prev_date, tel_date)) - - - def check_time(module, cas): """ Checking time coherence between input files and steering file info @@ -202,21 +160,16 @@ def check_time(module, cas): passed = True - if module in ['telemac2d', 'telemac3d']: - check_previous_comp(module, cas) - - if module == 'telemac3d': - # Checkgin for 2d continuation - check_previous_comp(module, cas, comp_cont="2D CONTINUATION", - prev_file="FILE FOR 2D CONTINUATION") - print(" ~> Displaying simulation date") start_date, end_date = get_simulation_date(module, cas) print("Starting date: {}".format(start_date)) print("Ending date: {}".format(end_date)) + if module not in ['telemac2d', 'telemac3d']: + return + atmospheric_file = cas.get('BINARY ATMOSPHERIC DATA FILE') - if atmospheric_file != '' and module in ['telemac2d', 'telemac3d']: + if atmospheric_file != '': print(' ~> Checking atmo binary file time coherence') meteo_date, time_start, time_end = get_file_date(atmospheric_file) meteo_start = meteo_date + timedelta(seconds=time_start) @@ -225,12 +178,12 @@ def check_time(module, cas): .format(meteo_start, meteo_end)) if start_date < meteo_start: - print("The simulation start at {} wheras the atmo binary " - "file start at {}" + print("The simulation starts at {} whereas the atmo binary " + "file starts at {}" .format(start_date, meteo_start)) passed = False if end_date > meteo_end: - print("The simulation ends at {} wheras the atmo binary " + print("The simulation ends at {} whereas the atmo binary " "file ends at {}" .format(end_date, meteo_end)) passed = False @@ -241,33 +194,37 @@ def check_time(module, cas): print(" ~> Failed") ascii_meteo_file = cas.get('ASCII ATMOSPHERIC DATA FILE') - if ascii_meteo_file != '' and module in ['telemac2d', 'telemac3d']: - print(' ~> Checking atmo ascii file time coherence') - time_start, time_end, date = get_lid_date(ascii_meteo_file) - - meteo_start = date + timedelta(seconds=time_start) - meteo_end = date + timedelta(seconds=time_end) - print("Time range of the atmospheric data {} to {}" - .format(meteo_start, meteo_end)) - - if start_date < meteo_start: - print("The simulation start at {} wheras the atmo ascii " - "file start at {}" - .format(start_date, meteo_start)) - passed = False - if end_date > meteo_end: - print("The simulation ends at {} wheras the atmo ascii " - "file ends at {}" - .format(end_date, meteo_end)) - passed = False - - if passed: - print(" ~> OK") + if ascii_meteo_file != '': + free_atmo = cas.get('FREE FORMAT FOR ATMOSPHERIC DATA FILE') + if free_atmo is False: + print(' ~> Checking atmo ascii file time coherence') + time_start, time_end, date = get_lid_date(ascii_meteo_file) + + meteo_start = date + timedelta(seconds=time_start) + meteo_end = date + timedelta(seconds=time_end) + print("Time range of the atmospheric data {} to {}" + .format(meteo_start, meteo_end)) + + if start_date < meteo_start: + print("The simulation starts at {} whereas the atmo ascii " + "file starts at {}" + .format(start_date, meteo_start)) + passed = False + if end_date > meteo_end: + print("The simulation ends at {} whereas the atmo ascii " + "file ends at {}" + .format(end_date, meteo_end)) + passed = False + + if passed: + print(" ~> OK") + else: + print(" ~> Failed") else: - print(" ~> Failed") + print(' ~> No checking atmo ascii file time coherence as free format') liq_bnd_file = cas.get('LIQUID BOUNDARIES FILE') - if liq_bnd_file != '' and module in ['telemac2d', 'telemac3d']: + if liq_bnd_file != '': print(' ~> Checking liquid boundaries file time coherence') time_start, time_end, date = get_lid_date(liq_bnd_file) @@ -277,13 +234,13 @@ def check_time(module, cas): .format(liq_start, liq_end)) if start_date < liq_start: - print("The simulation start at {} wheras the liquid boundaries " - "file start at {}" + print("The simulation starts at {} whereas the liquid boundaries " + "file starts at {}" .format(start_date, liq_start)) passed = False if end_date > liq_end: - print("The simulation ends at {} wheras the liquid boundaries " - "file ends at {}" + print("The simulation ends at {} whereas the liquid boundaries " + "file ends at {}" .format(end_date, liq_end)) passed = False @@ -292,10 +249,9 @@ def check_time(module, cas): else: print(" ~> Failed") - src_file = cas.get('SOURCES FILE') - if src_file != '' and module in ['telemac2d', 'telemac3d']: - print(' ~> Checking liquid boundaries file time coherence') + if src_file != '': + print(' ~> Checking sources file time coherence') time_start, time_end, date = get_lid_date(src_file) src_start = date + timedelta(seconds=time_start) @@ -304,12 +260,12 @@ def check_time(module, cas): .format(src_start, src_end)) if start_date < src_start: - print("The simulation start at {} wheras the sources " - "file start at {}" + print("The simulation starts at {} whereas the sources " + "file starts at {}" .format(start_date, src_start)) passed = False if end_date > src_end: - print("The simulation ends at {} wheras the sources " + print("The simulation ends at {} whereas the sources " "file ends at {}" .format(end_date, src_end)) passed = False @@ -319,9 +275,12 @@ def check_time(module, cas): else: print(" ~> Failed") + if module != 'telemac3d': + return + bnd_bin_file = cas.get('BINARY BOUNDARY DATA FILE', '') - if bnd_bin_file != '' and module in ['telemac3d']: - print(' ~> Checking atmo binary file time coherence') + if bnd_bin_file != '': + print(' ~> Checking binary boundary file time coherence') bnd_bin_date, time_start, time_end = get_file_date(bnd_bin_file) bnd_bin_start = bnd_bin_date + timedelta(seconds=time_start) bnd_bin_end = bnd_bin_date + timedelta(seconds=time_end) @@ -329,12 +288,12 @@ def check_time(module, cas): .format(bnd_bin_start, bnd_bin_end)) if start_date < bnd_bin_start: - print("The simulation start at {} wheras the binary boundary" - "file start at {}" + print("The simulation starts at {} whereas the binary boundary" + "file starts at {}" .format(start_date, bnd_bin_start)) passed = False if end_date > bnd_bin_end: - print("The simulation ends at {} wheras the binary boundary " + print("The simulation ends at {} whereas the binary boundary " "file ends at {}" .format(end_date, bnd_bin_end)) passed = False