Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

This tutorial will show how to download HMI SHARP data from France to use it in the algorithms.

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:

http://cluster-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:

[
  {
    "date__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://cluster-r730-1:8001/HMI/hmi.sharp_720s/5605571/magnetogram.fits",
      "http://cluster-r730-1:8001/HMI/hmi.sharp_720s/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",
      "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",
      "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",
      "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",
      "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",
      "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.

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'
incl_meta = 'false'

# retrieving list of SHARP images
print('loading SHARP list...')
response = requests.get("http://cluster-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:

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:

{
  "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:

# define the query parameter
sharp_image = 5601499
fields = ['area', 'cmask', 'distcoef']

# retrieving list of meta data
print('loading meta data...')
meta_data = requests.get("http://cluster-r730-1:8001/HMI/hmi.sharp_720s/meta/%s?fields=%s" % (str(sharp_image), ','.join(fields))).json()

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 all files of an entry
def download_files(urls):
    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:

# download all files
sharp_files = map(lambda s: download_files(s['urls']), sharp_list)

The sharp_files variable now contains the name to each of the files. 

Script

Here you can download the complete script.

load_sharp.py

  • No labels