Public API
All public packages, functions and classes are available in this module.
Functions:
Data classes:
Plotting:
IDSMapping(ids, exclude_empty=True, allow_blind_keys=False)
Bases: Mapping
Parameters:
-
ids
–
ids
-
exclude_empty
(
bool
) –exclude_empty
-
allow_blind_keys
(
bool
) –allows for the getting and inserting of keys which are not in the _keys, but could still fit in the ids
Source code in duqtools/ids/_mapping.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
dive(val, path)
Recursively find the data fields.
Parameters:
-
val
–
Current nested object being evaluated
-
path
(
List
) –Current path
Source code in duqtools/ids/_mapping.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
find_by_group(pattern)
Find keys matching regex pattern by group.
The dict key is defined by match.groups()
.
Dict entries will be overwritten if the groups are not unique.
Parameters:
-
pattern
(
str
) –Regex pattern (must contain groups)
Returns:
-
dict
–New dict with all matching key/value pairs.
Source code in duqtools/ids/_mapping.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
find_by_index(pattern)
Find keys matching regex pattern using time index.
Must include $i, which is a special character that matches
an integer (\d+
)
i.e. ids.find_by_index('profiles_1d/$i/zeff.*')
returns a dict with zeff
and error attributes.
Parameters:
-
pattern
(
str
) –Regex pattern, must include a group matching a digit.
Returns:
-
dict
–New dict with all matching key/value pairs.
Source code in duqtools/ids/_mapping.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
findall(pattern)
Find keys matching regex pattern.
Parameters:
-
pattern
(
str
) –Regex pattern
Returns:
-
dict
–New dict with all matching key/value pairs.
Source code in duqtools/ids/_mapping.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
sync(target)
Synchronize updated data back to IMAS db entry.
Shortcut for 'put' command.
Parameters:
-
target
(
ImasHandle
) –Points to an IMAS db entry of where the data should be written.
Source code in duqtools/ids/_mapping.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
to_dataframe(*variables, prefix='profiles_1d', time_steps=None)
Return long format dataframe for given variables.
Search string:
{prefix}/{time_step}/{variable}
Parameters:
-
*variables
(
str
) –Keys to extract, i.e.
zeff
,grid/rho_tor
-
prefix
(
str, optional
) –First part of the data path
-
time_steps
(
Sequence[int], optional
) –List or array of integer time steps to extract. Defaults to all time steps.
Returns:
Source code in duqtools/ids/_mapping.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
to_numpy(*variables, prefix='profiles_1d', time_steps=None)
Return numpy array containing data for given variables.
Search string:
{prefix}/{time_step}/{variable}
Parameters:
-
*variables
(
str
) –Keys to extract, i.e.
zeff
,grid/rho_tor
-
prefix
(
str, optional
) –First part of the data path
-
time_steps
(
Sequence[int], optional
) –List or array of integer time steps to extract. Defaults to all time steps.
Returns:
-
columns, array
–Numpy array with a column for the time step and each of the variables.
Source code in duqtools/ids/_mapping.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
ImasHandle
Bases: ImasBaseModel
copy_data_to(destination)
Copy ids entry to given destination.
Parameters:
-
destination
(
ImasHandle
) –Copy data to a new location.
Source code in duqtools/ids/_handle.py
98 99 100 101 102 103 104 105 106 107 |
|
delete()
Remove data from entry.
Source code in duqtools/ids/_handle.py
109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
entry(backend=imasdef.MDSPLUS_BACKEND)
Return reference to imas.DBEntry.
Parameters:
-
backend
(
optional
) –Which IMAS backend to use
Returns:
-
entry –
IMAS database entry
Source code in duqtools/ids/_handle.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
exists()
Return true if the directory exists.
Returns:
-
bool
–
Source code in duqtools/ids/_handle.py
88 89 90 91 92 93 94 95 96 |
|
from_string(string)
classmethod
Return location from formatted string.
Format:
<user>/<db>/<shot>/<run>
<db>/<shot>/<run>
Default to the current user if the user is not specified.
For example:
g2user/jet/91234/555
Parameters:
-
string
(
str
) –Input string containing imas db path
Returns:
-
ImasHandle
–
Source code in duqtools/ids/_handle.py
44 45 46 47 48 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 |
|
get(key='core_profiles', **kwargs)
Map the data to a dict-like structure.
Parameters:
-
key
(
str, optional
) –Name of profiles to open
-
**kwargs
–
These parameters are passed to initialize
IDSMapping
.
Returns:
-
IDSMapping
–
Source code in duqtools/ids/_handle.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
get_raw_data(key='core_profiles', **kwargs)
Get data from IDS entry.
Parameters:
-
key
(
str, optional
) –Name of profiles to open.
-
**kwargs
–
These keyword parameters are passed to
ImasHandle.open()
.
Returns:
-
data
–
Source code in duqtools/ids/_handle.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
open(backend=imasdef.MDSPLUS_BACKEND, create=False)
Context manager to open database entry.
Parameters:
-
backend
(
optional
) –Which IMAS backend to use
-
create
(
bool, optional
) –Create empty database entry if it does not exist.
Yields:
-
entry –
Opened IMAS database entry
Source code in duqtools/ids/_handle.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
path()
Return location as Path.
Source code in duqtools/ids/_handle.py
79 80 81 82 83 84 85 86 |
|
to_string()
Generate string representation of Imas location.
Source code in duqtools/ids/_handle.py
75 76 77 |
|
alt_errorband_chart(source, *, x, y)
Generate an altair errorband plot from a dataframe.
The dataframe must be generated using duqtools.ids.get_ids_dataframe
(or
have the same format).
Parameters:
-
source
(
pd.DataFrame
) –Input dataframe
-
x
(
str
) –X-value to plot, corresponds to a column in the source data
-
y
(
str
) –Y-value to plot, corresponds to a column in the source data
Returns:
-
alt.Chart
–Return an altair chart.
Source code in duqtools/_plot_utils.py
41 42 43 44 45 46 47 48 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 81 82 83 84 |
|
alt_line_chart(source, *, x, y)
Generate an altair line chart from a dataframe.
The dataframe must be generated using duqtools.ids.get_ids_dataframe
(or
have the same format).
Parameters:
-
source
(
pd.DataFrame
) –Input dataframe
-
x
(
str
) –X-value to plot, corresponds to a column in the source data
-
y
(
str
) –Y-value to plot, corresponds to a column in the source data
Returns:
-
alt.Chart
–Return an altair chart.
Source code in duqtools/_plot_utils.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
get_ids_dataframe(handles, *, keys, **kwargs)
Read a dict of IMAS handles into a structured pandas dataframe.
The returned dataframe will have the columns:
`run`, `tsteps`, `times`, `<ids col 1>, `<ids_col_2>`, ...
Where tstep
corresponds to the time index, and times
to the
actual times.
Parameters:
-
handles
(
Union[Sequence[str], Dict[str, ImasHandle]]
) –Dict with IMAS handles. The key is used as the 'run' name in the dataframe. If the handles are specified as a sequence, The Imas string representation will be used as the key.
-
keys
(
Sequence[str]
) –IDS values to extract. These will be used as columns in the data frame.
-
**kwargs
–
These keyword parameters are passed to
duqtools.ids.IDSMapping.to_dataframe
.
Returns:
Source code in duqtools/ids/_io.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
rebase_on_grid(source, *, grid, cols, grid_base=None)
Rebase data on new ids basis using interpolation.
This operation makes sure that all data on the x-axis are the same for each run and time step.
Uses scipy.interpolate.interp1d.
Parameters:
-
source
(
pd.DataFrame
) –Input data, contains the columns 'run', 'tstep' and any number of ids columns.
-
grid
(
str
) –This defines the base ids column that the new base belongs to. In other words, this is the
x
column in the interpolation. -
cols
(
Sequence[str]
) –The data in these ids columns will be interpolated. In other words, these are the
y
columns in the interpolation. IDS columns not defined by grid and cols will be omitted from the output. -
grid_base
(
np.ndarray, optional
) –Numpy array with the new base values for the given base column. If not defined, use the data in the base column of the first time step of the first run as the basis.
Returns:
-
pd.DataFrame
–For the returned dataframe, for each run and time step, the values in the base column will be the same.
Source code in duqtools/ids/_rebase.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
|
rebase_on_time(source, *, cols, time_base=None)
Rebase data on new time basis using interpolation.
This operation makes sure that each run has the same time steps.
Uses scipy.interpolate.interp1d.
Parameters:
-
source
(
pd.DataFrame
) –Input data, contains the columns 'run', 'tstep' and any number of ids columns.
-
cols
(
Sequence[str]
) –This defines the columns that should be rebased. IDS columns not defined will be omitted from the output.
-
time_base
(
np.ndarray, optional
) –Numpy array with the new base values for the time steps. If not defined, use the time steps in the first run of the source data.
Returns:
Source code in duqtools/ids/_rebase.py
81 82 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|