el1xr_opt.Modules.oM_InputSource#
el1xr_opt input source — the InputSource interface and open_source factory.
The model reads its input through one of two backends:
CSVSource— a directory ofoM_Dict_*/oM_Data_*CSV files(the historical layout).
DuckDBSource— a single<case>.duckdbfile holding the same tables.
open_source(path) looks at the path and returns the right backend: a
directory gives a CSVSource, a .duckdb file gives a DuckDBSource.
Both backends return identical DataFrames, so the rest of the model does not
know or care which one was used.
The duckdb backend is imported lazily, so a checkout without duckdb
installed can still build the CSV path.
- class el1xr_opt.Modules.oM_InputSource.InputSource[source]#
Bases:
ABCAbstract input source. Implementations:
CSVSource,DuckDBSource.-
case_name:
str#
- abstract list_data_stems()[source]#
Stems of the data tables present (no
oM_Data_prefix, no_<case>.csvsuffix).- Return type:
set
- abstract read_dict(stem)[source]#
Return the dimension dict for
stemas a plain DataFrame (no index).Returns an empty DataFrame if the dict is absent.
- Return type:
DataFrame- Parameters:
stem (str)
- abstract read_data(stem)[source]#
Return a data table with its leading unnamed columns set as a nameless index.
This is the exact shape
oM_InputDataexpects: the same DataFrame the oldpd.read_csv+set_index(unnamed columns)code produced. RaisesFileNotFoundErrorif the stem is absent.- Return type:
DataFrame- Parameters:
stem (str)
-
case_name:
- el1xr_opt.Modules.oM_InputSource.open_source(path)[source]#
Return a
CSVSourcefor a directory or aDuckDBSourcefor a.duckdbfile.- Return type:
- Parameters:
path (str | PathLike)
- el1xr_opt.Modules.oM_InputSource.resolve_source(dir_name, case_name)[source]#
Pick the input for
(dir_name, case_name).Prefers the CSV case folder
<dir_name>/<case_name>when it holds the case’soM_Data_Parameterfile (so CSV stays the default whenever a real case folder is present), otherwise falls back to the DuckDB file<dir_name>/<case_name>.duckdb. Checking for the Parameter file rather than just the folder means an empty results folder of the same name does not shadow a.duckdbinput.- Return type:
- Parameters:
dir_name (str | PathLike)
case_name (str)