This tutorial will show how to download HMI 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}.
Samples are written in Python but can be adapted to IDL by following Access to REST-Services in IDL
Prepare
Open sshuttle connection to host "cluster-r730-1" (see Access FLARECAST cluster (sshuttle)).
Open http://cluster-r730-1:8001/ui in a browser.
To download sharp_720s images over a period of time you have to set the series parameter and the start and end date. Optionally, you can request the available hmi-meta data by the corresponding meta parameter, which may requires some time. After trying it out you should see the request url which you can use in your python code:
Code Block | ||
---|---|---|
| ||
http://localhostcluster-r730-1:8001/HMI/hmi.sharp_720s?start=2015-12-11T00%3A00%3A00Z&end=2015-12-12T00%3A00%3A00Z&meta=false |
The result of this query will be a list of SHARP files with a link to them to download it:
Code Block | ||
---|---|---|
| ||
[ { "urldate__obs": "2015-12-11T23:34:08.799999Z", "download_time": null, "exptime": null, "harpnum": 6178, "mask_cadence": null, "nbr_update": 0, "quality": 0, "recnum": 5605571, "recnum_init": null, "series_name": "hmi.sharp_720s", "t_rec_index": 1005598, "time": "2016-01-20T05:41:33.750935Z", "type": null, "urls": [ "http://localhostcluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/magnetogram.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s_20151211_182208/5605571/bitmap.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/Dopplergram.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/continuum.fits", "date_obs": "2015-12-11T18:22:08.799999Z" }, { "url": "http://localhost:8001/HMI/sharp_720s/sharp_720s_20151211_183408 "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/inclination.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/azimuth.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/field.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/vlos_mag.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/dop_width.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/eta_0.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/damping.fits", "date_obs": "2015-12-11T18:34:08.799999Z" }, { "url": "http://localhost:8001/HMI/sharp_720s/sharp_720s_20151211_184608 "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/src_continuum.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/src_grad.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/alpha_mag.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/chisq.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/conv_flag.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/info_map.fits", "date_obs": "2015-12-11T18:46:08.799999Z" }, { "url": "http://localhost:8001/HMI/sharp_720s/sharp_720s_20151211_185808 "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/confid_map.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/inclination_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/azimuth_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/field_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/vlos_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/alpha_err.fits", "date_obs": "2015-12-11T18:58:08.799999Z" }, { "url": "http://localhost:8001/HMI/sharp_720s/sharp_720s_20151211_191008 "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/field_inclination_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/field_az_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/inclin_azimuth_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/field_alpha_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/inclination_alpha_err.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/azimuth_alpha_err.fits", "date_obs": "2015-12-11T19:10:08.799999Z" } "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/disambig.fits", "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/conf_disambig.fits" ], "wavelnth": 6173 }, ... ] |
Loading Metadata
We recommend the python library requests to interact with the rest interfaces from python.
...
Code Block | ||
---|---|---|
| ||
# define the query parameter start_date = '2015-12-11T00:00:00Z' end_date = '2015-12-12T00:00:00Z' incl_meta = 'false' # retrieving list of SHARP images print('loading SHARP list...') sharp_listresponse = requests.get("http://localhostcluster-r730-1:8001/HMI/hmi.sharp_720s?start=%s&end=%s&meta=%s" % (start_date, end_date, incl_meta)).json() |
...
sharp_list = response['data']
# extract specific properties of the first SHARP image
sharp_image = 0
first_sharp_date = sharp_list[sharp_image]['date__obs']
first_sharp_urls = sharp_list[sharp_image]['urls'] |
Given the above request url we could download all related hmi-meta data which is, however, not recommended. Resolving hmi-meta data requires some time whereas we may not be interessted in all meta data or all SHARP images. For this reason, we can reload specific meta data for a given set of images.
As an example, the above request reloads the area, cmask and distcoef meta data from the SHARP image 5601499. The corresponding url request looks like this:
Code Block | ||
---|---|---|
| ||
http://localhost:8001/HMI/hmi.sharp_720s/meta/5601499?fields=area,cmask,distcoef |
The result of this query is a list of header informations and meta data for each requested SHARP image:
Code Block | ||
---|---|---|
| ||
{
"5601499": {
"date__obs": "2015-12-11T23:34:08.800000Z",
"download_time": null,
"exptime": null,
"harpnum": 6167,
"mask_cadence": null,
"meta": {
"area": 3507.3125,
"cmask": 6423,
"distcoef": "/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps//../libs/lev15/"
},
"nbr_update": 0,
"quality": 0,
"recnum": 5601499,
"recnum_init": null,
"series_name": "hmi.sharp_720s",
"t_rec_index": 1005598,
"time": "2016-05-26T15:39:51Z",
"type": null,
"urls": [],
"wavelnth": 6173
}
} |
The same way as given in the first code example of this section we can now access those meta data using python and requests:
Code Block | ||
---|---|---|
| ||
# define the query parameter
sharp_image = 5601499
fields = ['area', 'cmask', 'distcoef']
# retrieving list of meta data
print('loading meta data...')
response = requests.get("http://cluster-r730-1:8001/HMI/hmi.sharp_720s/meta/%s?fields=%s" % (str(sharp_image), ','.join(fields))).json()
meta_data = response['data'] |
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.
Code Block | ||
---|---|---|
| ||
# download oneall file files of an entry def download_filefiles(urlurls): for url in urls: 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:
Code Block | ||
---|---|---|
| ||
# download everyall filefiles sharp_files = map(lambda s: download_filefiles(s['urlurls']), sharp_list) |
The sharp_files variable now contains the name to each of the files.
Script
Here you can download the complete script.
...