| 1 |
""" |
| 2 |
=================================== |
| 3 |
Exporting data with cutout requests |
| 4 |
=================================== |
| 5 |
|
| 6 |
This example shows how to submit a data export request with a cutout request using ``im_patch``. |
| 7 |
""" |
| 8 |
|
| 9 |
import os |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
import drms |
| 13 |
|
| 14 |
############################################################################### |
| 15 |
# First we will create a `drms.Client`, using the JSOC baseurl. |
| 16 |
|
| 17 |
client = drms.Client() |
| 18 |
|
| 19 |
############################################################################### |
| 20 |
# This example requires a registered export email address You can register |
| 21 |
# JSOC exports at: http://jsoc.stanford.edu/ajax/register_email.html |
| 22 |
# You must supply your own email. |
| 23 |
|
| 24 |
email = os.environ["JSOC_EMAIL"] |
| 25 |
|
| 26 |
# Create download directory if it does not exist yet. |
| 27 |
out_dir = Path("downloads") |
| 28 |
if not out_dir.exists(): |
| 29 |
Path(out_dir).mkdir(parents=True) |
| 30 |
|
| 31 |
############################################################################### |
| 32 |
# Construct the DRMS query string: ``"Series[timespan][wavelength]{data segments}"`` |
| 33 |
|
| 34 |
qstr = "aia.lev1_euv_12s[2025-01-01T04:33:30.000/1m@12s][171]{image}" |
| 35 |
print(f"Data export query:\n {qstr}\n") |
| 36 |
|
| 37 |
############################################################################### |
| 38 |
# Construct the dictionary specifying that we want to request a cutout. |
| 39 |
# This is done via the ``im_patch`` command. |
| 40 |
# We request a 345.6 arcsecond cutout (on both sides) centered on the coordinate (-517.2, -246) arcseconds as defined in the helioprojective frame of SDO at time ``t_ref``. |
| 41 |
# The ``t`` controls whether tracking is disabled (``1``) or enabled (``0``). |
| 42 |
# ``r`` controls the use of sub-pixel registration. |
| 43 |
# ``c`` controls whether off-limb pixels are filled with NaNs. |
| 44 |
# For additional details about ``im_patch``, see the `documentation <http://jsoc.stanford.edu/doxygen_html/group__im__patch.html>`_. |
| 45 |
process = { |
| 46 |
"im_patch": { |
| 47 |
"t_ref": "2025-01-01T04:33:30.000", |
| 48 |
"t": 0, |
| 49 |
"r": 0, |
| 50 |
"c": 0, |
| 51 |
"locunits": "arcsec", |
| 52 |
"boxunits": "arcsec", |
| 53 |
"x": -517.2, |
| 54 |
"y": -246, |
| 55 |
"width": 345.6, |
| 56 |
"height": 345.6, |
| 57 |
}, |
| 58 |
} |
| 59 |
|
| 60 |
# Submit export request using the 'fits' protocol |
| 61 |
print("Submitting export request...") |
| 62 |
result = client.export( |
| 63 |
qstr, |
| 64 |
method="url", |
| 65 |
protocol="fits", |
| 66 |
email=email, |
| 67 |
process=process, |
| 68 |
) |
| 69 |
|
| 70 |
# Print request URL. |
| 71 |
print(f"\nRequest URL: {result.request_url}") |
| 72 |
print(f"{len(result.urls)} file(s) available for download.\n") |
| 73 |
|
| 74 |
# Download selected files. |
| 75 |
result.wait() |
| 76 |
result.download(out_dir) |
| 77 |
print("Download finished.") |
| 78 |
print(f'\nDownload directory:\n "{out_dir.resolve()}"\n') |