Skip to main content

Similar to ``xmovie``, make animations from xarray objects.

Project description

xrframes

Version on PyPI Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept.

Similar to (and inspired by) jbusecke/xmovie, make animations from xarray objects by applying a matplotlib-based plotting function along a dimension.

Install

pip install xrframes

Install and use Dask[^a] or joblib[^b] to parallelize the frame creation step.

.to_gif() uses ImageMagick (magick or convert required on PATH); .to_mp4() uses FFmpeg (ffmpeg required on PATH). Both are available via conda-forge[^c], as well as other package managers.

Example

Basic example, using just the xarray object's plot method:

import xarray as xr
from xrframes import Frames

# Note: `pooch` required
ta = xr.tutorial.open_dataset("air_temperature").air.isel(time=slice(0, 10))

frames = Frames(ta, lambda da: da.plot(size=2.5, aspect=1.7), dim="time")
frames.write(dpi=120)  # serial
frames.to_gif("./ta_basic.gif", fps=5)

A bit fancier example with the same data, using Cartopy:

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import xarray as xr
from xrframes import Frames

# Note: `pooch` required
ta = xr.tutorial.open_dataset("air_temperature").air.isel(time=slice(0, 10))

proj = ccrs.Mercator()
tran = ccrs.PlateCarree()

def plot(da, **kwargs):
    fig, ax = plt.subplots(figsize=(6, 3), layout="constrained", subplot_kw=dict(projection=proj))

    ax.coastlines()
    ax.add_feature(cfeature.BORDERS)
    ax.add_feature(cfeature.STATES)
    ax.gridlines(draw_labels=True)

    da.plot.contourf(**kwargs, levels=np.arange(230, 305, 5), extend="both", ax=ax, transform=tran)

    ax.set_title("")
    ax.set_title(pd.Timestamp(da.time.item()).strftime(r"%Y-%m-%d %H:%M"), loc="left", size=10)

    return fig

frames = Frames(ta, plot, dim="time")
frames.write()  # serial
frames.to_mp4("./ta_cartopy.mp4", fps=5)

[^a]: dask on PyPI, dask-core on conda-forge, more info here [^b]: joblib on PyPI and on conda-forge [^c]: conda install -c conda-forge imagemagick ffmpeg

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

xrframes-0.0.4.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

xrframes-0.0.4-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file xrframes-0.0.4.tar.gz.

File metadata

  • Download URL: xrframes-0.0.4.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for xrframes-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0f2128687d72814a62931b520ba0c02683eb93eec972c0bd8d6c02ffa925a8d5
MD5 b8a8e5a0db92dc2e8ef8545875cbbb51
BLAKE2b-256 278ded3ac3c4b5321e1e80d5825aa7078b614549cfa408da7892fd13ce3eceb5

See more details on using hashes here.

File details

Details for the file xrframes-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: xrframes-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for xrframes-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8a6561b1e7f83ea4ed4984d913a9a7fb614c725a5be5d83c22b7fd31683ec731
MD5 a07b6aea8f99c20229df86b372ac1174
BLAKE2b-256 f7d5e1dbfec5c6f4d42f1c805fd44076590b71100f29341dbb7b8f6456ebd3f5

See more details on using hashes here.

Supported by

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