Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2013 08:09
Show Gist options
  • Save anonymous/6434091 to your computer and use it in GitHub Desktop.
Save anonymous/6434091 to your computer and use it in GitHub Desktop.
How to use IMPEx (FMI) from python2.7 with suds
from suds.client import Client
import random
import astropy.constants as const
url = 'http://impex-fp7.fmi.fi/impex/IMPExServer.php?wsdl'
client = Client(url)
print client #Shows all the methods available and their inputs
# getDataPointValue_spacecraft example
result = client.service.getDataPointValue_spacecraft(ResourceID="impex://FMI/HWA/HYB/venus/run01_nominal_with_cx/O+_ave_hybstate", Spacecraft_name="VenusExpress", StartTime="2007-01-11T00:00:00", StopTime="2007-01-21T00:00:00", Sampling="600")
print result
# getDataPointValue, by using a dictionary as input
values = {'ResourceID': 'impex://FMI/HWA/HYB/venus/run01_nominal_with_cx/O+_ave_hybstate',
'url_XYZ': 'http://impex-fp7.fmi.fi/ws/ws_dps/ex.votable'}
result = client.service.getDataPointValue(**values)
print result
#getParticleTrajectory for 100 starting points randomly distributed in the plane x = 12e6; between y and z range [-12e6,12e6]
X = ['12e6'] * 100
Y = [str(random.randrange(-12e6, 12e6)) for x in range(100)]
Z = [str(random.randrange(-12e6, 12e6)) for x in range(100)]
Vx = Vy = Vz = ['0'] * 100
mass = [str(16 * const.m_p.si.value)] * 100
charge = [str(const.e.si.value)] * 100
values = {x:','.join(eval(x)) for x in ['X', 'Y', 'Z', 'Vx', 'Vy', 'Vz', 'mass', 'charge']}
url_votable = client.service.getVOTableURL(**values)
values = {'ResourceID': 'impex://FMI/HWA/HYB/venus/run01_nominal_with_cx/O+_ave_hybstate',
'url_XYZ': url_votable}
url_particle = client.service.getParticleTrajectory(**values)
# Plot the particles trayectory
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.colors as colors
import matplotlib.cm as cmx
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Select colours from colortable: http://stackoverflow.com/questions/8931268/using-colormaps-to-set-color-of-line-in-matplotlib
jet = cm = plt.get_cmap('jet')
cNorm = colors.Normalize(vmin=0, vmax=100)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)
## Read the output with astropy
from astropy.io import votable
vot = votable.parse(url_particle)
# Extract a dictionary with posx, posy and posz for each line in the vot:
axis = ['x', 'y', 'z']
types = ['pos.cartesian.'+l for l in axis]
for idx, table in enumerate(vot.iter_tables()):
points = {}
for column in table.iter_fields_and_params():
ucd = str(column.ucd)
if ucd.lower() in types:
findaxis = lambda x: x in column.name.lower()
mask = map(findaxis, axis)
if True in mask:
column_values = table.array[column.ID].data * column.unit
points[column.ID] = column_values.si.value
# select the colour for each line
colorVal = scalarMap.to_rgba(idx)
ax.plot(points['posx'][:,0], points['posy'][:,0], points['posz'][:,0], color = colorVal)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment