konigcell

Quantitative, Fast Grid-Based Fields Calculations in 2D and 3D - Residence Time Distributions, Velocity Grids, Eulerian Cell Projections etc.

https://github.com/anicusan/konigcell

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary

Keywords

c grid pixels projection python residence-time-distribution visualization voxels
Last synced: 4 months ago · JSON representation ·

Repository

Quantitative, Fast Grid-Based Fields Calculations in 2D and 3D - Residence Time Distributions, Velocity Grids, Eulerian Cell Projections etc.

Basic Info
Statistics
  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Topics
c grid pixels projection python residence-time-distribution visualization voxels
Created over 4 years ago · Last pushed over 2 years ago
Metadata Files
Readme License Code of conduct Citation

README.md

KonigCell

PyPI version shields.io Documentation Status Language grade: Python Language grade: C/C++ License: MIT PyPI pyversions

Wheels Windows Wheels MacOS Wheels Linux Wheel Python

Quantitative, Fast Grid-Based Fields Calculations in 2D and 3D - Residence Time Distributions, Velocity Grids, Eulerian Cell Projections etc.

That sounds dry as heck.

Project moving particles' trajectories (experimental or simulated) onto 2D or 3D grids with infinite resolution.

Better? No? Here are some figures produced by KonigCell:

Example Plots

Left panel: 2D residence time distribution in a GranuTools GranuDrum imaged using Positron Emission Particle Tracking (PEPT). Two middle panels: 3D velocity distribution in the same system; voxels are rendered as a scatter plot (left) and tomogram-like 3-slice (right). Right panel: velocity vectorfield in a constricted pipe simulating a aneurysm, imaged using PEPT.

This is, to my knowledge, the only library that accurately projects particle trajectories onto grids - that is, taking their full projected area / volume into account (and not approximating them as points / lines). It's also the only one creating quantitative 3D projections.

And it is fast - 1,000,000 particle positions can be rasterized onto a 512x512 grid in 7 seconds on my 16-thread i9 CPU. The code is fully parallelised on threads, processes or distributed MPI nodes.

But Why?

Rasterizing moving tracers onto uniform grids is a powerful way of computing statistics about a system - occupancies, velocity vector fields, modelling particle clump imaging etc. - be it experimental or simulated. However, the classical approach of approximating particle trajectories as lines discards a lot of (most) information.

Here is an example of a particle moving randomly inside a box - on a high resolution (512x512) pixel grid, the classical approach (top row) does not yield much better statistics with increasing numbers of particle positions imaged. Projecting complete trajectory areas onto the grid (KonigCell, bottom row) preserves more information about the system explored:

Increasing Positions

A typical strategy for dealing with information loss is to coarsen the pixel grid, resulting in a trade-off between accuracy and statistical soundness. However, even very low resolutions still yield less information using line approximations (top row). With area projections, you can increase the resolution arbitrarily and improve precision (KonigCell, bottom row):

Increasing Resolution

The KonigCell Libraries

This repository effectively hosts three libraries:

  • konigcell2d: a portable C library for 2D grid projections.
  • konigcell3d: a portable C library for 3D grid projections.
  • konigcell: a user-friendly Python interface to the two libraries above.

Installing the Python Package

This package supports Python 3.6 and above (though it might work with even older versions).

Install this package from PyPI:

pip install konigcell

Or conda-forge:

conda install konigcell

If you have a relatively standard system, the above should just download pre-compiled wheels - so no prior configuration should be needed.

To build this package on your specific machine, you will need a C compiler - the low-level C code does not use any tomfoolery, so any compiler since the 2000s should do.

To build the latest development version from GitHub:

pip install git+https://github.com/anicusan/KonigCell

Integrating the C Libraries with your Code

The C libraries in the konigcell2d and konigcell3d directories in this repository; they contain instructions for compiling and using the low-level subroutines. All code is fully commented and follows a portable subset of the C99 standard - so no VLAs, weird macros or compiler-specific extensions. Even MSVC compiles it!

You can run make in the konigcell2d or konigcell3d directories to build shared libraries and the example executables under -Wall -Werror -Wextra like a stickler. Running make in the repository root builds both libraries.

Both libraries are effectively single-source - they should be as straightforward as possible to integrate in other C / C++ codebases, or interface with from higher-level programming languages.

Examples and Documentation

The examples directory contains some Python scripts using the high-level Python routines and the low-level Cython interfaces. The konigcell2d and konigcell3d directories contain C examples.

Full documentation is available here.

