Skip to content
Snippets Groups Projects

Fix script check_cas.py to check steering files + times consistence

Merged Chi-Tuân Pham requested to merge fix_check_cas into main
1 file
+ 141
183
Compare changes
  • Side-by-side
  • Inline
@@ -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,144 +160,144 @@ 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))
atmospheric_file = cas.get('BINARY ATMOSPHERIC DATA FILE')
if atmospheric_file != '' and module in ['telemac2d', 'telemac3d']:
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)
meteo_end = meteo_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 binary "
"file start at {}"
.format(start_date, meteo_start))
passed = False
if end_date > meteo_end:
print("The simulation ends at {} wheras the atmo binary "
"file ends at {}"
.format(end_date, meteo_end))
passed = False
if passed:
print(" ~> OK")
else:
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")
else:
print(" ~> Failed")
liq_bnd_file = cas.get('LIQUID BOUNDARIES FILE')
if liq_bnd_file != '' and module in ['telemac2d', 'telemac3d']:
print(' ~> Checking liquid boundaries file time coherence')
time_start, time_end, date = get_lid_date(liq_bnd_file)
liq_start = date + timedelta(seconds=time_start)
liq_end = date + timedelta(seconds=time_end)
print("Time range of the liquid boundary data {} to {}"
.format(liq_start, liq_end))
if start_date < liq_start:
print("The simulation start at {} wheras the liquid boundaries "
"file start 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 {}"
.format(end_date, liq_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
src_file = cas.get('SOURCES FILE')
if src_file != '' and module in ['telemac2d', 'telemac3d']:
print(' ~> Checking liquid boundaries file time coherence')
time_start, time_end, date = get_lid_date(src_file)
src_start = date + timedelta(seconds=time_start)
src_end = date + timedelta(seconds=time_end)
print("Time range of the source data {} to {}"
.format(src_start, src_end))
if start_date < src_start:
print("The simulation start at {} wheras the sources "
"file start at {}"
.format(start_date, src_start))
passed = False
if end_date > src_end:
print("The simulation ends at {} wheras the sources "
"file ends at {}"
.format(end_date, src_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
bnd_bin_file = cas.get('BINARY BOUNDARY DATA FILE', '')
if bnd_bin_file != '' and module in ['telemac3d']:
print(' ~> Checking atmo binary 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)
print("Time range of the atmospheric data {} to {}"
.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 {}"
.format(start_date, bnd_bin_start))
passed = False
if end_date > bnd_bin_end:
print("The simulation ends at {} wheras the binary boundary "
"file ends at {}"
.format(end_date, bnd_bin_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
if module in ['telemac2d', 'telemac3d']:
atmospheric_file = cas.get('BINARY ATMOSPHERIC DATA FILE')
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)
meteo_end = meteo_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 binary "
"file starts at {}"
.format(start_date, meteo_start))
passed = False
if end_date > meteo_end:
print("The simulation ends at {} whereas the atmo binary "
"file ends at {}"
.format(end_date, meteo_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
if module in ['telemac2d', 'telemac3d']:
ascii_meteo_file = cas.get('ASCII ATMOSPHERIC DATA FILE')
if ascii_meteo_file != '':
free_atmo = cas.get('FREE FORMAT FOR ATMOSPHERIC DATA FILE')
if free_atmo == 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(' ~> No checking atmo ascii file time coherence as free format')
if module in ['telemac2d', 'telemac3d']:
liq_bnd_file = cas.get('LIQUID BOUNDARIES FILE')
if liq_bnd_file != '':
print(' ~> Checking liquid boundaries file time coherence')
time_start, time_end, date = get_lid_date(liq_bnd_file)
liq_start = date + timedelta(seconds=time_start)
liq_end = date + timedelta(seconds=time_end)
print("Time range of the liquid boundary data {} to {}"
.format(liq_start, liq_end))
if start_date < liq_start:
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 {} whereas the liquid boundaries "
"file ends at {}"
.format(end_date, liq_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
if module in ['telemac2d', 'telemac3d']:
src_file = cas.get('SOURCES FILE')
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)
src_end = date + timedelta(seconds=time_end)
print("Time range of the source data {} to {}"
.format(src_start, src_end))
if start_date < src_start:
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 {} whereas the sources "
"file ends at {}"
.format(end_date, src_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
if module in ['telemac3d']:
bnd_bin_file = cas.get('BINARY BOUNDARY DATA FILE', '')
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)
print("Time range of the atmospheric data {} to {}"
.format(bnd_bin_start, bnd_bin_end))
if start_date < bnd_bin_start:
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 {} whereas the binary boundary "
"file ends at {}"
.format(end_date, bnd_bin_end))
passed = False
if passed:
print(" ~> OK")
else:
print(" ~> Failed")
Loading