{"id":10079,"library":"pyavm","title":"pyavm","description":"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.","status":"active","version":"0.9.9","language":"en","source_language":"en","source_url":"https://github.com/astropy/pyavm","tags":["astronomy","metadata","image processing","FITS","JPEG","AVM"],"install":[{"cmd":"pip install pyavm","lang":"bash","label":"Base install"},{"cmd":"pip install pyavm[astropy,pil]","lang":"bash","label":"Install with all core dependencies (recommended)"}],"dependencies":[{"reason":"Required for JPEG image manipulation and AVM embedding.","package":"Pillow","optional":false},{"reason":"Required for FITS file manipulation and AVM embedding (specifically `astropy.io.fits`).","package":"astropy","optional":false}],"imports":[{"symbol":"AVM","correct":"from pyavm import AVM"}],"quickstart":{"code":"from pyavm import AVM\nfrom PIL import Image\nimport numpy as np\nimport os\n\n# --- Create a dummy image for demonstration ---\nimg_data = np.zeros((200, 300, 3), dtype=np.uint8)\ndummy_path = \"dummy_image.jpg\"\nImage.fromarray(img_data).save(dummy_path)\n\n# --- Example: Create and add AVM metadata to an image ---\navm = AVM()\navm.Creator = \"John Doe\"\navm.Subject = \"Test Astronomical Image\"\navm.Date = \"2024-04-17T12:00:00\"\navm.Spatial_Scale = 1.25 # arcsec/pixel\n\noutput_path = \"image_with_avm.jpg\"\n# Add spatial AVM metadata from the AVM object to the image\navm.add_spatial_to_image(dummy_path, output_path)\n\nprint(f\"AVM metadata added to '{output_path}'\")\n\n# --- Example: Read AVM metadata from an existing image ---\navm_read = AVM.from_image(output_path)\n\nprint(f\"\\nMetadata read from '{output_path}':\")\nprint(f\"  Creator: {avm_read.Creator}\")\nprint(f\"  Spatial Scale: {avm_read.Spatial_Scale}\")\n\n# --- Clean up generated files ---\nos.remove(dummy_path)\nos.remove(output_path)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure the image file (JPEG or FITS) exists at the specified path before calling `AVM.from_image()` or `AVM.add_spatial_to_image()`.","message":"pyavm requires an existing image file on disk to embed or extract AVM metadata. It does not create or modify image data (pixel arrays) directly, only the metadata within the file.","severity":"gotcha","affected_versions":"all"},{"fix":"Always consult the changelog in the official documentation or GitHub repository for each new release to identify any API adjustments or breaking changes.","message":"As a pre-1.0.0 library, the API for pyavm can undergo changes even in minor versions (e.g., from 0.8.x to 0.9.x). While core functionality remains relatively stable, new features or less frequently used methods might be refactored.","severity":"breaking","affected_versions":"0.x.x"},{"fix":"It is recommended to install `pyavm` with its optional dependencies using `pip install pyavm[astropy,pil]` to ensure all necessary components are present.","message":"pyavm relies on specific external libraries for file handling: `Pillow` for JPEG images and `astropy` for FITS files. If these are not installed, or their versions are incompatible, operations on those file types will fail.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install `astropy` using `pip install astropy` or, preferably, `pip install pyavm[astropy,pil]` to include all core dependencies.","cause":"`astropy` (or specifically `astropy.io.fits`) is not installed or the installed version is incompatible with `pyavm`.","error":"ModuleNotFoundError: No module named 'astropy.io.fits'"},{"fix":"Verify that the image file is present at the specified path before attempting to read or write AVM metadata.","cause":"The image file path provided to `AVM.from_image()` or `AVM.add_spatial_to_image()` does not exist on disk.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_image.jpg'"},{"fix":"Ensure `pyavm` is installed and up-to-date with `pip install --upgrade pyavm`. The correct import is `from pyavm import AVM`.","cause":"Incorrect import statement or `pyavm` is not installed, or an outdated version of `pyavm` is installed where the `AVM` class might have been located differently.","error":"ImportError: cannot import name 'AVM' from 'pyavm'"}]}