Top Banner
The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO
19

The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

Mar 27, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

The VAO is operated by the VAO, LLC.

VO Application Libraries

Mike FitzpatrickNOAO

Page 2: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

22

Libraries

In order to VO-enable legacy applications, they must be able to use VO standards and protocols.

In order to reach as many applications as possible, we cannot be limited to a specific language or toolkit.

Start with the basics of an application toolkit:

VOTable - lingua franca of the VOSAMP - play nice with other toolsVOEvent - some seem to like itVOClient - get the data

Page 3: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

33

Development Concepts

C-based code Use SWIG to create other language interfaces (Python, Java, etc) Hand-code Fortran (and IRAF/SPP) interface

Hide the underlying complexity from the user/developer E.g. an application developer wants to use SAMP to send/receive

messages, they shouldn’t need to implement the full spec or know XML-RPC

Be Language-Neutral E.g. Don’t return a votable structure, use handles to more complex

objects

VO Protocols change and evolve Change the library, not every application using it

Page 4: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

44

libVOTable

Full Read/Write Capability Lenient Parser

Only requires proper XML to read Can be used as a validating parser

VOTable v1.2 compliant on output SAX-based parser, DOM interface

Fast lookup of data tables Provides low-level access to document structure

Self-contained, i.e. no need for parser lib

VOTables now accessible to Fortran applications

Page 5: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

55

libVOTable

main (int argc, char **argv){ vot = openVOTABLE (argv[1]); res = vot_getRESOURCE (vot); tab = vot_getTABLE (res); data = vot_getDATA (tab); tdata = vot_getTABLEDATA (data);

for (field=vot_getFIELD(tab); field; field = vot_getNext(field)) name = vot_getAttr (field, "name”) }

for (tr=vot_getTR (tdata); tr; tr=vot_getNext(tr)) { for (td=vot_getTD(tr),i=0; td; td=vot_getNext(td),i++) { printf ("%s", ((s = vot_getValue (td)) ? s : "") ); } }

Page 6: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

66

libVOTable

Print all the PARAM elements in a table with a single RESOURCE

a) Use the low-level interface dealing with document structure

res = vot_getRESOURCE (vot) for (p = vot_getChild (res); p; p = vot_getSibling (p)) { if (vot_typeOf (p) == TY_PARAM) printf ("PARAM name=%s value=%s\n", vot_getAttr(p, "name"), vot_getAttr(p, "value")) }

b) Use the common hi-level interface

res = vot_getRESOURCE (vot) for (p = vot_getPARAM (res); p; p = vot_getNext (p)) { printf ("PARAM name=%s value=%s\n", vot_getAttr(p, "name"), vot_getAttr(p, "value")) }

Page 7: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

77

libVOTable

vot1 = vot_openVOTABLE (in1); /* Parse the files */ vot2 = vot_openVOTABLE (in2);

res1 = vot_getRESOURCE (vot1);/* Get RESOURCEs */ res2 = vot_getRESOURCE (vot2);

vot3 = vot_openVOTABLE (out_fname);/* Open output */

vot_attachNode (vot3, res1); /* Concat tables */ vot_attachNode (vot3, res2);

vot_writeVOTable (vot3, stdout); /* Write it out */

vot_closeVOTABLE (vot1); vot_closeVOTABLE (vot2); if (vot3) vot_closeVOTABLE (vot3);

Page 8: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

88

libVOEvent

Similar to VOTable parser (shared code) Full Read/Write Capability Lenient Parser

Only requires proper XML to read Can be used as a validating parser

VOEvent v1.11 compliant on output SAX-based parser, DOM interface

Provides low-level access to document structure Self-contained, i.e. no need for parser lib

VOEvent now accessible to Fortran applications (!?!)

Hides the complexity of VOEvent from the user

Page 9: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

99

libVOEvent

The myth:VOEvent is a lightweight, simple format i.e.

<voevent><Who/><What/><WhenWhere/><Why/><How/>

</voevent>

Page 10: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1010

libVOEvent<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

