pyarts3.utils
This module contains convenience functions for any purposes.
- class pyarts3.utils.TempFileHandler(prefix='pyarts', suffix='.tmp', dir=None)[source]
Context manager for creating and deleting temporary files.
This class is a context manager that creates a temporary file and deletes it when the context is exited. The file is automatically removed if an exception occurs.
- Parameters:
- pyarts3.utils.builtin_groups(mod=<module 'pyarts3.arts' from '/scratch3/u237/users/olemke/code/arts/build/python/src/pyarts3/arts.cpython-312-x86_64-linux-gnu.so'>)[source]
- pyarts3.utils.deprecated(func=None, new_name=None, message=None)[source]
Decorator which can be used to mark functions as deprecated.
Examples
Calling
foo()
will raise aDeprecationWarning
.>>> @deprecated ... def deprecated_function(): ... pass
Display message with additional information:
>>> @deprecated(message='Additional information message.') ... def deprecated_function(): ... pass
- pyarts3.utils.path_append(dirname, path='PATH')[source]
Append a directory to environment path variable.
Append entries to colon-separated variables (e.g. the system path). If the entry is already in the list, it is moved to the end. A path variable is set, if not existing at function call.
- pyarts3.utils.path_prepend(dirname, path='PATH')[source]
Prepend a directory to environment path variable.
Append entries to colon-separated variables (e.g. the system path). If the entry is already in the list, it is moved to the end. A path variable is set, if not existing at function call.
- pyarts3.utils.path_remove(dirname, path='PATH')[source]
Remove a directory from environment path variable.
Remove entries from colon-separated variables (e.g. the system path). If the path variable is not set, nothing is done.
- pyarts3.utils.time_report(*, mode='plot', clear=True, scale=1.0, fig=None, mintime=None)[source]
Plots the time report.
The time report is available only when ARTS has been compiled with the CMake option
-DENABLE_ARTS_PROFILING=ON
, which is not part of the default distribution.Nevertheless, there is enough helpful parts in being able to see the state of parallelism and report the time of internal methods that this method is part of the distribution.
There is a cost in terms of performance to having the time report enabled, so it should not be used in production runs.
- Parameters:
mode (str, optional) – The mode of output. Options are “plot” and “table”. Default is “plot”.
clear (bool, optional) – Whether or not to clear the time-report. Default is True.
scale (float, optional) – The scale of the time axis, defaults to 1.0. Special values are 1e3 for milliseconds and 1e6 for microseconds.
fig (matplotlib figure, optional) – The figure to draw on in a plotting mode. By default creates a new figure.
mintime (float, optional) – The minimum time in seconds for a method to be included in the report. This is useful to filter out methods that are called often but take very little time, and thus clutter the report. Default is None to include all methods. mintime is applied after scaling.
- Returns:
r (dict) – The time report
*out (tuple) – If mode is “plot”, returns the matplotlib figure and axis. If mode is “table”, returns a string containing the time report in Markdown table format.
- pyarts3.utils.unique(seq)[source]
Remove duplicates from list whilst keeping the original order
Notes
If you do not care about keeping the order, use this code: >>>> list(set([0, 5, 1, 2, 0, 3, 1,])) [0, 1, 2, 3, 5]
This code is taken from https://stackoverflow.com/a/480227.
- Parameters:
seq – A sequence (list, etc.) of elements.
- Returns:
A list with unique items with original order.
Examples
>>>> unique([0, 5, 1, 2, 0, 3, 1,])