Debian Codegraph @

examples/export_tar.py

raw
1 """
2 ====================================
3 Downloading data as a tar collection
4 ====================================
5
6 This example shows how to submit a data export request using the 'url-tar'
7 method, which provides a single TAR archive containing all requested files.
8
9 Here we use this method to download data from the
10 'hmi.rdvflows_fd15_frame' series, which stores directories of text files
11 for each record. This is currently the only way to download directory
12 data segments using the Python DRMS client. The export protocol in this
13 case is 'as-is'. You might change the protocol to 'fits', if you are
14 downloading FITS files instead of text files.
15 """
16
17 import os
18 from pathlib import Path
19
20 import drms
21
22 ###############################################################################
23 # First we will create a `drms.Client`, using the JSOC baseurl.
24
25 client = drms.Client()
26
27 # This example requires a registered export email address. You can register
28 # JSOC exports at: http://jsoc.stanford.edu/ajax/register_email.html
29 # You must supply your own email.
30 email = os.environ["JSOC_EMAIL"]
31
32 # Create download directory if it does not exist yet.
33 out_dir = Path("downloads")
34 if not out_dir.exists():
35 Path(out_dir).mkdir(parents=True)
36
37 ###############################################################################
38 # Construct the DRMS query string: "Series[Carrington rotation][Carrington longitude]{data segments}"
39
40 qstr = "hmi.rdvflows_fd15_frame[2150][360]{Ux, Uy}"
41 print(f"Data export query:\n {qstr}\n")
42
43 # Submit export request using the 'url-tar' method, protocol default: 'as-is'
44 print("Submitting export request...")
45 result = client.export(qstr, method="url-tar", email=email)
46
47 # Print request URL.
48 print(f"\nRequest URL: {result.request_url}")
49 print(f"{len(result.urls)} file(s) available for download.\n")
50
51 # Download selected files.
52 dr = result.download(out_dir)
53 print("Download finished.")
54 print(f'\nDownloaded file:\n "{dr.download[0]}"\n')