Class: VORuby::Wesix::Service

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

Overview

Allows access to WESIX, a webservice interface to the standard astronomical image analysis package SExtractor together with a cross matching service using OpenSkyQuery.

Supposing the FITS file you’re interested in is available via a URL, to run a source extraction with sensible defaults:

wesix = Service.new
votable = wesix.extract('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')

If it happens to be on disk, you can:

votable = wesix.extract(File.new('myfits.fits'))

The returned object is a standard VOTable::V1_1::VOTable from which your sources can be extracted.

Likewise, an extraction and crossmatch against the SDSS could be done in the following way:

votable = wesix.xmatch('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')

or if it’s on disk:

votable = wesix.xmatch(File.new('myfits.fits'))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Service

Create a new wesix service instance. Currently the only valid key in the options hash is :end_point representing the location of the WESIX soap service, and defaults to nvogre.phyast.pitt.edu:8080/axis/services/WesixTest. Since at the moment this is the only existing instance of WESIX, you’ll never need to specify it.

wesix = Wesix.new


276
277
278
# File 'lib/voruby/wesix/wesix.rb', line 276

def initialize(options={})
  self.end_point = options[:end_point] || 'http://nvogre.phyast.pitt.edu:8080/axis/services/WesixTest'
end

Instance Attribute Details

#end_pointObject

Returns the value of attribute end_point.



253
254
255
# File 'lib/voruby/wesix/wesix.rb', line 253

def end_point
  @end_point
end

Class Method Details

.extract(resource, transpose = false, *args) ⇒ Object

Convenience method for Service#extract.

votable = Service.extract('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')


257
258
259
260
# File 'lib/voruby/wesix/wesix.rb', line 257

def self.extract(resource, transpose=false, *args)
  wesix = Service.new
  wesix.extract(resource, transpose, *args)
end

.xmatch(resource, transpose = false, *args) ⇒ Object

Convenience method for Service#xmatch.

votable = Service.xmatch('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')


264
265
266
267
# File 'lib/voruby/wesix/wesix.rb', line 264

def self.xmatch(resource, transpose=false, *args)
  wesix = Service.new
  wesix.xmatch(resource, transpose, *args)
end

Instance Method Details

#extract(resource, transpose = false, *args) ⇒ Object

Perform a source extraction on the specified FITS file.

resource is the FITS file in question. It may be string representing a URL, a URI object or an object that responds to #read (such as a File).

transpose is a boolean value indicating whether to transpose the image before SExtraction (sometimes necessary for SDSS images).

The next two optional arguments are the parameters to be used by SExtractor to create the source catalog (as a Params object) and the measured parameters to be included in the output catalog (as an OutputParams object).

A VOTable::V1_1::VOTable is returned.

Source extraction with defaults
wesix.extract('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')  # from a URL
wesix.extract(URL.parse('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits'))  # this is the same as above
wesix.extract(File.new('../fits/my_file.fits'))  # from a local file
Source extraction with sextractor parameters defined
wesix.extract(
  File.new('../fits/my_file.fits'),  # local file, pass a string or URI object if the FITS file is remote
  false,  # no transposition
  Params.new(:detect_thresh => 2.0, :analysis_thresh => 2.0)
)
Source extraction with sextractor parameters and measured parameters defined
wesix.extract(
  File.new('../fits/my_file.fits'),  # local file, pass a string or URI object if the FITS file is remote
  false,  # no transposition
  Params.new(:detect_thresh => 2.0, :analysis_thresh => 2.0),
  OutputParams.new(:flux_best => true, :fluxerr_best => true)
)


350
351
352
353
354
355
356
357
358
# File 'lib/voruby/wesix/wesix.rb', line 350

def extract(resource, transpose=false, *args)
  if resource.is_a?(URI) or resource.is_a?(String)    # FITS file is on a remote machine
    self.extract_from_url(resource.to_s, transpose, *args)
  elsif resource.respond_to?(:read)  # FITS file is on a local machine, stored as a diskfile
    self.extract_from_file(resource, transpose, *args)
  else
    raise ArgumentError, 'resource must be a URI, String or respond to a method called #read'
  end
end

#extract_and_xmatch(resource, transpose = false, *args) ⇒ Object

Perform a source extraction followed by a crossmatch on the specified FITS file.

resource is the FITS file in question. It may be string representing a URL, a URI object or an object that responds to #read (such as a File).

transpose is a boolean value indicating whether to transpose the image before SExtraction (sometimes necessary for SDSS images).

The next two optional arguments are the parameters to be used by SExtractor to create the source catalog (as a Params object) and the measured parameters to be included in the output catalog (as an OutputParams object).

A VOTable::V1_1::VOTable is returned.

Source extraction and crossmatch with defaults
wesix.extract_and_xmatch('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits')  # from a URL
wesix.extract_and_xmatch(URL.parse('http://nvogre.phyast.pitt.edu:8080/wesix/testr.fits'))  # this is the same as above
wesix.extract_and_xmatch(File.new('../fits/my_file.fits'))  # from a local file
Source extraction and crossmatch with sextractor parameters defined
wesix.extract_and_xmatch(
  File.new('../fits/my_file.fits'),  # local file, pass a string or URI object if the FITS file is remote
  false,  # no transposition
  Params.new(:detect_thresh => 2.0, :analysis_thresh => 2.0)
)
Source extraction and crossmatch with sextractor parameters and measured parameters defined
wesix.extract_and_xmatch(
  File.new('../fits/my_file.fits'),  # local file, pass a string or URI object if the FITS file is remote
  false,  # no transposition
  Params.new(:detect_thresh => 2.0, :analysis_thresh => 2.0),
  OutputParams.new(:flux_best => true, :fluxerr_best => true)
)


