File: export_tar.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 (54 lines) | stat: -rw-r--r-- 1,953 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
"""
====================================
Downloading data as a tar collection
====================================

This example shows how to submit a data export request using the 'url-tar'
method, which provides a single TAR archive containing all requested files.

Here we use this method to download data from the
'hmi.rdvflows_fd15_frame' series, which stores directories of text files
for each record. This is currently the only way to download directory
data segments using the Python DRMS client. The export protocol in this
case is 'as-is'. You might change the protocol to 'fits', if you are
downloading FITS files instead of text files.
"""

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

# 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[Carrington rotation][Carrington longitude]{data segments}"

qstr = "hmi.rdvflows_fd15_frame[2150][360]{Ux, Uy}"
print(f"Data export query:\n  {qstr}\n")

# Submit export request using the 'url-tar' method, protocol default: 'as-is'
print("Submitting export request...")
result = client.export(qstr, method="url-tar", email=email)

# Print request URL.
print(f"\nRequest URL: {result.request_url}")
print(f"{len(result.urls)} file(s) available for download.\n")

# Download selected files.
dr = result.download(out_dir)
print("Download finished.")
print(f'\nDownloaded file:\n  "{dr.download[0]}"\n')