File: export_fits.py

package info (click to toggle)
drms 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 568 kB
  • sloc: python: 2,498; makefile: 198
file content (55 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
======================
Exporting data as fits
======================

This example shows how to submit a data export request using the 'fits'
protocol and how to download the requested files.

Note that the 'as-is' protocol should be used instead of 'fits', if
record keywords in the FITS headers are not needed, as it greatly
reduces the server load.
"""

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"]

# Use 'as-is' instead of 'fits', if record keywords are not needed in the
# FITS header. This greatly reduces the server load!
export_protocol = "fits"

# 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[12519][2024.12.30_22:24:00_TAI/1d@8h]{continuum, magnetogram, field}"
print(f"Data export query:\n  {qstr}\n")

# Submit export request using the 'fits' protocol
print("Submitting export request...")
result = client.export(qstr, method="url", protocol=export_protocol, email=email)

# Print request URL.
print(f"\nRequest URL: {result.request_url}")
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.absolute()}"\n')