diff --git a/NEWS.txt b/NEWS.txt index 690af010e7282daa8470439631a46ea14ac593e3..14bbc2d090b39dde091e81953713f30773e22d79 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,5 +1,11 @@ Latest developments on main =========================== +Python: Add features to MascaretGeoFile class: + - reading topo-bathy information, + - reading sediment layers in Courlis geometry files, + - new method to generate GIS file formatted for PreCourlis QGIS plugin. +Modification of Section (class of mascaret_file.py) to store topo-bathy data + GAIA: new user subroutines for settling velocities and hindered formulations. TOMAWAC: Default value of keyword STATIONARY WIND is changed to .FALSE. diff --git a/notebooks/postel/example_courlis.ipynb b/notebooks/postel/example_courlis.ipynb index aa06118c96e9087454eb87b4be9315fb0f982eed..ef305bd3545c21725aa35accff47cc931b024eca 100644 --- a/notebooks/postel/example_courlis.ipynb +++ b/notebooks/postel/example_courlis.ipynb @@ -54,190 +54,136 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - "\r\n", - "Loading Options and Configurations\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - " _ \r\n", - " (_) \r\n", - " _ __ ___ __ _ _ _ __ \r\n", - " | '_ ` _ \\ / _` || || '_ \\ \r\n", - " | | | | | || (_| || || | | |\r\n", - " |_| |_| |_| \\__,_||_||_| |_|\r\n", - " \r\n", - " \r\n", - "\r\n", - "\r\n", - "Running your CAS file(s) for:\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "S10.gfortran.dyn: \r\n", - " \r\n", - "\r\n", - " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\r\n", - "\r\n", - " +> root: /home/d60881/telemac-mascaret\r\n", - " +> module: ad / api / artemis / bief\r\n", - " damocles / gaia / gretel / hermes\r\n", - " identify_liq_bnd / khione / mascaret / nestor\r\n", - " parallel / partel / postel3d / sisyphe\r\n", - " special / stbtel / telemac2d / telemac3d\r\n", - " tomawac / waqtel\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "... processing the steering file\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - "... checking parallelisation\r\n", - "\r\n", - "... handling temporary directories\r\n", - "~+> Creating FichierCas.txt\r\n", - "[ ] 0% | ---s\r", - " \r", - "[ ] 0% | ---s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 25% | 1s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 50% | 1s\r", - " \r", - "\r\n", - "... checking the executable\r\n", - "\r\n", - "\r\n", - "Running your simulation(s) :\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "In /home/d60881/telemac-mascaret/examples/courlis/Soni:\r\n", - "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\r\n", - "\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Fichiercas : FichierCas.txt\r\n", - "\r\n", - " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\r\n", - "\r\n", - " Data File : sarap.xcas\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Clip Evolution = 0.5000E-01\r\n", - "\r\n", - " Pente locale : F\r\n", - "\r\n", - " Attention, diametres nuls ou non renseignes dans le fichier cas\r\n", - " Utilisation de formules a partir du d50 pour determiner les diametres ci-dessous :\r\n", - "\r\n", - " Parametres utilises seulement pour les formules de transport de Recking et de Lefort\r\n", - " D84 = 0.6720E-03\r\n", - " Diametre moyen = 0.3520E-03\r\n", - "\r\n", - " Parametre utilise seulement pour la formule de transport de Lefort\r\n", - " D16 = 0.1600E-03\r\n", - "\r\n", - " Bedload option : T\r\n", - "\r\n", - " Suspension option : F\r\n", - "\r\n", - " sediment slide option : F\r\n", - "\r\n", - " planim clipping option : F\r\n", - "\r\n", - " absolute clipping = 0.1000E-04\r\n", - " 1\r\n", - "\r\n", - " bedload transport law is Meyer-Peter-Mueller\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Study name : Etude hydraulique1d\r\n", - "\r\n", - " Hydraulic statistics (prior solve phase)\r\n", - " ------ Geometric parameters ------\r\n", - " Number of reach(es) = 1\r\n", - " Number of cross-sections = 121\r\n", - " Number of open boundaries = 2\r\n", - " Number of junction(s) = 0\r\n", - " Number of inflow(s) = 0\r\n", - " Number of lateral weir(s) = 0\r\n", - " Number of storage area(s) = 0\r\n", - " Number of link(s) = 0\r\n", - " Number of dam(s)/weir(s) = 0\r\n", - " ------ Numerical parameters ------\r\n", - " Number of 1D nodes (mesh) = 121\r\n", - " Computation Kernel = 1\r\n", - " Initial time step = 5.0E-01\r\n", - " Variable time step? = 0\r\n", - " Simulation time = 5.4E+03\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " OptionCourlis T\r\n", - " Start the Simulation...\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Simulation ended successfully in 9.67529964 s\r\n", - " Simulation ended successfully in 9.67544079 s\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - " CPT_PLANIM = 125731\r\n", - " TEMPS PASSE 9.68791866\r\n", - " FIN CORRECTE DU CALCUL\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "... merging separated result files\r\n", - "\r\n", - "... handling result files\r\n", - "\r\n", - "... deleting working dir\r\n", - "\r\n", - "\r\n", - "\r\n", - "My work is done\r\n", - "\r\n", - "\r\n" + "\n", + "\n", + "Loading Options and Configurations\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + " _ \n", + " (_) \n", + " _ __ ___ __ _ _ _ __ \n", + " | '_ ` _ \\ / _` || || '_ \\ \n", + " | | | | | || (_| || || | | |\n", + " |_| |_| |_| \\__,_||_||_| |_|\n", + " \n", + " \n", + "\n", + "\n", + "Running your CAS file(s) for:\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "S10.gfortran.dyn: \n", + " \n", + "\n", + " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\n", + "\n", + " +> root: /home/d60881/telemac-mascaret\n", + " +> module: ad / api / artemis / bief\n", + " damocles / gaia / gretel / hermes\n", + " identify_liq_bnd / khione / mascaret / nestor\n", + " parallel / partel / postel3d / sisyphe\n", + " special / stbtel / telemac2d / telemac3d\n", + " tomawac / waqtel\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "... processing the steering file\n", + "\n", + "... checking parallelisation\n", + "\n", + "... handling temporary directories\n", + "~+> Creating FichierCas.txt\n", + " \n", + "... checking the executable\n", + "\n", + "\n", + "Running your simulation(s) :\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "In /home/d60881/telemac-mascaret/examples/courlis/Soni:\n", + "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\n", + "\n", + "\n", + " Fichiercas : FichierCas.txt\n", + "\n", + " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\n", + "\n", + " Data File : sarap.xcas\n", + "\n", + " Clip Evolution = 0.5000E-01\n", + "\n", + " Pente locale : F\n", + "\n", + " Attention, diametres nuls ou non renseignes dans le fichier cas\n", + " Utilisation de formules a partir du d50 pour determiner les diametres ci-dessous :\n", + "\n", + " Parametres utilises seulement pour les formules de transport de Recking et de Lefort\n", + " D84 = 0.6720E-03\n", + " Diametre moyen = 0.3520E-03\n", + "\n", + " Parametre utilise seulement pour la formule de transport de Lefort\n", + " D16 = 0.1600E-03\n", + "\n", + " Bedload option : T\n", + "\n", + " Suspension option : F\n", + "\n", + " sediment slide option : F\n", + "\n", + " planim clipping option : F\n", + "\n", + " absolute clipping = 0.1000E-04\n", + " 1\n", + "\n", + " bedload transport law is Meyer-Peter-Mueller\n", + " Study name : Etude hydraulique1d\n", + "\n", + " Hydraulic statistics (prior solve phase)\n", + " ------ Geometric parameters ------\n", + " Number of reach(es) = 1\n", + " Number of cross-sections = 121\n", + " Number of open boundaries = 2\n", + " Number of junction(s) = 0\n", + " Number of inflow(s) = 0\n", + " Number of lateral weir(s) = 0\n", + " Number of storage area(s) = 0\n", + " Number of link(s) = 0\n", + " Number of dam(s)/weir(s) = 0\n", + " ------ Numerical parameters ------\n", + " Number of 1D nodes (mesh) = 121\n", + " Computation Kernel = 1\n", + " Initial time step = 5.0E-01\n", + " Variable time step? = 0\n", + " Simulation time = 5.4E+03\n", + "\n", + " OptionCourlis T\n", + " Start the Simulation...\n", + " Simulation ended successfully in 9.67529964 s\n", + " Simulation ended successfully in 9.67544079 s\n", + "\n", + " CPT_PLANIM = 125731\n", + " TEMPS PASSE 9.68791866\n", + " FIN CORRECTE DU CALCUL\n", + "\n", + "... merging separated result files\n", + "\n", + "... handling result files\n", + "\n", + "... deleting working dir\n", + "\n", + "\n", + "\n", + "My work is done\n", + "\n", + "\n" ] } ], @@ -265,183 +211,141 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - "\r\n", - "Loading Options and Configurations\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - " _ \r\n", - " (_) \r\n", - " _ __ ___ __ _ _ _ __ \r\n", - " | '_ ` _ \\ / _` || || '_ \\ \r\n", - " | | | | | || (_| || || | | |\r\n", - " |_| |_| |_| \\__,_||_||_| |_|\r\n", - " \r\n", - " \r\n", - "\r\n", - "\r\n", - "Running your CAS file(s) for:\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "S10.gfortran.dyn: \r\n", - " \r\n", - "\r\n", - " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\r\n", - "\r\n", - " +> root: /home/d60881/telemac-mascaret\r\n", - " +> module: ad / api / artemis / bief\r\n", - " damocles / gaia / gretel / hermes\r\n", - " identify_liq_bnd / khione / mascaret / nestor\r\n", - " parallel / partel / postel3d / sisyphe\r\n", - " special / stbtel / telemac2d / telemac3d\r\n", - " tomawac / waqtel\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "... processing the steering file\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - "... checking parallelisation\r\n", - "\r\n", - "... handling temporary directories\r\n", - "~+> Creating FichierCas.txt\r\n", - "~+> Copying Abaques.txt\r\n", - "~+> Copying Controle.txt\r\n", - "~+> Copying dico_Courlis.txt\r\n", - "[ ] 0% | ---s\r", - " \r", - "[ ] 0% | ---s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 25% | 1s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 50% | 1s\r", - " \r", - "\r\n", - "... checking the executable\r\n", - "\r\n", - "\r\n", - "Running your simulation(s) :\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "In /home/d60881/telemac-mascaret/examples/courlis/Garonne:\r\n", - "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\r\n", - "\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Fichiercas : FichierCas.txt\r\n", - "\r\n", - " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\r\n", - "\r\n", - " Data File : hydro_Torr.xcas\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Clip Evolution = 0.5000E-01\r\n", - "\r\n", - " Pente locale : F\r\n", - "\r\n", - " Attention, diametres nuls ou non renseignes dans le fichier cas\r\n", - " Utilisation de formules a partir du d50 pour determiner les diametres ci-dessous :\r\n", - "\r\n", - " Parametres utilises seulement pour les formules de transport de Recking et de Lefort\r\n", - " D84 = 0.2100E+01\r\n", - " Diametre moyen = 0.1100E+01\r\n", - "\r\n", - " Parametre utilise seulement pour la formule de transport de Lefort\r\n", - " D16 = 0.5000E+00\r\n", - "\r\n", - " Bedload option : F\r\n", - "\r\n", - " Suspension option : T\r\n", - "\r\n", - " sediment slide option : F\r\n", - "\r\n", - " planim clipping option : F\r\n", - "\r\n", - " absolute clipping = 0.1000E-04\r\n", - " 1\r\n", - "\r\n", - " bedload transport law is Meyer-Peter-Mueller\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Study name : Etude hydraulique1d\r\n", - "\r\n", - " Hydraulic statistics (prior solve phase)\r\n", - " ------ Geometric parameters ------\r\n", - " Number of reach(es) = 1\r\n", - " Number of cross-sections = 103\r\n", - " Number of open boundaries = 2\r\n", - " Number of junction(s) = 0\r\n", - " Number of inflow(s) = 0\r\n", - " Number of lateral weir(s) = 0\r\n", - " Number of storage area(s) = 0\r\n", - " Number of link(s) = 0\r\n", - " Number of dam(s)/weir(s) = 0\r\n", - " ------ Numerical parameters ------\r\n", - " Number of 1D nodes (mesh) = 103\r\n", - " Computation Kernel = 3\r\n", - " Initial time step = 1.0E+00\r\n", - " Variable time step? = 0\r\n", - " Implicit Scheme? = 0\r\n", - " Non Hydrostatic? = 0\r\n", - " Simulation time = 3.0E+03\r\n", - "\r\n", - " OptionCourlis T\r\n", - " Start the Simulation...\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Simulation ended successfully in 3.20090008 s\r\n", - " Simulation ended successfully in 3.20156407 s\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - " CPT_PLANIM = 13020\r\n", - " TEMPS PASSE 3.26590896\r\n", - " FIN CORRECTE DU CALCUL\r\n", - "\r\n", - "... merging separated result files\r\n", - "\r\n", - "... handling result files\r\n", - "\r\n", - "... deleting working dir\r\n", - "\r\n", - "\r\n", - "\r\n", - "My work is done\r\n", - "\r\n", - "\r\n" + "\n", + "\n", + "Loading Options and Configurations\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + " _ \n", + " (_) \n", + " _ __ ___ __ _ _ _ __ \n", + " | '_ ` _ \\ / _` || || '_ \\ \n", + " | | | | | || (_| || || | | |\n", + " |_| |_| |_| \\__,_||_||_| |_|\n", + " \n", + " \n", + "\n", + "\n", + "Running your CAS file(s) for:\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "S10.gfortran.dyn: \n", + " \n", + "\n", + " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\n", + "\n", + " +> root: /home/d60881/telemac-mascaret\n", + " +> module: ad / api / artemis / bief\n", + " damocles / gaia / gretel / hermes\n", + " identify_liq_bnd / khione / mascaret / nestor\n", + " parallel / partel / postel3d / sisyphe\n", + " special / stbtel / telemac2d / telemac3d\n", + " tomawac / waqtel\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "... processing the steering file\n", + "\n", + "... checking parallelisation\n", + "\n", + "... handling temporary directories\n", + "~+> Creating FichierCas.txt\n", + "~+> Copying Abaques.txt\n", + "~+> Copying Controle.txt\n", + "~+> Copying dico_Courlis.txt\n", + " \n", + "... checking the executable\n", + "\n", + "\n", + "Running your simulation(s) :\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "In /home/d60881/telemac-mascaret/examples/courlis/Garonne:\n", + "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\n", + "\n", + "\n", + " Fichiercas : FichierCas.txt\n", + "\n", + " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\n", + "\n", + " Data File : hydro_Torr.xcas\n", + "\n", + " Clip Evolution = 0.5000E-01\n", + "\n", + " Pente locale : F\n", + "\n", + " Attention, diametres nuls ou non renseignes dans le fichier cas\n", + " Utilisation de formules a partir du d50 pour determiner les diametres ci-dessous :\n", + "\n", + " Parametres utilises seulement pour les formules de transport de Recking et de Lefort\n", + " D84 = 0.2100E+01\n", + " Diametre moyen = 0.1100E+01\n", + "\n", + " Parametre utilise seulement pour la formule de transport de Lefort\n", + " D16 = 0.5000E+00\n", + "\n", + " Bedload option : F\n", + "\n", + " Suspension option : T\n", + "\n", + " sediment slide option : F\n", + "\n", + " planim clipping option : F\n", + "\n", + " absolute clipping = 0.1000E-04\n", + " 1\n", + "\n", + " bedload transport law is Meyer-Peter-Mueller\n", + " Study name : Etude hydraulique1d\n", + "\n", + " Hydraulic statistics (prior solve phase)\n", + " ------ Geometric parameters ------\n", + " Number of reach(es) = 1\n", + " Number of cross-sections = 103\n", + " Number of open boundaries = 2\n", + " Number of junction(s) = 0\n", + " Number of inflow(s) = 0\n", + " Number of lateral weir(s) = 0\n", + " Number of storage area(s) = 0\n", + " Number of link(s) = 0\n", + " Number of dam(s)/weir(s) = 0\n", + " ------ Numerical parameters ------\n", + " Number of 1D nodes (mesh) = 103\n", + " Computation Kernel = 3\n", + " Initial time step = 1.0E+00\n", + " Variable time step? = 0\n", + " Implicit Scheme? = 0\n", + " Non Hydrostatic? = 0\n", + " Simulation time = 3.0E+03\n", + "\n", + " OptionCourlis T\n", + " Start the Simulation...\n", + " Simulation ended successfully in 3.20090008 s\n", + " Simulation ended successfully in 3.20156407 s\n", + "\n", + " CPT_PLANIM = 13020\n", + " TEMPS PASSE 3.26590896\n", + " FIN CORRECTE DU CALCUL\n", + "\n", + "... merging separated result files\n", + "\n", + "... handling result files\n", + "\n", + "... deleting working dir\n", + "\n", + "\n", + "\n", + "My work is done\n", + "\n", + "\n" ] } ], @@ -2020,7 +1924,7 @@ "\n", " for j in range(nlayers):\n", " thickness_table = layers_elevation[1][i][j+1] - layers_elevation[1][i][j+2]\n", - " section.add_layer(thickness_table)\n", + " section.add_layer_from_thickness(thickness_table)\n", "\n", " reach.add_section(section)\n", "\n", @@ -16709,7 +16613,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, diff --git a/notebooks/postel/example_mascaret.ipynb b/notebooks/postel/example_mascaret.ipynb index 7b285a1497208ce63c92d77440d957c54ae1d942..4063278e123307a780dcf1a1c7eaba9c4dad99ad 100644 --- a/notebooks/postel/example_mascaret.ipynb +++ b/notebooks/postel/example_mascaret.ipynb @@ -31,7 +31,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "~> MascaretGeoFile: /home/d60881/telemac-mascaret/examples/mascaret/Test6/geometrie\n", + "~> MascaretGeoFile: /home/A54371/TELEMAC/dev/telemac-mascaret/examples/mascaret/Test6/geometrie\n", " - Reach #1 (Bief_1) with 30 sections\n", " 1) Section #1 (prof1_1) at pk 0.000000\n", " 2) Section #2 (prof1_2) at pk 50.000000\n", @@ -64,7 +64,7 @@ " 29) Section #29 (prof1_29) at pk 1000.000000\n", " 30) Section #30 (prof1_30) at pk 1500.000000\n", "\n", - "~> MascaretGeoFile: /home/d60881/telemac-mascaret/examples/mascaret/Test15/mascaret0.geo\n", + "~> MascaretGeoFile: /home/A54371/TELEMAC/dev/telemac-mascaret/examples/mascaret/Test15/mascaret0.geo\n", " - Reach #1 (Bief_1) with 2 sections\n", " 1) Section #1 (PK1) at pk 0.000000\n", " 2) Section #2 (PK1bis) at pk 6.800000\n", @@ -85,7 +85,7 @@ "# File with a single reach\n", "mascgeo_file = MascaretGeoFile(os.path.join(os.environ['HOMETEL'],\n", " 'examples', 'mascaret', 'Test6', 'geometrie'),\n", - " 'geo')\n", + " fformat='geo')\n", "print(mascgeo_file.summary())\n", "\n", "# File with multiples reaches\n", @@ -125,140 +125,110 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - "\r\n", - "Loading Options and Configurations\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - " _ \r\n", - " (_) \r\n", - " _ __ ___ __ _ _ _ __ \r\n", - " | '_ ` _ \\ / _` || || '_ \\ \r\n", - " | | | | | || (_| || || | | |\r\n", - " |_| |_| |_| \\__,_||_||_| |_|\r\n", - " \r\n", - " \r\n", - "\r\n", - "\r\n", - "Running your CAS file(s) for:\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "S10.gfortran.dyn: \r\n", - " \r\n", - "\r\n", - " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\r\n", - "\r\n", - " +> root: /home/d60881/telemac-mascaret\r\n", - " +> module: ad / api / artemis / bief\r\n", - " damocles / gaia / gretel / hermes\r\n", - " identify_liq_bnd / khione / mascaret / nestor\r\n", - " parallel / partel / postel3d / sisyphe\r\n", - " special / stbtel / telemac2d / telemac3d\r\n", - " tomawac / waqtel\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "... processing the steering file\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - "... checking parallelisation\r\n", - "\r\n", - "... handling temporary directories\r\n", - "~+> Creating FichierCas.txt\r\n", - "~+> Copying Abaques.txt\r\n", - "~+> Copying Controle.txt\r\n", - "~+> Copying dico_Courlis.txt\r\n", - "[ ] 0% | ---s\r", - " \r", - "[ ] 0% | ---s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 25% | 1s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 50% | 1s\r", - " \r", - "\r\n", - "... checking the executable\r\n", - "\r\n", - "\r\n", - "Running your simulation(s) :\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "In /home/d60881/telemac-mascaret/examples/mascaret/Test18:\r\n", - "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\r\n", - "\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Fichiercas : FichierCas.txt\r\n", - "\r\n", - " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\r\n", - "\r\n", - " Data File : sarap.xcas\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Study name : deversoir\r\n", - "\r\n", - " Hydraulic statistics (prior solve phase)\r\n", - " ------ Geometric parameters ------\r\n", - " Number of reach(es) = 1\r\n", - " Number of cross-sections = 8\r\n", - " Number of open boundaries = 2\r\n", - " Number of junction(s) = 0\r\n", - " Number of inflow(s) = 18\r\n", - " Number of lateral weir(s) = 0\r\n", - " Number of storage area(s) = 0\r\n", - " Number of link(s) = 0\r\n", - " Number of dam(s)/weir(s) = 0\r\n", - " ------ Numerical parameters ------\r\n", - " Number of 1D nodes (mesh) = 144\r\n", - " Computation Kernel = 1\r\n", - " Initial time step = 1.0E+00\r\n", - " Variable time step? = 0\r\n", - " Number of time steps = 2\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " OptionCourlis F\r\n", - " Start the Simulation...\r\n", - " Simulation ended successfully in 1.89149976E-02 s\r\n", - " TEMPS PASSE 1.89249963E-02\r\n", - " FIN CORRECTE DU CALCUL\r\n", - "\r\n", - "... merging separated result files\r\n", - "\r\n", - "... handling result files\r\n", - "\r\n", - "... deleting working dir\r\n", - "\r\n", - "\r\n", - "\r\n", - "My work is done\r\n", - "\r\n", - "\r\n" + "\n", + "\n", + "Loading Options and Configurations\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + " _ \n", + " (_) \n", + " _ __ ___ __ _ _ _ __ \n", + " | '_ ` _ \\ / _` || || '_ \\ \n", + " | | | | | || (_| || || | | |\n", + " |_| |_| |_| \\__,_||_||_| |_|\n", + " \n", + " \n", + "\n", + "\n", + "Running your CAS file(s) for:\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "S10.gfortran.dyn: \n", + " \n", + "\n", + " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\n", + "\n", + " +> root: /home/d60881/telemac-mascaret\n", + " +> module: ad / api / artemis / bief\n", + " damocles / gaia / gretel / hermes\n", + " identify_liq_bnd / khione / mascaret / nestor\n", + " parallel / partel / postel3d / sisyphe\n", + " special / stbtel / telemac2d / telemac3d\n", + " tomawac / waqtel\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "... processing the steering file\n", + "\n", + "... checking parallelisation\n", + "\n", + "... handling temporary directories\n", + "~+> Creating FichierCas.txt\n", + "~+> Copying Abaques.txt\n", + "~+> Copying Controle.txt\n", + "~+> Copying dico_Courlis.txt\n", + " \n", + "... checking the executable\n", + "\n", + "\n", + "Running your simulation(s) :\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "In /home/d60881/telemac-mascaret/examples/mascaret/Test18:\n", + "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\n", + "\n", + "\n", + " Fichiercas : FichierCas.txt\n", + "\n", + " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\n", + "\n", + " Data File : sarap.xcas\n", + "\n", + " Study name : deversoir\n", + "\n", + " Hydraulic statistics (prior solve phase)\n", + " ------ Geometric parameters ------\n", + " Number of reach(es) = 1\n", + " Number of cross-sections = 8\n", + " Number of open boundaries = 2\n", + " Number of junction(s) = 0\n", + " Number of inflow(s) = 18\n", + " Number of lateral weir(s) = 0\n", + " Number of storage area(s) = 0\n", + " Number of link(s) = 0\n", + " Number of dam(s)/weir(s) = 0\n", + " ------ Numerical parameters ------\n", + " Number of 1D nodes (mesh) = 144\n", + " Computation Kernel = 1\n", + " Initial time step = 1.0E+00\n", + " Variable time step? = 0\n", + " Number of time steps = 2\n", + "\n", + " OptionCourlis F\n", + " Start the Simulation...\n", + " Simulation ended successfully in 1.89149976E-02 s\n", + " TEMPS PASSE 1.89249963E-02\n", + " FIN CORRECTE DU CALCUL\n", + "\n", + "... merging separated result files\n", + "\n", + "... handling result files\n", + "\n", + "... deleting working dir\n", + "\n", + "\n", + "\n", + "My work is done\n", + "\n", + "\n" ] } ], @@ -285,141 +255,111 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - "\r\n", - "Loading Options and Configurations\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - " _ \r\n", - " (_) \r\n", - " _ __ ___ __ _ _ _ __ \r\n", - " | '_ ` _ \\ / _` || || '_ \\ \r\n", - " | | | | | || (_| || || | | |\r\n", - " |_| |_| |_| \\__,_||_||_| |_|\r\n", - " \r\n", - " \r\n", - "\r\n", - "\r\n", - "Running your CAS file(s) for:\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "S10.gfortran.dyn: \r\n", - " \r\n", - "\r\n", - " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\r\n", - "\r\n", - " +> root: /home/d60881/telemac-mascaret\r\n", - " +> module: ad / api / artemis / bief\r\n", - " damocles / gaia / gretel / hermes\r\n", - " identify_liq_bnd / khione / mascaret / nestor\r\n", - " parallel / partel / postel3d / sisyphe\r\n", - " special / stbtel / telemac2d / telemac3d\r\n", - " tomawac / waqtel\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "... processing the steering file\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - "... checking parallelisation\r\n", - "\r\n", - "... handling temporary directories\r\n", - "~+> Creating FichierCas.txt\r\n", - "~+> Copying Abaques.txt\r\n", - "~+> Copying Controle.txt\r\n", - "~+> Copying dico_Courlis.txt\r\n", - "[ ] 0% | ---s\r", - " \r", - "[ ] 0% | ---s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 25% | 1s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 50% | 1s\r", - " \r", - "\r\n", - "... checking the executable\r\n", - "\r\n", - "\r\n", - "Running your simulation(s) :\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "In /home/d60881/telemac-mascaret/examples/mascaret/Test26:\r\n", - "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\r\n", - "\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Fichiercas : FichierCas.txt\r\n", - "\r\n", - " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\r\n", - "\r\n", - " Data File : rezo.xcas\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Study name : Etude hydraulique1d\r\n", - "\r\n", - " Hydraulic statistics (prior solve phase)\r\n", - " ------ Geometric parameters ------\r\n", - " Number of reach(es) = 3\r\n", - " Number of cross-sections = 6\r\n", - " Number of open boundaries = 3\r\n", - " Number of junction(s) = 1\r\n", - " Number of inflow(s) = 0\r\n", - " Number of lateral weir(s) = 0\r\n", - " Number of storage area(s) = 3\r\n", - " Number of link(s) = 5\r\n", - " Number of dam(s)/weir(s) = 0\r\n", - " ------ Numerical parameters ------\r\n", - " Number of 1D nodes (mesh) = 63\r\n", - " Computation Kernel = 2\r\n", - " Initial time step = 1.0E+01\r\n", - " Variable time step? = 0\r\n", - " Reduced Momentum Equation?= 0\r\n", - " Number of time steps = 1000\r\n", - "\r\n", - " OptionCourlis F\r\n", - " Start the Simulation...\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Simulation ended successfully in 0.225221008 s\r\n", - " TEMPS PASSE 0.225605994\r\n", - " FIN CORRECTE DU CALCUL\r\n", - "\r\n", - "... merging separated result files\r\n", - "\r\n", - "... handling result files\r\n", - "\r\n", - "... deleting working dir\r\n", - "\r\n", - "\r\n", - "\r\n", - "My work is done\r\n", - "\r\n", - "\r\n" + "\n", + "\n", + "Loading Options and Configurations\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + " _ \n", + " (_) \n", + " _ __ ___ __ _ _ _ __ \n", + " | '_ ` _ \\ / _` || || '_ \\ \n", + " | | | | | || (_| || || | | |\n", + " |_| |_| |_| \\__,_||_||_| |_|\n", + " \n", + " \n", + "\n", + "\n", + "Running your CAS file(s) for:\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "S10.gfortran.dyn: \n", + " \n", + "\n", + " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\n", + "\n", + " +> root: /home/d60881/telemac-mascaret\n", + " +> module: ad / api / artemis / bief\n", + " damocles / gaia / gretel / hermes\n", + " identify_liq_bnd / khione / mascaret / nestor\n", + " parallel / partel / postel3d / sisyphe\n", + " special / stbtel / telemac2d / telemac3d\n", + " tomawac / waqtel\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "... processing the steering file\n", + "\n", + "... checking parallelisation\n", + "\n", + "... handling temporary directories\n", + "~+> Creating FichierCas.txt\n", + "~+> Copying Abaques.txt\n", + "~+> Copying Controle.txt\n", + "~+> Copying dico_Courlis.txt\n", + " \n", + "... checking the executable\n", + "\n", + "\n", + "Running your simulation(s) :\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "In /home/d60881/telemac-mascaret/examples/mascaret/Test26:\n", + "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\n", + "\n", + "\n", + " Fichiercas : FichierCas.txt\n", + "\n", + " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\n", + "\n", + " Data File : rezo.xcas\n", + "\n", + " Study name : Etude hydraulique1d\n", + "\n", + " Hydraulic statistics (prior solve phase)\n", + " ------ Geometric parameters ------\n", + " Number of reach(es) = 3\n", + " Number of cross-sections = 6\n", + " Number of open boundaries = 3\n", + " Number of junction(s) = 1\n", + " Number of inflow(s) = 0\n", + " Number of lateral weir(s) = 0\n", + " Number of storage area(s) = 3\n", + " Number of link(s) = 5\n", + " Number of dam(s)/weir(s) = 0\n", + " ------ Numerical parameters ------\n", + " Number of 1D nodes (mesh) = 63\n", + " Computation Kernel = 2\n", + " Initial time step = 1.0E+01\n", + " Variable time step? = 0\n", + " Reduced Momentum Equation?= 0\n", + " Number of time steps = 1000\n", + "\n", + " OptionCourlis F\n", + " Start the Simulation...\n", + " Simulation ended successfully in 0.225221008 s\n", + " TEMPS PASSE 0.225605994\n", + " FIN CORRECTE DU CALCUL\n", + "\n", + "... merging separated result files\n", + "\n", + "... handling result files\n", + "\n", + "... deleting working dir\n", + "\n", + "\n", + "\n", + "My work is done\n", + "\n", + "\n" ] } ], @@ -1315,7 +1255,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, diff --git a/notebooks/workshop/solutions/exo_mascaret.ipynb b/notebooks/workshop/solutions/exo_mascaret.ipynb index 5e43bd7c325f5b04ec6d61445181f4b3184942d8..01626084c19db39bc7ee402844b1b2572543e340 100644 --- a/notebooks/workshop/solutions/exo_mascaret.ipynb +++ b/notebooks/workshop/solutions/exo_mascaret.ipynb @@ -58,7 +58,6 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:12.620628Z", "iopub.status.busy": "2022-12-01T11:13:12.620410Z", @@ -139,7 +138,7 @@ ], "source": [ "# File with a single reach\n", - "mascgeo_file = MascaretGeoFile(geo_file, 'geo')\n", + "mascgeo_file = MascaretGeoFile(geo_file, fformat='geo')\n", "\n", "print(mascgeo_file.summary())" ] @@ -163,7 +162,6 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:12.629922Z", "iopub.status.busy": "2022-12-01T11:13:12.629725Z", @@ -177,149 +175,113 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - "\r\n", - "Loading Options and Configurations\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " _ \r\n", - " (_) \r\n", - " _ __ ___ __ _ _ _ __ \r\n", - " | '_ ` _ \\ / _` || || '_ \\ \r\n", - " | | | | | || (_| || || | | |\r\n", - " |_| |_| |_| \\__,_||_||_| |_|\r\n", - " \r\n", - " \r\n", - "\r\n", - "\r\n", - "Running your CAS file(s) for:\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "S10.gfortran.dyn: \r\n", - " \r\n", - "\r\n", - " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\r\n", - "\r\n", - " +> root: /home/d60881/telemac-mascaret\r\n", - " +> module: ad / api / artemis / bief\r\n", - " damocles / gaia / gretel / hermes\r\n", - " identify_liq_bnd / khione / mascaret / nestor\r\n", - " parallel / partel / postel3d / sisyphe\r\n", - " special / stbtel / telemac2d / telemac3d\r\n", - " tomawac / waqtel\r\n", - "\r\n", - "\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "... processing the steering file\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r\n", - "... checking parallelisation\r\n", - "\r\n", - "... handling temporary directories\r\n", - "~+> Creating FichierCas.txt\r\n", - "~+> Copying Abaques.txt\r\n", - "~+> Copying Controle.txt\r\n", - "~+> Copying dico_Courlis.txt\r\n", - "[ ] 0% | ---s\r", - " \r", - "[ ] 0% | ---s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 25% | 1s\r", - "[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ] 50% | 1s\r", - " \r", - "\r\n", - "... checking the executable\r\n", - "\r\n", - "\r\n", - "Running your simulation(s) :\r\n", - "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n", - "\r\n", - "\r\n", - "\r\n", - "In /home/d60881/telemac-mascaret/examples/mascaret/Test24:\r\n", - "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\r\n", - "\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Fichiercas : FichierCas.txt\r\n", - "\r\n", - " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\r\n", - "\r\n", - " Data File : mascaret_imp.xcas\r\n", - "\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Study name : Etude hydraulique1d\r\n", - "\r\n", - " Hydraulic statistics (prior solve phase)\r\n", - " ------ Geometric parameters ------\r\n", - " Number of reach(es) = 1\r\n", - " Number of cross-sections = 59\r\n", - " Number of open boundaries = 2\r\n", - " Number of junction(s) = 0\r\n", - " Number of inflow(s) = 0\r\n", - " Number of lateral weir(s) = 0\r\n", - " Number of storage area(s) = 0\r\n", - " Number of link(s) = 0\r\n", - " Number of dam(s)/weir(s) = 0\r\n", - " ------ Numerical parameters ------\r\n", - " Number of 1D nodes (mesh) = 774\r\n", - " Computation Kernel = 3\r\n", - " Initial time step = 1.0E+00\r\n", - " Variable time step? = 1\r\n", - " Courant number = 2.0E+00\r\n", - " Implicit Scheme? = 1\r\n", - " Non Hydrostatic? = 0\r\n", - " Number of time steps = 5000\r\n", - "\r\n", - " OptionCourlis F\r\n", - " Start the Simulation...\r\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Simulation ended successfully in 3.32603216 s\r\n", - " TEMPS PASSE 3.33626199\r\n", - " FIN CORRECTE DU CALCUL\r\n", - "\r\n", - "... merging separated result files\r\n", - "\r\n", - "... handling result files\r\n", - "\r\n", - "... deleting working dir\r\n", - "\r\n", - "\r\n", - "\r\n", - "My work is done\r\n", - "\r\n", - "\r\n" + "\n", + "\n", + "Loading Options and Configurations\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + " _ \n", + " (_) \n", + " _ __ ___ __ _ _ _ __ \n", + " | '_ ` _ \\ / _` || || '_ \\ \n", + " | | | | | || (_| || || | | |\n", + " |_| |_| |_| \\__,_||_||_| |_|\n", + " \n", + " \n", + "\n", + "\n", + "Running your CAS file(s) for:\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "S10.gfortran.dyn: \n", + " \n", + "\n", + " +> Scibian 10 dynamic build using GFortran 8.3.0 and Open MPI.\n", + "\n", + " +> root: /home/d60881/telemac-mascaret\n", + " +> module: ad / api / artemis / bief\n", + " damocles / gaia / gretel / hermes\n", + " identify_liq_bnd / khione / mascaret / nestor\n", + " parallel / partel / postel3d / sisyphe\n", + " special / stbtel / telemac2d / telemac3d\n", + " tomawac / waqtel\n", + "\n", + "\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "... processing the steering file\n", + "\n", + "... checking parallelisation\n", + "\n", + "... handling temporary directories\n", + "~+> Creating FichierCas.txt\n", + "~+> Copying Abaques.txt\n", + "~+> Copying Controle.txt\n", + "~+> Copying dico_Courlis.txt\n", + " \n", + "... checking the executable\n", + "\n", + "\n", + "Running your simulation(s) :\n", + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\n", + "\n", + "\n", + "In /home/d60881/telemac-mascaret/examples/mascaret/Test24:\n", + "mpirun -np 1 /home/d60881/telemac-mascaret/builds/S10.gfortran.dyn/bin/mascaret\n", + "\n", + "\n", + " Fichiercas : FichierCas.txt\n", + "\n", + " TELEMAC-MASCARET V8P4R0 == Copyright (C) 2000-2022 EDF-CEREMA ==\n", + "\n", + " Data File : mascaret_imp.xcas\n", + "\n", + " Study name : Etude hydraulique1d\n", + "\n", + " Hydraulic statistics (prior solve phase)\n", + " ------ Geometric parameters ------\n", + " Number of reach(es) = 1\n", + " Number of cross-sections = 59\n", + " Number of open boundaries = 2\n", + " Number of junction(s) = 0\n", + " Number of inflow(s) = 0\n", + " Number of lateral weir(s) = 0\n", + " Number of storage area(s) = 0\n", + " Number of link(s) = 0\n", + " Number of dam(s)/weir(s) = 0\n", + " ------ Numerical parameters ------\n", + " Number of 1D nodes (mesh) = 774\n", + " Computation Kernel = 3\n", + " Initial time step = 1.0E+00\n", + " Variable time step? = 1\n", + " Courant number = 2.0E+00\n", + " Implicit Scheme? = 1\n", + " Non Hydrostatic? = 0\n", + " Number of time steps = 5000\n", + "\n", + " OptionCourlis F\n", + " Start the Simulation...\n", + " Simulation ended successfully in 3.32603216 s\n", + " TEMPS PASSE 3.33626199\n", + " FIN CORRECTE DU CALCUL\n", + "\n", + "... merging separated result files\n", + "\n", + "... handling result files\n", + "\n", + "... deleting working dir\n", + "\n", + "\n", + "\n", + "My work is done\n", + "\n", + "\n" ] } ], @@ -374,7 +336,6 @@ "cell_type": "code", "execution_count": 5, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:17.717295Z", "iopub.status.busy": "2022-12-01T11:13:17.717115Z", @@ -1257,7 +1218,6 @@ "cell_type": "code", "execution_count": 6, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:17.893838Z", "iopub.status.busy": "2022-12-01T11:13:17.893640Z", @@ -1347,7 +1307,6 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:18.658632Z", "iopub.status.busy": "2022-12-01T11:13:18.658399Z", @@ -1398,7 +1357,6 @@ "cell_type": "code", "execution_count": 8, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:18.714979Z", "iopub.status.busy": "2022-12-01T11:13:18.714795Z", @@ -1495,7 +1453,6 @@ "cell_type": "code", "execution_count": 10, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:20.190023Z", "iopub.status.busy": "2022-12-01T11:13:20.189849Z", @@ -1541,7 +1498,6 @@ "cell_type": "code", "execution_count": 11, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:20.460725Z", "iopub.status.busy": "2022-12-01T11:13:20.460447Z", @@ -2074,7 +2030,6 @@ "cell_type": "code", "execution_count": 13, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:20.477261Z", "iopub.status.busy": "2022-12-01T11:13:20.476941Z", @@ -2128,7 +2083,6 @@ "cell_type": "code", "execution_count": 14, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:20.653579Z", "iopub.status.busy": "2022-12-01T11:13:20.653400Z", @@ -2946,7 +2900,6 @@ "cell_type": "code", "execution_count": 15, "metadata": { - "collapsed": false, "execution": { "iopub.execute_input": "2022-12-01T11:13:20.692565Z", "iopub.status.busy": "2022-12-01T11:13:20.692385Z", @@ -4524,7 +4477,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, diff --git a/scripts/python3/data_manip/formats/mascaret_file.py b/scripts/python3/data_manip/formats/mascaret_file.py index 9d7e79fcbae7ec32457f880a619a0efcdf7c44f9..b82cb93946255c56bc83a6ad10e027087d3db471 100644 --- a/scripts/python3/data_manip/formats/mascaret_file.py +++ b/scripts/python3/data_manip/formats/mascaret_file.py @@ -123,6 +123,7 @@ class Section: self.y = np.array([]) self.z = np.array([]) self.distances = np.array([]) + self.topo_bath = [] self.nb_points = 0 self.limits = {} @@ -130,39 +131,101 @@ class Section: self.layers_elev = None self.layer_names = [] - def set_points_from_trans(self, dist_array, z_array): + def set_points_from_trans(self, dist_array, z_array, topo_baths=None): + """ + Method to add points on the section with transversal abscissa + and elevations + + @param dist_array (float list) section points abscissa + @param z_array (float list) section points elevations + @param topo_baths (str float) topo-bath section points definition ("T" + if topographic point, "B" if bathymetric points) + """ if len(dist_array) != len(z_array): raise MascaretException( 'set_points_from_trans:\ Input arrays have not the same length') - self.allocate(len(dist_array)) - for i, (dist, z) in enumerate(zip(dist_array, z_array)): - if i == 0: - limit = 'RD' - elif i == (self.nb_points - 1): + self._allocate(len(dist_array)) + first_RG_pt = True + first_RD_pt = True + + if topo_baths is None: + topo_baths = ["B" for i in z_array] + + for i, (dist, z, topo_bath) in \ + enumerate(zip(dist_array, z_array, topo_baths)): + if topo_bath == "B" and first_RG_pt is True: limit = 'RG' + first_RG_pt = False + elif (topo_bath == "T" and first_RG_pt is False and + first_RD_pt is True) or (i == (self.nb_points - 1) and + first_RD_pt is True): + self.limits['RD'] = i - 1 + first_RD_pt = False else: limit = None - self.set_point(i, self.pk, dist, z, limit) + self.set_point(i, self.pk, dist, z, topo_bath, limit) + + def set_points_from_xyz(self, x_list, y_list, z_list, topo_baths=None): + """ + Method to add points on the section with X and Y coordinates, + and elevations + + @param x_list (float list) section points X coordinates + @param y_list (float list) section points Y coordinates + @param z_list (float list) section points elevations + @param topo_baths (str list) topo-bath section points definition ("T" + if topographic point, "B" if bathymetric points) + """ - def set_points_from_xyz(self, x_list, y_list, z_list): if not len(x_list) == len(y_list) == len(z_list): raise MascaretException( 'set_points_from_xyz: Input arrays have not the same length') - self.allocate(len(x_list)) - for i, (x, y, z) in enumerate(zip(x_list, y_list, z_list)): - if i == 0: - limit = 'RD' - elif i == (self.nb_points - 1): + self._allocate(len(x_list)) + first_RG_pt = True + first_RD_pt = True + + if topo_baths is None: + topo_baths = ["B" for i in z_list] + + for i, (x, y, z, topo_bath) in \ + enumerate(zip(x_list, y_list, z_list, topo_baths)): + if topo_bath == "B" and first_RG_pt is True: limit = 'RG' + first_RG_pt = False + elif (topo_bath == "T" and first_RG_pt is False and + first_RD_pt is True) or (i == (self.nb_points - 1) and + first_RD_pt is True): + self.limits['RD'] = i - 1 + first_RD_pt = False else: limit = None - self.set_point(i, x, y, z, limit) + self.set_point(i, x, y, z, topo_bath, limit) - def set_axis(self, xa, ya): - self.axis = (xa, ya) + def set_axis(self, x_axis, y_axis): + """ + Method to define X and Y coordinates of the section point corresponding + to intersection of the section and the hydraulic axis crossed by the + hydraulic axis + + @param x_axis (float) X coordinate of the section point belonging + to hydraulic axis + @param y_axis (float) Y coordinate of the section point belonging + to hydraulic axis + """ + self.axis = (x_axis, y_axis) def get_limit(self, limit_name): + """ + Method which is returning index of the topography/bathymetry limits on + the section (i.e. left and right river banks) + These limits are also the limit between minor and major bed + + @param limit_name (str) 'RD' for right bank limit or 'RG' for the + left bank limit + @return (int) index of the point corresponding to the limit (taken + in the minor bed part) + """ try: return self.limits[limit_name] except KeyError: @@ -170,22 +233,46 @@ class Section: (limit_name, self)) def point_index_limit(self, i): + """ + Method which is returning name limit ('RD' for right bank and 'RG' for + left bank of the topography/bathymetry limits on the section + These limits are also the limit between minor and major bed + + @param (int) index of the point corresponding to the limit (taken + in the minor bed part) + @return limit_name (str) 'RD' for right bank limit or 'RG' for the + left bank limit + """ for limit_name, index in self.limits.items(): if index == i: return limit_name return None - def allocate(self, nb_points): + def _allocate(self, nb_points): self.x = np.empty(nb_points) self.y = np.empty(nb_points) self.z = np.empty(nb_points) self.distances = np.empty(nb_points) self.nb_points = nb_points - def set_point(self, i, x, y, z, limit=None): + def set_point(self, i, x, y, z, topo_bath, limit=None): + """ + Method to add a point to a section + + @param i (int) index of the point in the section + @param x (float) X coordinates of the point + @param y (float) Y coordinates of the point + @param z (float) Z elevation of the point + @param topo_bath (str) Type of the point : 'T' for topographic + (i.e. major bed) ; 'B' for bathymetric (i.e. minor bed) + @param limit (str) point corresponding to the minor/major bed limit + ('RG' : left bank ; 'RD' : right bank), limit is fixed inside + bathymetric points 'B' (minor bed) + """ self.x[i] = x self.y[i] = y self.z[i] = z + self.topo_bath.append(topo_bath) if limit is not None: self.limits[limit] = i if i == 0: @@ -195,7 +282,15 @@ class Section: sqrt((self.x[i] - self.x[i - 1]) ** 2 + (self.y[i] - self.y[i - 1]) ** 2) - def add_layer(self, thickness_table, name=None): + def add_layer_from_thickness(self, thickness_table, name=None): + """ + Add a sediment layer to a section with a thickness table + + @param thickness_table (numpy array) array which contain thickness of + the sediment layer to add to the section (size should correspond with + the number of points in the section) + @param name (str) name of the layer + """ self.nlayers += 1 if name is None: name = 'Layer ' + str(self.nlayers) @@ -209,11 +304,38 @@ class Section: self.layers_elev[self.nlayers - 2] - thickness_table)) + def add_layers_from_elevations(self, layers_elev, names=None): + """ + Add a sediment layer to a section with an array of elevations + + @param layers_elev (numpy array) array which contain elevations of + the sediment layer to add to the section (size should correspond with + the number of points in the section) + @param name (str) name of the layer + """ + self.nlayers = len(layers_elev[0]) + if names is None: + for n in range(self.nlayers): + self.layer_names.append('Layer_' + str(n)) + else: + for name in names: + self.layer_names.append(name) + self.layers_elev = np.array(layers_elev).T + def iter_on_points(self): - for i, (x, y, z) in enumerate(zip(self.x, self.y, self.z)): + """ + Method to iterate on points of the section + + @return (float, float, float, str, str) return X and Y coordinates, + elevation, type ('T' or 'B', i.e. major or minor bed), limit of + minor/major bed (None if the point is not a limit, 'RG'/'RD' if the + point correspond to a limit + """ + for i, (x, y, z, topo_bath) in enumerate(zip(self.x, self.y, self.z, + self.topo_bath)): limit = self.point_index_limit(i) limit_str = limit if limit is not None else '' - yield x, y, z, limit_str + yield x, y, z, topo_bath, limit_str def common_limits(self, other): """ @@ -223,10 +345,13 @@ class Section: """ return list(set(self.limits.keys()).intersection(other.limits.keys())) - def check_elevations(self): - pass # TODO - def __repr__(self): + """ + Method which defines the representation of the class (in a print + function) + + @return (str) representation of the class + """ return 'Section #%i (%s) at pk %f' % (self.id, self.name, self.pk) @@ -238,13 +363,13 @@ class MascaretFileParent: logger = logging.getLogger(__name__) - def __init__(self, file_name, access='r', log_lvl='INFO'): + def __init__(self, filename, access='r', log_lvl='INFO'): """ Constructor for MascaretFile Warning Only suited for results at cross-sections (not adapted to Casier or Traceur outputs) - @param file_name (str) Name of the file + @param filename (str) Name of the file @param access (str) Access to the file ('r' for read 'w' for write, add 'b' for binary file) @param log_lvl (str) logger level @@ -267,8 +392,9 @@ class MascaretFileParent: logging.basicConfig(level=i_log) # File name - self.file_name = file_name + self.filename = filename self._position_first_frame = 0 + self.fformat = None # Attributes for geometry self.nreaches = 0 @@ -294,15 +420,15 @@ class MascaretFileParent: self._times_pos = [] self._ntimestep = 0 - self._file = open(self.file_name, access) + self._file = open(self.filename, mode=access) def __del__(self): - self.logger.debug("Closing mesh file %s", self.file_name) + self.logger.debug("Closing mesh file %s", self.filename) if self._file is not None: self._file.close() def __repr__(self): - return 'MascaretFile: %s (mode=%s)' % (self.file_name, self._file.mode) + return 'MascaretFile: %s (mode=%s)' % (self.filename, self._file.mode) @property def times(self): @@ -346,12 +472,23 @@ class MascaretFileParent: self._file.seek(self._position_first_frame) def get_time(self): + """ + Method which return time of a MascaretFile (overrided in child class) + """ raise NotImplementedError('Has to be override in subclass') def get_reaches(self): + """ + Method which return reaches of a MascaretFile (overrided in child + class) + """ raise NotImplementedError('Has to be override in subclass') def error(self, message): + """ + Method which handle error in use of a MascaretFile (overrided in child + class) + """ raise MascaretException('ERROR: %s' % message) def add_variable(self, varname, varunit, varname_abbr): @@ -370,24 +507,26 @@ class MascaretFileParent: self.section_varnames_dict['id'].append(self.nsectionvar) self.nsectionvar += 1 - def get_position_var(self, var_name, type='names'): + def get_position_var(self, var_name, name_type='names'): """ Get position variable @param var_name (string) variable name - @param type (string) 'names' for full name or 'abbr' for abreviation + @param name_type (string) 'names' for full name or 'abbr' for + abreviation @return variable name index """ try: - if type == 'abbr': + if name_type == 'abbr': return self.varnames_dict['abbr'].index(var_name) - else: - return self.varnames_dict['names'].index(var_name) + + return self.varnames_dict['names'].index(var_name) + except ValueError: self.error('Variable `%s` not found. ' 'Possibles values are:\n%s' % - (var_name, self.varnames_dict[type])) + (var_name, self.varnames_dict[name_type])) def get_values_at_reach(self, record, reach_id, vars_indexes=None): """ @@ -508,9 +647,9 @@ class MascaretFileParent: if vars_indexes is None: vars_indexes = self.varnames_dict['id'] if times_indexes is None: - times_indexes = [i for i in range(len(self.times))] + times_indexes = list(range(len(self.times))) - outfile = open(outfile_name, 'w') + outfile = open(outfile_name, mode='w', encoding='utf-8') # write header self.write_optfile_header(outfile, vars_indexes) # write times @@ -523,11 +662,11 @@ class MascaretFileParent: outfile.close() - def export_as_lig(self, file_name, record): + def export_as_lig(self, filename, record): """ Write Mascaret restart file - @param file_name: (string) file name + @param filename: (string) file name @param record (int) time index @return """ @@ -560,7 +699,7 @@ class MascaretFileParent: result['Z'] = z result['Q'] = q - with open(file_name, 'w') as fich: + with open(filename, mode='w', encoding='utf-8') as fich: # Date is hardcoded, but it could be defined as: # datetime.datetime.utcnow() fich.write( @@ -595,6 +734,11 @@ class MascaretFileParent: # TODO: add section variables in the summary def summary(self): + """ + Method which return a summary of the class + + @return txt (str) summary text + """ txt = '~> %s\n' % self for _, reach in self.reaches.items(): txt += ' - %s\n' % reach @@ -620,26 +764,32 @@ class MascaretFileParent: class Opthyca(MascaretFileParent): + """ + Child class of MascaretFileParent to handle Opthyca format files + """ - def __init__(self, file_name, access='r', log_lvl='INFO'): + def __init__(self, filename, access='r', log_lvl='INFO'): """ Constructor for Opthyca file Warning: Only suited for results at cross-sections (not adapted to Casier or Traceur outputs) - @param file_name (string) Name of the file + @param filename (string) Name of the file @param access (string) Access to the file ('r' for read 'w' for write) @param log_lvl (string) Logger level Attributs specified to Opthyca: - fformat """ - super().__init__(file_name, access=access, log_lvl=log_lvl) + super().__init__(filename, access=access, log_lvl=log_lvl) self.fformat = 'opt' self._read_variables() def read_line(self): + """ + Method to read a line + """ return self._file.readline().rstrip('\n') def _read_variables(self): @@ -783,12 +933,15 @@ class Opthyca(MascaretFileParent): class Rubens(MascaretFileParent): + """ + Child class of MascaretFileParent to handle Rubens format files + """ - def __init__(self, file_name, access='r', log_lvl='INFO'): + def __init__(self, filename, access='r', log_lvl='INFO'): """ Constructor for Rubens file - @param file_name (string) Name of the file + @param filename (string) Name of the file @param access (string) Access to the file ('r' for read 'w' for write) @param log_lvl (string) Logger level @@ -797,9 +950,9 @@ class Rubens(MascaretFileParent): - _size_file - _endians """ - super().__init__(file_name, access=access + 'b', log_lvl=log_lvl) + super().__init__(filename, access=access + 'b', log_lvl=log_lvl) self.fformat = 'rub' - self._size_file = os.path.getsize(self.file_name) + self._size_file = os.path.getsize(self.filename) self._endians = '' self._read_binary_header() @@ -818,7 +971,9 @@ class Rubens(MascaretFileParent): """Read variable information""" names, units, abbrs = [], [], [] with open(os.path.join(os.path.dirname(__file__), - 'mascaret_variables_fr.csv'), newline='') as csvfile: + 'mascaret_variables_fr.csv'), newline='', mode='r', + encoding='utf-8')\ + as csvfile: reader = csv.DictReader(csvfile, delimiter=';') for row in reader: names.append(row['varname']) @@ -839,8 +994,7 @@ class Rubens(MascaretFileParent): if len(check) != 0: if check.decode('utf-8') == 'FIN': break - else: - variables.append(check.decode('utf-8')) + variables.append(check.decode('utf-8')) return variables def _read_binary_header(self): @@ -968,7 +1122,6 @@ class Rubens(MascaretFileParent): vars_indexes = self.varnames_dict['id'] res = OrderedDict() - requested_time = self.times[record] self._file.seek(self._times_pos[record]) values = [] @@ -1056,6 +1209,7 @@ class Rubens(MascaretFileParent): self.error("Number of frames is not consistant!") def get_endians(self): + """Method to detect endians of the file""" pos_init = self._file.tell() self._file.seek(0) @@ -1078,15 +1232,16 @@ class Rubens(MascaretFileParent): self._file.seek(pos_init) -# Question : est-il possible de sortir cette classe pour la mettre -# dans un fichier courlis_file.py? class ListingCourlis(MascaretFileParent): + """ + Child class of MascaretFileParent to handle Listing Courlis format files + """ - def __init__(self, file_name, access='r', log_lvl='INFO'): + def __init__(self, filename, access='r', log_lvl='INFO'): """ Constructor for ListingCourlis file - @param file_name (string) Name of the file + @param filename (string) Name of the file @param access (string) Access to the file ('r' for read 'w' for write) @param log_lvl (string) Logger level @@ -1095,9 +1250,9 @@ class ListingCourlis(MascaretFileParent): - _size_file - _endians """ - super().__init__(file_name, access=access + 'b', log_lvl=log_lvl) + super().__init__(filename, access=access + 'b', log_lvl=log_lvl) self.fformat = 'listingcourlis' - self._size_file = os.path.getsize(self.file_name) + self._size_file = os.path.getsize(self.filename) self._endians = '' self._sediment_budget_string_res = "Sediment budget not yet extracted" @@ -1117,7 +1272,8 @@ class ListingCourlis(MascaretFileParent): """Read variable information""" names, units, abbrs = [], [], [] with open(os.path.join(os.path.dirname(__file__), - 'listing_courlis_variables_fr.csv'), newline='') as csvfile: + 'listing_courlis_variables_fr.csv'), newline='', + encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile, delimiter=';') for row in reader: names.append(row['varname']) @@ -1210,11 +1366,11 @@ class ListingCourlis(MascaretFileParent): # Only one reach in Courlis reach = Reach(1) - for i in range(len(self._section_idx)): + for i, sec in enumerate(self._section_idx): # Dictionary index starting at 1 reach.add_section( Section( - self._section_idx[i], + sec, self._section_pk[i] ) ) @@ -1233,7 +1389,6 @@ class ListingCourlis(MascaretFileParent): vars_indexes = self.varnames_dict['id'] res = OrderedDict() - requested_time = self.times[record] self._file.seek(self._times_pos[record]) values = [] @@ -1312,6 +1467,12 @@ class ListingCourlis(MascaretFileParent): self._binary_frame_size) def sediment_budget(self, pandas=False): + """ + Method to generate the sediment budget + + @param pandas (bool) option activated when the sediment budget is + generating with Pandas + """ sediment_budget = [] @@ -1440,6 +1601,11 @@ class ListingCourlis(MascaretFileParent): return sediment_budget def export_sediment_budget_to_csv(self, outfile_name): + """ + Generate the sediment budget into a csv file + + @param outfile_name (str) Name of the csv file to write + """ sediment_budget = self.sediment_budget() self._sediment_budget_string_res = "" @@ -1549,11 +1715,16 @@ class ListingCourlis(MascaretFileParent): " -Volume sediment variation from t = 0 s :\ ;{:16.3f}; m3\n\n\n".format(sediment_budget[gap_2 + 1, 16]) - outfile = open(outfile_name, 'w') + outfile = open(outfile_name, 'w', encoding='utf-8') outfile.write(self._sediment_budget_string_res) outfile.close() def export_sediment_budget_to_txt(self, outfile_name): + """ + Method to write sediment budget to an ASCII file + + @param outfile_name (str) Name of the ASCII file to write + """ sediment_budget = self.sediment_budget() self._sediment_budget_string_res = "" @@ -1653,11 +1824,12 @@ class ListingCourlis(MascaretFileParent): " -Volume sediment variation from t = 0 s : {:16.3f} m3\n\n\n"\ .format(sediment_budget[gap_2 + 1, 16]) - outfile = open(outfile_name, 'w') + outfile = open(outfile_name, 'w', encoding='utf-8') outfile.write(self._sediment_budget_string_res) outfile.close() def get_endians(self): + """Method to detect endians of the file""" pos_init = self._file.tell() self._file.seek(0) @@ -1681,12 +1853,15 @@ class ListingCourlis(MascaretFileParent): class ptravers(MascaretFileParent): + """ + Child class of MascaretFileParent to handle ptravers format files + """ - def __init__(self, file_name, access='r', log_lvl='INFO'): + def __init__(self, filename, access='r', log_lvl='INFO'): """ Constructor for ptravers Courlis result file - @param file_name (string) Name of the file + @param filename (string) Name of the file @param access (string) Access to the file ('r' for read 'w' for write) @param log_lvl (string) Logger level @@ -1694,7 +1869,7 @@ class ptravers(MascaretFileParent): - fformat """ - super().__init__(file_name, access=access, log_lvl=log_lvl) + super().__init__(filename, access=access, log_lvl=log_lvl) self.fformat = 'ptravers' self._section_pk = [] @@ -1705,6 +1880,9 @@ class ptravers(MascaretFileParent): self._read_ptravers_header() def read_line(self): + """ + Method to read a line + """ return self._file.readline().rstrip('\n') def _read_ptravers_header(self): @@ -1812,7 +1990,6 @@ class ptravers(MascaretFileParent): res = OrderedDict() all_values = [] - requested_time = self.times[record] self._file.seek(self._times_pos[record]) # skip time in the first X-profile header @@ -1943,12 +2120,12 @@ class ptravers(MascaretFileParent): line = self.read_line() -def MascaretFile(file_name, fformat=None, access='r', log_lvl='INFO'): +def MascaretFile(filename, fformat=None, access='r', log_lvl='INFO'): """ Generic wrapper of mascaret classes will return the class assocaited with fformat - @param file_name (string) Path of the file + @param filename (string) Path of the file @param fformat (string) File format ('opt', 'listingcourlis', 'ptravers', 'rub'), optional (detection from extension) @param access (string) Access to the file ('r' for read 'w' for write) @@ -1958,18 +2135,18 @@ def MascaretFile(file_name, fformat=None, access='r', log_lvl='INFO'): """ # Determine file format from file extension if fformat is None: - fformat = file_name.split(".")[-1] + fformat = filename.split(".")[-1] if access != 'r': raise NotImplementedError('Write access is not supported yet!') if fformat == 'opt': - return Opthyca(file_name, access=access, log_lvl=log_lvl) + return Opthyca(filename, access=access, log_lvl=log_lvl) if fformat == 'rub': - return Rubens(file_name, access=access, log_lvl=log_lvl) + return Rubens(filename, access=access, log_lvl=log_lvl) if fformat == 'listingcourlis': - return ListingCourlis(file_name, access=access, log_lvl=log_lvl) + return ListingCourlis(filename, access=access, log_lvl=log_lvl) if fformat == 'ptravers': - return ptravers(file_name, access=access, log_lvl=log_lvl) + return ptravers(filename, access=access, log_lvl=log_lvl) raise FileNotFoundError( 'The format of the file "{}" is not recognized, ' diff --git a/scripts/python3/data_manip/formats/mascaretgeo_file.py b/scripts/python3/data_manip/formats/mascaretgeo_file.py index 8d9582f10634551ef2c5ec6eaf5a166b859a680b..cf0d511209f54bcc8362d70ef2864ca0094bffbe 100644 --- a/scripts/python3/data_manip/formats/mascaretgeo_file.py +++ b/scripts/python3/data_manip/formats/mascaretgeo_file.py @@ -5,7 +5,8 @@ from data_manip.formats.mascaret_file import Reach, Section from utils.exceptions import MascaretException -class MascaretGeoFile: + +class MascaretGeoFile(): """ Parse Mascaret geometry file (geo/geoC/georef/georefC) Handles multiple reaches @@ -23,9 +24,10 @@ class MascaretGeoFile: """ OUTPUT_FLOAT_FMT = '%.6f' - def __init__(self, file_name, fformat=None, mode='read'): + def __init__(self, file_name, load_file=True, fformat=None, mode='read'): """ @param file_name (str) file name + @param load_file (bool) option to activate loading of the file @param fformat (str) file format ('opt' or 'rub') @param mode (str) define the mode for the class, 'read' by default to read a file, @@ -44,18 +46,19 @@ class MascaretGeoFile: self.fformat = os.path.splitext(file_name)[1][1:] else: self.fformat = fformat.lower().strip() - if self.fformat not in ('geo', 'georef'): + if self.fformat not in ('geo', 'geoC', 'georef', 'georefC'): raise NotImplementedError( 'Format `%s` not supported,\ - only geo and georef formats are supported as input' % - self.fformat) + only geo, geoC, georef and georefC formats are supported\ + as input' % self.fformat) self.has_ref = 'ref' in self.fformat # Layers for sediments (Courlis) self.has_layers = self.fformat.endswith('C') - # Load file content - self.load() + if load_file: + # Load file content + self.load() def load(self): """ @@ -67,8 +70,9 @@ class MascaretGeoFile: section_id = 0 section_name = '' section_pk = -1.0 - dist, x_list, y_list, z_list = [], [], [], [] - xa, ya = None, None + dist, x_list, y_list, z_list, topo_bath_list, layers_elev_list = \ + [], [], [], [], [], [] + x_axis, y_axis = None, None for line in filein: if line.startswith('#'): @@ -78,19 +82,25 @@ class MascaretGeoFile: if dist: # Add previous Section section = Section(section_id, section_pk, section_name) - if xa is not None and ya is not None: - section.set_axis(xa, ya) + if x_axis is not None and y_axis is not None: + section.set_axis(x_axis, y_axis) if self.has_ref: - section.set_points_from_xyz(x_list, y_list, z_list) + section.set_points_from_xyz(x_list, y_list, z_list, + topo_bath_list) else: - section.set_points_from_trans(dist, z_list) + section.set_points_from_trans(dist, z_list, + topo_bath_list) + section.distances = dist + if self.has_layers: + section.add_layers_from_elevations( + layers_elev_list) reach.add_section(section) if self.has_ref: _, reach_name, section_name, pk_str, x1, y1, x2, y2,\ - _, xa, ya = line.split() - xa = float(xa) - ya = float(ya) + _, x_axis, y_axis = line.split() + x_axis = float(x_axis) + y_axis = float(y_axis) else: _, reach_name, section_name, pk_str = line.split() @@ -108,28 +118,89 @@ class MascaretGeoFile: # Reset variables to store section section_pk = float(pk_str) - dist, x_list, y_list, z_list = [], [], [], [] + dist, x_list, y_list, z_list, topo_bath_list, \ + layers_elev_list = [], [], [], [], [], [] section_id += 1 else: - if self.has_ref: - dist_str, z_str, _, x1, y1 = line.split() - x_list.append(float(x1)) - y_list.append(float(y1)) + list_line = line.split() + + if self.has_ref and self.has_layers is False: + dist_str = list_line[0] + z_str = list_line[1] + if "T" in list_line or "B" in list_line: + shift = 0 + topo_bath = list_line[2] + else: + shift = -1 + topo_bath = "B" + + x_list.append(float(list_line[shift + 3])) + y_list.append(float(list_line[shift + 4])) + + elif self.has_ref and self.has_layers: + dist_str = list_line[0] + z_str = list_line[1] + if "T" in list_line or "B" in list_line: + shift = 0 + topo_bath = list_line[-3] + else: + shift = 1 + topo_bath = "B" + + layers_elev = list_line[2:shift - 3] + + x_list.append(float(list_line[-2])) + y_list.append(float(list_line[-1])) + + layers_elev = [float(elev) for elev in layers_elev] + + if self.nlayers == 0: + self.nlayers = len(layers_elev) + + elif self.has_ref is False and self.has_layers: + dist_str = list_line[0] + z_str = list_line[1] + if "T" in list_line or "B" in list_line: + layers_elev = list_line[2:-1] + topo_bath = list_line[-1] + else: + layers_elev = list_line[2:] + topo_bath = "B" + + layers_elev = [float(elev) for elev in layers_elev] + + if self.nlayers == 0: + self.nlayers = len(layers_elev) + else: - dist_str, z_str, _ = line.split() + dist_str = list_line[0] + z_str = list_line[1] + + if "T" in list_line or "B" in list_line: + topo_bath = list_line[2] + else: + topo_bath = "B" # Add new point to current section dist.append(float(dist_str)) z_list.append(float(z_str)) + topo_bath_list.append(topo_bath) + if self.has_layers: + layers_elev_list.append(layers_elev) # Add last section section = Section(section_id, section_pk, section_name) - if xa is not None and ya is not None: - section.set_axis(xa, ya) + if x_axis is not None and y_axis is not None: + section.set_axis(x_axis, y_axis) if self.has_ref: - section.set_points_from_xyz(x_list, y_list, z_list) + section.set_points_from_xyz(x_list, y_list, z_list, + topo_bath_list) else: - section.set_points_from_trans(dist, z_list) + section.set_points_from_trans(dist, z_list, topo_bath_list) + section.distances = dist + if self.has_layers: + section.add_layers_from_elevations(layers_elev_list) + self.layer_names = section.layer_names reach.add_section(section) def save(self, output_file_name): @@ -149,64 +220,141 @@ class MascaretGeoFile: if ref and not self.has_ref: raise MascaretException('Could not write `%s` format without\ - any geo-referenced data' % fformat) + any geo-referenced data' % fformat) - with open(output_file_name, 'w') as fileout: + with open(output_file_name, 'w', encoding="utf-8") as fileout: for _, reach in self.reaches.items(): for sec in reach: positions_str = '' if ref: # Get river_banks and `AXE` coordinates if necessary - xa, ya = sec.axis - positions_str += ' %f %f %f %f' %\ + x_axis, y_axis = sec.axis + positions_str += '%f %f %f %f' %\ (sec.x[0], sec.y[0], sec.x[-1], sec.y[-1]) - positions_str += ' AXE %f %f' % (xa, ya) + positions_str += ' AXE %f %f' % (x_axis, y_axis) # Write profile header fileout.write( - 'Profil %s %s %f%s\n' % + 'Profil %s %s %f %s\n' % (reach.name, sec.name, sec.pk, positions_str)) # Write points and layers if necessary if not ref and not layers: - for dist, z in zip(sec.distances, sec.z): - fileout.write('%f %f B\n' % (dist, z)) + for dist, z, topo_bath in zip(sec.distances, sec.z, + sec.topo_bath): + fileout.write('%f %f %s\n' % (dist, z, topo_bath)) elif ref and not layers: - for dist, x, y, z in zip(sec.distances, - sec.x, sec.y, sec.z): - fileout.write('%f %f B %f %f\n' % (dist, z, x, y)) + for dist, x, y, z, topo_bath in zip(sec.distances, + sec.x, + sec.y, + sec.z, + sec.topo_bath): + fileout.write('%f %f %s %f %f\n' + % (dist, z, topo_bath, x, y)) elif not ref and layers: - for i, (dist, z) in enumerate(zip(sec.distances, - sec.z)): + for i, (dist, z, topo_bath) in \ + enumerate(zip(sec.distances, sec.z, + sec.topo_bath)): if self.nlayers == 0: layers_str = '' else: layers_str = ' ' +\ - ' '.join( - [MascaretGeoFile.OUTPUT_FLOAT_FMT % zl - for zl in sec.layers_elev[:, i]]) - fileout.write('%f %f%s B\n' % - (dist, z, layers_str)) + ' '.join( + [MascaretGeoFile.OUTPUT_FLOAT_FMT % zl + for zl in sec.layers_elev[:, i]]) + + try: + fileout.write('%f %f %s %s\n' % + (dist, z, layers_str, topo_bath)) + except Exception as e: + raise e elif ref and layers: - for i, (dist, x, y, z) in enumerate(zip(sec.distances, - sec.x, sec.y, - sec.z)): + for i, (dist, x, y, z, topo_bat) in enumerate(zip(sec.distances, + sec.x, + sec.y, + sec.z, + sec.topo_bath)): + if self.nlayers == 0: layers_str = '' else: layers_str = ' ' + ' '\ - .join([MascaretGeoFile.OUTPUT_FLOAT_FMT % - zl for zl in sec.layers_elev[:, i]]) - fileout.write('%f %f%s B %f %f\n' % - (dist, z, layers_str, x, y)) + .join([MascaretGeoFile.OUTPUT_FLOAT_FMT % + zl for zl in sec.layers_elev[:, i]]) + + try: + fileout.write('%f %f %s %s %f %f\n' + % (dist, z, layers_str, + topo_bath, x, y)) + except Exception as e: + raise e + def __repr__(self): return 'MascaretGeoFile: %s' % self.file_name + def save_precourlis(self, output_file_name, crs="EPSG:2154"): + """ + Method to export a MascaretGeoFile into the PreCourlis format + (geopackage with specific attributes) + It requires X and Y GIS coordinates (georef) + """ + import fiona + + properties = [('sec_id', 'int'), + ('sec_name', 'str:80'), + ('abs_long', 'float'), + ('axis_x', 'float'), + ('axis_y', 'float'), + ('layers', 'str:254'), + ('p_id', 'str:100000'), + ('topo_bat', 'str:100000'), + ('abs_lat', 'str:100000'), + ('zfond', 'str:100000')] + + for layer_name in self.layer_names: + properties.append((layer_name, 'str')) + + schema = {'geometry': 'LineString', + 'properties': OrderedDict(properties)} + + dict_lines = [] + + reach = self.reaches[1] + for sec in reach: + coord = [] + for x, y in zip(sec.x, sec.y): + coord.append((x, y)) + + properties_sec = [('sec_id', sec.id), + ('sec_name', sec.name), + ('abs_long', sec.pk), + ('axis_x', sec.axis[0]), + ('axis_y', sec.axis[1]), + ('layers', ','.join(sec.layer_names)), + ('p_id', ','.join(map(str, + range(sec.nb_points)))), + ('topo_bat', ','.join(sec.topo_bath)), + ('abs_lat', ','.join(map(str, sec.distances))), + ('zfond', ','.join(map(str, sec.z)))] + + for i, layer_name in enumerate(self.layer_names): + properties_sec.append((layer_name, ",".join(map( + str, sec.layers_elev[i, :])))) + + dict_lines.append({'geometry': {'type': 'LineString', + 'coordinates': coord}, + 'properties': OrderedDict(properties_sec)}) + + with fiona.open(output_file_name, 'w', driver='GPKG', crs=crs, + schema=schema) as shp: + for dict_line in dict_lines: + shp.write(dict_line) + def add_reach(self, reach): """ Add a single reach @@ -215,15 +363,23 @@ class MascaretGeoFile: self.reaches[reach.id] = reach def add_constant_layer(self, name, thickness): + """ + Add a sediment layer with a constant thickness on all profiles + @param name (str) name of the sediment layer + @param thickness (float) layer thickness + """ self.has_layers = True self.nlayers += 1 self.layer_names.append(name) for _, reach in self.reaches.items(): for section in reach: thickness_table = [thickness for i in range(section.nb_points)] - section.add_layer(thickness_table) + section.add_layer_from_thickness(thickness_table) def summary(self): + """ + Method to print the summary of the MascaretGeoFile object + """ txt = '~> %s\n' % self for _, reach in self.reaches.items(): txt += ' - %s\n' % reach @@ -241,8 +397,8 @@ if __name__ == '__main__': 'examples', 'mascaret'), '*.geo') geo_files += recursive_glob(os.path.join(os.environ['HOMETEL'], 'examples', 'mascaret'), 'geometrie') - for file_name in sorted(geo_files): - geo_file = MascaretGeoFile(file_name, 'geo') + for filename in sorted(geo_files): + geo_file = MascaretGeoFile(filename, 'geo') print(geo_file.summary()) except MascaretException as e: print(str(e))