<?xml version= "1.0" encoding= "UTF-8"?> <voe:VOEvent ivorn='ivo://nasa.gsfc.gcn/SWIFT#BAT_QuickLook_Pos_422437-319' role='observation' version='1.1' xmlns:voe='http://www.ivoa.net/xml/VOEvent/v1.1' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xlink='http://www.w3.org/1999/xlink' xsi:schemaLocation='http://www.ivoa.net/xml/VOEvent/v1.1 http://www.ivoa.net/xml/VOEvent/VOEvent-v1.1.xsd'> <Who> <AuthorIVORN> ivo://nasa.gsfc.tan/gcn </AuthorIVORN> <Author> <shortName> VO-GCN </shortName> <contactName> Scott Barthelmy </contactName> <contactPhone> +1-301-286-3106 </contactPhone> <contactEmail> [email protected] </contactEmail> </Author> <Date> 2010-05-18T06:19:02 </Date> <Description> This VOEvent message was created with GCN VOE version: 1.1 11mar10 </Description> </Who> <What> <Param name='Packet_Type' value='97'/> <Param name='Pkt_Ser_Num' value='1'/> <Param name='TrigID' value='422437' ucd='meta.id'/> <Param name='Segment_Num' value='0' ucd='meta.id.part'/> <Param name='Burst_TJD' value='15334' unit='days' ucd='time'/> <Param name='Burst_SOD' value='22706.56' unit='sec' ucd='time'/> <Param name='Trig_Index' value='157'/> <Param name='AT_Slew_Flags' value='0x3'/> <Param name='Misc_flags' value='0x0'/> <Param name='Rate_Signif' value='28.72' unit='sigma' ucd='stat.snr'/> <Param name='SC_Long' value='0.00' unit='deg' ucd='pos.earth.lon'/> <Param name='SC_Lat' value='0.00' unit='deg' ucd='pos.earth.lat'/>

<Group name='Misc_Flags'> <Param name='Values_Out_of_Range' value='false'/> <Param name='Near_Bright_Star' value='false'/> <Param name='Err_Circle_in_Galaxy' value='false'/> <Param name='Galaxy_in_Err_Circle' value='false'/> <Param name='TOO_Generated' value='false'/> <Param name='CRC_Error' value='false'/> </Group> <Param name='Coords_Type' value='1' unit='dn'/> <Param name='Coords_String' value='source_object'/> <Group name='Obs_Support_Info'> <Description> The Sun and Moon values are valid at the time the VOEvent XML message was created. </Description> <Param name='Sun_RA' value='54.93' unit='deg' ucd='pos.eq.ra'/> <Param name='Sun_Dec' value='19.54' unit='deg' ucd='pos.eq.dec'/> <Param name='Sun_Distance' value='87.38' unit='deg' ucd='pos.angDistance'/> <Param name='Sun_Hr_Angle' value='6.91' unit='hr'/> <Param name='Moon_RA' value='112.94' unit='deg' ucd='pos.eq.ra'/> <Param name='Moon_Dec' value='21.05' unit='deg' ucd='pos.eq.dec'/> <Param name='MOON_Distance' value='116.41' unit='deg' ucd='pos.angDistance'/> <Param name='Moon_Illum' value='20.77' unit='%' ucd='arith.ratio'/> <Param name='Galactic_Long' value='80.63' unit='deg' ucd='pos.galactic.lon'/> <Param name='Galactic_Lat' value='-1.62' unit='deg' ucd='pos.galactic.lat'/> <Param name='Ecliptic_Long' value='331.66' unit='deg' ucd='pos.ecliptic.lon'/> <Param name='Ecliptic_Lat' value='55.15' unit='deg' ucd='pos.ecliptic.lat'/> </Group> <Description> Type=97: The Swift-BAT instrument quick-look position notice. </Description> </What> <WhereWhen> <ObsDataLocation xmlns='http://www.ivoa.net/xml/STC/stc-v1.30.xsd'> <ObservatoryLocation xlink:href='ivo://STClib/Observatories#GEOLUN/' xlink:type='simple' id='GEOLUN'/> <ObservationLocation> <AstroCoordSystem xlink:href='ivo://STClib/CoordSys#UTC-FK5-GEO/' xlink:type='simple' id='FK5-UTC-GEO'/> <AstroCoords coord_system_id='FK5-UTC-GEO'> <Time unit='s'> <TimeInstant> <ISOTime> 2010-05-18T06:18:26.56

Page 11: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1111

libVOEvent<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

