Class: VORuby::VOTable::V1_1::Fits

Inherits:
Base show all
Defined in:
lib/voruby/votable/1.1/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')
)


1923
1924
1925
# File 'lib/voruby/votable/1.1/votable.rb', line 1923

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

Instance Method Details

#extnumObject

Retrieve the FITS extension number. Returns an integer.



1929
1930
1931
# File 'lib/voruby/votable/1.1/votable.rb', line 1929

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

#extnum=(e) ⇒ Object

Set the FITS extension number.



1934
1935
1936
# File 'lib/voruby/votable/1.1/votable.rb', line 1934

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

#streamObject

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



1939
1940
1941
# File 'lib/voruby/votable/1.1/votable.rb', line 1939

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')


1945
1946
1947
# File 'lib/voruby/votable/1.1/votable.rb', line 1945

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.



1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
# File 'lib/voruby/votable/1.1/votable.rb', line 1953

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