Previous: Remote access - introduction   Up: Remote access programming tutorial toc   Next: Matlab remote access

Madrigal web services tutorial

The following section gives a tutorial on the various Madrigal web services in the context of the Madrigal data model. This section is intended to help someone writing their own API to interface with Madrigal. If you simply want to use the existing Matlab or python API's, you can skip ahead to the next sections.

The web services are organized in the same way as the Madrigal data model, from Instrument at the highest level, down to the level of data values. See the Remote data access programming reference manual for complete descriptions of all the Madrigal web services.

Madrigal web services are built using the following cgi scripts:

getInstrumentsService.py

The top layer of the Madrigal data model is the instrument. All data in Madrigal is associated with one and only one instrument. Since Madrigal is ground-based focused, an instrument has a particular location associated with it. The following information is available for each instrument:

  1. instrument.name Example: Millstone Hill Incoherent Scatter Radar
  2. instrument.code (unique id) Example: 30
  3. instrument.mnemonic (also unique) (3 char string) Example: mlh
  4. instrument.latitude Example: 45.0
  5. instrument.longitude Example: 110.0
  6. instrument.altitude Example: 0.015 (km)

To access Instrument metadata, call url:

	<any Madrigal server>/getInstrumentsService.py 

For example:

http://www.haystack.mit.edu/cgi-bin/madrigal/getInstrumentsService.py 

will return comma-delimited lines with the six fields above, one for each instrument.

getExperimentsService.py

In the madrigal database system, the data are organized by experiment. An experiment consists of data from a single instrument covering a limited period of time, and, as a rule, is meant to address a particular scientific goal. The following information is available for each instrument:

  1. experiment.id (int) Example: 10000111
  2. experiment.url (string) Example: http://www.haystack.mit.edu/cgi-bin/madtoc/1997/mlh/03dec97
  3. experiment.name (string) Example: Wide Latitude Substorm Study
  4. experiment.siteid (int) Example: 1
  5. experiment.sitename (string) Example: Millstone Hill Observatory
  6. experiment.instcode (int) Code of instrument. Example: 30
  7. experiment.instname (string) Instrument name. Example: Millstone Hill Incoherent Scatter Radar
  8. experiment.start year (int) year of experiment start
  9. experiment.start month (int) month of experiment start
  10. experiment.start day (int) day of experiment start
  11. experiment.start hour (int) hour of experiment start
  12. experiment.start minute (int) min of experiment start
  13. experiment.start second (int) sec of experiment start
  14. experiment.end year (int) year of experiment end
  15. experiment.end month (int) month of experiment end
  16. experiment.end day (int) day of experiment end
  17. experiment.end hour (int) hour of experiment end
  18. experiment.end minute (int) min of experiment end
  19. experiment.end second (int) sec of experiment end
  20. experiment.isLocal (int) 1 if local, 0 if not

To access Experiment metadata for a given instrument and time range, call url:

<any Madrigal server>/getExperimentsService.py?code=<instrument code>&startyear=<year>&startmonth=<month>
&startday=<day>&starthour=<hour>&startmin=<min>&startsec=<sec>&endyear=<year>&endmonth=<month>&endday=<day>
&endhour=<hour>&endmin=<min>&endsec=<sec>&local=<1 or 0> 

Example: To get all data from instrument Millstone Hill ISR (code=30) during 1998 for all Madrigal servers, url is:

http://www.haystack.mit.edu/cgi-bin/madrigal/getExperimentsService.py?code=30&startyear=1998
&startmonth=1&startday=1&starthour=0&startmin=0&startsec=0&endyear=1999&endmonth=1&endday=1
&endhour=0&endmin=0&endsec=0&local=0

which will return comma-delimited lines with the 20 fields above, one for each experiment.

getExperimentFilesService.py

