xblobs
Python tool to detect and analyse coherent structures in turbulence, powered by xarray.
The algorithm has been developed originally to detect and track coherent structures (blobs) in plasma turbulence simulations but it can be applied on any 2D xarray Dataset with a cartesian grid and constant spacing dx,dy and dt. An example is shown below:
Requirements
- Python >= 3.5
- xarray >= 0.11.2
- scipy >= 1.2.0
- dask-image >= 0.2.0
- numpy >= 1.14
Installation
Dev install:
git clone https://github.com/gregordecristoforo/xblobs.git
cd xblobs
pip install -e .
Usage
The algorithm is based on the threshold method, i.e. all structures exceeding a defined threshold are labeled as blobs. In order to track blobs over time they have to spatially overlap in two consecutive frames.
Applying find_blobs function on xarray dataset returns the dataset with a new variable called blob_labels. The number of blobs is added as an attribute to blob_labels as number_of_blobs. The parameters of single blobs can then be calculated with the Blob class.
xstorm
The default implementation is done for a xstorm dataset.
from xblobs import Blob
from xblobs import find_blobs
from xstorm import open_stormdataset
ds = open_stormdataset(inputfilepath='./BOUT.inp')
ds = find_blobs(da = ds, scale_threshold = 'absolute_value' ,
threshold = 5e18 ,region = 0.0, background = 'flat')
blob1 = Blob(ds,1)
# call blob methods you are interested in
print(blob1.lifetime())
#etc
xbout
For BOUT++ simulations using xbout one has to specify the dimensions in addition.
from xblobs import Blob
from xblobs import find_blobs
from xbout import open_boutdataset
ds = open_boutdataset()
ds = find_blobs(da = ds, scale_threshold = 'absolute_value' ,
threshold = 1.3 ,region = 0.0, background = 'flat',
n_var = 'n', t_dim = 't', rad_dim = 'x', pol_dim = 'z')
blob1 = Blob(ds,1, n_var = 'n', t_dim = 't', rad_dim = 'x',pol_dim = 'z')
generic xarray dataset
For a generic xarray dataset adjust the dimensions to your needs, for example:
from xblobs import Blob
from xblobs import find_blobs
ds = load_your_dataset()
ds = find_blobs(da = ds, scale_threshold = 'absolute_value' ,
threshold = 1.3 ,region = 0.0, background = 'flat',
n_var = 'density', t_dim = 'time', rad_dim = 'radial', pol_dim = 'poloidal')
blob1 = Blob(ds,1, n_var = 'density', t_dim = 'time', rad_dim = 'radial', pol_dim = 'poloidal')
Input parameters
find_blobs()
-
da: xbout Dataset -
threshold: threshold value expressed in terms of the chosen scale_threshold -
scale_threshold: following methods implementedabsolute_value: threshold is scalar valueprofile: threshold is time- and poloidal-average profilestd: threshold is standard deviation over all three dimensionsstd_poloidal: threshold is standard deviation over poloidal dimensionstd_time: threshold is standard deviation over time dimension
-
region: blobs are detected in the region with radial indices greater thanregion -
background: background that is subtracted. Options:profile: time- and poloidal-averaged backgroundflat: no background subtracted
-
n_var: xarray variable used for blob tracking -
t_dim: xarray dimension for time -
rad_dim: xarray dimension for radial dimension -
pol_dim: xarray dimension for poloidal dimension
Blob()
variable: xbout Dataset containing blob_labelsid: integer between 0 and number of detected blobs- 0: refers to the background
- 1-n: detected blobs
- other parameters equivalent to
find_blobs
Blob methods
the following blob parameters are implemented:
t_init: time when blob is detectedlifetime: lifetime of blobcom: center of mass, over timevelocity: absolute velocity of centre of mass of blob, over timevelocity_x: radial velocity of centre of mass of blob, over timevelocity_y: poloidal velocity of centre of mass of blob, over timeamplitude: maximum of the signal within the blob above background, over timemax_amplitude: maximum of the signal within the blob above backgroundmass: integral of signal in area where background is exceeded, over timeaverage_mass: average blob masssize: integral of area above background, over time
other blob parameters are straightforward to implement
Parallelization
Blob detection is parallelised across any number of dimensions by dask-image.
Contact
If you have questions, suggestions or other comments you can contact me under gregor.decristoforo@uit.no
Metadata
Release files for xblobs 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xblobs-1.0.2.tar.gz | 6.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xblobs-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / xblobs-1.0.2.tar.gz
| Download URL | xblobs-1.0.2.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69225bae3df778e067842af134dbfb7e434a28a9c873d1421aa1923a2265b61e
|
|
BLAKE2b-256 checksum How to use checksums |
57d2290d57c72e96117b97f737e78fb38fb30d4500b592329334b4a97bf892e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.0 Linux/5.13.0-28-generic
|
Release files / xblobs-1.0.2-py3-none-any.whl
| Download URL | xblobs-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2bf330edd0a7577f6fbeea64cebecbad97e46b1930f9feb83b51c9b29c4b85b9
|
|
BLAKE2b-256 checksum How to use checksums |
d9d3c940189f9b333fe7f177c22bcc1bbe78a4dd5c3c0665103ae051b3ae64e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.0 Linux/5.13.0-28-generic
|
Security for xblobs 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.