Skip to main content

An implementation of USTB's ultrasound file format (UFF) in Python.

Project description

PyUFF (USTB)

An implementation of USTB's ultrasound file format (UFF) in Python.

Note that this project only implements USTB's version of UFF, which is considered version 0.0.1. Multiple versions of UFF exists, for example check out uff-reader. However, if you only planning to use USTB's version of UFF then you have come to the right place :)

Installing

Run the following command in your Python virtual environment:

python -m pip install pyuff-ustb

To verify that the installation was successful, run the following command:

python -c "import pyuff_ustb; print(pyuff_ustb.__version__)"

Reading UFF files

import pyuff_ustb as pyuff

uff = pyuff.Uff(filepath)
print(uff)  # <- print the keys of the UFF file
channel_data = uff.read("channel_data")
scan = uff.read("scan")

Writing UFF files

import pyuff_ustb as pyuff
import numpy as np

scan = pyuff.LinearScan(
    x_axis=np.linspace(-10e3, 10e3, 128),
    z_axis=np.linspace(0, 80e3, 128),
)
scan.write("my_scan.uff", "scan")
# To overwrite an existing field in the file, pass overwrite=True like so:
scan.write("my_scan.uff", "scan", overwrite=True)

UFF object structure

See the modules under pyuff_ustb/objects for all implemented UFF objects. The most important ones are ChannelData and Scan.

  • ChannelData contains the raw ultrasound data under the data (channel_data.data) property and other important beamforming properties such as sampling_frequency and probe setup, etc.
  • Scan is primarily a container of the points that are to be beamformed.

Check out the source code under pyuff_ustb/objects/channel_data.py in your favorite code editor to get a better understanding of the UFF object structure.

Lazy loading

PyUFF strives to only load what you need in order to speed up the reading process. This is done by using lazy loaded properties. Lazy loaded values are only actually read from the file when they are used. This is contrary to eager loading where all values are automatically read from the file when the object is created. Arrays are always eagerly loaded so that you can be sure that they are NumPy arrays (in previous versions we had a LazyArray abstraction but the benefits of this were small and the complexity cost was big).

In general, all UFF object fields are of the type cached_property. When a cached_property is accessed for the first time, its code will run, and the returned value will be cached, meaning that for most PyUFF fields, values are only read from a file once. The cached_property is further split into two types:

  • compulsory_property: fields that must be set in an object in order to write to a file.
  • optional_property: optional fields that may be None when writing to a file.

Additionally, there is dependent_property, which is not cached nor read from a file — instead, it is calculated from other compulsory and/or optional properties in the object. All properties of the PyUFF objects are decorated with either @compulsory_property, @optional_property or @dependent_property.

To invalidate a property from the cache (in order to re-read it from the file), simply delete the property from the object. Example:

obj = uff.read("channel_data")
data = obj.data[...]  # <- This will read the data from the file
data = obj.data[...]  # <- Subsequent calls do not read from the file
del obj.data  # <- This deletes the data from the cache
data = obj.data[...]  # <- The data is read again

You can still eagerly load all values from the file by calling pyuff_ustb.eager_load on the object. Note that eager_load does not update the object (but may read and cache properties) but returns a new copy. Example:

obj = uff.read("channel_data")
# Eagerly load all values (this usually takes a few seconds, depending on the file size)
# pyuff_ustb.eager_load returns a copy of the object, leaving the original unchanged (though perhaps with cached properties).
obj = pyuff_ustb.eager_load(obj)

Project details


Download files

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

Source Distribution

pyuff_ustb-3.0.0.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

pyuff_ustb-3.0.0-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file pyuff_ustb-3.0.0.tar.gz.

File metadata

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

File hashes

Hashes for pyuff_ustb-3.0.0.tar.gz
Algorithm Hash digest
SHA256 4291f40ca972153c4a688090d2ed2e7d6ba5b621fac9c1bc1878f0034a273571
MD5 fb37f16a283483c360713826da3743f4
BLAKE2b-256 48fe4f0dcce8c9f5ccc9faef19b46f729a757179c61b473946e92c2e52e4404f

See more details on using hashes here.

File details

Details for the file pyuff_ustb-3.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pyuff_ustb-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f5cdd17ef972c804f122749f56f86db4c6d74b639faf99b55a437fe6fe4fda6
MD5 6bc57c598c1661e8e9b57382e7db3ee1
BLAKE2b-256 3b95086aaf4c284618a5ba617861b0c68b0fe8c946a4e1c348f704988aa8b8d3

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