Coverage for python/gsfit/database_writers/__init__.py: 43%
14 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
1from .interface import DatabaseWriterProtocol
4def get_database_writer(method: str) -> DatabaseWriterProtocol:
5 """
6 Returns a `DatabaseWriter` instance for accessing different databases.
8 :param method: selects which DatabaseWriter to use. `method` is specified in the `GSFIT_code_settings.json` input file.
10 Lazy imports of the DatabaseWriter*** classes is deliberate.
11 This allows GSFit to function without having every database_writer module installed.
12 This is useful because not every institution will make their database interface public.
14 Typically, the `gsfit_controller` object is passed into the `DatabaseWriter` class.
15 `gsfit_controller.results` is intended to be a 1:1 mapping of nested dictionaries to the database structure
16 (in Tokamak Energy's case this is MDSplus).
17 """
19 match method:
20 case "tokamak_energy_mdsplus":
21 from .tokamak_energy_mdsplus import DatabaseWriterTokamakEnergyMDSplus
23 return DatabaseWriterTokamakEnergyMDSplus()
24 case "tokamak_energy_mdsplus_new":
25 from .tokamak_energy_mdsplus_new import DatabaseWriterTokamakEnergyMDSplusNew
27 return DatabaseWriterTokamakEnergyMDSplusNew()
28 case "rtgsfit_mdsplus":
29 from .rtgsfit_mdsplus import DatabaseWriterRTGSFitMDSplus
31 return DatabaseWriterRTGSFitMDSplus()
32 case _:
33 raise ValueError(f"Unknown database writer method: {method}")