Class: VORuby::VOTable::V1_0::Fits

Inherits:
Base show all
Defined in:
lib/voruby/votable/1.0/votable.rb

Overview

Tabular data represented as a FITS file.

Constant Summary collapse

ELEMENT_NAME =
'FITS'

Instance Attribute Summary

Attributes inherited from XML::Object::Base

#node

Instance Method Summary collapse

Methods inherited from Base

#==, element_name, #get_element, #xpath_for

Methods inherited from XML::Object::Base

#==, element_name, from_file, #to_s

Constructor Details

#initialize(defn = nil) ⇒ Fits

Create a new FITS data stream.

fits = Fits.new(
  :extnum => 2,
  :stream => Stream.new(:href => http://fits.gsfc.nasa.gov/nrao_data/samples/image/swp05569slg.fits')
)


1632
1633
1634
# File 'lib/voruby/votable/1.0/votable.rb', line 1632

def initialize(defn=nil)
  super(defn)
end

Instance Method Details

#extnumObject

Retrieve the FITS extension number. Returns an integer.



1638
1639
1640
# File 'lib/voruby/votable/1.0/votable.rb', line 1638

def extnum
  self.node['extnum'] ? self.node['extnum'].to_i : nil
end

#extnum=(e) ⇒ Object

Set the FITS extension number.



1643
1644
1645
# File 'lib/voruby/votable/1.0/votable.rb', line 1643

def extnum=(e)
  @node['extnum'] = e.to_s
end

#streamObject

Retrieve the stream (Stream) associated with the FITS file.



1648
1649
1650
# File 'lib/voruby/votable/1.0/votable.rb', line 1648

def stream
  get_element(Stream)
end

#stream=(s) ⇒ Object

Set the stream (Stream) associated with the FITS file.

fits.stream = Stream.new(:href => 'http://whatever/my_fits.fits')


1654
1655
1656
# File 'lib/voruby/votable/1.0/votable.rb', line 1654

def stream=(s)
  set_element(Stream, s)
end

#to_rfitsObject

Retrieves the FITS file locally and returns it. If rfits is present a RFits::File object is returned (or a RFits::HDU subclass if #extnum is specified). If rfits is not present a File object is returned instead.



1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
# File 'lib/voruby/votable/1.0/votable.rb', line 1662

def to_rfits
  io = self.stream.retrieve
  
  io_obj = if io.is_a?(StringIO)
    tmp = Tempfile.new('fits')
    tmp.write(io.read)
    tmp
  else
    io
  end
  
  # RFits isn't absolutely required, but it's nice to have.
  return io_obj if !VORuby.rfits?
  
  rfits = RFits::File.new(io_obj.path)
  self.extnum ? rfits[self.extnum - 1] : rfits
end