========
UCSD Hub
========

Comprehensive doctest for the INCF DAI hub provided by UCSD

>>> from incf.dai.utils import get_hub_by_name
>>> ucsd = get_hub_by_name('ucsd')
>>> sorted(ucsd.capabilities)  # doctest: +NORMALIZE_WHITESPACE
[u'DescribeSRS', 
 u'Get2DImagesByPOI', 
 u'GetStructureNamesByPOI', 
 u'ListSRSs', 
 u'ListTransformations', 
 u'Retrieve2DImage', 
 u'TransformPOI']


Checking ``ListSRSs``

>>> r = ucsd.ListSRSs()
>>> r.keys()  # doctest: +NORMALIZE_WHITESPACE
[u'xmlns_xlink', u'wps_Process', u'xml_lang', u'wps_Status', 
u'wps_ProcessOutputs', u'service', u'xmlns_xsi', u'xmlns_ows', 
u'xsi_schemaLocation', u'version', u'xmlns_ogc', u'xmlns_wps', 
u'serviceInstance']
>>> data = r.wps_ProcessOutputs.wps_Output.wps_Data.wps_ComplexData
>>> data.ListSRSResponse.SRSCollection.SRSList.SRS.Name.data
u'Mouse_Paxinos_1.0'


Checking ``DescribeSRS``

(Seems like this is not implemented yet - or I have not yet figured 
out how to call it.)

Checking ``ListTransformations``

>>> r = ucsd.ListTransformations(format=None, inputSrsName='Mouse_Paxinos_1.0', outputSrsName='Mouse_ABAreference_1.0', filter='Cerebellum')
>>> [t.code for t in r.TransformationList.CoordinateTransformation] # doctest: +NORMALIZE_WHITESPACE
[u'Mouse_Paxinos_1.0_To_Mouse_WHS_0.9',
 u'Mouse_WHS_0.9_To_Mouse_AGEA_1.0',
 u'Mouse_AGEA_1.0_To_Mouse_ABAvoxel_1.0',
 u'Mouse_ABAvoxel_1.0_To_Mouse_ABAreference_1.0']


Checking ``GetStructureNameByPOI``

>>> r = ucsd.GetStructureNamesByPOI(format=None,srsName='Mouse_paxinos_1.0', x='1', y='4.3', z='1.78')
>>> data = r.wps_ProcessOutputs.wps_Output.wps_Data.wps_ComplexData
>>> data.StructureTermsResponse.StructureTerms.StructureTerm.Code.data
u'S1Tr'
>>> data.StructureTermsResponse.StructureTerms.StructureTerm.Name
''
>>> data.StructureTermsResponse.StructureTerms.StructureTerm.Description
u'primary somatosensory cortex'

(why is ``Description`` populated but ``Name`` is empty?)

Note to self: needed to omit the filter=structureset:fine from the
initial call 


Checking ``TransformPOI``

>>> r = ucsd.TransformPOI(format=None, inputSrsName='Mouse_Paxinos_1.0', outputSrsName='Mouse_WHS_0.9', x='1', y='4.3', z='1.78', filter='cerebellum')
>>> r.POI.gml_Point.gml_pos
u'308 642 224'
>>> r.POI.gml_Point.srsName
u'Mouse_WHS_0.9'

(are we sure the unqualified coordinate triple will always suffice?)


Checking ``Get2DImagesByPOI``

>>> r = ucsd.Get2DImagesByPOI(format=None, srsName='Mouse_ABAvoxel_1.0', x='263', y='159', z='227', filter='maptype:Sagittal', tolerance='3')

This returns a total of 10 images at the moment

>>> len(r.Image2Dcollection)
10

the first of which contains the following info (no idea whether that 
will always be the first)

>>> r.Image2Dcollection[0].Image2D.ImageSource.format
u'image/png'
>>> r.Image2Dcollection[0].Image2D.ImageSource.type
u'url'
>>> r.Image2Dcollection[0].Image2D.ImageSource.data
u'http://image.wholebraincatalog.org/cgi-bin/mapserv?map=crbsatlas/mapfiles/gensat_3363_modified_sm_transformed-ms.map&LAYERS=gensat_penk1_09&FORMAT=png24&VERSION=1.1.1&REQUEST=GetMap'

