Child pages
  • ICES SOAP data request using Python
Skip to end of metadata
Go to start of metadata

Below a script to request data from the ICES database (http://ocean.ices.dk) via a SOAP operation using PYTHON2.7 with the SUDS package, a lightweight SOAP python client for consuming Web Service. For windows user, get PythonXY and manually install the suds package with easy_install.

python # start python in DOS shell to install easy_install
>>> from ez_setup import use_setuptools
>>> use_setuptools()
>>> exit() # now easy_install works outside python
easy_install suds

Now work with Suds as follows

# import modules
from suds.client import Client

# define URL
url = 'http://ocean.ices.dk/webservices/hydchem.asmx?WSDL'

# request for client object
client = Client(url)

# get the result for one parameter (PSAL)
result = client.service.GetICEData('PSAL',2009,2010,1,12,   -2,9,   49,57,   0,1e5)

# write data to a csv file
afn = r'ICES_PSAL_2009-2010.txt'
af = open(afn,'wb')
af.write('Longitude'+','+'Latitude'+','+'DateTime'+','+'Pressure'+','+'Value'+'\r\n')
for i in range(len(result['ICEData'])):
   af.write(str(result['ICEData'][i]['Longitude'])+','+str(result['ICEData'][i]['Latitude'])+','+str(result['ICEData'][i]['DateTime'])+','+str(result['ICEData'][i]['Pressure'])+','+str(result['ICEData'][i]['Value'])+'r\n')

af.close()

This request takes about 30 seconds, which is nearly twice as fast as the Matlab equivalent. All time is spent in client.service.GetICEData that consists of the server-response time and the parsing of the xml answer. In the Matlab equivalent these are separate, and shows us that the server-response time is negligible, while most time is spent parsing xml. It shows that xml is not a very efficient way of transporting data over the web. The python xml parser is faster than the Matlab one, which makes a significant performance difference when processing xml that is used in many (OGC) like, e.g. WxS.

ICES delivers the following services:

  • GetICEData
  • GetICEDataAverage
    The full list of services including the methods and types can be derived via print client

Requests have to be build up using the following elements

"ParameterCode" type="tns:ParameterCodeEnum"
"FromYear" type="s:int"
"ToYear" type="s:int"
"FromMonth" type="s:int"
"ToMonth" type="s:int"
"FromLongitude" type="s:double"
"ToLongitude" type="s:double"
"FromLatitude" type="s:double"
"ToLatitude" type="s:double"
"FromPressure" type="s:double"
"ToPressure" type="s:double"

The following parameters can be requested for:

<s:enumeration value="TEMP"/>
<s:enumeration value="PSAL"/>
<s:enumeration value="DOXY"/>
<s:enumeration value="PHOS"/>
<s:enumeration value="TPHS"/>
<s:enumeration value="AMON"/>
<s:enumeration value="NTRI"/>
<s:enumeration value="NTRA"/>
<s:enumeration value="NTOT"/>
<s:enumeration value="SLCA"/>
<s:enumeration value="H2SX"/>
<s:enumeration value="PHPH"/>
<s:enumeration value="ALKY"/>
<s:enumeration value="CPHL"/>

A full description the complete service can be derived via http://ocean.ices.dk/webservices/hydchem.asmx?WSDL

See also: ICES SOAP data request using matlab, NOAA CO-OPS SOAP services as implemented in DelftDashBoard