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 v2

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 four main submodules: expression solver, physical units, material properties 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 other submodules. For more description and examples of Expression Solver please refer to the documentation. C++ implementation of this module is available in a separate GitHub repository.

>>> 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. A C++ implementation of this module scnt-puq is currently available also as a Python module pypuq on PyPi.

>>> 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)

Material Properties

Simulation setups often require atomic and molecular properties of various materials. The core of this submodule, molecular expression solver, is designed to simplify calculations of such properties from a given molecular formula. For more description and examples of Material Properties please refer to the documentation.

>>> from scinumtools.units import Quantity
>>> from scinumtools.materials import Substance
>>> s = Substance('H2O', natural=False, mass_density=Quantity(997,'kg/m3'), volume=Quantity(1,'l'))
>>> s.print()
Components:

expr element  isotope  ionisation  mass[Da]  count  Z  N  e
   H       H        1           0  1.007825    2.0  1  0  1
   O       O       16           0 15.994915    1.0  8  8  8

Composite:

Total mass:     Quantity(1.801e+01 Da)
Total number:   3.0

expr  mass[Da]         Z        N         e       x[%]       X[%]
   H  2.015650  2.000000 0.000000  2.000000  66.666667  11.191487
   O 15.994915  8.000000 8.000000  8.000000  33.333333  88.808513
 avg  6.003522  3.333333 2.666667  3.333333  33.333333  33.333333
 sum 18.010565 10.000000 8.000000 10.000000 100.000000 100.000000

Matter:

Mass density:   Quantity(9.970e-01 g*cm-3)
Number density: Quantity(3.334e+22 cm-3)
Volume:         Quantity(1.000e+00 l)
Mass:           Quantity(9.970e+02 g)

expr      n[cm-3]  rho[g/cm3]            N       M[g]
   H 6.667280e+22    0.111579 6.667280e+25 111.579129
   O 3.333640e+22    0.885421 3.333640e+25 885.420871
 avg 3.333640e+22    0.332333 3.333640e+25 332.333333
 sum 1.000092e+23    0.997000 1.000092e+26 997.000000

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.add_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')}

Alternative Python module dipl implements basic loading and dumping functionality of DIP and provides quick solution for data parsing using DIP.

>>> import dipl
>>>
>>> dipl.load("""
>>> width float = 173.34 cm
>>> age int = 24 yr
>>> """)
{'width': (173.34, 'cm'), 'age': (24, 'yr')}
>>>
>>> dipl.dump({
>>> 'children': ['John','Jenny','Jonah'],
>>> 'car': True
>>> })
children str[3] = ["John","Jenny","Jonah"]
car bool = true

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.19.4.tar.gz (483.4 kB view details)

Uploaded Source

Built Distribution

scinumtools-2.19.4-py3-none-any.whl (137.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scinumtools-2.19.4.tar.gz
  • Upload date:
  • Size: 483.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for scinumtools-2.19.4.tar.gz
Algorithm Hash digest
SHA256 3bd93df37115d5e3fa6f450f188b41abce013873252cfae869a607e9421e517f
MD5 8553d56df91c866f40e1f613f0d0415f
BLAKE2b-256 341135ab652bcd3e887fa3b6650cc6cddbe69805f29cf7644b3e674086afaac7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scinumtools-2.19.4-py3-none-any.whl
  • Upload date:
  • Size: 137.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for scinumtools-2.19.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3488017ce3a1510981c22f0039ee61424a63918ec82d6196ea811fbe31a0bab1
MD5 f6722350c136ef1f7535003bf13c30db
BLAKE2b-256 7ee425d885434d3898748482b07da4fda9efd91795b8df6229f540592dc3a00d

See more details on using hashes here.

Supported by

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