Debian Codegraph @

examples/export_fits.py

raw
1 """
2 ======================
3 Exporting data as fits
4 ======================
5
6 This example shows how to submit a data export request using the 'fits'
7 protocol and how to download the requested files.
8
9 Note that the 'as-is' protocol should be used instead of 'fits', if
10 record keywords in the FITS headers are not needed, as it greatly
11 reduces the server load.
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 # Use 'as-is' instead of 'fits', if record keywords are not needed in the
30 # FITS header. This greatly reduces the server load!
31 export_protocol = "fits"
32
33 # Create download directory if it does not exist yet.
34 out_dir = Path("downloads")
35 if not out_dir.exists():
36 Path(out_dir).mkdir(parents=True)
37
38 ###############################################################################
39 # Construct the DRMS query string: "Series[harpnum][timespan]{data segments}"
40
41 qstr = "hmi.sharp_720s[12519][2024.12.30_22:24:00_TAI/1d@8h]{continuum, magnetogram, field}"
42 print(f"Data export query:\n {qstr}\n")
43
44 # Submit export request using the 'fits' protocol
45 print("Submitting export request...")
46 result = client.export(qstr, method="url", protocol=export_protocol, email=email)
47
48 # Print request URL.
49 print(f"\nRequest URL: {result.request_url}")
50 print(f"{len(result.urls)} file(s) available for download.\n")
51
52 # Download selected files.
53 result.download(out_dir)
54 print("Download finished.")
55 print(f'\nDownload directory:\n "{out_dir.absolute()}"\n')