Skip to main content

This Python Package allows interfacing with dotThz files.

Reason this release was yanked:

too early

Project description

Interface with dotTHz files using Python

PEP8 PyPI PyPI - Downloads

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

    # save the file
    path1 = Path("test1.thz")
    with DotthzFile(path1, "w") as file:
        file["Measurement 1"] = DotthzMeasurement()

        # 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"

        file["Measurement 1"].meta_data = meta_data

        # for thzVer 1.00, we need to transpose the array!
        # important: do not manipulate keys on the `dataset` field, otherwise it won't be written to the file.
        file["Measurement 1"]["Sample"] = np.array([time, data]).T

    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["Measurement 2"] = DotthzMeasurement()
    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.measurements
        for name, measurement in measurements.items():
            file1[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.measurements.keys())[0]
        print(file1.measurements.get(key).meta_data)
        print(file1.measurements.get(key).datasets)

    # read out an image file:
    path3 = Path("tests/test_files/test_image.thz")
    with DotthzFile(path3, "r") as image_file:
        # read the first group/measurement
        key = list(image_file.measurements.keys())[0]
        print(image_file.measurements.get(key).meta_data)
        datasets = image_file.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("tests/test_files/test_image_2.thz")
    with DotthzFile(path4, "w") as file:

        file.measurements["Image"] = DotthzMeasurement()

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

        file.measurements["Image"].meta_data = meta_data

        # important: do not manipulate keys on the `dataset` field, otherwise it won't be written to the file.
        file.measurements["Image"]["time"] = time_trace
        file.measurements["Image"]["dataset"] = image

Requires hdf5 to be installed.

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

pydotthz-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydotthz-1.0.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pydotthz-1.0.0.tar.gz.

File metadata

  • Download URL: pydotthz-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydotthz-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c32c7854b776531b1777dc9cabf72a56cf8b89b86edef1379401212c62abe6a1
MD5 fa7006bb40c582a3656f5f050d6d34fa
BLAKE2b-256 c5015aaa97c4756b89f197cf1b0521e2dec63c865d08d09c5ff19c6107171741

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydotthz-1.0.0.tar.gz:

Publisher: publish.yml on dotTHzTAG/pydotthz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydotthz-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydotthz-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydotthz-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f010b10cba7d94d42df4ab041a152784adec45c58c3e20da6bd4c97f0a240d5
MD5 dd04d50fd72c032aaae2454b50fc5df2
BLAKE2b-256 2b9d30c0d721e4e27d1162375326d686f58d421ce72b2fd22f6e34f2d059041b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydotthz-1.0.0-py3-none-any.whl:

Publisher: publish.yml on dotTHzTAG/pydotthz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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