Exporting a movie#

This example shows how to export movies from image data, using the ‘mp4’ protocol.

The ‘mp4’ protocol accepts additional protocol arguments, like color table, color scaling or pixel binning. For a list of available color tables, see http://jsoc.stanford.edu/ajax/exportdata.html and select the MP4 protocol.

import os
from pathlib import Path

import drms

First we will create a drms.Client, using the JSOC baseurl.

client = drms.Client()

# This example requires a registered export email address. You can register
# JSOC exports at: http://jsoc.stanford.edu/ajax/register_email.html
# You must supply your own email.
email = os.environ["JSOC_EMAIL"]

# Create download directory if it does not exist yet.
out_dir = Path("downloads")
if not out_dir.exists():
    Path(out_dir).mkdir(parents=True)

Construct the DRMS query string: “Series[timespan]{segment}”

qstr = "hmi.m_720s[2014.11.28_00:00:00_TAI/5d@1h]{magnetogram}"
print(f"Data export query:\n  {qstr}\n")
Data export query:
  hmi.m_720s[2014.11.28_00:00:00_TAI/5d@1h]{magnetogram}

Arguments for ‘mp4’ protocol

mp4_args = {
    "ct": "grey.sao",  # color table
    "min": -1500,  # min value
    "max": 1500,  # max value
    "scaling": "mag",  # color scaling
    "size": 8,  # binning (1 -> 4k, 2 -> 2k, 4 -> 1k, 8 -> 512)
}

# Submit export request using the 'mp4' protocol with custom protocol_args
print("Submitting export request...")
result = client.export(qstr, protocol="mp4", protocol_args=mp4_args, email=email)
result.wait(sleep=10)

# Print request URL.
print(f"\nRequest URL: {result.request_url}")
print(f"{len(result.urls)} file(s) available for download.\n")

# Download movie file only: index=0
result.download(out_dir, index=0)
print("Download finished.")
print(f"\nDownload directory:\n  {out_dir.resolve()}\n")
Submitting export request...

Request URL: http://jsoc.stanford.edu/SUM66/D1733160217/S00000
/home/docs/checkouts/readthedocs.org/user_builds/drms/envs/stable/lib/python3.11/site-packages/drms/client.py:196: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:

df["col"][row_indexer] = value

Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

  res.record[0] = None
121 file(s) available for download.

Download finished.

Download directory:
  /home/docs/checkouts/readthedocs.org/user_builds/drms/checkouts/stable/examples/downloads

Total running time of the script: (0 minutes 12.012 seconds)

Gallery generated by Sphinx-Gallery