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

pycroscopy_gwyfile-1.0.2.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

pycroscopy_gwyfile-1.0.2-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pycroscopy_gwyfile-1.0.2.tar.gz.

File metadata

  • Download URL: pycroscopy_gwyfile-1.0.2.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for pycroscopy_gwyfile-1.0.2.tar.gz
Algorithm Hash digest
SHA256 11cd3f44ee0bd341bdbd5ac96df73679c0f07ed8759322cafbd6b22e170824f6
MD5 cd290f257b483e1e4075299339c6af36
BLAKE2b-256 b95676858cd18b4cc1467afa706dea7e4270db6625524dd82b779e062e069ca7

See more details on using hashes here.

File details

Details for the file pycroscopy_gwyfile-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pycroscopy_gwyfile-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ffa57c501769efcfb387b76bf3f301945a162df759503027308bf70c3283291d
MD5 a464f4f96d2cbd102527b47d9136dabc
BLAKE2b-256 3e0793928e5945cd1a821fd10abc93173dc560635f68ff710716565c416f962c

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