Coverage for C:\src\imod-python\imod\msw\initial_conditions.py: 67%
42 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 10:26 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 10:26 +0200
1import pathlib
2import shutil
4from imod.msw.fixed_format import VariableMetaData
5from imod.msw.pkgbase import MetaSwapPackage
8class InitialConditionsEquilibrium(MetaSwapPackage):
9 """
10 Use an equilibrium profile to initialize the model.
12 This class is responsible for the file `init_svat.inp`
13 """
15 _file_name = "init_svat.inp"
16 _option = "Equilibrium"
17 _metadata_dict = {}
19 def __init__(self):
20 super().__init__()
22 def _render(self, file, *args):
23 file.write(self._option + "\n")
26class InitialConditionsRootzonePressureHead(MetaSwapPackage):
27 """
28 Use the pF-value of the root zone pressure head as initial condition.
30 This class is responsible for the file `init_svat.inp`
32 Parameters
33 ----------
34 initial_pF: float
35 Initial pF value to be used for all soil columns.
36 """
38 _file_name = "init_svat.inp"
39 _option = "Rootzone_pF"
40 _metadata_dict = {
41 "initial_pF": VariableMetaData(6, 0.0, 6.0, float),
42 }
44 def __init__(self, initial_pF=2.2):
45 super().__init__()
46 self.dataset["initial_pF"] = initial_pF
48 def _render(self, file, *args):
49 file.write(self._option + "\n")
51 dataframe = self.dataset.assign_coords(index=[0]).to_dataframe()
53 self.write_dataframe_fixed_width(file, dataframe)
56class InitialConditionsPercolation(MetaSwapPackage):
57 """
58 The precipitation intensity at the starting time (iybg, tdbg in
59 PARA_SIM.INP) is used for initializing the percolation flux in the profiles.
60 This type of initialization is normally done separately from the actual run,
61 using a specially prepared meteo-input file. After letting the model reach
62 near equilibrium by letting it run for a number of years, the saved state is
63 used for the initialization of subsequent runs.
65 This class is responsible for the file `init_svat.inp`
66 """
68 _file_name = "init_svat.inp"
69 _option = "MeteoInputP"
70 _metadata_dict = {}
72 def __init__(self):
73 super().__init__()
75 def _render(self, file, *args):
76 file.write(self._option + "\n")
79class InitialConditionsSavedState(MetaSwapPackage):
80 """
81 Use saved state of a previous MetaSWAP run as initial condition.
83 This class is responsible for the file `init_svat.inp`
85 Parameters
86 ----------
87 saved_state: Path or str
88 Path to a previously saved state. This file will be copied to
89 init_svat.inp.
91 """
93 _file_name = "init_svat.inp"
94 _option = "Saved_State"
95 _metadata_dict = {}
97 def __init__(self, saved_state):
98 super().__init__()
99 self.saved_state = saved_state
101 def write(self, directory, *args):
102 directory = pathlib.Path(directory)
103 filename = directory / self._file_name
105 shutil.copyfile(self.saved_state, filename)