401
402
403
404
405
406
407
408
409
# File 'lib/voruby/wesix/wesix.rb', line 401

def extract_and_xmatch(resource, transpose=false, *args)
  if resource.is_a?(URI) or resource.is_a?(String)  # FITS file is on a remote machine
    self.extract_and_xmatch_from_url(resource.to_s, transpose, *args)
  elsif resource.respond_to?(:read)  # FITS file is on a local machine, stored as a diskfile
    self.extract_and_xmatch_from_file(resource, transpose, *args)
  else
    raise ArgumentError, 'resource must be a URI, String or respond to a method called #read'
  end
end

#extract_and_xmatch_from_file(file, transpose = false, *args) ⇒ Object

Perform a source extraction and crossmatch on a local FITS file. file is any object with a #read method (such as File). Otherwise exactly as #extract_and_xmatch.



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/voruby/wesix/wesix.rb', line 436

def extract_and_xmatch_from_file(file, transpose=false, *args)
  raise "resource does not respond to #read" if !file.respond_to?(:read)
  
  file = SOAP::SOAPBase64.new(file.read)
  file.type = XSD::QName.new('http://www.w3.org/2001/XMLSchema', 'base64Binary')
  transpose = transpose ? 1 : 0
  
  response = case args.size
    when 0      then @extractor.wsextractor1VOXmatch(file, transpose)  # basic
    when 1      then @extractor.wsextractor2VOXmatch(file, args.first, transpose)   # input params specified
    when 2      then @extractor.wsextractor3VOXmatch(file, args.first, args.last, transpose) # input params/output flags specified
    else
      raise ArgumentError, "wrong number of optional arguments: #{args.size} > 2"
  end
  
  vot_node = XML::Parser.string(response).parse.root.find_first("//*[local-name()='VOTABLE']")
  VORuby::VOTable.from_xml(vot_node)
end

#extract_and_xmatch_from_url(url, transpose = false, *args) ⇒ Object

Perform a source extraction and crossmatch on a remotely accessible FITS file. url may be a string or a URI object. Otherwise exactly as for #extract_and_xmatch.



474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/voruby/wesix/wesix.rb', line 474

def extract_and_xmatch_from_url(url, transpose=false, *args)
  transpose = transpose ? 1 : 0
  
  response = case args.size
    when 0      then @extractor.wsextractorURL1VOXmatch(url.to_s, transpose)  # basic
    when 1      then @extractor.wsextractorURL2VOXmatch(url.to_s, args.first, transpose)   # input params specified
    when 2      then @extractor.wsextractorURL3VOXmatch(url.to_s, args.first, args.last, transpose) # input params/output flags specified
    else
      raise ArgumentError, "wrong number of optional arguments: #{args.size} > 2"
  end
  
  vot_node = XML::Parser.string(response).parse.root.find_first("//*[local-name()='VOTABLE']")
  VORuby::VOTable.from_xml(vot_node)
end

#extract_from_file(file, transpose = false, *args) ⇒ Object

Perform a source extraction on a local FITS file. file is any object with a #read method (such as File). Otherwise exactly as #extract.



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/voruby/wesix/wesix.rb', line 414

def extract_from_file(file, transpose=false, *args)
  raise "resource does not respond to #read" if !file.respond_to?(:read)

  file = SOAP::SOAPBase64.new(file.read)
  file.type = XSD::QName.new('http://www.w3.org/2001/XMLSchema', 'base64Binary')
  transpose = transpose ? 1 : 0
  
  response = case args.size
    when 0      then @extractor.wsextractor1VO(file, transpose)  # basic
    when 1      then @extractor.wsextractor2VO(file, args.first, transpose)   # input params specified
    when 2      then @extractor.wsextractor3VO(file, args.first, args.last, transpose) # input params/output flags specified
    else
      raise ArgumentError, "wrong number of optional arguments: #{args.size} > 2"
  end
  
  vot_node = XML::Parser.string(response).parse.root.find_first("//*[local-name()='VOTABLE']")
  VORuby::VOTable.from_xml(vot_node)
end

#extract_from_url(url, transpose = false, *args) ⇒ Object

Perform a source extraction on a remotely accessible FITS file. url may be a string or a URI object. Otherwise exactly as for #extract.



457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/voruby/wesix/wesix.rb', line 457

def extract_from_url(url, transpose=false, *args)
  transpose = transpose ? 1 : 0
  
  response = case args.size
    when 0      then @extractor.wsextractorURL1VO(url.to_s, transpose)  # basic
    when 1      then @extractor.wsextractorURL2VO(url.to_s, args.first, transpose)   # input params specified
    when 2      then @extractor.wsextractorURL3VO(url.to_s, args.first, args.last, transpose) # input params/output flags specified
    else
      raise ArgumentError, "wrong number of optional arguments: #{args.size} > 2"
  end
  
  vot_node = XML::Parser.string(response).parse.root.find_first("//*[local-name()='VOTABLE']")
  VORuby::VOTable.from_xml(vot_node)
end

#xmatch(resource, transpose = false, *args) ⇒ Object

Alias for #extract_and_xmatch



361
362
363
# File 'lib/voruby/wesix/wesix.rb', line 361

def xmatch(resource, transpose=false, *args)
  self.extract_and_xmatch(resource, transpose, *args)
end