This tutorial will show how to download SHARP data from France to use it in the algorithms.
Prepare
To load SHARP images from France you have to be connected to France over the SSH tunnel and added the port mapping (see ssh_port_forwarding_template.sh). Then you are able to go to the HMI Service UI (http://localhost:8001/ui/) to create your query. The only route you will need directly is the /HMI/{series}.
Follow the instructions on Access to infrastructure on cluster to make sure you have access to the host "cluster-r730-1".
To download sharp_720s images over a period of time you have to set the series parameter and the start and end date. After trying it out you should see the request url which you can use in your python code:
http://cluster-r730-1:8001/HMI/sharp_720s?start=2015-12-11T00%3A00%3A00Z&end=2015-12-12T00%3A00%3A00Z
The result of this query will be a list of SHARP files with a link to them to download it:
[ { "url": "http://cluster-r730-1:8001/HMI/sharp_720s/sharp_720s_20151211_182208", "date_obs": "2015-12-11T18:22:08.799999Z" }, { "url": "http://cluster-r730-1:8001/HMI/sharp_720s/sharp_720s_20151211_183408", "date_obs": "2015-12-11T18:34:08.799999Z" }, { "url": "http://cluster-r730-1:8001/HMI/sharp_720s/sharp_720s_20151211_184608", "date_obs": "2015-12-11T18:46:08.799999Z" }, { "url": "http://cluster-r730-1:8001/HMI/sharp_720s/sharp_720s_20151211_185808", "date_obs": "2015-12-11T18:58:08.799999Z" }, { "url": "http://cluster-r730-1:8001/HMI/sharp_720s/sharp_720s_20151211_191008", "date_obs": "2015-12-11T19:10:08.799999Z" } ]
Loading Metadata
We recommend the python library requests to interact with the rest interfaces from python.
To get a list of SHARP images in this time range you have to create a GET request to the url we tried out before. For a better overview we recommend to separate the parameters of the query into variables.
# define the query parameter start_date = '2015-12-11T00:00:00Z' end_date = '2015-12-12T00:00:00Z' # retrieving list of SHARP images print('loading SHARP list...') sharp_list = requests.get("http://cluster-r730-1:8001/HMI/sharp_720s?start=%s&end=%s" % (start_date, end_date)).json()
This list contains the url and the date of the specific SHARP image.
Downloading Images
With the metadata it is now possible to download the actual images. To do this we have written a tiny function which needs a url as parameter and downloads the file. The image name will be obtained from the header of the http response. The files are written in to the same folder where the script is.
# download one file def download_file(url): r = requests.get(url, stream=True) dispo = r.headers['content-disposition'] file_name = re.findall("filename=(.+)", dispo)[0] print("downloading %s ..." % file_name) if r.status_code == 200: with open(file_name, 'wb') as f: for chunk in r.iter_content(1024): f.write(chunk) return file_name
With this method the download of all SHARP files is now a one-liner:
# download every file sharp_files = map(lambda s: download_file(s['url']), sharp_list)
The sharp_files variable now contains the name to each of the files.
Script
Here you can download the complete script.