talsimpy 3.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
talsimpy/__init__.py ADDED
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ # ---------------------------------------------------------
3
+ # Copyright (C) SYDRO Consult GmbH, <mail@sydro.de>
4
+ # This file may not be copied, modified and/or distributed
5
+ # without the express permission of SYDRO Consult GmbH
6
+ # ---------------------------------------------------------
7
+ """
8
+ Package talsim
9
+
10
+ This package contains the following classes:
11
+ * `TalsimDataset` for handling and manipulating a Talsim ASCII dataset
12
+ * `TalsimDatabase` for handling a Talsim 5 database
13
+ * `TalsimScenario` for handling and manipulating a scenario in a database
14
+ * `TalsimEngine` for carrying out simulations with Talsim
15
+ * `Timeseries` for handling and manipulating time series
16
+ """
17
+
18
+ __version__ = "3.0.0"
19
+
20
+ from .talsimdatabase import TalsimDatabase
21
+ from .talsimdataset import TalsimDataset
22
+ from .talsimscenario import TalsimScenario
23
+ from .talsimengine import TalsimEngine
24
+ from .timeseries import Timeseries
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ # ---------------------------------------------------------
3
+ # Copyright (C) SYDRO Consult GmbH, <mail@sydro.de>
4
+ # This file may not be copied, modified and/or distributed
5
+ # without the express permission of SYDRO Consult GmbH
6
+ # ---------------------------------------------------------
7
+ """
8
+ Package talsim
9
+ """
10
+ from __future__ import annotations
11
+ import logging
12
+ from pathlib import Path
13
+ import sqlite3
14
+
15
+ from .talsimscenario import TalsimScenario
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+ class TalsimDatabase():
20
+ """
21
+ CLass for handling a Talsim 5 database
22
+ """
23
+
24
+ def __init__(self, path: Path|str):
25
+
26
+ self.path = Path(path)
27
+ self.scenarios: dict[int, str] = {} # {id: name, ...}
28
+
29
+ try:
30
+ conn = sqlite3.Connection(path)
31
+ # read scenarios
32
+ result = conn.execute("SELECT Id, Name FROM Scenario ORDER BY Id;")
33
+ for id, name in result:
34
+ self.scenarios[id] = name
35
+
36
+ except Exception as e:
37
+ logger.error(f"Error while reading Talsim database: {e}")
38
+
39
+ finally:
40
+ result.close()
41
+ conn.close()
42
+
43
+
44
+ def open_scenario(self, scenario_id: int) -> TalsimScenario:
45
+ """
46
+ Opens a scenario from the database, returning a corresponding TalsimScenario instance
47
+ """
48
+ return TalsimScenario(self.path, scenario_id)
49
+
50
+
51
+ def __repr__(self) -> str:
52
+ return f"Talsim database at {self.path}"