xrframes
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 Dask1 or joblib2 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-forge3, 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)
Metadata
Release files for xrframes 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xrframes-0.0.4.tar.gz | 9.9 kB | Without provenance | Details for xrframes-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xrframes-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for xrframes-0.0.4-py3-none-any.whl |
Total release size: 20.5 kB
Release files / xrframes-0.0.4.tar.gz
| Download URL | xrframes-0.0.4.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f2128687d72814a62931b520ba0c02683eb93eec972c0bd8d6c02ffa925a8d5
|
|
BLAKE2b-256 checksum How to use checksums |
278ded3ac3c4b5321e1e80d5825aa7078b614549cfa408da7892fd13ce3eceb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / xrframes-0.0.4-py3-none-any.whl
| Download URL | xrframes-0.0.4-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a6561b1e7f83ea4ed4984d913a9a7fb614c725a5be5d83c22b7fd31683ec731
|
|
BLAKE2b-256 checksum How to use checksums |
f7d5e1dbfec5c6f4d42f1c805fd44076590b71100f29341dbb7b8f6456ebd3f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for xrframes 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.