The data from a given experiment is stored in one or more experiment files. The format of these files is the Cedar database format, but this is not important since this data is exposed remotely in an ascii format. Note that once we are at the level of experiment files, we need to request the file from the right Madrigal server. The name of correct Madrigal server is given by the experiment.url field, with everything after the "madtoc" indicator replaced by the correct cgi script name (see example below). The following information is available for each experiment file:

  1. file.name (string) Example /opt/madrigal/blah/mlh980120g.001
  2. file.kindat (int) Kindat code. Example: 3001
  3. file.kindat desc (string) Kindat description: Example Basic Derived Parameters
  4. file.category (int) (1=default, 2=variant, 3=history, 4=real-time)
  5. file.status (string)(preliminary, final, or any other description)
  6. file.permission (int) 0 for public, 1 for private. For now will not return private files.

To access Experiment file metadata for a given experiment, call url:

<the correct Madrigal server>/getExperimentFilesService.py?id=<experiment id>

where experiment id was returned by getExperimentsService.py, and the correct Madrigal server is experiment.url, truncated before /madtoc/.

Example: to get Experiment File from experiment id = 20001996,experiment url = http://www.eiscat.se/madrigal/cgi-bin/madtoc/1998/mlh/20jan98:

 http://www.eiscat.se/madrigal/cgi-bin/getExperimentFilesService.py?id=20001996

which will return comma-delimited lines with the 6 fields above, one for each experiment file. (Note: this experiment id may change in the future).

getParametersService.py

Any given file is made up a series of records holding parameters. The next cgi scripts returns information about the parameters contained in a given file. The following information is available about the parameters in any experiment file:

  1. parameter.mnemonic (string) Example dti
  2. parameter.description (string) Example: "F10.7 Multiday average observed (Ott)"
  3. parameter.isError (int) 1 if error parameter, 0 if not
  4. parameter.units (string) Example "W/m2/Hz"
  5. parameter.isMeasured (int) 1 if measured, 0 if derivable
  6. parameter.category (string) Example: "Time Related Parameter"
  7. parameter.isSure (int) - 1 if parameter can be found for every record, 0 if can only be found for some

Note that Madrigal will automatically derive a large number of parameters such as Kp and Magnetic field strength that aren't in the file itself; from the user's point of view these derived parameters appear to be in the file. This is the meaning of column 5: isMeasured. 1 means the data comes from the file itself, 0 means it was derived. To access the parameter information for a given file, call url:

<the correct Madrigal server>/getParametersService.py?filename=<full filename>

where full filename was returned by getExperimentFilesService.py in column 1, and the correct Madrigal server is again required.

Example: to get the parameters for file mil980120g.001 from the eiscat server:

http://www.eiscat.se/madrigal/cgi-bin/getParametersService.py?filename=/usr/local/madroot/experiments/1998/mlh/20jan98/mil980120g.001 

which will return backslash-delimited lines with the 7 fields above, one for each parameter. Note that backslash is used as a delimiter since commas appear in the parameter descriptions.

isprintService.py

The bottom level of the Madrigal data model is of course the data itself. A Madrigal file is made up of a series of records, each with a start and stop time, representing the integration period of measurement (Madrigal tries to enforce the idea that all measurements take a finite time, but sometimes the start time = the stop time). When a user wants data from a file, they simply specify the parameters they want (and optionally, any filters to apply to the data). For the moment I'll ignore filtering data (for details, see isprint services ).

To access the parameters for a given file, call url:

<the correct Madrigal server>/isprintService.py?file=<full filename> &parms=<plus-separated parameter mnemonics>

where the filename is the same as in getParametersService.py and parameter mnemonics were returned by getParametersService.py.

Example: To get parameters year, month, day, hour, min, sec, gdlat, glon, gdalt, and ti (temperature ions) from the file /usr/local/madroot/experiments/1998/mlh/20jan98/mil980120g.001, we call url:

http://www.eiscat.se/madrigal/cgi-bin/isprintService.py?file=/usr/local/madroot/experiments/1998/mlh/20jan98/mil980120g.001
&parms=year+month+day+hour+min+sec+gdlat+glon+gdalt+ti 

This will return 11 columns for the 11 requested parameters in the same order as they were requested, with one line for each measurement.

madCalculatorService.py

Madrigal can derive data, as well as display data from existing experiment files. For example, Madrigal can derive MSIS neutral atmosphere parameters for any time and location. To access this derivation engine, call the madCalculatorService.py script. This script allows you to derive one or more parameters for a range of locations at a single time. If you need data at more than one time, simply call this script repeatedly. If you need data that is independent of position (such as Kp) for more than one time, use the madTimeCalculator.py service. Note that this service does not provide measured data from Madrigal data files; use isprintService.py for that.

