Note
Go to the end to download the full example code.
Exporting data as ‘as-is’#
This example shows how to submit an ‘url_quick’ / ‘as-is’ data export request to JSOC and how to download the requested files.
The export protocol ‘as-is’, should be preferred over other protocols, because it minimizes the server load. The only reason to use protocol=’fits’ is, when keywords in the FITS header are really needed.
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[harpnum][timespan]{data segments}”
qstr = "hmi.sharp_720s[7451][2020.09.27_00:00:00_TAI]{continuum, magnetogram, field}"
print(f"Data export query:\n {qstr}\n")
# Submit export request, defaults to method='url_quick' and protocol='as-is'
print("Submitting export request...")
result = client.export(qstr, email=email)
print(f"{int(len(result.urls))} file(s) available for download.\n")
# Download selected files.
result.download(out_dir)
print("Download finished.")
print(f'\nDownload directory:\n "{out_dir.resolve()}"\n')
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/drms/checkouts/stable/examples/export_as_is.py", line 43, in <module>
print(f"{int(len(result.urls))} file(s) available for download.\n")
^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/drms/conda/stable/lib/python3.12/site-packages/drms/client.py", line 332, in urls
self._download_urls_cache = self._generate_download_urls()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/drms/conda/stable/lib/python3.12/site-packages/drms/client.py", line 177, in _generate_download_urls
res = self.data.copy()
^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/drms/conda/stable/lib/python3.12/site-packages/drms/client.py", line 280, in data
self._raise_on_error()
File "/home/docs/checkouts/readthedocs.org/user_builds/drms/conda/stable/lib/python3.12/site-packages/drms/client.py", line 171, in _raise_on_error
raise DrmsExportError(msg)
drms.exceptions.DrmsExportError: User jsoc@sunpy.org has 1 pending export requests (JSOC_20250619_002786); please wait until at least one request has completed before submitting a new one. [status=7]
Total running time of the script: (0 minutes 1.814 seconds)