| 1 |
""" |
| 2 |
================= |
| 3 |
Exporting a movie |
| 4 |
================= |
| 5 |
|
| 6 |
This example shows how to export movies from image data, using the 'mp4' |
| 7 |
protocol. |
| 8 |
|
| 9 |
The 'mp4' protocol accepts additional protocol arguments, like color |
| 10 |
table, color scaling or pixel binning. For a list of available color |
| 11 |
tables, see http://jsoc.stanford.edu/ajax/exportdata.html and select the |
| 12 |
MP4 protocol. |
| 13 |
""" |
| 14 |
|
| 15 |
import os |
| 16 |
from pathlib import Path |
| 17 |
|
| 18 |
import drms |
| 19 |
|
| 20 |
############################################################################### |
| 21 |
# First we will create a `drms.Client`, using the JSOC baseurl. |
| 22 |
|
| 23 |
client = drms.Client() |
| 24 |
|
| 25 |
# This example requires a registered export email address. You can register |
| 26 |
# JSOC exports at: http://jsoc.stanford.edu/ajax/register_email.html |
| 27 |
# You must supply your own email. |
| 28 |
email = os.environ["JSOC_EMAIL"] |
| 29 |
|
| 30 |
# Create download directory if it does not exist yet. |
| 31 |
out_dir = Path("downloads") |
| 32 |
if not out_dir.exists(): |
| 33 |
Path(out_dir).mkdir(parents=True) |
| 34 |
|
| 35 |
############################################################################### |
| 36 |
# Construct the DRMS query string: "Series[timespan]{segment}" |
| 37 |
|
| 38 |
qstr = "hmi.M_720s[2025.01.29_23:12:00_TAI/5d@1h]{magnetogram}" |
| 39 |
print(f"Data export query:\n {qstr}\n") |
| 40 |
|
| 41 |
############################################################################### |
| 42 |
# Arguments for 'mp4' protocol |
| 43 |
|
| 44 |
mp4_args = { |
| 45 |
"ct": "grey.sao", # color table |
| 46 |
"min": -1500, # min value |
| 47 |
"max": 1500, # max value |
| 48 |
"scaling": "mag", # color scaling |
| 49 |
"size": 8, # binning (1 -> 4k, 2 -> 2k, 4 -> 1k, 8 -> 512) |
| 50 |
} |
| 51 |
|
| 52 |
# Submit export request using the 'mp4' protocol with custom protocol_args |
| 53 |
print("Submitting export request...") |
| 54 |
result = client.export(qstr, protocol="mp4", protocol_args=mp4_args, email=email) |
| 55 |
result.wait(sleep=10) |
| 56 |
|
| 57 |
# Print request URL. |
| 58 |
print(f"\nRequest URL: {result.request_url}") |
| 59 |
print(f"{len(result.urls)} file(s) available for download.\n") |
| 60 |
|
| 61 |
# Download movie file only: index=0 |
| 62 |
result.download(out_dir, index=0) |
| 63 |
print("Download finished.") |
| 64 |
print(f"\nDownload directory:\n {out_dir.resolve()}\n") |