The UKCP
Application Programming Interface (API) - Getting Started
A walk-through of how to use the API key
The following steps will help get you started:- Log in to the web site and run a process
- Click on the Login link on the top right corner of the screen
- Log in
- Make a note of your API key, you will need this later
- Go to the Products page
- Select the Plume plot of time series anomaly from probabilistic UK climate projections product
- Fill in the form and then Submit it
- On the job viewer page copy the URL
- When the process has finished go to the Job Details tab
- Use the embedded copy button to copy the Job Request URL
- Modify the inputs as required
- Initially just keep them the same
- Later you could try changing the TimeSlice
to
2000|2030
or the TimePeriod tojun
- Test in the browser
- Paste the URL into a browser
- You should get an XML response telling you the job has run
- The XML includes details of the job as well as links to the outputs generated
Using the API directly from code
Using the URL obtained in the example above it is possible to construct a script to call the api. For example:
import urllib2
api_key = "<YOUR_API_KEY>"
months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
"nov", "dec"]
url_template = ("https://ukclimateprojections-ui.metoffice.gov.uk/wps/Execute?"
"Request=Execute&"
"Identifier=LS1_Plume_01&Format=text/xml&Inform=true&Store=false&"
"Status=false&DataInputs=Area=point|245333.38|778933.24;Baseline=b8100;"
"Collection=land-prob;ColourMode=c;DataFormat=csv;FontSize=m;"
"ImageFormat=png;ImageSize=1200;LegendPosition=7;PlotType=PDF_PLOT;"
"Scenario=sres-a1b;TemporalAverage={month};TimeSlice=2050-2069;"
"TimeSliceDuration=20y;Variable=tasAnom;"
"&ApiKey={api_key}")
for month in months:
url = url_template.format(month=month,api_key=api_key)
response = urllib2.urlopen(url)
xml_doc = response.read()