</ISOTime> </TimeInstant> </Time> <Position2D unit='deg'> <Name1> RA </Name1> <Name2> Dec </Name2> <Value2> <C1 pos_unit='deg'> 311.1619 </C1> <C2 pos_unit='deg'> 40.1699 </C2> </Value2> <Error2Radius> 0.0500 </Error2Radius> </Position2D> </AstroCoords> </ObservationLocation> </ObsDataLocation> <Description> The RA,Dec coordinates are of the type: source_object. </Description> </WhereWhen> <How> <Description> Swift Satellite, BAT Instrument </Description> <Reference uri='http://gcn.gsfc.nasa.gov/swift.html' type='url'/> </How> <Why importance='0.90'> <Inference probability='0.98'> <Name> GRB 100518 </Name> <Concept> process.variation.burst;em.gamma </Concept> </Inference> </Why> <Description> </Description> </voe:VOEvent>

• Twice as many elements as VOTable• Addition of ephemeris, time-series, etc won’t help•No general-purpose code available

Page 12: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1212

libVOEvent<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

Sample Low-level interface:

voe = voe_openVOEvent (str|fname, &version, &ivorn) voe_closeVOEvent (voe)

who = voe_getWho (voe) str = voe_getAuthorIVORN (who) auth = voe_getAuthor (who)

str = voe_getTitle (auth) str = voe_getShortName (auth) str = voe_getLogoURL (auth) str = voe_getContactName (auth) str = voe_getContactEmail (auth) str = voe_getContactPhone (auth) str = voe_getContributor (auth)

: :

Page 13: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1313

libVOEvent<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

Sample Hi-level interface:

who_str = voe_getWho (voe) what_str = voe_getWhat (voe) when_str = voe_getWhenWhere (voe) how_str = voe_getHow (voe) why_str = voe_getWhy (voe)

voe_setWho (voe, title, shortName, contactName, ivorn) voe_setWhat (voe, name[], value[], ucd[]) voe_setWhenWhere (voe, obsName, ra, dec, err) voe_setHow (voe, refUri, type, name) voe_setWhy (voe, name, concept, probability)

Page 14: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1414

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

• Client-side middleware to send/receive messages

• Based on XMLRPC-C w/ simpler interface

• Distributed as part of the library

• No separate Hub implementation

• High-level interface for easy use

Page 15: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1515

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

• Client-side middleware to send/receive messages

• Based on XMLRPC-C w/ simpler interface

• Distributed as part of the library

• No separate Hub implementation

• Hides Hub interaction, no need for user to be aware

• High-level interface for easy use

• Low-level interface for finer control

Page 16: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1616

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

samp = sampInit (appName, descr)

sampClose (samp)

stat = sampStartup (samp

sampShutdown (samp)

samp_setMetadata (samp, field, value)

samp_setSubscription (samp, mtype, handler)

samp_setCallMode (samp, sync|async)

samp_setReplyCallback (samp, func)

samp_setResponseCallback (samp, func)

stat = samp_replyStatus (samp)

Page 17: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1717

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

Example Code:

samp = sampInit (name, descr); /* initialize the interface */

samp_setMetadata (samp, "samp.icon.url", "none”) samp_setMetadata (samp, "echo.test", "myValue");

/* Subscribe to various message types. */ samp_setSubscription (samp, "samp.app.ping", NULL); samp_setSubscription (samp, ”image.*", imageHandler); samp_setSubscription (samp, ”table.*", tableHandler);

sampStartup (samp); /* Startup */

.... do other stuff

sampShutdown (samp);

Page 18: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1818

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

High-level message sending:

msg_id = samp_tableLoadFITS (recip, url, id, name[, method]) msg_id = samp_tableLoadVOTable (recip, url, id, name[, method]) msg_id = samp_tableHighlightRow (recip, url, id, row[, method]) msg_id = samp_tableSelectRowList (recip, url, id, rowlist[, method])

msg_id = samp_imageLoadFITS (recip, url, id, name[, method]): : : : :

reply = samp_getReply (msg_id)

Page 19: The VAO is operated by the VAO, LLC. VO Application Libraries Mike Fitzpatrick NOAO.

May 18, 2010IVOA Interop – Victoria, 2010

1919

libSAMP<?xml version= "1.0" encoding= "UTF-8"?> </Why> <Description> </Description> </voe:VOEvent>

Dealing with Maps / Lists

map = samp_newMap () samp_freeMap (Map map) samp_setStringInMap (Map map, char *key, char *value) samp_setMapInMap (Map map1, char *key, Map map2) samp_setListInMap (Map map, char *key, List list) str = samp_getStringFromMap (Map map, char *key) map = samp_getMapFromMap (Map map, char *key) list = samp_getListFromMap (Map map, char *key)