Skip to content

Commit

Permalink
Improvements for better agreement with FC XML rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lucduron committed Jan 8, 2020
1 parent fef6a25 commit 5a7c2d1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
10 changes: 5 additions & 5 deletions crue10/data/templates/dcsp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- if branche.type == 1 %}
<DonCalcSansPrtBranchePdc NomRef="{{ branche.id }}">
<Pdc Nom="{{ branche.name_loi_LoiQPdc }}" Type="LoiQPdc">
<Commentaire>{{ branche.comment_loi }}</Commentaire>
<Commentaire>{{ branche.comment_loi|html_escape }}</Commentaire>
<EvolutionFF>
{%- for q, dz in branche.loi_QPdc %}
<PointFF>{{ q }} {{ dz }}</PointFF>
Expand Down Expand Up @@ -54,7 +54,7 @@
<QLimInf>{{ branche.QLimInf|float2str }}</QLimInf>
<QLimSup>{{ branche.QLimSup|float2str }}</QLimSup>
<Zasso Nom="{{ branche.name_loi_ZavZam }}" Type="LoiZavZam">
<Commentaire>{{ branche.comment_loi }}</Commentaire>
<Commentaire>{{ branche.comment_loi|html_escape }}</Commentaire>
<EvolutionFF>
{%- for z_am, z_av in branche.loi_ZavZam %}
<PointFF>{{ z_am }} {{ z_av }}</PointFF>
Expand All @@ -67,15 +67,15 @@
<QLimInf>{{ branche.QLimInf|float2str }}</QLimInf>
<QLimSup>{{ branche.QLimSup|float2str }}</QLimSup>
<RegimeNoye Nom="{{ branche.name_loi_QDz }}" Type="LoiQDz">
<Commentaire>{{ branche.comment_noye }}</Commentaire>
<Commentaire>{{ branche.comment_noye|html_escape }}</Commentaire>
<EvolutionFF>
{%- for q, dz in branche.loi_QDz %}
<PointFF>{{ q }} {{ dz }}</PointFF>
{%- endfor %}
</EvolutionFF>
</RegimeNoye>
<RegimeDenoye Nom="{{ branche.name_loi_QpilZam }}" Type="LoiQpilZam">
<Commentaire>{{ branche.comment_denoye }}</Commentaire>
<Commentaire>{{ branche.comment_denoye|html_escape }}</Commentaire>
<EvolutionFF>
{%- for q, zam in branche.loi_QpilZam %}
<PointFF>{{ q }} {{ zam }}</PointFF>
Expand All @@ -96,7 +96,7 @@
</ElemSeuil>
{%- endfor %}
<RegimeDenoye Nom="{{ branche.name_loi_QZam }}" Type="LoiQpilZam">
<Commentaire>{{ branche.comment_denoye }}</Commentaire>
<Commentaire>{{ branche.comment_denoye|html_escape }}</Commentaire>
<EvolutionFF>
{%- for q, zam in branche.loi_QZam %}
<PointFF>{{ q }} {{ zam }}</PointFF>
Expand Down
2 changes: 1 addition & 1 deletion crue10/data/templates/dfrt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<LoiFFs>
{%- for friction_law in friction_law_list %}
<LoiFF Nom="{{ friction_law.id }}" Type="{{ friction_law.type }}">
<Commentaire>{# Not supported #}</Commentaire>
<Commentaire>{{ friction_law.comment|html_escape }}</Commentaire>
<EvolutionFF>
{%- for z, k in friction_law.loi_Fk %}
<PointFF>{{ z }} {{ k }}</PointFF>
Expand Down
4 changes: 2 additions & 2 deletions crue10/data/templates/dptg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DonPrtGeoProfilCasiers>
{%- for profil_casier in profil_casier_list %}
<ProfilCasier Nom="{{ profil_casier.id }}">
<Commentaire>{{ profil_casier.comment }}</Commentaire>
<Commentaire>{{ profil_casier.comment|html_escape }}</Commentaire>
<Longueur>{{ profil_casier.distance }}</Longueur>
<EvolutionFF>
{%- for xt, z in profil_casier.xz %}
Expand All @@ -21,7 +21,7 @@
<DonPrtGeoProfilSections>
{%- for section in section_profil_list %}
<ProfilSection Nom="{{ section.nom_profilsection }}">
<Commentaire>{{ section.comment_profilsection }}</Commentaire>
<Commentaire>{{ section.comment_profilsection|html_escape }}</Commentaire>
{%- if section.has_fente %}
<Fente>
<LargeurFente>{{ section.fente[0] }}</LargeurFente>
Expand Down
2 changes: 1 addition & 1 deletion crue10/data/templates/etu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<Runs>
{%- for run_id, run in scenario.runs.items() %}
<Run Nom="{{ run_id }}">
<Commentaire>{{ run.metadata.Commentaire }}</Commentaire>
<Commentaire>{{ run.metadata.Commentaire|html_escape }}</Commentaire>
<AuteurCreation>{{ run.metadata.AuteurCreation }}</AuteurCreation>
<DateCreation>{{ run.metadata.DateCreation }}</DateCreation>
<AuteurDerniereModif>{{ run.metadata.AuteurDerniereModif }}</AuteurDerniereModif>
Expand Down
2 changes: 2 additions & 0 deletions crue10/emh/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FrictionLaw:
- id <str>: friction law identifier
- type <str>: friction law type
- loi_Fk <2D-array>: ndarray(dtype=float, ndim=2) with Strickler coefficient varying with elevation
- comment <str>: optional text explanation
"""

TYPES = ['FkSto', 'Fk']
Expand All @@ -45,6 +46,7 @@ def __init__(self, nom_loi_frottement, type, loi_Fk):
self.id = nom_loi_frottement
self.type = type
self.loi_Fk = loi_Fk
self.comment = ''


DEFAULT_FK_STO = FrictionLaw('FkSto_K0_0001', 'FkSto', np.array([(0.0, 0.0)]))
Expand Down
1 change: 1 addition & 0 deletions crue10/submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def _read_dfrt(self):
root = self._get_xml_root_and_set_comment('dfrt')
for loi in root.find(PREFIX + 'LoiFFs'):
friction_law = FrictionLaw(loi.get('Nom'), loi.get('Type'), parse_loi(loi))
friction_law.comment = get_optional_commentaire(loi)
self.add_friction_law(friction_law)

def _read_drso(self, filter_branch_types=None):
Expand Down
9 changes: 7 additions & 2 deletions crue10/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from jinja2 import Environment, FileSystemLoader
import logging
import os
import re
import shutil
from lxml import etree

Expand All @@ -26,7 +25,10 @@
except:
USERNAME = 'inconnu'

SELF_CLOSING_TAGS = ['IniCalcCI', 'IniCalcPrecedent', 'InterpolLineaire', 'Lois', 'OrdreDRSO']
SELF_CLOSING_TAGS = [
'IniCalcCI', 'IniCalcPrecedent', 'InterpolLineaire', 'Lois', 'OrdreDRSO',
'HydrogrammeQapp', 'Limnigramme' # dclm
]

PREFIX = "{http://www.fudaa.fr/xsd/crue}"

Expand Down Expand Up @@ -104,13 +106,16 @@ def float2str(value):
# text = format(value, '.15f')
# return re.sub(r'\.([0-9])([0]+)$', r'.\1', text) # remove ending useless zeros


def write_default_xml_file(xml_type, file_path):
shutil.copyfile(os.path.join(XML_DEFAULT_FOLDER, xml_type + '.xml'), file_path)


def get_xml_root_from_file(file_path):
with open(file_path, 'r', encoding=XML_ENCODING) as in_xml:
content = ''.join(in_xml.readlines())
if not isinstance(content, str): # Python2 fix on Linux
content = content.encode(XML_ENCODING)
return etree.fromstring(content)


Expand Down
32 changes: 26 additions & 6 deletions snippets/read_studies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# coding: utf-8
"""
Lecture d'études Crue10 et vérification des fichiers XML
Bilan des différentes modifications du texte des fichiers introduites par le passage dans Crue10_tools.
# BE2016_conc
OK
# Etu_BV2016_Conc_Etatref - ISfonds2016_K2016
- dlhy: &apos; => '
- drso: some empty `Commentaire` tags appear as they were missing
# GE2009_Conc
- dclm: &apos; => '
(With Python2 on Linux: drso: some Xp are truncated)
# VA2018_Conc
OK (sauf copie manquante des fichiers orphelins)
(With Python2 on Linux: drso: some Xp are truncated)
"""
from glob import glob
import os.path
Expand All @@ -9,21 +26,24 @@
from crue10.utils import CrueError, logger


for folder in glob(os.path.join('..', '..', 'Crue10_examples', 'Cas-tests', '*')):
for folder in glob(os.path.join('..', '..', 'Crue10_examples', 'Etudes-tests', '*')):
for etu_path in glob(os.path.join(folder, '*.etu.xml')):
logger.info(etu_path)
try:
study = Study(etu_path)
study.check_xml_files()
try:
study.check_xml_files()
except IOError: # avoid some Crue9 missing files in `Etu_BV2016_Conc_Etatref - ISfonds2016_K2016`
pass
study.read_all()

# Write study
out_folder = os.path.join('../tmp/Cas-tests', os.path.basename(etu_path)[:-8])
# Write study (to check in integrity, see difference in file docstring above)
out_folder = os.path.join('../tmp/Etudes-tests', os.path.basename(folder))
study.write_all(out_folder)

# Write topographical graph for each model
for _, model in study.models.items():
model.write_topological_graph([os.path.join(out_folder, model.id + '.png')])
# for _, model in study.models.items():
# model.write_topological_graph([os.path.join(out_folder, model.id + '.png')])

except CrueError as e:
logger.critical(e)

0 comments on commit 5a7c2d1

Please sign in to comment.