fips.utils#
Utility functions for inversion module.
Functions
|
Convert a pandas DataFrame to an xarray DataArray. |
|
Parallelize a function across an iterable. |
|
Rounds the values in a pandas Index or MultiIndex if the level's data type is a numpy floating type. |
- fips.utils.parallelize(func, num_processes=1)[source]#
Parallelize a function across an iterable.
- Parameters:
func (function) – The function to parallelize.
num_processes (int or 'max', optional) – The number of processes to use. Uses the minimum of the number of items in the iterable and the number of CPUs requested. If ‘max’, uses all available CPUs. Default is 1.
- Returns:
parallelized – A function that will execute the input function in parallel across an iterable.
- Return type:
function
- fips.utils.round_index(index, decimals)[source]#
Rounds the values in a pandas Index or MultiIndex if the level’s data type is a numpy floating type.
- Parameters:
index (pd.Index | pd.MultiIndex) – Input index to round.
decimals (int) – Number of decimal places to round to.
- Returns:
Rounded index.
- Return type:
pd.Index | pd.MultiIndex
- fips.utils.dataframe_matrix_to_xarray(frame)[source]#
Convert a pandas DataFrame to an xarray DataArray.
If the DataFrame has a MultiIndex for columns, all levels of the MultiIndex are stacked into the index of the resulting DataArray.
- Parameters:
frame (pd.DataFrame) – DataFrame to convert.
- Returns:
Converted DataArray.
- Return type:
xr.DataArray