; ; NOSA HEADER START ; ; The contents of this file are subject to the terms of the NASA Open ; Source Agreement (NOSA), Version 1.3 only (the "Agreement"). You may ; not use this file except in compliance with the Agreement. ; ; You can obtain a copy of the agreement at ; docs/NASA_Open_Source_Agreement_1.3.txt ; or ; https://cdaweb.gsfc.nasa.gov/WebServices/NASA_Open_Source_Agreement_1.3.txt. ; ; See the Agreement for the specific language governing permissions ; and limitations under the Agreement. ; ; When distributing Covered Code, include this NOSA HEADER in each ; file and include the Agreement file at ; docs/NASA_Open_Source_Agreement_1.3.txt. If applicable, add the ; following below this NOSA HEADER, with the fields enclosed by ; brackets "[]" replaced with your own identifying information: ; Portions Copyright [yyyy] [name of copyright owner} ; ; NOSA HEADER END ; ; Copyright (c) 2016-2017 United States Government as represented by the ; National Aeronautics and Space Administration. No copyright is claimed ; in the United States under Title 17, U.S.Code. All Other Rights ; Reserved. ; ; ; ; Note: The following requires IDL 8.4 or higher (and the root ; certficate of the Certificate Authority which issued cdaweb's ; TLS certificate (https://sscweb.gsfc.nasa.gov/WebServices/https.html). ; ;+ ; Gets the specified parameter description from a HAPI data response. ; ; @param hapiData the result of JSON_PARSE on the response of a HAPI ; data request to cdaweb. That is, an ORDEREDHASH containing the ; ordered key-value pairs from the HAPI data response. ; @param name name of parameter to get. ; @return specified parameter description or !null if not found. The ; parameter description will be an ORDEREDHASH containing the the ; HAPI description of the specified parameter. ;- function getParameter, hapiData, name parameters = hapiData['parameters'] foreach parameter, parameters do begin if (parameter['name'] eq name) then return, parameter endforeach return, !null end ;+ ; Converts the given CDF_EPOCH values to Julian Date values. ; ; @param values the string representation of CDF_EPOCH values to ; convert. ; @return Julian Date values corresponding to the given CDF_EPOCH ; values. ;- function epochToJul, values julValues = dblarr(n_elements(values)) for i = 0, n_elements(values) - 1 do begin timestamptovalues, values[i], year=year, month=month, $ day=day, hour=hour, minute=minute, second=second julValues[i] = julday(month, day, year, hour, minute, second) endfor return, julValues end ;+ ; This procedure demonstrates calling the CDAS HAPI service and ; accessing the results. ;- pro HapiCdawebExample compile_opt idl2 cdasHapiUrl = $ 'https://cdaweb.gsfc.nasa.gov/registry/hdp/hapi' resourceId = 'spase://VSPO/NumericalData/ACE/MAG/L2/PT16S' cdashapi = obj_new('IDLnetURL') catalog = json_parse(cdashapi->get(/string, $ url = cdasHapiUrl + '/catalog.xql')) print, 'Catalog' print, /implied, catalog aceMagL2Pt16sInfo = $ json_parse(cdashapi->get(/string, url = cdasHapiUrl + $ '/info.xql?id=' + resourceId)) print, '====================================================' print, resourceId, ' Info' print, /implied, aceMagL2Pt16sInfo aceMagL2Pt16sData = $ json_parse(cdashapi->get(/string, url = cdasHapiUrl + $ '/data.xql?id=' + resourceId + $ '&time.min=2010-01-01T00:00:00Z' + $ '&time.max=2010-01-01T00:01:00Z&' + $ 'parameters=Magnitude,BGSEc&' + $ 'include=header&format=x_json1')) print, '====================================================' print, resourceId, ' Data' print, /implied, aceMagL2Pt16sData epochValues = aceMagL2Pt16sData['Epoch'].toArray() julEpoch = epochToJul(epochValues) magValues = aceMagL2Pt16sData['Magnitude'].toArray(type='FLOAT') magParameter = getParameter(aceMagL2Pt16sData, 'Magnitude') magLabel = magParameter['label'] bGse = aceMagL2Pt16sData['BGSEc'] bGseParameter = getParameter(aceMagL2Pt16sData, 'BGSEc') bGseDescription = bGseParameter['description'] bGseUnits = bGseParameter['units'] bGseLabels = bGseParameter['label'] bx = list() by = list() bz = list() foreach element, bGse do begin componentValues = element['elements'] bx.add, float(componentValues[0]) by.add, float(componentValues[1]) bz.add, float(componentValues[2]) endforeach timeLabel = label_date(date_format=['%I:%S', '%H', '%Y %M %D']) magPlot = plot(julEpoch, magValues, '-k2+', $ xtitle='Time', ytitle=bGseUnits, $ title=bGseDescription, $ xtickunits=['Time']) ; xtickformat=[timeLabel], $ ; xtickinterval=?, $ ; xtickunits=['Time', 'Hour', 'Day']) t0 = text(julEpoch[1], magValues[1], magLabel, /data) magPlot = plot(julEpoch, bx.toArray(), '-r2+', /over) t1 = text(julEpoch[1], bx[1], bGseLabels[0], /data) magPlot = plot(julEpoch, by.toArray(), '-g2+', /over) t2 = text(julEpoch[1], by[1], bGseLabels[1], /data) magPlot = plot(julEpoch, bz.toArray(), '-b2+', /over) t3 = text(julEpoch[1], bz[1], bGseLabels[2], /data) obj_destroy, cdashapi end