Skip to main content

Set of most frequently used tools for a rapid numerical code development in Python.

Project description

PyPI Supported Python Versions PyTest

scinumtools

scinumtools

Python package scinumtools contains essential tools for scientific and numerical calculations, simulation setup and data analysis.

Documentation

For more information, see the scinumtools documentation. The documentation is currently in a process of writing, so any comments and suggestions for improvement are heartily welcomed.

Quick start

The newest release of scinumtools is available on PyPi and can be easily installed using pip package manager:

pip3 install scinumtools

Besides several useful tools, package scinumtools consist of three main submodules: expression solver, physical units and DIP.

Expression Solver

Using expression solver one can quickly build a custom parser that can process numerical, logical and textual expressions. This module is an integral part of both, physical units and DIP modules. For more description and examples of Expression Solver please refer to the documentation.

>>> from scinumtools.solver import *
>>> class AtomCustom(AtomBase):
>>>     value: str
>>>     def __init__(self, value:str):
>>>         self.value = str(value)
>>>     def __add__(self, other):
>>>         return AtomCustom(self.value + other.value)
>>>     def __gt__(self, other):
>>>         return AtomCustom(len(self.value) > len(other.value))
>>> operators = {'add':OperatorAdd,'gt':OperatorGt,'par':OperatorPar}
>>> steps = [
>>>     dict(operators=['par'],  otype=Otype.ARGS),
>>>     dict(operators=['add'],  otype=Otype.BINARY),
>>>     dict(operators=['gt'],   otype=Otype.BINARY),
>>> ]
>>> with ExpressionSolver(AtomCustom, operators, steps) as es:
>>>     es.solve("(limit + 100 km/s) > (limit + 50000000000 km/s)")
'False'

Physical Units

This submodule has an aim to make calculations with physical units quick and easy. It includes multiple types of units, constants and implements standard numerical operations with physical quantities. Besides that, it features unit convertor, supports calculations with uncertainties and can be used in combination with third party libraries like NumPy, or Decimal. For more description and examples of Physical Units please refer to the documentation.

>>> import numpy as np
>>> from scinumtools.units import Quantity, Unit
>>> Quantity(23.34, 'kg*m2/s2').to('erg')     # unit conversions
Quantity(2.334e+08 erg)
>>> u = Unit()                                # calculations with units
>>> 34*u.cm + 53*u.dm  
Quantity(5.640e+02 cm)
>>> Quantity(23.34, 'cm', abse=0.03)          # uncertainities
Quantity(2.3340(30)e+01 cm)
>>> Quantity(3, 'A').value('dBA')             # logarithmic units
9.542425094393248
>>> np.sqrt(Quantity([23,59,20,10], 'm2'))    # arrays and NumPy
Quantity([4.796 7.681 4.472 3.162] m)

Dimensional Input Parameters

DIP is a serialization language that was designed to collect, manage, convert, document and validate dimensional input parameters used by numerical codes. The main goal of this package is to help developers to focus less on initialization processes mentioned above and more on actual code development. DIP should serve as a quick tool that makes user interface with the code clear and straightforward. For more description and examples of DIP please refer to the documentation.

>>> from scinumtools.dip import DIP, Format
>>> with DIP() as dip:
>>>     dip.add_source("settings", 'settings.dip')
>>>     dip.add_unit("length", 1, "m")
>>>     dip.from_string("""
>>>     box
>>>       width float = 23 [length]
>>>       height float = 11.5 cm
>>>     sphere
>>>       radius float = {settings?sphere.radius}
>>>     """)
>>>     env = dip.parse()
>>>     env.data(Format.TUPLE)
{'box.width': (23.0, '[length]'), 'box.height': (11.5, 'cm'), 'sphere.radius': (34.2, 'mm')}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scinumtools-2.12.1.tar.gz (459.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scinumtools-2.12.1-py3-none-any.whl (131.8 kB view details)

Uploaded Python 3

File details

Details for the file scinumtools-2.12.1.tar.gz.

File metadata

  • Download URL: scinumtools-2.12.1.tar.gz
  • Upload date:
  • Size: 459.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for scinumtools-2.12.1.tar.gz
Algorithm Hash digest
SHA256 d544d17c2be34fbf933fc134ba277cd7a8de59f07bdcc6a2ffdabf03ceedcc98
MD5 d242af2b894585296360ec04ce35a142
BLAKE2b-256 4dcfcbfb5667ba5ffc4840d36706413a9e9fe401b1e3fde42b70c46ce2122561

See more details on using hashes here.

File details

Details for the file scinumtools-2.12.1-py3-none-any.whl.

File metadata

  • Download URL: scinumtools-2.12.1-py3-none-any.whl
  • Upload date:
  • Size: 131.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for scinumtools-2.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb483f7b0a91e1286f80587ddcdb62581f4f654acdf2a5a9b634a5041c4a17c
MD5 0af1acb66e669868d909d5feb1cce7f4
BLAKE2b-256 995aa68e03e8c5d7c947d3f7001438b616e691c94e0776e03072f6af38645082

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page