Cache Setting
cache_setting
parameter to the RetrievalSettings
class. Some subclasses and mappings covering common use cases for retrieving data are provided.
Usage¤
Currently, these are the options that can be passed to the cache_setting
parameter in RetrievalSettings
:
- An instance of a subclass of
CacheSetting
- A string identifier in the
_cache_setting_mappings
dictionary:_cache_setting_mappings: Dict[str, CacheSetting] = { "sql": SQLCacheSetting(), }
- A dictionary mapping tokamak type strings to the desired
CacheSetting
for that tokamak. E.g.{'cmod': 'sql'}
. Currently supported tokamak type strings are:"cmod", "d3d"
Built-in Implementations¤
This module provides classes for managing and retrieving cached data from various sources, including SQL databases and Pandas DataFrames.
disruption_py.settings.cache_setting.CacheSettingDict ¤
Bases: CacheSetting
A class that resolves and manages cache settings for Tokamak instances.
This class takes a dictionary of cache settings and resolves them for easy access.
ATTRIBUTE | DESCRIPTION |
---|---|
resolved_cache_setting_dict |
A mapping of Tokamak instances to their resolved cache settings.
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
cache_setting_dict |
A dictionary of initial cache settings for each Tokamak.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
_get_cache_data |
Retrieves cache data for the specified Tokamak. |
Source code in disruption_py/settings/cache_setting.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
disruption_py.settings.cache_setting.DFCacheSetting ¤
Bases: CacheSetting
Cache setting for retrieving data from a Pandas DataFrame.
PARAMETER | DESCRIPTION |
---|---|
cache_data |
The DataFrame to use as the cached data.
TYPE:
|
Source code in disruption_py/settings/cache_setting.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
disruption_py.settings.cache_setting.SQLCacheSetting ¤
Bases: CacheSetting
Cache setting for retrieving data from SQL database.
Source code in disruption_py/settings/cache_setting.py
122 123 124 125 126 127 |
|
disruption_py.settings.cache_setting.resolve_cache_setting ¤
resolve_cache_setting(
cache_setting: CacheSettingType,
) -> CacheSetting
Resolve the cache setting to a CacheSetting instance.
PARAMETER | DESCRIPTION |
---|---|
cache_setting |
The cache setting to resolve. This can be an instance of CacheSetting, a string representing a cache setting type, a Pandas DataFrame, or a dictionary of cache settings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CacheSetting
|
An instance of CacheSetting corresponding to the provided cache setting. |
Source code in disruption_py/settings/cache_setting.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
Custom Implementations¤
Custom implementations of cache setting must inherit from the CacheSetting
abstract class, implementing the abstract methods.
This module provides classes for managing and retrieving cached data from various sources, including SQL databases and Pandas DataFrames.
disruption_py.settings.cache_setting.CacheSetting ¤
Bases: ABC
CacheSetting abstract class that should be inherited by all cache setting classes.
Subclasses must implement the _get_cache_data
method to define how cached data is retrieved.
Source code in disruption_py/settings/cache_setting.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
_get_cache_data
abstractmethod
¤
_get_cache_data(params: CacheSettingParams) -> pd.DataFrame
Abstract method implemented by subclasses to get cached data for a given set of params as a Pandas dataframe.
PARAMETER | DESCRIPTION |
---|---|
params |
Params that can be used to determine and retrieve cached data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Pandas dataframe containing cached data. |
Source code in disruption_py/settings/cache_setting.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
get_cache_data ¤
get_cache_data(params: CacheSettingParams) -> pd.DataFrame
Return cached data, using tokamak-specific overrides if available.
Source code in disruption_py/settings/cache_setting.py
56 57 58 59 60 61 62 63 |
|
disruption_py.settings.cache_setting.CacheSettingParams
dataclass
¤
Params passed by disruption_py to _get_cache_data() method.
ATTRIBUTE | DESCRIPTION |
---|---|
shot_id |
Shot Id for which to get cached data. Defaults to logbook.
TYPE:
|
database |
Database object to use for getting cached data. A different database connection is used by each thread/process.
TYPE:
|
tokamak |
The tokamak being run.
TYPE:
|
logger |
Logger object from disruption_py to use for logging.
TYPE:
|
Source code in disruption_py/settings/cache_setting.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|