| 1 |
""" |
| 2 |
=============== |
| 3 |
Exporting JPEGs |
| 4 |
=============== |
| 5 |
|
| 6 |
This example shows how to export image data as JPEG file, using the 'jpg' |
| 7 |
protocol. |
| 8 |
|
| 9 |
The 'jpg' 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 |
JPEG 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 |
# Arguments for 'jpg' protocol |
| 31 |
jpg_args = { |
| 32 |
"ct": "aia_304.lut", # color table |
| 33 |
"min": 4, # min value |
| 34 |
"max": 800, # max value |
| 35 |
"scaling": "log", # color scaling |
| 36 |
"size": 2, # binning (1 -> 4k, 2 -> 2k, 4 -> 1k) |
| 37 |
} |
| 38 |
|
| 39 |
# Create download directory if it does not exist yet. |
| 40 |
out_dir = Path("downloads") |
| 41 |
if not out_dir.exists(): |
| 42 |
Path(out_dir).mkdir(parents=True) |
| 43 |
|
| 44 |
############################################################################### |
| 45 |
# Construct the DRMS query string: "Series[timespan][wavelength]{data segments}" |
| 46 |
|
| 47 |
qstr = "aia.lev1_euv_12s[2012-08-31T19:48:01Z][304]{image}" |
| 48 |
print(f"Data export query:\n {qstr}\n") |
| 49 |
|
| 50 |
# Submit export request using the 'jpg' protocol with custom protocol_args |
| 51 |
print("Submitting export request...") |
| 52 |
result = client.export(qstr, protocol="jpg", protocol_args=jpg_args, email=email) |
| 53 |
|
| 54 |
# Print request URL. |
| 55 |
print(f"\nRequest URL: {result.request_url}") |
| 56 |
print(f"{len(result.urls)} file(s) available for download.\n") |
| 57 |
|
| 58 |
# Download selected files. |
| 59 |
result.download(out_dir) |
| 60 |
print("Download finished.") |
| 61 |
print(f"\nDownload directory:\n {out_dir.resolve()}\n") |