Skip to main content

Pure Python implementation of the Gwyddion file format

Project description

https://img.shields.io/pypi/v/gwyfile.svg https://img.shields.io/pypi/l/gwyfile.svg https://img.shields.io/pypi/wheel/gwyfile.svg https://img.shields.io/pypi/pyversions/gwyfile.svg

A pure Python interface to reading and writing Gwyddion files.

Installation

$ pip install gwyfile

Usage

At the heart of this module is the GwyObject class, derived from collections.OrderedDict. Gwyddion files are just serialized copies of GwyObjects and its subclasses (GwyContainer, GwyDataField, …).

Here is a simple example that shows how to load a file and display a data channel:

import gwyfile

# Load a Gwyddion file into memory
obj = gwyfile.load('test.gwy')
# Return a dictionary with the datafield titles as keys and the
# datafield objects as values.
channels = gwyfile.util.get_datafields(obj)
channel = channels['Test']
# Datafield objects have a `data` property to access their
# two-dimensional data as numpy arrays.
data = channel.data

# Plot the data using matplotlib.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.imshow(data, interpolation='none', origin='upper',
        extent=(0, channel.xreal, 0, channel.yreal))
plt.show()

It is also possible to manipulate and save objects:

import numpy as np
from gwyfile.objects import GwyContainer, GwyDataField
obj = GwyContainer()
obj['/0/data/title'] = 'Noise'
data = np.random.normal(size=(256, 256))
obj['/0/data'] = GwyDataField(data)
obj.tofile('noise.gwy')

The Gwyddion manual has a nice description of the file format. See there for further information on object properties.

Status

GwyObject serialization and deserialization should be complete. There are specialized subclasses for GwyDataField and GwySIUnit, but other convenience wrappers e.g. for GwyBrick are missing.

License

This project is licensed under the MIT license. See LICENSE.rst for details.

© 2014-17 Tino Wagner

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

gwyfile-0.3.0.tar.gz (133.7 kB view details)

Uploaded Source

Built Distribution

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

gwyfile-0.3.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file gwyfile-0.3.0.tar.gz.

File metadata

  • Download URL: gwyfile-0.3.0.tar.gz
  • Upload date:
  • Size: 133.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for gwyfile-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c12b1bab832698af554afad1e6e4f9c06b1d309b589e235a8ef365bdeef66549
MD5 838aff9f7ded87e8ee15776a38713f18
BLAKE2b-256 e4f94652b4d44cfeb9ddfb3ea8e0da0e98eb23e51dc181adb039f92af3fe2171

See more details on using hashes here.

File details

Details for the file gwyfile-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: gwyfile-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for gwyfile-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a68c5c748f0390cce1e0d6b8d622fa7f267ef94d47aa5fd7eb95abfeb4256c1
MD5 d6bed4da26081127e04d54349b9fae97
BLAKE2b-256 c60326d3d8eab0d4df620830a6a3296878d08e3a9240c206d38f5b2e8aeb6a9f

See more details on using hashes here.

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