Public API
All public packages, functions and classes are available in this module.
Functions:
Data classes:
- ImasHandle
- IDSMapping
- Variable
- Job
- [Run][duqtools.api.Run]
- [Runs][duqtools.api.Runs]
Plotting:
IDSMapping(ids)
Bases: Mapping
Empty arrays are excluded from the mapping.
You can still get/set these keys directly,
but key in map
returns False
if map['key']
is an empty array.
Parameters:
-
ids
(Any
) –IMAS DB entry for the IDS.
Attributes:
-
exclude_empty
(bool
) –
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
dive(val, path)
Recursively find the data fields.
Parameters:
-
val
–Current nested object being evaluated
-
path
(list
) –Current path
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
204 205 206 207 208 209 210 211 212 213 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 |
|
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 /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
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 /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
get_at_index(variable, index, **kwargs)
Grab key with index replacement.
Example: IDSMapping.get_at_index(var, index=0)
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
144 145 146 147 148 149 150 151 |
|
length_of_key(key)
length_of_key gives you the number of entries of a (partial) ids path, or None if the length does not exist.
Note: this is different then the length of an IDSMapping, which is defined as the number of keys
Note: calling len(map[key])
works as well
Example:
map.length_of_key('1d_profiles')
Parameters:
-
key
(str
) –key
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
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 |
|
set_at_index(variable, index, value, **kwargs)
Grab key with index replacement.
Example: IDSMapping.set_at_index(var, value, index=0)
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
153 154 155 156 157 158 159 160 |
|
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 /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
to_xarray(variables, empty_var_ok=False, **kwargs)
Return dataset for given variables.
Parameters:
-
variables
(Sequence[str | IDSVariableModel]]
) –Dictionary of data variables
-
empty_var_ok
(bool
, default:False
) –If True, silently skip data that are missing from the mapping. If False (default), raise an error when data that are missing from the dataset are requested.
Returns:
-
ds
(Dataset
) –Return query as Dataset
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
write_array_in_parts(variable_path, data)
write_back data, give the data, and the variable path, where *
denotes the dimensions. This function will figure out how to write it
back to the IDS.
Parameters:
-
variable_path
(str
) –path of the variable in the IDS, something like 'profiles_1d/*/zeff'
-
data
(DataArray
) –data of the variable, in the correct dimensions (every star in the
variable_path
is a dimension in this array)
Returns:
-
None
–
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_mapping.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
ImasHandle
Bases: ImasBaseModel
is_local_db
property
Return True if the handle points to a local imas database.
copy_data_to(destination)
Copy ids entry to given destination.
Parameters:
-
destination
(ImasHandle
) –Copy data to a new location.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
delete()
Remove data from entry.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
183 184 185 186 187 188 189 190 191 192 193 194 |
|
entry(backend=imasdef.MDSPLUS_BACKEND)
Return reference to imas.DBEntry.
Parameters:
-
backend
(optional
, default:MDSPLUS_BACKEND
) –Which IMAS backend to use
Returns:
-
entry
(`imas.DBEntry`
) –IMAS database entry
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
exists()
Return true if the directory exists.
Returns:
-
bool
–
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
158 159 160 161 162 163 164 165 166 |
|
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 /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
get(ids='core_profiles')
Map the data to a dict-like structure.
Parameters:
-
ids
(str
, default:'core_profiles'
) –Name of profiles to open
Returns:
-
IDSMapping
–
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
get_all_variables(extra_variables=[], squash=True, ids='core_profiles', **kwargs)
Get all variables that duqtools knows of from selected ids from the dataset.
This function looks up the data location from the
duqtools.config.var_lookup
table
Parameters:
-
variables
(Sequence[IDSVariableModel]
) –Extra variables to load in addition to the ones known by duqtools.
-
squash
(bool
, default:True
) –Squash placeholder variables
Returns:
-
ds
(xarray
) –The data in
xarray
format. -
**kwargs
–These keyword arguments are passed to
IDSMapping.to_xarray()
Raises:
-
ValueError
–When variables are from multiple IDSs.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
get_raw_data(ids='core_profiles', **kwargs)
Get data from IDS entry.
Parameters:
-
ids
(str
, default:'core_profiles'
) –Name of profiles to open.
-
**kwargs
–These keyword parameters are passed to
ImasHandle.open()
.
Returns:
-
data
–
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
get_variables(variables, squash=True, **kwargs)
Get variables from data set.
This function looks up the data location from the
duqtools.config.var_lookup
table, and returns
Parameters:
-
variables
(Sequence[Union[str, IDSVariableModel]]
) –Variable names of the data to load.
-
squash
(bool
, default:True
) –Squash placeholder variables
Returns:
-
ds
(xarray
) –The data in
xarray
format. -
**kwargs
–These keyword arguments are passed to
IDSMapping.to_xarray()
Raises:
-
ValueError
–When variables are from multiple IDSs.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 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 |
|
imasdb_path()
Return path to imasdb.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
154 155 156 |
|
open(backend=imasdef.MDSPLUS_BACKEND, create=False)
Context manager to open database entry.
Parameters:
-
backend
(optional
, default:MDSPLUS_BACKEND
) –Which IMAS backend to use
-
create
(bool
, default:False
) –Create empty database entry if it does not exist.
Yields:
-
entry
(`imas.DBEntry`
) –Opened IMAS database entry
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
path(suffix=SUFFIXES[0])
Return location as Path.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
paths()
Return location of all files as a list of Paths.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
150 151 152 |
|
to_string()
Generate string representation of Imas location.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
123 124 125 |
|
validate()
Validate the user.
If the user is a path, then create it.
Raises:
-
ValueError:
–If the user is invalid.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_handle.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
Job(path, *, cfg)
Parameters:
-
path
(Path
) –Directory for simulation or model run.
-
cfg
(Optional[Config]
) –Duqtools config, defaults to global config if unspecified.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
has_status: bool
property
Return true if a status file exists.
has_submit_script: bool
property
Return true if directory has submit script.
in_file: Path
property
Return path to the input file for the job.
is_completed: bool
property
Return true if the job has been completed succesfully.
is_done: bool
property
Return true if the job is done (completed or failed).
is_failed: bool
property
Return true if the job has failed.
is_running: bool
property
Return true if the job is running.
is_submitted: bool
property
Return true if the job has been submitted.
lockfile: Path
property
Return the path of the lockfile.
out_file: Path
property
Return path to the output file for the job.
status_file: Path
property
Return the path of the status file.
status_symbol
property
One letter status symbol.
submit_script: Path
property
Return the path of the submit script.
start()
Submit job and return generate that raises StopIteration when done.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
161 162 163 164 165 166 167 168 |
|
status()
Return the status of the job.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
status_symbol_help()
staticmethod
Return help string for status codes.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
63 64 65 66 |
|
submit()
Submit job.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
153 154 155 156 157 158 159 |
|
wait_until_done(time_step=1.0)
Submit task and wait until done.
Parameters:
-
time_step
(float
, default:1.0
) –Time in seconds step between status updates.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/models/_job.py
170 171 172 173 174 175 176 177 178 179 |
|
Variable
Bases: IDSPath
Variable for describing data within a IMAS database.
The variable can be given a name, which will be used in the rest of the config to reference the variable. It will also be used as the column labels or on plots.
The dimensions for each variable must be specified. This ensures the
the data will be self-consistent. For example for 1D data, you can
use [x]
and for 2D data, [x, y]
.
The IDS path may contain indices. You can point to a single index,
by simply giving the complete path (i.e. profiles_1d/0/t_i_ave
for
the 0th time slice). To retrieve all time slices, you can use
profiles_1d/*/t_i_ave
.
alt_errorband_chart(source, *, x, y, z='time')
Generate an altair errorband plot from a dataframe.
Parameters:
-
source
(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
-
z
(str
, default:'time'
) –Slider variable (time), corresponds to a column in the source data
Returns:
-
Chart
–Return an altair chart.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/_plot_utils.py
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 153 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 190 191 192 193 194 195 |
|
alt_line_chart(source, *, x, y, z='time', std=False)
Generate an altair line chart from a dataframe.
Parameters:
-
source
(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
-
z
(str
, default:'time'
) –Slider variable (time), corresponds to a column in the source data
std : bool Plot the error bound from {x}_error_upper in the plot as well
Returns:
-
Chart
–Return an altair chart.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/_plot_utils.py
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 79 80 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 |
|
create(config, **kwargs)
Wrapper around create for python api.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/create.py
302 303 304 305 306 307 308 309 310 311 312 313 |
|
duqmap(function, *, runs=None, **kwargs)
Duqmap is a mapping function which can be used to map a user defined
function function
over either the runs created by duqtools, or the runs
specified by the user in runs
.
An important gotcha is that when Paths
are used to define the runs, duqtools
does not know how to associate the corresponding ImasHandles, as that information
is not available. So when using it in this way, it is not possible to provide a
function which takes an ImasHandle
as input.
Parameters:
-
function
(Callable[[Run | ImasHandle], Any]
) –function which is called for each run, specified either by
runs
, or implicitly by any availableruns.yaml
-
runs
(Optional[List[Run | Path]]
, default:None
) –A list of runs over which to operate the function
-
kwargs
–optional arguments that need to be passed to each
function
that you provide
Returns:
-
List[Any]:
–A list of anything that your function returns
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/duqmap.py
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 85 86 87 |
|
get_status(config, **kwargs)
Wrapper around status for python api.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/status.py
218 219 220 221 |
|
rebase_all_coords(datasets, reference_dataset)
Rebase all coords, by applying rebase operations.
Parameters:
-
datasets
(Sequence[Dataset]
) –datasets
-
reference_dataset
(Dataset
) –reference_dataset
Returns:
-
tuple[Dataset, ...]
–
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_rebase.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
rebase_on_grid(ds, *, coord_dim, new_coords)
Rebase (interpolate) the coordinate dimension to the new coordinates.
Thin wrapper around xarray.Dataset.interp
.
Parameters:
-
ds
(Dataset
) –Source dataset
-
coord_dim
(str
) –Name of the grid dimension (i.e. grid variable).
-
new_coords
(ndarray
) –The coordinates to interpolate to
Returns:
-
Dataset
–Rebased dataset
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_rebase.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
rebase_on_time(ds, *, time_dim='time', new_coords)
Rebase (interpolate) the time dimension to the new coordinates.
Thin wrapper around xarray.Dataset.interp
.
Parameters:
-
ds
(Dataset
) –Source dataset
-
time_dim
(str
, default:'time'
) –Name of the time dimension (i.e. time variable).
-
new_coords
(ndarray
) –The coordinates to interpolate to
Returns:
-
Dataset
–Rebased dataset
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_rebase.py
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 |
|
recreate(config, runs, **kwargs)
Wrapper around create for python api.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/create.py
354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
standardize_grid_and_time(datasets, *, grid_var='rho_tor_norm', time_var='time', reference_dataset=0)
Standardize list of datasets by applying standard rebase operations.
Applies, in sequence:
1. rezero_time
2. standardize_grid
3. rebase_on_grid
4. rebase_on_time
Parameters:
-
datasets
(Sequence[Dataset]
) –List of source datasets
-
grid_var
(str
, default:'rho_tor_norm'
) –Name of the grid dimension (i.e. grid variable)
-
time_var
(str
, default:'time'
) –Name of the time dimension (i.e. time variable)
-
reference_dataset
(int
, default:0
) –The dataset with this index will be used as the reference for rebasing. The grid and time coordinates of the other datasets will be rebased to the reference.
Returns:
-
tuple[Dataset]
–Tuple of output datasets
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/ids/_rebase.py
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
submit(config, **kwargs)
Wrapper around submit for python api.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/submit.py
271 272 273 274 |
|