DataInterface#
- class DataInterface(params=None, **kwargs)#
Bases:
Generic[T_Params,T_Source,T_Data]Define how to interface with data.
Delegates features to modules for parameters management, source management, data loading, and data writing.
- Parameters:
params (Any | None)
kwargs (Any)
- Loader#
alias of
LoaderAbstract
- Parameters#
alias of
ParametersAbstract
- Source#
alias of
SourceAbstract
- Writer#
alias of
WriterAbstract
- get_data(*args, **kwargs)#
Return data object.
Wraps around
loader.get_data().
- get_data_sets(params_maps=None, params_sets=None, **kwargs)#
Return data for specific sets of parameters.
Each set of parameter will specify one filename. Parameters that do not change from one set to the next do not need to be specified if they are fixed (by setting them in the interface). The sets can be specified with either one of params_maps or params_sets.
- Parameters:
params_maps (Sequence[Mapping[str, Any]] | None) –
Each set is specified by a mapping of parameters names to a value:
[{'Y': 2020, 'm': 1, 'd': 15}, {'Y': 2021, 'm': 2, 'd': 24}, {'Y': 2022, 'm', 6, 'd': 2}]
This will give 3 filenames for 3 different dates. Note that here, the parameters do not need to be the same for all sets, for example in a fourth set we could have
{'Y': 2023, 'm': 1, 'd': 10, 'depth': 50}to override the value of ‘depth’ set in the interface parameters.params_sets (Sequence[Sequence] | None) –
Here each set is specified by sequence of parameters values. This first row gives the order of parameters. The same input as before can be written as:
[['Y', 'm', 'd'], [2020, 1, 15], [2021, 2, 24], [2022, 6, 2]]
Here the changing parameters must remain the same for the whole sequence.
kwargs (Any) – Arguments passed to
get_data().
- Returns:
data – List of data objects corresponding to each set of parameters. Subclasses can overwrite this method to specify how to combine them into one if needed.
- Return type:
- get_source(*args, **kwargs)#
Return source for the data.
Can be filenames, URL, store object, etc.
Wraps around
source.get_source().
- loader: LoaderAbstract[T_Source, T_Data]#
- parameters: ParametersAbstract[T_Params]#
- register_callback(key, func)#
Register a new callback. Throw error if it already exists.
- save_excursion(save_cache=False)#
Save and restore current parameters after a with block.
For instance:
# we have some parameters, self.parameters["p"] = 0 with self.save_excursion(): # we change them self.parameters["p"] = 2 self.get_data() # we are back to self.parameters["p"] = 0
Any exception happening in the with block will be raised.
- Parameters:
save_cache (bool) – If true, save and restore the cache. This may lead to unexpected behavior and is disabled by default.
- Returns:
context – Context object containing the original parameters.
- Return type:
_ParamsContext
- source: SourceAbstract[T_Source]#
- trigger_callbacks(callbacks=True, **kwargs)#
Call all registered callbacks.
Modules should register callback in the dictionary
_reset_callbacksduringsetup().
- write(*args, **kwargs)#
Write data to target.
Wraps around
writer.write().
- writer: WriterAbstract[T_Source, T_Data]#