Class: VORuby::SkyQuery::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/voruby/sky_query/sky_query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Service

Create a new SkyQuery service instance. Currently the only valid keys in the options hash is :end_point representing the location of the SkyQuery soap service and :namespace representing the namespace of that service. The default is to use OpenSkyQuery (i.e. end_point = openskyquery.net/Sky/SkyPortal/SkyPortal.asmx and namespace = SkyPortal.ivoa.net)

portal = SkyQuery.new


33
34
35
36
# File 'lib/voruby/sky_query/sky_query.rb', line 33

def initialize(options={})
  self.namespace = options[:namespace] || 'SkyPortal.ivoa.net'
  self.end_point = options[:end_point] || 'http://openskyquery.net/Sky/SkyPortal/SkyPortal.asmx'
end

Instance Attribute Details

#end_pointObject

Returns the value of attribute end_point.



16
17
18
# File 'lib/voruby/sky_query/sky_query.rb', line 16

def end_point
  @end_point
end

#namespaceObject

Returns the value of attribute namespace.



15
16
17
# File 'lib/voruby/sky_query/sky_query.rb', line 15

def namespace
  @namespace
end

Class Method Details

.query(adql, node = nil, options = {}) ⇒ Object

Query the SkyQuery service. A VOTable::V1_1::VOTable is returned.

Service.query('SELECT o.objid, o.ra, o.dec FROM SDSS:PhotoPrimary o WHERE o.type = 3')

This is a convenience method for

Service.new.query('SELECT o.objid, o.ra, o.dec FROM SDSS:PhotoPrimary o WHERE o.type = 3')


22
23
24
# File 'lib/voruby/sky_query/sky_query.rb', line 22

def self.query(adql, node=nil, options={})
  self.new(options).query(adql, node)
end

Instance Method Details

#column_info(node, table, column) ⇒ Object

Retrieve the metadata associated with the specified column. Returns an object with #name, #unit, #description and #ucd fields.

info = portal.column_info('SDSS', 'PhotoPrimary', 'modelMag_i')


144
145
146
147
148
# File 'lib/voruby/sky_query/sky_query.rb', line 144

def column_info(node, table, column)
  response = @portal.call('GetColumnInfo', node.to_s, table.to_s, column.to_s)
  xml = XML::Parser.string(response).parse.root.find_first("//*[local-name()='GetColumnInfoResult']")
  parse_meta_column(xml)
end

#columns(node, table) ⇒ Object

Retrieve the list of columns associated with the specified table. Returns a list of column names.

column_names = portal.columns('SDSS', 'PhotoPrimary')


153
154
155
156
# File 'lib/voruby/sky_query/sky_query.rb', line 153

def columns(node, table)
  response = @portal.call('GetColumns', node.to_s, table.to_s)
  XML::Parser.string(response).parse.root.find("//*[local-name()='string']").collect { |c| c.content }
end

#meta_columns(node, table) ⇒ Object

Retrieve the metadata associated with the columns of the specified table. Returns a list of objects with #name, #unit, #description and #ucd fields.

columns = portal.meta_columns('SDSS', 'PhotoPrimary')


136
137
138
139
# File 'lib/voruby/sky_query/sky_query.rb', line 136

def meta_columns(node, table)
  response = @portal.call('GetMetaColumns', node.to_s, table.to_s)
  XML::Parser.string(response).parse.root.find("//*[local-name()='MetaColumn']").collect{ |mc| parse_meta_column(mc) }
end

#query(adql, node = nil) ⇒ Object

Query the SkyQuery service. A VOTable::V1_1::VOTable is returned.

votable = portal.query('SELECT o.objid, o.ra, o.dec FROM SDSS:PhotoPrimary o WHERE o.type = 3') # typical, distributed query
votable = portal.query('SELECT o.objid, o.ra, o.dec FROM SDSS:PhotoPrimary o WHERE o.type = 3', 'SDSS') # query a particular node (unusual)


108
109
110
111
112
113
114
# File 'lib/voruby/sky_query/sky_query.rb', line 108

def query(adql, node=nil)
  response = node ?
    @portal.call('SubmitQuery', adql.to_s, node, 'votable') :
    @portal.call('SubmitDistributedQuery', adql.to_s, 'votable')
    
  parse_votable(response)
end

#sky_nodesObject

Find all nodes available from the SkyPortal service. Returns a VOTable::V1_1::VOTable.



100
101
102
103
# File 'lib/voruby/sky_query/sky_query.rb', line 100

def sky_nodes
  response = @portal.call('GetAllSkyNodesVOTable')
  parse_votable(response, 'GetAllSkyNodesVOTableResult')
end

#table_info(node, table) ⇒ Object

Retrieve the metadata associated with the specified table. Returns an object with #name, #description and #rows fields.

info = portal.table_info('SDSS', 'PhotoPrimary')


127
128
129
130
131
# File 'lib/voruby/sky_query/sky_query.rb', line 127

def table_info(node, table)
  response = @portal.call('GetTableInfo', node.to_s, table.to_s)
  xml = XML::Parser.string(response).parse.root.find_first("//*[local-name()='GetTableInfoResult']")
  parse_meta_table(xml)
end

#tables(node) ⇒ Object

Retrieve the list of tables associated with the specified node. Returns a list of objects with #name, #description and #rows fields.

tables = portal.tables('SDSS')


119
120
121
122
# File 'lib/voruby/sky_query/sky_query.rb', line 119

def tables(node)
  response = @portal.call('GetTables', node.to_s)
  XML::Parser.string(response).parse.root.find("//*[local-name()='MetaTable']").collect{ |mt| parse_meta_table(mt) }
end