```python import numpy as np import konigcell as kc

Generate a short trajectory of XY positions to pixellise

positions = np.array([ [0.3, 0.2], [0.2, 0.8], [0.3, 0.55], [0.6, 0.8], [0.3, 0.45], [0.6, 0.2], ])

The particle radius may change

radii = np.array([0.05, 0.03, 0.01, 0.02, 0.02, 0.03])

Values to rasterize - velocity, duration, etc.

values = np.array([1, 2, 1, 1, 2, 1])

Pixellise the particle trajectories

pixels1 = kc.dynamic2d( positions, mode = kc.ONE, radii = radii, values = values[:-1], resolution = (512, 512), )

pixels2 = kc.static2d( positions, mode = kc.ONE, radii = radii, values = values, resolution = (512, 512), )

Create Plotly 1x2 subplot grid and add Plotly heatmaps of pixels

fig = kc.createfig( nrows = 1, ncols = 2, subplottitles = ["Dynamic 2D", "Static 2D"], )

fig.addtrace(pixels1.heatmaptrace(), row = 1, col = 1) fig.addtrace(pixels2.heatmaptrace(), row = 1, col = 2)

fig.show() ```

Static-Dynamic 2D

Contributing

You are more than welcome to contribute to this library in the form of library improvements, documentation or helpful examples; please submit them either as:

Acknowledgements

I would like to thank the Formulation Engineering CDT @School of Chemical Engineering and the Positron Imaging Centre @School of Physics and Astronomy, University of Birmingham for supporting my work.

And thanks to Dr. Kit Windows-Yule for putting up with my bonkers ideas.

Citing

If you use this library in your research, you are kindly asked to cite:

[Paper after publication]

This library would not have been possible without the excellent r3d library (https://github.com/devonmpowell/r3d) which forms the very core of the C subroutines; if you use KonigCell in your work, please also cite:

Powell D, Abel T. An exact general remeshing scheme applied to physically conservative voxelization. Journal of Computational Physics. 2015 Sep 15;297:340-56.

Licensing

KonigCell is MIT licensed. Enjoy.

Owner

  • Name: Andrei Leonard Nicusan
  • Login: anicusan
  • Kind: user
  • Location: Birmingham, UK
  • Company: University of Birmingham

Birmingham PhD student, passionate about particle simulations. I like fast code.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, you are kindly asked to cite it as below."
authors:
  - family-names: Nicusan
    given-names: Andrei-Leonard
    orcid: https://orcid.org/0000-0002-4796-8719
  - family-names: Windows-Yule
    given-names: Kit
    orcid: https://orcid.org/0000-0003-1305-537X
title: "KonigCell: Quantitative, Fast Grid-Based Fields Calculations in 2D and 3D"
version: 0.2.0
doi: 10.5281/zenodo.7473472
date-released: 2022-12-22
url: "https://github.com/anicusan/KonigCell"

GitHub Events

Total
Last Year

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 52
  • Total Committers: 2
  • Avg Commits per committer: 26.0
  • Development Distribution Score (DDS): 0.019
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Andrei Leonard Nicusan a****n@b****k 51
Andrei Leonard Nicusan n****9@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 351 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 4
  • Total maintainers: 1
pypi.org: konigcell

Quantitative, Fast Grid-Based Fields Calculations in 2D and 3D - Residence Time Distributions, Velocity Grids, Eulerian Cell Projections etc.

  • Versions: 4
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 351 Last month
Rankings
Dependent packages count: 4.7%
Downloads: 18.8%
Average: 19.6%
Dependent repos count: 21.6%
Stargazers count: 23.0%
Forks count: 29.8%
Maintainers (1)
Last synced: 4 months ago

Dependencies

requirements.txt pypi
  • Cython >=0.29.13
  • numpy >=1.17.3
  • tqdm >=4.41.1
requirements_extra.txt pypi
  • Sphinx >=4.1
  • ipython >=5.5.0
  • matplotlib >=3.2.2
  • numpydoc >=1.1
  • plotly >=4.4.1
  • pydata-sphinx-theme >=0.6.3
  • pytest >=3.6.4
  • pyvista >=0.31
.github/workflows/build_wheels.yml actions
  • actions/checkout v2 composite
  • actions/download-artifact v2 composite
  • actions/setup-python v2 composite
  • actions/upload-artifact v2 composite
  • py-actions/py-dependency-install v2 composite
  • pypa/cibuildwheel v2.1.1 composite
  • pypa/gh-action-pypi-publish v1.4.2 composite
pyproject.toml pypi
setup.py pypi