| 1 |
""" |
| 2 |
========================= |
| 3 |
Exporting data as 'as-is' |
| 4 |
========================= |
| 5 |
|
| 6 |
This example shows how to submit an 'url_quick' / 'as-is' data export request |
| 7 |
to JSOC and how to download the requested files. |
| 8 |
|
| 9 |
The export protocol 'as-is', should be preferred over other protocols, |
| 10 |
because it minimizes the server load. The only reason to use |
| 11 |
protocol='fits' is, when keywords in the FITS header are really needed. |
| 12 |
""" |
| 13 |
|
| 14 |
import os |
| 15 |
from pathlib import Path |
| 16 |
|
| 17 |
import drms |
| 18 |
|
| 19 |
############################################################################### |
| 20 |
# First we will create a `drms.Client`, using the JSOC baseurl. |
| 21 |
|
| 22 |
client = drms.Client() |
| 23 |
|
| 24 |
# This example requires a registered export email address. You can register |
| 25 |
# JSOC exports at: http://jsoc.stanford.edu/ajax/register_email.html |
| 26 |
# You must supply your own email. |
| 27 |
email = os.environ["JSOC_EMAIL"] |
| 28 |
|
| 29 |
# Create download directory if it does not exist yet. |
| 30 |
out_dir = Path("downloads") |
| 31 |
if not out_dir.exists(): |
| 32 |
Path(out_dir).mkdir(parents=True) |
| 33 |
|
| 34 |
############################################################################### |
| 35 |
# Construct the DRMS query string: "Series[harpnum][timespan]{data segments}" |
| 36 |
|
| 37 |
qstr = "hmi.sharp_720s[7451][2020.09.27_00:00:00_TAI]{continuum, magnetogram, field}" |
| 38 |
print(f"Data export query:\n {qstr}\n") |
| 39 |
|
| 40 |
# Submit export request, defaults to method='url_quick' and protocol='as-is' |
| 41 |
print("Submitting export request...") |
| 42 |
result = client.export(qstr, email=email) |
| 43 |
print(f"{len(result.urls)} file(s) available for download.\n") |
| 44 |
|
| 45 |
# Download selected files. |
| 46 |
result.download(out_dir) |
| 47 |
print("Download finished.") |
| 48 |
print(f'\nDownload directory:\n "{out_dir.resolve()}"\n') |