pyavm

0.9.9 · active · verified Fri Apr 17

pyavm is a pure-Python library for reading and writing AVM (Astronomical Visualization Metadata) information to/from FITS and JPEG files. It leverages Astropy for FITS handling and Pillow for JPEG. The current version is 0.9.9, and it's actively maintained as part of the Astropy ecosystem, with regular but pre-1.0.0 releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an AVM object, populate it with metadata, embed this metadata into an existing JPEG image, and then read the AVM data back from the modified image. It uses Pillow to create a dummy image as a prerequisite.

from pyavm import AVM
from PIL import Image
import numpy as np
import os

# --- Create a dummy image for demonstration ---
img_data = np.zeros((200, 300, 3), dtype=np.uint8)
dummy_path = "dummy_image.jpg"
Image.fromarray(img_data).save(dummy_path)

# --- Example: Create and add AVM metadata to an image ---
avm = AVM()
avm.Creator = "John Doe"
avm.Subject = "Test Astronomical Image"
avm.Date = "2024-04-17T12:00:00"
avm.Spatial_Scale = 1.25 # arcsec/pixel

output_path = "image_with_avm.jpg"
# Add spatial AVM metadata from the AVM object to the image
avm.add_spatial_to_image(dummy_path, output_path)

print(f"AVM metadata added to '{output_path}'")

# --- Example: Read AVM metadata from an existing image ---
avm_read = AVM.from_image(output_path)

print(f"\nMetadata read from '{output_path}':")
print(f"  Creator: {avm_read.Creator}")
print(f"  Spatial Scale: {avm_read.Spatial_Scale}")

# --- Clean up generated files ---
os.remove(dummy_path)
os.remove(output_path)

view raw JSON →