scinumtools package

Subpackages

Submodules

scinumtools.cached_function module

scinumtools.cached_function.CachedFunction(file_cache)

Decorator function that cashes data produced by a function

Parameters:

file_cache (str) – Name of the file that will store cached data

scinumtools.cached_function.hash_file_name(file_cache, args, kwargs)

scinumtools.data_combination module

class scinumtools.data_combination.DataCombination(items)

Bases: object

items()
keys()
values()

scinumtools.data_plot_grid module

class scinumtools.data_plot_grid.DataPlotGrid(data: list | dict, ncols: int = 2, axsize: tuple = (4, 2))

Bases: object

data: list | dict
figsize: tuple
items(missing: bool | None = None, transpose: bool = False)
ncols: int
ndata: int
nrows: int

scinumtools.image_metadata module

class scinumtools.image_metadata.ImageMetadata(file_name: str)

Bases: object

file_name: str
get(key: Metadata)
metadata: dict
modified: bool = False
print()
save()
set(key: Metadata, value: str)
class scinumtools.image_metadata.Metadata(value)

Bases: Enum

An enumeration.

DATETIME = 'DateTime'
DIR_DATA = 'DirData'
DIR_SETUP = 'DirSetup'
GIT_BRANCH = 'GitBranch'
GIT_COMMIT = 'GitCommit'
SETTINGS = 'Settings'

scinumtools.normalize_data module

class scinumtools.normalize_data.NormalizeData(xaxis=None, yaxis=None)

Bases: object

Normalize numerical data across multiple plots

append(vdata, xdata=None, ydata=None)

Append data to the range collector

Statistics of x and y axes is optional

Parameters:
  • vdata – Numerical data

  • xdata – X-axis points

  • ydata – Y-axis points

data()

Return collected ranges as a dictionary

extent(xlog=False, ylog=False)
items()
linnorm()

Return linear norm from ranges

lognorm()

Return logarithmic norm from ranges

xaxis: str
xranges()

Return x-axis ranges

yaxis: str
yranges()

Return y-axis ranges

zranges()

Return data ranges

class scinumtools.normalize_data.Ranges(minpos: float, min: float, max: float)

Bases: object

Dataclass that contains data ranges

max: float
min: float
minpos: float

scinumtools.parameter_table module

class scinumtools.parameter_table.ParameterSettings(settings)

Bases: object

ParameterSettings class contain all settings of a parameter

data()
items()
keys()
class scinumtools.parameter_table.ParameterTable(settings: list, parameters: list | dict | None = None, keys: bool = False, keyname: str = '#')

Bases: object

ParameterDict class collects parameters in a concise form and create a dictionary

append(*args)
data()
items()
keys()
shape()
to_dataframe()
to_text(**kwargs)

scinumtools.progress_bar module

class scinumtools.progress_bar.ProgressBar(nsteps: int)

Bases: object

close()
current: int = 0
nsteps: int
ntimes: int = 20
size: int = 70
step(info: int = '')
time_start: float
times: deque

scinumtools.row_collector module

class scinumtools.row_collector.RowCollector(columns: list | dict = [], rows: list | None = None, array: bool = False)

Bases: object

RowCollector class collect table rows and transform them into one of available formats

Example of use:

import scinumtools as snt

with snt.structs.RowCollector(['col1','col2','col3']) as rc:
     rc.append([1,2,3])
     rc.append([4,5,6])
     data = rc.to_dict()
Parameters:
  • columns – This can be either a list of column names or a dictionary with column array settings

  • array (bool) – Stores values as numpy arrays if ‘True’, otherwise store data in lists

append(values: list | dict)

Append a single row

Parameters:

values – List of values for each column

shape()
size()

Get number of items in columns

sort(name: str, reverse=False)

Sort all columns according to one

Parameters:

name (str) – name of the sorting column

to_csv(file_name: str, **kwargs)

Save class data as a CSV formatted file

Parameters:

str (file_name) – Name of the new file

to_dataframe(columns: list | dict | None = None)

Convert class data to a pandas data frame

Parameters:

columns – This can be either a list of columns or a dictionary of column:title pairs. If not set, all coumns are being taken.

to_dict(transpose: str | None = None)

Convert class data to a dictionary of lists/arrays

to_file(file_name: str, **kwargs)

Save tabulated class data as a text file

Parameters:

str (file_name) – Name of the new file

to_text(**kwargs)

Convert class data to a text using pandas dataframe

Parameters:

kwargs – kwargs of DataFrame’s to_string() method

scinumtools.stopwatch module

class scinumtools.stopwatch.Stopwatch

Bases: object

Helper class that measures time of various processes in the code

All nodes have to be closed in an oposite order as started.

observer(name: str)

Start an observer

Parameters:

name (str) – Name of a node

report()

Print time report for all nodes

start(name: str)

Start a new measuring node

Parameters:

name (str) – Name of a node

stop(name: str)

Stop existing node

Parameters:

name (str) – Name of a node

class scinumtools.stopwatch.StopwatchObserver(name, stopwatch)

Bases: object

name: str

scinumtools.thumbnail_image module

class scinumtools.thumbnail_image.ThumbnailImage(data, extent: list | None = None, mode=None)

Bases: object

Create a thumbnail from an image

Parameters:
  • data – Image data array or a file name string

  • extent (tuple) – Extent of an image (xmin, xmax, ymin, ymax)

  • mode (str) – Image mode F/RGB/RGBA

crop(left: float | tuple, right: float | None = None, bottom: float | None = None, top: float | None = None, bgcolor=0)

Change image extent

Parameters:
  • left – Tuple with an image extent, or left extent

  • right (float) – Right extent

  • bottom (float) – Bottom extent

  • top (float) – Top extent

  • bgcolor – Color of the thumbnail padding (float or a tuple)

draw(ax=None, **kwargs)

Draw current image on an axis

Parameters:

ax – Matplotlib axis

extent: list
im: <module 'PIL.Image' from '/home/runner/.local/lib/python3.10/site-packages/PIL/Image.py'> = None
resize(xres: int | None = None, yres: int | None = None)

Change image resolution

Parameters:
  • xres (int) – Resolution on the X-axis

  • yres (int) – Resolution on the Y-axis

save(file_name: str, format: str | None = None)

Save thumbnail as a file

Parameters:

file_name (str) – Name of the image file

Module contents