Class: VORuby::Resolver::Sesame

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

Overview

Sesame is the standard name resolution service of the virtual observatory. There are a couple of ways to use it, but typically one wants the RA and Dec of the target:

ra, dec = Sesame.resolve_position('m51')  # => the primary J2000 RA and Dec of M 51 in degrees
sesame = Sesame.resolve('m51')            # => a Sesame object with in-depth information about the name resolution
puts sesame.jradeg, sesame.jdedeg

It’s also possible to change the location of the web service used (to a mirror, say) and to specify which resolvers sesame should aggregate over (by default Simbad is used).

Defined Under Namespace

Classes: ResolvedInfo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sesame

Create a new sesame name resolver. options is a hash with the following keys:

:end_point

the sesame SOAP endpoint to use (default: cdsws.u-strasbg.fr/axis/services/Sesame)

:check_availability

whether to try to determine if the sesame service is available or not before each name resolution (default: false)

sesame = Sesame.new(
  :end_point => 'http://vizier.nao.ac.jp:8080/axis/services/Sesame' # maybe we're in Japan...
  :check_availability => true # and we want to always check the availability of the service
)


67
68
69
70
# File 'lib/voruby/resolver/sesame.rb', line 67

def initialize(options={})        
  self.end_point = options[:end_point] || 'http://cdsws.u-strasbg.fr/axis/services/Sesame'
  self.check_availability = options[:check_availability] || false
end

Instance Attribute Details

#check_availabilityObject

Whether to try to determine if the sesame service is available or not before each name resolution. The default is false.



24
25
26
# File 'lib/voruby/resolver/sesame.rb', line 24

def check_availability
  @check_availability
end

#xmlObject (readonly)

The result of the name resolution as an XML::Node. Not available until after #resolve has been called.



19
20
21
# File 'lib/voruby/resolver/sesame.rb', line 19

def xml
  @xml
end

Class Method Details

.resolve(target, against = :simbad, options = {}) ⇒ Object

Resolve the target. The optional against may be one of :simbad, :ned, :vizier or :all. Simbad is the most reliable, so that’s the default. options is a hash with the following keys:

:end_point

the sesame SOAP endpoint to use (default: cdsws.u-strasbg.fr/axis/services/Sesame)

:check_availability

whether to try to determine if the sesame service is available or not before each name resolution (default: false)

Returns a Sesame object, and is exactly equivalent to:

sesame = Sesame.new
sesame.resolve


38
39
40
41
42
43
# File 'lib/voruby/resolver/sesame.rb', line 38

def self.resolve(target, against=:simbad, options={})
  sesame = Sesame.new(options)
  sesame.resolve(target, against)
  
  sesame
end

.resolve_position(target, against = :simbad, as = :degrees, options = {}) ⇒ Object

Resolve the target, but return only the primary position and no other information. The parameters are as for #resolve with the addition of as which may be :degrees (default) or :sexigesimal. In the former case, an array of floats (ra, dec) is returned while in the latter an array of strings.

Sesame.resolve_position('m51')                # => [202.4682083, 47.1946667]
Sesame.resolve_position('m51', :sexigesimal)  # => ['13:29:52.36', '+47:11:40.8']


53
54
55
# File 'lib/voruby/resolver/sesame.rb', line 53

def self.resolve_position(target, against=:simbad, as=:degrees, options={})
  self.resolve(target, against, options).position(as)
end

Instance Method Details

#available?Boolean

Checks to see whether sesame is available. At this point it’s assumed the service is present at the location specified by #end_point. This just checks to see whether sesame reports itself as available or not.

Returns:

  • (Boolean)


140
141
142
143
144
145
146
# File 'lib/voruby/resolver/sesame.rb', line 140

def available?
  # We don't use an XML parser here because (as of 2007-01-04)
  # the validTo tag isn't closed properly, rendering the XML
  # malformed.
  result = @resolver.getAvailability
  result.match(/<available>\s*(.*)\s*<\/available>/)[1] == 'true'
end

#end_pointObject

The “end-point” or location of the name resolver’s webservice.



73
74
75
# File 'lib/voruby/resolver/sesame.rb', line 73

def end_point
  @end_point
end

#end_point=(epoint) ⇒ Object

Set the end-point or location of the name resolver’s webservice.

sesame.end_point = 'http://vizier.nao.ac.jp:8080/axis/services/Sesame'


79
80
81
82
83
84
85
86
# File 'lib/voruby/resolver/sesame.rb', line 79

def end_point=(epoint)
  @end_point = epoint
  
  # We don't use the WSDL for this because ruby doesn't deal well with method overloading.
  @resolver = SOAP::RPC::Driver.new(@end_point)
  @resolver.add_rpc_method('sesame', 'name', 'resultType', 'all', 'service')
  @resolver.add_rpc_method('getAvailability')
end

#errorsObject

Any errors reported by sesame sent back with your results.



118
119
120
# File 'lib/voruby/resolver/sesame.rb', line 118

def errors
  self.xml.find('ERROR').collect{ |e| e.content }
end

#infosObject

Any information that sesame sent back with your results.



113
114
115
# File 'lib/voruby/resolver/sesame.rb', line 113

def infos
  self.xml.find('INFO').collect{ |i| i.content }
end

#position(as = :degrees) ⇒ Object

A shortcut for ResolvedInfo#position. Assumes the first resolver is the one you’re most interested in.



132
133
134
# File 'lib/voruby/resolver/sesame.rb', line 132

def position(as=:degrees)
  self.resolvers.first.position(as)
end

#resolve(target, against = :simbad) ⇒ Object

Retrieve whatever information we can about the position of the specified target. The optional against may be one of :simbad, :ned, :vizier or :all. Simbad is the most reliable, so that’s the default.

sesame.resolve('m51', :all)  # use all the resources at sesame's disposal

This method may throw an exception if:

  • #end_point doesn’t exist

  • you have set #check_availabilty to true and the resolver has indicated it is not available



98
99
100
101
102
103
104
105
# File 'lib/voruby/resolver/sesame.rb', line 98

def resolve(target, against=:simbad)
  raise "Sesame at #{self.end_point} is not currently available" if self.check_availability and !self.available?
  
  parser = XML::Parser.new
  parser.string = 
    @resolver.sesame(target.to_s, 'x', true, service_designation(against))
  @xml = parser.parse.root
end

#resolversObject

Sesame actually aggregates results from a number of sources. Returns an array of ResolvedInfo objects, one for each resource polled (i.e. some combination of Simbad, VizieR and Ned).



125
126
127
# File 'lib/voruby/resolver/sesame.rb', line 125

def resolvers
  self.xml.find('Resolver').collect{ |r| ResolvedInfo.new(r) }
end

#targetObject

The target you requested name resolution on.



108
109
110
# File 'lib/voruby/resolver/sesame.rb', line 108

def target
  self.xml.find_first('target').content
end