This Python Package allows interfacing with dotThz files.
Project description
Interface with dotTHz files using Python
This crate provides an easy way to interface with dotTHz files in Python.
Install it
pip install pydotthz
or
pip3 install pydotthz
and then use like specified in the following example:
from pathlib import Path
import numpy as np
from dotthz import DotthzFile, DotthzMeasurement, DotthzMetaData
if __name__ == "__main__":
# Sample data
time = np.linspace(0, 1, 100) # your time array
data = np.random.rand(100) # example 3D data array
measurement = DotthzMeasurement()
# for thzVer 1.00, we need to transpose the array!
datasets = {"Sample": np.array([time, data]).T}
measurement.datasets = datasets
# create meta-data
meta_data = DotthzMetaData()
meta_data.user = "John Doe"
meta_data.version = "1.00"
meta_data.instrument = "Toptica TeraFlash Pro"
meta_data.mode = "THz-TDS/Transmission"
measurement.meta_data = meta_data
# save the file
path1 = Path("test1.thz")
with DotthzFile(path1, "w") as file:
file.write_measurement("Measurement 1", measurement)
del file # optional, not required as the file is already closed
# create and save a second file
path2 = Path("test2.thz")
with DotthzFile(path2, "w") as file:
file.write_measurement("Measurement 2", measurement)
del file # optional, not required as the file is already closed
# open the first file again in append mode and the second in read mode
with DotthzFile(path1, "a") as file1, DotthzFile(path2) as file2:
measurements = file2.get_measurements()
for name, measurement in measurements.items():
file1.write_measurement(name, measurement)
del file1 # optional, not required as the file is already closed
with DotthzFile(path1, "r") as file1:
# read the first measurement
key = list(file1.get_measurements().keys())[0]
print(file1.get_measurements().get(key).meta_data)
print(file1.get_measurements().get(key).datasets)
# read out an image file:
path3 = Path("test_files/test_image.thz")
with DotthzFile(path3, "r") as image_file:
# read the first group/measurement
key = list(image_file.get_measurements().keys())[0]
print(image_file.get_measurements().get(key).meta_data)
datasets = image_file.get_measurements().get(key).datasets
print(datasets.keys())
# from the first dataset, extract the image:
time_trace = datasets["time"]
image = datasets["dataset"]
# print image dimensions
print(image.shape)
# save an image file:
path4 = Path("test_files/test_image_2.thz")
with DotthzFile(path4, "w") as file:
file.groups = {}
measurement = DotthzMeasurement()
measurement.datasets = {}
measurement.datasets[f"time"] = time_trace
measurement.datasets[f"dataset"] = image
# set meta_data
meta_data = DotthzMetaData()
meta_data.user = "John Doe"
meta_data.email = "john.doe@unibe.ch"
meta_data.institution = "University of Bern"
meta_data.orcid = "ORCID"
meta_data.description = "some comment"
meta_data.date = "date"
meta_data.time = "time"
meta_data.version = "1.10"
meta_data.instrument = "Toptica TeraFlash Pro"
meta_data.mode = "THz-TDS/Transmission"
# add more keys from your "info" dictionary ...
# for (key, value) in info.items():
# meta_data.add_field(key, value)
measurement.meta_data = meta_data
file.groups[f"Image"] = measurement
Requires hdf5 to be installed.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydotthz-0.3.0.tar.gz.
File metadata
- Download URL: pydotthz-0.3.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1793fd23cb01980349bdf736ce8ccd6e54aad177b6bbdcad5600295ebeb47f31
|
|
| MD5 |
a601ec4ebd5d90ebc05d60612d4c54ea
|
|
| BLAKE2b-256 |
af2b6e5972b4992196519868e6227dfe24e7a57ac411e777336bd27f7e6189a7
|
Provenance
The following attestation bundles were made for pydotthz-0.3.0.tar.gz:
Publisher:
publish.yml on hacknus/pydotthz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydotthz-0.3.0.tar.gz -
Subject digest:
1793fd23cb01980349bdf736ce8ccd6e54aad177b6bbdcad5600295ebeb47f31 - Sigstore transparency entry: 166221230
- Sigstore integration time:
-
Permalink:
hacknus/pydotthz@d09df366733074020130e8541ba9fd885714a01c -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/hacknus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d09df366733074020130e8541ba9fd885714a01c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydotthz-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pydotthz-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5ed549824785607a8f6b6f219410dcc9d1814fbf4af2734b16937bab6ef36f5
|
|
| MD5 |
48edd53a58fcb6dea7b9b3c8e1f31ac4
|
|
| BLAKE2b-256 |
6b60ab71122a98e41bbb6fe9135d9a0f11c43f1a567413cca5ffa22835ac9067
|
Provenance
The following attestation bundles were made for pydotthz-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on hacknus/pydotthz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydotthz-0.3.0-py3-none-any.whl -
Subject digest:
a5ed549824785607a8f6b6f219410dcc9d1814fbf4af2734b16937bab6ef36f5 - Sigstore transparency entry: 166221232
- Sigstore integration time:
-
Permalink:
hacknus/pydotthz@d09df366733074020130e8541ba9fd885714a01c -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/hacknus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d09df366733074020130e8541ba9fd885714a01c -
Trigger Event:
release
-
Statement type: