Class: RFits::HDU

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

Overview

The base class for all HDUs. It’s possible to use this on its own, but really it’s intended to be abstract.

Direct Known Subclasses

Image, Table

Constant Summary collapse

HDU_TYPE_MAP =
{
  IO::Proxy::IMAGE_HDU => :image,
  IO::Proxy::ASCII_TBL => :ascii_tbl,
  IO::Proxy::BINARY_TBL => :binary_tbl,
  IO::Proxy::ANY_HDU => :other
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, extpos) ⇒ HDU

Initialize a new HDU in the specified file at the specified position (zero-based). This doesn’t actually write bytes to file–use HDU#create for that.

fits = File.open('m31.fits', 'rw') do |f|
  hdu = HDU.new(f, 2)
end


805
806
807
808
809
810
811
# File 'lib/rfits/rfits.rb', line 805

def initialize(file, extpos)
  @file = file
  @extpos = extpos
  
  @header = Header.new(self)
  @data = ImageData.new(self)
end

Instance Attribute Details

#dataObject (readonly)

The data associated with the HDU.



798
799
800
# File 'lib/rfits/rfits.rb', line 798

def data
  @data
end

#fileObject (readonly)

The file object associated with the HDU.



792
793
794
# File 'lib/rfits/rfits.rb', line 792

def file
  @file
end

#headerObject (readonly)

The header associated with the HDU.



795
796
797
# File 'lib/rfits/rfits.rb', line 795

def header
  @header
end

Instance Method Details

#hdu_typeObject

Get the type of HDU. Possibilities are: :image, :ascii_tbl, :binary_tbl, :other



814
815
816
817
# File 'lib/rfits/rfits.rb', line 814

def hdu_type
  reset_position()
  HDU_TYPE_MAP[IO::Proxy.fits_get_hdu_type(self.file.io)] || :unknown
end

#positionObject

Get the position of the HDU.

puts hdu.position   # 2 -> this is the third HDU in the file


821
822
823
824
# File 'lib/rfits/rfits.rb', line 821

def position
  reset_position()
  IO::Proxy.fits_get_hdu_num(self.file.io) - 1
end

#reset_positionObject



826
827
828
# File 'lib/rfits/rfits.rb', line 826

def reset_position
  IO::Proxy.fits_movabs_hdu(self.file.io, @extpos + 1)
end