It has the following input arguments:

The script returns comma-delimited data, one line for each combination of lat, long, and alt, with the following fields:

  1. latitude 2. longitude 3. altitude 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace

Example: To get the three components on the magnetic field (BN, BE, BD) at midnight 1/1/2000 at latitude = 20, longitude = 40, and altitudes of 100 to 1000 km in steps of 100 km, use:

http://madrigal.haystack.mit.edu/cgi-bin/madrigal/madCalculatorService.py?year=2000&month=1&day=1&
hour=0&min=0&sec=0&startLat=20&endLat=20&stepLat=1&startLong=40&endLong=40&stepLong=1&
startAlt=100&endAlt=1000&stepAlt=100&parms=bn,be,bd 

This will return the following six columns: latitude, longitude, altitude, BN, BE, BD:



20.00 40.00 100.00 3.33234e-05 1.23289e-06 1.69326e-05 
20.00 40.00 200.00 3.16261e-05 1.07499e-06 1.60124e-05 
20.00 40.00 300.00 3.00451e-05 9.33461e-07 1.51637e-05 
20.00 40.00 400.00 2.85703e-05 8.06412e-07 1.43793e-05 
20.00 40.00 500.00 2.71927e-05 6.92227e-07 1.36528e-05 
20.00 40.00 600.00 2.59044e-05 5.89497e-07 1.29786e-05 
20.00 40.00 700.00 2.46981e-05 4.96988e-07 1.23518e-05 
20.00 40.00 800.00 2.35672e-05 4.13624e-07 1.17679e-05 
20.00 40.00 900.00 2.25059e-05 3.38453e-07 1.12232e-05 
20.00 40.00 1000.00 2.15087e-05 2.70640e-07 1.07142e-05


madTimeCalculatorService.py

The madTimeCalculatorService.py service is similar to the madCalculatorService.py service, but it calculates values for a series of times. However, it is limited to parameters that are independent of position, such as Kp.

Input cgi arguments:

  1. startyear - int (required)
  2. startmonth - int (required)
  3. startday - int (required)
  4. starthour - int (required)
  5. startmin - int (required)
  6. startsec - int (required)
  7. endyear - int (required)
  8. endmonth - int (required)
  9. endday - int (required)
  10. endhour - int (required)
  11. endmin - int (required)
  12. endsec - int (required)
  13. stephours - double - number of hours between each measurement (required)
  14. parms - comma delimited string of Madrigal parameters desired (required)

Returns comma-delimited data, one line for time, with the following fields:

  1. year
  2. month
  3. day
  4. hour
  5. min
  6. sec
  7. Values for each Madrigal parameter listed in argument parms, separated by whitespace

Example: To get Kp and F10.7 for each 3 hour interval on Jan. 1, 2000, use:

http://grail.haystack.mit.edu/cgi-bin/madrigal/madTimeCalculatorService.py?
startyear=2000&startmonth=1&startday=1&starthour=0
&startmin=0&startsec=0&endyear=2000&endmonth=1&
endday=1&endhour=23&endmin=59&endsec=59&stephours=1&parms=kp,f10.7 

This will return the following eight columns: year, month, day, hour, min, sec, kp, f10.7:

 
 2000 1 1 0 0 0 5.30 1.29900e-20 
 2000 1 1 3 0 0 4.70 1.29900e-20 
 2000 1 1 6 0 0 4.00 1.29900e-20 
 2000 1 1 9 0 0 3.30 1.29900e-20 
 2000 1 1 12 0 0 4.30 1.29900e-20 
 2000 1 1 15 0 0 3.00 1.29900e-20 
 2000 1 1 18 0 0 4.30 1.29900e-20 
 2000 1 1 21 0 0 3.70 1.29900e-20 
 

RadarToGeodeticService.py

The radarToGeodeticService.py script converts a radar position (azimuth, elevation, and range) to a geodetic location. Use geodeticToRadarService.py to go in the other direction.

Input cgi arguments:

  1. slatgd - radar geodetic latitude
  2. slon - radar longitude
  3. saltgd - radar geodetic altitude
  4. az - a comma-separated list of radar azimuth in degrees (0 = north)
  5. el - a comma-separated list of radar elevation in degrees
  6. range - a comma-separated list of radar range in km

Returns comma-delimited data, one line for point in lists:

  1. geodetic latitude of point
  2. longitude of point
  3. geodetic altitude of point

Example: To get the geodetic point at azimuth=100, elevation=45,55, and 65, and range=1000 km from the Millstone Hill IS Radar at latitude=42.619, longitude=288.51, and altitude=0.146, use:

http://madrigal.haystack.mit.edu/cgi-bin/madrigal/radarToGeodeticService.py?
slatgd=42.619&slon=288.51&saltgd=0.146&az=100,100,100&el=45,55,65&range=1000,1000,1000

which will return the geodetic latitude, longitude, and altitude of those three radar positions:

  41.361338,-64.012651,742.038442
  41.645771,-65.488196,841.794521
  41.932738,-67.098375,918.473216

geodeticToRadar

The geodeticToRadarService.py script converts a a geodetic location to radar position (azimuth, elevation, and range) . Use radarToGeodeticService.py to go the other way.

Input cgi arguments:

  1. slatgd - radar geodetic latitude
  2. slon - radar longitude
  3. saltgd - radar geodetic altitude
  4. gdlat - a comma-separated list of geodetic latitude of point
  5. glon - a comma-separated list of longitude of point
  6. gdalt - a comma-separated list of geodetic altitude of point

Returns comma-delimited data, one line for point in lists:

  1. radar azimuth in degrees (0 = north)
  2. radar elevation in degrees
  3. radar range in km

Example: To get the radar location at gdlat=42, glon=290, and gdalt=1000, 2000, and 3000 km from the Millstone Hill IS Radar at latitude=42.619, longitude=288.51, and altitude=0.146, use:

http://madrigal.haystack.mit.edu/cgi-bin/madrigal/geodeticToRadarService.py?
slatgd=42.619&slon=288.51&saltgd=0.146&gdlat=42,42,42&glon=290,290,290&gdalt=1000,2000,3000

which will return the azimuth, elevation, and range of those three geodetic positions:

 117.704418,80.825093,1011.252383
 116.906481,84.802395,2006.351074
 116.270492,86.139493,3004.705956

traceMagneticFieldService.py

The traceMagneticFieldService.py service allows you to trace magnetic field lines using either the IGRF model or the Tysganenko models.

Input cgi arguments:

Returns comma-delimited data, one line for point in in lists:

  1. geodetic altitude or ZGSM of ending point
  2. geodetic latitude or XGSM of ending point
  3. longitude or YGSM of ending point

Example: To get the position of the magnetic field line when it crosses 1000 km in the northern hemisphere at midnight 1/1/2004, using the Tysganenko model, with starting points given in GSM and output in geodetic, use:

http://www.haystack.mit.edu/cgi-bin/madrigal/traceMagneticFieldService.py?
model=0&stopAlt=1000.000000&year=2004&month=1&day=1&hour=0&min=0&sec=0&
in1=0.269000,0.300000,0.300000,0.300000,0.300000&
in2=0.583000,0.600000,0.600000,0.600000,0.600000&
in3=-0.959870,-10.000000,-1.000000,-10.000000,-1.000000&inputType=1&outputType=0&qualifier=1

which in this case returns a comma-separated list of geodetic altitude, latitude, and longitude:

missing,missing,missing
1000.000000,74.695086,102.027236
1000.000000,19.026779,129.445239
1000.000000,74.695086,102.027236
1000.000000,19.026779,129.445239

getMetadata

Finally, one other tcl cgi script should be included as part of the web services API: getMetadata. This cgi script allows direct downloading of any of the 10 metadata files . In general, all information needed from Madrigal should be available in an easier-to-use form from the python cgi scripts above. However, there is some information in the metadata that is not available through those scripts, and if that information is ever needed, a user can call getMetadata to download the metadata file itself as follows:

cgiUrl /getMetadata?fileType= value

where value is

 

Previous: Remote access - introduction   Up: Remote access programming tutorial toc   Next: Matlab remote access